From 1df1809fd6f8c53a637114c41007de4216d6e2b9 Mon Sep 17 00:00:00 2001 From: sriramv Date: Wed, 3 Nov 2021 11:54:19 +0530 Subject: [PATCH] GWM --- app/controllers/financial.controller.js | 59 ++++-- app/controllers/test.controller.js | 268 +++++++++++++----------- app/models/Entityfinyear.js | 29 +++ app/routes/routes.js | 4 +- 4 files changed, 223 insertions(+), 137 deletions(-) create mode 100644 app/models/Entityfinyear.js diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index ee33c54..7421365 100644 --- a/app/controllers/financial.controller.js +++ b/app/controllers/financial.controller.js @@ -1,4 +1,4 @@ -const { sequelize, Entities , Financials , Statementsmaster , Sectionsmaster , Subsectionsmaster , Brokenperiods , Entityfinyears } = require('../models') +const { sequelize, Entities , Financials , Statementsmaster , Sectionsmaster , Subsectionsmaster , Brokenperiods , Entityfinyears , Entityfinyear } = require('../models') const { logMsg } = require('../services/logger.js'); const financialControllerHelper = require('../services/financial.controller.helper.js'); const camundaHelper = require('../services/camunda.helper.js'); @@ -114,7 +114,7 @@ exports.FinantialsSummary = async (req, res) => { .then(EntitiesData => { const instancesid = EntitiesData.dataValues.process_instance_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 => { + .then(data => { const Year_1 = data[0][0].Y1; const Year_2 = data[0][0].Y2; @@ -830,22 +830,44 @@ promise.then(() => { -exports.camunda = async (req, res) => { +exports.demo = (req, res) => { const losid = "MW112233"; + const entityid = 7; try - { - const myPromise = new Promise((resolve, reject) => { - Entities.findAll({where : { losid } , attributes: [ 'id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' , 'process_instance_id' ] }) - .then(EntitiesData => { - console.log("Start"); - EntitiesData.forEach(value => { - console.log(value.dataValues.process_instance_id); - }); - }) - }); - - myPromise.then( console.log("End")) - + { + +Entityfinyear.findAll({where : { losid , entityid } , attributes: [ 'id', 'losid' , 'entityid' , 'FY' , 'st_type' , 'additional_year_type' ] , order: [['FY', 'DESC']] }) +.then(EntityfinyearData => { + const year_1 = EntityfinyearData[0].FY; + var select_items = ""; + var sub_query = ""; + EntityfinyearData.forEach((value, key)=>{ + const words = ['','one','two','three','four', 'five','six','seven','eight','nine','ten']; + if(key != 0) + { + console.log(key+"--"+value.FY); + key_addition = key + 1; + alisename = words[key_addition]; + select_items += ","+alisename+".st_type as Y"+key_addition+"_st_type,"+alisename+".fy as Y"+key_addition+","+alisename+".id Y"+key_addition+"_id ,"+alisename+".value Y"+key_addition+"_value"; + sub_query += "LEFT JOIN ( SELECT id,entity_id, itemid, value,fy,is_active,st_type FROM financials WHERE fy = '"+value.FY+"' and entity_id = "+entityid+" and is_active = 1) "+alisename+" ON a.entity_id = "+alisename+".entity_id and a.itemid = "+alisename+".itemid "; + } + }); // end of foreach + var query = "Select a.entity_id,x.id as statement_id,x.statement as statement,y.id as section_id,y.section as section,w.subsection as subsection_id,z.subsection as subsection , z.itemtext as subsection_itemtext ,a.itemid,w.itemtext as items,w.formula,w.is_calculated,w.is_summary,a.st_type as Y1_st_type,a.fy as Y1,a.id as Y1_id ,a.value as Y1_value "+ select_items +",v.remarks , v.id as remarks_id FROM financials a LEFT JOIN ( SELECT id,entity_id,itemid,remarks FROM fin_remarks WHERE is_active = 1) v ON a.entity_id = v.entity_id and a.itemid = v.itemid JOIN ( SELECT id,itemtext,statement,section,subsection,formula,is_calculated,is_summary FROM itemsmaster ) w ON a.itemid = w.id JOIN ( SELECT id, statement FROM statementsmaster ) x ON w.statement = x.id JOIN ( SELECT id, section FROM sectionsmaster ) y ON w.section = y.id LEFT JOIN ( SELECT id, subsection , itemtext FROM subsectionsmaster ) z ON w.subsection = z.id "+ sub_query +"WHERE a.fy = '"+year_1+"' and a.entity_id = "+entityid+" and a.is_active = 1 order by w.statement asc , w.section asc , w.subsection asc"; + setTimeout(function(){ + console.log(query); + sequelize.query(query) + .then(summary => { + + res.send({'status':200,'message':"success",'fin_summary' : summary } ); + }).catch(err => { + res.status(500).send({'status':404, + message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" }); + }); + + }, 1000);// end of set time out + + + }); } catch(err) { res.status(500).send({'status':404, message: err.message || "Some error occurred while inserting statements." ,'data': "No data" @@ -878,6 +900,7 @@ Entities.findAll({where : { losid } , attributes: [ 'id', 'losid' , 'pan' , 'cin .then(EntitiesData => { Sync(function(){ EntitiesData.forEach((value, key)=>{ + console.log(key); instancesid = value.dataValues.process_instance_id; taskid = camundaHelper.financialsListOfProcessInstances(instancesid); taskid.then(function(result){ @@ -887,8 +910,8 @@ Entities.findAll({where : { losid } , attributes: [ 'id', 'losid' , 'pan' , 'cin console.log(formVariableResult); }); }); - }); -}); // end of EntitiesData foreach + }); // end of EntitiesData foreach +}); // end of sync function console.log("end"); diff --git a/app/controllers/test.controller.js b/app/controllers/test.controller.js index fc0fea4..12a9941 100644 --- a/app/controllers/test.controller.js +++ b/app/controllers/test.controller.js @@ -34,54 +34,71 @@ function giveresponse(value) { // menu list api function MenuList (value,giveresponse) { - console.log(value) - console.log('3') - const losid = value.losid - try { - - if(value.status == 200) - { - Statementsmaster.findAll({ - where :{is_active : 1} , - attributes: ['id', 'statement', 'is_active'], - include :[{ - association: 'sectionsmasterData' , - where :{is_active : 1} , - attributes: ['id', 'section', 'is_active'], - include :[{ - association: 'subsectionsmasterData' , - where :{is_active : 1} , - attributes: ['id', 'subsection','itemtext', 'is_active'], - required :false - }], - required :false - }], - required :false - }) - .then(MasterData => { - Entities.findAll({where : { losid } , attributes: ['id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' ] }) - .then(EntitiesData => { - let data = []; - EntitiesData.forEach((value, key)=>{ - obj_data = { ...value.dataValues , statementsmasterrData:MasterData } - - data.push(obj_data); - }) // end of EntitiesData foreach - console.log(data) - console.log('4') - logMsg.info("MenuList api working"); - - giveresponse({'status':200,'message':"success",'data':data}); - }); // end of findall EntitiesData - }); // end of findall masters datas - } // end of starter function if condition - //return {'status':200,'message':"success",'data':data}; - } - - catch (err) { - console.log(err) - return res.status(500).json({'status':404,'message':"failed",'data':"No data"}) - } + try { + const losid = req.query.losid + // call starter function here + + req_obj ={"losid":losid} + + starter_response = starter(req_obj); + + setTimeout(()=>{ + if(starter_response.status == 200) + { + Statementsmaster.findAll({ + where :{is_active : 1} , + attributes: ['id', 'statement', 'is_active'], + include :[{ + association: 'sectionsmasterData' , + where :{is_active : 1} , + attributes: ['id', 'section', 'is_active'], + include :[{ + association: 'subsectionsmasterData' , + where :{is_active : 1} , + attributes: ['id', 'subsection','itemtext', 'is_active'], + required :false + }], + required :false + }], + required :false + }) + .then(MasterData => { + Entities.findAll({where : { losid } , attributes: [ 'id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' , 'process_instance_id' ] }) + .then(EntitiesData => { + let data = []; + EntitiesData.forEach((value, key)=>{ + + instancesid = value.dataValues.process_instance_id; + taskid = camundaHelper.financialsListOfProcessInstances(instancesid); + taskid.then(function(result){ + formVariable = camundaHelper.financialsFormVariables(result); + formVariable.then(function(form_result){ + formVariableResult = JSON.parse(form_result); + if(formVariableResult.type){ camunda_status = {"process_status":"NULL"}; } else { camunda_status =JSON.parse(form_result); } + obj_data = { ...value.dataValues ,status:camunda_status , statementsmasterrData:MasterData } + data.push(obj_data); + }); + }); + // obj_data = { ...value.dataValues , statementsmasterrData:MasterData } + // data.push(obj_data); + + }); // end of EntitiesData foreach + + setTimeout(()=>{ + // 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}); + },5000) + }); // end of findall EntitiesData + }); // end of findall masters datas + } // end of starter function if condition + },5000) + } catch (err) { + console.log(err) + return res.status(500).json({'status':404,'message':"failed",'data':"No data"}) + } }; @@ -89,79 +106,96 @@ function MenuList (value,giveresponse) { //testing function starter(value, MenuList) { -const losid = value -console.log(value) -console.log('2') - -//pro 42 api call using losid -const Pro42Data = [ - {"losid":losid,"pan":"AA1234AAAA","cin":"test1_cin","bizname":"test1_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4}, - {"losid":losid,"pan":"BB1234BBBB","cin":"test2_cin","bizname":"test2_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4} - ]; -// insert pro42data into entities table using using foreach -Pro42Data.forEach((Pro42Datavalue, key)=>{ - // check if the Pro42Data (entity) already inserted - Entities.findOne({ where: { losid : Pro42Datavalue.losid , pan : Pro42Datavalue.pan , cin : Pro42Datavalue.cin } }).then(Entity => { - if(Entity) + + const losid = req.losid; + try { - // skip inserting - } - else - { - Entities.create({ "losid":Pro42Datavalue.losid,"pan":Pro42Datavalue.pan,"cin":Pro42Datavalue.cin,"bizname":Pro42Datavalue.bizname,"entity_type":Pro42Datavalue.entity_type,"activity_group":Pro42Datavalue.activity_group,"biz_act_desc":Pro42Datavalue.biz_act_desc,"createdby":Pro42Datavalue.createdby}) - .then(Entitydata => { - - //create Entityfinyears data - const Y1 = new Date().getFullYear(); - const Y2 = Y1-1; - const Y3 = Y2-1; - Entityfinyears.create({ "losid":Entitydata.dataValues.losid,"entityid":Entitydata.dataValues.id,"Y1":Y1,"Y2":Y2,"Y3":Y3,"Y1_st_type":2,"Y2_st_type":2,"Y3_st_type":2}) - .then(Entityfinyearsdata => { - - //create financials data based on Entityfinyears - let fin_years_array = []; - fin_years_array = [ - {"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y1,"st_type":Entityfinyearsdata.dataValues.Y1_st_type}, - {"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y2,"st_type":Entityfinyearsdata.dataValues.Y2_st_type}, - {"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y3,"st_type":Entityfinyearsdata.dataValues.Y3_st_type} - ]; + + //pro 42 api call using losid + const Pro42Data = [ + {"losid":losid,"pan":"AA1234AAAA","cin":"test1_cin","bizname":"test1_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4}, + {"losid":losid,"pan":"BB1234BBBB","cin":"test2_cin","bizname":"test2_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4} + ]; + // insert pro42data into entities table using using foreach + Pro42Data.forEach((Pro42Datavalue, key)=>{ + // check if the Pro42Data (entity) already inserted + Entities.findOne({ where: { losid : Pro42Datavalue.losid , pan : Pro42Datavalue.pan , cin : Pro42Datavalue.cin } }).then(Entity => { + if(Entity) + { + // skip inserting + } + else + { + Entities.create({ "losid":Pro42Datavalue.losid,"pan":Pro42Datavalue.pan,"cin":Pro42Datavalue.cin,"bizname":Pro42Datavalue.bizname,"entity_type":Pro42Datavalue.entity_type,"activity_group":Pro42Datavalue.activity_group,"biz_act_desc":Pro42Datavalue.biz_act_desc,"createdby":Pro42Datavalue.createdby}) + .then(Entitydata => { + + //process instance Id update + const primeryId = Entitydata.dataValues.id; + const user = "SMC"; + processInstanceId = camundaHelper.startFinancialsProcessInstance(Entitydata.dataValues.losid,Entitydata.dataValues.pan,user); + processInstanceId.then(function(InstanceId){ + Entities.update({ "process_instance_id":InstanceId },{ where: { id: primeryId }}); + }); + + //create Entityfinyears data + const Y1 = new Date().getFullYear(); + const Y2 = Y1-1; + const Y3 = Y2-1; + Entityfinyears.create({ "losid":Entitydata.dataValues.losid,"entityid":Entitydata.dataValues.id,"Y1":Y1,"Y2":Y2,"Y3":Y3,"Y1_st_type":2,"Y2_st_type":2,"Y3_st_type":2}) + .then(Entityfinyearsdata => { + + //create financials data based on Entityfinyears + let fin_years_array = []; + fin_years_array = [ + {"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y1,"st_type":Entityfinyearsdata.dataValues.Y1_st_type}, + {"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y2,"st_type":Entityfinyearsdata.dataValues.Y2_st_type}, + {"entity_id":Entityfinyearsdata.dataValues.entityid,"fy":Entityfinyearsdata.dataValues.Y3,"st_type":Entityfinyearsdata.dataValues.Y3_st_type} + ]; + + // create skeletion + fin_years_array.forEach((value, key)=>{ + const entity_id = value.entity_id; + const fy = value.fy; + const st_type = value.st_type; + + // generate financials data array + let fin_data_array = []; + for (let i = 1; i < 120; i++) + { + 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) + }); + - // create skeletion - fin_years_array.forEach((value, key)=>{ - const entity_id = value.entity_id; - const fy = value.fy; - const st_type = value.st_type; - - // generate financials data array - let fin_data_array = []; - for (let i = 1; i < 120; i++) - { - 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); - } - //bulk financials data create - Financials.bulkCreate(fin_data_array); - //console.log(fin_data_array) - }); - - - }).catch(err => { - res.status(404).send({'status':404, - message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" }); - }); // end of entity fin year table data insert + }).catch(err => { + res.status(404).send({'status':404, + message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" }); + }); // end of entity fin year table data insert + + }).catch(err => { + res.status(404).send({'status':404, + message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" }); + }); // end of entity insert + + } //end of else condition + + }); // end of (losid,pan,cin) combination checking entity data exist or not + + }); // end of pro42 data foreach + + MenuList({'losid':losid,'status':200,'message':"success",'data':"No data"}); // success message - }).catch(err => { - res.status(404).send({'status':404, - message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" }); - }); // end of entity insert - - } //end of else condition - - }); // end of (losid,pan,cin) combination checking entity data exist or not + + } catch(err) { + res.status(500).send({'status':404, + message: err.message || "Some error occurred while inserting statements." ,'data': "No data" + }); } //end of try catch - }); // end of pro42 data foreach - - MenuList({'losid':losid,'status':200,'message':"success",'data':"No data"}); // success message + //end of try catch diff --git a/app/models/Entityfinyear.js b/app/models/Entityfinyear.js new file mode 100644 index 0000000..b5de92c --- /dev/null +++ b/app/models/Entityfinyear.js @@ -0,0 +1,29 @@ +'use strict' +const { Model } = require('sequelize') +module.exports = (sequelize, DataTypes) => { + class Entityfinyear extends Model { + + + } + Entityfinyear.init( + { + losid: { type: DataTypes.STRING }, + entityid: { type: DataTypes.INTEGER }, + FY: { type: DataTypes.INTEGER }, + st_type: { type: DataTypes.INTEGER }, + additional_year_type: { type: DataTypes.INTEGER }, + createdby: { type: DataTypes.INTEGER }, + updatedby: { type: DataTypes.INTEGER }, + + }, + { + sequelize, + tableName: 'entity_fin_year', + modelName: 'Entityfinyear', + createdAt: 'createdon', + updatedAt: 'updatedon', + + } + ) + return Entityfinyear +} diff --git a/app/routes/routes.js b/app/routes/routes.js index 85fee05..351c9f0 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("/camunda", financials.camunda); - // router.get("/test", financials.test); + router.get("/demo", financials.demo); + router.get("/testthree", financials.testthree); /** * @swagger