vat-preview-output-invoice.ctrl.js 29.5 KB
Newer Older
Memorydoc's avatar
#  
Memorydoc 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 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 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
citModule.controller('citPreviewOutputInvoiceController', ['$scope', '$log', '$translate', '$timeout', 'SweetAlert', '$q', 'uiGridConstants', '$interval',
    'vatPreviewService', 'vatSessionService', 'citSessionService', 'browserService', 'enums', 'region', 'vatExportService',
    function ($scope, $log, $translate, $timeout, SweetAlert, $q, uiGridConstants, $interval, vatPreviewService, vatSessionService, citSessionService,
        browserService, enums, region, 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.curPageItemCount = 0;
        var startMonth = new Date().getMonth();
        var endMonth = new Date().getMonth();
        var minDate = [1, vatSessionService.project.year];
        var maxDate = [12, vatSessionService.project.year];
        var setDate = [
            [citSessionService.month, vatSessionService.project.year],
            [citSessionService.month, vatSessionService.project.year]];
        //发票类型
        var invoiceTypeEnum = {
            Normal: $translate.instant('Normal'),
            Special: $translate.instant('Special')
        };
        //区间
        $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')
        ];
        //发票类型
        $scope.invoiceTypeList = [
            { id: 999, name: $translate.instant('AllTheItems') },
            { id: enums.outputInvoiceType.Normal, name: $translate.instant('Normal') },
            { id: enums.outputInvoiceType.Special, name: $translate.instant('Special') },
        ];

        $scope.PeriodStart = {};
        $scope.PeriodEnd = {};
        $scope.InvoiceType = {};

        //初始化期间
        var initPeriods = function () { 
            $scope.queryParams = {
                pageInfo: {},
                periodStart: '',
                periodEnd: '',
                invoiceDateStart: null,
                invoiceDateEnd: null,
                classCode: '',
                invoiceNumber: '',
                buyerName: '',
                productName:'',
                amountStart: null,
                amountEnd: null,
                invoiceType: null,
                taxAmountStart: null,
                taxAmountEnd: null
            };
            $scope.queryParams.periodStart = citSessionService.month;
            $scope.queryParams.periodEnd = citSessionService.month;
        };

        //从数据库中load数据
        var loadOutputInvoiceDataFromDB = function (pageIndex) {
            initOutputInvoicePagination();

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

            vatPreviewService.queryOutputInvoiceList($scope.queryParams).success(function (data) {
                if (data) {
                    var index = 1;
                    data.list.forEach(function (v) {
                        v.index = index++;
                        v.amount = PWC.round(v.amount, 2);
                        v.taxAmount = PWC.round(v.taxAmount, 2);
                    });
                    $scope.gridOptions.data = data.list;
                    $scope.queryOutputInvoiceResult.pageInfo = data.pageInfo;
                    computeOutputInvoiceItemPage();
                }
            }).error(function () {
                SweetAlert.error($translate.instant('PleaseContactAdministrator'));
            });
        }

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

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

            if ($scope.queryOutputInvoiceResult.pageInfo && $scope.queryOutputInvoiceResult.pageInfo.totalCount > 0) {

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

                if ($scope.queryOutputInvoiceResult.pageInfo.pageIndex === totalPage) {
                    $scope.curPageItemCount = $scope.queryOutputInvoiceResult.pageInfo.totalCount % $scope.queryOutputInvoiceResult.pageInfo.pageSize;
                }
                else {
                    $scope.curPageItemCount = $scope.queryOutputInvoiceResult.pageInfo.pageSize;
                }

                $scope.queryOutputInvoiceResult.pageInfo.totalPage = totalPage;

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

                $('#totalInvoicePage').css('display', 'inline-block');
            } else {
                var createPage = $("#totalInvoicePage").createPage({
                    pageCount: 0,
                    current: $scope.curOutputInvoiceItemPage,
                    backFn: function (p) {
                        //单击回调方法,p是当前页码
                        loadOutputInvoiceDataByPage(p);
                    }
                });

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

        //初始化分页信息
        var initOutputInvoicePagination = function () {
            $scope.queryOutputInvoiceResult = {
                list: [],
                pageInfo: {
                    totalCount: 0,
                    pageIndex: 1,
                    pageSize: 100,
                    totalPage: 0,
                }
            }
            $scope.curOutputInvoiceItemPage = 1;
        };

        //发票类型转换
        $scope.typeToString = function (strType) {
            var type = invoiceTypeEnum.Normal;
            switch (strType) {
                case 0:
                    type = invoiceTypeEnum.Normal;
                    break;
                case 1:
                    type = invoiceTypeEnum.Special;
                    break; 
                default:
                    type = "";
            }
            return type;
        }

        //将选择了的查询条件显示在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.invoiceType === null) {
                        $scope.InvoiceType.selected = undefined;
                    } 
                });
            }

            //设置发票类型和认证结果
            if ($scope.InvoiceType.selected !== undefined)
                $scope.queryParams.invoiceType = $scope.InvoiceType.selected.id;
            else
                $scope.queryParams.invoiceType = null; 

            // 将查询条件加入到grid上方
            var crits = $scope.queryParams;
            //定义查询条件数组用于存放已选的查询条件
            $scope.criteriaList = [];

            var crit = [];

            //日期
            if (!PWC.isNullOrEmpty(crits.invoiceDateStart) && !PWC.isNullOrEmpty(crits.invoiceDateEnd)) {
                if (new Date(crits.invoiceDateStart.replace(/[\.-]/g, '/')) > new Date(crits.invoiceDateEnd.replace(/[\.-]/g, '/'))) {
                    $scope.criteriaList = [];
                    SweetAlert.warning($translate.instant('InvoiceDateQueryError'));
                    return;
                }
                crit = new Object;
                crit.name = $translate.instant('InvoiceDate')+":" + crits.invoiceDateStart + "-" + crits.invoiceDateEnd;
                crit.valueFrom = crits.invoiceDateStart;
                crit.valueTo = crits.invoiceDateEnd;
                crit.propertyName = "invoiceDateStart|invoiceDateEnd";

                $scope.criteriaList.push(crit);
            }
            else if (!PWC.isNullOrEmpty(crits.invoiceDateStart) && PWC.isNullOrEmpty(crits.invoiceDateEnd)) {
                crit = new Object;
                crit.name = $translate.instant('InvoiceDate') + ":" + crits.invoiceDateStart + $translate.instant('After');
                crit.valueFrom = crits.invoiceDateStart;
                crit.valueTo = crits.invoiceDateEnd;
                crit.propertyName = "invoiceDateStart|invoiceDateEnd";

                $scope.criteriaList.push(crit);
            }
            else if (PWC.isNullOrEmpty(crits.invoiceDateStart) && !PWC.isNullOrEmpty(crits.invoiceDateEnd)) {
                crit = new Object;
                crit.name = $translate.instant('InvoiceDate') + ":" + crits.invoiceDateEnd + $translate.instant('Before');
                crit.valueFrom = crits.invoiceDateStart;
                crit.valueTo = crits.invoiceDateEnd;
                crit.propertyName = "invoiceDateStart|invoiceDateEnd";
                $scope.criteriaList.push(crit);
            }

            //发票代码
            if (!PWC.isNullOrEmpty(crits.classCode)) {
                crit = new Object;
                crit.name = $translate.instant('ClassCode') + ":" + PWC.limitString(crits.classCode, 10);
                crit.valueFrom = crits.classCode;
                crit.propertyName = "classCode";

                $scope.criteriaList.push(crit);
            }

            //发票号码
            if (!PWC.isNullOrEmpty(crits.invoiceNumber)) {
                crit = new Object;
                crit.name = $translate.instant('InvoiceNumber') + ":" + PWC.limitString(crits.invoiceNumber, 10);
                crit.valueFrom = crits.invoiceNumber;
                crit.propertyName = "invoiceNumber";

                $scope.criteriaList.push(crit);
            }

            //购方名称
            if (!PWC.isNullOrEmpty(crits.buyerName)) {
                crit = new Object;
                crit.name = $translate.instant('BuyerName') + ":" + PWC.limitString(crits.buyerName, 10);
                crit.valueFrom = crits.buyerName;
                crit.propertyName = "buyerName";

                $scope.criteriaList.push(crit);
            }

            //产品名称
            if (!PWC.isNullOrEmpty(crits.productName)) {
                crit = new Object;
                crit.name = $translate.instant('ProductName') + ":" + PWC.limitString(crits.productName, 10);
                crit.valueFrom = crits.productName;
                crit.propertyName = "productName";

                $scope.criteriaList.push(crit);
            }

            //发票类型
            if (!PWC.isNullOrEmpty(crits.invoiceType)) {
                crit = new Object;
                crit.valueFrom = _.find($scope.invoiceTypeList, function (v) {
                    return v.id === crits.invoiceType;
                }).name;
                crit.name = $translate.instant('InvoiceType') + ":" + crit.valueFrom;
                crit.propertyName = "invoiceType";

                $scope.criteriaList.push(crit);
            }

            //金额
            if (!PWC.isNullOrEmpty(crits.amountStart) && !PWC.isNullOrEmpty(crits.amountEnd)) {
                if (Number(crits.amountStart) > Number(crits.amountEnd)) {
                    $scope.criteriaList = [];
                    SweetAlert.warning($translate.instant('AmountQueryError'));
                    return;
                }
                crit = new Object;
                crit.name = $translate.instant('Amount') + ":" + PWC.limitString(crits.amountStart, 5) + "-" + PWC.limitString(crits.amountEnd, 5);
                crit.valueFrom = crits.amountStart;
                crit.valueTo = crits.amountEnd;
                crit.propertyName = "amountStart|amountEnd";

                $scope.criteriaList.push(crit);
            }
            else if (!PWC.isNullOrEmpty(crits.amountStart) && PWC.isNullOrEmpty(crits.amountEnd)) {
                crit = new Object;
                crit.name = $translate.instant('Amount') + ":" + PWC.limitString(crits.amountStart, 5) + $translate.instant('MoreThan');
                crit.valueFrom = crits.amountStart;
                crit.valueTo = crits.amountEnd;
                crit.propertyName = "amountStart|amountEnd";

                $scope.criteriaList.push(crit);
            }
            else if (PWC.isNullOrEmpty(crits.amountStart) && !PWC.isNullOrEmpty(crits.amountEnd)) {
                crit = new Object;
                crit.name = $translate.instant('Amount') + ":" + PWC.limitString(crits.amountEnd, 5) + $translate.instant('LessThan');
                crit.valueFrom = crits.amountStart;
                crit.valueTo = crits.amountEnd;
                crit.propertyName = "amountStart|amountEnd";

                $scope.criteriaList.push(crit);
            }

            //税额
            if (!PWC.isNullOrEmpty(crits.taxAmountStart) && !PWC.isNullOrEmpty(crits.taxAmountEnd)) {
                if (Number(crits.taxAmountStart) > Number(crits.taxAmountEnd)) {
                    $scope.criteriaList = [];
                    SweetAlert.warning($translate.instant('TaxAmountQueryError'));
                    return;
                }
                crit = new Object;
                crit.name = $translate.instant('TaxAmount') + ":" + PWC.limitString(crits.taxAmountStart, 5) + "-" + PWC.limitString(crits.taxAmountEnd, 5);
                crit.valueFrom = crits.taxAmountStart;
                crit.valueTo = crits.taxAmountEnd;
                crit.propertyName = "taxAmountStart|taxAmountEnd";

                $scope.criteriaList.push(crit);
            }
            else if (!PWC.isNullOrEmpty(crits.taxAmountStart) && PWC.isNullOrEmpty(crits.taxAmountEnd)) {
                crit = new Object;
                crit.name = $translate.instant('TaxAmount') + ":" + PWC.limitString(crits.taxAmountStart, 5) + $translate.instant('MoreThan');
                crit.valueFrom = crits.taxAmountStart;
                crit.valueTo = crits.taxAmountEnd;
                crit.propertyName = "taxAmountStart|taxAmountEnd";

                $scope.criteriaList.push(crit);
            }
            else if (!PWC.isNullOrEmpty(crits.taxAmountStart) && PWC.isNullOrEmpty(crits.taxAmountEnd)) {
                crit = new Object;
                crit.name = $translate.instant('TaxAmount') + ":" + PWC.limitString(crits.taxAmountEnd, 5) + $translate.instant('LessThan');
                crit.valueFrom = crits.taxAmountStart;
                crit.valueTo = crits.taxAmountEnd;
                crit.propertyName = "taxAmountStart|taxAmountEnd";

                $scope.criteriaList.push(crit);
            }

            // add to Criteria List for display on top of the grid:
            //********************************************************************************
            var criteria = JSON.stringify($scope.queryParams);
            if (browserService.isIE() || browserService.isEdge())
                criteria = encodeURIComponent(criteria);

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

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

        //初始化时间控件
        var initDatePickers = function () {
            //开票开始时间
            var ele1 = $("#invoiceDateStart");
            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.invoiceDateStart);
            //开票结束时间
            var ele2 = $("#invoiceDateEnd");
            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.invoiceDateEnd);


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

        //转换百分比
        $scope.decimalToPercent = function (data) {
            return (data * 100).toFixed(0) + "%";
        }

        //导出
        var doExport = function ()
        { 
            vatPreviewService.getExportOutputInvoiceList($scope.queryParams).success(function (data, status, headers) {
sam.x.wang's avatar
sam.x.wang committed
448
                vatExportService.exportToExcel(data, status, headers, '销项发票信息');
Memorydoc's avatar
#  
Memorydoc committed
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
            }).error(function () {
                SweetAlert.error($translate.instant('PleaseContactAdministrator'));
            });
        }

        //$scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
        //    export_table_to_excel('exportTable', 'OutputInvoice', 'xlsx', '');
        //});
        
        $scope.gridOptionsColumnDefs = [
            {
                name: $translate.instant('ImportErrorPopUpNoCol'), width: '5%',
                cellTemplate: '<div class="ui-grid-cell-contents" ><span>{{row.entity.index}}<span></div>'
            },
              {
                  name: $translate.instant('PeriodId'), width: '5%',
                  cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.periodID}}"><span>{{row.entity.periodID}}<span></div>'
              },
               {
                   name: $translate.instant('InvoiceDate'), width: '10%',
                   cellTemplate: '<div class="ui-grid-cell-contents" ><span>{{row.entity.invoiceDate | date:"yyyy-MM-dd"}}</span></div>'
               },
                 {
                     name: $translate.instant('InvoiceType'), width: '10%',
                     cellTemplate: '<div class="ui-grid-cell-contents" title="{{grid.appScope.typeToString(row.entity.invoiceType)}}"><span>{{grid.appScope.typeToString(row.entity.invoiceType)}}<span></div>'
                 }, 
              {
                  name: $translate.instant('ClassCode'), width: '10%',
                  cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.classCode}}"><span>{{row.entity.classCode}}<span></div>'
              },
              {
                  name: $translate.instant('InvoiceNumber'), width: '10%',
                  cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.invoiceNumber}}"><span>{{row.entity.invoiceNumber}}</span></div>'
              }, 
              {
                  name: $translate.instant('BuyerName'), width: '15%',
                  cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.buyerName}}"><span>{{row.entity.buyerName}}</span></div>'
              },
              {
                  name: $translate.instant('BuyerTaxNumber'), width: '15%',
                  cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.buyerTaxNumber}}"><span>{{row.entity.buyerTaxNumber}}</span></div>'
              },
              //{
              //    name: $translate.instant('BankAccount'), width: '10%',
              //    cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.bankAccount}}"><span>{{row.entity.bankAccount}}</span></div>'
              //},
              //{
              //    name: $translate.instant('PhoneNum'), width: '8%',
              //    cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.phoneNum}}"><span>{{row.entity.phoneNum}}</span></div>'
              //},  
           {
               name: $translate.instant('Amount'), width: '8%', headerCellClass: 'right',
               cellTemplate: '<div class="ui-grid-cell-contents right" title="{{row.entity.amount}}"><span>{{row.entity.amount}}</span></div>'
           },
            {
                name: $translate.instant('TaxAmount'), width: '8%', headerCellClass: 'right',
                cellTemplate: '<div class="ui-grid-cell-contents right"  title="{{row.entity.taxAmount}}"><span>{{row.entity.taxAmount}}</span></div>'
            }
        ];

        $scope.subGridOptionsColumnDefs = [
                {
                    name: $translate.instant('ImportErrorPopUpNoCol'), width: '5%',
                    cellTemplate: '<div class="ui-grid-cell-contents"><span>{{row.entity.seqNo}}</span></div>'
                },
                {
                    name: $translate.instant('ProductName'),  
                    cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.productName}}"><span>{{row.entity.productName}}</span></div>'
                },
                {
                    name: $translate.instant('Quantity'),   headerCellClass: 'right',
                    cellTemplate: '<div class="ui-grid-cell-contents right" title="{{row.entity.quantity}}"><span>{{row.entity.quantity}}</span></div>'
                },
                {
                    name: $translate.instant('UnitPrice'),   headerCellClass: 'right',
                    cellTemplate: '<div class="ui-grid-cell-contents right" title="{{row.entity.unitPrice}}"><span>{{row.entity.unitPrice}}</span></div>'
                },
                {
                    name: $translate.instant('Amount'),   headerCellClass: 'right',
                    cellTemplate: '<div class="ui-grid-cell-contents right" title="{{row.entity.amount}}"><span>{{row.entity.amount}}</span></div>'
                },
                {
                    name: $translate.instant('TaxRate'),  headerCellClass: 'right',
                    cellTemplate: '<div class="ui-grid-cell-contents right" title="{{row.entity.taxRate}}"><span>{{((row.entity.taxRate) * 100).toFixed(0) + "%"}}</span></div>'
                },
                {
                    name: $translate.instant('TaxAmount'),  headerCellClass: 'right',
                    cellTemplate: '<div class="ui-grid-cell-contents right" title="{{row.entity.taxAmount}}"><span>{{row.entity.taxAmount}}</span></div>'
                },
             //{
             //    name: $translate.instant('CodeVersion'), width: '8%',
             //    cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.codeVersion}}"><span>{{row.entity.codeVersion}}</span></div>'
             //},
             //{
             //    name: $translate.instant('DocumentNum'), width: '8%',
             //    cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.documentNum}}"><span>{{row.entity.documentNum}}</span></div>'
             //},
            
             //{
             //    name: $translate.instant('ProductStandar'), width: '8%',
             //    cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.productStandar}}"><span>{{row.entity.productStandar}}</span></div>'
             //},
             //{
             //    name: $translate.instant('Unit'), width: '8%',
             //    cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.unit}}"><span>{{row.entity.unit}}</span></div>'
             //}, 
             //{
             //    name: $translate.instant('TaxClassCode'), width: '15%',
             //    cellTemplate: '<div class="ui-grid-cell-contents" title="{{row.entity.taxClassCode}}"><span>{{row.entity.taxClassCode}}</span></div>'
             //}
        ];

        (function initialize() {
            $log.debug('citPreviewOutputInvoiceController.ctor()...');
            $scope.periodId = citSessionService.month;

            //初始化month-picker
            $('#output-invoice-period-picker').rangePicker({
                minDate: minDate,
                maxDate: maxDate,
                setDate: setDate,
                months: $scope.monthList,
                ConfirmBtnText: $translate.instant('Confirm'),
                CancelBtnText: $translate.instant('ButtonCancel')
            })
             .on('datePicker.done', function (e, result) {
                 //开始月份
                 startMonth = result[0][0];
                 //结束月份
                 endMonth = result[1][0];
                 $scope.queryParams.periodStart = startMonth; 
                 $scope.queryParams.periodEnd = endMonth;

                 loadOutputInvoiceDataFromDB(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,
                columnDefs: $scope.gridOptionsColumnDefs,

                onRegisterApi: function (gridApi) {
                    $scope.gridApi = gridApi;

                    //定义子table属性
                    gridApi.expandable.on.rowExpandedStateChanged($scope, function (row) {
                        if (row.isExpanded) {
                            row.entity.subGridOptions = {
                                rowHeight: constant.UIGrid.rowHeight,
                                selectionRowHeaderWidth: constant.UIGrid.rowHeight,
                                virtualizationThreshold: 50,//默认加载50条数据,避免在数据展示时,只显示前面4条
                                enableSorting: false,
                                enableColumnMenus: false,
                                columnDefs: $scope.subGridOptionsColumnDefs,
Ken you's avatar
Ken you committed
607 608
                            };
                            //获取子table数据
Memorydoc's avatar
#  
Memorydoc committed
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
                            vatPreviewService.queryOutputInvoiceItemList(row.entity.invoiceID).success(function (data) {
                                if (data) {
                                    data.forEach(function (v) {                                        
                                        v.unitPrice = PWC.round(v.unitPrice, 2);
                                        v.amount = PWC.round(v.amount, 2);
                                        v.taxRate = PWC.round(v.taxRate, 2);
                                        v.taxAmount = PWC.round(v.taxAmount, 2);
                                    });
                                    row.entity.subGridOptions.data = data;
                                }
                            });
                        }
                    });

                    $interval(function () {
                        $scope.gridApi.core.handleWindowResize();
                    }, 500, 60 * 60 * 8);
                }
            }; 
            $scope.doDataFilter = doDataFilter;
            $scope.doDataFilterReset = doDataFilterReset;
            $scope.doExport = doExport; 
            $scope.showPopover = showPopover;
            initPeriods();
            initOutputInvoicePagination();
            loadOutputInvoiceDataFromDB(1);
        })();
    }
Ken you's avatar
Ken you committed
637
]);