issued-invoice-bd-view.ctrl.js 29.5 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 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 448 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 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
invoiceModule.controller('issuedInvoiceBdViewController', ['$scope', '$log', '$document', '$uibModal', 'SweetAlert', '$translate',
    '$q', 'apiInterceptor', '$interval', 'region', '$timeout', '$location', 'vatOutputInvoiceManageService', 'enums', '$state',
    'loginContext', 'modalAdapterService', 'Upload',
    function ($scope, $log, $document, $uibModal, SweetAlert, $translate, $q, apiInterceptor, $interval, region, $timeout,
        $location, vatOutputInvoiceManageService, enums, $state, loginContext, modalAdapterService, Upload) {
        'use strict';

        //-----------------搜索对象定义-----------------//start
        var isShowClearButton = true;
        $scope.searchOptions = {};
        $scope.searchEntity = {};

        var gdStatusList = _.chain(enums.GDBDStatusEnum)
            .invert().pairs().map(function (x) {
                return [x[0], $translate.instant(x[1])];
            }).value();

        $scope.searchOptions.InvoiceNo = {
            width: "100%",
            placeholder: $translate.instant('InputPlaceholder'),
            showClearButton: isShowClearButton,
            bindingOptions: {
                value: 'searchEntity.invoiceNo',
            }
        };

        $scope.searchOptions.VIN = {
            width: "100%",
            placeholder: $translate.instant('InputPlaceholder'),
            showClearButton: isShowClearButton,
            bindingOptions: {
                value: 'searchEntity.VIN',
            }
        };

        $scope.searchOptions.IssuedPeriodStart = {
            type: 'date',
            width: "100%",
            placeholder: $translate.instant("ChoosePlaceholder"),
            showClearButton: isShowClearButton,
            bindingOptions: {
                value: 'searchEntity.startTime',
            },
            displayFormat: 'yyyy-MM-dd',
        };

        $scope.searchOptions.IssuedPeriodEnd = {
            type: 'date',
            width: '100%',
            placeholder: $translate.instant("ChoosePlaceholder"),
            showClearButton: isShowClearButton,
            bindingOptions: {
                value: 'searchEntity.endTime',
            },
            displayFormat: 'yyyy-MM-dd',
        };

        //$scope.searchOptions.VehicleModel = {
        //    width: "100%",
        //    placeholder: $translate.instant('InputPlaceholder'),
        //    showClearButton: isShowClearButton,
        //    bindingOptions: {
        //        value: 'searchEntity.vehicleModel'
        //    }
        //};

        $scope.searchOptions.gdStatus = {
            dataSource: gdStatusList,
            displayExpr: '1',
            valueExpr: '0',
            multiline: false,
            width: "100%",
            placeholder: $translate.instant("ChoosePlaceholder"),
            showDropButton: true,
            showClearButton: isShowClearButton,
            bindingOptions: {
                value: 'searchEntity.gdStatus'
            }
        },

        $scope.searchOptions.IssuanceType = {
            width: "100%",
            valueExpr: 'id',
            displayExpr: 'name',
            placeholder: $translate.instant("ChoosePlaceholder"),
            showClearButton: isShowClearButton,
            items: [{ name: '' }, { id: 1, name: 'Salesforce' }, { id: 2, name: 'Smart Tax' }, { id: 3, name: 'Local' }],
            bindingOptions: {
                value: 'searchEntity.issuanceType',
            }
        };

        $scope.toggleSearchContent = function () {
            if ($("#toggle-search-tr").css("display") == "none") {
                $(".hide-search-btn").addClass("fa-angle-up").html('  Collapse');
                $(".hide-search-btn").removeClass("fa-angle-down");
            } else {
                $(".hide-search-btn").addClass("fa-angle-down").html('  Expand');
                $(".hide-search-btn").removeClass("fa-angle-up");
            }
            $("#toggle-search-tr").toggle(200);
            $timeout(function () {
                $scope.setInvoiceGridHeight();
            }, 300);
        };
        //-----------------搜索对象定义-----------------//end

        //-----------------表格对象定义-----------------//start
        $scope.selectedIssuedInvoiceCount = 0;
        $scope.selectedIssuedInvoiceData = [];
        $scope.selectedIssuedInvoiceAmount = '0.00';

        $scope.dataGridOption = {
            keyExpr: 'id',
            showRowLines: true,
            showColumnLines: true,
            showBorders: true,
            allowColumnResizing: true,
            columnAutoWidth: true,
           // hoverStateEnabled: true,
            //rowAlternationEnabled: true,
           // allowColumnReordering: true,
            columnFixing: {
                enabled: true
            },
            paging: {
                enabled: false
            },
            columnChooser: {
                enabled: true
            },
            selection: {
                mode: 'multiple',
                showCheckBoxesMode: 'always'
            },
            bindingOptions: {
                dataSource: 'invoiceGridDataSource',
                height: 'dataGridHeight'
            },
            onSelectionChanged: function (e) {
                if (e && e.selectedRowsData) {
                    $scope.selectedIssuedInvoiceCount = e.selectedRowsData.length;
                    $scope.selectedIssuedInvoiceData = e.selectedRowsData;
                    var amount = 0;
                    _.each(e.selectedRowsData, function (item) {
                        if (item.subtotalforFinalPayment) {
                            amount += item.subtotalforFinalPayment;
                        }
                    });
                    $scope.selectedIssuedInvoiceAmount = amount.formatAmount(2);
                }
            }
        };

        $scope.dataGridOption.columns = [
            { dataField: 'invoiceNo', caption: $translate.instant('InvoiceNo'),fixed:true },
            { dataField: 'invoiceCode', caption: $translate.instant('InvoiceCode'), fixed: true },
            { dataField: 'vin', caption: $translate.instant('VIN') },
            { dataField: 'caseNumber', caption: $translate.instant('InvoiceCaseNum') },
            { dataField: 'vehicleModel', caption: $translate.instant('ModelSeriesG') },
            { dataField: 'cabinConfiguration', caption: $translate.instant('CabinConfig') },
            { dataField: 'registrationLocalName', caption: $translate.instant('RegistrationLocalName') },
            { dataField: 'issuedDate', caption: $translate.instant('IssuedDate')},
            {
                dataField: 'subtotalforFinalPayment', caption: $translate.instant('SubtotalForFinalPayment'),
                format: { type: 'fixedPoint', precision: 2 }
            },
            { dataField: 'issuranceType', caption: $translate.instant('IssuranceType') },
            { dataField: 'bdStatus', caption: $translate.instant('BDStatus')},
            {
                dataField: 'gdBdStatus', caption: $translate.instant('GDBDStatus'),
                cellTemplate: function (ele, info) {
                    if (info && info.value) {
                        if (info.value === 'Issued') {
                            $('<span>')
                                .html(info.value + '&nbsp;&nbsp;<i style="color: #b22;font-size: 22px; vertical-align: middle; cursor: pointer;" class="fa fa-arrow-circle-o-left"></i>')
                                .appendTo(ele)
                                .on('dxclick', function (e) {
                                    //执行红冲GD-BD发票操作
                                    if (e.target.localName === 'i') {
                                        $scope.redLetterGdBdInvoice(info.data);
                                    }
                                });
                        } else {
                            $('<span>').text(info.value).appendTo(ele);
                        }
                    }
                }
            },
            {
                caption: $translate.instant('Action'), alignment: 'left', cellTemplate: function (ele, info) {
                    $('<a/>').css({ 'color': '#6699cc', 'cursor': 'pointer' }).text($translate.instant('View')).on('dxclick', function () {
                        $scope.invoiceOperateType = constant.Operation.Query;
                        $scope.invoiceModel = info.data;
                    }).appendTo(ele);

                    var checkDateStart = new Date().dateAdd('d', -1 * (new Date().getDate() + 180)).dateTimeToString('yyyyMMdd');
                    var checkDateEnd = new Date().dateAdd('d', -1 * new Date().getDate()).dateTimeToString('yyyyMMdd');

                    if (info.data.bdStatus != 'Red-lettered' && info.data.bdStatus != 'Cancelled' &&
                        info.data.issuedDate >= checkDateStart && info.data.issuedDate <= checkDateEnd) {
                        var element = $('<a/>');
                        element.css({ 'color': '#6699cc', 'cursor': 'pointer', 'margin-left': '10px' }).text($translate.instant('Red Letter')).on('dxclick', function () {
                            $scope.redLetterBdUserInvoice(info.data, element);
                        }).appendTo(ele);
                    }
                }
            }
        ];

        //获取数据服务
        $scope.getOutputInvoicePrintedList = function () {
            var deferred = $q.defer();

            var invoiceParams = {
                QueryParam: $scope.searchEntity,
                PagingParam: $scope.pagingOptions,
            };

            vatOutputInvoiceManageService.getIssuedVehicleBdList(invoiceParams).success(function (data) {
                if (data && data.list) {
                    $scope.pagingOptions.totalItems = data.pageInfo && data.pageInfo.totalCount;
                    data.list.forEach(function (item) {
                        item.invoiceNo = item.invoiceNumber;
                        item.invoiceCase = '';
                        item.issuedDate = item.bdIssuedDate ? (new Date(item.bdIssuedDate)).dateTimeToString('yyyyMMdd') : '';
                        item.caseCollectionDate = item.caseCollectionDate ? (new Date(item.caseCollectionDate)).dateTimeToString('yyyyMMdd') : '';
                        item.issuranceType = $translate.instant(PWC.getEnumKeyByValue(enums.IssuanceType, item.issuranceType));
                        item.bdStatus = $translate.instant(PWC.getEnumKeyByValue(enums.BDStatusEnum, item.bdStatus));
                        if (PWC.getEnumKeyByValue(enums.GDBDStatusEnum, item.gdBdStatus) === 'readyToIssue') {
                            item.gdBdStatus = '';
                        }else{
                            item.gdBdStatus = $translate.instant(PWC.getEnumKeyByValue(enums.GDBDStatusEnum, item.gdBdStatus));
                        }
                        if (!item.cabinConfiguration) {
                            item.cabinConfiguration = $translate.instant('FiveSeatInterior');
                        }
                    });
                   
                    $scope.invoiceGridDataSource = data.list;
                    //清除选中状态
                    $("#dxIssuedInvoiceDataGridContainer").dxDataGrid('instance').clearSelection();
                    deferred.resolve(data);
                };
            });
            return deferred.promise;
        };

        //设置dataGrid分页
        $scope.pagingOptions = {
            pageIndex: 1,  //当前页码
            totalItems: 100,  //总数据
            totalPages: 10,//总页数
            maxSize: 10, //分页数字的限制。
            pageSize: 20,  //每页多少条数据 
            pageSizeString: '20',
            firstPage: $translate.instant('PagingFirstPage'),
            previousPage: $translate.instant('PagingPreviousPage'),
            nextPage: $translate.instant('PagingNextPage'),
            lastPage: $translate.instant('PagingLastPage'),
        };

        //分页里面的处理
        $scope.pagingService = {
            setPage: function (pageNo) {

            },
            //分页的时候改变数字
            pageIndexChanging: function () {
                if ($scope.pagingOptions.pageIndex > $scope.pagingOptions.totalPages) {
                    $scope.pagingOptions.pageIndex = $scope.pagingOptions.totalPages;
                }

                $log.log('Page changed to: ' + $scope.pagingOptions.pageIndex);
                $scope.getOutputInvoicePrintedList();
            },

            //每页显示的数据下拉改变
            pageSizeSelectionChanged: function () {
                $scope.pagingOptions.pageSize = parseInt($scope.pagingOptions.pageSizeString);
                $scope.getOutputInvoicePrintedList();
            }
        };

        //-----------------表格对象定义-----------------//end

        //-----------------发票操作定义-----------------//start

        //红冲BD-User Invoice
        $scope.redLetterBdUserInvoice = function (data,element) {

            var redLetterBdUserPopController = function ($scope) {
                $scope.redLetterData = {};
                $scope.redLetterData.needReasonRdio = 1;

                $scope.redLetterData.inputReasonOption = {
                    width: '100%',
                    height: 60,
                    bindingOptions: {
                        value: 'redLetterData.inputReason'
                    }
                };
                $scope.validateOption = {};
                $scope.validateOption.inputReasonOption = {
                    validationRules: [{
                        type: "required",
                        message: $translate.instant('BdUserRedLetterWarningInfoInputRequired')
                    }, {
                        type: 'stringLength',
                        max: 500,
                        message: $translate.instant('BdUserRedLetterWarningInfoInputLengthCheck')
                    }]
                };

                var addBdUserRedLetterReason = function (files) {
                    var reasonData = {};
                    reasonData.invoicingReasonIndex = $scope.redLetterData.needReasonRdio;
                    if ($scope.redLetterData.needReasonRdio == 2) {
                        reasonData.inputReason = $scope.redLetterData.inputReason;
                    }
                    reasonData.isRecievingAll = $scope.redLetterData.isRevievingAll ? 1 : 0;
                    reasonData.invoiceID = data.id;
                    reasonData.caseNumber = data.caseNumber;

                    //用户首字母大写
                    var tmpChar = loginContext.userName.substring(0, 1).toUpperCase();
                    var postString = loginContext.userName.substring(1, loginContext.userName.length);
                    var tmpStr = tmpChar + postString;
                    reasonData.createBy = tmpStr;

                    //设置附件
                    if (files && files.length > 0) {
                        var fileIds = [];
                        _.each(files, function (item) {
                            fileIds.push(item.data.fileID);
                        });
                        reasonData.evidenceDocuments = fileIds.join(',');
                    }

                    var deffered = $q.defer();
                    vatOutputInvoiceManageService.addBdUserRedLetterReason(reasonData).success(function (data) {
                        deffered.resolve(data);
                    });
                    return deffered.promise;
                };

                //BD红冲检查。
                var checkDataAvailable = function (files) {
                    if ($scope.redLetterData.needReasonRdio == 2) {

                        var dxResult = DevExpress.validationEngine.validateGroup($('#reasonModalForm').dxValidationGroup("instance")).isValid;
                        if (!dxResult) {
                            return;
                        }

                        if (!$scope.redLetterData.inputReason) {
                            SweetAlert.warning($translate.instant('BdUserRedLetterWarningInfoInputRequired'));
                            return false;
                        } else if ($scope.redLetterData.inputReason.length > 500) {
                            SweetAlert.warning($translate.instant('BdUserRedLetterWarningInfoInputLengthCheck'));
                            return false;
                        }
                    }
                    if (!files || files.length < 1 || !$scope.redLetterData.isRevievingAll) {
                        //检查证明文件
                        if (!files || files.length < 1) {
                            $('#UploadFileCheckTipId').show();
                        } else {
                            $('#UploadFileCheckTipId').hide();
                        }
                        if (!$scope.redLetterData.isRevievingAll) {
                            $('#CancelDialogTextTipId').show();
                        } else {
                            $('#CancelDialogTextTipId').hide();
                        }
                        return false;
                    } else {
                        $('#UploadFileCheckTipId').hide();
                        $('#CancelDialogTextTipId').hide();
                    }
                    return true;
                };

                $scope.$watch('$parent.uploadFileOption.files', function (newValue, oldValue) {
                    if (newValue && newValue != oldValue) {
                        var files = $scope.$parent.uploadFileOption.files;
                    }
                });

                //上传文件
                $scope.uploadFile = function () {
                    $scope.$parent.uploadFileType = 'multiple';
                    $scope.$parent.uploadFileOption = {
                        title: 'Upload Evidence Document',
                        uploadButtonText: 'Select Upload Files',
                        files: $scope.$parent.uploadFileOption.files || []
                    };
                }

                //关闭弹窗口
                $scope.hidePopPanel = function () {
                    $scope.$parent.uploadFileOption = {};
                    $scope.$dismiss({ $value: 'cancel' });
                };

                //删除证据文件
                $scope.deleteEvidenceFile = function (fileId) {
                    var fileList = [fileId];
                    vatOutputInvoiceManageService.deleteEvidenceFile(fileList).then(function () {
                        $scope.$parent.uploadFileOption.files = _.filter($scope.$parent.uploadFileOption.files, function (item) {
                            return item.data.fileID != fileId;
                        });
                    });
                }

                //下载证据文件
                $scope.downloadEvidenceFile = function (data) {
                    var queryDto = {};
                    queryDto.fileName = data.fileName;
                    queryDto.filePath = data.filePath;
                    vatOutputInvoiceManageService.downloadEvidenceFile(queryDto);
                };

                //执行红冲发票
                $scope.confirmRedLetterInvoice = function (files) {
                    if (checkDataAvailable(files)) {
                        //调用红冲接口
                        vatOutputInvoiceManageService.redLetterInvoice(data.id).then(function () {
                            //保存红冲原因及附件。
                            var promise = addBdUserRedLetterReason(files);
                            promise.then(function (data) {
                                //红冲结束隐藏红冲按钮。
                                element.hide();
                                $scope.$parent.uploadFileOption = {};
                                $scope.$dismiss({ $value: 'cancel' });
                                $scope.getOutputInvoicePrintedList();
                            });
                        });
                    }
                };

            };

            var parentElem = angular.element($document[0].querySelector('#red-letter-bd-user-pop'));
            var modalInstance = $uibModal.open({
                ariaLabelledBy: 'modal-title',
                ariaDescribedBy: 'modal-body',
                backdrop: 'static',
                templateUrl: 'red-letter-bd-user-page.html',
                controller: redLetterBdUserPopController,
                windowClass: 'data-table',
                appendTo: parentElem,
                scope: $scope
            });
        };


        //红冲GD-BD Invoice (只改GD-BD发票中的该车的状态为Pending For Approval)
        $scope.redLetterGdBdInvoice = function (data) {
            //vatOutputInvoiceManageService.sendEmail(data.vin);
            //vatOutputInvoiceManageService.receiveEmail();
            var redLetterGdBdInvoiceController = function ($scope) {
                $scope.data = data;
                if (data.vin) {
                    vatOutputInvoiceManageService.getOutputInvoiceImportedByVin(data.vin).success(function (result) {
                        //排除自己
                        result = _.filter(result, function (item) {
                            return item.bdFapiaoEntity != data.bdFapiaoEntity ||
                                   item.registrationLocalName != data.registrationLocalName ||
                                   item.companyVATIDTaxID != data.companyVATIDTaxID ||
                                   item.organizationCode != data.organizationCode;
                        });
                        $scope.data.BDList = result;
                    });
                }


                $scope.data = data;
                //关闭弹窗口
                $scope.hidePopPanel = function () {
                    $scope.$dismiss({ $value: 'cancel' });
                };

                //执行更新GD-BD车辆 invoice status
                $scope.confirmRedLetterInvoice = function () {
                    vatOutputInvoiceManageService.updateInvoiceVichelGdBdStatus(data.id, enums.GDBDStatusEnum.pendingForApproval).success(function () {
                        $scope.$dismiss({ $value: 'cancel' });
                        $scope.getOutputInvoicePrintedList();
                        vatOutputInvoiceManageService.sendEmail(data.vin,data.id);
                    });
                };

                $scope.dataGridGdBdOptions = {
                    showRowLines: true,
                    showColumnLines: true,
                    showBorders: true,
                    allowColumnResizing: true,
                    hoverStateEnabled: true,
                    rowAlternationEnabled: true,
                    bindingOptions: {
                        dataSource: 'data.BDList'
                    },
                    columns: [
                                { dataField: 'bdFapiaoEntity', caption: 'Entity', width: '25%' },
                                { dataField: 'registrationLocalName', caption: 'Customer name', width: '25%' },
                                { dataField: 'companyVATIDTaxID', caption: 'Customer tax ID or National ID', width: '25%' },
                                { dataField: 'organizationCode', caption: 'Organization Code (if applicable)', width: '25%' }
                    ]
                };

                $timeout(function () {
                    $scope.dataGridGdBdOptions.height = 130;
                }, 500);

            };

            var parentElem = angular.element($document[0].querySelector('#red-letter-gd-bd-pop'));
            var modalInstance = $uibModal.open({
                ariaLabelledBy: 'modal-title',
                ariaDescribedBy: 'modal-body',
                backdrop: 'static',
                templateUrl: 'red-letter-gd-bd-page.html',
                controller: redLetterGdBdInvoiceController,
                windowClass: 'data-table',
                appendTo: parentElem,
                scope: $scope
            });
        };

        $scope.cancelCore = function () {
            //调用取消发票接口执行取消发票功能。
            var promiss = [];
            var data = $scope.selectedIssuedInvoiceData;

            //已红冲和已取消的发票不能再做取消操作。
            var canCancelDatas = [];
            var negativeDatas = [];
            _.each(data, function (item) {
                if (item.bdStatus == enums.BDStatusEnum.Cancelled || item.bdStatus == enums.BDStatusEnum.RedLettered) {
                    canCancelDatas.push(item);
                }
            });

            _.each(data, function (item) {
                if (item.subtotalforFinalPayment < 0) {
                    negativeDatas.push(item);
                }
            });
            if (canCancelDatas.length > 0) {
                SweetAlert.warning($translate.instant('BDFapiaoCancelCheck')
                    .replace('{0}', _.pluck(canCancelDatas, 'invoiceNumber').join(',')));
                return;
            }

            if (negativeDatas.length > 0) {
                SweetAlert.warning($translate.instant('NegativeFapiaoCheck')
                    .replace('{0}', _.pluck(negativeDatas, 'invoiceNumber').join(',')));
                return;
            }

            _.each(data, function (item) {
                var cancelPromiss = vatOutputInvoiceManageService.cancelInvoice(item.id, $scope.isReprint);
                promiss.push(cancelPromiss);
            });
            $q.all(promiss).then(function () {
                modalAdapterService.close(constant.OutputInvoiceCancalDialog, "issued-invoice-bd-view-container");
                $scope.getOutputInvoicePrintedList();                
            },
            //可能有错误的时候
            function (err) {
                SweetAlert.error('', $translate.instant('CommonFail'));
            });
        };
        //取消发票
        $scope.CancelInvoice = function (data, reprint) {
            if (!data || data.length < 1) {
                SweetAlert.warning($translate.instant('SelectBdInvoiceCheck'));
                return;
            }
            $scope.title = reprint ? $translate.instant("CancelReprintInvoiceBDTitle") : $translate.instant("CancelInvoiceBDTitle")
            $scope.isReprint = reprint ? reprint : false;
            modalAdapterService.open(constant.OutputInvoiceCancalDialog, "issued-invoice-bd-view-container");
        };

        //-----------------发票操作定义-----------------//end

        //Upload Vin file define -->start
        var resumable = true;
        $scope.chunkSize = 500 * 1024;
        $scope.uploadOption = {};
        $scope.uploadOption.uploadFiles = [];
        $scope.$watch('uploadOption.uploadFiles', function (newValue, oldValue) {
            if (newValue && newValue !== oldValue) {
                uploadfile($scope.uploadOption.uploadFiles);
            }
        });

        //执行上传文件操作。
        var uploadfile = function (file) {
            if (file) {
                var uploadSuccessCallBack = function (data) {
                    var result = data;
                };

                var uploadSuccess = function (data) {
                    //根据上传的vin勾选发票
                    var result = data;
                    var gridInstance = $('#dxIssuedInvoiceDataGridContainer').dxDataGrid('instance');
                    var selectedInvoices = _.filter($scope.invoiceGridDataSource, function (item) {
                        return result.data.indexOf(item.vin) >= 0;
                    });
                    var selectedKeys = _.pluck(selectedInvoices, 'id');
                    gridInstance.selectRows(selectedKeys,true);
                };

                if (!file.$error) {
                    var tempFileName = PWC.newGuid() + '.dat';
                    var token = $('input[name="__RequestVerificationToken"]').val();
                    Upload.upload({
                        url: apiInterceptor.webApiHostUrl + '/outputInvoicePrinted/uploadVinFile',
                        data: {
                            cancel: false,
                            filename: file.name,
                            tempFileName: tempFileName,
                            file: file,
                            period: $scope.period
                        },
                        resumeChunkSize: resumable ? $scope.chunkSize : null,
                        headers: {
                            'Access-Control-Allow-Origin': '*',
631
                            Authorization: apiInterceptor.tokenType + ' ' + apiInterceptor.apiToken()
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
                        },
                        __RequestVerificationToken: token,
                        withCredentials: true
                    }).then(uploadSuccess, uploadSuccessCallBack);
                }
            }
        };//Upload Vin file define -->end

        $scope.$on('teslaOutputInvoiceMenuClick', function (event, data) {
            //设置表格高度
            $timeout(function () {
                $scope.setInvoiceGridHeight();
            }, 500);
        });


        $scope.printGDInvoice = function () {

            if (!$scope.selectedIssuedInvoiceData || $scope.selectedIssuedInvoiceData.length === 0) {
                SweetAlert.warning($translate.instant('SelectBdInvoiceCheck'));

                return;
            };

            $state.go('outputInvoiceManage.gdInvoicePrint', { invoiceList: $scope.selectedIssuedInvoiceData });
        };

        (function () {
            var promise = $scope.getOutputInvoicePrintedList();
            $scope.uploadFileType = null;
            $scope.uploadFileOption = {};


            promise.then(function () {
                //设置表格高度
                $timeout(function () {
                    $scope.setInvoiceGridHeight();
                }, 500);
            });
        })();
    }
]);