diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index f0e8699..4fec31c 100644 --- a/app/controllers/financial.controller.js +++ b/app/controllers/financial.controller.js @@ -34,7 +34,7 @@ exports.MasterDatas = async (req, res) => { // menu list api exports.MenuList = (req, res) => { - //findAll({ where :{is_active : 1} , include: { all: true, nested: true , where :{is_active : 1} }}); + //Statementsmaster.findAll({ where :{is_active : 1} , include: { all: true, nested: true , where :{is_active : 1} , required:false}}) try { const losid = req.query.losid // call starter function here @@ -42,6 +42,7 @@ exports.MenuList = (req, res) => { req_obj ={"losid":losid} starter_response = starter(req_obj); + console.log(starter_response) setTimeout(()=>{ if(starter_response.status == 200) { @@ -91,34 +92,38 @@ exports.MenuList = (req, res) => { exports.FinantialsSummary = async (req, res) => { const id = req.query.entityid - 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 LEFT JOIN (SELECT id,statement_name FROM statement_type) b ON a.Y1_st_type = b.id LEFT JOIN (SELECT id,statement_name FROM statement_type) c ON a.Y2_st_type = c.id LEFT JOIN (SELECT id,statement_name FROM statement_type) d ON a.Y3_st_type = d.id WHERE entityid ="+id) + sequelize.query("select a.losid,a.entityid,a.Y1,a.Y2,a.Y3,a.Y4,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 , a.Y4_st_type as Y4_st_type_id, e.statement_name as Y4_st_type_name FROM entity_fin_years a LEFT JOIN (SELECT id,statement_name FROM statement_type) b ON a.Y1_st_type = b.id LEFT JOIN (SELECT id,statement_name FROM statement_type) c ON a.Y2_st_type = c.id LEFT JOIN (SELECT id,statement_name FROM statement_type) d ON a.Y3_st_type = d.id LEFT JOIN (SELECT id,statement_name FROM statement_type) e ON a.Y4_st_type = e.id WHERE entityid ="+id) .then(data => { const Year_1 = data[0][0].Y1; const Year_2 = data[0][0].Y2; const Year_3 = data[0][0].Y3; + const Year_4 = data[0][0].Y4; const years_data = data[0][0]; - // const current_year = new Date().getFullYear(); - // const current_month = new Date().getMonth() + 1; - // let add_new_FY_flag; - // if(Year_1 >= current_year && 3 < current_month) - // { - // add_new_FY_flag = {show_add_finyear_button:0}; - // } - // else - // { - // add_new_FY_flag = {show_add_finyear_button:1,FY:current_year}; - // } - add_new_FY_flag = financialControllerHelper.addNewFyFlag(Year_1); - //sequelize.query("Select a.entity_id,x.id as statement_id,x.statement as statement,y.id as section_id,y.section as section,e.subsection as subsection_id,z.subsection as subsection , z.itemtext as subsection_itemtext ,a.itemid,e.itemtext as items,e.formula,e.is_calculated,a.st_type,f.statement_name as st_name,a.fy as Y1,a.id as Y1_id ,a.value as Y1_value ,b.fy as Y2, b.id Y2_id ,b.value Y2_value ,c.fy as Y3,c.id as Y3_id ,c.value Y3_value , g.remarks FROM financials a JOIN ( SELECT id,itemtext,statement,section,subsection,formula,is_calculated FROM itemsmaster ) e ON a.itemid = e.id LEFT JOIN ( SELECT id, statement_name FROM statement_type ) f ON a.st_type = f.id LEFT JOIN ( SELECT id,entity_id,itemid,remarks FROM fin_remarks ) g ON a.entity_id = g.entity_id and a.itemid = g.itemid JOIN ( SELECT id, statement FROM statementsmaster ) x ON e.statement = x.id JOIN ( SELECT id, section FROM sectionsmaster ) y ON e.section = y.id LEFT JOIN ( SELECT id, subsection , itemtext FROM subsectionsmaster ) z ON e.subsection = z.id JOIN ( SELECT id,entity_id, itemid, value,fy,is_active FROM financials WHERE fy = "+Year_3+" and is_active = 1 and entity_id = "+id+") c ON a.entity_id = c.entity_id and a.itemid = c.itemid JOIN ( SELECT id,entity_id, itemid, value,fy,is_active FROM financials WHERE fy = "+Year_2+" and is_active = 1 and entity_id = "+id+") b ON a.entity_id = b.entity_id and a.itemid = b.itemid AND a.fy = "+Year_1+" WHERE a.entity_id = "+id+" and a.is_active = 1 order by x.id asc , y.id asc , a.itemid asc ") - sequelize.query("Select a.entity_id,x.id as statement_id,x.statement as statement,y.id as section_id,y.section as section,e.subsection as subsection_id,z.subsection as subsection , z.itemtext as subsection_itemtext ,a.itemid,e.itemtext as items,e.formula,e.is_calculated,a.st_type as Y1_st_type,a.fy as Y1,a.id as Y1_id ,a.value as Y1_value ,b.st_type as Y2_st_type,b.fy as Y2, b.id Y2_id ,b.value Y2_value ,c.st_type as Y3_st_type,c.fy as Y3,c.id as Y3_id ,c.value Y3_value , g.remarks , g.id as remarks_id FROM financials a LEFT JOIN ( SELECT id,entity_id,itemid,remarks FROM fin_remarks WHERE is_active = 1) g ON a.entity_id = g.entity_id and a.itemid = g.itemid JOIN ( SELECT id,itemtext,statement,section,subsection,formula,is_calculated FROM itemsmaster ) e ON a.itemid = e.id JOIN ( SELECT id, statement FROM statementsmaster ) x ON e.statement = x.id JOIN ( SELECT id, section FROM sectionsmaster ) y ON e.section = y.id LEFT JOIN ( SELECT id, subsection , itemtext FROM subsectionsmaster ) z ON e.subsection = z.id LEFT JOIN ( SELECT id,entity_id, itemid, value,fy,is_active,st_type FROM financials WHERE fy = "+Year_3+" and entity_id ="+id+" and is_active = 1) c ON a.entity_id = c.entity_id and a.itemid = c.itemid LEFT JOIN ( SELECT id,entity_id, itemid, value,fy,is_active,st_type FROM financials WHERE fy = "+Year_2+" and entity_id = "+id+" and is_active = 1) b ON a.entity_id = b.entity_id and a.itemid = b.itemid WHERE a.fy = "+Year_1+" and a.entity_id = "+id+" and a.is_active = 1 order by e.statement asc , e.section asc , e.id asc") - .then(result => { - const arr = {"years" : years_data , "summary" : result } - res.send({'status':200,'message':"success",'data':{"years" : years_data ,"add_new_finyear_flag" : add_new_FY_flag, "summary" : result } }); - }).catch(err => { + add_new_FY_flag = financialControllerHelper.addNewFyFlag(Year_1); + if(Year_4 == null) + { + sequelize.query("Select a.entity_id,x.id as statement_id,x.statement as statement,y.id as section_id,y.section as section,e.subsection as subsection_id,z.subsection as subsection , z.itemtext as subsection_itemtext ,a.itemid,e.itemtext as items,e.formula,e.is_calculated,a.st_type as Y1_st_type,a.fy as Y1,a.id as Y1_id ,a.value as Y1_value ,b.st_type as Y2_st_type,b.fy as Y2, b.id Y2_id ,b.value Y2_value ,c.st_type as Y3_st_type,c.fy as Y3,c.id as Y3_id ,c.value Y3_value , g.remarks , g.id as remarks_id FROM financials a LEFT JOIN ( SELECT id,entity_id,itemid,remarks FROM fin_remarks WHERE is_active = 1) g ON a.entity_id = g.entity_id and a.itemid = g.itemid JOIN ( SELECT id,itemtext,statement,section,subsection,formula,is_calculated FROM itemsmaster ) e ON a.itemid = e.id JOIN ( SELECT id, statement FROM statementsmaster ) x ON e.statement = x.id JOIN ( SELECT id, section FROM sectionsmaster ) y ON e.section = y.id LEFT JOIN ( SELECT id, subsection , itemtext FROM subsectionsmaster ) z ON e.subsection = z.id LEFT JOIN ( SELECT id,entity_id, itemid, value,fy,is_active,st_type FROM financials WHERE fy = "+Year_3+" and entity_id ="+id+" and is_active = 1) c ON a.entity_id = c.entity_id and a.itemid = c.itemid LEFT JOIN ( SELECT id,entity_id, itemid, value,fy,is_active,st_type FROM financials WHERE fy = "+Year_2+" and entity_id = "+id+" and is_active = 1) b ON a.entity_id = b.entity_id and a.itemid = b.itemid WHERE a.fy = "+Year_1+" and a.entity_id = "+id+" and a.is_active = 1 order by e.statement asc , e.section asc , e.id asc") + .then(result => { + const arr = {"years" : years_data , "summary" : result } + res.send({'status':200,'message':"success",'data':{"years" : years_data ,"add_new_finyear_flag" : add_new_FY_flag, "summary" : result } }); + }).catch(err => { res.status(500).send({'status':404, message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" }); - }); + }); + } + else + { + sequelize.query("Select a.entity_id,x.id as statement_id,x.statement as statement,y.id as section_id,y.section as section,e.subsection as subsection_id,z.subsection as subsection , z.itemtext as subsection_itemtext ,a.itemid,e.itemtext as items,e.formula,e.is_calculated,a.st_type as Y1_st_type,a.fy as Y1,a.id as Y1_id ,a.value as Y1_value ,b.st_type as Y2_st_type,b.fy as Y2, b.id Y2_id ,b.value Y2_value ,c.st_type as Y3_st_type,c.fy as Y3,c.id as Y3_id ,c.value Y3_value ,d.st_type as Y4_st_type,d.fy as Y4,d.id as Y4_id ,d.value Y4_value , g.remarks , g.id as remarks_id FROM financials a LEFT JOIN ( SELECT id,entity_id,itemid,remarks FROM fin_remarks WHERE is_active = 1) g ON a.entity_id = g.entity_id and a.itemid = g.itemid JOIN ( SELECT id,itemtext,statement,section,subsection,formula,is_calculated FROM itemsmaster ) e ON a.itemid = e.id JOIN ( SELECT id, statement FROM statementsmaster ) x ON e.statement = x.id JOIN ( SELECT id, section FROM sectionsmaster ) y ON e.section = y.id LEFT JOIN ( SELECT id, subsection , itemtext FROM subsectionsmaster ) z ON e.subsection = z.id LEFT JOIN ( SELECT id,entity_id, itemid, value,fy,is_active,st_type FROM financials WHERE fy = "+Year_4+" and entity_id ="+id+" and is_active = 1) d ON a.entity_id = d.entity_id and a.itemid = d.itemid LEFT JOIN ( SELECT id,entity_id, itemid, value,fy,is_active,st_type FROM financials WHERE fy = "+Year_3+" and entity_id ="+id+" and is_active = 1) c ON a.entity_id = c.entity_id and a.itemid = c.itemid LEFT JOIN ( SELECT id,entity_id, itemid, value,fy,is_active,st_type FROM financials WHERE fy = "+Year_2+" and entity_id = "+id+" and is_active = 1) b ON a.entity_id = b.entity_id and a.itemid = b.itemid WHERE a.fy = "+Year_1+" and a.entity_id = "+id+" and a.is_active = 1 order by e.statement asc , e.section asc , e.id asc") + .then(result => { + const arr = {"years" : years_data , "summary" : result } + res.send({'status':200,'message':"success",'data':{"years" : years_data ,"add_new_finyear_flag" : add_new_FY_flag, "summary" : result } }); + }).catch(err => { + res.status(500).send({'status':404, + message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" }); + }); + } + }) @@ -305,7 +310,7 @@ Pro42Data.forEach((Pro42Datavalue, key)=>{ { 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); - } + } console.log("------"+entity_id +"---"+ fy) //bulk financials data create Financials.bulkCreate(fin_data_array); //console.log(fin_data_array) @@ -329,13 +334,13 @@ Pro42Data.forEach((Pro42Datavalue, key)=>{ }); // 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 @@ -394,4 +399,38 @@ function testhree(req , res) { console.log( new Date().getFullYear()) console.log( req.losid) return {'status':200,'message':"success"}; -} \ No newline at end of file +} + + + + + + + + + +function inner_test(req , res) { + const losid = req.losid + new Promise((resolve, reject) => { + console.log("from-inner-fn="+losid) + resolve(losid); + + }).then(value => { console.log("from-then="+value); return (value ); }) + +//return {'status':200,'message':"success"}; +} + + + +// let promise = Promise.resolve(); +// const posts = [{}, {}, {}]; + +// posts.forEach(post => { +// promise = promise.then(() => { +// return db.insert(post); +// }); +// }); + +// promise.then(() => { +// // now all our docs have been saved +// }) \ No newline at end of file diff --git a/app/controllers/test.controller.js b/app/controllers/test.controller.js index 6a88f88..94ffd50 100644 --- a/app/controllers/test.controller.js +++ b/app/controllers/test.controller.js @@ -174,15 +174,18 @@ Pro42Data.forEach((Pro42Datavalue, key)=>{ exports.testwo = async (req, res) => { + console.log( "testtwo") req_obj ={"losid":"TEST123"} - const testhree_fn = testhree(req_obj) - console.log(testhree_fn) + testhree(req_obj); + }; + function testhree(req , res) { - console.log( new Date().getFullYear()) + console.log( "testthree") + console.log( req.losid) - return {'status':200,'message':"success"}; + res.send({'status':200,'message':"success"}); } diff --git a/app/routes/routes.js b/app/routes/routes.js index d2d7558..6698188 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -8,7 +8,7 @@ module.exports = app => { var router = require("express").Router(); - + /** * @swagger