sum_api_changes:GWM
This commit is contained in:
parent
ed72838587
commit
d4f6c75ced
@ -368,12 +368,8 @@ exports.createFinancialYear = async (req, res) => {
|
|||||||
const Y3_st_type = Entityfinyearsdata.dataValues.Y2_st_type;
|
const Y3_st_type = Entityfinyearsdata.dataValues.Y2_st_type;
|
||||||
const Y4_st_type = Entityfinyearsdata.dataValues.Y3_st_type;
|
const Y4_st_type = Entityfinyearsdata.dataValues.Y3_st_type;
|
||||||
const additional_year_type = req.body.additional_year_type;
|
const additional_year_type = req.body.additional_year_type;
|
||||||
if(req.body.fy > new Date().getFullYear() && req.body.fy == Entityfinyearsdata.dataValues.Y1)
|
const crnt_yr = new Date().getFullYear();
|
||||||
{
|
if(req.body.fy <= crnt_yr && req.body.fy != Y2)
|
||||||
// not allowing any process
|
|
||||||
res.status(500).send({'status':500, 'message': "The year creation not allowed" ,'data': "No data" });
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
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 }})
|
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 => {
|
.then(UpdatedEntityfinyearsdata => {
|
||||||
@ -388,13 +384,16 @@ exports.createFinancialYear = async (req, res) => {
|
|||||||
//bulk financials data create
|
//bulk financials data create
|
||||||
Financials.bulkCreate(fin_data_array);
|
Financials.bulkCreate(fin_data_array);
|
||||||
//response
|
//response
|
||||||
res.send({'status':200,'message':"success",'data':"No data"});
|
res.status(200).send({'status':200,'message':"success",'data':"No data"});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
res.status(404).send({'status':404,
|
res.status(404).send({'status':404,
|
||||||
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
||||||
}); // end of update Entityfinyears
|
}); // 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 => {
|
}).catch(err => {
|
||||||
res.status(404).send({'status':404,
|
res.status(404).send({'status':404,
|
||||||
@ -411,45 +410,47 @@ exports.createFinancialYear = async (req, res) => {
|
|||||||
exports.ConsolidatedSummary = async (req, res) => {
|
exports.ConsolidatedSummary = async (req, res) => {
|
||||||
|
|
||||||
const losid = req.query.losid;
|
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+"'");
|
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;
|
.then(EntityfinyearsData =>{
|
||||||
const Year_1 = years_data[0][years_count - 1].years;
|
const years_count = EntityfinyearsData[0].length;
|
||||||
const Year_2 = years_data[0][years_count - 2].years;
|
const Year_1 = EntityfinyearsData[0][years_count - 1].years;
|
||||||
const Year_3 = years_data[0][years_count - 3].years;
|
const Year_2 = EntityfinyearsData[0][years_count - 2].years;
|
||||||
//const Year_4 = years_data[0][years_count - 4].years;
|
const Year_3 = EntityfinyearsData[0][years_count - 3].years;
|
||||||
|
const Year_4 = EntityfinyearsData[0][years_count - 4].years;
|
||||||
Entityfinyears.findAll({where : { losid } , attributes: ['entityid','Y1','Y2','Y3','Y4'] })
|
if(Year_4 == null)
|
||||||
.then(EntityfinyearsData =>{
|
{
|
||||||
let data=[];
|
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")
|
||||||
EntityfinyearsData.forEach((value, key)=>{
|
.then(sum_data =>{
|
||||||
obj_data = value.dataValues.entityid;
|
res.send({'status':200,message: "success" ,'data': sum_data });
|
||||||
data.push(obj_data);
|
})
|
||||||
}); // end of EntityfinyearsData foreach
|
.catch(err => {
|
||||||
const IN = data.join();
|
res.status(404).send({'status':404,
|
||||||
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")
|
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
||||||
//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 });
|
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 => {
|
.catch(err => {
|
||||||
res.status(404).send({'status':404,
|
res.status(404).send({'status':404,
|
||||||
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
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) => {
|
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")
|
||||||
//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")
|
||||||
// 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) {
|
function testhree(req , res) {
|
||||||
|
|||||||
@ -200,6 +200,10 @@ module.exports = app => {
|
|||||||
* type: integer
|
* type: integer
|
||||||
* description: statement type
|
* description: statement type
|
||||||
* example: 2
|
* example: 2
|
||||||
|
* additional_year_type:
|
||||||
|
* type: integer
|
||||||
|
* description: additional year type
|
||||||
|
* example: 2
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user