preview-account-voucher.js 13.2 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
commonModule.directive('previewAccountVoucher', ['$log', 'browserService', '$translate',
    function ($log, browserService, $translate) {
        $log.debug('previewAccountVoucher.ctor()...');

        return {
            restrict: 'E',
            templateUrl: '/app/common/controls/preview-account-voucher/preview-account-voucher.html' + '?_=' + Math.random(),
            scope: {
                isFromReMapping: '@',
                reMappId: '@',
                isEdit: '@',
                enterpriseCode: '=?',
                selectedVouchers: "=?",
                project: '=?',
                month:'=?',
            },
            controller: 'previewAccountVoucherController',
            link: function ($scope, element) {
                // ************************************************************************************************
                // Perform Data filter
                $scope.doDataFilter = function (removeData) {

                    $scope.filterData.periodFrom = $scope.monthFrom.selected.id;
                    $scope.filterData.periodTo = $scope.monthTo.selected.id;

                    if ($scope.filterData.periodFrom > $scope.filterData.periodTo) {
                        $scope.filterData.periodTo = $scope.filterData.periodFrom;
                    }

                    if (removeData !== "") {

                        $scope.openFilterPopup();

                        var textBoxNames = removeData.split("|");

                        for (var i = 0; i < textBoxNames.length; i++)
                            $("#" + textBoxNames[i]).val("");
  
                    }

                    $scope.filterData = {
                        periodFrom: $scope.filterData.periodFrom,
                        periodTo: $scope.filterData.periodTo,
                        accountCode: $("#accountCode").val().trim(),
                        accountName: $("#accountName").val().trim(),
                        debitOpeningBalanceFrom: $("#debitOpeningBalanceFrom").val().trim(),
                        debitOpeningBalanceTo: $("#debitOpeningBalanceTo").val().trim(),
                        creditOpeningBalanceFrom: $("#creditOpeningBalanceFrom").val().trim(),
                        creditOpeningBalanceTo: $("#creditOpeningBalanceTo").val().trim(),
                        accumulatedDebitAmountFrom: $("#accumulatedDebitAmountFrom").val().trim(),
                        accumulatedDebitAmountTo: $("#accumulatedDebitAmountTo").val().trim(),
                        accumulatedCreditAmountFrom: $("#accumulatedCreditAmountFrom").val().trim(),
                        accumulatedCreditAmountTo: $("#accumulatedCreditAmountTo").val().trim(),
                        debitClosingBalanceFrom: $("#debitClosingBalanceFrom").val().trim(),
                        debitClosingBalanceTo: $("#debitClosingBalanceTo").val().trim(),
                        creditClosingBalanceFrom: $("#creditClosingBalanceFrom").val().trim(),
                        creditClosingBalanceTo: $("#creditClosingBalanceTo").val().trim()
                    };

                    //********************************************************************************
                    // add to Criteria List for display on top of the grid:
                    var crits = $scope.filterData;

                    $scope.criteriaList = [];

                    var crit = [];
                    if (crits.accountCode !== "null" && crits.accountCode.length > 0) {
                        crit = new Object;
                        crit.name = $translate.instant('AccountCode');
                        crit.valueFrom = crits.accountCode;
                        crit.propertyName = "accountCode";

                        $scope.criteriaList.push(crit);
                    }

                    if (crits.accountName !== "null" && crits.accountName.length > 0) {
                        crit = new Object;
                        crit.name = $translate.instant('AccountName');
                        crit.valueFrom = crits.accountName;
                        crit.propertyName = "accountName";

                        $scope.criteriaList.push(crit);
                    }

                    if (crits.debitOpeningBalanceFrom !== "null" && crits.debitOpeningBalanceFrom.length > 0 || crits.debitOpeningBalanceTo !== "null" && crits.debitOpeningBalanceTo.length) {
                        crit = new Object;
                        crit.name = $translate.instant('DebitOpeningBalance');
                        crit.valueFrom = crits.debitOpeningBalanceFrom;
                        crit.valueTo = crits.debitOpeningBalanceTo;
                        crit.propertyName = "debitOpeningBalanceFrom|debitOpeningBalanceTo";

                        $scope.criteriaList.push(crit);
                    }

                    if (crits.creditOpeningBalanceFrom !== "null" && crits.creditOpeningBalanceFrom.length > 0 || crits.creditOpeningBalanceTo !== "null" && crits.creditOpeningBalanceTo.length) {
                        crit = new Object;
                        crit.name = $translate.instant('CreditOpeningBalance');
                        crit.valueFrom = crits.creditOpeningBalanceFrom;
                        crit.valueTo = crits.creditOpeningBalanceTo;
                        crit.propertyName = "creditOpeningBalanceFrom|creditOpeningBalanceTo";

                        $scope.criteriaList.push(crit);
                    }

                    if (crits.accumulatedDebitAmountFrom !== "null" && crits.accumulatedDebitAmountFrom.length > 0 || crits.accumulatedDebitAmountTo !== "null" && crits.accumulatedDebitAmountTo.length) {
                        crit = new Object;
                        crit.name = $translate.instant('AccumulatedDebitAmount');
                        crit.valueFrom = crits.accumulatedDebitAmountFrom;
                        crit.valueTo = crits.accumulatedDebitAmountTo;
                        crit.propertyName = "accumulatedDebitAmountFrom|accumulatedDebitAmountTo";

                        $scope.criteriaList.push(crit);
                    }

                    if (crits.accumulatedCreditAmountFrom !== "null" && crits.accumulatedCreditAmountFrom.length > 0 || crits.accumulatedCreditAmountTo !== "null" && crits.accumulatedCreditAmountTo.length) {
                        crit = new Object;
                        crit.name = $translate.instant('AccumulatedCreditAmount');
                        crit.valueFrom = crits.accumulatedCreditAmountFrom;
                        crit.valueTo = crits.accumulatedCreditAmountTo;
                        crit.propertyName = "accumulatedCreditAmountFrom|accumulatedCreditAmountTo";

                        $scope.criteriaList.push(crit);
                    }

                    if (crits.debitClosingBalanceFrom !== "null" && crits.debitClosingBalanceFrom.length > 0 || crits.debitClosingBalanceTo !== "null" && crits.debitClosingBalanceTo.length) {
                        crit = new Object;
                        crit.name = $translate.instant('DebitClosingBalance');
                        crit.valueFrom = crits.debitClosingBalanceFrom;
                        crit.valueTo = crits.debitClosingBalanceTo;
                        crit.propertyName = "debitClosingBalanceFrom|debitClosingBalanceTo";

                        $scope.criteriaList.push(crit);
                    }

                    if (crits.creditClosingBalanceFrom !== "null" && crits.creditClosingBalanceFrom.length > 0 || crits.creditClosingBalanceTo !== "null" && crits.creditClosingBalanceTo.length) {
                        crit = new Object;
                        crit.name = $translate.instant('CreditClosingBalance');
                        crit.valueFrom = crits.creditClosingBalanceFrom;
                        crit.valueTo = crits.creditClosingBalanceTo;
                        crit.propertyName = "creditClosingBalanceFrom|creditClosingBalanceTo";

                        $scope.criteriaList.push(crit);
                    }
                    // add to Criteria List for display on top of the grid:
                    //********************************************************************************



                    var criteria = JSON.stringify($scope.filterData);
                    if (browserService.isIE() || browserService.isEdge())
                        criteria = encodeURIComponent(criteria);

                    $scope.getDataFromDatabase($scope.currentCategory, $scope.filterData.periodFrom, $scope.filterData.periodTo, criteria);
                    $('.justPopMeOver').popover("hide");
                };
                // Perform Data filter
                // ************************************************************************************************

                $scope.openFilterPopup = function () {

                    $("#accountCode").val($scope.filterData.accountCode);
                    $("#accountName").val($scope.filterData.accountName);
                    $("#debitOpeningBalanceFrom").val($scope.filterData.debitOpeningBalanceFrom);
                    $("#debitOpeningBalanceTo").val($scope.filterData.debitOpeningBalanceTo);
                    $("#creditOpeningBalanceFrom").val($scope.filterData.creditOpeningBalanceFrom);
                    $("#creditOpeningBalanceTo").val($scope.filterData.creditOpeningBalanceTo);
                    $("#accumulatedDebitAmountFrom").val($scope.filterData.accumulatedDebitAmountFrom);
                    $("#accumulatedDebitAmountTo").val($scope.filterData.accumulatedDebitAmountTo);
                    $("#accumulatedCreditAmountFrom").val($scope.filterData.accumulatedCreditAmountFrom);
                    $("#accumulatedCreditAmountTo").val($scope.filterData.accumulatedCreditAmountTo);
                    $("#debitClosingBalanceFrom").val($scope.filterData.debitClosingBalanceFrom);
                    $("#debitClosingBalanceTo").val($scope.filterData.debitClosingBalanceTo);
                    $("#creditClosingBalanceFrom").val($scope.filterData.creditClosingBalanceFrom);
                    $("#creditClosingBalanceTo").val($scope.filterData.creditClosingBalanceTo);


                };
         
                $scope.isFromReMapping = false;
                
                $scope.$watch("enterpriseCode", function (newValue, oldValue) {
                    //选择不同COA时,初始化搜索条件  
                    if ($scope.isFromReMapping) {
                        $log.debug("start vat-preview-accountVoucher.js watching  enterpriseCode");
                        //设置科目代码
                        $("#coaAutoComplete").dxAutocomplete("instance").option("value", newValue);
                        if (!_.isUndefined(newValue) && !_.isUndefined(oldValue)) {
                            if (!_.isEqual(newValue, oldValue)) {                              
                                $scope.voucherDataList = [];
                                $('#gridContainer').dxDataGrid('instance').option("dataSource", $scope.voucherDataList); //切换不同的COA时,查询界面重置为空
                                $scope.queryString = ''; //查询条件汇总
                                $scope.vIDCount = 0;//凭证数
                                $scope.itemIDCount = 0;//分路数
                                $scope.debitSum = 0;//借方金额
                                $scope.creditSum = 0;//贷方金额
                            }
                        }
                    }                                        
                });

      
                $scope.$watch("isEdit", function (newValue, oldValue) {
                    $log.debug("start vat-preview-accountVoucher.js watching  isEdit");
                    $log.debug($scope.enterpriseCode);
                    $log.debug($scope.selectedVouchers);
                    $log.debug($scope.isEdit);

                    if ($scope.isFromReMapping) {
                        $("#coaAutoComplete").dxAutocomplete("instance").option("value", $scope.enterpriseCode);
                        $scope.voucherDataList = [];
                        $('#gridContainer').dxDataGrid('instance').option("dataSource", $scope.voucherDataList); //切换不同的COA时,查询界面重置为空
                        $scope.queryString = ''; //查询条件汇总
                        $scope.vIDCount = 0;//凭证数
                        $scope.itemIDCount = 0;//分路数
                        $scope.debitSum = 0;//借方金额
                        $scope.creditSum = 0;//贷方金额

                        //当凭证重对应点击编辑按钮时,调用查询
                        if (!_.isNull($scope.selectedVouchers) && $scope.isEdit === "true") {
                            $log.debug("start vat-preview-accountVoucher.js watching  selectVoucher ");
                            $scope.selectVoucher(); 
                        }

                    }
                });

             
            }
        };
    }
]);


commonModule.directive('convertToNumber', function () {
    return {
        require: 'ngModel',
        link: function (scope, element, attrs, ngModel) {
            ngModel.$parsers.push(function (val) {
                return val != null ? parseInt(val, 10) : null;
            });
            ngModel.$formatters.push(function (val) {
                return val != null ? '' + val : null;
            });
        }
    };
});