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

AccountOrderCheckingController.controller('AccountOrderCheckingController', [
    '$rootScope',
    '$scope',
    'AccountOrderCheckingService',
    'ngDialog',
    function($rootScope, $scope, AccountOrderCheckingService,ngDialog) {
        $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,
        };

        //获取对账单列表
        AccountOrderCheckingService.accountPagerList($scope.accountQuery);
        $scope.$on('accounts.list', function(){
            $scope.accounts = AccountOrderCheckingService.accounts;
            $scope.numPages = AccountOrderCheckingService.accounts.totalPage;
            $scope.totalRecord = AccountOrderCheckingService.accounts.totalRecord;
        });

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

        //搜索
        $scope.search=function(){
            $scope.accountQuery.pageNow=1;
            $scope.accountQuery.settleStartDate = $('#settleStartDate').val();
            $scope.accountQuery.settleEndDate   = $('#settleEndDate').val();
            AccountOrderCheckingService.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){
                    if(data.status !=1){
                        var id =data.orderCheckingId;
                        $scope.choseAtrr.push(id);
                    }
                })
            };
        }

        //废除账单
        $scope.dropOrder=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 ==2||data.auditStatus ==4)&&data.orderCheckingId==id&&flag){
                        alert("不能废除已废除或者已确认的账单!");
                        flag=false;
                        return;
                    }
                })
            })
            if(flag){
                if(confirm("陛下,确定要废除账单吗? 臣妾做不到啊!")){
                    AccountOrderCheckingService.dropOrder(ids,function(){
                        $scope.master=false;
                        $scope.choseAtrr=[];
                        AccountOrderCheckingService.accountPagerList($scope.accountQuery);
                    });
                }
            }
        }

        //审核账单
        $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 !=0&&data.orderCheckingId==id&&flag){
                        alert("只能审核待审核的账单!");
                        flag=false;
                        return;
                    }
                })
            })
            if(flag){
                if(confirm("陛下,确定要审核账单吗? 臣妾做不到啊!")){
                    AccountOrderCheckingService.verifyOrder(ids,function(data){
                        if(!data){
                            $scope.master=false;
                            $scope.choseAtrr=[];
                            AccountOrderCheckingService.accountPagerList($scope.accountQuery);
                            return;
                        }
                        $scope.order=data;
                        ngDialog.open({
                            template: 'html/account/verifyUnsignOrderId.html',
                            className: 'ngdialog-theme-plain',
                            width: 650,
                            scope:$scope,
                            cache: false
                        });
                    });
                }
            }
        };

        //关闭模态窗口
        $scope.closeNgDialog = function() {
            ngDialog.close();
        };

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

    }
]);



AccountOrderCheckingController.controller('createAccountOrderCheckingController', [
    '$rootScope',
    '$scope',
    'AccountOrderCheckingService',
    'SysConfigService',
    'BaseService',
    'SupplierService',
    'ngDialog',
    function($rootScope, $scope, AccountOrderCheckingService,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);
            }

        }


    }]
);

AccountOrderCheckingController.controller('ImportActualPaymentOrderController', [
    '$rootScope',
    '$scope',
    'BaseService',
    function($rootScope, $scope, BaseService) {
        $scope.actualPayOrderInfos = [];
        $scope.errorMsg = "";
    }
]);



productSpecController.controller('discountsProportionController', [
    '$rootScope',
    '$scope',
    'AccountOrderCheckingService',
    'BaseService',
    function($rootScope, $scope, AccountOrderCheckingService,BaseService) {
        $scope.items=[];
        $scope.itemLength = 0;
        $scope.headTitles=["起始金额","结束金额","优惠比例(%)","操作"];
        $scope.valueKeys=['id','startAmount','endAmount','rate'];
        $scope.master=[];
        $scope.skus=[];
        $scope.dpList=[];
        var jsonObj={};
        AccountOrderCheckingService.listDiscountsProportion();
        $scope.$on('discountsProportions.list', function() {
            $scope.dpList = AccountOrderCheckingService.discountsProportions;
            if($scope.dpList&&$scope.dpList.length>0){
                for(var i=0;i<$scope.dpList.length;i++){
                    var discount=$scope.dpList[i];
                    var jsonObj={};
                    jsonObj['id']=discount.id;
                    jsonObj['startAmount']=discount.startAmount;
                    jsonObj['endAmount']=discount.endAmount;
                    jsonObj['rate']=discount.rate;
                    $scope.items.push(jsonObj);
                }
            }
        });

        $scope.addDp = function () {
            jsonObj={};
            for(var i=0;i<$scope.valueKeys.length;i++){
                var key=$scope.valueKeys[i];
                jsonObj[key]="";
            }
            $scope.items.push(jsonObj);
            $scope.itemLength = $scope.items.length-1;
        }
        $scope.deleteDp = function(index) {
            $scope.items.splice(index, 1);
            $scope.itemLength = $scope.items.length-1;
        }

        //保存数据
        $scope.saveDp=function(){
            if($scope.items.length>0){
                 for(var i=0;i<$scope.items.length;i++){
                     if(i==0){
                         $scope.items[i].startAmount=0;
                         $scope.items[i].endAmount=$scope.items[i].endAmount;
                     }else {
                         $scope.items[i].startAmount=$scope.items[i-1].endAmount;
                     }
                 }
                var dps=JSON.stringify($scope.items);
                AccountOrderCheckingService.saveOrUpdateDp(dps);
            }else {
                 var str=[];
                 for(var i=0;i<$scope.dpList.length;i++){
                     str.push($scope.dpList[i].id);
                 }
                AccountOrderCheckingService.deleteDp(str);
            }
         }


    }]
);