Merge branch 'master' of https://bitbucket.org/venbainformationtechnology/smc_cet_financials_backend
This commit is contained in:
commit
9bde8a53ca
@ -317,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)
|
||||
} //console.log("------"+entity_id +"---"+ fy)
|
||||
//bulk financials data create
|
||||
Financials.bulkCreate(fin_data_array);
|
||||
//console.log(fin_data_array)
|
||||
@ -368,9 +368,12 @@ 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;
|
||||
const crnt_yr = new Date().getFullYear();
|
||||
if(req.body.fy != 0)
|
||||
{
|
||||
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
|
||||
let fin_data_array = [];
|
||||
for (let i = 1; i < 120; i++)
|
||||
@ -381,11 +384,17 @@ 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
|
||||
}
|
||||
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,
|
||||
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
|
||||
@ -401,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) {
|
||||
|
||||
@ -8,7 +8,27 @@ module.exports = app => {
|
||||
var router = require("express").Router();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/ConsolidatedSummary:
|
||||
* get:
|
||||
* summary: Consolidated Summary
|
||||
* description: Get consolidated Financials Summary data by sending losid
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: losid
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: LOSID
|
||||
* example: MW112233
|
||||
* responses:
|
||||
* 200:
|
||||
* description: success
|
||||
*/
|
||||
// get financials summary
|
||||
router.get("/ConsolidatedSummary", financials.ConsolidatedSummary);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@ -180,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
|
||||
|
||||
@ -9,11 +9,11 @@
|
||||
let add_new_FY_flag;
|
||||
if(Year_1 >= current_year && 3 < current_month)
|
||||
{
|
||||
add_new_FY_flag = {show_add_finyear_button:0};
|
||||
add_new_FY_flag = {show_add_finyear_button:0,FY:0};
|
||||
}
|
||||
else
|
||||
{
|
||||
add_new_FY_flag = {show_add_finyear_button:1,FY:current_year};
|
||||
add_new_FY_flag = {show_add_finyear_button:1,FY:Year_1 + 1};
|
||||
}
|
||||
return add_new_FY_flag;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user