'use strict';

// CSL, 2019-01-18

//允许使用的工料机类型：人工、普通材料、混凝土、砂浆、配合比、商品混凝土、商品砂浆、其他材料费、机械台班、机械组成物、机上人工、主材、设备、企业管理费、利润
if(typeof allowGljType !== 'undefined'){
    allowGljType = [1, 201, 202, 203, 204, 205, 206, 207, 301, 302, 303, 4, 5, 6, 7];
}
if(typeof allowComponent !== 'undefined'){
    //允许含有组成物的工料机类型：混凝土、砂浆、配合比、机械台班、主材
    allowComponent = [202, 203, 204, 301, 4];
}
if(typeof componentType !== 'undefined'){
    //可以作为组成物的工料机类型：普通材料、机械组成物、机上人工、主材
    componentType = [201, 302, 303, 4];
}
if(typeof machineAllowComponent !== 'undefined'){
    //允许含有组成物的机械工料机类型：机械台班
    machineAllowComponent = [301];
}
if(typeof machineComponent !== 'undefined'){
    //可以作为机械工料机组成物的工料机类型：机械组成物、机上人工
    machineComponent = [302, 303];
}
if(typeof materialAllowComponent !== 'undefined'){
    //允许含有组成物的材料工料机类型：混凝土、砂浆、配合比
    materialAllowComponent = [202, 203, 204];
}
if(typeof materialComponent !== 'undefined'){
    //可以作为材料工料机组成物的工料机类型：普通材料
    materialComponent = [201];
}

(function overwriteFeeTypes() {
    if (typeof cpFeeTypes == 'undefined') return;
    cpFeeTypes = [
        {type: 'marketLabour', name: '人工费'},
        {type: 'marketMaterial', name: '材料费'},
        {type: 'marketMachine', name: '施工机具使用费'},
        {type: 'labour', name: '定额人工费'},
        {type: 'material', name: '定额材料费'},
        {type: 'machine', name: '定额施工机具使用费'},
        {type: 'mainMaterial', name: '主材费'},
        {type: 'equipment', name: '设备费'},
        {type: 'manage', name: '管理费'},
        {type: 'profit', name: '利润'},
        {type: 'safeAndEnvironment', name: '安全文明施工与环境保护费'},
        {type: 'tempFacility', name: '临时设施费'},
        {type: 'rain', name: '雨季施工增加费'},
        {type: 'protect', name: '已完工程及设备保护费'},
        {type: 'retest', name: '工程定位复测费'},
        {type: 'secondHandling', name: '二次搬运费'},
        {type: 'specialArea', name: '特殊地区施工增加费'},
        {type: 'night', name: '夜间施工增加费'},
        // {type: 'safeMeasures', name: '安全文明施工费'},
        {type: 'basement', name: '白天在地下室施工增加费'},
        {type: 'winter', name: '冬季施工增加费'},
        {type: 'risk', name: '风险费'},
        {type: 'force', name: '规费'},
        {type: 'tax', name: '税金'},
        {type: 'common', name: '工程造价'}
    ];
})();

