special-vat-invoice.ctrl.js 14.2 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
vatModule.controller('specialVatInvoiceController', ['$log', '$timeout', '$scope', '$translate', 'vatOutputInvoiceManageService',
    'SweetAlert', 'orgService', 'enums', 'modalAdapterService',
    function ($log, $timeout, $scope, $translate, vatOutputInvoiceManageService, SweetAlert,
        orgService, enums, modalAdapterService) {
        //分页的设置
        var dateFormat = 'yyyy-MM-dd';
        $scope.pleaseSelect = $translate.instant("ChoosePlaceholder");
        $scope.pleaseInput = $translate.instant('InputPlaceholder');
        $scope.pagingOptions = {
            pageIndex: 1,  //当前页码
            totalItems: 0,  //总数据
            pageSize: constant.page.pageSizeArrary[1],  //每页多少条数据 
        };
        $scope.specialSearchEntity = {
            invoiceNumberVaule: null,
            VRLValue: null,
            issuedPeriodFromValue: null,
            issuedPeriodToValue: null,
            entityCodeValue: null,
            statusValue: [],
            revertStatusList:[]
        };
        $scope.specialInvoiceVariables = {
            selectedTableRows: [],
            selectedTotalAmount: 0.00,
            pageName: $translate.instant('IssuedInvoiceSpecial'),
            selectedInvoice:null
           
        };
        $scope.specialInvoice = {
            invoiceNumberOptions: {
                bindingOptions: {
                    'value': 'specialSearchEntity.invoiceNumberVaule'
                },
                showClearButton: true,
                placeholder: $scope.pleaseInput
            },
            VRLOptions: {
                bindingOptions: {
                    'dataSource': 'allDBVRL',
                    'value': 'specialSearchEntity.VRLValue'
                },
                showClearButton: true,
                placeholder: $scope.pleaseSelect
            },
            issuedPeriodFromOptions: {
                type: "date",
                dateSerializationFormat:dateFormat,
                displayFormat: dateFormat,
                bindingOptions: {
                    'value': 'specialSearchEntity.issuedPeriodFromValue'
                },
                width: '100%',
                showClearButton: true,
                placeholder: $scope.pleaseSelect
            },
            issuedPeriodToOptions: {
                type: "date",
                dateSerializationFormat: dateFormat,
                displayFormat: dateFormat,
                bindingOptions: {
                    'value': 'specialSearchEntity.issuedPeriodToValue'
                },
                width: '100%',
                showClearButton: true,
                placeholder: $scope.pleaseSelect
            },
            entityOptions:{
                bindingOptions: {
                    'value': 'specialSearchEntity.entityCodeValue',
                    'dataSource':'entitySource'
                },
                showClearButton: true,
                displayExpr: 'name',
                valueExpr: 'id',
                placeholder: $scope.pleaseSelect
            },
            statusOptions:{
                bindingOptions: {
                    'value': 'specialSearchEntity.statusValue',
                    'dataSource': 'specialStatus'
                },
                showClearButton: true,
                showDropButton: true,
                multiline: false,
                showSelectionControls: true,
                applyValueMode: "useButtons",
                displayExpr: 'name',
                valueExpr: 'id',
                //fieldTemplate: function (selectedItems, fieldElement) {                   
                //    selectedItems = Array.isArray(selectedItems) ? selectedItems : [selectedItems];
                   
                //    var selCount = selectedItems.length,
                //         $textBox = $('<div>', { class: "input-field" }).dxTextBox({});
                   
                //    var $field = $("<div>", { class: "tag-container" }).text(
                //        selCount > 1 ? selCount + " selected" : selCount===1?selectedItems[0].name:null
                //    );

                //    return fieldElement.append($field).append($textBox);
                //},              
                placeholder: $scope.pleaseSelect
            },
            specialGridContainer: {
                //height:'260px',
                bindingOptions: {
                    dataSource: 'specialInvoiceList',
                    'height': 'height'
                },
                loadPanel: {
                    enabled: false,
                },
                noDataText:$translate.instant('NoDataText'),
                columnAutoWidth:true,
                showRowLines: true,
                showBorders: true,
                columnChooser: {
                    enabled: true
                },
                paging: {
                    enabled: false
                },
                selection:{
                    mode: 'multiple',
                    showCheckBoxesMode: 'always'
                },
                onSelectionChanged: function (e) {
                    $scope.specialInvoiceVariables.selectedTotalAmount = 0.00;
                    $scope.specialInvoiceVariables.selectedTableRows = e.selectedRowsData;
                    _.each(e.selectedRowsData, function (item) {
                        $scope.specialInvoiceVariables.selectedTotalAmount += item.totalAmount;
                    });
                },
                headerFilter:{
                    visible: false,
                    texts: {
                        cancel: $translate.instant('ENCancel'),
                        emptyValue: $translate.instant('Blank'),
                        ok:$translate.instant('Confirm')
                    }
                },
                columns: [
                    { dataField: 'vrl', caption: $translate.instant('VRL'),allowHeaderFiltering:false,visible:false },
                    { dataField: 'buyerOrganizationCode', caption: $translate.instant('Entity'), allowHeaderFiltering: false },
                    { dataField: 'gdInvoiceNumber', caption: $translate.instant('InvoiceNo'), allowHeaderFiltering: false },
                    { dataField: 'gdInvoiceCode', caption: $translate.instant('InvoiceCode'), allowHeaderFiltering: false },
                    { dataField: 'buyerOrganizationName', caption: $translate.instant('BuyerName'), allowHeaderFiltering: false },
                    { dataField: 'buyerOrganizationTaxID', caption: $translate.instant('BuyerTaxID'), allowHeaderFiltering: false },
                    {
                        dataField: 'totalAmount', caption: $translate.instant('Amount'),
                        format: { type: 'fixedPoint', precision: 2 }, allowHeaderFiltering: false
                    },
                     {
                         dataField: 'totalTaxAmount', caption: $translate.instant('TaxAmount'),
                         format: { type: 'fixedPoint', precision: 2 }, allowHeaderFiltering: false
                     },
                    {
                        dataField: 'gdIssuedDate', caption: $translate.instant('IssuedDate'),
                        dataType: 'date', format: dateFormat, allowHeaderFiltering: false
                    },
                    {
                        dataField: 'status', caption: $translate.instant('Status'),
                        calculateDisplayValue: function (rowData) {
                            return $translate.instant($scope.specialSearchEntity.revertStatusList[rowData.status]);
                        }
                        //headerFilter: {
                        //    dataSource: {
                        //        load: function () {
                        //           return _.map(enums.GDInvoiceStatusEnum, function (item, key) {                                       
                        //               return {
                        //                   text: $translate.instant(key),
                        //                   value: ["status", "=", item]
                        //               };
                        //            });
                        //        }
                        //    }
                        //}
                    },
                    {
                        caption: $translate.instant('Details'),
                        cellTemplate: 'detailTemplate', allowHeaderFiltering: false
                    }

                ]
            }
        };


        $scope.eventService = {
            checkBeforCancel: function () {
                var list = $scope.specialInvoiceVariables.selectedTableRows;
                //过月的不能cancel
                var currentMonth = new Date().getMonth();//1-12
                var notValidMonthCount = 0;
                var notValidStatus = true;
                var isRed = false;
                _.each(list, function (item) {
                    var m = new Date(item.gdIssuedDate).getMonth();
                    notValidMonthCount = m === currentMonth ? notValidMonthCount : ++notValidMonthCount;
                    if (item.status !== enums.GDInvoiceStatusEnum.issued) {
                        notValidStatus = false;
                    } 
                    if (item.isRedInvoice) {
                        //红票不能cancel
                        isRed = true;
                    }
                    
                });
                var result = {
                    pass: notValidMonthCount === 0 && notValidStatus && !isRed,
                    notMatchMonth: notValidMonthCount,
                    notValidStatus: notValidStatus,
                    isRedInvoice: isRed
                }
                return result;
            },
            cancelInvoiceCore: function () {
                var dto = {
                    items: $scope.specialInvoiceVariables.selectedTableRows,
                    reprint: $scope.isReprint,
                    userName: null,
                    userID: null
                }
                //need call baiwang jie kou
                vatOutputInvoiceManageService.cancelGDInvoice(dto).success(function (response) {
                    if (response.result) {
                        //_.each($scope.specialInvoiceVariables.selectedTableRows, function (item) {
                        //    item.status = enums.GDInvoiceStatusEnum.cancelled;
                        //});
                        modalAdapterService.close(constant.OutputInvoiceCancalDialog, 'special-vat-page');
                        $scope.eventService.refreshInvoiceDataGrid();
                    }
                }).error(function () {
                    SweetAlert.error('', $translate.instant('CommonFail'));
                });
            },
            cancelFapiao: function (reprint) {
                if (!$scope.specialInvoiceVariables.selectedTableRows || $scope.specialInvoiceVariables.selectedTableRows.length < 1) {
                    SweetAlert.warning($translate.instant('SelectBdInvoiceCheck'));
                    return;
                }
                var result=$scope.eventService.checkBeforCancel();
                if (result.pass) {
                    $scope.title = reprint ? $translate.instant("CancelReprintInvoiceGDTitle") : $translate.instant("CancelInvoiceGDTitle")
                   $scope.isReprint = reprint ? reprint : false;
                   modalAdapterService.open(constant.OutputInvoiceCancalDialog, 'special-vat-page');
                }else
                {
                    var message =result.notMatchMonth===0?"": $translate.instant('HasNotMatchMonth') + result.notMatchMonth + $translate.instant('Separator');
                    message = result.notValidStatus ? message : message + $translate.instant('HasNotMatchStatus');
                    message = result.isRedInvoice ? message + $translate.instant('RedInvoiceWarrning') : message;
                    SweetAlert.warning('', message);
                }
               
            },
            cancelandPrintFapiao:function(){
                $scope.eventService.cancelFapiao(true);
            },
            getQueryBasicData: function () {
                $scope.specialStatus = _.map(enums.GDInvoiceStatusEnum, function (item, key) {
                    return { id: item, name: $translate.instant(key) };
                });
                orgService.getBdList().success(function (res) {
                    $scope.entitySource=  _.map(res,function(item){
                        return { id: item.code, name: item.code + item.name };
                    });
                    $scope.allDBVRL = _.filter(_.uniq(_.pluck(res, 'vehicleroutinglocation')),
                        function (item) { return item !== null });
                });
                
            },
            refreshInvoiceDataGrid: function () {
                var dataDto = {
                    parameters:$scope.specialSearchEntity,
                        pagingInfo: $scope.pagingOptions
                }
                vatOutputInvoiceManageService.getSpecailGBInvoiceList(dataDto).success(function (response) {
                    $scope.specialInvoiceList = response.list;
                    $scope.pagingOptions.totalItems = response.pageInfo.totalCount;
                }).error(function () {
                    SweetAlert.error('', $translate.instant('CommonFail'));
                });
     
            },
            showDetail: function (rowData) {
                $scope.specialInvoiceVariables.selectedInvoice = rowData;
                $scope.$broadcast("openGDDetailDialog");
            },
            //隐藏或者展示搜索框
            showOrHideSearchBox: function () {
                $scope.hasShowMoreSearchBox = !$scope.hasShowMoreSearchBox;
                // $scope.eventService.refreshInvoiceDataGrid();
                $timeout(function () {
                    $scope.setInvoiceGridHeight();
                }, 500);

            }
        };

      
        (function () {
            $scope.specialSearchEntity.revertStatusList = _.invert(enums.GDInvoiceStatusEnum);
            $scope.eventService.getQueryBasicData();
            $scope.eventService.refreshInvoiceDataGrid();
            $scope.hasShowMoreSearchBox = false;
            //设置表格高度
            $timeout(function () {
                $scope.setInvoiceGridHeight();
            }, 500);
        })();
    }
])