Merge branch 'master' of https://bitbucket.org/venbainformationtechnology/smc_cet_financials_backend
This commit is contained in:
commit
f5984d1ac3
@ -33,43 +33,49 @@ exports.MasterDatas = async (req, res) => {
|
||||
};
|
||||
|
||||
// menu list api
|
||||
exports.MenuList = async (req, res) => {
|
||||
//findAll({ where :{is_active : 1} ,include : { association: 'sectionsmasterData' } });
|
||||
exports.MenuList = (req, res) => {
|
||||
|
||||
//findAll({ where :{is_active : 1} , include: { all: true, nested: true , where :{is_active : 1} }});
|
||||
try {
|
||||
const losid = req.query.losid
|
||||
const MasterData = await Statementsmaster.findAll({
|
||||
where :{is_active : 1} ,
|
||||
attributes: ['id', 'statement', 'is_active'],
|
||||
include :[{
|
||||
association: 'sectionsmasterData' ,
|
||||
where :{is_active : 1} ,
|
||||
attributes: ['id', 'section', 'is_active'],
|
||||
include :[{
|
||||
association: 'subsectionsmasterData' ,
|
||||
where :{is_active : 1} ,
|
||||
attributes: ['id', 'subsection','itemtext', 'is_active'],
|
||||
required :false
|
||||
}],
|
||||
required :false
|
||||
}],
|
||||
required :false
|
||||
|
||||
});
|
||||
//*******
|
||||
// const bk = { id:"brokenperiod",statement : "Broken Periods" }
|
||||
// MasterData.push(bk);
|
||||
//*******
|
||||
const EntitiesData = await Entities.findAll({where : { losid } , attributes: ['id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' ] });
|
||||
// call starter function here
|
||||
// req_obj ={"losid":losid}
|
||||
// starter_response = starter(req_obj);
|
||||
// if(starter_response.status == 200)
|
||||
// {
|
||||
Statementsmaster.findAll({
|
||||
where :{is_active : 1} ,
|
||||
attributes: ['id', 'statement', 'is_active'],
|
||||
include :[{
|
||||
association: 'sectionsmasterData' ,
|
||||
where :{is_active : 1} ,
|
||||
attributes: ['id', 'section', 'is_active'],
|
||||
include :[{
|
||||
association: 'subsectionsmasterData' ,
|
||||
where :{is_active : 1} ,
|
||||
attributes: ['id', 'subsection','itemtext', 'is_active'],
|
||||
required :false
|
||||
}],
|
||||
required :false
|
||||
}],
|
||||
required :false
|
||||
})
|
||||
.then(MasterData => {
|
||||
Entities.findAll({where : { losid } , attributes: ['id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' ] })
|
||||
.then(EntitiesData => {
|
||||
let data = [];
|
||||
EntitiesData.forEach((value, key)=>{
|
||||
obj_data = { ...value.dataValues , statementsmasterrData:MasterData }
|
||||
|
||||
data.push(obj_data);
|
||||
});
|
||||
|
||||
}); // end of EntitiesData foreach
|
||||
|
||||
res.send({'status':200,'message':"success",'data':data});
|
||||
logMsg.info("MenuList api working");
|
||||
}); // end of findall EntitiesData
|
||||
}); // end of findall masters datas
|
||||
//} // end of starter function if condition
|
||||
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return res.status(500).json({'status':404,'message':"failed",'data':"No data"})
|
||||
@ -233,25 +239,146 @@ exports.updateFinancials = (req, res) => {
|
||||
|
||||
|
||||
//testing
|
||||
exports.test = (req, res) => {
|
||||
sequelize.query("select a.losid,a.entityid,a.Y1,a.Y2,a.Y3,a.Y1_st_type as Y1_st_type_id, b.statement_name as Y1_st_type_name,a.Y2_st_type as Y2_st_type_id, c.statement_name as Y2_st_type_name,a.Y3_st_type as Y3_st_type_id, d.statement_name as Y3_st_type_name FROM entity_fin_years a JOIN (SELECT id,statement_name FROM statement_type) b ON a.Y1_st_type = b.id JOIN (SELECT id,statement_name FROM statement_type) c ON a.Y2_st_type = c.id JOIN (SELECT id,statement_name FROM statement_type) d ON a.Y3_st_type = d.id WHERE entityid = 6")
|
||||
.then(result => {
|
||||
console.log(result[0][0])
|
||||
res.send({'status':200,'message':"success",'data':result });
|
||||
}).catch(err => {
|
||||
res.status(500).send({'status':404,
|
||||
message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" });
|
||||
});
|
||||
// try
|
||||
// {
|
||||
// for (let i = 1; i < 121; i++) {
|
||||
// Financials.create({ "entity_id":7,"st_type":2,"itemid":i,"fy":2020,"value": Math.floor(50000 + Math.random() * 150000),"is_active":1,"createdby":2 })
|
||||
// }
|
||||
// res.send({'status':200,'message':"success",'data':"No data"});
|
||||
function starter(req, res)
|
||||
{
|
||||
|
||||
const losid = req.losid;
|
||||
try
|
||||
{
|
||||
|
||||
// }catch(err) {
|
||||
// res.status(500).send({'status':404,
|
||||
// message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||
// }); }
|
||||
//pro 42 api call using losid
|
||||
const Pro42Data = [
|
||||
{"losid":losid,"pan":"AA1234AAAA","cin":"test1_cin","bizname":"test1_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4},
|
||||
{"losid":losid,"pan":"BB1234BBBB","cin":"test2_cin","bizname":"test2_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4}
|
||||
];
|
||||
// insert pro42data into entities table using using foreach
|
||||
Pro42Data.forEach((Pro42Datavalue, key)=>{
|
||||
// check if the Pro42Data (entity) already inserted
|
||||
Entities.findOne({ where: { losid : Pro42Datavalue.losid , pan : Pro42Datavalue.pan , cin : Pro42Datavalue.cin } }).then(Entity => {
|
||||
if(Entity)
|
||||
{
|
||||
// skip inserting
|
||||
}
|
||||
else
|
||||
{
|
||||
Entities.create({ "losid":Pro42Datavalue.losid,"pan":Pro42Datavalue.pan,"cin":Pro42Datavalue.cin,"bizname":Pro42Datavalue.bizname,"entity_type":Pro42Datavalue.entity_type,"activity_group":Pro42Datavalue.activity_group,"biz_act_desc":Pro42Datavalue.biz_act_desc,"createdby":Pro42Datavalue.createdby})
|
||||
.then(Entitydata => {
|
||||
|
||||
//create Entityfinyears data
|
||||
const Y1 = new Date().getFullYear();
|
||||
const Y2 = Y1-1;
|
||||
const Y3 = Y2-1;
|
||||
Entityfinyears.create({ "losid":Entitydata.dataValues.losid,"entityid":Entitydata.dataValues.id,"Y1":Y1,"Y2":Y2,"Y3":Y3,"Y1_st_type":2,"Y2_st_type":2,"Y3_st_type":2})
|
||||
.then(Entityfinyearsdata => {
|
||||
|
||||
//create financials data based on Entityfinyears
|
||||
let fin_years_array = [];
|
||||
fin_years_array = [
|
||||
{"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y1,"st_type":Entityfinyearsdata.dataValues.Y1_st_type},
|
||||
{"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y2,"st_type":Entityfinyearsdata.dataValues.Y2_st_type},
|
||||
{"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y3,"st_type":Entityfinyearsdata.dataValues.Y3_st_type}
|
||||
];
|
||||
|
||||
// create skeletion
|
||||
fin_years_array.forEach((value, key)=>{
|
||||
const entity_id = value.entity_id;
|
||||
const fy = value.fy;
|
||||
const st_type = value.st_type;
|
||||
|
||||
// generate financials data array
|
||||
let fin_data_array = [];
|
||||
for (let i = 1; i < 120; i++)
|
||||
{
|
||||
fin_data_obj = { "entity_id":entity_id,"st_type":st_type,"itemid":i,"fy":fy,"value":0,"is_active":1,"createdby":4}
|
||||
fin_data_array.push(fin_data_obj);
|
||||
}
|
||||
//bulk financials data create
|
||||
Financials.bulkCreate(fin_data_array);
|
||||
//console.log(fin_data_array)
|
||||
});
|
||||
|
||||
}).catch(err => {
|
||||
res.status(404).send({'status':404,
|
||||
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
||||
}); // end of entity fin year table data insert
|
||||
|
||||
};
|
||||
}).catch(err => {
|
||||
res.status(404).send({'status':404,
|
||||
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
||||
}); // end of entity insert
|
||||
|
||||
} //end of else condition
|
||||
|
||||
}); // end of (losid,pan,cin) combination checking entity data exist or not
|
||||
|
||||
}); // end of pro42 data foreach
|
||||
|
||||
return {'status':200,'message':"success",'data':"No data"}; // success message
|
||||
|
||||
|
||||
} catch(err) {
|
||||
res.status(500).send({'status':404,
|
||||
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||
}); } //end of try catch
|
||||
|
||||
};
|
||||
|
||||
// create financial skeletion for given year
|
||||
exports.createFinancialYear = async (req, res) => {
|
||||
losid = req.body.losid;
|
||||
entityid = req.body.entityid;
|
||||
Entityfinyears.findOne({ where: { losid : losid , entityid : entityid } })
|
||||
.then(Entityfinyearsdata => {
|
||||
// rearrange entity_fin_years and update data
|
||||
const id = Entityfinyearsdata.dataValues.id;
|
||||
const Y1 = req.body.fy;
|
||||
const Y2 = Entityfinyearsdata.dataValues.Y1;
|
||||
const Y3 = Entityfinyearsdata.dataValues.Y2;
|
||||
const Y4 = Entityfinyearsdata.dataValues.Y3;
|
||||
const Y1_st_type = req.body.st_type;
|
||||
const Y2_st_type = Entityfinyearsdata.dataValues.Y1_st_type;
|
||||
const Y3_st_type = Entityfinyearsdata.dataValues.Y2_st_type;
|
||||
const Y4_st_type = Entityfinyearsdata.dataValues.Y3_st_type;
|
||||
Entityfinyears.update({ Y1:Y1,Y2:Y2,Y3:Y3,Y4:Y4,Y1_st_type:Y1_st_type,Y2_st_type:Y2_st_type,Y3_st_type:Y3_st_type,Y4_st_type:Y4_st_type },{ where: { id: id }})
|
||||
.then(UpdatedEntityfinyearsdata => {
|
||||
|
||||
// generate new financials data array for given FY with entity_id
|
||||
let fin_data_array = [];
|
||||
for (let i = 1; i < 120; i++)
|
||||
{
|
||||
fin_data_obj = { "entity_id":req.body.entityid,"st_type":req.body.st_type,"itemid":i,"fy":req.body.fy,"value":0,"is_active":1,"createdby":4}
|
||||
fin_data_array.push(fin_data_obj);
|
||||
}
|
||||
//bulk financials data create
|
||||
Financials.bulkCreate(fin_data_array);
|
||||
//response
|
||||
res.send({'status':200,'message':"success",'data':"No data"});
|
||||
}).catch(err => {
|
||||
res.status(404).send({'status':404,
|
||||
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
||||
}); // end of update Entityfinyears
|
||||
}).catch(err => {
|
||||
res.status(404).send({'status':404,
|
||||
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
||||
}); // end of findOne Entityfinyears
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
exports.testwo = async (req, res) => {
|
||||
req_obj ={"losid":"TEST123"}
|
||||
const testhree_fn = testhree(req_obj)
|
||||
console.log(testhree_fn)
|
||||
|
||||
};
|
||||
function testhree(req , res) {
|
||||
console.log( new Date().getFullYear())
|
||||
console.log( req.losid)
|
||||
return {'status':200,'message':"success"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -152,10 +152,10 @@ module.exports = app => {
|
||||
router.post("/BrokenPeriods", financials.BrokenPeriods);
|
||||
// create financials data
|
||||
router.post("/createFinancials", financials.createFinancials);
|
||||
// update financials data
|
||||
router.post("/updateFinancials", financials.updateFinancials);
|
||||
|
||||
|
||||
// create new FinancialYear skeletion
|
||||
//post_object = {"losid":"MW12233","entityid":6,"fy":2022,"st_type":2}
|
||||
router.post("/createFinancialYear", financials.createFinancialYear);
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user