vat-preview-invoice-data.ctrl.js 16.1 KB
Newer Older
gary's avatar
gary committed
1 2
vatModule.controller('VatPreviewInvoiceDataController', ['$rootScope','$scope', '$log','$filter', '$translate', '$timeout', 'SweetAlert', '$q', 'uiGridConstants', '$interval', 'vatPreviewService', 'browserService', 'vatSessionService', 'region', 'enums', 'vatExportService',
    function ($rootScope,$scope, $log,$filter, $translate, $timeout, SweetAlert, $q, uiGridConstants, $interval, vatPreviewService, browserService, vatSessionService, region, enums, vatExportService) {
gary's avatar
gary committed
3 4 5 6 7 8 9 10 11
        '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;
gary's avatar
gary committed
12
        $scope.pageSize = constant.vatPagesize;
gary's avatar
gary committed
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

        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: '',
                certificationDateStart: null,
                certificationDateEnd: null,
                invoiceCode: '',
                invoiceNumber: '',
                sellerTaxNumber: '',
                amountStart: null,
                amountEnd: null,
                invoiceType: null,
                taxAmountStart: null,
                taxAmountEnd: null,
                certificationStatus: null
            };
        };

        /*var countTotal = function(){
            $scope.queryParams.pageInfo = {
                totalCount: -1,
                pageIndex: 1,
                pageSize: -1,
                totalPage: 0,
            };
            vatPreviewService.queryInputInvoiceAllList($scope.queryParams).success(function (data) {
                if (data) {
                    var totalMoneyAmount = 0;
                    var totalTaxAmount = 0;
                    _.each(data, function (x) {
                        totalMoneyAmount = totalMoneyAmount + parseFloat(x.hjje.replace(/,/g, ""));
                        totalTaxAmount = totalTaxAmount + parseFloat(x.hjse.replace(/,/g, ""));
                    })
                    $scope.totalMoneyAmount = totalMoneyAmount.toLocaleString();
                    $scope.totalTaxAmount = totalTaxAmount.toLocaleString();
                }
            });
        };*/

        //从数据库中load数据
        var loadInvoiceDataItemDataFromDB = function (pageIndex) {
            initInvoiceDataItemPagination();

            $scope.curInvoiceDataItemPage = pageIndex;

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

        $scope.getDataFromDatabase = function (queryParams){
            vatPreviewService.getIDDataForDisplay(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.queryInvoiceDataResult.pageInfo = data;
                    computeInvoiceDataItemPage();
                    /*$scope.ledgerName = data.list[0].ledgerName;
                    $scope.currencyCode = data.list[0].ledgerCurrencyCode;
                    $scope.status = data.list[0].status;
                    $scope.importDate = $filter('date')(data.list[0].date, "yyyy-MM-dd hh:mm:ss");*/
                }
            });
        };

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

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

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

gary's avatar
gary committed
125 126
                var totalPage = parseInt($scope.queryInvoiceDataResult.pageInfo.total / $scope.pageSize);
                totalPage = $scope.queryInvoiceDataResult.pageInfo.totalCount % $scope.pageSize == 0 ? totalPage : totalPage + 1;
