From d4f6c75cedbf06678b9441d6f4a74df773418470 Mon Sep 17 00:00:00 2001 From: sriramv Date: Fri, 24 Sep 2021 15:51:29 +0530 Subject: [PATCH] sum_api_changes:GWM --- app/controllers/financial.controller.js | 85 +++++++++++++------------ app/routes/routes.js | 4 ++ 2 files changed, 47 insertions(+), 42 deletions(-) diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index ddfb5b6..fe6cbf0 100644 --- a/app/controllers/financial.controller.js +++ b/app/controllers/financial.controller.js @@ -368,12 +368,8 @@ exports.createFinancialYear = async (req, res) => { const Y3_st_type = Entityfinyearsdata.dataValues.Y2_st_type; const Y4_st_type = Entityfinyearsdata.dataValues.Y3_st_type; const additional_year_type = req.body.additional_year_type; - if(req.body.fy > new Date().getFullYear() && req.body.fy == Entityfinyearsdata.dataValues.Y1) - { - // not allowing any process - res.status(500).send({'status':500, 'message': "The year creation not allowed" ,'data': "No data" }); - } - else + const crnt_yr = new Date().getFullYear(); + if(req.body.fy <= crnt_yr && req.body.fy != Y2) { 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 => { @@ -388,13 +384,16 @@ exports.createFinancialYear = async (req, res) => { //bulk financials data create Financials.bulkCreate(fin_data_array); //response - res.send({'status':200,'message':"success",'data':"No data"}); + res.status(200).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 - - } // end of else part + } + else + { + res.status(405).send({'status':405, 'message': "The year creation not allowed" ,'data': "No data" }); + } // end of else part }).catch(err => { res.status(404).send({'status':404, @@ -411,45 +410,47 @@ exports.createFinancialYear = async (req, res) => { 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 }); + 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+"'") + .then(EntityfinyearsData =>{ + const years_count = EntityfinyearsData[0].length; + const Year_1 = EntityfinyearsData[0][years_count - 1].years; + const Year_2 = EntityfinyearsData[0][years_count - 2].years; + const Year_3 = EntityfinyearsData[0][years_count - 3].years; + const Year_4 = EntityfinyearsData[0][years_count - 4].years; + if(Year_4 == null) + { + 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,g.subsection as subsection , g.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 entities z JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_1+"' and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) a ON z.id = a.entity_id JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_2+"' and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) b ON z.id = b.entity_id and a.itemid = b.itemid JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_3+"' and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) c ON z.id = c.entity_id and a.itemid = c.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 ) g ON e.subsection = g.id where losid = '"+losid+"' GROUP BY a.itemid,x.id,x.statement,y.id,y.section,e.subsection,g.subsection,g.itemtext,e.itemtext,e.statement,e.section,e.id,a.fy,b.fy,c.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" }); + }); + } + else + { + 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,g.subsection as subsection , g.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 entities z JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_1+"' and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) a ON z.id = a.entity_id JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_2+"' and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) b ON z.id = b.entity_id and a.itemid = b.itemid JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_3+"' and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) c ON z.id = c.entity_id and a.itemid = c.itemid JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+Year_4+"' and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) d ON z.id = d.entity_id and a.itemid = d.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 ) g ON e.subsection = g.id where losid = '"+losid+"' GROUP BY a.itemid,x.id,x.statement,y.id,y.section,e.subsection,g.subsection,g.itemtext,e.itemtext,e.statement,e.section,e.id,a.fy,b.fy,c.fy,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" }); + }); + }//end of else part }) .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" }); - }); + 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") - + //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") + }; function testhree(req , res) { diff --git a/app/routes/routes.js b/app/routes/routes.js index ef48032..b514227 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -200,6 +200,10 @@ module.exports = app => { * type: integer * description: statement type * example: 2 +* additional_year_type: +* type: integer +* description: additional year type +* example: 2 */ /** * @swagger