123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- /**
- * Created by CSL on 2017-07-19.
- * dispExpr: F8*(L-1); expression: "@('8') * (L-1)";
- * 说明:F后跟行号,L替换人工系数值,@后跟ID。用到L的规则必须有labourCoeID属性(反过来不要求),
- * 用到费率的规则必须有feeRateID属性,当有该属性时,会自动显示费率值。
- */
- let defaultBillTemplate = {
- ID: 15,
- name: "清单缺省",
- calcItems: [
- {
- ID: 1,
- code: "1",
- name: "定额直接费",
- dispExpr: "F2+F3+F4",
- expression: "@('2')+@('3')+@('4')",
- statement: "人工费+材料费+机械费",
- feeRate: null,
- memo: ''
- },
- {
- ID: 2,
- code: "1.1",
- name: "人工费",
- dispExpr: "HJ",
- expression: "HJ",
- statement: "合计",
- feeRate: 50,
- fieldName: 'labour',
- memo: ''
- },
- {
- ID: 3,
- code: "1.2",
- name: "材料费",
- dispExpr: "HJ",
- expression: "HJ",
- statement: "合计",
- feeRate: 30,
- fieldName: 'material',
- memo: ''
- },
- {
- ID: 4,
- code: "1.3",
- name: "机械费",
- dispExpr: "HJ",
- expression: "HJ",
- statement: "合计",
- feeRate: 20,
- fieldName: 'machine',
- memo: ''
- },
- {
- ID: 5,
- code: "2",
- name: "企业管理费",
- dispExpr: "F1",
- expression: "@('1')",
- statement: "定额直接费",
- feeRate: null,
- fieldName: 'manage',
- memo: ''
- },
- {
- ID: 6,
- code: "3",
- name: "利润",
- dispExpr: "F1",
- expression: "@('1')",
- statement: "定额直接费",
- feeRate: null,
- fieldName: 'profit',
- memo: ''
- },
- {
- ID: 7,
- code: "4",
- name: "风险费用",
- dispExpr: "F1",
- expression: "@('1')",
- statement: "定额直接费",
- feeRate: null,
- fieldName: 'risk',
- memo: ''
- },
- {
- ID: 8,
- code: "5",
- name: "综合单价",
- dispExpr: "F1+F5+F6+F7",
- expression: "@('1')+@('5')+@('6')+@('7')",
- statement: "定额直接费+企业管理费+利润+风险费用",
- feeRate: null,
- fieldName: 'common',
- memo: ''
- }
- ]
- };
- class CalcProgram {
- constructor(project){
- this.project = project;
- this.datas = [];
- this.calc = new Calculation();
- project.registerModule(ModuleNames.calc_program, this);
- };
- getSourceType () {
- return ModuleNames.calc_program;
- };
- loadData (datas) {
- this.datas = datas;
- };
- doAfterUpdate (err, data) {
- if(!err){
- // do
- }
- };
- // 经测试,全部编译一次耗时0.003~0.004秒。耗时基本忽略不计。
- compileAllTemps(){
- let calcFeeRates = this.project.FeeRate.datas.rates;
- let calcLabourCoes = this.project.labourCoe.datas.coes;
- let calcTemplates = this.project.calcProgram.datas.templates;
- calcTemplates.push(defaultBillTemplate);
- this.calc.compilePublics(calcFeeRates, calcLabourCoes, feeType, rationCalcBase);
- for (let ct of calcTemplates){
- this.calc.compileTemplate(ct);
- };
- // 存储费率临时数据,报表用。
- if (this.calc.saveForReports.length > 0){
- let saveDatas = {};
- saveDatas.projectID = projectInfoObj.projectInfo.ID;
- saveDatas.calcItems = this.calc.saveForReports;
- CommonAjax.post('/calcProgram/saveCalcItems', saveDatas, function (data) {
- this.calc.saveForReports = [];
- });
- };
- };
- calculate(treeNode){
- let me = this;
- me.calc.calculate(treeNode);
- // 还原,防止出现混乱影响下次计算
- delete treeNode.data.baseTotalPrice;
- delete treeNode.data.gatherType;
- // 存储、刷新本结点、所有父结点
- if (treeNode.changed) {
- me.saveAndCalcParents(treeNode);
- delete treeNode.changed;
- };
- };
- saveAndCalcParents(treeNode) {
- if (treeNode.parent) {
- projectObj.converseCalculateBills(treeNode.parent);
- };
- let data = {ID: treeNode.data.ID, projectID: projectObj.project.ID(), fees: treeNode.data.fees};
- let newDta = {'updateType': 'ut_update', 'updateData': data};
- let newDataArr = [];
- newDataArr.push(newDta);
- projectObj.project.pushNow('', treeNode.sourceType, newDataArr);
- projectObj.mainController.refreshTreeNode([treeNode]);
- };
- getCalcDatas(treeNode){
- let me = this;
- let rst = [];
- let isRation = treeNode.sourceType === me.project.Ration.getSourceType();
- let isBill = treeNode.sourceType === me.project.Bills.getSourceType();
- let isLeafBill = isBill && treeNode.source.children && treeNode.source.children.length === 0;
- let isBillPriceCalc = me.project.projSetting.billsCalcMode === billsPrice;
- if (isRation) {
- //
- }
- else if (isLeafBill) {
- let ct = '';
- if (treeNode.children && treeNode.children.length > 0){
- if (treeNode.children[0].sourceType == me.project.Ration.getSourceType()){
- ct = childrenType.ration;
- }
- else if (treeNode.children[0].sourceType == me.project.VolumePrice.getSourceType()){
- ct = childrenType.volumePrice;
- };
- }
- else{
- ct = childrenType.formula;
- };
- if (ct == childrenType.ration){
- if (isBillPriceCalc){ // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算
- }
- else{ // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
- treeNode.data.gatherType = CP_GatherType.rations;
- };
- }
- else if (ct == childrenType.volumePrice){
- let totalPrice = 10000;
- treeNode.data.baseTotalPrice = totalPrice;
- }
- else if (ct == childrenType.formula){
- let totalPrice = 20000;
- treeNode.data.baseTotalPrice = totalPrice;
- };
- }
- else if (isBill){ // 父清单:汇总子清单的费用类别
- treeNode.data.gatherType = CP_GatherType.bills;
- };
- me.calculate(treeNode);
- rst = treeNode.data.calcTemplate.calcItems;
- return rst;
- }
- }
|