fin_summary:GWM

This commit is contained in:
sriramv 2021-09-03 16:22:54 +05:30
parent 0042c574e0
commit fa17c6bf9b
4 changed files with 60 additions and 24 deletions

View File

@ -83,17 +83,15 @@ exports.MenuList = async (req, res) => {
exports.FinantialsSummary = async (req, res) => {
const id = req.query.entityid
Entityfinyears.findAll({where : { entityid : id } ,attributes: ['fy'], group: ['fy'] , order: [['fy', 'DESC']] })
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 JOIN (SELECT id,statement_name FROM statement_type) b ON a.Y1_st_type = b.id JOIN (SELECT id,statement_name FROM statement_type) c ON a.Y2_st_type = c.id JOIN (SELECT id,statement_name FROM statement_type) d ON a.Y3_st_type = d.id WHERE entityid ="+id)
.then(data => {
// console.log(data.length)
if(data.length >= 3)
{
const Year_1 = data[0].dataValues.fy
const Year_2 = data[1].dataValues.fy
const Year_3 = data[2].dataValues.fy
const years_data = {'Y1':Year_1 , 'Y2':Year_2 , 'Y3':Year_3}
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];
//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.fy as Y1,i.id as Y1_st_type_id,i.statement_name as Y1_st_type,a.id as Y1_id ,a.value as Y1_value ,b.fy as Y2,j.id as Y2_st_type_id,j.statement_name as Y2_st_type, b.id Y2_id ,b.value Y2_value ,c.fy as Y3,k.id as Y3_st_type_id,k.statement_name as Y3_st_type,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 LEFT JOIN ( SELECT id, statement_name FROM statement_type ) i ON a.st_type = i.id LEFT JOIN ( SELECT id, statement_name FROM statement_type ) j ON b.st_type = j.id LEFT JOIN ( SELECT id, statement_name FROM statement_type ) k ON c.st_type = k.id 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")
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 , "summary" : result } });
@ -101,7 +99,7 @@ exports.FinantialsSummary = async (req, res) => {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" });
});
} else { res.send({'status':404,'message':"failed",'data':"No data"}); }
})
.catch(err => {
@ -236,17 +234,24 @@ exports.updateFinancials = (req, res) => {
//testing
exports.test = (req, res) => {
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 JOIN (SELECT id,statement_name FROM statement_type) b ON a.Y1_st_type = b.id JOIN (SELECT id,statement_name FROM statement_type) c ON a.Y2_st_type = c.id JOIN (SELECT id,statement_name FROM statement_type) d ON a.Y3_st_type = d.id WHERE entityid = 6")
.then(result => {
console.log(result[0][0])
res.send({'status':200,'message':"success",'data':result });
}).catch(err => {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" });
});
// try
// {
// for (let i = 1; i < 121; i++) {
// Financials.create({ "entity_id":7,"st_type":2,"itemid":i,"fy":2020,"value": Math.floor(50000 + Math.random() * 150000),"is_active":1,"createdby":2 })
// }
// res.send({'status':200,'message':"success",'data':"No data"});
try
{
for (let i = 1; i < 121; i++) {
Financials.create({ "entity_id":7,"st_type":2,"itemid":i,"fy":2020,"value": Math.floor(50000 + Math.random() * 150000),"is_active":1,"createdby":2 })
}
res.send({'status':200,'message':"success",'data':"No data"});
}catch(err) {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
}); }
// }catch(err) {
// res.status(500).send({'status':404,
// message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
// }); }
};

View File

@ -9,8 +9,14 @@ module.exports = (sequelize, DataTypes) => {
{
losid: { type: DataTypes.STRING },
entityid: { type: DataTypes.INTEGER },
fy: { type: DataTypes.INTEGER },
st_type: { type: DataTypes.INTEGER },
Y1: { type: DataTypes.INTEGER },
Y2: { type: DataTypes.INTEGER },
Y3: { type: DataTypes.INTEGER },
Y4: { type: DataTypes.INTEGER },
Y1_st_type: { type: DataTypes.INTEGER },
Y2_st_type: { type: DataTypes.INTEGER },
Y3_st_type: { type: DataTypes.INTEGER },
Y4_st_type: { type: DataTypes.INTEGER },
createdby: { type: DataTypes.INTEGER },
updatedby: { type: DataTypes.INTEGER },

View File

@ -0,0 +1,25 @@
'use strict'
const { Model } = require('sequelize')
module.exports = (sequelize, DataTypes) => {
class Statementtype extends Model {
}
Statementtype.init(
{
statement_name: { type: DataTypes.STRING },
createdby: { type: DataTypes.INTEGER },
updatedby: { type: DataTypes.INTEGER },
},
{
sequelize,
tableName: 'statement_type',
modelName: 'Statementtype',
createdAt: 'createdon',
updatedAt: 'updatedon',
}
)
return Statementtype
}

View File

@ -155,7 +155,7 @@ module.exports = app => {
// update financials data
router.post("/updateFinancials", financials.updateFinancials);