|
@@ -7,14 +7,48 @@ let moment = require('moment');
|
|
|
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';
|
|
|
|
|
|
var rationItemDAO = function(){};
|
|
|
|
|
|
+rationItemDAO.prototype.sortToNumber = function (datas) {
|
|
|
+ for(let i = 0, len = datas.length; i < len; i++){
|
|
|
+ let data = datas[i]._doc;
|
|
|
+ if(_exist(data, 'labourPrice')){
|
|
|
+ data['labourPrice'] = parseFloat(data['labourPrice']);
|
|
|
+ }
|
|
|
+ if(_exist(data, 'materialPrice')){
|
|
|
+ data['materialPrice'] = parseFloat(data['materialPrice']);
|
|
|
+ }
|
|
|
+ if(_exist(data, 'machinePrice')){
|
|
|
+ data['machinePrice'] = parseFloat(data['machinePrice']);
|
|
|
+ }
|
|
|
+ if(_exist(data, 'basePrice')){
|
|
|
+ data['basePrice'] = parseFloat(data['basePrice']);
|
|
|
+ }
|
|
|
+ if(_exist(data, 'rationGljList')){
|
|
|
+ for(let j = 0, jLen = data['rationGljList'].length; j < jLen; j++){
|
|
|
+ let raGljObj = data['rationGljList'][j]._doc;
|
|
|
+ if(_exist(raGljObj, 'consumeAmt')){
|
|
|
+ raGljObj['consumeAmt'] = parseFloat(raGljObj['consumeAmt']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ function _exist(data, attr){
|
|
|
+ return data && data[attr] !== undefined && data[attr];
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
rationItemDAO.prototype.getRationItemsBySection = function(sectionId,callback){
|
|
|
+ let me = this;
|
|
|
rationItemModel.find({"sectionId": sectionId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
|
|
|
- if(err) callback(true, "Fail to get items", "")
|
|
|
- else callback(false,"Get items successfully", data);
|
|
|
+ if(err) callback(true, "Fail to get items", "");
|
|
|
+ else {
|
|
|
+ me.sortToNumber(data);
|
|
|
+ callback(false,"Get items successfully", data);
|
|
|
+ }
|
|
|
})
|
|
|
};
|
|
|
rationItemDAO.prototype.mixUpdateRationItems = function(rationLibId, lastOpr, sectionId, updateItems, addItems, rIds, callback){
|
|
@@ -252,13 +286,13 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
|
|
|
gljArr.push({gljId: gljItems[i].ID, basePrice: adjBasePrice, gljParentType: gljParentType});
|
|
|
}
|
|
|
else {
|
|
|
- gljArr.push({gljId: gljItems[i].ID, basePrice: gljItems[i].basePrice, gljParentType: gljParentType});
|
|
|
+ gljArr.push({gljId: gljItems[i].ID, basePrice: parseFloat(gljItems[i].basePrice), gljParentType: gljParentType});
|
|
|
}
|
|
|
}
|
|
|
gljArr.forEach(function (gljItem) {
|
|
|
rationGljList.forEach(function (rationGlj) {
|
|
|
if(gljItem.gljId === rationGlj.gljId){
|
|
|
- gljItem.consumeAmt = rationGlj.consumeAmt;
|
|
|
+ gljItem.consumeAmt = parseFloat(rationGlj.consumeAmt);
|
|
|
}
|
|
|
})
|
|
|
});
|
|
@@ -266,7 +300,7 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
|
|
|
let labourPrc = [], materialPrc = [], machinePrc = [], singlePrc, updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, basePrice: 0};
|
|
|
gljArr.forEach(function (gljItem) {
|
|
|
if(gljItem.gljParentType !== -1){
|
|
|
- singlePrc = round(gljItem.basePrice * gljItem.consumeAmt, 3);
|
|
|
+ singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, -3);
|
|
|
if(gljItem.gljParentType === 1){
|
|
|
labourPrc.push(singlePrc);
|
|
|
}
|
|
@@ -283,26 +317,26 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
|
|
|
for(let i=0; i<labourPrc.length; i++){
|
|
|
sumLaP += labourPrc[i];
|
|
|
}
|
|
|
- updatePrc.labourPrice = round(sumLaP, 2);
|
|
|
+ updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
|
|
|
}
|
|
|
if(materialPrc.length > 0){
|
|
|
let sumMtP = 0;
|
|
|
for(let i= 0; i<materialPrc.length; i++){
|
|
|
sumMtP += materialPrc[i];
|
|
|
}
|
|
|
- updatePrc.materialPrice = round(sumMtP, 2);
|
|
|
+ updatePrc.materialPrice = scMathUtil.roundTo(sumMtP, -2);
|
|
|
}
|
|
|
if(machinePrc.length > 0){
|
|
|
let sumMaP = 0;
|
|
|
for(let i =0; i< machinePrc.length; i++){
|
|
|
sumMaP += machinePrc[i];
|
|
|
}
|
|
|
- updatePrc.machinePrice = round(sumMaP, 2);
|
|
|
+ updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
|
|
|
}
|
|
|
updatePrc.basePrice = updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice;
|
|
|
//updateDataBase
|
|
|
- rationItemModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice, materialPrice: updatePrc.materialPrice,
|
|
|
- machinePrice: updatePrc.machinePrice, basePrice: updatePrc.basePrice}},
|
|
|
+ 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);
|