gljUtil.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /**
  2. * Created by zhang on 2018/6/7.
  3. */
  4. let gljUtil = {
  5. calcProjectGLJQuantity: function (projectGLJDatas, rationGLJDatas, rationDatas, billsDatas, q_decimal, _, scMathUtil, isReport) {
  6. let project_gljs = projectGLJDatas.gljList,
  7. mixRatioMap = projectGLJDatas.mixRatioMap,
  8. com_electrovalence = projectGLJDatas.com_electrovalence;
  9. let rations = rationDatas;
  10. let rationMap = _.indexBy(rations, 'ID');
  11. let quantityMap = {};
  12. let rationGljGroup = _.groupBy(rationGLJDatas, 'projectGLJID');
  13. let IDarray = this.getSubdivisionAndTechBillsLeavesID(billsDatas); //分别取分部分项和技术措施项目的所有叶子清单ID
  14. let billIDs = IDarray[0],
  15. tech_billIDS = IDarray[1];
  16. let materialCalcMap = {};
  17. //养护没有分部分项消耗量这一说的所以不用管
  18. let qField = "quantity";
  19. let mField = "materialQuantity"; //材料计算的工料机消耗量
  20. let elecIndex = ""; //记住电的标识
  21. for (let pglj of project_gljs) {
  22. let pg_index = this.getIndex(pglj, this.gljKeyArray);
  23. pglj[qField] = 0;
  24. pglj[mField] = 0;
  25. let gljGroup = rationGljGroup[pglj.id] ? rationGljGroup[pglj.id] : []; //定额工料机没有,有可能是定额类型的工料机
  26. let result = this.getQuantityPerGLJ(gljGroup, rations, rationMap, pglj, billIDs, tech_billIDS, q_decimal, _, scMathUtil);
  27. pglj[qField] = result.quantity;
  28. pglj.tenderQuantity = result.tenderQuantity;
  29. quantityMap[pg_index] = pglj;
  30. if (pglj.code == gljUtil.getElecCode() && pglj.name == '电' && pglj.unit == "kW·h") elecIndex = pg_index;
  31. if (pglj.unit_price.calcMaterial == 1) materialCalcMap[pg_index] = true;
  32. }
  33. //计算做为组成物的消耗量
  34. for (let pkey in mixRatioMap) {
  35. let mixRatioList = mixRatioMap[pkey];
  36. for (let m of mixRatioList) {
  37. let m_index = this.getIndex(m, this.gljKeyArray);
  38. let m_glj = quantityMap[m_index];
  39. let p_glj = quantityMap[pkey];
  40. if (m_glj && p_glj && !gljUtil.isConcreteType(p_glj.type)) { //混凝土、砂浆、配合比组成物的消耗量在定额下已经有体现了,不用再计算进去
  41. let quantity = scMathUtil.roundForObj(parseFloat(p_glj[qField]) * parseFloat(m.consumption), q_decimal);
  42. let tenderQuantity = scMathUtil.roundForObj(parseFloat(p_glj.tenderQuantity) * parseFloat(m.consumption), q_decimal);
  43. m_glj[qField] = scMathUtil.roundForObj(parseFloat(m_glj[qField]) + quantity, q_decimal);
  44. m_glj.tenderQuantity = scMathUtil.roundForObj(parseFloat(m_glj.tenderQuantity) + tenderQuantity, q_decimal);
  45. }
  46. }
  47. }
  48. //计算经过场外运输损耗后的总消耗量
  49. for (let pglj of project_gljs) {
  50. let offSiteTransportLossRate = this.getOffSiteTransportLossRate(pglj);
  51. pglj.offSiteTransportLossRate = parseFloat(offSiteTransportLossRate); //scMathUtil.roundForObj(offSiteTransportLossRate,getDecimal("glj.unitPrice")) ;这里再取小数位数太麻烦了,暂时用保存的吧
  52. offSiteTransportLossRate = offSiteTransportLossRate / 100;
  53. pglj.transportLossQuantity = scMathUtil.roundForObj(pglj.quantity * offSiteTransportLossRate, q_decimal);
  54. pglj.quantity = scMathUtil.roundForObj(pglj.quantity + pglj.transportLossQuantity, q_decimal);
  55. pglj.tenderTransportLossQuantity = scMathUtil.roundForObj(pglj.tenderQuantity * offSiteTransportLossRate, q_decimal);
  56. pglj.tenderQuantity = scMathUtil.roundForObj(pglj.tenderQuantity + pglj.tenderTransportLossQuantity, q_decimal);
  57. if (isReport)
  58. pglj.quantity = pglj.tenderQuantity;
  59. }
  60. //材料计算中,工料机的消耗量
  61. //材料计算中,有可能A包含B,B包含C。。。。。等情况,为避免循环计算,只多计算一次,不做再深的嵌套处理
  62. // 1.先计算做为父工料机的材料计算消耗量
  63. if (projectGLJDatas.freightList) this.setMaterialCalcQuantity(quantityMap, materialCalcMap, true, projectGLJDatas.freightList, q_decimal, _, scMathUtil); //运费计算中工料机的消耗量
  64. if (projectGLJDatas.originalList) this.setMaterialCalcQuantity(quantityMap, materialCalcMap, true, projectGLJDatas.originalList, q_decimal, _, scMathUtil); //原价计算中工料机的消耗量
  65. // 2.再计算做为子工料机的材料计算消耗量
  66. if (projectGLJDatas.freightList) this.setMaterialCalcQuantity(quantityMap, materialCalcMap, false, projectGLJDatas.freightList, q_decimal, _, scMathUtil); //运费计算中工料机的消耗量
  67. if (projectGLJDatas.originalList) this.setMaterialCalcQuantity(quantityMap, materialCalcMap, false, projectGLJDatas.originalList, q_decimal, _, scMathUtil); //原价计算中工料机的消耗量
  68. //因为材料计算里自采材料产生的消耗量和进行材料计算的父工料机的消耗量有关,所以材料计算中的组成物的消耗量要在上一步的组成物计算完后,再计算自采材料里组成物的消耗量,所认两个组成物计算不能合并,而且乘的值也不同
  69. for (let pkey in mixRatioMap) {
  70. let mixRatioList = mixRatioMap[pkey];
  71. for (let m of mixRatioList) {
  72. let m_index = this.getIndex(m, this.gljKeyArray);
  73. let m_glj = quantityMap[m_index];
  74. let p_glj = quantityMap[pkey];
  75. if (m_glj && p_glj && !gljUtil.isConcreteType(p_glj.type) && p_glj[mField] > 0) { //混凝土、砂浆、配合比组成物的消耗量在定额下已经有体现了,不用再计算进去
  76. let materialQuantity = scMathUtil.roundForObj(parseFloat(p_glj[mField]) * parseFloat(m.consumption), q_decimal);
  77. m_glj[qField] = scMathUtil.roundForObj(parseFloat(m_glj[qField]) + materialQuantity, q_decimal);
  78. m_glj[mField] = scMathUtil.roundForObj(parseFloat(m_glj[mField]) + materialQuantity, q_decimal);
  79. }
  80. }
  81. }
  82. //计算综合电价中,电网电和机械台班的消耗量 - 电有可能做为组成物存在,计算综合电价的各消耗量时,要以电的总消耗量为基础,所以这步要放在最后,即电都计算完成以后
  83. if (com_electrovalence && com_electrovalence.gljList && quantityMap[elecIndex]) {
  84. for (let cg of com_electrovalence.gljList) {
  85. //网电的消耗量=电的总消耗量×加权系数
  86. let eq = scMathUtil.roundForObj(quantityMap[elecIndex][qField] * parseFloat(cg.coe), q_decimal);
  87. if (cg.name == '电网电') {
  88. quantityMap[this.getIndex(cg)][qField] = eq;
  89. } else {
  90. let tquantity = 0;
  91. let w = parseInt(cg.name);
  92. if (w) tquantity = scMathUtil.roundForObj(eq / w, 6);
  93. tquantity = scMathUtil.roundForObj(tquantity * this.getElecCoe(), q_decimal);
  94. let ekey = this.getIndex(cg);
  95. quantityMap[ekey][qField] = tquantity;
  96. //计算机械台班下的组成物的消耗量
  97. if (mixRatioMap[ekey]) {
  98. for (let m of mixRatioMap[ekey]) {
  99. let cmkey = this.getIndex(m);
  100. if (quantityMap[cmkey] && tquantity > 0) { //混凝土、砂浆、配合比组成物的消耗量在定额下已经有体现了,不用再计算进去
  101. let c_m_quantity = scMathUtil.roundForObj(tquantity * parseFloat(m.consumption), 6);
  102. quantityMap[cmkey][qField] = scMathUtil.roundForObj(parseFloat(quantityMap[cmkey][qField]) + c_m_quantity, q_decimal);
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. },
  110. setMaterialCalcQuantity: function (quantityMap, materialCalcMap, isParent, calcList, q_decimal, _, scMathUtil) {
  111. let qField = "quantity";
  112. let p_decimal = 6; //自采定额这里计算结果都看成是中间过程,取6位小数
  113. for (let t of calcList) {
  114. if (quantityMap[t.connect_key] && quantityMap[t.connect_key][qField] > 0) {
  115. let rationIDMap = _.indexBy(t.rations, "ID");
  116. if (t.ration_gljs) {
  117. for (let rg of t.ration_gljs) {
  118. let rIndex = this.getIndex(rg);
  119. let pglj = quantityMap[rIndex];
  120. let ration = rationIDMap[rg.rationID];
  121. if (isParent == true) { //当计算做为材料计算父消耗量时,忽略子消耗量
  122. if (!materialCalcMap[rIndex]) continue
  123. } else { //当计算做为材料计算子消耗量时,忽略父消耗量
  124. if (materialCalcMap[rIndex]) continue
  125. }
  126. if (pglj && ration) {
  127. let rg_quantity = scMathUtil.roundForObj(rg.quantity, q_decimal);
  128. let r_quantity = scMathUtil.roundForObj(ration.quantity, q_decimal);
  129. let result = scMathUtil.roundForObj(rg_quantity * r_quantity, p_decimal);
  130. result = scMathUtil.roundForObj(quantityMap[t.connect_key][qField] * result, p_decimal);
  131. pglj.quantity = scMathUtil.roundForObj(pglj.quantity + result, q_decimal);
  132. pglj.materialQuantity = scMathUtil.roundForObj(pglj.materialQuantity + result, q_decimal);
  133. }
  134. }
  135. }
  136. }
  137. }
  138. },
  139. getOffSiteTransportLossRate: function (pglj) {
  140. let offSiteTransportLossRate; //场外运输损耗率
  141. let handlingLossRate; //每增加一次装卸损耗率
  142. let totalLoadingTimes = 1; //没有材料计算,获取不到装卸总次数,则按1计算
  143. //场外总损耗率=场外运输损耗率%+(装卸总次数-1)*每增加一次装卸损耗率%。
  144. if (pglj.unit_price) {
  145. if (pglj.unit_price.calcMaterial == 1) { //如果是材料计算,则用修改过的新值
  146. offSiteTransportLossRate = pglj.unit_price.offSiteTransportLossRate_n;
  147. handlingLossRate = pglj.unit_price.handlingLossRate_n;
  148. if (pglj.unit_price.totalLoadingTimes && pglj.unit_price.totalLoadingTimes > 1) totalLoadingTimes = parseFloat(pglj.unit_price.totalLoadingTimes)
  149. } else {
  150. offSiteTransportLossRate = pglj.unit_price.offSiteTransportLossRate;
  151. handlingLossRate = pglj.unit_price.handlingLossRate;
  152. }
  153. }
  154. offSiteTransportLossRate = offSiteTransportLossRate ? parseFloat(offSiteTransportLossRate) : 0;
  155. handlingLossRate = handlingLossRate ? parseFloat(handlingLossRate) : 0;
  156. // 场外运输损耗率%+(装卸总次数-1)*每增加一次装卸损耗率%
  157. return (offSiteTransportLossRate + (totalLoadingTimes - 1) * handlingLossRate);
  158. },
  159. getQuantityPerGLJ: function (ration_glj_list, rations, rationMap, pglj, billIDs, tech_billIDS, q_decimal, _, scMathUtil) {
  160. let result = {};
  161. let quantity_sum = 0; //工料机汇总消耗量
  162. let tender_qantity_sum = 0;
  163. for (let rg of ration_glj_list) {
  164. let tem_ration = rationMap[rg.rationID];
  165. let r_quantity = tem_ration ? scMathUtil.roundForObj(tem_ration.quantity, q_decimal) : 0;
  166. let glj_quantity = scMathUtil.roundForObj(rg.quantity, q_decimal);
  167. let tender_r_quantity = r_quantity;
  168. let tender_glj_quantity = glj_quantity;
  169. if (!r_quantity) {
  170. continue;
  171. }
  172. if (!pglj.is_adjust_price) {
  173. tender_glj_quantity = this.getRationGLJTenderQuantity(rg, tem_ration, q_decimal, scMathUtil, pglj);
  174. tender_r_quantity = this.getRationTenderQuantity(tem_ration, q_decimal, scMathUtil);
  175. }
  176. let total = scMathUtil.roundForObj(glj_quantity * r_quantity, q_decimal);
  177. let tender_total = scMathUtil.roundForObj(tender_glj_quantity * tender_r_quantity, q_decimal);
  178. quantity_sum = scMathUtil.roundForObj(quantity_sum + total, q_decimal);
  179. tender_qantity_sum = scMathUtil.roundForObj(tender_qantity_sum + tender_total, q_decimal);
  180. }
  181. for (let ra of rations) { //计算定额类型工料机的消耗量
  182. if (ra.type == this.rationType.gljRation && ra.projectGLJID === pglj.id) {
  183. let r_quantity = scMathUtil.roundForObj(ra.quantity, q_decimal);
  184. r_quantity = r_quantity ? r_quantity : 0;
  185. let tender_r_quantity = r_quantity;
  186. if (!pglj.is_adjust_price) {
  187. tender_r_quantity = this.getRationTenderQuantity(ra, q_decimal, scMathUtil);
  188. }
  189. quantity_sum = scMathUtil.roundForObj(quantity_sum + r_quantity, q_decimal);
  190. tender_qantity_sum = scMathUtil.roundForObj(tender_qantity_sum + tender_r_quantity, q_decimal);
  191. }
  192. }
  193. result.quantity = quantity_sum;
  194. result.tenderQuantity = tender_qantity_sum;
  195. return result;
  196. },
  197. getRationGLJTenderQuantity: function (ration_glj, ration, q_decimal, scMathUtil, projectGLJ) {
  198. let coeMap = {
  199. 1: 'labour', //人工
  200. 2: 'material', //材料
  201. 3: 'machine', //机械
  202. 4: 'main', //主材
  203. 5: 'equipment' //设备
  204. };
  205. let typeString = ration_glj.type + "";
  206. let coeField = "";
  207. for (let key in coeMap) {
  208. if (typeString.indexOf(key) == 0) {
  209. coeField = coeMap[key];
  210. break;
  211. }
  212. }
  213. let coe = 1;
  214. if (projectGLJ && projectGLJ.is_adjust_price == 0) {
  215. coe = ration.quantityCoe && this.isNotEmpty(ration.quantityCoe[coeField]) ? ration.quantityCoe[coeField] : 1;
  216. coe = parseFloat(coe);
  217. } else {
  218. coe = 1;
  219. }
  220. if (coe == 0) coe = 1;
  221. let glj_quantity = scMathUtil.roundForObj(ration_glj.quantity, q_decimal);
  222. return scMathUtil.roundForObj(glj_quantity * coe, q_decimal);
  223. },
  224. getRationTenderQuantity: function (ration, q_decimal, scMathUtil) {
  225. let rationQuantityCoe = this.isNotEmpty(ration.rationQuantityCoe) ? ration.rationQuantityCoe : 1;
  226. rationQuantityCoe = parseFloat(rationQuantityCoe);
  227. if (rationQuantityCoe == 0) rationQuantityCoe = 1;
  228. let r_quantity = ration ? scMathUtil.roundForObj(ration.quantity, q_decimal) : 0;
  229. return scMathUtil.roundForObj(r_quantity * rationQuantityCoe, q_decimal);
  230. },
  231. isNotEmpty: function (str) {
  232. return this.isDef(str) && str != "";
  233. },
  234. getSubdivisionAndTechBillsLeavesID: function (billsDatas) { //分别取分部分项和技术措施项目的所有叶子清单ID
  235. if (typeof (projectObj) !== 'undefined') { //存在,说明在前端调用
  236. return [projectObj.project.Bills.getSubdivisionProjectLeavesID(), projectObj.project.Bills.getTechLeavesID()];
  237. }
  238. let parentMap = {};
  239. let subdivisionBillID = null,
  240. techBillID = null,
  241. sIDs = [],
  242. tIDS = [];
  243. for (let b of billsDatas) {
  244. if (parentMap[b.ParentID]) {
  245. parentMap[b.ParentID].push(b);
  246. } else {
  247. parentMap[b.ParentID] = [b];
  248. }
  249. let flag = this.getFlag(b);
  250. if (this.isDef(flag) && flag.flag == this.fixedFlag.SUB_ENGINERRING) {
  251. subdivisionBillID = b.ID;
  252. }
  253. if (this.isDef(flag) && flag.flag == this.fixedFlag.CONSTRUCTION_TECH) {
  254. techBillID = b.ID;
  255. }
  256. }
  257. getLeaveIDs(subdivisionBillID, parentMap, sIDs);
  258. getLeaveIDs(techBillID, parentMap, tIDS);
  259. return [sIDs, tIDS];
  260. function getLeaveIDs(ID, parentM, leaveIDs) {
  261. if (parentM[ID] && parentM[ID].length > 0) {
  262. let children = parentM[ID];
  263. for (let c of children) {
  264. if (parentM[c.ID]) {
  265. getLeaveIDs(c.ID, parentM, leaveIDs);
  266. } else {
  267. leaveIDs.push(c.ID);
  268. }
  269. }
  270. }
  271. }
  272. },
  273. getFlag: function (b) {
  274. let lo_sh = typeof _ !== 'undefined' ? _ : this._;
  275. return lo_sh.find(b.flags, {
  276. "fieldName": "fixed"
  277. });
  278. },
  279. getGLJPrice: function (glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil, ext, tenderCoe, isReport) {
  280. let result = {};
  281. if (isReport) {
  282. result.marketPrice = this.getMarketPrice(glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil, tenderCoe, ext);
  283. } else {
  284. result.marketPrice = this.getMarketPrice(glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil);
  285. result.tenderPrice = this.getMarketPrice(glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil, tenderCoe);
  286. }
  287. if (this.calcPriceDiff(glj, calcOptions) == true) { //计取价差
  288. result.basePrice = this.getBasePrice(glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil);
  289. result.adjustPrice = this.getAdjustPrice(glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil);
  290. } else { //不计价差
  291. result.basePrice = result.marketPrice;
  292. result.adjustPrice = result.marketPrice;
  293. }
  294. return result;
  295. },
  296. getMarketPrice: function (glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil, tenderCoe, ext) {
  297. let price_decimal = decimalObj.glj.unitPrice;
  298. let price_hasM_decimal = decimalObj.glj.unitPriceHasMix ? decimalObj.glj.unitPriceHasMix : decimalObj.glj.unitPrice;
  299. let quantity_decimal = decimalObj.glj.quantity;
  300. let process_decimal = this.isDef(decimalObj.marketPriceProcess) ? decimalObj.marketPriceProcess : decimalObj.process; //20200722 旧的项目还是默认6位,新的用两位
  301. let feeRate_decimal = decimalObj.feeRate;
  302. let priceCoe = this.isDef(tenderCoe) ? tenderCoe : 1;
  303. if (priceCoe == '0' || priceCoe == 0) priceCoe = 1; // 这里加个保护
  304. if (['GLF', 'LR', 'FXF'].includes(glj.code)) priceCoe = 1; // 类型是“企业管理费”、“利润”、“一般风险费”的,不应调整单价。
  305. if (!this.isConcreteType(glj.unit_price.type) && this.notEditType.indexOf(glj.unit_price.type) != -1 && glj.ratio_data.length > 0) { //对于机械台班等有组成物的材料,价格需根据组成物计算得出(排除混凝土、配合比、砂浆这几个类型直接为0)。
  306. let p = 0;
  307. let consSum = 0; //不变费用总和
  308. let temSum = 0;//可变费用总和
  309. //不变费用组成物包括:折旧费、检修费、维护费、安拆辅助费,这几个材料只能通过名称判断了,类型没有细分。
  310. let constNames = ['折旧费','检修费','维护费','安拆辅助费'];
  311. let constCoe = scMathUtil.roundForObj(projectGLJDatas.constData.machineConstCoe,feeRate_decimal);
  312. for (let ratio of glj.ratio_data) {
  313. let rIndex = gljUtil.getIndex(ratio);
  314. let tem = _.find(projectGLJDatas.gljList, function (item) {
  315. return rIndex == gljUtil.getIndex(item);
  316. });
  317. if (tem) {
  318. let tem_marketPrice = this.getMarketPrice(tem, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, true, _, scMathUtil);
  319. if (ext && ext[tem.id] && this.isDef(ext[tem.id].marketPrice)) { //在修改组成物的价格或消耗量时,影响了父工料机的价格,这时以父工料机的价格应当用组成物的新值来记算
  320. tem_marketPrice = ext[tem.id].marketPrice;
  321. };
  322. let temP = scMathUtil.roundForObj(tem_marketPrice * priceCoe, price_decimal) * scMathUtil.roundForObj(ratio.consumption, quantity_decimal);
  323. if(decimalObj.temProcess) temP = scMathUtil.roundForObj(temP, decimalObj.temProcess);//取两次防止中间过程使用两位导致 4舍5入后少0.01的情况
  324. temP = scMathUtil.roundForObj(temP,process_decimal);
  325. if(constNames.includes(tem.name) && constCoe !== 1){//不等于1的时候才要另外计算
  326. temP = scMathUtil.roundForObj(temP*constCoe,process_decimal);
  327. consSum = scMathUtil.roundForObj(temP + consSum,process_decimal);
  328. }else {
  329. temSum = scMathUtil.roundForObj(temP + temSum, process_decimal);
  330. }
  331. }
  332. }
  333. return scMathUtil.roundForObj(temSum + consSum, price_hasM_decimal);
  334. } else {
  335. let tem_decimal = price_decimal; //isRadio==true?process_decimal:price_decimal;
  336. let tem_price = scMathUtil.roundForObj(glj.unit_price.market_price, price_decimal);
  337. return scMathUtil.roundForObj(tem_price * priceCoe, tem_decimal);
  338. }
  339. },
  340. getBasePrice: function (glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil) {
  341. let price_decimal = decimalObj.glj.unitPrice;
  342. let price_hasM_decimal = decimalObj.glj.unitPriceHasMix ? decimalObj.glj.unitPriceHasMix : decimalObj.glj.unitPrice;
  343. let quantity_decimal = decimalObj.glj.quantity;
  344. let process_decimal = decimalObj.process;
  345. if (this.notEditType.indexOf(glj.unit_price.type) != -1 && glj.ratio_data.length > 0) { //对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。
  346. //2018-09-07 需求修改,定额价不按组成物的量和价实时计算出来,直接取单价文件中的定额价
  347. /* let p =0;
  348. for(let ratio of glj.ratio_data){
  349. let tem = _.find( projectGLJDatas.gljList,{
  350. 'code': ratio.code,
  351. 'name': ratio.name,
  352. 'specs':ratio.specs,
  353. 'type': ratio.type,
  354. 'unit': ratio.unit
  355. });
  356. if(tem){
  357. let priceData=this.getGLJPrice(tem,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,true,_,scMathUtil);
  358. let temP = scMathUtil.roundForObj(priceData.basePrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal);
  359. p = scMathUtil.roundForObj(temP + p,process_decimal);
  360. }
  361. }
  362. return scMathUtil.roundForObj(p,price_hasM_decimal);*/
  363. return scMathUtil.roundForObj(glj.unit_price.base_price, price_hasM_decimal);
  364. } else {
  365. let tem_decimal = price_decimal; //isRadio==true?process_decimal:price_decimal;
  366. return scMathUtil.roundForObj(glj.unit_price.base_price, tem_decimal);
  367. }
  368. },
  369. getAdjustPrice: function (glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil) {
  370. let decimal = decimalObj.glj.unitPrice;
  371. let price_hasM_decimal = decimalObj.glj.unitPriceHasMix ? decimalObj.glj.unitPriceHasMix : decimalObj.glj.unitPrice;
  372. let quantity_decimal = decimalObj.glj.quantity;
  373. let process_decimal = this.isDef(decimalObj.marketPriceProcess) ? decimalObj.marketPriceProcess : decimalObj.process;
  374. let tem_decimal = isRadio == true ? process_decimal : decimal;
  375. if (glj.unit_price.type == this.gljType.LABOUR || glj.unit_price.type == this.gljType.MACHINE_LABOUR) { //人工、机上人工,调整价根据定额价*调整系数计算得出。
  376. let labour = _.find(labourCoeDatas.coes, {
  377. 'ID': glj.adjCoe
  378. });
  379. let coe = labour && labour.coe ? labour.coe : 1;
  380. return scMathUtil.roundTo(parseFloat(coe * scMathUtil.roundForObj(glj.unit_price.base_price, decimal)), -decimal);
  381. } else if (this.notEditType.indexOf(glj.unit_price.type) != -1 && glj.ratio_data.length > 0) { //对于混凝土、配合比、砂浆、机械台班,调整价根据组成物计算得出。
  382. let p = 0;
  383. for (let ratio of glj.ratio_data) {
  384. let tem = _.find(projectGLJDatas.gljList, {
  385. 'code': ratio.code,
  386. 'name': ratio.name,
  387. 'specs': ratio.specs,
  388. 'type': ratio.type,
  389. 'unit': ratio.unit
  390. })
  391. if (tem) {
  392. let priceData = this.getGLJPrice(tem, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, true, _, scMathUtil);
  393. let temP = scMathUtil.roundForObj(priceData.adjustPrice * scMathUtil.roundForObj(ratio.consumption, quantity_decimal), process_decimal);
  394. p = scMathUtil.roundForObj(temP + p, process_decimal);
  395. }
  396. }
  397. return scMathUtil.roundForObj(p, price_hasM_decimal);
  398. } else { //对于其他普通材料等,无调整系数,调整价=定额价。
  399. return scMathUtil.roundForObj(glj.unit_price.base_price, decimal)
  400. }
  401. },
  402. calcPriceDiff: function (glj, calcOptions) {
  403. if (glj.is_evaluate == 1) { //先按是否暂估判断
  404. return calcOptions.calc_est;
  405. }
  406. if (glj.type == this.gljType.MAIN_MATERIAL || glj.type == this.gljType.EQUIPMENT) { //再判断是否是主材和设备
  407. return calcOptions.calc_main;
  408. }
  409. if (glj.unit_price.is_add == 1) { //再判断是否新增
  410. return calcOptions.calc_add;
  411. }
  412. return true;
  413. },
  414. isFlag: function (v) {
  415. return this.isDef(v.flagsIndex) && this.isDef(v.flagsIndex.fixed) && this.isDef(v.flagsIndex.fixed.flag);
  416. },
  417. isDef: function (v) {
  418. return v !== undefined && v !== null;
  419. },
  420. getIndex(obj, pops) {
  421. let t_index = '';
  422. let k_arr = [];
  423. if (!this.isDef(pops)) pops = this.gljKeyArray;
  424. for (let p of pops) {
  425. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  426. k_arr.push(tmpK);
  427. }
  428. t_index = k_arr.join("|-|");
  429. return t_index;
  430. },
  431. getMainType: function (type) {
  432. let str = type + "";
  433. return parseInt(str.substr(0, 1));
  434. },
  435. sortRationGLJ: function (list, std) {
  436. const field = std ? 'gljType' : 'type';
  437. let lo_sh = typeof _ !== 'undefined' ? _ : this._;
  438. list = lo_sh.sortByAll(list, [function (item) {
  439. return gljUtil.getMainType(item[field]);
  440. }, gljUtil.getCodeSortMath()]);
  441. return list;
  442. },
  443. sortMixRatio: function (list) {
  444. let lo_sh = typeof _ !== 'undefined' ? _ : this._;
  445. return lo_sh.sortByAll(list, ["code"]);
  446. },
  447. //项目工料机 混凝土、砂浆、配合比排序与定额工料机不一样,同时,type取值的地方不一样
  448. sortProjectGLJ: function (list, lodash) {
  449. let lo = lodash ? lodash : _;
  450. let specialMap = {
  451. 1: -1,
  452. 303: 0,
  453. 202: 9,
  454. 203: 10,
  455. 204: 11
  456. }; //,人工、机械工排在最前,混凝土、砂浆、配合比 排到最后
  457. list = lo.sortByAll(list, [function (item) {
  458. let unit_price = item.unit_price ? item.unit_price : item;
  459. if (specialMap[unit_price.type] != undefined) return specialMap[unit_price.type];
  460. return gljUtil.getMainType(unit_price.type);
  461. }, gljUtil.getCodeSortMath()]);
  462. return list;
  463. },
  464. getCodeSortMath: function () {
  465. return "code"
  466. },
  467. isConcreteType: function (type) {
  468. let concreteType = [gljUtil.gljType.CONCRETE, gljUtil.gljType.MORTAR, gljUtil.gljType.MIX_RATIO]; //混凝土大类:混凝土、砂浆,配合比
  469. return concreteType.indexOf(type) != -1
  470. },
  471. isCommercialConcreteType: function (type) {
  472. let commercialType = [gljUtil.gljType.COMMERCIAL_CONCRETE, gljUtil.gljType.COMMERCIAL_MORTAR]; //商品混凝土、商品砂浆
  473. return commercialType.indexOf(type) != -1
  474. },
  475. //是否从混凝土改成商品混凝土,并且混凝土的定额消耗量不为空,则原混凝土的自定义消耗改成0,插入一条新的商品混凝土自定义消耗量为原自定义或定额消耗
  476. isAddCommercialForReplace: function (oldType, newType, rationItemQuantity) {
  477. return this.isConcreteToCommercialConcrete(oldType, newType) && rationItemQuantity && rationItemQuantity != '0';
  478. },
  479. isMaterialType: function (type) {
  480. let materialType = [gljType.GENERAL_MATERIAL, gljType.GREEN_SEEDLING, gljType.PURCHASE_COMPONENT, gljType.COMMERCIAL_CONCRETE, gljType.COMMERCIAL_MORTAR]; //可以添加材料计算的类型普通材料”、“绿化苗木”、“外购砼构件”、“商品混凝土”、“商品砂浆”
  481. return materialType.indexOf(type) != -1
  482. },
  483. isConcreteToCommercialConcrete: function (oldType, newType) {
  484. return gljUtil.isConcreteType(oldType) && gljUtil.isCommercialConcreteType(newType)
  485. },
  486. hasComposition: function (ration_glj, isRationType) { //判断是否有组成物,有则返回true 现在主材类型的工料机也有可能有组成物。
  487. let type = isRationType == true ? ration_glj.subType : ration_glj.type;
  488. if (this.notEditType.indexOf(type) != -1 || type == gljType.MAIN_MATERIAL) {
  489. let keyArray = isRationType == true ? rationKeyArray : gljKeyArray;
  490. let con_key = this.getIndex(ration_glj, keyArray);
  491. var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  492. if (mixRatioMap[con_key] && mixRatioMap[con_key].length > 0) {
  493. return true;
  494. }
  495. }
  496. return false;
  497. },
  498. getCCSProjectGLJ: function (unitFileID, project_id) {
  499. return {
  500. "ratio_data": [],
  501. "unit_price": {
  502. "base_price": "1",
  503. "market_price": "1",
  504. "code": "80CCS",
  505. "name": "车船税",
  506. "unit_price_file_id": unitFileID,
  507. "type": 302,
  508. "short_name": "机",
  509. "glj_id": -99,
  510. "unit": "元",
  511. "original_code": "80CCS",
  512. "id": -99,
  513. "is_add": 0,
  514. "specs": ""
  515. },
  516. "glj_id": -99,
  517. "project_id": project_id,
  518. "code": "80CCS",
  519. "unit": "元",
  520. "type": 302,
  521. "original_code": "80CCS",
  522. "id": -99,
  523. "from": "std",
  524. "is_main_material": 1,
  525. "specs": "",
  526. "is_adjust_price": 0,
  527. "delivery_address": "",
  528. "delivery": "",
  529. "supply_quantity": 0,
  530. "supply": 0,
  531. "is_evaluate": 0,
  532. "name": "车船税"
  533. }
  534. },
  535. getBaseCCSMixRatio: function (unitFileID, consumption, connect_key) {
  536. return {
  537. glj_id: -99,
  538. unit_price_file_id: unitFileID,
  539. connect_key: connect_key,
  540. consumption: consumption,
  541. code: '80CCS',
  542. name: '车船税',
  543. unit: '元',
  544. type: 302,
  545. specs: '',
  546. from: "cpt"
  547. }
  548. },
  549. updateProperty: function (obj, doc) {
  550. let lo_sh = typeof _ !== 'undefined' ? _ : this._;
  551. lo_sh.forEach(doc, function (n, key) {
  552. obj[key] = n;
  553. });
  554. },
  555. getTotalQuantity: function (glj, ration, rd, gd) {
  556. if (ration) {
  557. let quantity = ration.quantity;
  558. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  559. quantity = scMathUtil.roundForObj(quantity, rd); //计算前进行4舍5入
  560. glj.quantity = scMathUtil.roundForObj(glj.quantity, gd);
  561. let pglj = calcTools.getProjectGLJ(glj);
  562. glj.tenderQuantity = this.getRationGLJTenderQuantity(glj, ration, gd, scMathUtil, pglj);
  563. return scMathUtil.roundToString(quantity * glj.quantity, gd);
  564. }
  565. },
  566. setMaterialCalcRationFee: function (ration, ration_gljs, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, _, scMathUtil) {
  567. let pMap = _.indexBy(projectGLJDatas.gljList, 'id');
  568. let process_decimal = decimalObj.process;
  569. let ration_quantity_decimal = decimalObj.ration.quantity;
  570. let glj_quantity_decimal = decimalObj.glj.quantity;
  571. let glj_unitPrice_decimal = decimalObj.glj.unitPrice;
  572. let assFeeRate = scMathUtil.roundForObj(projectGLJDatas.constData.assistProductionFeeRate, decimalObj.feeRate) * 0.01; //辅助生产间接费费率
  573. let rationLaberFee = 0; //定额人工费(市场价)
  574. let rationMachineFee = 0; //定额施工机械使用费(市场价)
  575. let rationLaberFee_b = 0; //定额人工费(定额价)
  576. let rationMachineFee_b = 0; //定额施工机械使用费(定额价)
  577. let directFee = 0; //直接费
  578. let rationQuantity = scMathUtil.roundForObj(ration.quantity, ration_quantity_decimal);
  579. for (let g of ration_gljs) {
  580. let result = this.getGLJPrice(pMap[g.projectGLJID], projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, false, _, scMathUtil);
  581. g.marketPrice = result.marketPrice;
  582. g.basePrice = result.basePrice;
  583. let quantity = scMathUtil.roundForObj(g.quantity, glj_quantity_decimal);
  584. let t = scMathUtil.roundForObj(quantity * g.marketPrice * rationQuantity, process_decimal); //市场价
  585. let rt = scMathUtil.roundForObj(quantity * g.basePrice * rationQuantity, process_decimal); //定额价
  586. if (g.type == this.gljType.LABOUR) {
  587. rationLaberFee = scMathUtil.roundForObj(rationLaberFee + t, process_decimal);
  588. rationLaberFee_b = scMathUtil.roundForObj(rationLaberFee_b + rt, process_decimal);
  589. } else if (this.getMainType(g.type) == 3) {
  590. rationMachineFee = scMathUtil.roundForObj(rationMachineFee + t, process_decimal);
  591. rationMachineFee_b = scMathUtil.roundForObj(rationMachineFee_b + rt, process_decimal);
  592. }
  593. directFee = scMathUtil.roundForObj(directFee + t, process_decimal);
  594. }
  595. ration.assistProductionFee = scMathUtil.roundForObj(rationLaberFee_b * assFeeRate, glj_unitPrice_decimal); //辅助生产间接费
  596. ration.rationLaberFee = scMathUtil.roundForObj(rationLaberFee, glj_unitPrice_decimal); //定额人工费(市场价)
  597. ration.rationMachineFee = scMathUtil.roundForObj(rationMachineFee, glj_unitPrice_decimal); //定额施工机械使用费(市场价)
  598. ration.directFee = scMathUtil.roundForObj(directFee, glj_unitPrice_decimal); //直接费
  599. //to do 高原取费类别的情况待确认
  600. //let hs = scMathUtil.roundForObj(tt*hightFeeRate,process_decimal);//(人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量)*高原取费类别费率
  601. },
  602. getAssUsedPrice: function (g) {
  603. return g.basePrice;
  604. },
  605. getElecCoe: function () {
  606. return 0.15;
  607. },
  608. getElecCode: function () {
  609. return '3005002';
  610. },
  611. getTenderPriceCoe: function (glj, tproperty) {
  612. let tenderCoe = 1;
  613. let property = tproperty ? tproperty : projectObj.project.property;
  614. if (!glj.is_adjust_price && property.tenderSetting && isDef(property.tenderSetting.gljPriceTenderCoe)) {
  615. tenderCoe = parseFloat(property.tenderSetting.gljPriceTenderCoe);
  616. if (tenderCoe == 0) tenderCoe = 1;
  617. }
  618. return tenderCoe;
  619. function isDef(v) {
  620. return v !== undefined && v !== null;
  621. }
  622. },
  623. setProperty: function (Obj, updateData) {
  624. let lo_sh = typeof _ !== 'undefined' ? _ : this._;
  625. for (let ukey in updateData) {
  626. if (lo_sh.isObject(updateData[ukey]) && lo_sh.isObject(Obj[ukey]) && !lo_sh.isArray(updateData[ukey])) {
  627. setProperty(Obj[ukey], updateData[ukey]);
  628. } else {
  629. Obj[ukey] = updateData[ukey];
  630. }
  631. }
  632. },
  633. isKGtoT: function (bills_unit, ration_unit) { //是否由KG转成T,b_unit清单单位,t_unit定额单位
  634. let t_unit = ration_unit ? ration_unit : "";
  635. let b_unit = bills_unit ? bills_unit : "";
  636. return (/.*kg$/i).test(b_unit) && (/.*t$/i).test(t_unit);
  637. },
  638. fixedFlag: {
  639. // 分部分项工程
  640. SUB_ENGINERRING: 1,
  641. // 措施项目
  642. MEASURE: 2,
  643. // 施工技术措施项目
  644. CONSTRUCTION_TECH: 3
  645. },
  646. gljType: {
  647. LABOUR: 1, // 人工
  648. // ==============材料类型 ↓=================
  649. GENERAL_MATERIAL: 201, // 普通材料
  650. CONCRETE: 202, // 混凝土
  651. MORTAR: 203, // 砂浆
  652. MIX_RATIO: 204, // 配合比
  653. COMMERCIAL_CONCRETE: 205, // 商品混凝土
  654. COMMERCIAL_MORTAR: 206, // 商品砂浆
  655. OTHER_MATERIAL: 207, // 其它材料
  656. PURCHASE_COMPONENT: 208, // 外购砼构件
  657. GREEN_SEEDLING: 209, // 绿化苗木
  658. // ==============材料类型 ↑=================
  659. // ==============机械类型 ↓=================
  660. GENERAL_MACHINE: 301, // 机械台班
  661. MACHINE_COMPOSITION: 302, // 机械组成物
  662. MACHINE_LABOUR: 303, // 机上人工
  663. INSTRUMENT: 304, // 仪器仪表
  664. FUEL_POWER_FEE: 305, // 燃料动力费
  665. DEPRECIATION_FEE: 306, // 折旧费
  666. INSPECTION_FEE: 307, // 检修费
  667. MAINTENANCE: 308, // 维护费
  668. DISMANTLING_FREIGHT_FEE: 309, // 安拆费及场外运费
  669. VERIFICATION_FEE: 310, // 校验费
  670. OTHER_FEE: 311, // 其他费用
  671. OTHER_MACHINE_USED: 312, // 其他施工机具使用费
  672. // ==============机械类型 ↑=================
  673. MAIN_MATERIAL: 4, // 主材
  674. EQUIPMENT: 5, // 设备
  675. MANAGEMENT_FEE: 6, // 企业管理费
  676. PROFIT: 7, // 利润
  677. GENERAL_RISK_FEE: 8 // 一般风险费
  678. },
  679. extraType: [6, 7, 8], //一些其它的工料机类型
  680. notEditType: [202, 203, 204, 301, 304, 4],
  681. gljKeyArray: ['code', 'name', 'specs', 'unit', 'type'],
  682. rationType: {
  683. ration: 1,
  684. volumePrice: 2,
  685. gljRation: 3,
  686. install: 4
  687. },
  688. hasCompMaterial: [202, 203, 204], //有组成物的材料
  689. hasCompMachine: [301], //有组成物的机械
  690. machineComposition: [201, 302, 303] //可以做为机械组成物的类型
  691. }
  692. if (typeof module !== 'undefined') {
  693. gljUtil._ = require("lodash");
  694. module.exports = gljUtil;
  695. }