bills_calc.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /**
  2. * Created by Mai on 2017/7/5.
  3. */
  4. const rationContent = 0, rationPrice = 1, rationPriceConverse = 2, billsPrice = 3;
  5. const sumTotalFeeFlag = 0, totalFeeFlag = 1;
  6. const rationContentUnitFeeFlag = 0, averageQtyUnitFeeFlag = 1, billsPriceUnitFeeFlag = 2;
  7. let rationContentCalcFields = [
  8. {'type': 'common', 'unitFeeFlag': rationContentUnitFeeFlag, 'totalFeeFlag': totalFeeFlag},
  9. {'type': 'labour', 'unitFeeFlag': rationContentUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  10. {'type': 'material', 'unitFeeFlag': rationContentUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  11. {'type': 'machine', 'unitFeeFlag': rationContentUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  12. ];
  13. let rationPriceCalcFields = [
  14. {'type': 'common', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': totalFeeFlag},
  15. {'type': 'labour', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  16. {'type': 'material', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  17. {'type': 'machine', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  18. ];
  19. let rationPriceConverseCalcFields = [
  20. {'type': 'common', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  21. {'type': 'labour', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  22. {'type': 'material', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  23. {'type': 'machine', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  24. ];
  25. let billsPriceCalcFields = [
  26. {'type': 'common', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': totalFeeFlag},
  27. {'type': 'labour', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  28. {'type': 'material', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  29. {'type': 'machine', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
  30. ];
  31. let nodeCalcObj = {
  32. node: null,
  33. digit: 2,
  34. field: null,
  35. getFee: calcFees.getFee,
  36. sumTotalFee: function() {
  37. let result = 0, child;
  38. for (child of this.node.children) {
  39. result += this.getFee(child.data, this.field.totalFee);
  40. }
  41. return result;
  42. },
  43. averageQty: function() {
  44. let result = 0, child, qty;
  45. result = this.sumTotalFee(this.field);
  46. qty = this.getFee(this.node.data, 'quantity');
  47. if (qty !== 0) {
  48. result = result / qty;
  49. }
  50. return result;
  51. },
  52. totalFee: function () {
  53. return this.getFee(this.node.data, this.field.unitFee) * this.getFee(this.node.data, 'quantity');
  54. },
  55. rationContentUnitFee: function () {
  56. let result = 0, child, qty = this.getFee(this.node.data, 'quantity');
  57. if (qty === 0) {
  58. qty = 1;
  59. }
  60. for (child of this.node.children) {
  61. result += (this.getFee(child.data, this.field.unitFee) * this.getFee(child.data, 'quantity') / qty).toDecimal(this.digit);
  62. }
  63. return result;
  64. }
  65. };
  66. let baseCalcField = [
  67. {
  68. ID: 1,
  69. // 序号
  70. serialNo: '一',
  71. // 费用代号
  72. code: "A",
  73. // 名称
  74. name: "定额直接费",
  75. // 计算基数
  76. dispExpr: "A1+A2+A3",
  77. // 基数说明
  78. statement: "人工费+材料费+机械费",
  79. // 费率
  80. feeRate: null,
  81. // 费用类别
  82. type: 'RationDirect',
  83. // 备注
  84. memo: ''
  85. }, {
  86. ID: 2,
  87. // 序号
  88. serialNo: '1',
  89. // 费用代号
  90. code: "A1",
  91. // 名称
  92. name: "人工费",
  93. // 计算基数
  94. dispExpr: "H_J",
  95. // 基数说明
  96. statement: "合计",
  97. // 费率
  98. feeRate: 0,
  99. // 费用类别
  100. type: 'labour',
  101. // 备注
  102. memo: ''
  103. }, {
  104. ID: 3,
  105. // 序号
  106. serialNo: '2',
  107. // 费用代号
  108. code: "A2",
  109. // 名称
  110. name: "材料费",
  111. // 计算基数
  112. dispExpr: "H_J",
  113. // 基数说明
  114. statement: "合计",
  115. // 费率
  116. feeRate: 100,
  117. // 费用类别
  118. type: 'material',
  119. // 备注
  120. memo: ''
  121. }, {
  122. ID: 4,
  123. // 序号
  124. serialNo: '3',
  125. // 费用代号
  126. code: "A3",
  127. // 名称
  128. name: "机械费",
  129. // 计算基数
  130. dispExpr: "H_J",
  131. // 基数说明
  132. statement: "合计",
  133. // 费率
  134. feeRate: 0,
  135. // 费用类别
  136. type: 'machine',
  137. // 备注
  138. memo: ''
  139. }, {
  140. ID: 5,
  141. // 序号
  142. serialNo: '二',
  143. // 费用代号
  144. code: "A4",
  145. // 名称
  146. name: "管理费",
  147. // 计算基数
  148. dispExpr: "A",
  149. // 基数说明
  150. statement: "定额直接费",
  151. // 费率
  152. feeRate: 0,
  153. // 费用类别
  154. type: 'management',
  155. // 备注
  156. memo: ''
  157. }, {
  158. ID: 6,
  159. // 序号
  160. serialNo: '三',
  161. // 费用代号
  162. code: "B",
  163. // 名称
  164. name: "利润",
  165. // 计算基数
  166. dispExpr: "A",
  167. // 基数说明
  168. statement: "定额直接费",
  169. // 费率
  170. feeRate: 0,
  171. // 费用类别
  172. type: 'profit',
  173. // 备注
  174. memo: ''
  175. }, {
  176. ID: 7,
  177. // 序号
  178. serialNo: '四',
  179. // 费用代号
  180. code: "C",
  181. // 名称
  182. name: "风险费用",
  183. // 计算基数
  184. dispExpr: "",
  185. // 基数说明
  186. statement: "",
  187. // 费率
  188. feeRate: null,
  189. // 费用类别
  190. type: 'risk',
  191. // 备注
  192. memo: ''
  193. }, {
  194. ID: 8,
  195. // 序号
  196. serialNo: '',
  197. // 费用代号
  198. code: "",
  199. // 名称
  200. name: "综合单价",
  201. // 计算基数
  202. dispExpr: "A+B",
  203. // 基数说明
  204. statement: "定额直接费+利润",
  205. // 费率
  206. feeRate: NaN,
  207. // 费用类别
  208. type: 'common',
  209. // 备注
  210. memo: ''
  211. }
  212. ];
  213. class BillsCalcHelper {
  214. constructor (project, CalcFlag) {
  215. this.project = project;
  216. this.CalcFlag = CalcFlag;
  217. this.digit = 2;
  218. switch (this.CalcFlag) {
  219. case rationContent:
  220. this.calcField = rationContentCalcFields;
  221. break;
  222. case rationPrice:
  223. this.calcField = rationPriceCalcFields;
  224. break;
  225. case rationPriceConverse:
  226. this.calcField = rationPriceConverseCalcFields;
  227. break;
  228. case billsPrice:
  229. this.calcField = billsPriceCalcFields;
  230. break;
  231. default:
  232. this.calcField = [];
  233. }
  234. this.InitFields(this.calcField);
  235. };
  236. getBillsGLjs (node) {
  237. let rations = this.project.Ration.getBillsSortRation(node.source.getID());
  238. let gljs = this.project.ration_glj.getGatherGljArrByRations(rations);
  239. for (let glj of gljs) {
  240. glj.quantity = (glj.quantity / calcFees.getFee(node.data, 'quantity')).toDecimal(4);
  241. }
  242. return gljs;
  243. };
  244. calcRationLeaf (node, fields) {
  245. nodeCalcObj.node = node;
  246. nodeCalcObj.digit = this.digit;
  247. calcFees.checkFields(node.data, fields);
  248. let nodeCalc = nodeCalcObj, virData= null;
  249. // 清单单价:套用定额计算程序
  250. if (this.CalcFlag === billsPrice) {
  251. rationCalcObj.calcGljs = this.getBillsGLjs(node);
  252. console.log(rationCalcObj.calcGljs);
  253. rationCalcObj.calcFields = rationCalcFields;
  254. virData = rationCalcObj.calculate();
  255. }
  256. for (let field of fields) {
  257. nodeCalcObj.field = field;
  258. switch (field.unitFeeFlag) {
  259. case rationContentUnitFeeFlag:
  260. node.data.feesIndex[field.type].unitFee = nodeCalcObj.rationContentUnitFee().toDecimal(this.digit);
  261. break;
  262. case averageQtyUnitFeeFlag:
  263. node.data.feesIndex[field.type].unitFee = nodeCalcObj.averageQty().toDecimal(this.digit);
  264. break;
  265. case billsPriceUnitFeeFlag:
  266. node.data.feesIndex[field.type].unitFee = virData[field.type];
  267. break;
  268. default:
  269. node.data.feesIndex[field.type].unitFee = 0;
  270. }
  271. switch (field.totalFeeFlag) {
  272. case sumTotalFeeFlag:
  273. node.data.feesIndex[field.type].totalFee = nodeCalcObj.sumTotalFee().toDecimal(this.digit);
  274. break;
  275. case totalFeeFlag:
  276. node.data.feesIndex[field.type].totalFee = nodeCalcObj.totalFee().toDecimal(this.digit);
  277. break;
  278. default:
  279. node.data.feesIndex[field.type].totalFee = 0;
  280. }
  281. }
  282. };
  283. calcVolumePriceLeaf (node, fields) {
  284. };
  285. calcParent (node, fields) {
  286. nodeCalcObj.node = node;
  287. calcFees.checkFields(node.data, fields);
  288. for (let field of fields) {
  289. nodeCalcObj.field = field;
  290. node.data.feesIndex[field.type].totalFee = nodeCalcObj.sumTotalFee().toDecimal(this.digit);
  291. }
  292. };
  293. calcNodes (nodes) {
  294. for (let node of nodes) {
  295. if (node.sourceType !== this.project.Bills.getSourceType()) {
  296. return;
  297. }
  298. if (node.source.children.length > 0) {
  299. this.calcNodes(node.children);
  300. this.calcParent(node, this.calcField);
  301. } else {
  302. if (node.children.length > 0) {
  303. if (node.firstChild().sourceType === this.project.Ration.getSourceType()) {
  304. this.calcRationLeaf(node, this.calcField);
  305. } else {
  306. this.calcVolumePriceLeaf(node, this.calcField);
  307. }
  308. } else {
  309. }
  310. }
  311. }
  312. };
  313. calcAll () {
  314. this.calcNodes(this.project.mainTree.roots);
  315. };
  316. InitFields (fields) {
  317. for (let field of fields) {
  318. if (field.unitFee) return;
  319. field.unitFee = 'feesIndex.' + field.type + '.unitFee';
  320. field.unitFeeSplit = field.unitFee.split('.');
  321. field.totalFee = 'feesIndex.' + field.type + '.totalFee';
  322. field.totalFeeSplit = field.totalFee.split('.');
  323. field.tenderUnitFee = 'feesIndex.'+ field.type + '.tenderUnitFee';
  324. field.tenderUnitFeeSplit = field.tenderUnitFee.split('.');
  325. field.tenderTotalFee = 'feesIndex.' + field.type + '.tenderTotalFee';
  326. field.tenderTotalFeeSplit = field.tenderTotalFee.split('.');
  327. }
  328. }
  329. }