gary's avatar
gary committed
127 128 129

                //计算本页记录数
                if ($scope.queryInvoiceDataResult.pageInfo.pageNum === totalPage) {
gary's avatar
gary committed
130
                    $scope.curPageItemCount = $scope.queryInvoiceDataResult.pageInfo.total % $scope.pageSize;
gary's avatar
gary committed
131 132
                }
                else {
gary's avatar
gary committed
133
                    $scope.curPageItemCount = $scope.pageSize;
gary's avatar
gary committed
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
                }

                $scope.queryInvoiceDataResult.pageInfo.totalPage = totalPage;

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

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

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

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

            $scope.curInvoiceDataItemPage = 1;
        };

        //去掉所有的查询条件,重新load数据
        var doDataFilterReset = function () {
            $scope.queryParams = {
                pageInfo: {},
                periodStart: '',
                periodEnd: '',
                certificationDateStart: null,
                certificationDateEnd: null,
                invoiceCode: '',
                invoiceNumber: '',
                sellerTaxNumber: '',
                amountStart: null,
                amountEnd: null,
                invoiceType: null,
                taxAmountStart: null,
                taxAmountEnd: null,
                certificationStatus: null
            };
            $scope.criteriaList = [];
            $scope.queryParams.periodStart = $scope.startMonth;
            $scope.queryParams.periodEnd = $scope.endMonth;
            // countTotal();
            loadInvoiceDataItemDataFromDB(1);
            $('.filter-button').popover("hide");
        };

        //在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);


            //初始化已选择的发票类型和认证结果
            $scope.InvoiceType.selected = _.find($scope.invoiceTypeList, function (v) {
                return v.id == $scope.queryParams.invoiceType;
            })

            $scope.CertificationStatus.selected = _.find($scope.cetificationResultList, function (v) {
                return v.id == $scope.queryParams.certificationStatus;
            })
        };

        (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][0];
                 //结束月份
                 var endMonth = result[1][0];
                 $scope.startMonth = startMonth;
                 $scope.endMonth = endMonth;

                 $scope.queryParams.periodStart = startMonth;
                 $scope.queryParams.periodEnd = endMonth;
                 $scope.queryParams.orgId = vatSessionService.project.organizationID;
                 // countTotal();
                 loadInvoiceDataItemDataFromDB(1);
             });

            var downloadID = function () {
gary's avatar
gary committed
280 281 282
                var localDate=$filter('date')(new  Date(), 'yyyyMMddHHmmss');
                var fileName= constant.exportExcelFileName.invoiceData + localDate;
                vatPreviewService.initExportIDData($scope.queryParams,fileName).then(function (data) {
gary's avatar
gary committed
283 284 285 286 287 288 289 290 291 292 293 294
                });
            };

            $scope.gridOptions = {
                rowHeight: constant.UIGrid.rowHeight,
                selectionRowHeaderWidth: constant.UIGrid.rowHeight,
                virtualizationThreshold: 50,//默认加载50条数据,避免在数据展示时,只显示前面4条
                enableSorting: false,
                enableColumnMenus: false,
                columnDefs: [
                 { name: $translate.instant('ProjectName'),  cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.projectName}}<span></div>' },
                 // { name: $translate.instant('InvoiceQJ'), width: '8%', cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.periodID}}<span></div>' },
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
                 {
                     name: $translate.instant('IDTotalAmount'),
                     headerCellClass:'rightHeader',
                     cellTemplate: '<div class="ui-grid-cell-contents" style="text-align: right"><span>{{row.entity.totalAmount | number:2}}<span></div>' },
                 {
                     name: $translate.instant('Amount1'),
                     headerCellClass:'rightHeader',
                     cellTemplate: '<div class="ui-grid-cell-contents" style="text-align: right"><span>{{row.entity.amount1 | number:2}}</span></div>' },
                 {
                     name: $translate.instant('Amount2'),
                     headerCellClass:'rightHeader',
                     cellTemplate: '<div class="ui-grid-cell-contents" style="text-align: right"><span>{{row.entity.amount2 | number:2}}</span></div>' },
                 {
                     name: $translate.instant('Amount3'),
                     headerCellClass:'rightHeader',
                     cellTemplate: '<div class="ui-grid-cell-contents" style="text-align: right"><span>{{row.entity.amount3 | number:2}}</span></div>' },
                 {
                     name: $translate.instant('Amount4'),
                     headerCellClass:'rightHeader',
                     cellTemplate: '<div class="ui-grid-cell-contents" style="text-align: right"><span>{{row.entity.amount4 | number:2}}</span></div>' },
                 {
                     name: $translate.instant('Amount5'),
                     headerCellClass:'rightHeader',
                     cellTemplate: '<div class="ui-grid-cell-contents " style="text-align: right"><span>{{row.entity.amount5 | number:2}}</span></div>' },
                 {
                     name: $translate.instant('Amount6'),
                     headerCellClass:'rightHeader',
                     cellTemplate: '<div class="ui-grid-cell-contents " style="text-align: right"><span>{{row.entity.amount6 | number:2}}</span></div>' },
                 {
                     name: $translate.instant('Amount7'),
                     headerCellClass:'rightHeader',
                     cellTemplate: '<div class="ui-grid-cell-contents" style="text-align: right"><span>{{row.entity.amount7 | number:2}}</span></div>' },
                 {
                     name: $translate.instant('OtherAmount'),
                     headerCellClass:'rightHeader',
                     cellTemplate: '<div class="ui-grid-cell-contents" style="text-align: right"><span>{{row.entity.otherAmount | number:2}}</span></div>' }
gary's avatar
gary committed
331 332 333 334 335 336 337 338 339 340 341 342 343
                 ]
            };

            $scope.doDataFilterReset = doDataFilterReset;
            $scope.showPopover = showPopover;
            $scope.downloadID = downloadID;

            initPeriods();
            initInvoiceDataItemPagination();
            //初始化查询条件-期间范围
            $scope.queryParams.periodStart = vatSessionService.year * 100 + vatSessionService.month;
            $scope.queryParams.periodEnd = vatSessionService.year * 100 + vatSessionService.month;
            $scope.queryParams.orgId = vatSessionService.project.organizationID;
gary's avatar
gary committed
344
            if($rootScope.currentLanguage === 'en-us'){
gary's avatar
gary committed
345 346
                $('.periodInput')[0].style.left = "250px";
            }else{
gary's avatar
gary committed
347
                $('.periodInput')[0].style.left = "130px";
gary's avatar
gary committed
348 349 350 351 352 353 354 355 356 357
            }
            loadInvoiceDataItemDataFromDB(1);

        })();
    }
]);