vat-preview-journal.ctrl.js 21.6 KB
Newer Older
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
vatModule.controller('VatPreviewJournalController', ['$scope', '$log', '$translate', '$timeout', 'SweetAlert', '$q', 'uiGridConstants', '$interval', 'vatPreviewService', 'browserService', 'vatSessionService', 'region', 'enums', 'vatExportService',
    function ($scope, $log, $translate, $timeout, SweetAlert, $q, uiGridConstants, $interval, vatPreviewService, browserService, vatSessionService, region, enums, vatExportService) {
        'use strict';

        $scope.startDate = new Date(vatSessionService.project.year, 0, 1);
        $scope.endDate = new Date(vatSessionService.project.year, 11, 31);
        $scope.dateFormat = $translate.instant('dateFormat4YearMonthDay');
        $scope.startMonth = vatSessionService.month;
        $scope.endMonth = vatSessionService.month;
        $scope.totalMoneyAmount = 0;
        $scope.totalTaxAmount = 0;

        var minDate = [1, vatSessionService.project.year];
        // var minDate = moment().startOf('month').subtract(0, 'months');
        var maxDate = [12, vatSessionService.project.year];
        var setDate = [
            [vatSessionService.month, vatSessionService.project.year],
            [vatSessionService.month, vatSessionService.project.year]];

        $scope.monthList = [$translate.instant('Month01'),
                            $translate.instant('Month02'),
                            $translate.instant('Month03'),
                            $translate.instant('Month04'),
                            $translate.instant('Month05'),
                            $translate.instant('Month06'),
                            $translate.instant('Month07'),
                            $translate.instant('Month08'),
                            $translate.instant('Month09'),
                            $translate.instant('Month10'),
                            $translate.instant('Month11'),
                            $translate.instant('Month12')
        ];

        //初始化期间
        var initPeriods = function () {
            var curMonth = new Date().getMonth() + 1;

            $scope.queryParams = {
                pageInfo: {},
                periodStart: '',
                periodEnd: '',
                orgId: '',
                segment3: null,
                segment3Name: null,
                segment5: null,
                segment5Name: null,
                segment6: null,
                segment6Name: null,
                description: null,
                containsAdjustmentRecord: null
            };
        };

        //从数据库中load数据
        var loadJournalEntryDataFromDB = function (pageIndex) {
            initJournalEntryPagination();
            $scope.curJournalEntryPage = pageIndex;

            //初始化查询信息
            $scope.queryParams.pageInfo = {
                totalCount: $scope.queryJournalEntryResult.pageInfo.totalCount,
                pageIndex: pageIndex,
                pageSize: $scope.queryJournalEntryResult.pageInfo.pageSize,
                totalPage: 0
            };
            $scope.getDataFromDatabase($scope.queryParams);
        };

        $scope.getDataFromDatabase = function (queryParams){
            vatPreviewService.getJEDataForDisplay(queryParams).success(function (data) {
                if (data) {
                    // minDate = data.
                    var index = 1;
                    data.list.forEach(function (v) {
                        v.index = index++;
                    });
                    $scope.gridOptions.data = data.list;
                    $scope.queryJournalEntryResult.pageInfo = data;
                    computeJournalEntryPage();
                }
            });
        };


        //点击任意一页加载数据事件
        var loadIncomeInvoiceDataByPage = function (pageIndex) {
            loadJournalEntryDataFromDB(pageIndex);
        };

        //计算页数,创建分页栏
        var computeJournalEntryPage = function () {

            if ($scope.queryJournalEntryResult.pageInfo && $scope.queryJournalEntryResult.pageInfo.total > 0) {

                var totalPage = parseInt($scope.queryJournalEntryResult.pageInfo.total / $scope.queryJournalEntryResult.pageInfo.pageSize);
                totalPage = $scope.queryJournalEntryResult.pageInfo.totalCount % $scope.queryJournalEntryResult.pageInfo.pageSize == 0 ? totalPage : totalPage + 1;

                //计算本页记录数
                if ($scope.queryJournalEntryResult.pageInfo.pageNum === totalPage) {
                    $scope.curPageItemCount = $scope.queryJournalEntryResult.pageInfo.total % $scope.queryJournalEntryResult.pageInfo.pageSize;
                }
                else {
                    $scope.curPageItemCount = $scope.queryJournalEntryResult.pageInfo.pageSize;
                }

                $scope.queryJournalEntryResult.pageInfo.totalPage = totalPage;

                var createPage = $("#totalInvoicePage").createPage({
                    pageCount: totalPage,
                    current: $scope.curJournalEntryPage,
                    backFn: function (p) {
                        //单击回调方法,p是当前页码
                        loadIncomeInvoiceDataByPage(p);
                    }
                });

                $('#totalInvoicePage').css('display', 'inline-block');
            } else {
                //如果查询结果为0,则直接设置本页记录数为0
                $scope.curPageItemCount = 0;
                var createPage = $("#totalInvoicePage").createPage({
                    pageCount: 0,
                    current: $scope.curJournalEntryPage,
                    backFn: function (p) {
                        //单击回调方法,p是当前页码
                        loadIncomeInvoiceDataByPage(p);
                    }
                });

                $('#totalInvoicePage').css('display', 'inline-block');
            }
        };

        //初始化分页信息
        var initJournalEntryPagination = function () {
            $scope.queryJournalEntryResult = {
                list: [],
                pageInfo: {
                    totalCount: -1,
                    pageIndex: 1,
                    pageSize: constant.pagesize,
                    totalPage: 0,
                }
            }

            $scope.curJournalEntryPage = 1;
        };

        //将选择了的查询条件显示在grid上方
        var doDataFilter = function (removeData) {
            if ($scope.queryParams.periodStart > $scope.queryParams.periodEnd) {
                $scope.queryParams.periodEnd = $scope.queryParams.periodStart;
            }

            //设置需要去掉的查询条件的值为空
            if (!PWC.isNullOrEmpty(removeData)) {
                var removeItem = removeData.split("|");
                removeItem.forEach(function (v) {
                    $scope.queryParams[v] = null;

                    if ($scope.queryParams.segment3 === null) {
                        $scope.queryParams.segment3 = '';
                    }
                    if ($scope.queryParams.segment3Name === null) {
                        $scope.queryParams.segment3Name = '';
                    }
                    if ($scope.queryParams.segment5 === null) {
                        $scope.queryParams.segment5Name = '';
                    }
                    if ($scope.queryParams.segment6 === null) {
                        $scope.queryParams.segment6 = '';
                    }
                    if ($scope.queryParams.segment6Name === null) {
                        $scope.queryParams.segment6Name = '';
                    }
                    if ($scope.queryParams.description === null) {
                        $scope.queryParams.description = '';
                    }
                    if ($scope.queryParams.invoiceType === null) {
                        $scope.InvoiceType.selected = undefined;
                    }
                });
            }

            loadJournalEntryDataFromDB(1);
            if ($scope.criteriaList.length > 6) {
                $scope.criteriaListFirstRow = $scope.criteriaList.slice(0, 6);
                $scope.criteriaListSecondRow = $scope.criteriaList.slice(6, $scope.criteriaList.length);
            }
            else {
                $scope.criteriaListFirstRow = $scope.criteriaList.slice(0, $scope.criteriaList.length);
            }
            $('.filter-button').popover("hide");
        };

        //去掉所有的查询条件,重新load数据
        var doDataFilterReset = function () {
            $scope.queryParams = {
                pageInfo: {},
                periodStart: '',
                periodEnd: '',
                segment3: null,
                segment3Name: null,
                segment5: null,
                segment5Name: null,
                segment6: null,
                segment6Name: null,
                description: null,
                containsAdjustmentRecord: null
            };
            $scope.queryParams.periodStart = $scope.startMonth;
            $scope.queryParams.periodEnd = $scope.endMonth;
            loadJournalEntryDataFromDB(1);
            $('.filter-button').popover("hide");
        };

        var prepareSummary = function () {
            // do something before show popover
        };

        //在popover打开时执行事件
        var showPopover = function () {
            $timeout(function () {
                initDatePickers();
            }, 500);
        };

        //初始化时间控件
        var initDatePickers = function () {
            //认证开始时间
            var ele1 = $("#certificationDateStart");
            ele1.datepicker({
                startDate: $scope.startDate,
                endDate: $scope.endDate,
                language: region,
                autoclose: true,//选中之后自动隐藏日期选择框
                clearBtn: true,//清除按钮
                todayBtn: false,//今日按钮
                format: $scope.dateFormat//日期格式,详见 http://bootstrap-datepicker.readthedocs.org/en/release/options.html#format
            });
            ele1.datepicker("setDate", $scope.queryParams.certificationDateStart);
            //认证结束时间
            var ele2 = $("#certificationDateEnd");
            ele2.datepicker({
                startDate: $scope.startDate,
                endDate: $scope.endDate,
                language: region,
                autoclose: true,//选中之后自动隐藏日期选择框
                clearBtn: true,//清除按钮
                todayBtn: false,//今日按钮
                format: $scope.dateFormat//日期格式,详见 http://bootstrap-datepicker.readthedocs.org/en/release/options.html#format
            })
            ele2.datepicker("setDate", $scope.queryParams.certificationDateEnd);
        };

        //导出进项发票数据
        var downloadJE = function () {
            vatPreviewService.initExportJEData($scope.queryParams).success(function (data, status, headers) {
                if(status===204){
                    SweetAlert.warning("没有数据可以下载");
                    return;
                }
                vatExportService.exportToExcel(data, status, headers, '日记账信息.xls');
            }).error(function () {
                SweetAlert.error($translate.instant('PleaseContactAdministrator'));
            });
        };


        (function initialize() {
            $log.debug('VatPreviewInputInvoiceController.ctor()...');
            $('#input-invoice-period-picker').focus(function () {
                $('.filter-button').popover("hide");
            });
            //初始化month-picker
            $('#input-invoice-period-picker').rangePicker({
                minDate: minDate,
                maxDate: maxDate,
                setDate: setDate,
                months: $scope.monthList,//['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
                ConfirmBtnText: $translate.instant('Confirm'),
                CancelBtnText: $translate.instant('ButtonCancel')
            })
             .on('datePicker.done', function (e, result) {
                 //开始月份
                 var startMonth = result[0][1] * 100 + result[0][0];
                 //结束月份
                 var endMonth = result[1][1] * 100 + result[1][0];
                 $scope.startMonth = startMonth;
                 $scope.endMonth = endMonth;

                 $scope.queryParams.periodStart = startMonth;
                 $scope.queryParams.periodEnd = endMonth;
                 loadJournalEntryDataFromDB(1);
             });

            
            $scope.gridOptions = {
                rowHeight: constant.UIGrid.rowHeight,
                selectionRowHeaderWidth: constant.UIGrid.rowHeight,
                // expandableRowTemplate: '<div ui-grid="row.entity.subGridOptions" style="height:150px;"></div>',
                virtualizationThreshold: 50,//默认加载50条数据,避免在数据展示时,只显示前面4条
                enableSorting: false,
                enableColumnMenus: false,
                enableHorizontalScrollbar : 1,
                columnDefs: [
                 { name: $translate.instant('ApprovalStatus'), width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.approvalStatus}}<span></div>' },
                 // { name: $translate.instant('InvoiceQJ'), width: '8%', cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.periodID}}<span></div>' },
                 { name: $translate.instant('Posting'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.postedStatus}}<span></div>' },
                 { name: $translate.instant('AccountingPeriod'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span title="{{row.entity.fpdm}}">{{row.entity.period}}</span></div>' },
                 { name: $translate.instant('DocumentDate'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span title="{{row.entity.fphm}}">{{row.entity.accountingDate}}</span></div>' },
                 { name: $translate.instant('JournalSource'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span title="{{row.entity.xfsh}}">{{row.entity.journalSource}}</span></div>' },
                 { name: $translate.instant('JournalCategory'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span title="{{row.entity.fplx}}">{{row.entity.category}}</span></div>' },
                 { name: $translate.instant('JournalName'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents right"><span style="float:right">{{row.entity.name}}</span></div>' },
                 { name: $translate.instant('DocumentNo'),  width: 200,cellTemplate: '<div class="ui-grid-cell-contents right"><span style="float:right">{{row.entity.voucherNum}}</span></div>' },
                 { name: $translate.instant('Summary'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.description}}</span></div>' },
                 { name: $translate.instant('MainBodyDescription'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.segment1Name}}</span></div>' },
                 { name: $translate.instant('CostCenterDescription'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.segment2Name}}</span></div>' },
                 { name: $translate.instant('SubjectDescription'),width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.segment3Name}}</span></div>' },
                 { name: $translate.instant('AuxiliaryAccountDescription'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.segment4Name}}</span></div>' },
                 { name: $translate.instant('ProfitCenterDescription'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.segment5Name}}</span></div>' },
                 { name: $translate.instant('ProductManual'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.segment6Name}}</span></div>' },
                 { name: $translate.instant('ProjectInstruction'), width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.segment7Name}}</span></div>' },
                 { name: $translate.instant('InterCompanyDescription'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.segment8Name}}</span></div>' },
                 { name: $translate.instant('Alternate1Description'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.segment9Name}}</span></div>' },
                 { name: $translate.instant('Alternate2Description'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.segment10Name}}</span></div>' },
                 { name: $translate.instant('Currency'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.journal_currencyCode}}</span></div>' },
                 { name: $translate.instant('LocalCurrency'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.sob_currencyCode}}</span></div>' },
                 { name: $translate.instant('JournalDebitAmount'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.accountedDr}}</span></div>' },
                 { name: $translate.instant('JournalCreditAmount'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.accountedCr}}</span></div>' },
                 { name: $translate.instant('Amount'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span></span></div>' },
                 { name: $translate.instant('LocalCurrencyDebitAmount'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.enteredDr}}</span></div>' },
                 { name: $translate.instant('LocalCurrencyCreditAmount'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.enteredCr}}</span></div>' },
                 { name: $translate.instant('CashFlowEntry'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.cfItem}}</span></div>' },
                 { name: $translate.instant('City'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute1}}</span></div>' },
                 { name: $translate.instant('TransactionDate'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute2}}</span></div>' },
                 { name: $translate.instant('BankAccountNumber'), width: 200,cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute3}}</span></div>' },
                 { name: $translate.instant('BankSerialNumber'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute4}}</span></div>' },
                 { name: $translate.instant('SupplierCode'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute5}}</span></div>' },
                 { name: $translate.instant('TransactionOrderNumber'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute6}}</span></div>' },
                 { name: $translate.instant('SupplierName'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute7}}</span></div>' },
                 { name: $translate.instant('ReceiveCode'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute8}}</span></div>' },
                 { name: $translate.instant('PreparedBy'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute9}}</span></div>' },
                 { name: $translate.instant('Reviewer'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute10}}</span></div>' },
                 { name: $translate.instant('CostCenterDepartmentDescription1'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute11}}</span></div>' },
                 { name: $translate.instant('CostCenterDepartmentDescription2'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute12}}</span></div>' },
                 { name: $translate.instant('CostCenterDepartmentDescription3'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute13}}</span></div>' },
                 { name: $translate.instant('CostCenterDepartmentDescription4'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute14}}</span></div>' },
                 { name: $translate.instant('CostCenterDepartmentDescription5'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute15}}</span></div>' },
                 { name: $translate.instant('CostCenterDepartmentDescription6'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.attribute16}}</span></div>' },
                 { name: $translate.instant('GroupCertificateNumber'),width: 200, cellTemplate: '<div class="ui-grid-cell-contents"><span></span></div>' }
                ]
            };

            $scope.doDataFilter = doDataFilter;
            $scope.doDataFilterReset = doDataFilterReset;
            $scope.prepareSummary = prepareSummary;
            $scope.showPopover = showPopover;
            $scope.downloadJE = downloadJE;

            initPeriods();
            initJournalEntryPagination();
            //初始化查询条件-期间范围
            $scope.queryParams.periodStart = vatSessionService.year * 100 + vatSessionService.month;
            $scope.queryParams.periodEnd = vatSessionService.year * 100 + vatSessionService.month;
            $scope.queryParams.orgId = vatSessionService.project.organizationID;
            loadJournalEntryDataFromDB(1);

        })();
    }
]);