StoreAccountOrderCheckingController.js 9.9 KB
"use strict";
var StoreAccountOrderCheckingController = angular.module('StoreAccountOrderCheckingController',['ngDialog']);

StoreAccountOrderCheckingController.controller('StoreAccountOrderCheckingController', [
    '$rootScope',
    '$scope',
    'StoreAccountOrderCheckingService',
    function($rootScope, $scope, StoreAccountOrderCheckingService) {
        $scope.accounts=[];
        $scope.currentPage = 1;
        $scope.pageSize = 15;
        $scope.numPages = 1;
        $scope.totalRecord = 0;
        $scope.choseAtrr=[];
        $scope.pages = [];
        $scope.master=false;
        $scope.order=[];
        $scope.accountQuery={
            checkingOrderCode:'',
            supplierName:'',
            auditStatus:'',
            settleStartDate:'',
            settleEndDate:'',
            pageNow:1,
            pageSize:10,
        };

        StoreAccountOrderCheckingService.accountPagerList($scope.accountQuery);
        $scope.$on('accounts.list', function(){
            $scope.accounts = StoreAccountOrderCheckingService.accounts;
            $scope.numPages = StoreAccountOrderCheckingService.accounts.totalPage;
            $scope.totalRecord = StoreAccountOrderCheckingService.accounts.totalRecord;
        });


        //选当前页
        $scope.onSelectPage = function(page) {
            $scope.accountQuery.pageNow=page;
            $scope.currentPage=page;
            StoreAccountOrderCheckingService.accountPagerList($scope.accountQuery);
        };

        $scope.search=function(){
            $scope.accountQuery.pageNow=1;
            $scope.accountQuery.settleStartDate = $('#settleStartDate').val();
            $scope.accountQuery.settleEndDate   = $('#settleEndDate').val();
            StoreAccountOrderCheckingService.accountPagerList($scope.accountQuery);
        }

        $scope.chk=function(orderCheckingId,check){
            var id =orderCheckingId;
            //选中变未选中
            if(check){
                var index=$scope.choseAtrr.indexOf(id);
                $scope.choseAtrr.splice(index,1);
            }else{
                //未选中变选中
                $scope.choseAtrr.push(id);
            }
        }

        $scope.allcheck=function(c){
            $scope.x=c;
            $scope.choseAtrr=[];
            if(!c){
                angular.forEach($scope.accounts.datas,function(data){
                    var id =data.orderCheckingId;
                    $scope.choseAtrr.push(id);

                })
            };
        }
        //确认账单
        $scope.verifyOrder=function(orderCheckingId){
            if(orderCheckingId){
                var id=orderCheckingId;
                $scope.choseAtrr=[id];
            }
            if($scope.choseAtrr.length<=0){
                alert("请先选中操作记录");
                return;
            }
            var ids= $scope.choseAtrr.join(";");
            var flag=true;
            angular.forEach($scope.choseAtrr,function(id){
                angular.forEach($scope.accounts.datas,function(data){
                    if(data.auditStatus !=3&&data.orderCheckingId==id&&flag){
                        alert("只能确认待确认的账单!");
                        flag=false;
                        return;
                    }
                })
            })
            if(flag){
                if(confirm("确定确认账单?")){
                    StoreAccountOrderCheckingService.verifyOrder(ids,function(){
                        $scope.master=false;
                        $scope.choseAtrr=[];
                        StoreAccountOrderCheckingService.accountPagerList($scope.accountQuery);
                    });
                }
            }
        };

        //导出对账单
        $scope.exportCheckingOrder=function(orderCheckingId) {
            window.open("../template/exportStoreOrderCheckingExcel/"+orderCheckingId);
        };
    }
]);


StoreAccountOrderCheckingController.controller('discountsProportionDetailsController', [
	'$rootScope',
	'$scope',
	'StoreAccountOrderCheckingService',
	'ngDialog',
	function($rootScope, $scope, StoreAccountOrderCheckingService,ngDialog) {
		$scope.discountsProportions=[];
		$scope.currentPage = 1;
		$scope.pageSize = 15;
		$scope.numPages = 1;
		$scope.totalRecord = 0;
		$scope.pages = [];
		$scope.master=false;
		$scope.dpdQuery={
			startAmount:'',
			endAmount:'',
			startDate:'',
			endDate:'',
			pageNow:1,
			pageSize:10,
		};

		StoreAccountOrderCheckingService.discountsProportionDetailPager($scope.dpdQuery);
		$scope.$on('discountsProportions.list', function(){
			$scope.discountsProportions = StoreAccountOrderCheckingService.discountsProportions;
			$scope.numPages = StoreAccountOrderCheckingService.discountsProportions.totalPage;
			$scope.totalRecord = StoreAccountOrderCheckingService.discountsProportions.totalRecord;
		});


		//选当前页
		$scope.onSelectPage = function(page) {
			$scope.dpdQuery.pageNow=page;
			$scope.currentPage=page;
			StoreAccountOrderCheckingService.discountsProportionDetailPager($scope.dpdQuery);
		};

		$scope.search=function(){
			$scope.dpdQuery.pageNow=1;
			$scope.dpdQuery.startDate = $('#startDate').val();
			$scope.dpdQuery.endDate   = $('#endDate').val();
			StoreAccountOrderCheckingService.discountsProportionDetailPager($scope.dpdQuery);
		}
       $scope.deleteDiscountsProportion=function(id){
		   if(confirm("确定要删除这条数据吗?")){
			   StoreAccountOrderCheckingService.deleteDiscountsProportion(id,function(){
				   StoreAccountOrderCheckingService.discountsProportionDetailPager($scope.dpdQuery);
				   $scope.$on('discountsProportions.list', function(){
					   $scope.discountsProportions = StoreAccountOrderCheckingService.discountsProportions;
					   $scope.numPages = StoreAccountOrderCheckingService.discountsProportions.totalPage;
					   $scope.totalRecord = StoreAccountOrderCheckingService.discountsProportions.totalRecord;
				   });
			   });
		   }
	   }

	}
]);