function overwriteRationCalcBases (taxType){
    if (typeof rationCalcBases == 'undefined') return;
    for (let key in rationCalcBases) delete rationCalcBases[key];

    rationCalcBases['人工费'] = function (node, isTender) {
        return calcTools.rationBaseFee(node, [gljType.LABOUR], priceTypes.ptMarketPrice, isTender);
    };
    rationCalcBases['材料费'] = function (node, isTender) {
        return calcTools.rationBaseFee(node, baseMaterialTypes, priceTypes.ptMarketPrice, isTender);
    };
    rationCalcBases['施工机具使用费'] = function (node, isTender) {
        return calcTools.rationBaseFee(node, baseMachineTypes, priceTypes.ptMarketPrice, isTender);
    };
    rationCalcBases['主材费'] = function (node, isTender) {
        return calcTools.rationBaseFee(node, [gljType.MAIN_MATERIAL], priceTypes.ptMarketPrice, isTender);
    };
    rationCalcBases['设备费'] = function (node, isTender) {
        return calcTools.rationBaseFee(node, [gljType.EQUIPMENT], priceTypes.ptMarketPrice, isTender);
    };
    rationCalcBases['定额人工费'] = function (node, isTender) {
        return calcTools.rationBaseFee(node, [gljType.LABOUR], priceTypes.ptBasePrice, isTender);
    };
    rationCalcBases['定额材料费'] = function (node, isTender) {
        return calcTools.rationBaseFee(node, baseMaterialTypes, priceTypes.ptBasePrice, isTender);
    };
    rationCalcBases['定额施工机具使用费'] = function (node, isTender) {
        return calcTools.rationBaseFee(node, baseMachineTypes, priceTypes.ptBasePrice, isTender);
    };
    rationCalcBases['人工工日'] = function (node, isTender) {
        return calcTools.labourDays(node, isTender);
    };
    rationCalcBases['甲供人工费'] = function (node, isTender) {
        return calcTools.partASupplyFee(node, '甲供人工费', isTender, false);
    };
    rationCalcBases['甲供材料费'] = function (node, isTender) {
        return calcTools.partASupplyFee(node, '甲供材料费', isTender, false);
    };
    rationCalcBases['甲供施工机具使用费'] = function (node, isTender) {
        return calcTools.partASupplyFee(node, '甲供施工机具使用费', isTender, false);
    };
    rationCalcBases['甲供主材费'] = function (node, isTender) {
        return calcTools.partASupplyFee(node, '甲供主材费', isTender, false);
    };
    rationCalcBases['甲供设备费'] = function (node, isTender) {
        return calcTools.partASupplyFee(node, '甲供设备费', isTender, false);
    };
    rationCalcBases['甲定人工费'] = function (node, isTender) {
        return calcTools.partASupplyFee(node, '甲定人工费', isTender, false);
    };
    rationCalcBases['甲定材料费'] = function (node, isTender) {
        return calcTools.partASupplyFee(node, '甲定材料费', isTender, false);
    };
    rationCalcBases['甲定施工机具使用费'] = function (node, isTender) {
        return calcTools.partASupplyFee(node, '甲定施工机具使用费', isTender, false);
    };
    rationCalcBases['甲定主材费'] = function (node, isTender) {
        return calcTools.partASupplyFee(node, '甲定主材费', isTender, false);
    };
    rationCalcBases['甲定设备费'] = function (node, isTender) {
        return calcTools.partASupplyFee(node, '甲定设备费', isTender, false);
    };
    rationCalcBases['暂估材料费'] = function (node, isTender) {
        return calcTools.estimateFee(node, true, isTender);
    };
    rationCalcBases['分包人工费'] = function (node, isTender) {
        if (node.data.isSubcontract)
            return calcTools.rationBaseFee(node, [gljType.LABOUR], priceTypes.ptMarketPrice, isTender)
        else
            return 0;
    };
    rationCalcBases['分包材料费'] = function (node, isTender) {
        if (node.data.isSubcontract)
            return calcTools.rationBaseFee(node, baseMaterialTypes, priceTypes.ptMarketPrice, isTender)
        else
            return 0;
    };
    rationCalcBases['分包施工机具使用费'] = function (node, isTender) {
        if (node.data.isSubcontract)
            return calcTools.rationBaseFee(node, baseMachineTypes, priceTypes.ptMarketPrice, isTender)
        else
            return 0;
    };
    rationCalcBases['分包主材费'] = function (node, isTender) {
        if (node.data.isSubcontract)
            return calcTools.rationBaseFee(node, [gljType.MAIN_MATERIAL], priceTypes.ptMarketPrice, isTender)
        else
            return 0;
    };
    rationCalcBases['分包设备费'] = function (node, isTender) {
        if (node.data.isSubcontract)
            return calcTools.rationBaseFee(node, [gljType.EQUIPMENT], priceTypes.ptMarketPrice, isTender)
        else
            return 0;
    };
    rationCalcBases['分包定额人工费'] = function (node, isTender) {
        if (node.data.isSubcontract)
            return calcTools.rationBaseFee(node, [gljType.LABOUR], priceTypes.ptBasePrice, isTender)
        else
            return 0;
    };
    rationCalcBases['分包定额材料费'] = function (node, isTender) {
        if (node.data.isSubcontract)
            return calcTools.rationBaseFee(node, baseMaterialTypes, priceTypes.ptBasePrice, isTender)
        else
            return 0;
    };
    rationCalcBases['分包定额施工机具使用费'] = function (node, isTender) {
        if (node.data.isSubcontract)
            return calcTools.rationBaseFee(node, baseMachineTypes, priceTypes.ptBasePrice, isTender)
        else
            return 0;
    };
    rationCalcBases['分包人工工日'] = function (node, isTender) {
        if (node.data.isSubcontract)
            return calcTools.labourDays(node, isTender)
        else
            return 0;
    };
};

