|
@@ -8,7 +8,7 @@ let counter = require('../../../public/counter/counter');
|
|
|
let gljDao = require('./glj_repository');
|
|
|
let rationRepositoryDao = require('./repository_map');
|
|
|
const scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
|
-import {rationItemModel} from './schemas';
|
|
|
+import {rationItemModel, compleRationModel} from './schemas';
|
|
|
|
|
|
var rationItemDAO = function(){};
|
|
|
|
|
@@ -208,12 +208,8 @@ function round(v,e){
|
|
|
return Math.round(v*t)/t;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
|
|
|
- // let basePrcArr = data.basePrcArr;
|
|
|
- // adjGljId = data.gljId, adjBasePrice = data.basePrice, adjGljType = data.gljType,
|
|
|
- // repId = data.repId, lastOpr = data.lastOpr;
|
|
|
- //
|
|
|
- // let updateArr;
|
|
|
async.each(basePrcArr, function (basePrcObj, finalCb) {
|
|
|
let adjGljId = basePrcObj.gljId, adjBasePrice = basePrcObj.basePrice, adjGljType = basePrcObj.gljType;
|
|
|
async.waterfall([
|
|
@@ -230,7 +226,25 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
|
|
|
cb(err);
|
|
|
}
|
|
|
else{
|
|
|
- cb(null, result);
|
|
|
+ //补充定额
|
|
|
+ compleRationModel.find({'rationGljList.gljId': adjGljId},{ID: 1, rationGljList: 1}, function (err, compleRst) {
|
|
|
+ if(err){
|
|
|
+ cb(err);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ compleRationModel.update({'rationGljList.gljId': adjGljId}, {$pull: {rationGljList: {gljId: adjGljId}}}, {multi: true}, function (err) {
|
|
|
+ if(err){
|
|
|
+ cb(err);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ for(let i = 0, len = compleRst.length; i < len; i++){
|
|
|
+ compleRst[i]._doc.type = 'complementary';
|
|
|
+ }
|
|
|
+ cb(null, result.concat(compleRst));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -242,27 +256,26 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
|
|
|
cb(err);
|
|
|
}
|
|
|
else{
|
|
|
- cb(null, result);
|
|
|
+ compleRationModel.find({'rationGljList.gljId': adjGljId}, function (err, compleRst) {
|
|
|
+ if(err){
|
|
|
+ cb(err);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ for(let i = 0, len = compleRst.length; i < len; i++){
|
|
|
+ compleRst[i]._doc.type = 'complementary';
|
|
|
+ }
|
|
|
+ cb(null, result.concat(compleRst));
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- /* rationItemModel.find({'rationGljList.gljId': adjGljId}, function (err, result) {
|
|
|
- if(err){
|
|
|
- cb(err);
|
|
|
- }
|
|
|
- else{
|
|
|
- cb(null, result);
|
|
|
- }
|
|
|
- });*/
|
|
|
},
|
|
|
function (result, cb) {
|
|
|
async.each(result, function (rationItem, ecb) {
|
|
|
let rationGljList = rationItem.rationGljList,
|
|
|
gljIds = [];
|
|
|
- rationGljList.forEach(function (rationGlj) {
|
|
|
- gljIds.push(rationGlj.gljId);
|
|
|
- });
|
|
|
- gljDao.getGljItems(gljIds, function(err, gljItems){
|
|
|
+ gljDao.getStdCompleGljItems(rationGljList, function(err, gljItems){
|
|
|
if(err){
|
|
|
ecb(err);
|
|
|
}
|
|
@@ -335,16 +348,30 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
|
|
|
}
|
|
|
updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice, -2);
|
|
|
//updateDataBase
|
|
|
- rationItemModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice.toString(), materialPrice: updatePrc.materialPrice.toString(),
|
|
|
- machinePrice: updatePrc.machinePrice.toString(), basePrice: updatePrc.basePrice.toString()}},
|
|
|
- function (err, result) {
|
|
|
- if(err){
|
|
|
- ecb(err);
|
|
|
- }
|
|
|
- else {
|
|
|
- ecb(null);
|
|
|
- }
|
|
|
- });
|
|
|
+ if(rationItem._doc.type !== undefined && rationItem._doc.type === 'complementary'){
|
|
|
+ compleRationModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice.toString(), materialPrice: updatePrc.materialPrice.toString(),
|
|
|
+ machinePrice: updatePrc.machinePrice.toString(), basePrice: updatePrc.basePrice.toString()}},
|
|
|
+ function (err, result) {
|
|
|
+ if(err){
|
|
|
+ ecb(err);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ecb(null);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ rationItemModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice.toString(), materialPrice: updatePrc.materialPrice.toString(),
|
|
|
+ machinePrice: updatePrc.machinePrice.toString(), basePrice: updatePrc.basePrice.toString()}},
|
|
|
+ function (err, result) {
|
|
|
+ if(err){
|
|
|
+ ecb(err);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ecb(null);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}, function(err){
|