StoreAccountOrderCheckingController.controller('editDiscountsProportionController', [
	'$rootScope',
	'$scope',
	'StoreAccountOrderCheckingService',
	'BaseService',
	function($rootScope, $scope, StoreAccountOrderCheckingService,BaseService) {
		var aid =  $rootScope.$stateParams.id;
		$scope.imageUrl = '';
		$scope.editDpdInfo={
			id:aid,
			startAmount:0,
			endAmount:0,
			rate:0
		};

		if(aid){
			StoreAccountOrderCheckingService.getDiscountsProportion(aid, function (data) {
				$scope.editDpdInfo = data.data;
			});
		}

		$scope.onSubmitDiscountsProportion=function(){
			if(isNaN($scope.editDpdInfo.startAmount) || isNaN($scope.editDpdInfo.endAmount)){
				BaseService.updateAlert("小主,起始金额与结束金额只能输入数字!");
			}else if($scope.editDpdInfo.startAmount<0 || $scope.editDpdInfo.endAmount<0){
				BaseService.updateAlert("小主,起始金额与结束金额不能小于0!");
			}else if($scope.editDpdInfo.startAmount==0 && $scope.editDpdInfo.endAmount==0){
				BaseService.updateAlert("小主,起始金额与结束金额不能全部为0!");
			}else if(isNaN($scope.editDpdInfo.rate)){
				BaseService.updateAlert("小主,优惠比例只能输入数字!");
			}else if($scope.editDpdInfo.rate<0 || $scope.editDpdInfo.rate>100){
				BaseService.updateAlert("小主,优惠比例不能小于0或大于100!");
			}else {
				StoreAccountOrderCheckingService.editDiscountsProportionDetail($scope.editDpdInfo,aid);
			}
		}

	}]
);

StoreAccountOrderCheckingController.controller('createAccountOrderCheckingController', [
    '$rootScope',
    '$scope',
    'StoreAccountOrderCheckingService',
    'SysConfigService',
    'BaseService',
    'SupplierService',
    'ngDialog',
    function($rootScope, $scope, StoreAccountOrderCheckingService,SysConfigService,BaseService,SupplierService,ngDialog) {
        $scope.period = 30;
        $scope.period1 = 30;
        $scope.suppliers=[];
        $scope.orderChecking={
            settleStartDate:'',
            settleEndDate:'',
            supplierId:''
        };
        //获取商家列表
        SupplierService.listSupplier();
        $scope.$on('supplier.list',function(){
            $scope.suppliers=SupplierService.suppliers;
        });
       //获取周期
        SysConfigService.loanSysConfig();
        $scope.$on('sys.period', function () {
            if(SysConfigService.period!=null  && SysConfigService.period!=""){
                $scope.period = SysConfigService.period.content+"号";
                $scope.period1 = SysConfigService.period.content;
            }
        });

        $scope.exportOrderChecking = function(){
            $scope.orderChecking.settleStartDate = $('#settleStartDate').val();
            $scope.orderChecking.settleEndDate  = $('#settleEndDate').val();
            if($("#datepickfrom").val() !=null && $("#datepickfrom").val() !=""){
                if(confirm("小主,生成数据很多,请耐心等待...")) {
                    window.open("../accOrderCheckingController/createOrderChecking?startDate="+$scope.orderChecking.settleStartDate+
                        "&endDate="+  $scope.orderChecking.settleEndDate+"&supplierId="+ $scope.orderChecking.supplierId);
                }
            }else{
                BaseService.updateAlert("请选择月份");
            }

        }

        $scope.periodConfiguration= function(){
            $scope.flag = prompt("请输入你要配置的周期(号)");
            if($scope.flag !=null &&  $scope.flag !=""){
                if(isNaN($scope.flag)){
                    BaseService.updateAlert("请输入数字");
                    return false;
                }
                if(Math.floor($scope.flag) != $scope.flag){
                    BaseService.updateAlert("请输入整数!");
                    return false;
                }
                if($scope.flag <=0){
                    BaseService.updateAlert("请输入大于0的整数!");
                    return false;
                }
                SysConfigService.updatePeriodConfiguration($scope.flag);
            }

        }





    }]
);