//清单基数相关
(() => {
    if(typeof baseFigureMap !== 'undefined'){
        baseFigureMap = {
            //与清单直接关联
            '分部分项工程费': {base: 'FBFXGCF', fixedFlag: fixedFlag.SUB_ENGINERRING, class: 'FBFX'},
            '分部分项定额人工费': {base: 'FBFXDEJJRGF', fixedFlag: fixedFlag.SUB_ENGINERRING, class: 'FBFX'},
            '分部分项定额材料费': {base: 'FBFXDEJJCLF', fixedFlag: fixedFlag.SUB_ENGINERRING, class: 'FBFX'},
            '分部分项定额施工机具使用费': {base: 'FBFXDEJJJXF', fixedFlag: fixedFlag.SUB_ENGINERRING, class: 'FBFX'},
            '分部分项主材费': {base: 'FBFXZCF', fixedFlag: fixedFlag.SUB_ENGINERRING, class: 'FBFX'},
            '分部分项设备费': {base: 'FBFXSBF', fixedFlag: fixedFlag.SUB_ENGINERRING, class: 'FBFX'},
            '分部分项人工工日': {base: 'FBFXRGGR', fixedFlag: fixedFlag.SUB_ENGINERRING, class: 'FBFX'},
            '措施项目费': {base: 'CSXMF', fixedFlag: fixedFlag.MEASURE, class: 'CSXM'},
            '组织措施项目费': {base: 'ZZCSXMF', fixedFlag: fixedFlag.CONSTRUCTION_ORGANIZATION, class: 'CSXM'},
            '组织措施项目定额人工费': {base: 'ZZCSXMDEJJRGF', fixedFlag: fixedFlag.CONSTRUCTION_ORGANIZATION, class: 'CSXM'},
            '组织措施项目定额材料费': {base: 'ZZCSXMDEJJCLF', fixedFlag: fixedFlag.CONSTRUCTION_ORGANIZATION, class: 'CSXM'},
            '组织措施项目定额施工机具使用费': {base: 'ZZCSXMDEJJJXF', fixedFlag: fixedFlag.CONSTRUCTION_ORGANIZATION, class: 'CSXM'},
            '技术措施项目费': {base: 'JSCSXMF', fixedFlag: fixedFlag.CONSTRUCTION_TECH, class: 'CSXM'},
            '技术措施项目定额人工费': {base: 'JSCSXMDEJJRGF', fixedFlag: fixedFlag.CONSTRUCTION_TECH, class: 'CSXM'},
            '技术措施项目定额材料费': {base: 'JSCSXMDEJJCLF', fixedFlag: fixedFlag.CONSTRUCTION_TECH, class: 'CSXM'},
            '技术措施项目定额施工机具使用费': {base: 'JSCSXMDEJJJXF', fixedFlag: fixedFlag.CONSTRUCTION_TECH, class: 'CSXM'},
            '技术措施项目主材费': {base: 'JSCSXMZCF', fixedFlag: fixedFlag.CONSTRUCTION_TECH, class: 'CSXM'},
            '技术措施项目设备费': {base: 'JSCSXMSBF', fixedFlag: fixedFlag.CONSTRUCTION_TECH, class: 'CSXM'},
            '技术措施项目人工工日': {base: 'JSCSXMRGGR', fixedFlag: fixedFlag.CONSTRUCTION_TECH, class: 'CSXM'},
            '其他项目费': {base: 'QTXMF', fixedFlag: fixedFlag.OTHER, class: 'QTXM'},
            '规费': {base: 'GF', fixedFlag: fixedFlag.CHARGE, class: 'GF'},
            '税金': {base: 'SJ', fixedFlag: fixedFlag.TAX, class: 'SJ'},
            //不与清单直接关联
            '建筑面积': {base: 'JZMJ', class: 'FBFX'},
            '甲供定额人工费': {base: 'JGDEJJRGF', class: 'RCJ'},
            '甲供定额材料费': {base: 'JGDEJJCLF', class: 'RCJ'},
            '甲供定额施工机具使用费': {base: 'JGDEJJJXF', class: 'RCJ'},
            '甲供人工费': {base: 'JGRGF', class: 'RCJ'},
            '甲供材料费': {base: 'JGCLF', class: 'RCJ'},
            '甲供施工机具使用费': {base: 'JGJXF', class: 'RCJ'},
            '甲供主材费': {base: 'JGZCF', class: 'RCJ'},
            '甲供设备费': {base: 'JGSBF', class: 'RCJ'},
            '甲定定额人工费': {base: 'JDDEJJRGF', class: 'RCJ'},
            '甲定定额材料费': {base: 'JDDEJJCLF', class: 'RCJ'},
            '甲定定额施工机具使用费': {base: 'JDDEJJJXF', class: 'RCJ'},
            '甲定人工费': {base: 'JDRGF', class: 'RCJ'},
            '甲定材料费': {base: 'JDCLF', class: 'RCJ'},
            '甲定施工机具使用费': {base: 'JDJXF', class: 'RCJ'},
            '甲定主材费': {base: 'JDZCF', class: 'RCJ'},
            '甲定设备费': {base: 'JDSBF', class: 'RCJ'},
            '暂估材料费(从子目汇总)': {base: 'ZGCLFFZM', class: 'RCJ'},
            '分包费': {base: 'FBF', class: 'FBF'},
            '分包定额人工费': {base: 'FBDEJJRGF', class: 'FBF'},
            '分包定额材料费': {base: 'FBDEJJCLF', class: 'FBF'},
            '分包定额施工机具使用费': {base: 'FBDEJJJXF', class: 'FBF'},
            '分包主材费': {base: 'FBZCF', class: 'FBF'},
            '分包设备费': {base: 'FBSBF', class: 'FBF'},
            '分包人工工日': {base: 'FBRGGR', class: 'FBF'},
            '税前工程造价': {base: 'SQGCZJ', class: 'SQGCZJ',
                cycleCalcRef: [fixedFlag.SUB_ENGINERRING, fixedFlag.OTHER, fixedFlag.CHARGE],   //循环计算相关固定行，由于计算排除了本身，不用判断措施项目
                multiRef: [fixedFlag.SUB_ENGINERRING, fixedFlag.MEASURE, fixedFlag.OTHER, fixedFlag.CHARGE]},//相关固定行
        }
    }
})();

if(typeof module !== 'undefined'){
    module.exports = {
        getBillsCalcMode: getBillsCalcMode
    };
}

function getBillsCalcMode() {
  return 1
}