|
@@ -488,6 +488,79 @@ rationItemDAO.prototype.updateAnnotation = function (lastOpr, repId, updateArr,
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+//计算导入数据的价格
|
|
|
+rationItemDAO.prototype.calcForRation = function (stdGljList, ration) {
|
|
|
+ //根据工料机类型划分价格
|
|
|
+ const labour = [1], material = [201, 202, 203, 204, 205, 206], machine = [301, 302, 303];
|
|
|
+ let labourPrc = [], materialPrc = [], machinePrc = [], singlePrc, updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, basePrice: 0};
|
|
|
+ let rationGljList = ration.rationGljList;
|
|
|
+ for(let rationGlj of rationGljList){
|
|
|
+ let glj = stdGljList[rationGlj.gljId];
|
|
|
+ let prcType = isDef(glj) ? getParentType(glj.gljType) : null;
|
|
|
+ if(isDef(prcType)){
|
|
|
+ singlePrc = scMathUtil.roundTo(parseFloat(glj.basePrice) * parseFloat(rationGlj.consumeAmt), -3);
|
|
|
+ if(prcType === 'labour'){
|
|
|
+ labourPrc.push(singlePrc);
|
|
|
+ }
|
|
|
+ else if(prcType === 'material'){
|
|
|
+ materialPrc.push(singlePrc);
|
|
|
+ }
|
|
|
+ else if(prcType === 'machine'){
|
|
|
+ machinePrc.push(singlePrc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //计算人工费
|
|
|
+ if(labourPrc.length > 0){
|
|
|
+ let sumLaP = 0;
|
|
|
+ for(let i = 0, len = labourPrc.length; i < len; i++){
|
|
|
+ sumLaP += labourPrc[i];
|
|
|
+ }
|
|
|
+ updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
|
|
|
+ }
|
|
|
+ //材料费
|
|
|
+ if(materialPrc.length > 0){
|
|
|
+ let sumLaP = 0;
|
|
|
+ for(let i = 0, len = materialPrc.length; i < len; i++){
|
|
|
+ sumLaP += materialPrc[i];
|
|
|
+ }
|
|
|
+ updatePrc.materialPrice = scMathUtil.roundTo(sumLaP, -2);
|
|
|
+ }
|
|
|
+ //机械费
|
|
|
+ if(machinePrc.length > 0){
|
|
|
+ let sumLaP = 0;
|
|
|
+ for(let i = 0, len = machinePrc.length; i < len; i++){
|
|
|
+ sumLaP += machinePrc[i];
|
|
|
+ }
|
|
|
+ updatePrc.machinePrice = scMathUtil.roundTo(sumLaP, -2);
|
|
|
+ }
|
|
|
+ //基价
|
|
|
+ updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice, -2);
|
|
|
+ //更新定额数据
|
|
|
+ ration.labourPrice = updatePrc.labourPrice.toString();
|
|
|
+ ration.materialPrice = updatePrc.materialPrice.toString();
|
|
|
+ ration.machinePrice = updatePrc.machinePrice.toString();
|
|
|
+ ration.basePrice = updatePrc.basePrice.toString();
|
|
|
+
|
|
|
+ function isDef(v){
|
|
|
+ return v !== undefined && v !== null;
|
|
|
+ }
|
|
|
+ //是否属于人工、材料、机械类型
|
|
|
+ function getParentType(type){
|
|
|
+ if(labour.indexOf(type) !== -1){
|
|
|
+ return 'labour';
|
|
|
+ }
|
|
|
+ if(material.indexOf(type) !== -1){
|
|
|
+ return 'material';
|
|
|
+ }
|
|
|
+ if(machine.indexOf(type) !== -1){
|
|
|
+ return 'machine';
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* 根据条件获取定额数据
|
|
|
*
|
|
@@ -533,8 +606,10 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) {
|
|
|
const stdGLJData = await stdBillsLibListsModel.getGljItemsByRep(rationRepository[0].gljLib);
|
|
|
// 整理标准工料机库数据
|
|
|
let stdGLJList = {};
|
|
|
+ let stdGLJListByID = {};
|
|
|
for (const tmp of stdGLJData) {
|
|
|
stdGLJList[tmp.code.toString()] = tmp.ID;
|
|
|
+ stdGLJListByID[tmp.ID] = tmp;
|
|
|
}
|
|
|
let lastData = {};
|
|
|
const rationData = [];
|
|
@@ -579,6 +654,10 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) {
|
|
|
caption: tmp[2],
|
|
|
rationRepId: rationRepId,
|
|
|
sectionId: 0,
|
|
|
+ labourPrice: '0',
|
|
|
+ materialPrice: '0',
|
|
|
+ machinePrice: '0',
|
|
|
+ basePrice: '0',
|
|
|
rationGljList: []
|
|
|
};
|
|
|
// 防止重复加入
|
|
@@ -607,6 +686,11 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) {
|
|
|
if (insertData.length <= 0) {
|
|
|
return true;
|
|
|
}
|
|
|
+ //计算价格
|
|
|
+ for(let ration of insertData){
|
|
|
+ this.calcForRation(stdGLJListByID, ration);
|
|
|
+ }
|
|
|
+
|
|
|
// 组织id
|
|
|
const counterInfo = await counter.counterDAO.getIDAfterCount(counter.moduleName.rations, insertData.length);
|
|
|
let maxId = counterInfo.value.sequence_value;
|