vat-account-mapping.ctrl.js 95.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
vatModule.controller('vatAccountMappingController', ['$scope', '$log', '$timeout',
    '$q', '$translate', '$interval', 'loginContext', 'apiInterceptor', 'SweetAlert',
    'vatReductionService', 'vatSessionService', 'uiGridConstants', 'enums',
    'i18nService', 'BSPLService', 'vatCommonService', '$uibModal', 'commonWebService', 'vatOperationLogService',
    'vatImportService',
function ($scope, $log, $timeout, $q, $translate, $interval, loginContext, apiInterceptor,
    SweetAlert, vatReductionService, vatSessionService, uiGridConstants, enums,
    i18nService, BSPLService, vatCommonService, $uibModal, commonWebService, vatOperationLogService, vatImportService) {
    'use strict';
    $log.debug('vatAccountMappingController.ctor()...');
    var period = vatSessionService.month; //period < 0 覆盖导入时会删除所有数据
    var projectRuleId = 2; //todo: 应该在vatSessionService.project中获取
13
    var projectId = vatSessionService.project.id;
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
    var selectedRemapType = -1;
    //写日志
    var comment = vatSessionService.project.name + " " + vatSessionService.project.year + "年" + vatSessionService.month + "月";
    $scope.moduleid = enums.vatModuleEnum.Import_AccountMapping;
    $scope.periodId = vatSessionService.month;
    var logDto = {
        ID: '',
        OperationName: '',
        ModuleID: $scope.moduleid,
        OperationObject: '',
        OperationType: '',
        OperationContent: '',
        OriginalState: '',
        UpdateState: '',
        CreatorID: vatSessionService.logUser.ID,
        Comment: comment,
        IP: '',
        Period: $scope.periodId,
    };

    var stdDto = {
        id: '',
        acctProp: '',
        code: '',
        direction: '',
        fullName: '',
        hasChildren: false,
        name: '',
        parent: ''
    };

    //添加企业科目过滤下拉列表
    var InitFilterAccount = function () {
        var data = constant.espAccountFilter.data;
        data.forEach(function (row) {
            row.value = $translate.instant(row.value);
        });

        $scope.accountFilterList = data;
    };

    $scope.isSelected = function (id) {
        return $scope.filter.selected.indexOf(id) >= 0;
    };


    var showOperateLogPop = function () {
        $scope.isShowLog = true;
    }

    //检查用户机构权限
    var checkUserOrganizationPermissionList = function () {
        var list = [];
        var userManageTemp = constant.vatPermission.dataManage.accountMapping;
        list.push(userManageTemp.importCode);
        $scope.hasImportPermission = false;
        $scope.$root.checkUserOrganizationPermissionList(list).success(function (data) {
            $scope.hasImportPermission = data[userManageTemp.importCode];
        });
    };

    //初始化企业科目数据列表
    var InitEnterpriseSubject = function () {
        vatReductionService.mapStdCodeRecursiveByAccountList(period).success(function (or) {
            if (or.result) {
                var data = or.data;
                if (data === null) return;
                data.forEach(function (row) {
                    //row.directionStr = _.find($scope.directionList, function (num) {
                    //    return num.id === row.direction;
                    //}).name;
                    if (row.acctProp) {

                    }
                    if (row.acctLevel != null) {
                        row.$$treeLevel = parseInt(row.acctLevel - 1);
                    }

                    row.stdResult = getStdResult(row.stdCode, row.stdFullName);
                });

                $log.debug("InitEnterpriseSubject success");
                $log.debug(data);
                $scope.gridOptionsSubjectList.data = data;
                $scope.EnterpriceAccountList = data;
            }
        });
    };


    //切换筛选条件的时候,ng-check event will be triggered
    var stateChanged = function ($event, data) {
        $scope.filter.selected = [];
        $scope.filterConditionDesc = '';
        var checkbox = $event.target;
        if (checkbox.checked && $scope.filter.selected.indexOf(data.key) < 0) {
            $scope.filter.selected.push(data.key);
            $scope.filterConditionDesc = data.value;
        }

        accountFilterChanged();
    };

    //根据不同的状态过滤,未对应,已对应,借贷方向不一致等
    var accountFilterChanged = function () {
        var selectArr = $scope.filter.selected;
        var data = $scope.EnterpriceAccountList;
        var tempData = [];
        var key = $scope.filter.selected[0] || constant.espAccountFilter.key_0;

        switch (key) {
            //所有对应状态,取默认值
            case constant.espAccountFilter.key_0:
                tempData = data;
                break;
                //未对应
            case constant.espAccountFilter.key_1:
                tempData = _.filter(data, function (item) {
                    return item.stdCode == null;
                });
                break;
                //已对应
            case constant.espAccountFilter.key_2:
                tempData = _.filter(data, function (item) {
                    return item.stdCode != null;
                });
                break;
                //借贷方向不一致
            case constant.espAccountFilter.key_3:
                tempData = _.filter(data, function (item) {
                    return item.stdCode != null && item.stdCode != "-" && item.direction != 0
                        && item.stdDirection != null && item.directionDescription != item.stdDirection;
                });
                break;
                //科目类型不一致
            case constant.espAccountFilter.key_4:
                tempData = _.filter(data, function (item) {
                    return item.stdCode != null && item.stdCode != "-" && item.enterAcctProp != 0 && item.enterAcctProp != item.stdAcctProp;
                });
                break;
        }

        $scope.gridOptionsSubjectList.data = tempData;
    };


    ///根据标准科目code和name获取最终界面上应该显示的内容
    var getStdResult = function (stdCode, stdName) {
        var stdResult = stdCode === null ? $translate.instant('Unmapped') : (stdCode === "0000" ? "-" : stdCode + "-" + stdName);
        return stdResult;
    }

    //初始数据
    var InitNgData = function () {
        $scope.stdCollapsed = true;
        $scope.accountFilterList = [];
        //初始化选择器为空
        $scope.filter = {};
        $scope.filter.selected = [];
        //初始化企业科目筛选列表
        InitFilterAccount();
        //设置默认过滤条件为:所有对应状态
        var allMappStatus = constant.espAccountFilter.data[0];
        $scope.filter.selected.push(allMappStatus.key);
        $scope.filterConditionDesc = $translate.instant('AllMappingStatus');

        $timeout(function () {
            $scope.isLoadComplete = true;
        }, 500);
    }

    var getUITreeScope = function (uiTreeID) {
        return angular.element(document.getElementById(uiTreeID)).scope();
    };

    //如果没有全部展开,return false.
    var isExpandAll = function (uiTreeID) {
        var childNodes = getUITreeScope(uiTreeID).childNodes();

        var isCollapsed = function (c) {
            if (c.collapsed)
                return true;

            var childs = c.childNodes();

            for (var i = 0; i < childs.length; i++) {
                if (isCollapsed(childs[i])) {
                    return true;
                }
            }
            return false;
        }

        return !_.some(childNodes, isCollapsed);
    };


    //标准科目,单独展开或折叠
    var toggle1 = function (scope) {
        scope.toggle();
        if (scope.collapsed) {
            $scope.stdCollapsed = true;
        }
        else {
            //如果全部展开,最顶层也要展开
            if (isExpandAll('tree-root')) {
                $scope.stdCollapsed = false;
            }
        }
    };

    //标准科目,全部展开或折叠
    var toggleStdSubject = function () {
        $scope.stdCollapsed = !$scope.stdCollapsed;
        commonWebService.expandCollapseAll('vatStadardAccountTreeTable', $scope.stdCollapsed);
    }

    var updateParentEnterpriseAccount = function (parentMapingDict) {
        for (var key in parentMapingDict) {
            $scope.gridApiSubject.grid.rows.forEach(function (row) {
                if (row.entity.code === key) {
                    row.entity['stdCode'] = parentMapingDict[key][0];
                    row.entity['stdName'] = parentMapingDict[key][1];
                    row.entity['stdResult'] = getStdResult(parentMapingDict[key][0], parentMapingDict[key][2]);
                }
            });
        }
    };

    //当在取消或者手动对应之后更新界面
    //selectedRows: uigrid中当前选中的行集合
    //codeToUpdate: 需要将旧的代码设置为该code
    //nameToUpdate: 需要将旧的科目名称设置为该name
    var updateChildrenEnterpriseAccount = function (selectedRows, codeToUpdate, nameToUpdate) {
        //codeToUpdate = null && nameToUpdate = '': 取消对应
        if (!_.isNull(codeToUpdate) && nameToUpdate != '') {
            getStdCodeListRescurive();
        }

        var stdDto = _.where($scope.stdAccountList, { code: codeToUpdate })[0];
        selectedRows.forEach(function (v) {
            v['stdCode'] = codeToUpdate;
            v['stdName'] = nameToUpdate;
            v['stdResult'] = getStdResult(codeToUpdate, nameToUpdate);
            if (!_.isUndefined(stdDto)) {
                v['stdAcctProp'] = parseInt(stdDto.acctProp);
                v['stdCodeName'] = codeToUpdate + '/' + stdDto.fullName;
                v['stdDirection'] = stdDto.direction === "1" ? $translate.instant('StandardAccountDebit') : $translate.instant('StandardAccountCredit');
                v['stdFullName'] = stdDto.fullName;
            }

            //取消对应
            if (_.isNull(codeToUpdate) && nameToUpdate === '') {
                v['stdAcctProp'] = null;
                v['stdCodeName'] = null;
                v['stdDirection'] = null;
                v['stdFullName'] = null;
            }


            //找出该选中节点的所有子节点,然后复制,避免再次从数据库获取数据
            $scope.gridApiSubject.grid.rows.forEach(function (row) {
                if (row.entity.parent === v.code) {
                    row.entity['stdCode'] = codeToUpdate;
                    row.entity['stdName'] = nameToUpdate;
                    row.entity['stdResult'] = getStdResult(codeToUpdate, nameToUpdate);

                    //再次更新该row下面的子节点如果存在的话
                    updateChildrenMappedCodeNameRecursive($scope.gridApiSubject.grid.rows, row.entity['code'], codeToUpdate, nameToUpdate);
                }
            });
        });
    };

    var updateChildrenMappedCodeNameRecursive = function (rows, filterCode, codeToUpdate, nameToUpdate) {
        $scope.gridApiSubject.grid.rows.forEach(function (row) {
            if (row.entity.parent === filterCode) {
                row.entity['stdCode'] = codeToUpdate;
                row.entity['stdName'] = nameToUpdate;
                row.entity['stdResult'] = getStdResult(codeToUpdate, nameToUpdate);

                //再次更新该row下面的子节点如果存在的话
                updateChildrenMappedCodeNameRecursive($scope.gridApiSubject.grid.rows, row.entity['code'], codeToUpdate, nameToUpdate);
            }
        });
    }

    function getStatusByCurrentStatus(isSubmit) {
        if (!isSubmit &&
            (_.isEqual(vatSessionService.project.projectStatusList[period], constant.ProjectStatusEnum.Imported)
            || _.isEqual(vatSessionService.project.projectStatusList[period], constant.ProjectStatusEnum.AccountMapSubmitted))) {
            return constant.ProjectStatusEnum.Imported;
        }

        if (isSubmit &&
           (_.isEqual(vatSessionService.project.projectStatusList[period], constant.ProjectStatusEnum.Imported)
           || _.isEqual(vatSessionService.project.projectStatusList[period], constant.ProjectStatusEnum.AccountMapSubmitted))) {
            return constant.ProjectStatusEnum.AccountMapSubmitted;
        }

        if (vatSessionService.project.projectStatusList[period] >= constant.ProjectStatusEnum.Generated) {
            return vatSessionService.project.projectStatusList[period];
        }
    }

    function doAutoMap() {
        logDto.ID = PWC.newGuid();
        logDto.CreateTime = new Date();
        logDto.UpdateTime = new Date();
        logDto.OperationContent = "";
        logDto.OriginalState = "";
        logDto.OperationName = $translate.instant('AutoMapping');
        logDto.OperationType = enums.vatLogOperationTypeEnum.AM_AutoMapping;

        vatReductionService.autoMap(projectRuleId, period).success(function (or) {
            if (or != null && or != undefined) {
                if (or.result) {
                    getEnterpriseAccountNotMapped();
                    var status = getStatusByCurrentStatus(false);
                    vatCommonService.setProjectStatus(projectDbName, period, status, constant.DictionaryDictKey.WFAccountMap, enums.FinishStatusEnum.NotFinished);
                    logDto.UpdateState = $translate.instant('AccountMapSuccess');
                    vatOperationLogService.addOperationLog(logDto);
                    // mapping success
                    SweetAlert.success($translate.instant('AccountMapSuccess'));
                    InitEnterpriseSubject();
                }
                else {
                    SweetAlert.warning($translate.instant(or.resultMsg));
                }
            }
            else {
                logDto.UpdateState = $translate.instant('AccountMapFailed');
                vatOperationLogService.addOperationLog(logDto);
                SweetAlert.warning($translate.instant('AccountMapFailed'));
            }
        });
    }

    //自动对应
    var autoMap = function () {
        if (vatSessionService.project.projectStatusList[period] < constant.ProjectStatusEnum.Imported) {
            SweetAlert.warning($translate.instant('AutoMapWarning'));
        }

        if (vatSessionService.project.projectStatusList[period] === constant.ProjectStatusEnum.Imported) {
            doAutoMap();
        }

        if (vatSessionService.project.projectStatusList[period] > constant.ProjectStatusEnum.Imported) {
            swal({
                title: $translate.instant('WarningTitle'),
                text: $translate.instant('IsConfirmToReMap').formatObj({ status: vatCommonService.getProjectStautsEnumDesc(vatSessionService.project.projectStatusList[period]) }),
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: $translate.instant('Yes'),
                cancelButtonText: $translate.instant('No'),
                closeOnConfirm: true,
                closeOnCancel: true
            },
            function (isConfirm) {
                if (isConfirm) {
                    doAutoMap();
                }
                else {
                    swal.close();
                }
            });
        }
    };


    function doClearMap() {
        var clearEnterpriseAccountCodes = [];
        var selectedRows = $scope.gridApiSubject.selection.getSelectedRows();
        var orignalStdCodeName = [];
        if (selectedRows.length === 0) {
            SweetAlert.warning($translate.instant('SelectOneAccountToClearMap'));
            return;
        }

        selectedRows.forEach(function (v) {
            clearEnterpriseAccountCodes.push(v['code']);
            orignalStdCodeName.push(v.stdResult);
        });


        logDto.ID = PWC.newGuid();
        logDto.CreateTime = new Date();
        logDto.UpdateTime = new Date();
        logDto.OriginalState = orignalStdCodeName.join(",");
        logDto.UpdateState = "";
        logDto.OperationContent = "";
        logDto.OperationName = $translate.instant('CancelMapping');
        logDto.OperationObject = clearEnterpriseAccountCodes.join(",");
        logDto.OperationType = enums.vatLogOperationTypeEnum.AM_CancelMapping;



        vatReductionService.clearMap(period, clearEnterpriseAccountCodes).success(function (or) {
            if (or != null && or != undefined) {
                if (or.result) {
                    getEnterpriseAccountNotMapped();
                    var status = getStatusByCurrentStatus(false);
418
                    vatCommonService.setProjectStatus(project.id, period, status, constant.DictionaryDictKey.WFAccountMap, enums.FinishStatusEnum.NotFinished);
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 631 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 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
                    // clear mapping success
                    SweetAlert.success($translate.instant('ClearMapSuccess'));
                    //如果重新从数据库加载,数据会重新绑定然后感觉界面被刷新
                    updateChildrenEnterpriseAccount(selectedRows, null, '');
                    updateParentEnterpriseAccount(or.data);
                    //清除所有checkbox
                    $scope.gridApiSubject.selection.clearSelectedRows();
                    vatOperationLogService.addOperationLog(logDto);
                }
                else {
                    logDto.UpdateState = $translate.instant('ClearMapFailed');
                    vatOperationLogService.addOperationLog(logDto);
                    SweetAlert.warning($translate.instant(or.resultMsg));
                }
            }
            else {
                logDto.UpdateState = $translate.instant('ClearMapFailed');
                vatOperationLogService.addOperationLog(logDto);
                SweetAlert.warning($translate.instant('ClearMapFailed'));
            }
        });
    }

    //取消对应
    var ClearMap = function () {
        if (vatSessionService.project.projectStatusList[period] >= constant.ProjectStatusEnum.AccountMapSubmitted) {
            swal({
                title: $translate.instant('WarningTitle'),
                text: $translate.instant('IsConfirmCancelMap').formatObj({ status: vatCommonService.getProjectStautsEnumDesc(vatSessionService.project.projectStatusList[period]) }),
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: $translate.instant('Yes'),
                cancelButtonText: $translate.instant('No'),
                closeOnConfirm: true,
                closeOnCancel: true
            },
            function (isConfirm) {
                if (isConfirm) {
                    doClearMap();
                }
                else {
                    swal.close();
                }
            });
        }
        else {
            SweetAlert.warning($translate.instant('CancelMapWarning'));
            //doClearMap();
        }
    };

    function doMapStdAccount(code, name, acctProp, direction) {
        if (!$scope.hasImportPermission || $scope.isSubmitted) {
            if ($scope.isSubmitted) {
                $timeout(function () {
                    SweetAlert.warning($translate.instant('UndoAccountMapToMap'));
                }, 300)

            }
            return false;
        }
        var accountMap = {};
        var rowIndexArray = [];
        var isMapped = false;
        var isAcctPropMatched = false;
        var isDirectionMatched = false;

        accountMap.enterpriseAccountCodes = [];
        accountMap.standardAccountCode = code;

        var selectedRows = $scope.gridApiSubject.selection.getSelectedRows();
        if (selectedRows.length === 0) {
            SweetAlert.warning($translate.instant('SelectOneAccountToMap'));
            return;
        }

        var stdAcctProp = acctProp;
        var stdDirection = direction;
        var orignalStdCodeName = [];
        selectedRows.forEach(function (v) {
            accountMap.enterpriseAccountCodes.push(v['code']);
            var rowIndex = findIndexByKeyValue($scope.gridOptionsSubjectList.data, "code", v['code']);
            rowIndexArray.push(rowIndex);
            orignalStdCodeName.push(v.stdResult);
            var stdCode = v['stdCode'];
            var acctProp = v['enterAcctProp'].toString();
            var direction = v['direction'].toString();

            //判断企业科目是否已有对应的标准科目,如果有isMapped=true
            isMapped = !_.isNull(stdCode) ? true : false;

            //判断企业科目和标准科目的类型否一致,如果不一致,isAcctPropMatched=false
            if (acctProp !== -1 && !_.isNull(acctProp) && stdAcctProp !== acctProp) {
                isAcctPropMatched = false;
            }
            else {
                isAcctPropMatched = true;
            }

            //判断企业科目和标准科目的借贷方是否一致,如果不一致,isDirectionMatched=false
            if (stdDirection !== direction) {
                isDirectionMatched = false;
            }
            else {
                isDirectionMatched = true;
            }
        });

        logDto.ID = PWC.newGuid();
        logDto.CreateTime = new Date();
        logDto.UpdateTime = new Date();
        logDto.OriginalState = orignalStdCodeName.join(",");
        logDto.UpdateState = code + "-" + name;
        logDto.OperationContent = code;
        logDto.OperationName = $translate.instant('HandleMapping');
        logDto.OperationObject = accountMap.enterpriseAccountCodes.join(",");
        logDto.OperationType = enums.vatLogOperationTypeEnum.AM_ManualMapping;


        //如果已经map过
        if (isMapped) {
            msgboxOptions.text = $translate.instant('ComfirmToReMap');
            msgboxOptions.closeOnConfirm = isAcctPropMatched && isDirectionMatched ? true : false;
            SweetAlert.swal(msgboxOptions, function (isConfirm) {
                if (isConfirm) {
                    //如果科目类型不一致
                    if (!isAcctPropMatched) {
                        msgboxOptions.text = $translate.instant('ConfirmToMapForDiffAcctProp');
                        msgboxOptions.closeOnConfirm = isDirectionMatched ? true : false;
                        SweetAlert.swal(msgboxOptions, function (isConfirm) {
                            if (isConfirm) {
                                //如果科目类型一致,则判断借贷方向是否一致
                                if (!isDirectionMatched) {
                                    msgboxOptions.text = $translate.instant('ConfirmToMapForDiffDirection');
                                    msgboxOptions.closeOnConfirm = true;
                                    SweetAlert.swal(msgboxOptions, function (isConfirm) {
                                        if (isConfirm) {
                                            mapAccountParentChild(selectedRows, accountMap, code, name, logDto);
                                        } else {
                                            swal.close();
                                        }
                                    });
                                } else {
                                    mapAccountParentChild(selectedRows, accountMap, code, name, logDto);
                                }
                            } else {
                                swal.close();
                            }
                        });
                    }
                    else {
                        //如果借贷方向不一致
                        if (!isDirectionMatched) {
                            msgboxOptions.text = $translate.instant('ConfirmToMapForDiffDirection');
                            msgboxOptions.closeOnConfirm = true;
                            SweetAlert.swal(msgboxOptions, function (isConfirm) {
                                if (isConfirm) {
                                    mapAccountParentChild(selectedRows, accountMap, code, name, logDto);
                                } else {
                                    swal.close();
                                }
                            });
                        }
                        else {
                            mapAccountParentChild(selectedRows, accountMap, code, name, logDto);
                        }
                    }
                } else {
                    swal.close();
                }
            });
        }
        else {
            //如果没有map过,则判断科目类型是否一致
            if (!isAcctPropMatched) {
                msgboxOptions.text = $translate.instant('ConfirmToMapForDiffAcctProp');
                msgboxOptions.closeOnConfirm = isDirectionMatched ? true : false;
                SweetAlert.swal(msgboxOptions, function (isConfirm) {
                    if (isConfirm) {
                        //如果科目类型一致,则判断借贷方向是否一致
                        if (!isDirectionMatched) {
                            msgboxOptions.text = $translate.instant('ConfirmToMapForDiffDirection');
                            msgboxOptions.closeOnConfirm = true;
                            SweetAlert.swal(msgboxOptions, function (isConfirm) {
                                if (isConfirm) {
                                    mapAccountParentChild(selectedRows, accountMap, code, name, logDto);
                                } else {
                                    swal.close();
                                }
                            });
                        } else {
                            mapAccountParentChild(selectedRows, accountMap, code, name, logDto);
                        }
                    } else {
                        swal.close();
                    }
                });
            }
            else {
                //如果借贷方向不一致
                if (!isDirectionMatched) {
                    msgboxOptions.text = $translate.instant('ConfirmToMapForDiffDirection');
                    msgboxOptions.closeOnConfirm = true;
                    SweetAlert.swal(msgboxOptions, function (isConfirm) {
                        if (isConfirm) {
                            mapAccountParentChild(selectedRows, accountMap, code, name, logDto);
                        } else {
                            swal.close();
                        }
                    });
                } else {
                    mapAccountParentChild(selectedRows, accountMap, code, name, logDto);
                }
            }
        }
    };


    //手动对应,双击页面右侧的标准科目列表执行该事件
    var mapStdAccount = function (code, name, acctProp, direction) {
        if (vatSessionService.project.projectStatusList[period] >= constant.ProjectStatusEnum.Imported) {
            if ($scope.manualMapAlter) {
                swal({
                    title: $translate.instant('WarningTitle'),
                    text: $translate.instant('IsConfirmToReMap').formatObj({ status: vatCommonService.getProjectStautsEnumDesc(vatSessionService.project.projectStatusList[period]) }),
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: $translate.instant('Yes'),
                    cancelButtonText: $translate.instant('No'),
                    closeOnConfirm: true,
                    closeOnCancel: true
                },
               function (isConfirm) {
                   if (isConfirm) {
                       $scope.manualMapAlter = false;
                       $timeout(function () {
                           doMapStdAccount(code, name, acctProp, direction);
                       }, 300);

                   }
                   else {
                       swal.close();
                   }
               });
            }
            else {
                $timeout(function () {
                    doMapStdAccount(code, name, acctProp, direction);
                }, 300);

            }

        }
        else {
            //doMapStdAccount(code, name, acctProp, direction);
            SweetAlert.warning($translate.instant('ManualMapWarning'));
        }
    };


    var findIndexByKeyValue = function (arrayToSearch, key, valueToSearch) {
        for (var i = 0; i < arrayToSearch.length; i++) {
            if (arrayToSearch[i][key] == valueToSearch) {
                return i;
            }
        }
        return null;
    };

    //弹出框的默认配置项
    var msgboxOptions = {
        title: $translate.instant('ConfirmToContinue'),
        text: $translate.instant('ComfirmToReMap'),
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: $translate.instant('Confirm'),
        cancelButtonText: $translate.instant('Cancel'),
        closeOnConfirm: false,
        closeOnCancel: true
    };

    var mapAccountParentChild = function (selectedRows, accountMap, code, name, logDtoValue) {
        vatReductionService.mapAccount(accountMap.standardAccountCode, period, accountMap.enterpriseAccountCodes).success(function (or) {
            if (or.result === true) {
                getEnterpriseAccountNotMapped();
                $scope.gridApiSubject.selection.clearSelectedRows();

                //如果重新从数据库加载,数据会重新绑定然后感觉界面被刷新
                updateChildrenEnterpriseAccount(selectedRows, code, name);
                //更新父级科目的状态
                updateParentEnterpriseAccount(or.data);
                var status = getStatusByCurrentStatus(false);
714
                vatCommonService.setProjectStatus(project.id, period, status, constant.DictionaryDictKey.WFAccountMap, enums.FinishStatusEnum.NotFinished);
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893
                if (!_.isNull(logDtoValue)) {
                    vatOperationLogService.addOperationLog(logDtoValue);
                }
                //SweetAlert.success($translate.instant('AccountMapSuccess'));
            }
            else {
                logDtoValue.UpdateState = $translate.instant('AccountMapFailed');
                if (!_.isNull(logDtoValue)) {
                    vatOperationLogService.addOperationLog(logDtoValue);
                }
                SweetAlert.warning($translate.instant(or.resultMsg).formatObj({ code: or.data.standardAccountCode }));
            }
        });
    };

    $scope.getGridHeight = function () {
        if ($scope.isLoadComplete) {
            return {
                height: $(".subject-corresponding-container #enterprizeAccount .subject-list-grid-warp").height() + "px"
            };
        }
    };


    //动态设定重分类明细grid的高度
    var getReclassificationItemGridHeight = function () {
        if ($scope.isLoadComplete) {
            var y = $("#reclassification-item-wrapper").height();

            // Enough space
            if (y > constant.UIGrid.gapHeight) {
                y = y - constant.UIGrid.gapHeight;
                return { height: (y - $('#topMenu').height()) + "px" };
            } else {
                return { height: '0px' };
            }
        }

        return {};
    };

    //单击企业科目代码,显示重分类grid明细
    var toggleReclassificationGridTab = function () {
        $scope.ImportErrorTag = !$scope.ImportErrorTag;

        // topIcon and content-resize gapBottom 15px
        if (!$scope.ImportErrorTag) {
            setErrorWrapCssDefault();
        } else {

            if (parseInt($('#content-resizer').css('bottom')) < 100) {
                $('#content-resizer').css('bottom', '130px');
                $('.reclassification-item-wrapper').css('height', '130px');
            }
        }
    };

    //重置重分类明细的位置
    var setErrorWrapCssDefault = function () {
        $('#content-resizer').css('bottom', '0px');
        $('.reclassification-item-wrapper').css('height', '0px');
    };

    //点击手工重分类事件
    var manualReclassificate = function () {
        if (vatSessionService.project.projectStatusList[period] >= constant.ProjectStatusEnum.Imported) {
            $log.debug("start manualReclassificate");
            setAutoCompleteDataSource("reMapCustStdAutoComplete");
            selectedRemapType = enums.vatReMapType.ReMapCust;
            var selectedRows = $scope.gridApiSubject.selection.getSelectedRows();
            if (selectedRows.length !== 1) {
                SweetAlert.warning($translate.instant('SelectOneAccountToManualReclassificate'));
                return;
            }

            if (!isEnterpriseCodeLeafAcct()) {
                SweetAlert.warning($translate.instant('NotLeafEnterpriseCode'));
                return;
            }

            $scope.enterpriseCode = selectedRows[0].code;
            $scope.processTypeId = enums.processType.Add;
            initReMapCustModel(constant.Operation.Add, -1, null);
            logDto.OperationName = $translate.instant('AddCustRemap');
            logDto.OperationType = enums.vatLogOperationTypeEnum.AM_AddManualClass;
            logDto.OriginalState = "";
            $scope.remapTitle = $translate.instant('AccountMappingTitle') + "  " + selectedRows[0].codeNameDesc;
            resetCustRemapValidation();
            //$("#reMapCustStdAutoComplete").dxAutocomplete("instance").option("value", "");
            $scope.selectedStdCode = "";
            $('#manualReclassificationModal').modal('show');
        }
        else {
            SweetAlert.warning($translate.instant('RemapClickWarning'));
        }
    };

    //点击凭证重分类按钮事件
    var voucherReclassificate = function () {
        if (vatSessionService.project.projectStatusList[period] >= constant.ProjectStatusEnum.Imported) {
            $log.debug("start voucherReclassificate");
            selectedRemapType = enums.vatReMapType.ReMapVoucher;
            setAutoCompleteDataSource("reMapStdAutoComplete");
            var selectedRows = $scope.gridApiSubject.selection.getSelectedRows();
            if (selectedRows.length !== 1) {
                SweetAlert.warning($translate.instant('SelectOneAccountToVoucherReclassificate'));
                return;
            }

            if (!isEnterpriseCodeLeafAcct()) {
                SweetAlert.warning($translate.instant('NotLeafEnterpriseCode'));
                return;
            }


            //清空重分类明细选择项
            $scope.gridApiReclassificationItem.selection.clearSelectedRows();
            $scope.enterpriseCode = selectedRows[0].code;
            $scope.processTypeId = enums.processType.Add;
            initReMapVoucherModel(constant.Operation.Add, null, -1);
            $scope.isSearching = true;
            logDto.OperationName = $translate.instant('AddVoucherReMap');
            logDto.OperationType = enums.vatLogOperationTypeEnum.AM_AddVoucherClass;
            logDto.OriginalState = "";
            $scope.remapTitle = $translate.instant('VoucherReclassificationTitle') + "  " + selectedRows[0].codeNameDesc;
            resetVoucerRemapValidation();
            //$("#reMapStdAutoComplete").dxAutocomplete("instance").option("value", "");        
            $scope.selectedStdCode = "";
            $('#voucherReclassificationModal').modal('show');
        }
        else {
            SweetAlert.warning($translate.instant('RemapClickWarning'));
        }
    };

    //企业科目单击事件
    var showReclassificationItemGrid = function (etsRow) {
        $log.debug("start showReclassificationItemGrid");
        if (parseInt($('#content-resizer').css('bottom')) < 100) {
            $('#content-resizer').css('bottom', '20px');
            $('.reclassification-item-wrapper').css('height', '20px');
        }

        initReMapVoucherModel(constant.Operation.Add, null, -1);
        initReMapCustModel(constant.Operation.Add, -1, null);
        var selectedRows = $scope.gridApiSubject.selection.getSelectedRows();
        $scope.enterpriseCode = selectedRows[0].code;
        getReMapItemByCode(etsRow.code);
    };


    function doSaveManualReclassification() {
        $log.debug("start saveManualReclassification");
        constructReMapCustModel(selectedRemapType);
        $log.debug($scope.editManualRModel);


        var stdDto = _.where($scope.stdAccountList, { code: $scope.editManualRModel.stdCode })[0];
        var updateStateStr = "";
        if (!_.isNull(stdDto)) {
            //var directStr = stdDto.direction === "1" ? $translate.instant('StandardAccountDebit') : $translate.instant('StandardAccountCredit');
            updateStateStr = stdDto.code + "-" + stdDto.fullName + ":"
                            + $translate.instant('AccountVoucher_Debit') + ":" + $scope.editManualRModel.reMapDebit + "  "
                            + $translate.instant('AccountVoucher_Credit') + ":" + $scope.editManualRModel.reMapCredit;
        }
        logDto.ID = PWC.newGuid();
        logDto.CreateTime = new Date();
        logDto.UpdateTime = new Date();
        logDto.OperationObject = $scope.enterpriseCode;
        logDto.OperationContent = $scope.editManualRModel.reMapName;
        logDto.UpdateState = updateStateStr;


        vatReductionService.saveManualReclassification($scope.editManualRModel).success(function (or) {
            if (!_.isNull(or) && !_.isUndefined(or)) {
                if (or.result) {
                    $('#manualReclassificationModal').modal('hide');
                    getReMapItemByCode($scope.editManualRModel.code);
                    var status = getStatusByCurrentStatus(false);
894
                    vatCommonService.setProjectStatus(project.id, period, status, constant.DictionaryDictKey.WFAccountMap, enums.FinishStatusEnum.NotFinished);
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
                    vatOperationLogService.addOperationLog(logDto);
                    InitEnterpriseSubject();
                    SweetAlert.success($translate.instant('CustReMappingSuccess'));
                }
                else {
                    logDto.UpdateState = $translate.instant('AccountReMappingFail');
                    vatOperationLogService.addOperationLog(logDto);
                    SweetAlert.warning($translate.instant(or.resultMsg));
                }
            }
            else {
                logDto.UpdateState = $translate.instant('AccountReMappingFail');
                vatOperationLogService.addOperationLog(logDto);
                SweetAlert.warning($translate.instant('AccountReMappingFail'));
            }

        });
    }

    //保存手工重分类数据
    var saveManualReclassification = function () {
        if (vatSessionService.project.projectStatusList[period] >= constant.ProjectStatusEnum.AccountMapSubmitted) {
            swal({
                title: $translate.instant('WarningTitle'),
                text: $translate.instant('IsConfirmManualReClassify').formatObj({ status: vatCommonService.getProjectStautsEnumDesc(vatSessionService.project.projectStatusList[period]) }),
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: $translate.instant('Yes'),
                cancelButtonText: $translate.instant('No'),
                closeOnConfirm: true,
                closeOnCancel: true
            },
            function (isConfirm) {
                if (isConfirm) {
                    doSaveManualReclassification();
                }
                else {
                    swal.close();
                }
            });
        }
        else {
            doSaveManualReclassification();
        }
    };


    function doSaveVoucherReclassification() {
        $log.debug("start saveVoucherReclassification ");
        $scope.isSearching = false;
        constructReMapVoucherModel($scope.selectedVouchers, selectedRemapType, $scope.processTypeId);
        $log.debug($scope.editVoucherRModel);
        $log.debug($scope.selectedVouchers);

        var stdDto = _.where($scope.stdAccountList, { code: $scope.editVoucherRModel.stdCode })[0];
        var updateStateStr = "";
        if (!_.isNull(stdDto)) {
            //var directStr = stdDto.direction === "1" ? $translate.instant('StandardAccountDebit') : $translate.instant('StandardAccountCredit');
            updateStateStr = stdDto.code + "-" + stdDto.fullName + ":"
                            + $translate.instant('AccountVoucher_Debit') + ":" + $scope.editVoucherRModel.reMapDebit + "  "
                            + $translate.instant('AccountVoucher_Credit') + ":" + $scope.editVoucherRModel.reMapCredit;
        }
        logDto.ID = PWC.newGuid();
        logDto.CreateTime = new Date();
        logDto.UpdateTime = new Date();
        logDto.OperationObject = $scope.enterpriseCode;
        logDto.OperationContent = $scope.editVoucherRModel.reMapName;
        logDto.UpdateState = updateStateStr;

        vatReductionService.saveVoucherReclassification($scope.editVoucherRModel).success(function (or) {
            if (!_.isNull(or) && !_.isUndefined(or)) {
                if (or.result) {
                    $('#voucherReclassificationModal').modal('hide');
                    getReMapItemByCode($scope.editVoucherRModel.code);
                    var status = getStatusByCurrentStatus(false);
971
                    vatCommonService.setProjectStatus(project.id, period, status, constant.DictionaryDictKey.WFAccountMap, enums.FinishStatusEnum.NotFinished);
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
                    vatOperationLogService.addOperationLog(logDto);
                    InitEnterpriseSubject();
                    SweetAlert.success($translate.instant('VoucherReMappingSuccess'));
                }
                else {
                    logDto.UpdateState = $translate.instant('AccountReMappingFail');
                    vatOperationLogService.addOperationLog(logDto);
                    SweetAlert.warning($translate.instant(or.resultMsg));
                }
            }
            else {
                logDto.UpdateState = $translate.instant('AccountReMappingFail');
                vatOperationLogService.addOperationLog(logDto);
                SweetAlert.warning($translate.instant('AccountReMappingFail'));
            }
        });
    }

    //保存凭证重分类数据
    var saveVoucherReclassification = function () {
        if (vatSessionService.project.projectStatusList[period] >= constant.ProjectStatusEnum.AccountMapSubmitted) {
            swal({
                title: $translate.instant('WarningTitle'),
                text: $translate.instant('IsConfirmVoucherReClassify').formatObj({ status: vatCommonService.getProjectStautsEnumDesc(vatSessionService.project.projectStatusList[period]) }),
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: $translate.instant('Yes'),
                cancelButtonText: $translate.instant('No'),
                closeOnConfirm: true,
                closeOnCancel: true
            },
            function (isConfirm) {
                if (isConfirm) {
                    doSaveVoucherReclassification();
                }
                else {
                    swal.close();
                }
            });
        }
        else {
            doSaveVoucherReclassification();
        }
    };


    //编辑重对应记录
    var editReMapItem = function () {
        $log.debug("editReMapItem");
        $log.debug($scope.selectedVouchers);
        $scope.isSearching = false;
        $scope.processTypeId = enums.processType.Edit;

        var selectedRows = $scope.gridApiReclassificationItem.selection.getSelectedRows();
        if (!_.isNull(selectedRows) && !_.isUndefined(selectedRows)) {
            if (selectedRows.length === 0) {
                SweetAlert.warning($translate.instant('AccountReMappingSelectOne'));
                return false;
            }
            $log.debug(selectedRows);
            var selectedRemapItem = selectedRows[0];
            var reMapTypeId = selectedRemapItem.reMappTypeId;
            if (reMapTypeId === enums.vatReMapType.ReMapVoucher) {
                $log.debug("edit voucher remap");
                $scope.isSearching = true;
                setAutoCompleteDataSource("reMapStdAutoComplete");
                if (_.isNull($scope.selectedVouchers) || $scope.selectedVouchers.length === 0) {
                    $scope.selectedVouchers = selectedRemapItem.vouchers;
                }

                var vStdDto = _.where($scope.stdAccountList, { code: selectedRemapItem.stdCode })[0];
                var vOriginalState = "";
                if (!_.isNull(vStdDto)) {
                    vOriginalState = vStdDto.code + "-" + vStdDto.fullName + ":"
                            + $translate.instant('AccountVoucher_Debit') + ":" + selectedRemapItem.remapDebit + "  "
                            + $translate.instant('AccountVoucher_Credit') + ":" + selectedRemapItem.remapCredit;
                }

                logDto.OperationName = $translate.instant('EditVoucherReMap');
                logDto.OperationType = enums.vatLogOperationTypeEnum.AM_EditVoucherClass;
                logDto.OriginalState = vOriginalState;

                $log.debug($scope.selectedVouchers);
                $('#voucherReclassificationModal').modal('show');
            }

            if (reMapTypeId === enums.vatReMapType.ReMapCust) {
                $log.debug("edit cust remap");
                setAutoCompleteDataSource("reMapCustStdAutoComplete");
                initReMapCustModel(constant.Operation.Edit, enums.vatReMapType.ReMapCust, selectedRemapItem);

                var vCustStdDto = _.where($scope.stdAccountList, { code: selectedRemapItem.stdCode })[0];
                var vCustOriginalState = "";
                if (!_.isNull(vStdDto)) {
                    vCustOriginalState = vCustStdDto.code + "-" + vCustStdDto.fullName + ":"
                            + $translate.instant('AccountVoucher_Debit') + ":" + selectedRemapItem.remapDebit + "  "
                            + $translate.instant('AccountVoucher_Credit') + ":" + selectedRemapItem.remapCredit;
                }

                logDto.OperationName = $translate.instant('EditCustRemap');
                logDto.OperationType = enums.vatLogOperationTypeEnum.AM_EditManualClass;
                logDto.OriginalState = vCustOriginalState;

                $('#manualReclassificationModal').modal('show');
            }
        }
    }

    //删除重对应记录
    var deleteReMapItem = function () {
        $log.debug("deleteReMapItem");
        var selectedRows = $scope.gridApiReclassificationItem.selection.getSelectedRows();
        $scope.processTypeId = enums.processType.Delete;
        if (selectedRows.length === 0) {
            SweetAlert.warning($translate.instant('AccountReMappingSelectOne'));
            return false;
        }

        if (!_.isNull(selectedRows) && !_.isUndefined(selectedRows)) {
            var selectedRemapItem = selectedRows[0];
            $log.debug(selectedRemapItem);
            deleteReMappingRecords(selectedRemapItem);
        }

    }


    //提交科目对应
    var submitAccountMap = function () {
        if (vatSessionService.project.projectStatusList[period] < constant.ProjectStatusEnum.Imported) {
            SweetAlert.warning($translate.instant('NotAllowSubmitAccountMap'));
            return false;
        }
        vatReductionService.submitAccountMapping(enums.vatReMapType.ReMapVoucher, enums.vatReMapType.ReMapCust).success(function (ret) {
            if (ret.result) {
                BSPLService.GenerateBSPL(vatSessionService.project.id, vatSessionService.month).success(function () {
                    $scope.isSubmitted = true;
                    var status = getStatusByCurrentStatus(true);
1111
                    vatCommonService.setProjectStatus(project.id, period, constant.ProjectStatusEnum.AccountMapSubmitted
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
                                                      , constant.DictionaryDictKey.WFAccountMap, enums.FinishStatusEnum.Finished);
                    SweetAlert.success($translate.instant('AccountMappingSubmitComplete'));
                }).error(function () {
                    SweetAlert.error('生成报表失败');
                });
            }
            else {
                SweetAlert.error($translate.instant('CallbackError').formatObj({ errorMsg: ret.resultMsg }));
            }
        });
    };


    //撤销科目对应
    var undoAccountMap = function () {

        //已提交状态时不用提醒直接撤销
        if (vatSessionService.project.projectStatusList[period] === constant.ProjectStatusEnum.AccountMapSubmitted) {
            $scope.isSubmitted = false;
            var status = getStatusByCurrentStatus(false);
1132
            vatCommonService.setProjectStatus(project.id, period, status, constant.DictionaryDictKey.WFAccountMap, enums.FinishStatusEnum.NotFinished);
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
            SweetAlert.success($translate.instant('UndoAccountMappingComplete'));
        }


        //到底已生成之后需要提醒确认之后再撤销
        if (vatSessionService.project.projectStatusList[period] >= constant.ProjectStatusEnum.Generated) {
            swal({
                title: $translate.instant('WarningTitle'),
                text: $translate.instant('IsConfirmUndoMap').formatObj({ status: vatCommonService.getProjectStautsEnumDesc(vatSessionService.project.projectStatusList[period]) }),
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: $translate.instant('Yes'),
                cancelButtonText: $translate.instant('No'),
                closeOnConfirm: true,
                closeOnCancel: true
            },
            function (isConfirm) {
                if (isConfirm) {
                    $scope.isSubmitted = false;
                    var status = getStatusByCurrentStatus(false);
1154
                    vatCommonService.setProjectStatus(project.id, period, status, constant.DictionaryDictKey.WFAccountMap, enums.FinishStatusEnum.NotFinished);
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175
                    SweetAlert.success($translate.instant('UndoAccountMappingComplete'));
                }
                else {
                    swal.close();
                }
            });
        }
        else {
            $scope.isSubmitted = false;
        }
    }

    var onReMapGridRowSelectionChanged = function (entity) {
        $log.debug("onReMapGridRowSelectionChanged");
        $scope.reMappId = entity.remapId;
        $scope.reMapItem = entity;
        if (entity.reMappTypeId === enums.vatReMapType.ReMapVoucher) {
            selectedRemapType = enums.vatReMapType.ReMapVoucher;
            var selectedReMapRow = $scope.gridApiReclassificationItem.selection.getSelectedRows()[0];
            $log.debug(selectedReMapRow);
            if (!_.isNull(selectedReMapRow) && !_.isUndefined(selectedReMapRow)) {
                $scope.selectedVouchers = selectedReMapRow.vouchers;//当前选择的重对应记录关联的vouchers
                $log.debug($scope.selectedVouchers);
            }
            initReMapVoucherModel(constant.Operation.Edit, selectedReMapRow, enums.vatReMapType.ReMapVoucher);

        }

        if (entity.reMappTypeId === enums.vatReMapType.ReMapCust) {
            selectedRemapType = enums.vatReMapType.ReMapCust;
            initReMapCustModel(constant.Operation.Add, -1, null);
        }
    }


    var closeModal = function (e) {
        var buttonId = e.target.id;
        if (!_.isUndefined(buttonId) && !_.isNull(buttonId)) {
            if (_.isEqual(buttonId, "btnCloseStdReMapResult")) {
                $('#stdReMapResultModal').modal('hide');
            }

            if (_.isEqual(buttonId, "btnCloseVoucherRemap")) {
                $scope.isSearching = false;
            }

            if (_.isEqual(buttonId, "btnCloseVouchersDetail")) {
                $('#voucherDetailModal').modal('hide');
            }
        }
    }


    //获取标准科目重对应结果
    var getStdRemapResult = function () {
        //todo: period = -1 is only for test
        vatReductionService.getStdRemapResult(period).success(function (or) {
            if (!_.isUndefined(or) && !_.isNull(or)) {
                if (or.result) {
                    $log.debug("getStdRemapResult success");
                    if (!_.isUndefined(or.data) && !_.isNull(or.data)) {
                        $log.debug(or.data);
                        $scope.gridOptionsStdReMapResult.data = or.data;
                        $('#stdReMapResultModal').modal('show');
                    }
                }
                else {
                    SweetAlert.warning($translate.instant(or.resultMsg));
                }

            }
            else {
                SweetAlert.warning($translate.instant('AccountReMappingFail'));
            }
        });
    }


    function setStdAccountIsLeaf(e) {
        var selectedCode = !_.isUndefined(e.selectedItem.code) ? e.selectedItem.code : e.selectedItem;
        var stdAccount = _.where($scope.stdAccountList, { code: selectedCode })[0];
        if (!_.isUndefined(stdAccount)) {
            $scope.stdAccountIsLeaf = !stdAccount.hasChildren;
        }
    }

    function isStdCodeLeafNode(codeValue) {
        var stdAccount = _.where($scope.stdAccountList, { code: codeValue })[0];
        if (!_.isUndefined(stdAccount)) {
            $scope.stdAccountIsLeaf = !stdAccount.hasChildren;
        }
    }

    function onSelectionChangedHandlerVoucherRemap(e) {
        setStdAccountIsLeaf(e);
        $scope.selectedStdCode = !_.isUndefined(e.selectedItem.code) ? e.selectedItem.code : e.selectedItem;
    }

    function onSelectionChangedHandlerCustRemap(e) {
        setStdAccountIsLeaf(e);
        $scope.selectedStdCode = !_.isUndefined(e.selectedItem.code) ? e.selectedItem.code : e.selectedItem;
    }


    function calcVoucherDebitCredit(vocuhers) {
        var sumDebit = 0.00;
        var sumCredit = 0.00;
        $.each(vocuhers, function (index, element) {
            sumDebit += PWC.parseFloatRound(element.debit, 2);
            sumCredit += PWC.parseFloatRound(element.credit, 2);
        });

        $scope.editVoucherRModel.reMapDebit = PWC.parseFloatRound(sumDebit.toString(), 2);
        $scope.editVoucherRModel.reMapCredit = PWC.parseFloatRound(sumCredit.toString(), 2);
    }


    //提交之前构建editVoucherRModel
    function constructReMapVoucherModel(selectedVouchers, reMapType, processTypeId) {
        var selectedRemapItem = $scope.gridApiReclassificationItem.selection.getSelectedRows()[0];
        var stdCode = "";
        if (!_.isNull(selectedRemapItem) && !_.isUndefined(selectedRemapItem)) {
            switch (processTypeId) {
                case enums.processType.Add:
                    stdCode = "";
                    break;
                case enums.processType.Edit:
                    stdCode = selectedRemapItem.stdCode;
                    break;
            }
        }

        $scope.editVoucherRModel = {
            //reMapId: !_.isUndefined(selectedRemapItem) ? selectedRemapItem.remapId : PWC.newGuid(),
            remapBatchId: !_.isUndefined(selectedRemapItem) ? selectedRemapItem.remapBatchId : PWC.newGuid(),
            code: $scope.enterpriseCode,
            stdCode: $scope.selectedStdCode,//$("#reMapStdAutoComplete").dxAutocomplete("instance").option("value"),
            reMapStdCode: stdCode,
            reMapName: $("#voucherName").val(),
            reMapDebit: PWC.round($("#voucherDebit").val(), 2),
            reMapCredit: PWC.round($("#voucherCredit").val(), 2),
            reMapReason: $("#voucherReason").val(),
            reMapTypeId: reMapType,
            reMapDateTime: new Date(),
            period: period,
            reMapProcessTypeId: processTypeId,
            vouchers: selectedVouchers
        };
    }

    //初始化凭证重分类的model:editVoucherRModel
    function initReMapVoucherModel(operation, reMapModel, reMapType) {
        $log.debug("initReMapVoucherModel");
        if (_.isEqual(operation, constant.Operation.Add)) {
            $scope.editVoucherRModel = {
                //reMapId: PWC.newGuid(),
                remapBatchId: PWC.newGuid(),
                code: $scope.enterpriseCode,
                stdCode: "",
                reMapStdCode: "",
                reMapName: "",
                reMapDebit: 0.00,
                reMapCredit: 0.00,
                reMapReason: "",
                reMapTypeId: reMapType,
                reMapDateTime: new Date(),
                period: period,
                reMapProcessTypeId: $scope.processTypeId,
                vouchers: _.isNull(reMapModel) || _.isUndefined(reMapModel) ? null : reMapModel.vouchers
            };
            $scope.selectedVouchers = null;
        }

        if (_.isEqual(operation, constant.Operation.Edit)) {
            $scope.editVoucherRModel = {
                //reMapId: reMapModel.remapId,
                remapBatchId: reMapModel.remapBatchId,
                code: $scope.enterpriseCode,
                stdCode: reMapModel.stdCode,
                reMapStdCode: reMapModel.stdCode,
                reMapName: reMapModel.reMappName,
                reMapDebit: reMapModel.remapDebit,
                reMapCredit: reMapModel.remapCredit,
                reMapReason: reMapModel.reMappReason,
                reMapTypeId: reMapType,
                reMapDateTime: new Date(),
                period: period,
                reMapProcessTypeId: $scope.processTypeId,
                vouchers: _.isNull(reMapModel) || _.isUndefined(reMapModel) ? null : reMapModel.vouchers
            };
            //$("#reMapStdAutoComplete").dxAutocomplete("instance").option("value", reMapModel.stdCode);
            $scope.selectedStdCode = reMapModel.stdCode;
        }
    }


    function constructReMapCustModel(reMapType) {
        $scope.editManualRModel = {
            code: $scope.enterpriseCode,
            stdCode: $scope.selectedStdCode,//$("#reMapCustStdAutoComplete").dxAutocomplete("instance").option("value"),
            reMapName: $("#manualName").val(),
            reMapDebit: PWC.round($("#manualDebitBal").val(), 2),
            reMapCredit: PWC.round($("#manualCreditBal").val(), 2),
            reMapReason: $("#manualReason").val(),
            reMapTypeId: reMapType,
            period: period
        };
    }


    //初始化手动重分类的model:editManualRModel
    //operation: 操作类型。 constant.Operation.Add: 添加操作; constant.Operation.Edit:编辑操作
    //reMapType: 重对应类型。永远为2
    //reMapItem: 选中的重对应数据。Add操作时为NULL
    function initReMapCustModel(operation, reMapType, reMapItem) {
        if (_.isEqual(operation, constant.Operation.Add)) {
            $scope.editManualRModel = {
                code: "",
                stdCode: "",
                reMapName: "",
                reMapDebit: 0.00,
                reMapCredit: 0.00,
                reMapReason: "",
                reMapTypeId: reMapType,
                period: period
            }
            $scope.selectedVouchers = null;
        }

        if (_.isEqual(operation, constant.Operation.Edit) && !_.isNull(reMapItem)) {
            $scope.editManualRModel = {
                code: reMapItem.acctCode,
                stdCode: reMapItem.stdCode,
                reMapName: reMapItem.reMappName,
                reMapDebit: reMapItem.remapDebit,
                reMapCredit: reMapItem.remapCredit,
                reMapReason: reMapItem.reMappReason,
                reMapTypeId: reMapType,
                period: period
            }
            //$("#reMapCustStdAutoComplete").dxAutocomplete("instance").option("value", reMapItem.stdCode);
            $scope.selectedStdCode = reMapItem.stdCode;
        }

    }


    //获取重对应结果(包含凭证信息)
    function getReMapItemByCode(estCode) {
        vatReductionService.getClassificationList(estCode).success(function (or) {
            if (!_.isNull(or) && !_.isUndefined(or)) {
                if (or.result) {
                    $log.debug(or.data);
                    $scope.gridOptionsReclassificationItem.data = or.data;
                    $log.debug("getReMapItemByCode assigned value finished");
                    $log.debug($scope.gridOptionsReclassificationItem.data);
                }
                else {
                    SweetAlert.warning($translate.instant(or.resultMsg));
                }
            }
            else {
                SweetAlert.warning($translate.instant('AccountReMappingFail'))
            }

        });
    }


    function deleteReMappingRecords(model) {
        logDto.ID = PWC.newGuid();
        logDto.CreateTime = new Date();
        logDto.UpdateTime = new Date();
        logDto.OperationObject = $scope.enterpriseCode;
        logDto.OperationContent = model.reMappName;
        logDto.OriginalState = "";

        var vStdDto = _.where($scope.stdAccountList, { code: model.stdCode })[0];
        var vUpdateState = "";
        if (!_.isNull(vStdDto) && !_.isUndefined(vStdDto)) {
            vUpdateState = vStdDto.code + "-" + vStdDto.fullName + ":"
                    + $translate.instant('AccountVoucher_Debit') + ":" + model.remapDebit + "  "
                    + $translate.instant('AccountVoucher_Credit') + ":" + model.remapCredit;
        }
        logDto.UpdateState = vUpdateState;

        if (model.reMappTypeId === enums.vatReMapType.ReMapVoucher) {
            logDto.OperationType = enums.vatLogOperationTypeEnum.AM_DeleteVoucherClass;
            logDto.OperationName = $translate.instant('DeleteVoucherRemap');
        }


        if (model.reMappTypeId === enums.vatReMapType.ReMapCust) {
            logDto.OperationType = enums.vatLogOperationTypeEnum.AM_DeleteManualClass;
            logDto.OperationName = $translate.instant('DeleteCustRemap');
        }

        vatReductionService.deleteReMappingRecords(model).success(function (or) {
            if (!_.isNull(or) && !_.isUndefined(or)) {
                if (or.result) {
                    getReMapItemByCode(model.acctCode);
                    vatOperationLogService.addOperationLog(logDto);
                    InitEnterpriseSubject();
                    SweetAlert.success($translate.instant('AccountReMappingSuccess'));

                }
                else {
                    logDto.UpdateState = $translate.instant('AccountReMappingFail');
                    vatOperationLogService.addOperationLog(logDto);
                    SweetAlert.warning($translate.instant(or.resultMsg));
                }
            }
            else {
                logDto.UpdateState = $translate.instant('AccountReMappingFail');
                vatOperationLogService.addOperationLog(logDto);
                SweetAlert.warning($translate.instant('AccountReMappingFail'));
            }
        });
    }


    function showReMapVouchers(entity) {
        $log.debug("showReMapVouchers");
        $log.debug(entity);
        if (!_.isUndefined(entity) && !_.isNull(entity)) {
            //重分类明细选中凭证
            if (!_.isNull(entity.vouchers) && !_.isUndefined(entity.vouchers)) {
                var remapVouchers = _.filter(entity.vouchers, function (v) {
                    var chk = _.find(entity.remapIdes, function (id) { return id === v.remapId; });
                    return chk;
                });
                $scope.gridOptionsVouchersDetail.data = remapVouchers;//entity.vouchers;
                $('#voucherDetailModal').modal('show');
            }
            else { //企业科目列表选中凭证                     
                vatReductionService.getVouchersByCode(entity.code, period).success(function (or) {
                    if (!_.isNull(or) && !_.isUndefined(or)) {
                        if (or.result) {
                            $scope.gridOptionsVouchersDetail.data = or.data;
                            $('#voucherDetailModal').modal('show');
                        }
                        else {
                            SweetAlert.warning($translate.instant(or.resultMsg));
                        }
                    }
                    else {
                        SweetAlert.warning($translate.instant('GetVoucherDetailsFail'));
                    }
                });

            }

        }
    }

    function getAllStdCodes(id) {
        var tree = $("#vatStadardAccountTreeTable").fancytree("getTree");
        var treeSourceData = tree.toDict(true);
        $scope.stdAccountList = [];
        $.each(treeSourceData.children, function (index, item) {
            $.each(item.children, function (index1, item1) {
                getChildStdCodes(item1, $scope.stdAccountList);
            })
        });
        $("#" + id).dxAutocomplete("instance").option("dataSource", $scope.stdAccountList);
    }

    function getChildStdCodes(stdParent, stdLists) {
        stdParent.data.directionDesc = stdParent.data.direction === "1" ? $translate.instant('AccountVoucher_Direction_Debit')
                                       : $translate.instant('AccountVoucher_Direction_Credit');
        stdLists.push(stdParent.data);
        if (!_.isNull(stdParent.children) && !_.isUndefined(stdParent.children)) {
            $.each(stdParent.children, function (index, item) {
                item.data.directionDesc = item.direction === "1" ? $translate.instant('AccountVoucher_Direction_Debit')
                   : $translate.instant('AccountVoucher_Direction_Credit');
                getChildStdCodes(item, stdLists);
            })
        }
    };

    function getStdCodeListRescurive() {
        var tree = $("#vatStadardAccountTreeTable").fancytree("getTree");
        var treeSourceData = tree.toDict(true);
        if ($scope.stdAccountList.length === 0) {
            $scope.stdAccountList = [];
            $.each(treeSourceData.children, function (index, item) {
                $.each(item.children, function (index1, item1) {
                    getChildStdCodes(item1, $scope.stdAccountList);
                })
            });
        }
    }

    function setAutoCompleteDataSource(id) {
        getStdCodeListRescurive();
        $("#" + id).dxAutocomplete("instance").option("dataSource", $scope.stdAccountList);
    }

    //获取未对应企业科目数量
    function getEnterpriseAccountNotMapped() {
        vatReductionService.getEnterpriseAccountNotMapped(vatSessionService.month).success(function (data) {
            $scope.notMappedCount = vatSessionService.enterpriseAccountNotMappedCount = data;
            $scope.$emit('notMappedCount', $scope.notMappedCount);
        });
    };


    //获取TB、ERP导入类型
    function getPeriodInfor() {
        vatImportService.getImportType(vatSessionService.project.id, period).success(function (data) {
            $scope.importTypeId = data;
            vatImportService.IsImportAuditAdjustOnly(vatSessionService.project.id, period).success(function (or) {
                if (or.result) {
                    $scope.isImportAuditAdjust = or.data;

                }
            });
        });
    }

    function isEnterpriseCodeLeafAcct() {
        var selectedRow = $scope.gridApiSubject.selection.getSelectedRows()[0];
        if (!_.isNull(selectedRow) && !_.isUndefined(selectedRow)) {
            if (selectedRow.isLeaf === 1) {
                return true;
            }
            else {
                return false;
            }
        }
    }

    //重置凭证重对应的valudation results
    function resetVoucerRemapValidation() {
        $scope.stdAccountIsLeaf = true;
        $scope.addVoucherReclassificationItem.$setPristine();
    }

    //重置手工重对应的valudation results
    function resetCustRemapValidation() {
        $scope.stdAccountIsLeaf = true;
        $scope.addReclassificationItem.$setPristine();
    }


    //通过科目的$$treeLevel来决定使用哪个class
    //cellTemplate :'<div class="text-align-left-padding ui-grid-cell-contents {{grid.appScope.rowLevel(row.entity)}}"><span>{{row.entity.codeNameDesc}}<span></div>'
    function rowLevel(row) {
        var cls = '';
        cls = 'rowLevel-' + row.$$treeLevel;
        return cls;
    }

    function getExportData() {
        var temp = [];
        var data = $scope.gridOptionsSubjectList.data;
        data.forEach(function (d) {
            var item = {};
            item.code = d.code;
            item.stdCode = d.stdCode;
            item.fullName = d.fullName;
            item.stdFullName = d.stdFullName;
            item.directionDescription = d.directionDescription;
            item.stdDirection = d.stdDirection;
            temp.push(item);
        });

        $scope.exportDataList = temp;
        $log.debug($scope.exportDataList);
    }


    function exportData() {
        getExportData();
        $scope.isToPrint = true;
    }


    (function initialize() {
        //初始化右侧标准科目的树,使用jquery fancytree的方式来显示树,所以需要用到ajax的方式
        var stdAccountUrl = '/AccountMapping/stdAccounts/getStdAccountHierarchy';
        commonWebService.initVATFancyTreeAjax('vatStadardAccountTreeTable', stdAccountUrl, mapStdAccount);
        getEnterpriseAccountNotMapped();

        $scope.stdAccountsCategories = [];
        $scope.stdAccountList = [];
        // i18nService.setCurrentLang("zh-cn");
        //默认显示科目重分类grid
        $scope.ImportErrorTag = true;
        //借贷方向
        $scope.directionList = [
                { id: 1, name: $translate.instant('StandardAccountDebit') },
                { id: -1, name: $translate.instant('StandardAccountCredit') }
        ];

        //标准科目类别
        $scope.acctPropList = [
            { id: 0, name: 'UnKnow' },
            { id: 1, name: $translate.instant('StandardAccountAcctPropAsset') },
            { id: 2, name: $translate.instant('StandardAccountAcctPropDebt') },
            { id: 3, name: $translate.instant('StandardAccountAcctPropCommon') },
            { id: 4, name: $translate.instant('StandardAccountAcctPropInterest') },
            { id: 5, name: $translate.instant('StandardAccountAcctPropCost') },
            { id: 6, name: $translate.instant('StandardAccountAcctPropProfitAndLoss') }
        ];

        //操作菜单选择框
        $scope.processMenuList = [
            //{ key: 'UnSelected', name: $translate.instant('AccountMappingMenuUnSelect') },
            { key: constant.AccountMappingProcessKey.Submit, name: $translate.instant('AccountMappingSubmit') },
            { key: constant.AccountMappingProcessKey.Undo, name: $translate.instant('AccountMappingUndo') }
        ];

        $scope.currentProcess = {};
        $scope.currentProcess.selected = {
            key: constant.AccountMappingProcessKey.UnSelected, name: $translate.instant('AccountMappingMenuUnSelect')
        };

        //********start 重对应autocomplete scope变量定义********

        $scope.maxStdCodeLength = constant.ReMapMaxLength.MaxStdCodeLength;
        $scope.autocompletePlaceholder = $translate.instant('MaxLengthTips').formatObj({ maxLength: $scope.maxStdCodeLength }) + "  "
                                         + $translate.instant("TypeStandardCode");
        $scope.autocompleteSearchModeStartsWith = "startswith";
        $scope.autocompleteSearchModeContains = "contains";
        $scope.maxTextLength = constant.ReMapMaxLength.MaxTextLength;
        $scope.maxRemarkLength = constant.ReMapMaxLength.MaxRemarkLength;
        $scope.regexNum = "/^(\-)?\d+(\.\d{1,2})?$/"; //带1-2位小数的正数或负数 需要在开头和结尾加'/',不然会报Lexer error  
        $scope.stdAccountIsLeaf = true; //默认不展示错误提示
        $scope.onSelectionChangedHandlerCustRemap = onSelectionChangedHandlerCustRemap;
        $scope.onSelectionChangedHandlerVoucherRemap = onSelectionChangedHandlerVoucherRemap;


        //********end 重对应autocomplete scope变量定义********




        //企业科目列表grid
        $scope.gridOptionsSubjectList = {
            virtualizationThreshold: 50,
            enableColumnResizing: true,
            enableRowSelection: false,
            enableSelectAll: true,
            rowHeight: constant.UIGrid.rowHeight,
            enableRowHeaderSelection: true,
            modifierKeysToMultiSelect: true, //按住Ctrl才能多选 
            enableHorizontalScrollbar: uiGridConstants.scrollbars.enableHorizontalScrollbar,
            enableVerticalScrollbar: uiGridConstants.scrollbars.enableVerticalScrollbar,
            selectionRowHeaderWidth: constant.UIGrid.selectionRowHeaderWidth,
            enableSorting: false,
            enableColumnMenus: true,
            enableFiltering: false,
            showTreeExpandNoChildren: false,
            enableFullRowSelection: false, //是否点击行任意位置后选中,默认为false
            multiSelect: true,// 是否可以选择多个,默认为true;
            columnDefs: [
                {
                    name: $translate.instant('CITProject'), headerCellClass: '', width: '25%', pinnedLeft: true,
                    cellTemplate: '<div class="text-align-left-padding ui-grid-cell-contents"><span>{{row.entity.codeNameDesc}}<span></div>'
                },
                {
                    name: $translate.instant('SubjectDirectionCol'), headerCellClass: '', width: '10%', pinnedLeft: true,
                    cellTemplate: '<div class="text-align-left-padding">'
                                  + '<span>{{row.entity.directionDescription}}</span></div>'
                },
                {
                    name: $translate.instant('SubjectTypeCol'), headerCellClass: '', width: '10%',
                    cellTemplate: '<div class="text-align-left-padding">'
                                 + ' <span>{{row.entity.acctPropStr}}</span></div>'
                },
                {
                    name: $translate.instant('DebitRelevantAmtCol'), headerCellClass: '', width: '20%',
                    cellTemplate: '<div class="text-align-right-padding">'
                                 + ' <span>{{row.entity.debitBal}}</span></div>'
                },
                {
                    name: $translate.instant('CreditRelevantAmtCol'), headerCellClass: '', width: '20%',
                    cellTemplate: '<div class="text-align-right-padding">'
                                 + ' <span>{{row.entity.creditBal}}</span></div>'
                },
                {
                    name: $translate.instant('DebitReclassificationCol'), headerCellClass: '', width: '15%',
                    cellTemplate: '<div class="text-align-right-padding">'
                                 + ' <span>{{row.entity.remapDebit}}</span></div>'
                },
                {
                    name: $translate.instant('CreditReclassificationCol'), headerCellClass: '', width: '15%',
                    cellTemplate: '<div class="text-align-right-padding">'
                                 + ' <span>{{row.entity.remapCredit}}</span></div>'
                },
                {
                    name: $translate.instant('StandardSubjectCol'), headerCellClass: '', width: '20%',
                    cellTemplate: '<div class="text-align-left-padding"><span title="{{row.entity.stdResult}}"><i class="material-icons map-status-flag" ng-if="row.entity.stdCode == null">flag</i>{{row.entity.stdResult}}</span></div>'
                },
                {
                    name: $translate.instant('RelatedVoucherCol'), headerCellClass: '', width: '10%',
                    cellTemplate: '<div class="text-align-left-padding" ng-click="grid.appScope.showReMapVouchers(row.entity)">'
                                  + ' <i class="fa fa-clipboard" style="color:#E84100;" aria-hidden="true" ng-if="row.entity.isShowVoucher"></i></div>'
                },
                {
                    name: $translate.instant('IsLeafCol'), headerCellClass: '', width: '15%', visible: false,
                    cellTemplate: '<div class="text-align-right-padding"><span>{{row.entity.isLeaf}}</span></div>'
                },
                {
                    name: $translate.instant('StdAcctPropCol'), headerCellClass: '', width: '15%', visible: false,
                    cellTemplate: '<div class="text-align-right-padding"><span>{{row.entity.stdAcctProp}}</span></div>'
                },
                {
                    name: $translate.instant('EnterAcctPropCol'), headerCellClass: '', width: '15%', visible: false,
                    cellTemplate: '<div class="text-align-right-padding"><span>{{row.entity.enterAcctProp}}</span></div>'
                },
            ],
            onRegisterApi: function (gridApi) {
                $scope.gridApiSubject = gridApi;
                $scope.gridSelectCount = $scope.gridApiSubject.selection.getSelectedRows().length;
                var onRowsRenderedOff = gridApi.core.on.rowsRendered(null, function () {
                    onRowsRenderedOff(); // run once
                    PWC.triggerRowSelectOnClick('#etsGrid'); // requires '.ui-grid-canvas'
                });
                // call resize every 500 ms for 5 s after modal finishes opening - usually only necessary on a bootstrap modal
                //$interval(function () {
                //    $scope.gridApiSubject.core.handleWindowResize();
                //}, 500, 60 * 60 * 8);

                $interval(function () {
                    $scope.gridApiSubject.core.handleWindowResize();
                }, 500, 60 * 60 * 8);

                $scope.gridApiSubject.selection.on.rowSelectionChanged($scope, function (row) {
                    var msg = 'row selected ' + row.isSelected;
                    $log.debug(msg);
                    $log.debug(row);
                    if (row.isSelected) {
                        $scope.showReclassificationItemGrid(row.entity);
                    }
                });
            }
        };

        //重分类明细grid
        $scope.gridOptionsReclassificationItem = {
            virtualizationThreshold: 50,
            enableColumnResizing: true,
            rowHeight: constant.UIGrid.rowHeight,
            selectionRowHeaderWidth: constant.UIGrid.selectionRowHeaderWidth,
            enableSorting: false,
            enableColumnMenus: false,
            enableHorizontalScrollbar: uiGridConstants.scrollbars.NEVER,
            enableRowSelection: true,
            enableSelectAll: false,
            enableRowHeaderSelection: false,
            enableFiltering: false,
            showTreeExpandNoChildren: false,
            multiSelect: false,
            columnDefs: [
                {
                    name: $translate.instant('ReclassificationIdCol'), headerCellClass: '', visible: false,
                    cellTemplate: '<div class="text-align-left-padding" ng-show = "false"><span>{{row.entity.remapId}}<span></div>'
                },
                {
                    name: $translate.instant('ReclassificationBatchIdCol'), headerCellClass: '', visible: false,
                    cellTemplate: '<div class="text-align-left-padding" ng-show = "false"><span>{{row.entity.remapBatchId}}<span></div>'
                },
                {
                    name: $translate.instant('ImportErrorPopUpNoCol'), width: '5%', headerCellClass: '',
                    cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.num}}<span></div>'
                },
                {
                    name: $translate.instant('ReclassificationNameCol'), width: '15%', headerCellClass: '',
                    cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.reMappName}}</span></div>'
                },
                {
                    name: $translate.instant('AdjustmentReasonCol'), width: '15%', headerCellClass: '',
                    cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.reMappReason}}</span></div>'
                },
                {
                    name: $translate.instant('AccountReMappingCustomerCode'), headerCellClass: '', visible: false,
                    cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.customerCode}}</span></div>'
                },
                {
                    name: $translate.instant('AccountReMappingDebit'), width: '15%', headerCellClass: '',
                    cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.remapDebit}}</span></div>'
                },
                {
                    name: $translate.instant('AccountReMappingCredit'), width: '15%', headerCellClass: '',
                    cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.remapCredit}}</span></div>'
                },
                {
                    name: $translate.instant('STANDARDProject'), width: '15%', headerCellClass: 'text-align-center',
                    cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.stdCode}}</span></div>'
                    //cellTemplate: '<div class="text-align-left-padding"><span><i class="material-icons map-status-flag" ng-if="row.entity.etsCode === null">flag</i>{{row.entity.etsCode === null ? "未对应" : (row.entity.etsCode + "-" + row.entity.etsName)}}</span></div>'
                },
                {
                    name: $translate.instant('AccountReMappingType'), width: '10%', headerCellClass: 'text-align-center',
                    cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.reMappTypeDesc}}</span></div>'
                    //cellTemplate: '<div class="text-align-left-padding"><span><i class="material-icons map-status-flag" ng-if="row.entity.etsCode === null">flag</i>{{row.entity.etsCode === null ? "未对应" : (row.entity.etsCode + "-" + row.entity.etsName)}}</span></div>'
                },
                {
                    name: $translate.instant('RelatedVoucherCol'), width: '10%', headerCellClass: '',
                    cellTemplate: '<div class="text-align-left-padding" ng-click="grid.appScope.showReMapVouchers(row.entity)"><span></span>'
                        + ' <i class="fa fa-clipboard" style="color:#E84100;" aria-hidden="true" ng-if = "row.entity.vouchers != null" ></i></div>'
                },
                //{
                //    name: $translate.instant('RelatedAttachmentCol'), width: '5%', headerCellClass: '',
                //    cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.attachments}}</span></div>'
                //}
            ],
            onRegisterApi: function (gridApi) {
                $scope.gridApiReclassificationItem = gridApi;
                // call resize every 500 ms for 5 s after modal finishes opening - usually only necessary on a bootstrap modal
                //$interval(function () {
                //    $scope.gridApiReclassificationItem.core.handleWindowResize();
                //}, 500, 60 * 60 * 8);


                $scope.gridApiReclassificationItem.selection.on.rowSelectionChanged($scope, function (row) {
                    var msg = 'row selected ' + row.isSelected;
                    $log.debug(msg);
                    $log.debug(row);
                    if (row.isSelected) {
                        $scope.onReMapGridRowSelectionChanged(row.entity);
                    }
                });

            }
        };


        //标准科目对应结果
        $scope.gridOptionsStdReMapResult = {
            virtualizationThreshold: 50,
            enableColumnResizing: true,
            rowHeight: constant.UIGrid.rowHeight,
            selectionRowHeaderWidth: constant.UIGrid.selectionRowHeaderWidth,
            enableSorting: false,
            enableColumnMenus: false,
            enableHorizontalScrollbar: uiGridConstants.scrollbars.enableHorizontalScrollbar,
            enableVerticalScrollbar: uiGridConstants.scrollbars.enableVerticalScrollbar,
            enableRowSelection: true,
            enableSelectAll: false,
            enableRowHeaderSelection: false,
            enableFiltering: false,
            showTreeExpandNoChildren: false,
            multiSelect: false,
            columnDefs: [
               {
                   name: $translate.instant('STANDARDProject'), headerCellClass: '', width: '15%',
                   cellTemplate: '<div class="text-align-left-padding" ><span>{{row.entity.stdCodeAndStdName}}</span></div>'
               },
               {
                   name: $translate.instant('FinalDebit'), headerCellClass: '', width: '15%',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.stdDebitStr}}</span></div>'
               },
               {
                   name: $translate.instant('FinalCredit'), headerCellClass: '', width: '15%',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.stdCreditStr}}</span></div>'
               },
               {
                   name: $translate.instant('AccountVoucher_DataGrid_ColAcctCodeAndNameShow'), headerCellClass: '', width: '10%',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.acctCodeAndAcctName}}</span></div>'
               },
               {
                   name: $translate.instant('DebitRelevantAmtCol'), headerCellClass: '', width: '10%',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.debitStr}}</span></div>'
               },
               {
                   name: $translate.instant('CreditRelevantAmtCol'), headerCellClass: '', width: '10%',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.creditStr}}</span></div>'
               },
               {
                   name: $translate.instant('DebitReclassificationCol'), headerCellClass: '', width: '10%',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.remapDebitStr}}</span></div>'
               },
               {
                   name: $translate.instant('CreditReclassificationCol'), headerCellClass: '', width: '10%',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.remapCreditStr}}</span></div>'
               },
               {
                   name: $translate.instant('ConfirmDebit'), headerCellClass: '', width: '10%',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.acctRealDebitStr}}</span></div>'
               },
               {
                   name: $translate.instant('ConfirmCredit'), headerCellClass: '', width: '10%',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.acctRealCreditStr}}</span></div>'
               }
            ],
            onRegisterApi: function (gridApi) {
                $scope.gridApiStdMapResult = gridApi;
                // call resize every 500 ms for 5 s after modal finishes opening - usually only necessary on a bootstrap modal
                $interval(function () {
                    $scope.gridApiStdMapResult.core.handleWindowResize();
                }, 500, 60 * 60 * 8);
            }
        }


        //凭证信息
        $scope.gridOptionsVouchersDetail = {
            virtualizationThreshold: 50,
            enableColumnResizing: true,
            rowHeight: constant.UIGrid.rowHeight,
            selectionRowHeaderWidth: constant.UIGrid.selectionRowHeaderWidth,
            enableSorting: false,
            enableColumnMenus: false,
            enableHorizontalScrollbar: uiGridConstants.scrollbars.NEVER,
            enableRowSelection: false,
            enableSelectAll: false,
            enableRowHeaderSelection: false,
            enableFiltering: false,
            showTreeExpandNoChildren: false,
            multiSelect: false,
            columnDefs: [
               {
                   name: $translate.instant('JournalQJ'), headerCellClass: '',
                   cellTemplate: '<div class="text-align-left-padding" ><span>{{row.entity.period}}</span></div>'
               },
               {
                   name: $translate.instant('AccountVoucher_DataGrid_ColDate'), headerCellClass: '',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.date | date:"yyyy-MM-dd"}}</span></div>'
               },
               {
                   name: $translate.instant('AccountVoucher_DataGrid_ColGroup'), headerCellClass: '',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.group}}</span></div>'
               },
               {
                   name: $translate.instant('AccountVoucher_DataGrid_ColVID'), headerCellClass: '',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.vid}}</span></div>'
               },
               {
                   name: $translate.instant('AccountVoucher_DataGrid_ColSummary'), headerCellClass: '',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.summary}}</span></div>'
               },
               {
                   name: $translate.instant('AccountVoucher_DataGrid_ColAcctCodeAndNameShow'), headerCellClass: '',
                   cellTemplate: '<div class="text-align-left-padding" ><span>{{row.entity.acctCodeAndNameShow}}</span></div>'
               },
               {
                   name: $translate.instant('AccountVoucher_DataGrid_ColStdCodeAndNameShow'), headerCellClass: '',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.stdCodeAndNameShow}}</span></div>'
               },
               {
                   name: $translate.instant('AccountVoucher_Debit'), headerCellClass: '',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.debit}}</span></div>'
               },
               {
                   name: $translate.instant('AccountVoucher_Credit'), headerCellClass: '',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.credit}}</span></div>'
               },
               {
                   name: $translate.instant('AccountReMappingCustomerCode'), headerCellClass: '',
                   cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.customerCode}}</span></div>'
               }
               //{
               //    name: $translate.instant('itemID'), headerCellClass: '',
               //    cellTemplate: '<div class="text-align-left-padding"><span>{{row.entity.itemID}}</span></div>'
               //}                                         
            ],
            onRegisterApi: function (gridApi) {
                $scope.gridApiVouchersDetail = gridApi;
                //$scope.gridApiVouchersDetail.core.handleWindowResize();
                // call resize every 500 ms for 5 s after modal finishes opening - usually only necessary on a bootstrap modal
                $interval(function () {
                    $scope.gridApiVouchersDetail.core.handleWindowResize();
                }, 500, 60 * 60 * 8);
            }
        }



        //var editorValue = ko.observable("").extend({
        //    dxValidator: {
        //        validationRules: [{
        //            type: 'required',
        //            message: 'Specify this value'
        //        }]
        //    }
        //});

        //重对应 autocomplete配置
        $scope.dxAutocompleteOptions = {
            CustRemapAutocomplete: {
                dataSource: $scope.stdAccountList,
                minSearchLength: 1,
                maxItemCount: 7,
                searchTimeout: 50,
                placeholder: $scope.autocompletePlaceholder,
                valueExpr: 'code',
                searchExpr: 'code',
                focusStateEnabled: true,
                itemTemplate: 'acStdItemTemplate',
                //validationError: editorValue.dxValidator.validationError,
                onSelectionChanged: $scope.onSelectionChangedHandlerCustRemap,
                bindingOptions: {
                    maxLength: 'maxStdCodeLength',
                    searchMode: 'autocompleteSearchModeContains',
                    value: 'selectedStdCode'
                    //disabled: "!queryParams.selectors.accountCode.selected.id",                   

                }

            },

            VoucherRemapAutoComplete: {
                dataSource: $scope.stdAccountList,
                minSearchLength: 1,
                maxItemCount: 7,
                searchTimeout: 50,
                placeholder: $scope.autocompletePlaceholder,
                valueExpr: 'code',
                searchExpr: 'code',
                focusStateEnabled: true,
                itemTemplate: 'acStdItemTemplate',
                //validationError: editorValue.dxValidator.validationError,
                onSelectionChanged: $scope.onSelectionChangedHandlerVoucherRemap,
                bindingOptions: {
                    maxLength: 'maxStdCodeLength',
                    searchMode: 'autocompleteSearchModeContains',
                    value: 'selectedStdCode'
                    //disabled: "!queryParams.selectors.accountCode.selected.id",                   

                }
            }
        }


        $scope.popTheParentCode = function () {
            $scope.isShowStdFilter = true;
            $scope.selectedStdCode = "";
        }

        InitEnterpriseSubject();
        InitNgData();
        //默认隐藏重分类明细grid
        setErrorWrapCssDefault();
        getPeriodInfor();
        $scope.manualMapAlter = true; //手工对应时,“是否重新对应”的提示只出现一次

        $scope.stateChanged = stateChanged;

        $scope.autoMap = autoMap;

        $scope.ClearMap = ClearMap;

        $scope.toggle1 = toggle1;

        $scope.toggleStdSubject = toggleStdSubject;

        $scope.mapStdAccount = mapStdAccount;

        $scope.getReclassificationItemGridHeight = getReclassificationItemGridHeight;

        $scope.toggleReclassificationGridTab = toggleReclassificationGridTab;

        $scope.manualReclassificate = manualReclassificate;

        $scope.voucherReclassificate = voucherReclassificate;

        $scope.showReclassificationItemGrid = showReclassificationItemGrid;

        $scope.saveManualReclassification = saveManualReclassification;

        $scope.saveVoucherReclassification = saveVoucherReclassification;

        $scope.getStdRemapResult = getStdRemapResult;

        $scope.closeModal = closeModal;

        $scope.submitAccountMap = submitAccountMap;

        $scope.undoAccountMap = undoAccountMap;

        $scope.showOperateLogPop = showOperateLogPop;


        checkUserOrganizationPermissionList();
        initReMapVoucherModel(constant.Operation.Add, null, -1);
        initReMapCustModel(constant.Operation.Add, -1, null);

        $scope.showReMapVouchers = showReMapVouchers;
        $scope.rowLevel = rowLevel;
        $scope.editReMapItem = editReMapItem;
        $scope.deleteReMapItem = deleteReMapItem;
        $scope.onReMapGridRowSelectionChanged = onReMapGridRowSelectionChanged;
        $scope.enterpriseCode;//选中的企业科目代码    
        $scope.selectedVouchers;//凭证对应时选中的分录
        $scope.reMappId;//重对应明细记录的id
        $scope.isSubmitted = vatSessionService.project.projectStatusList[vatSessionService.month] <= constant.ProjectStatusEnum.Imported
                             ? false : true;
        $scope.isSearching = false;
        $scope.remapTitle = "";
        $scope.processTypeId = enums.processType.UnDefined;
        $scope.userId = vatSessionService.logUser.id;
        $scope.exportData = exportData;
        $scope.isToPrint = false;
        $scope.exportDataList = [];


        //watch $scope.selectedVouchers的长度变化
        $scope.$watch('selectedVouchers.length', function (newValue, oldValue) {
            $log.debug("start to watch selectedVouchers");
            $log.debug($scope.selectedVouchers);
            calcVoucherDebitCredit($scope.selectedVouchers);
        });

        $scope.$watch('selectedStdCode', function (newValue, oldValue) {
            isStdCodeLeafNode(newValue);
        });

        //执行exportData(),table: exportTable ng-repeat绘制完成后执行
        $scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
            if ($scope.isToPrint) {
                export_table_to_excel('exportTable', 'AccountMapping', 'xlsx', '');
            }
            $scope.isToPrint = false;
        });


    })();
}
]);