neimenggu_2017.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2019/4/17
  7. * @version
  8. */
  9. //允许使用的工料机类型:人工、普通材料、混凝土、砂浆、配合比、商品混凝土、商品砂浆、其他材料费、机械台班、机械组成物、机上人工、主材、设备、企业管理费、利润
  10. if(typeof allowGljType !== 'undefined'){
  11. allowGljType = [1, 201, 202, 203, 204, 205, 206, 207, 301, 302, 303, 4, 5, 6, 7];
  12. }
  13. if(typeof allowComponent !== 'undefined'){
  14. //允许含有组成物的工料机类型:混凝土、砂浆、配合比、机械台班、主材
  15. allowComponent = [202, 203, 204, 301, 4];
  16. }
  17. if(typeof componentType !== 'undefined'){
  18. //可以作为组成物的工料机类型:普通材料、机械组成物、机上人工、主材
  19. componentType = [201, 302, 303, 4];
  20. }
  21. if(typeof machineAllowComponent !== 'undefined'){
  22. //允许含有组成物的机械工料机类型:机械台班
  23. machineAllowComponent = [301];
  24. }
  25. if(typeof machineComponent !== 'undefined'){
  26. //可以作为机械工料机组成物的工料机类型:机械组成物、机上人工
  27. machineComponent = [302, 303];
  28. }
  29. if(typeof materialAllowComponent !== 'undefined'){
  30. //允许含有组成物的材料工料机类型:混凝土、砂浆、配合比
  31. materialAllowComponent = [202, 203, 204];
  32. }
  33. if(typeof materialComponent !== 'undefined'){
  34. //可以作为材料工料机组成物的工料机类型:普通材料
  35. materialComponent = [201];
  36. }
  37. // 计算单个人材机定额价小数位数
  38. let singleDecimal = -6,
  39. // 汇总小数位数
  40. summaryDecimal = -2,
  41. // 中间过程
  42. processDecimal = -6;
  43. //覆盖前端定额基价计算
  44. //基价=人工费+材料费+机械费+管理费利润
  45. //管理费利润=Round(人工费*(管理费消耗量+利润消耗量)%,2) 注:书中管理费、利润的单位都是“%”
  46. //材料费相关:应该是先算单位不是%的,算一个临时材料费,然后%的单个材料费算法是临时材料费*消耗量*0.01,然后最终的材料费是临时材料费+%的单个材料费
  47. if (typeof rationGLJOprObj !== 'undefined' && typeof rationGLJOprObj.rationCal !== 'undefined') {
  48. rationGLJOprObj.rationCal = function () {
  49. let me = rationGLJOprObj;
  50. let price = {gljType1: [], gljType2: [], gljType3: []},
  51. // 临时材料费(非%单位的材料)
  52. tempPrice = {gljType1: 0, gljType2: 0, gljType3: 0},
  53. rst = {labourPrice: 0, materialPrice: 0, machinePrice: 0},
  54. rationBasePrc = 0;
  55. let manageProfitConsume = 0; //管理费、利润消耗量
  56. if(me.currentRationItem && me.cache['_GLJ_' + me.currentRationItem.ID]){
  57. let cacheArr = me.cache['_GLJ_' + me.currentRationItem.ID];
  58. // 获取临时材料费
  59. cacheArr.forEach(function (gljData) {
  60. if(gljData.gljType && gljData.consumeAmt && gljData.unit !== '%'){
  61. let parentGLJType = parseInt(String(gljData.gljType)[0]);
  62. if (parentGLJType <= 3) { // 人工、材料、机械
  63. let single = scMathUtil.roundTo(gljData.basePrice * gljData.consumeAmt, singleDecimal);
  64. tempPrice['gljType' + parentGLJType] = scMathUtil.roundTo(tempPrice['gljType' + parentGLJType] + single, processDecimal);
  65. }
  66. }
  67. });
  68. // 临时材料费放入待汇总价格数组中
  69. for (let attr in price) {
  70. price[attr].push(tempPrice[attr])
  71. }
  72. cacheArr.forEach(function (gljData) {
  73. if(gljData.gljType && gljData.consumeAmt){
  74. let parentGLJType = parseInt(String(gljData.gljType)[0]);
  75. if (parentGLJType <= 3 && gljData.unit === '%') { // 人工、材料、机械
  76. // %的单个材料费算法是临时材料费*消耗量*0.01
  77. price['gljType' + parentGLJType].push(scMathUtil.roundTo(tempPrice['gljType' + parentGLJType] * gljData.consumeAmt * 0.01, singleDecimal));
  78. } else if([6, 7].includes(gljData.gljType)){
  79. manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljData.consumeAmt, processDecimal);
  80. }
  81. }
  82. });
  83. if(price.gljType1.length > 0){
  84. let labourPrice = 0;
  85. price.gljType1.forEach(function (singlePrc) {
  86. labourPrice = scMathUtil.roundTo(labourPrice + singlePrc, processDecimal);
  87. });
  88. let roundPrice = scMathUtil.roundTo(labourPrice, summaryDecimal);
  89. rst.labourPrice = roundPrice;
  90. rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, summaryDecimal);
  91. //管理费利润
  92. let manageProfitPrc = scMathUtil.roundTo(roundPrice * manageProfitConsume * 0.01, summaryDecimal);
  93. rationBasePrc = scMathUtil.roundTo(rationBasePrc + manageProfitPrc, summaryDecimal);
  94. }
  95. if(price.gljType2.length > 0){
  96. let materialPrice = 0;
  97. price.gljType2.forEach(function (singlePrc) {
  98. materialPrice = scMathUtil.roundTo(materialPrice + singlePrc, processDecimal);
  99. });
  100. let roundPrice = scMathUtil.roundTo(materialPrice, summaryDecimal);
  101. rst.materialPrice = roundPrice;
  102. rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, summaryDecimal);
  103. }
  104. if(price.gljType3.length > 0){
  105. let machinePrice = 0;
  106. price.gljType3.forEach(function (singlePrc) {
  107. machinePrice = scMathUtil.roundTo(machinePrice + singlePrc, processDecimal);
  108. });
  109. let roundPrice = scMathUtil.roundTo(machinePrice, summaryDecimal);
  110. rst.machinePrice = roundPrice;
  111. rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, summaryDecimal);
  112. }
  113. rst.rationBasePrc = rationBasePrc;
  114. }
  115. return rst;
  116. }
  117. }
  118. // 后端用 计算定额基价
  119. function calcRation(gljArr, scMathUtil) {
  120. let labourPrc = [],
  121. materialPrc = [],
  122. machinePrc = [],
  123. manageProfitConsume = 0,
  124. updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, manageProfitPrice: 0, basePrice: 0};
  125. // 临时材料费
  126. let tempPrice = {gljType1: 0, gljType2: 0, gljType3: 0};
  127. gljArr.forEach(function (gljItem) {
  128. if (gljItem.gljParentType !== -1 &&
  129. gljItem.gljParentType <= 3 &&
  130. gljItem.unit !== '%') {
  131. let single = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, singleDecimal);
  132. tempPrice['gljType' + gljItem.gljParentType] = scMathUtil.roundTo(tempPrice['gljType' + gljItem.gljParentType] + single, processDecimal);
  133. }
  134. });
  135. labourPrc.push(tempPrice.gljType1);
  136. materialPrc.push(tempPrice.gljType2);
  137. machinePrc.push(tempPrice.gljType3);
  138. gljArr.forEach(function (gljItem) {
  139. let singlePrc = 0;
  140. if(gljItem.gljParentType !== -1){
  141. if (gljItem.gljParentType <= 3 && gljItem.unit === '%') {
  142. singlePrc = scMathUtil.roundTo(tempPrice['gljType' + gljItem.gljParentType] * gljItem.consumeAmt * 0.01, singleDecimal);
  143. } else if (gljItem.gljParentType > 3) {
  144. singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, singleDecimal);
  145. }
  146. if(gljItem.gljParentType === 1){
  147. labourPrc.push(singlePrc);
  148. } else if(gljItem.gljParentType ===2){
  149. materialPrc.push(singlePrc);
  150. } else if(gljItem.gljParentType === 3){
  151. machinePrc.push(singlePrc);
  152. } else if(gljItem.gljParentType === 6){
  153. manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljItem.consumeAmt, processDecimal);
  154. } else if(gljItem.gljParentType === 7){
  155. manageProfitConsume = scMathUtil.roundTo(manageProfitConsume + gljItem.consumeAmt, processDecimal);
  156. }
  157. }
  158. });
  159. if(labourPrc.length > 0){
  160. let sumLaP = 0;
  161. for(let i=0; i<labourPrc.length; i++){
  162. sumLaP = scMathUtil.roundTo(sumLaP + labourPrc[i], processDecimal);
  163. }
  164. updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, summaryDecimal);
  165. updatePrc.manageProfitPrice = scMathUtil.roundTo(updatePrc.labourPrice * manageProfitConsume * 0.01, summaryDecimal);
  166. updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.manageProfitPrice, summaryDecimal);
  167. }
  168. if(materialPrc.length > 0){
  169. let sumMtP = 0;
  170. for(let i= 0; i<materialPrc.length; i++){
  171. sumMtP = scMathUtil.roundTo(sumMtP + materialPrc[i], processDecimal);
  172. }
  173. updatePrc.materialPrice = scMathUtil.roundTo(sumMtP, summaryDecimal);
  174. updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.materialPrice, summaryDecimal);
  175. }
  176. if(machinePrc.length > 0){
  177. let sumMaP = 0;
  178. for(let i =0; i< machinePrc.length; i++){
  179. sumMaP = scMathUtil.roundTo(sumMaP + machinePrc[i], processDecimal);
  180. }
  181. updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, summaryDecimal);
  182. updatePrc.basePrice = scMathUtil.roundTo(updatePrc.basePrice + updatePrc.machinePrice, summaryDecimal);
  183. }
  184. return updatePrc;
  185. }
  186. //计税方式
  187. const taxModel = {'common': 1, 'simple': 2};
  188. //价格属性:计税方式
  189. const pricePropertiesTemplate = [
  190. {
  191. region: '全省',
  192. taxModel: taxModel.common,
  193. price: {
  194. dataCode: 'price1',
  195. dataName: '单价-一般'
  196. }
  197. },
  198. {
  199. region: '全省',
  200. taxModel: taxModel.simple,
  201. price: {
  202. dataCode: 'price2',
  203. dataName: '单价-简易'
  204. }
  205. }
  206. ];
  207. //消耗量属性:计税方式
  208. const consumeAmtPropertiesTemplate = [
  209. {
  210. region: '全省',
  211. taxModel: taxModel.common,
  212. consumeAmt: {
  213. dataCode: 'consumeAmt1',
  214. dataName: '消耗-一般',
  215. refPrice: 'price1' //关联的单价字段
  216. }
  217. },
  218. {
  219. region: '全省',
  220. taxModel: taxModel.simple,
  221. consumeAmt: {
  222. dataCode: 'consumeAmt2',
  223. dataName: '消耗-简易',
  224. refPrice: 'price2' //关联的单价字段
  225. }
  226. }
  227. ];
  228. if(typeof module !== 'undefined'){
  229. module.exports = {
  230. pricePropertiesTemplate: pricePropertiesTemplate,
  231. consumeAmtPropertiesTemplate: consumeAmtPropertiesTemplate,
  232. calcRation: calcRation
  233. };
  234. }