171 lines
3.3 KiB
JavaScript
171 lines
3.3 KiB
JavaScript
|
|
const { sequelize,MasterP , MasterC , OtherIncomeP , OtherIncomeC , Master} = require('../models')
|
|
const { logMsg } = require('../services/logger.js');
|
|
|
|
exports.otherIncomeList = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
OtherIncomeData = await OtherIncomeP.findAll({ where:{ losid:req.query.losid, is_active:1},order :[['order_id','ASC']],include:[{model:OtherIncomeC}]}).catch(err=>{});
|
|
|
|
if(OtherIncomeData.length != 0)
|
|
{
|
|
|
|
res.send({'status':200 , message:"Success." ,'data': OtherIncomeData});
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
MasterData = await MasterP.findAll({ where:{ is_active:1},include:[{model:MasterC}]}).catch(err=>{});
|
|
var MasterDataInsert = new Promise(async(resolve, reject) => {
|
|
|
|
MasterData.forEach(async(master_value,index,array) => {
|
|
OtherIncomeP.create({losid:req.query.losid,order_id:master_value.order_id,table_name:master_value.table_name,particulars:master_value.particulars})
|
|
.then(async(parent_data)=>{
|
|
master_value.MasterCs.forEach(async(child_data) => {
|
|
await OtherIncomeC.create({other_income_id:parent_data.dataValues.id,column_name:child_data.column_name,value:child_data.value})
|
|
.catch(err=>{logMsg.info(err);});
|
|
});
|
|
if (index === array.length -1) { resolve(); }
|
|
}).catch(err=>{logMsg.info(err);});
|
|
});
|
|
|
|
});
|
|
MasterDataInsert.then(async()=>{
|
|
setTimeout(async() => {
|
|
OtherIncomeData = await OtherIncomeP.findAll({ where:{ losid:req.query.losid, is_active:1},order :[['order_id','ASC']],include:[{model:OtherIncomeC}]}).catch(err=>{});
|
|
res.send({'status':200 , message:"Success." ,'data': OtherIncomeData});
|
|
}, 500);
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch(err) {
|
|
res.status(500).send({'status':404,
|
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
|
}); } //end of try catch
|
|
|
|
};
|
|
|
|
|
|
exports.updateOtherIncome = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
var updateOtherIncome = new Promise(async(resolve, reject) => {
|
|
for(const IncomeData of req.body)
|
|
{
|
|
await OtherIncomeP.update({updatedby:IncomeData.updatedby},{where:{id:IncomeData.id}}).catch(err=>{logMsg.info(err);});
|
|
for(const [index , child_data] of IncomeData.childData.entries())
|
|
{
|
|
await OtherIncomeC.update({value:child_data.value},{where:{id:child_data.id,other_income_id:child_data.other_income_id,column_name:child_data.column_name}})
|
|
.then(data=>{
|
|
if (index === [IncomeData.childData].length -1) { resolve(data); }
|
|
})
|
|
.catch(err=>{logMsg.info(err);});
|
|
}
|
|
}
|
|
});
|
|
updateOtherIncome.then(async(data)=>{
|
|
res.send({'status':200 , message:"Success." ,'data': data});
|
|
});
|
|
|
|
} catch(err) {
|
|
res.status(500).send({'status':404,
|
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
|
}); } //end of try catch
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.getMasterData = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
data =await Master.findAll();
|
|
res.send({'status':200 , message:"Success." ,'data': data});
|
|
|
|
} catch(err) {
|
|
res.status(500).send({'status':404,
|
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
|
}); } //end of try catch
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|