diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index f0e8699..0109ec4 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) { @@ -71,9 +72,14 @@ exports.MenuList = (req, res) => { data.push(obj_data); }); // end of EntitiesData foreach + + // below code for overall sum object push process + sum_data = { ...{'losid':losid,'bizname':"Consolidated Financials Summary",'is_consolidated_api_call':1} , statementsmasterrData:MasterData }; + data.push(sum_data); + + // send respose to FE + res.send({'status':200,'message':"success",'data':data}); - 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 @@ -91,34 +97,40 @@ 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,a.additional_year_type 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 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 => { + const Year_4 = data[0][0].Y4; + //const years_data = data[0][0]; + add_new_FY_flag = financialControllerHelper.addNewFyFlag(Year_1); + if(Year_4 == null) + { + const three_years_data = {"losid": data[0][0].losid,"entityid": data[0][0].entityid,"Y1": data[0][0].Y1,"Y2": data[0][0].Y2,"Y3": data[0][0].Y3,"Y1_st_type_id":data[0][0].Y1_st_type_id,"Y1_st_type_name": data[0][0].Y1_st_type_name,"Y2_st_type_id":data[0][0].Y2_st_type_id,"Y2_st_type_name": data[0][0].Y2_st_type_name,"Y3_st_type_id": data[0][0].Y3_st_type_id,"Y3_st_type_name": data[0][0].Y3_st_type_name} + 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 => { + + res.send({'status':200,'message':"success",'data':{"years" : three_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 + { + const four_years_data = {"losid": data[0][0].losid,"entityid": data[0][0].entityid,"Y1": data[0][0].Y1,"Y2": data[0][0].Y2,"Y3": data[0][0].Y3,"Y4": data[0][0].Y4,"Y1_st_type_id":data[0][0].Y1_st_type_id,"Y1_st_type_name": data[0][0].Y1_st_type_name,"Y2_st_type_id":data[0][0].Y2_st_type_id,"Y2_st_type_name": data[0][0].Y2_st_type_name,"Y3_st_type_id": data[0][0].Y3_st_type_id,"Y3_st_type_name": data[0][0].Y3_st_type_name,"Y4_st_type_id":data[0][0].Y4_st_type_id,"Y4_st_type_name":data[0][0].Y4_st_type_name,"additional_year_type":data[0][0].additional_year_type} + 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 => { + + res.send({'status':200,'message':"success",'data':{"years" : four_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 +317,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,19 +341,20 @@ 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 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 @@ -354,7 +367,8 @@ exports.createFinancialYear = async (req, res) => { 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 }}) + const additional_year_type = req.body.additional_year_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,additional_year_type:additional_year_type },{ where: { id: id }}) .then(UpdatedEntityfinyearsdata => { // generate new financials data array for given FY with entity_id @@ -384,14 +398,97 @@ exports.createFinancialYear = async (req, res) => { -exports.testwo = async (req, res) => { - req_obj ={"losid":"TEST123"} - const testhree_fn = testhree(req_obj) - console.log(testhree_fn) - +exports.ConsolidatedSummary = async (req, res) => { + + const losid = req.query.losid; + const years_data = await sequelize.query("select distinct (Y4) as years from entity_fin_years where losid = '"+losid+"' union select distinct (Y3) from entity_fin_years where losid = '"+losid+"' union select distinct (Y2) from entity_fin_years where losid = '"+losid+"' union select distinct (Y1) from entity_fin_years where losid = '"+losid+"'"); + const years_count = years_data[0].length; + const Year_1 = years_data[0][years_count - 1].years; + const Year_2 = years_data[0][years_count - 2].years; + const Year_3 = years_data[0][years_count - 3].years; + //const Year_4 = years_data[0][years_count - 4].years; + + Entityfinyears.findAll({where : { losid } , attributes: ['entityid','Y1','Y2','Y3','Y4'] }) + .then(EntityfinyearsData =>{ + let data=[]; + EntityfinyearsData.forEach((value, key)=>{ + obj_data = value.dataValues.entityid; + data.push(obj_data); + }); // end of EntityfinyearsData foreach + const IN = data.join(); + sequelize.query("SELECT 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,a.fy as Y1,SUM(a.value) as Y1_value ,b.fy as Y2,SUM(b.value) as Y2_value,c.fy as Y3,SUM(c.value) as Y3_value FROM financials a 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 entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_3+"' and entity_id IN ("+IN+") and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) c ON a.entity_id = c.entity_id and a.itemid = c.itemid LEFT JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_2+"' and entity_id IN ("+IN+") and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) b ON a.entity_id = b.entity_id and a.itemid = b.itemid WHERE a.fy = '"+Year_1+"' and a.entity_id IN ("+IN+") and is_active = 1 GROUP BY a.itemid,a.fy,a.is_active,b.fy,c.fy,x.id,x.statement,y.id,y.section,e.subsection,z.subsection,z.itemtext,e.itemtext,e.statement,e.section,e.id order by e.statement asc , e.section asc , e.id asc") + //sequelize.query("SELECT 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,a.fy as Y1,SUM(a.value) as Y1_value ,b.fy as Y2,SUM(b.value) as Y2_value,c.fy as Y3,SUM(c.value) as Y3_value,d.fy as Y4,SUM(d.value) as Y4_value FROM financials a 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 entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_4+"' and entity_id IN ("+IN+") and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) d ON a.entity_id = d.entity_id and a.itemid = d.itemid LEFT JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_3+"' and entity_id IN ("+IN+") and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) c ON a.entity_id = c.entity_id and a.itemid = c.itemid LEFT JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_2+"' and entity_id IN ("+IN+") and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) b ON a.entity_id = b.entity_id and a.itemid = b.itemid WHERE a.fy = '"+Year_1+"' and a.entity_id IN ("+IN+") and is_active = 1 GROUP BY a.itemid,a.fy,a.is_active,b.fy,c.fy,x.id,x.statement,y.id,y.section,e.subsection,z.subsection,z.itemtext,e.itemtext,e.statement,e.section,e.id,d.fy order by e.statement asc , e.section asc , e.id asc") + .then(sum_data =>{ + res.send({'status':200,message: "success" ,'data': sum_data }); + }) + .catch(err => { + res.status(404).send({'status':404, + message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" }); + }); + + }) + .catch(err => { + res.status(404).send({'status':404, + message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" }); + }); + }; + +exports.testwo = async (req, res) => { +// 3 years sum +//sequelize.query("SELECT 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,a.fy as Y1,SUM(a.value) as Y1_value ,b.fy as Y2,SUM(b.value) as Y2_value,c.fy as Y3,SUM(c.value) as Y3_value FROM financials a 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 entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_3+"' and entity_id IN ("+IN+") and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) c ON a.entity_id = c.entity_id and a.itemid = c.itemid LEFT JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_2+"' and entity_id IN ("+IN+") and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) b ON a.entity_id = b.entity_id and a.itemid = b.itemid WHERE a.fy = '"+Year_1+"' and a.entity_id IN ("+IN+") and is_active = 1 GROUP BY a.itemid,a.fy,a.is_active,b.fy,c.fy,x.id,x.statement,y.id,y.section,e.subsection,z.subsection,z.itemtext,e.itemtext,e.statement,e.section,e.id order by e.statement asc , e.section asc , e.id asc") +// 4 year sum +//sequelize.query("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,a.fy as Y1,SUM(a.value) as Y1_value ,b.fy as Y2,SUM(b.value) as Y2_value,c.fy as Y3,SUM(c.value) as Y3_value,d.fy as Y4,SUM(d.value) as Y4_value FROM financials a 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 entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_4+"' and entity_id IN ("+IN+") and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) d ON a.entity_id = d.entity_id and a.itemid = d.itemid LEFT JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_3+"' and entity_id IN ("+IN+") and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) c ON a.entity_id = c.entity_id and a.itemid = c.itemid LEFT JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_2+"' and entity_id IN ("+IN+") and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) b ON a.entity_id = b.entity_id and a.itemid = b.itemid WHERE a.fy = '"+Year_1+"' and a.entity_id IN ("+IN+") and is_active = 1 GROUP BY a.itemid,a.fy,a.is_active,b.fy,c.fy,x.id,x.statement,y.id,y.section,e.subsection,z.subsection,z.itemtext,e.itemtext,e.statement,e.section,e.id,d.fy order by e.statement asc , e.section asc , e.id asc") + +}; + function testhree(req , res) { console.log( new Date().getFullYear()) console.log( req.losid) return {'status':200,'message':"success"}; -} \ No newline at end of file +} + + // const fin_summary = await Financials.findAll({ + // attributes: [['fy','Y1'] ,'itemid',[sequelize.fn('sum', sequelize.col('value')), 'Y1_value'],],group: ['fy','itemid'], + // where: { fy : 2019 , entity_id : [6,7] , is_active : 1 } + // }, + // ); + +// sequelize.query("SELECT 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,a.fy as Y1,SUM(a.value) as Y1_value ,b.fy as Y2,SUM(b.value) as Y2_value,c.fy as Y3,SUM(c.value) as Y3_value FROM financials a 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 entity_id,itemid,fy,value FROM financials WHERE fy = '2019' and entity_id IN (6,7) and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) c ON a.entity_id = c.entity_id and a.itemid = c.itemid LEFT JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '2020' and entity_id IN (6,7) and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) b ON a.entity_id = b.entity_id and a.itemid = b.itemid WHERE a.fy = '2021' and a.entity_id IN (6,7) and is_active = 1 GROUP BY a.itemid,a.fy,a.is_active,b.fy,c.fy,x.id,x.statement,y.id,y.section,e.subsection,z.subsection,z.itemtext,e.itemtext,e.statement,e.section,e.id order by e.statement asc , e.section asc , e.id asc") + // .then(data =>{ + // res.send({'status':200,message: "success" ,'data': data }); + // }) + // .catch(err => { + // res.status(404).send({'status':404, + // message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" }); + // }); + + + + + +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 ff10df3..57e17fa 100644 --- a/app/controllers/test.controller.js +++ b/app/controllers/test.controller.js @@ -169,6 +169,7 @@ Pro42Data.forEach((Pro42Datavalue, key)=>{ +<<<<<<< HEAD // exports.printAll = () => { // .then(() => { @@ -391,5 +392,21 @@ exports.test = (req, res) => { +======= +exports.testwo = async (req, res) => { + console.log( "testtwo") + req_obj ={"losid":"TEST123"} + testhree(req_obj); + + +}; + +function testhree(req , res) { + console.log( "testthree") + + console.log( req.losid) + res.send({'status':200,'message':"success"}); +} +>>>>>>> face92357d074e92248fc160a42396b716d3f7b5 diff --git a/app/models/Entityfinyears.js b/app/models/Entityfinyears.js index aaea47a..6e38fee 100644 --- a/app/models/Entityfinyears.js +++ b/app/models/Entityfinyears.js @@ -16,7 +16,8 @@ module.exports = (sequelize, DataTypes) => { Y1_st_type: { type: DataTypes.INTEGER }, Y2_st_type: { type: DataTypes.INTEGER }, Y3_st_type: { type: DataTypes.INTEGER }, - Y4_st_type: { type: DataTypes.INTEGER }, + Y4_st_type: { type: DataTypes.INTEGER }, + additional_year_type: { type: DataTypes.INTEGER }, createdby: { type: DataTypes.INTEGER }, updatedby: { type: DataTypes.INTEGER }, diff --git a/app/routes/routes.js b/app/routes/routes.js index 2cd233c..a8ababc 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -8,8 +8,8 @@ module.exports = app => { var router = require("express").Router(); - - + + router.get("/ConsolidatedSummary", financials.ConsolidatedSummary); /** * @swagger * /api/FinantialsSummary: @@ -180,6 +180,10 @@ module.exports = app => { * type: integer * description: statement type * example: 2 +* additional_year_type: +* type: integer +* description: additional year type(1=Quarterly , 2=Halfyearly , 3=Full) +* example: 3 */ /** * @swagger