glj_calculate_facade.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /**
  2. * Created by chen on 2017/7/12.
  3. */
  4. let mongoose = require('mongoose');
  5. let _=require("lodash");
  6. let ration_glj = mongoose.model('ration_glj');
  7. let ration = mongoose.model('ration');
  8. let ration_coe = mongoose.model('ration_coe');
  9. const ProjectModel = require('../../pm/models/project_model').project;
  10. let mixRatioModel = mongoose.model('mix_ratio');
  11. let std_ration_lib_ration_items = mongoose.model('std_ration_lib_ration_items');
  12. let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
  13. let glj_type_util = require('../../../public/cache/std_glj_type_util');
  14. const scMathUtil = require('../../../public/scMathUtil').getUtil();
  15. let decimal_facade = require('../../main/facade/decimal_facade');
  16. let gljUtil = require('../../../public/gljUtil');
  17. const common_util = require('../../../public/common_util');
  18. module.exports={
  19. calculateQuantity:calculateQuantity,
  20. getGLJTypeByID:getGLJTypeByID
  21. }
  22. //辅助定额调整、稳定土配合比、替换工料机、标准附注条件调整、添加工料机、自定义消耗量(包括删除工料机)、自定义乘系数、市场单价调整
  23. let stateSeq ={
  24. ass:1,
  25. proportion: 2,
  26. replace:3,
  27. coe:4,
  28. add:5,
  29. cusQuantity:6,
  30. cusCoe:7,
  31. adjMak:8
  32. };
  33. //自定义乘系数与定额工料机类型映射表
  34. let coeTypeMap = {
  35. "人工":1,
  36. "材料":2,
  37. "机械":3,
  38. "施工机具":3,
  39. "主材":4,
  40. "设备":5
  41. };
  42. async function calculateQuantity(query,noNeedCal=null,refreshRationName = false){
  43. try {
  44. let result ={
  45. glj_result:[],
  46. rationID:query.rationID
  47. };
  48. let impactRation = await ration.findOne({ID:query.rationID});
  49. let gljList = await ration_glj.find(query);//{projectID:query.projectID,rationID:query.rationID}
  50. let coeList = await ration_coe.find({rationID:query.rationID}).sort('seq').exec();
  51. let assList=[], assRation = null, adjustState=[],mixRatioMap = {};
  52. if(!impactRation){//如果定额不存在或者已删除,返回空
  53. return null;
  54. }
  55. if(impactRation._doc.hasOwnProperty("rationAssList")&&impactRation.rationAssList.length>0){
  56. prepareAss(impactRation.rationAssList);
  57. let temTimes = [];
  58. let thirdRationCodes=[];
  59. for(let i=0;i<impactRation.rationAssList.length;i++){
  60. let times = calculateTimes(impactRation.rationAssList[i]);
  61. if(times!=0){
  62. let thirdRationCode = impactRation.rationAssList[i].thirdRationCode;
  63. if(thirdRationCode && thirdRationCode !=''){
  64. temTimes.push(times);
  65. thirdRationCodes.push(thirdRationCode)
  66. }
  67. assRation = await std_ration_lib_ration_items.findOne({rationRepId:impactRation.libID,code:impactRation.rationAssList[i].assistCode});
  68. assList.push({times:times,assRation:assRation});
  69. adjustState.push({index:stateSeq.ass,content:impactRation.rationAssList[i].name+" "+impactRation.rationAssList[i].actualValue+" : +"+impactRation.rationAssList[i].assistCode+"x"+times});
  70. }
  71. }
  72. if(temTimes.length == 2 &&thirdRationCodes[0] == thirdRationCodes[1] ){ //说明有第三定额
  73. let times_t = temTimes[0] * temTimes[1];
  74. let tration = await std_ration_lib_ration_items.findOne({rationRepId:impactRation.libID,code:thirdRationCodes[0]});
  75. if(tration){
  76. assList.push({times:times_t,assRation:tration});
  77. adjustState.push({index:stateSeq.ass,content:"+"+thirdRationCodes[0]+"x"+times_t});
  78. }
  79. }
  80. }
  81. // 稳定土调整状态
  82. const proportionStr = gljList.filter(glj => glj.rationProportion).map(glj => glj.adjustProportion || 0).join(':');
  83. if (proportionStr) {
  84. adjustState.push({ index: stateSeq.proportion, content: proportionStr });
  85. }
  86. for(let glj of gljList){//先把混凝土,砂浆,配合比有自定义消耗的挑出来
  87. if(gljUtil.isConcreteType(glj.type)) await getMixRatioMap(glj,gljList,coeList,assList,mixRatioMap);
  88. }
  89. gljList = gljUtil.sortRationGLJ(gljList);
  90. for(let i =0;i<gljList.length;i++ ){
  91. let r = await calculateQuantityPerGLJ(gljList[i],gljList,coeList,assList,adjustState,mixRatioMap,noNeedCal);
  92. if(quantityUpdateCheck(gljList[i],r) == true) result.glj_result.push(r);
  93. }
  94. if(noNeedCal==null && result.glj_result.length > 0){
  95. await ration_glj.bulkWrite(generateUpdateTasks(result.glj_result));
  96. }
  97. adjustState= _.sortByOrder(adjustState, ['index'], ['asc']);
  98. adjustState=_.map(adjustState, _.property('content'));
  99. let adjustStateString = adjustState.join(';');
  100. let setData = {adjustState:adjustStateString};
  101. if(refreshRationName == true){//需要更新定额名称
  102. let newName = generateRationName(impactRation,gljList);
  103. setData.name = newName;
  104. result.rationName = newName;
  105. }
  106. await ration.update({ID:query.rationID},setData);
  107. result.adjustState=adjustStateString;
  108. return result;
  109. }catch (err){
  110. console.log(err);
  111. throw err;
  112. }
  113. }
  114. function quantityUpdateCheck(glj,r) {//检查,有改变的才更新
  115. for(let key in r.doc){
  116. if(glj._doc[key] != r.doc[key]) return true
  117. }
  118. return false
  119. }
  120. function generateRationName(ration,gljList) {
  121. let caption = ration.caption ? ration.caption:ration.name;
  122. let replaceList = [];
  123. if(ration.rationAssList && ration.rationAssList.length > 0){//这里要处理第三定额和多辅助定额的情况
  124. let isThird = ration.rationAssList.length == 2 && ration.rationAssList[0].thirdRationCode&&ration.rationAssList[0].thirdRationCode!='';//说明有第三定额的情况
  125. let adjustMatch = "",notAdjust="";
  126. for(let ass of ration.rationAssList){
  127. let tem = "";
  128. if( ass.isAdjust == 1 && ass.actualValue != null && ass.actualValue != undefined ){
  129. tem = ass.actualValue;
  130. adjustMatch = tem;
  131. }else {
  132. tem = ass.stdValue;
  133. notAdjust = tem;
  134. }
  135. if(isThird) replaceList.push(tem);
  136. }
  137. if(replaceList.length == 0){
  138. adjustMatch!=""?replaceList.push(adjustMatch):replaceList.push(notAdjust);
  139. }
  140. for(let r of replaceList){
  141. caption = caption.replace(/%s/i,r);
  142. }
  143. }
  144. // 更新定额名称中显示的稳定土配合比
  145. const proportionStr = gljList.filter(glj => glj.rationProportion).map(glj => glj.adjustProportion || 0).join(':');
  146. if (proportionStr) {
  147. caption = caption.replace(/%p/i, proportionStr);
  148. }
  149. let reNameList = [];
  150. for(let g of gljList){
  151. //glj._doc.createType=='replace'&&glj.rcode!=glj.code
  152. if(g.createType=='replace'&&g.rcode!=g.code){ //是替换工料机
  153. let reName = g.name;
  154. if(!_.isEmpty(g.specs)) reName = reName + ' '+g.specs;
  155. reNameList.push(reName);
  156. }
  157. }
  158. if(reNameList.length > 0){
  159. let reNameString = reNameList.join(" ");
  160. caption = caption + " 换为【"+ reNameString + "】";
  161. }
  162. return caption;
  163. }
  164. function generateUpdateTasks(result) {
  165. let tasks = [];
  166. for(let i =0;i<result.length;i++){
  167. let task= {
  168. updateOne: {
  169. filter: result[i].query,
  170. update: result[i].doc
  171. }
  172. };
  173. tasks.push(task);
  174. }
  175. return tasks;
  176. }
  177. async function calcWhenNoCustomQuantiyt(decimal,glj,gljList,coeList,assList) {
  178. let quantity = glj.rationItemQuantity ? scMathUtil.roundTo(parseFloat(glj.rationItemQuantity),-decimal):0;
  179. quantity =scMathUtil.roundTo(await calculateAss(quantity,assList,glj),-decimal);
  180. if (glj.rationProportion && common_util.isDef(glj.adjustProportion)) {
  181. const proportionRate = glj.adjustProportion / glj.rationProportion;
  182. quantity *= proportionRate;
  183. }
  184. quantity = calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal);
  185. return quantity;
  186. }
  187. async function calculateQuantityPerGLJ(glj,gljList,coeList,assList,adjustState,mixRatioMap,noNeedCal) {
  188. let decimalObject = await decimal_facade.getProjectDecimal(glj.projectID);
  189. let decimal = (decimalObject&&decimalObject.glj&&decimalObject.glj.quantity)?decimalObject.glj.quantity:3;
  190. let quantity = scMathUtil.roundTo(parseFloat(glj.quantity),-decimal);
  191. let result={
  192. query:{
  193. ID:glj.ID
  194. },
  195. doc:{
  196. quantity: quantity
  197. }
  198. };
  199. try {
  200. if(noNeedCal==null){//计算顺序:辅助定额, 稳定土配合比、附注条件,自定义消耗(如果有就不用前计算两项),自定义乘系数
  201. if(noCustomQuantiyt(glj)){
  202. quantity = await calcWhenNoCustomQuantiyt(decimal,glj,gljList,coeList,assList);
  203. let mIndex = gljUtil.getIndex(glj);
  204. if(mixRatioMap[mIndex]){//组成物
  205. quantity = calcQuantityForMix(quantity,mixRatioMap[mIndex],decimal);
  206. }
  207. }else {//对于有自定义消耗量的,并且是混凝土,浆砂,配合比 这三种类型,其组成物的消耗量要跟据自定义消耗量做相应的换算
  208. quantity = glj.customQuantity;
  209. result.doc.customQuantity = glj.customQuantity;
  210. }
  211. let customerCoe = _.last(coeList);
  212. if(customerCoe&&customerCoe.isAdjust==1){
  213. quantity = scMathUtil.roundToString(quantity,decimal);
  214. quantity = calculateQuantityByCustomerCoes(quantity,customerCoe,glj,decimal);
  215. }
  216. if(quantity < 0) quantity = 0;
  217. result.doc.quantity =scMathUtil.roundToString(quantity,decimal);
  218. //2019-01-03 需求修改中间过程的价格不参与计算
  219. //glj.quantity = quantity;//这里保存中间过程计算出来的消耗量,后面处理“+*”操作符时要用到
  220. }
  221. generateAdjustState(glj,coeList,adjustState,gljList,result.doc.quantity);
  222. return result;
  223. }catch (err){
  224. throw err;
  225. }
  226. }
  227. function calcQuantityForMix(quantity,plist,decimal) {
  228. for(let pglj of plist){
  229. let consumption = scMathUtil.roundForObj(pglj.consumption,decimal);
  230. let customQuantity = scMathUtil.roundForObj(pglj.customQuantity,decimal);
  231. let temQuantity = scMathUtil.roundForObj(consumption * pglj.assCoeQuantity,6);
  232. let pcustomQuantity = scMathUtil.roundForObj(consumption * customQuantity,6);
  233. quantity = scMathUtil.roundForObj(quantity - temQuantity,6);
  234. quantity = scMathUtil.roundForObj(quantity + pcustomQuantity,decimal);
  235. }
  236. return quantity;
  237. }
  238. async function getMixRatioMap(glj,gljList,coeList,assList,mixRatioMap) {//生成组成物对应的父工料机的映射表
  239. let decimalObject = await decimal_facade.getProjectDecimal(glj.projectID);
  240. let decimal = (decimalObject&&decimalObject.glj&&decimalObject.glj.quantity)?decimalObject.glj.quantity:3;
  241. let assCoeQuantity = await calcWhenNoCustomQuantiyt(decimal,glj,gljList,coeList,assList);//计算要用父工料机经过辅助子目换算后的量
  242. let unitPriceFileId = await ProjectModel.getUnitPriceFileId(glj.projectID);
  243. let connect_key = gljUtil.getIndex(glj);
  244. let mixList = await mixRatioModel.find({"unit_price_file_id":unitPriceFileId,'connect_key':connect_key});
  245. for(let m of mixList){
  246. if(glj.createType == 'replace'&& glj.mIndexObj){//如果是替换过的工料机,要造一条加的数据去补回下面的减数据
  247. //与下面的减相对应,如果有没被引用子组成物工料机,会少一条加的数据,这样,那条没被引用的消耗量会被减为0
  248. addToMixMap(m,mixRatioMap,assCoeQuantity,0); //addToMixMap(m,mixRatioMap,glj.rationItemQuantity,0); -- 2019-04-15 和下面的减相对做修改
  249. }
  250. if(!noCustomQuantiyt(glj)) {//有自定义消耗量才做正常的计算处理
  251. addToMixMap(m,mixRatioMap,glj.customQuantity,assCoeQuantity);
  252. }
  253. }
  254. if(glj.createType == 'replace' && glj.mIndexObj){//如果这条是替换过的混凝土,原来的组成物的消耗量还要减去替换前的混凝土得到的消耗量
  255. let t_con_key = gljUtil.getIndex(glj.mIndexObj);
  256. let tmixList = await mixRatioModel.find({"unit_price_file_id":unitPriceFileId,'connect_key':t_con_key});
  257. for(let tm of tmixList ){
  258. addToMixMap(tm,mixRatioMap,0,assCoeQuantity); //addToMixMap(tm,mixRatioMap,0,glj.rationItemQuantity);
  259. // -- 2019-04-15 修改bugs 这里把glj.rationItemQuantity 改成assCoeQuantity。 定额下组成物的消耗量要减去父工料机经过辅助定额或者子目换算后的对应的增加量
  260. }
  261. }
  262. function addToMixMap(m,map,cust,ass,isReplace = false) {
  263. let mkey = gljUtil.getIndex(m);
  264. let pObj = {customQuantity:cust,assCoeQuantity:ass,consumption:m.consumption,isReplace:isReplace};
  265. if(map[mkey]){
  266. map[mkey].push(pObj);
  267. }else {
  268. map[mkey] = [pObj];
  269. }
  270. }
  271. }
  272. function noCustomQuantiyt(glj) {//是否有自定义消耗量
  273. return !glj._doc.hasOwnProperty('customQuantity')||glj.customQuantity==null||glj.customQuantity==""
  274. }
  275. async function calculateAss(quantity,assList,glj) {
  276. for(let i=0;i<assList.length;i++){
  277. if(assList[i].assRation){
  278. let assglj = null;
  279. for(let aglj of assList[i].assRation.rationGljList){
  280. if(glj.createType == 'replace'){//如果工料机是替换过的,要用原始的编码来匹配
  281. let std_glj = await std_glj_lib_gljList_model.findOne({'ID':aglj.gljId});
  282. if(glj.rcode == std_glj.code){
  283. assglj = aglj;
  284. break;
  285. }
  286. }else if(aglj.gljId == glj.GLJID){
  287. assglj = aglj;
  288. break;
  289. }
  290. }
  291. if(assglj){
  292. let calQuantity = assglj.consumeAmt*assList[i].times;
  293. quantity += calQuantity
  294. }
  295. }
  296. }
  297. return scMathUtil.roundTo(quantity,-6);
  298. }
  299. function generateAdjustState(glj,coeList,adjustState,gljList,quantity) {
  300. //替换工料机 and 添加工料机
  301. if(glj._doc.createType=='replace'&&glj.rcode!=glj.code){
  302. adjustState.push({index:stateSeq.replace,content:glj.rcode+'换'+glj.code});
  303. }else if(glj._doc.createType=='add'){
  304. let displayQuantity = quantity;
  305. if(glj._doc.hasOwnProperty('customQuantity')&&(glj.customQuantity != null||glj.customQuantity != '')){
  306. displayQuantity = glj.customQuantity;
  307. }
  308. displayQuantity = displayQuantity&&displayQuantity!=""?parseFloat(displayQuantity):0;
  309. adjustState.push({index:stateSeq.add,content:'添'+glj.code+'量'+ displayQuantity,type:"添"+glj.code});
  310. }
  311. // to do
  312. //标准附注条件调整 + 自定义乘系数
  313. if(_.last(gljList).ID == glj.ID){//最后一个工料机的时候才生成,生成一次就可以了
  314. for(let i=0;i<coeList.length;i++){
  315. if(coeList[i].isAdjust==1){
  316. if(i==coeList.length-1){
  317. adjustState.push({index:stateSeq.cusCoe,content:getContent(coeList[i].coes)});//自定义乘系数要去掉倍数为1的
  318. }else {
  319. if(coeList[i].select_code && coeList[i].select_code!=""){
  320. _.remove(adjustState,{'content':coeList[i].original_code+'换'+coeList[i].select_code});//去掉替换工料机自动生成的调整状态
  321. adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].original_code+'换'+coeList[i].select_code});
  322. }
  323. for(let c of coeList[i].coes){
  324. if(c.coeType=='单个工料机') _.remove(adjustState,{'type':"添"+c.gljCode});//如果是单个工料机子目换算类型自动添加的,去掉前面手动生成的调整状态
  325. if(c.coeType=='替换人材机') _.remove(adjustState,{'content':c.gljCode+'换'+c.replaceCode});//如果是替换人材机子目换算类型自动添加的,去掉前面手动生成的调整状态
  326. }
  327. if(coeList[i].content) adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].content});//coeList[i].content
  328. }
  329. }
  330. }
  331. }
  332. //自定义消耗量
  333. if(glj._doc.createType!='add'&&glj._doc.hasOwnProperty('customQuantity')){
  334. if(glj.customQuantity!==null&&glj.customQuantity!=""){
  335. adjustState.push({index:stateSeq.cusQuantity,content:glj.code+'量'+parseFloat(glj.customQuantity)});
  336. }
  337. }
  338. //市场单价调整
  339. if(glj._doc.hasOwnProperty('marketPriceAdjust')&&glj.marketPriceAdjust&&glj.marketPriceAdjust!=0){
  340. //0101005价66.00
  341. adjustState.push({index:stateSeq.adjMak,content:glj.code+'价'+glj.marketPriceAdjust});
  342. }
  343. return adjustState;
  344. }
  345. function getContent(coes) {
  346. let stringList=[];
  347. let temAmount = null;
  348. let theSame = true;
  349. for(let t of coes){
  350. if(temAmount == null){
  351. temAmount = t.amount;
  352. }else if(temAmount != t.amount){
  353. theSame = false;
  354. break;
  355. }
  356. }
  357. for(let c of coes){
  358. if( c.amount&&c.amount!=1){
  359. let operator = c.operator;
  360. if(c.operator =="*"){
  361. operator = "X";
  362. }
  363. if(theSame == true && c.coeType == "定额"){
  364. stringList.push(c.coeType+operator+c.amount);
  365. break;
  366. }else
  367. if(theSame == false && c.coeType != "定额"){
  368. stringList.push(c.coeType+operator+c.amount);
  369. }
  370. }
  371. }
  372. return stringList.join(",");
  373. }
  374. function prepareAss(assList) {//处理辅助定额,支持多个辅助定额的情况
  375. for(let a of assList){
  376. if(a.groupList && a.groupList.length > 1){//组里有多个定额的情况
  377. let newList = _.sortByAll(a.groupList,[function(item){
  378. return parseFloat(item.param)
  379. }]);//先按参数排序
  380. let pre = 0;
  381. for(let n of newList){
  382. if(a.actualValue > pre && a.actualValue <= parseFloat(n.param)){//落在中间,则用组里的这条定额
  383. a._doc.param = n.param;
  384. a._doc.paramName = n.paramName;
  385. a._doc.assistCode = n.assistCode;
  386. break;
  387. }
  388. pre = parseFloat(n.param);
  389. }
  390. }
  391. }
  392. }
  393. function calculateTimes(ass){
  394. if(ass.isAdjust == 0) return 0;//打勾辅助定额才计算
  395. let times =(ass.actualValue-ass.stdValue)/ass.stepValue;
  396. let r = false;
  397. if(times<0){
  398. r=true;
  399. times=times*-1;
  400. }
  401. if(ass.carryBit=='四舍五入'){
  402. times = _.round(times,ass.decimal);
  403. }else if (ass.carryBit=='进一'){
  404. times =_.ceil(times,ass.decimal);
  405. }else if(ass.carryBit == '舍一'){
  406. times = _.floor(times,ass.decimal);
  407. }
  408. if(r){
  409. times=times*-1;
  410. }
  411. return scMathUtil.roundTo(times,-6);
  412. }
  413. function calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal){
  414. let coeQuantity = quantity;
  415. if(coeList.length>1){
  416. for(let i=0;i<coeList.length-1;i++){
  417. coeQuantity = everyCoe(coeQuantity,coeList[i],glj,gljList,decimal);
  418. }
  419. }
  420. return scMathUtil.roundTo(coeQuantity,-6);
  421. }
  422. function everyCoe(quantity,coe,glj,gljList,decimal) {
  423. let coeQuantity = quantity;
  424. if(coe.isAdjust==1){
  425. for(let i=0;i<coe.coes.length;i++){
  426. if(coe.coes[i].coeType=='单个工料机' &&coe.coes[i].gljCode==glj.code){//if(coe.coes[i].coeType=='单个工料机'&&coe.coes[i].gljCode==glj.code)
  427. coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
  428. }else if(coe.coes[i].coeType== "替换人材机" && glj.rcode == coe.coes[i].gljCode && glj.code == coe.coes[i].replaceCode){
  429. coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
  430. }else if(coe.coes[i].coeType== "所选人材机" && glj.rcode == coe.original_code && glj.code == coe.select_code ){
  431. coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
  432. } else if(coe.coes[i].coeType=='定额'){
  433. coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
  434. }else if(coeTypeMap[coe.coes[i].coeType]==getRootGLJType(glj.type).ID){
  435. coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
  436. }
  437. }
  438. }
  439. return scMathUtil.roundTo(coeQuantity,-6);
  440. }
  441. function calculateQuantityByCustomerCoes(quantify,coe,glj) {
  442. let rationAmount = coe.coes[0].amount;
  443. if(_.every(coe.coes,'amount',rationAmount)){
  444. return getCalculateResult(quantify, coe.coes[0])
  445. }else {
  446. for(let i=1;i<coe.coes.length;i++){
  447. if(coeTypeMap[coe.coes[i].coeType]==getRootGLJType(glj.type).ID){
  448. return getCalculateResult(quantify,coe.coes[i])
  449. }
  450. }
  451. }
  452. return quantify
  453. }
  454. function getCoeSelectedGLJ(gljList,rcode,code) {
  455. if(gljList&& code && code !=""){
  456. let o_glj = _.find(gljList,{'rcode':rcode,'code':code});
  457. return o_glj;
  458. }
  459. return null;
  460. }
  461. function getCalculateResult(quantify,c,coe,gljList,decimal) {
  462. let q = quantify;
  463. let o_glj = null;
  464. switch (c.operator){
  465. case '+' :
  466. q = q + c.amount;
  467. break;
  468. case '-' :
  469. q = q - c.amount;
  470. break;
  471. case '*' :
  472. q = q * c.amount;
  473. break;
  474. case '/' :
  475. q = q / c.amount;
  476. break;
  477. case '+*' :
  478. o_glj = getCoeSelectedGLJ(gljList,coe.original_code,coe.select_code);
  479. if(o_glj){
  480. q = q + c.amount * scMathUtil.roundForObj(o_glj.rationItemQuantity,decimal);
  481. }
  482. break;
  483. case '-*' :
  484. o_glj = getCoeSelectedGLJ(gljList,coe.original_code,coe.select_code);
  485. if(o_glj){
  486. q = q - c.amount * scMathUtil.roundForObj(o_glj.rationItemQuantity,decimal);
  487. }
  488. break;
  489. case '=' :
  490. q = c.amount;
  491. break;
  492. }
  493. return q;
  494. }
  495. function getRootGLJType(id){
  496. let glj_type_object = glj_type_util.getStdGljTypeCacheObj();
  497. let topTypeId = glj_type_object.getTopParentIdByItemId(id);
  498. let type = glj_type_object.getItemById(topTypeId);
  499. return type;
  500. }
  501. function getGLJTypeByID(id) {
  502. let type = getRootGLJType(id);
  503. if(type!=undefined){
  504. return type.fullName;
  505. }else {
  506. return '';
  507. }
  508. }