gljUtil.js 36 KB

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