createFinancials:GWM

This commit is contained in:
sriramv 2021-08-28 10:42:27 +05:30
parent 40de1eb17b
commit 995b25018f

View File

@ -176,29 +176,28 @@ exports.BrokenPeriods = (req, res) => {
exports.createFinancials = (req, res) => {
let req_array_data = req.body;
let req_array_id = [];
const req_array_data = req.body;
req_array_data.forEach((value, key)=>{
req_array_id.push(value.id);
delete value.id;
});
Financials.update({ is_active : 0 },{ where: { id: req_array_id }})
.then(data => {
logMsg.info("Is_active 0 update Success for :"(data));
Financials.findOne({ where: { id : value.id } }).then(function(result) {
if(result.value == value.value)
{
logMsg.info("Value not updated for - EntityId : "+value.entity_id+" , FY : "+value.fy+",ItemId : "+value.itemid+",primary key :"+value.id);
}
else
{
Financials.update({ is_active : 0 },{ where: { id: value.id }});
logMsg.info("updated is_active = 0 for primary key : "+value.id);
Financials.create({ "entity_id":value.entity_id,"st_type":value.st_type,"itemid":value.itemid,"fy":value.fy,"value":value.value,"is_active":value.is_active,"createdby":value.createdby })
logMsg.info("Created new financials data - EntityId : "+value.entity_id+" , FY : "+value.fy+",ItemId : "+value.itemid);
}
})
.catch(err => {
logMsg.info("Is_active update failed ,meaasge :"(err.message));
});
Financials.bulkCreate(req_array_data)
.then(data => {
res.send({'status':200,'message':"success",'data':data});
logMsg.info("Success :"(data));
})
.catch(err => {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
});
});
res.send({'status':200,'message':"success",'data':"No data"});
};