From 897e0d9b1b4af3c15a650c0468a4a3545aff8ddc Mon Sep 17 00:00:00 2001 From: sriramv Date: Thu, 19 May 2022 09:58:38 +0530 Subject: [PATCH] timeDelay:GWM --- app/controllers/financial.controller.js | 133 ++++++++++++++++++++---- app/routes/routes.js | 4 +- 2 files changed, 114 insertions(+), 23 deletions(-) diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index 1f3e64e..5d5bffc 100644 --- a/app/controllers/financial.controller.js +++ b/app/controllers/financial.controller.js @@ -63,6 +63,10 @@ exports.MenuList = async (req, res) => { const losid = req.query.losid; var EntityInsert = new Promise((resolve, reject) => { + if(req.query.redirection_api_call == 0) + { + resolve(); + } //Redirection api call with losid redirectionApi = ApiCallHelper.redirectionApiCall(losid); redirectionApi.then(function(redirectionApiData){ @@ -271,17 +275,109 @@ exports.MenuList = async (req, res) => { // FinantialsSummary +// exports.FinantialsSummary = async (req, res) => { +// try +// { +// const id = req.query.entityid +// Entities.findOne({where : { id } , attributes: [ 'id','losid','process_instance_id' , 'entity_type' , 'probe42_data_status' ] }) +// .then(EntitiesData => { +// const instancesid = EntitiesData.dataValues.process_instance_id; +// const probe42_data_status = EntitiesData.dataValues.probe42_data_status; +// if(probe42_data_status == 0){order_by_key = "pvtltd_itemorder"}else if(probe42_data_status == 2){order_by_key = "itemorder"}else{order_by_key = "NULL"} +// sequelize.query("select a.losid,a.entityid,a.FY,a.st_type as st_type_id, b.statement_name as st_type_name,a.additional_year_type, a.probe42_data_status FROM entity_fin_year a LEFT JOIN (SELECT id,statement_name FROM statement_type) b ON a.st_type = b.id WHERE entityid ="+id+" order by a.fy desc") +// .then(EntityfinyearData => { +// if(EntityfinyearData[0].length != 0) +// { +// const data = EntityfinyearData[0]; +// const year_1 = EntityfinyearData[0][0].FY; +// const additional_year_type = EntityfinyearData[0][0].additional_year_type; +// if(EntitiesData.dataValues.entity_type == "COMPANY"){entity_type_key = "pvtltd"} else if(EntitiesData.dataValues.entity_type == "INDIVIDUAL"){entity_type_key = "llp"} else {entity_type_key = "others"} +// const years = {losid:EntitiesData.dataValues.losid,entityid:EntitiesData.dataValues.id,order_by_key:order_by_key,probe42_data_status:probe42_data_status,additional_year_type:additional_year_type}; +// formula_obj = {}; +// // below function call is for calculation of additional new year flag generation +// add_new_FY_flag = financialControllerHelper.addNewFyFlag(year_1); +// // below code for constructing query for dynamic financial years +// var select_items = ""; +// var sub_query = ""; +// data.forEach((value, key)=>{ +// const words = ['','one','two','three','four', 'five','six','seven','eight','nine','ten']; +// // years object construction +// year_count = key + 1; +// years["Y"+year_count] = value.FY; +// years["Y"+year_count+"_st_type_id"] = value.st_type_id; +// years["Y"+year_count+"_st_type_name"] = value.st_type_name; +// years["Y"+year_count+"_probe42_data_fetched"] = value.probe42_data_status; +// // formula helper obj construct here for FE calculation +// formula_obj[value.FY] = {"value_key" : "Y"+year_count+"_value"}; +// // fin_query construction +// if(key != 0) +// { +// 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+".is_editable as Y"+key_addition+"_is_editable ,"+alisename+".value Y"+key_addition+"_value,"+alisename+".sub_value Y"+key_addition+"_sub_value"; +// sub_query += "LEFT JOIN ( SELECT id,entity_id, itemid, value,sub_value,fy,is_active,st_type,is_editable FROM financials WHERE fy = '"+value.FY+"' and entity_id = "+id+" 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,w.itemkey,w.itemorder,w.pvtltd_itemorder,z.subsection as subsection , z.itemtext as subsection_itemtext ,a.itemid,w.itemtext as items,w.formula,w.is_calculated,w.is_summary,w.pvtltd,w.llp,w.others,a.st_type as Y1_st_type,a.fy as Y1,a.id as Y1_id ,a.is_editable as Y1_is_editable,a.value as Y1_value,a.sub_value as Y1_sub_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,itemkey,itemorder,pvtltd_itemorder,formula,is_calculated,is_summary,pvtltd,llp,others 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 = "+id+" and a.is_active = 1 order by w.statement asc , w.section asc , w.subsection "; +// setTimeout(function(){ +// sequelize.query(query).then(summary => { console.log(query) +// // is_summary filter from fin_summary data +// let is_summary_item_array = []; +// const fin_summary = summary[0]; +// fin_summary.forEach((value, key)=>{ +// if(value.is_summary == 1) +// { +// obj_data = value; +// is_summary_item_array.push(obj_data); +// } +// }); +// // get camunda status +// 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); } +// setTimeout(function() +// { +// res.send({'status':200,'message':"success",'data':{"years" : years , formula_obj : formula_obj ,"add_new_finyear_flag" : add_new_FY_flag , status:camunda_status,"summary" : is_summary_item_array , "fin_summary" : summary } }); +// }, 3000); +// }); // enf of formVariable api call +// }); // enf of taskid api call + + +// }).catch(err => { +// res.status(500).send({'status':404, +// message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" }); +// }); + +// }, 2000);// end of set time out +// } else { res.status(404).send({'status':404,message: "Financials data not found." ,'data': "No data" });} + +// }) // end of EntityfinyearData query + +// }) // end of EntitiesData query +// } catch(err) { +// res.status(500).send({'status':404, +// message: err.message || "Some error occurred while inserting statements." ,'data': "No data" +// }); } +// }; + + + + exports.FinantialsSummary = async (req, res) => { try { const id = req.query.entityid Entities.findOne({where : { id } , attributes: [ 'id','losid','process_instance_id' , 'entity_type' , 'probe42_data_status' ] }) -.then(EntitiesData => { +.then(async(EntitiesData) => { const instancesid = EntitiesData.dataValues.process_instance_id; const probe42_data_status = EntitiesData.dataValues.probe42_data_status; if(probe42_data_status == 0){order_by_key = "pvtltd_itemorder"}else if(probe42_data_status == 2){order_by_key = "itemorder"}else{order_by_key = "NULL"} sequelize.query("select a.losid,a.entityid,a.FY,a.st_type as st_type_id, b.statement_name as st_type_name,a.additional_year_type, a.probe42_data_status FROM entity_fin_year a LEFT JOIN (SELECT id,statement_name FROM statement_type) b ON a.st_type = b.id WHERE entityid ="+id+" order by a.fy desc") -.then(EntityfinyearData => { +.then(async(EntityfinyearData) => { if(EntityfinyearData[0].length != 0) { const data = EntityfinyearData[0]; @@ -316,8 +412,14 @@ sequelize.query("select a.losid,a.entityid,a.FY,a.st_type as st_type_id, b.state }); // 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,w.itemkey,w.itemorder,w.pvtltd_itemorder,z.subsection as subsection , z.itemtext as subsection_itemtext ,a.itemid,w.itemtext as items,w.formula,w.is_calculated,w.is_summary,w.pvtltd,w.llp,w.others,a.st_type as Y1_st_type,a.fy as Y1,a.id as Y1_id ,a.is_editable as Y1_is_editable,a.value as Y1_value,a.sub_value as Y1_sub_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,itemkey,itemorder,pvtltd_itemorder,formula,is_calculated,is_summary,pvtltd,llp,others 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 = "+id+" and a.is_active = 1 order by w.statement asc , w.section asc , w.subsection "; - setTimeout(function(){ - sequelize.query(query).then(summary => { console.log(query) + // get camunda status + taskid = await camundaHelper.financialsListOfProcessInstances(instancesid); + formVariable = await camundaHelper.financialsFormVariables(taskid); + formVariableResult = JSON.parse(formVariable); + if(formVariableResult.type){ camunda_status = {"process_status":"NULL"}; } else { camunda_status =JSON.parse(formVariable); } + + // execute constructed financial summary query + sequelize.query(query).then(async(summary) => { // is_summary filter from fin_summary data let is_summary_item_array = []; const fin_summary = summary[0]; @@ -328,27 +430,16 @@ sequelize.query("select a.losid,a.entityid,a.FY,a.st_type as st_type_id, b.state is_summary_item_array.push(obj_data); } }); - // get camunda status - 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); } - setTimeout(function() - { - res.send({'status':200,'message':"success",'data':{"years" : years , formula_obj : formula_obj ,"add_new_finyear_flag" : add_new_FY_flag , status:camunda_status,"summary" : is_summary_item_array , "fin_summary" : summary } }); - }, 3000); - }); // enf of formVariable api call - }); // enf of taskid api call - + + res.send({'status':200,'message':"success",'data':{"years" : years , formula_obj : formula_obj ,"add_new_finyear_flag" : add_new_FY_flag , status:camunda_status,"summary" : is_summary_item_array , "fin_summary" : summary } }); + }).catch(err => { res.status(500).send({'status':404, message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" }); }); - }, 2000);// end of set time out + } else { res.status(404).send({'status':404,message: "Financials data not found." ,'data': "No data" });} }) // end of EntityfinyearData query @@ -844,8 +935,8 @@ exports.test = async (req, res) => { { key = "manual"; - Itemsmaster.findAll({ where :{ key : 1,is_active : 1},attributes: ['id'] , order: [['statement', 'ASC'],['section', 'ASC']] }) - .then(ItemsmasterData => { + Itemsmaster.findAll({ where :{manual:1,is_active : 1},attributes: ['id'] , order: [['statement', 'ASC'],['section', 'ASC'],['itemorder', 'ASC']] }) + .then(ItemsmasterData => { res.send(ItemsmasterData); }); diff --git a/app/routes/routes.js b/app/routes/routes.js index 50c9dd7..60474d4 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -7,7 +7,7 @@ module.exports = app => { const { logMsg } = require('../services/logger.js'); var router = require("express").Router(); - router.get("/test", financials.test); + router.get("/demo", financials.demo); /** * @swagger * /api/checkProbeStatus: @@ -35,7 +35,7 @@ module.exports = app => { */ // get financials summary router.get("/checkProbeStatus", financials.checkProbeStatus); - /** + /** * @swagger * definitions: * RefreshApiCall: