From 951a125ce7d87b47e15459828107e060d198ecbd Mon Sep 17 00:00:00 2001 From: sriramv Date: Tue, 28 Dec 2021 11:57:49 +0530 Subject: [PATCH] probe42dataupdate:GWM --- .gitignore | 5 - app/controllers/financial.controller.js | 1314 +++++++++-------- app/models/Entityfinyear.js | 29 + app/models/Entityfinyears.js | 35 - app/models/Financials.js | 1 + app/models/Itemsmaster.js | 1 + app/routes/routes.js | 4 +- app/services/financials.apicall.helper.js | 42 + .../probe42lineitem.mapping.helper.js | 107 ++ 9 files changed, 843 insertions(+), 695 deletions(-) create mode 100644 app/models/Entityfinyear.js delete mode 100644 app/models/Entityfinyears.js create mode 100644 app/services/financials.apicall.helper.js create mode 100644 app/services/probe42lineitem.mapping.helper.js diff --git a/.gitignore b/.gitignore index 19f0ba2..37051fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,3 @@ /node_modules /storage .env - - - - - diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index ee33c54..ff8519a 100644 --- a/app/controllers/financial.controller.js +++ b/app/controllers/financial.controller.js @@ -1,8 +1,15 @@ -const { sequelize, Entities , Financials , Statementsmaster , Sectionsmaster , Subsectionsmaster , Brokenperiods , Entityfinyears } = require('../models') +const { sequelize, Entities , Financials , Statementsmaster , Sectionsmaster , Subsectionsmaster , Itemsmaster , Brokenperiods , Entityfinyear} = require('../models') const { logMsg } = require('../services/logger.js'); const financialControllerHelper = require('../services/financial.controller.helper.js'); const camundaHelper = require('../services/camunda.helper.js'); +const ApiCallHelper = require('../services/financials.apicall.helper.js'); +const Probe42DataMappingHelper = require('../services/probe42lineitem.mapping.helper.js'); const Sync = require('sync'); +const { Op } = require("sequelize"); + + + + // all master data list for dropdown exports.MasterDatas = async (req, res) => { await Statementsmaster.findAll({ @@ -33,179 +40,484 @@ exports.MasterDatas = async (req, res) => { }); }; -// menu list api -exports.MenuList = (req, res) => { - //Statementsmaster.findAll({ where :{is_active : 1} , include: { all: true, nested: true , where :{is_active : 1} , required:false}}) - 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) + +exports.MenuList = (req, res) => { + Sync(function() + { + try { - 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)=>{ + const losid = req.query.losid; + //pro 42 api call using losid + const Pro42Data = [ + {"losid":losid,"pan":"AA1234AAAA","cin":"L74120MH1985PLC035308","bizname":"test1_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4}, + {"losid":losid,"pan":"BB1234BBBB","cin":"L74120MH1985PLC035308","bizname":"test2_bizname","entity_type":"type","activity_group":"grp","biz_act_desc":"des","createdby":4} + ]; - 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); +var EntityInsert = new Promise((resolve, reject) => { + // insert pro42data into entities table using using foreach + Pro42Data.forEach((Pro42Datavalue, key,array)=>{ + // 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 + if (key === array.length -1) {resolve();} + } + 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 cin = Entitydata.dataValues.cin; + const entityid = 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: entityid }}); + }); + + // call and get financial year wise data for entity (probe42 api call) + financials_data_api_response = ApiCallHelper.probe42ApiCall(cin); + financials_data_api_response.then(function(result){ + //filter lineitems from api responce and construct to needed format + lineItem_data = Probe42DataMappingHelper.lineItemFetching(result); + lineItem_data.then(function(lineItem_result){ + + //create financial table and entityfinyear table record here + lineItem_result.forEach((value, key)=>{ + + Entityfinyear.create({ "losid":Entitydata.dataValues.losid,"entityid":Entitydata.dataValues.id,"FY":value.year,"st_type": 1 }) + .then(Entityfinyearsdata => { + + // create skeletion + // generate financials data array + let fin_data_array = []; + for (let i = 1; i < 141; i++) + { + if(i != 124 && i != 125 && i != 130) + { + fin_data_obj = { "entity_id":Entityfinyearsdata.dataValues.entityid,"st_type":Entityfinyearsdata.dataValues.st_type,"itemid":i,"fy":Entityfinyearsdata.dataValues.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).then(data=>{}).catch(err=>(console.log(err))); + + console.log("working") + setTimeout(() => { + lineItem_result.forEach((value,index,array) => { + // mapping of probe42 api lineItem with itemMaster primary key + final_array = Probe42DataMappingHelper.lineItemMapping(value,entityid); + final_array.then(function(update_array_data){ + // update mapped lineitem value here + Probe42DataMappingHelper.lineItemUpdate(update_array_data); + });//end of lineItemUpdate helper call + });//end of lineItem mapping with itemMaster primary key helper call + }, 500); + + + + + }).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 + + });//end of foreach + + + + });//end of lineItem filter from api response helper call + });//end of probe42 api call + + + + + if (key === array.length -1) {resolve();} + + }).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 + + }); // end of promise + + + + + EntityInsert.then(() => { + setTimeout(()=>{ + Statementsmaster.findAll({ where :{is_active : 1} , include: { all: true, nested: true , where :{is_active : 1} , 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 Time = 2000; + let data = []; + EntitiesData.forEach((value, key)=>{ + Time = Time + 500; + instancesid = value.dataValues.process_instance_id; + taskid = camundaHelper.financialsListOfProcessInstances(instancesid); + taskid.then(function(result){ + Time = Time + 500; + 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}); + },Time) + }); // end of findall EntitiesData + }); // end of findall masters datas + },2000) + }); + + } 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 sync function + + }; + + + + + +// menu list api +// exports.MenuList = (req, res) => { + +// //Statementsmaster.findAll({ where :{is_active : 1} , include: { all: true, nested: true , where :{is_active : 1} , required:false}}) +// 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} , include: { all: true, nested: true , where :{is_active : 1} , 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)=>{ - }); // end of EntitiesData foreach +// 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"}) +// } + +// }; + + + +// //starter function +// function starter(req, res) +// { + +// const losid = req.losid; +// try +// { + +// //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 entityid = 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: entityid }}); +// }); + +// // call and get financial year wise data for entity +// const crnt_year = new Date().getFullYear(); +// const Y1 = crnt_year - 1; +// const Y2 = Y1-1; +// const Y3 = Y2-1; +// const financial_years_api_reaponce_data =[{'fy':Y1,'st_type':2},{'fy':Y2,'st_type':2},{'fy':Y3,'st_type':2}]; + +// //create financial table and entityfinyear table record here +// financial_years_api_reaponce_data.forEach((value, key)=>{ + +// //create Entityfinyears data +// Entityfinyear.create({ "losid":Entitydata.dataValues.losid,"entityid":Entitydata.dataValues.id,"FY":value.fy,"st_type":value.st_type}) +// .then(Entityfinyearsdata => { + +// // create skeletion +// // generate financials data array +// let fin_data_array = []; +// for (let i = 1; i < 120; i++) +// { +// fin_data_obj = { "entity_id":Entityfinyearsdata.dataValues.entityid,"st_type":Entityfinyearsdata.dataValues.st_type,"itemid":i,"fy":Entityfinyearsdata.dataValues.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); + +// }).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 + +// });//end of foreach + +// }).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 + +// return {'status':200,'message':"success",'data':"No data"}; // success message + + +// } catch(err) { +// res.status(500).send({'status':404, +// message: err.message || "Some error occurred while inserting statements." ,'data': "No data" +// }); } //end of try catch + +// }; + + + + - 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"}) - } -}; // FinantialsSummary exports.FinantialsSummary = async (req, res) => { - const id = req.query.entityid - Entities.findOne({where : { id } , attributes: [ 'process_instance_id' ] }) - .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 => { - - const Year_1 = data[0][0].Y1; - const Year_2 = data[0][0].Y2; - const Year_3 = data[0][0].Y3; - const Year_4 = data[0][0].Y4; - //const years_data = data[0][0]; - add_new_FY_flag = financialControllerHelper.addNewFyFlag(Year_1); - if(Year_4 == null) + try + { +const id = req.query.entityid +Entities.findOne({where : { id } , attributes: [ 'id','losid','process_instance_id' ] }) +.then(EntitiesData => { + const instancesid = EntitiesData.dataValues.process_instance_id; +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 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 => { + const data = EntityfinyearData[0]; + const year_1 = EntityfinyearData[0][0].FY; + const additional_year_type = EntityfinyearData[0][0].additional_year_type; + const years = {losid:EntitiesData.dataValues.losid,entityid:EntitiesData.dataValues.id,additional_year_type:additional_year_type}; + // 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; + // fin_query construction + if(key != 0) { - const three_years_data = {"losid": data[0][0].losid,"entityid": data[0][0].entityid,"Y1": data[0][0].Y1,"Y2": data[0][0].Y2,"Y3": data[0][0].Y3,"Y1_st_type_id":data[0][0].Y1_st_type_id,"Y1_st_type_name": data[0][0].Y1_st_type_name,"Y2_st_type_id":data[0][0].Y2_st_type_id,"Y2_st_type_name": data[0][0].Y2_st_type_name,"Y3_st_type_id": data[0][0].Y3_st_type_id,"Y3_st_type_name": data[0][0].Y3_st_type_name} - 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,e.is_summary,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,is_summary 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(summary => { - // 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" : three_years_data ,"add_new_finyear_flag" : add_new_FY_flag , status:camunda_status,"summary" : is_summary_item_array, "fin_summary" : summary } }); - }, 3000); - - }); - }); - //res.send({'status':200,'message':"success",'data':{"years" : three_years_data ,"add_new_finyear_flag" : add_new_FY_flag, "summary" : result } }); - }).catch(err => { - res.status(500).send({'status':404, - message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" }); - }); + 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 = "+id+" and is_active = 1) "+alisename+" ON a.entity_id = "+alisename+".entity_id and a.itemid = "+alisename+".itemid "; } - else - { - const four_years_data = {"losid": data[0][0].losid,"entityid": data[0][0].entityid,"Y1": data[0][0].Y1,"Y2": data[0][0].Y2,"Y3": data[0][0].Y3,"Y4": data[0][0].Y4,"Y1_st_type_id":data[0][0].Y1_st_type_id,"Y1_st_type_name": data[0][0].Y1_st_type_name,"Y2_st_type_id":data[0][0].Y2_st_type_id,"Y2_st_type_name": data[0][0].Y2_st_type_name,"Y3_st_type_id": data[0][0].Y3_st_type_id,"Y3_st_type_name": data[0][0].Y3_st_type_name,"Y4_st_type_id":data[0][0].Y4_st_type_id,"Y4_st_type_name":data[0][0].Y4_st_type_name,"additional_year_type":data[0][0].additional_year_type} - 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,e.is_summary,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 ,d.st_type as Y4_st_type,d.fy as Y4,d.id as Y4_id ,d.value Y4_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,is_summary 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_4+" and entity_id ="+id+" and is_active = 1) d ON a.entity_id = d.entity_id and a.itemid = d.itemid 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(summary => { - // 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" : four_years_data ,"add_new_finyear_flag" : add_new_FY_flag , status:camunda_status,"summary" : is_summary_item_array , "fin_summary" : summary } }); - }, 3000); - - }); - }); - //res.send({'status':200,'message':"success",'data':{"years" : four_years_data ,"add_new_finyear_flag" : add_new_FY_flag, "summary" : result } }); - }).catch(err => { - res.status(500).send({'status':404, - message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" }); + }); // 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,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,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,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 asc"; + setTimeout(function(){ + sequelize.query(query) + .then(summary => { + // 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); + } }); - } - }) - .catch(err => { + // 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 ,"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" }); - }); - - - }) - .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 + + + }) // 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" + }); } }; + + + + + + +//ConsolidatedSummary +exports.ConsolidatedSummary = async (req, res) => { + + try + { + const losid = req.query.losid + Entityfinyear.findAll({where : { losid } , attributes: [ [sequelize.fn('DISTINCT', sequelize.col('FY')), 'FY'] ] , order: [['FY', 'DESC']] }) + .then(EntityfinyearData => { + const year_1 = EntityfinyearData[0].FY; + var select_items = ""; + var sub_query = ""; + var group = ""; + EntityfinyearData.forEach((value,key)=>{ + const words = ['','one','two','three','four', 'five','six','seven','eight','nine','ten']; + if(key != 0) + { + key_addition = key + 1; + alisename = words[key_addition]; + select_items += ","+alisename+".fy as Y"+key_addition+" ,SUM("+alisename+".value) as Y"+key_addition+"_value", + sub_query += " JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+value.FY+"' and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) "+alisename+ " ON z.id = " + alisename + ".entity_id and a.itemid = "+ alisename +".itemid " + group += ","+alisename+".fy"; + } + }); // end of foreach + + var 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,e.is_summary,a.fy as Y1 , SUM(a.value) as Y1_value"+ select_items +" 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" + sub_query + " JOIN ( SELECT id,itemtext,statement,section,subsection,formula,is_calculated,is_summary 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,e.is_summary " + group + " ORDER BY e.statement asc , e.section asc , e.id asc" + + setTimeout(function(){ + sequelize.query(query) + .then(summary => { + let is_summary_item_array = []; + const summary_data = summary[0]; + summary_data.forEach((value, key)=>{ + if(value.is_summary == 1) + { + obj_data = value; + is_summary_item_array.push(obj_data); + } + }); + setTimeout(function(){ + res.send({'status':200,'message':"success","data":{"summary": is_summary_item_array,'consolidated_summary' : summary }} ); + }, 2000);// end of set time out + }).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 + + //}); + + }); +} catch(err) { + res.status(500).send({'status':404, + message: err.message || "Some error occurred while inserting statements." ,'data': "No data" + }); } + +}; + + + + + + + + // Broken period list api exports.BrokenPeriodsList = (req, res) => { const entityid = req.query.entityid @@ -223,6 +535,13 @@ exports.BrokenPeriodsList = (req, res) => { }); } }; + + + + + + + // Broken period Insert OR Update exports.BrokenPeriods = (req, res) => { const obj = req.body @@ -277,6 +596,12 @@ exports.BrokenPeriods = (req, res) => { + + + + + + exports.createFinancials = (req, res) => { const req_array_data = req.body; @@ -308,6 +633,10 @@ exports.createFinancials = (req, res) => { }; + + + + exports.updateFinancials = (req, res) => { const req_array_data = req.body; try @@ -330,127 +659,28 @@ exports.updateFinancials = (req, res) => { -//testing - function starter(req, res) - { -const losid = req.losid; - try - { - -//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) - }); - - - }).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 - - return {'status':200,'message':"success",'data':"No data"}; // success message - - - } catch(err) { - res.status(500).send({'status':404, - message: err.message || "Some error occurred while inserting statements." ,'data': "No data" - }); } //end of try catch - -}; // create financial skeletion for given year exports.createFinancialYear = async (req, res) => { losid = req.body.losid; entityid = req.body.entityid; - Entityfinyears.findOne({ where: { losid : losid , entityid : entityid } }) + Entityfinyear.findOne({ where: { losid : losid , entityid : entityid } }) .then(Entityfinyearsdata => { - // rearrange entity_fin_years and update data - const id = Entityfinyearsdata.dataValues.id; - const Y1 = req.body.fy; - const Y2 = Entityfinyearsdata.dataValues.Y1; - const Y3 = Entityfinyearsdata.dataValues.Y2; - const Y4 = Entityfinyearsdata.dataValues.Y3; - const Y1_st_type = req.body.st_type; - const Y2_st_type = Entityfinyearsdata.dataValues.Y1_st_type; - const Y3_st_type = Entityfinyearsdata.dataValues.Y2_st_type; - const Y4_st_type = Entityfinyearsdata.dataValues.Y3_st_type; + + const fy = req.body.fy; + const st_type = req.body.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 => { - + Entityfinyear.create({ losid:Entityfinyearsdata.dataValues.losid,entityid:Entityfinyearsdata.dataValues.entityid,FY:fy,st_type:st_type,additional_year_type:additional_year_type }) + .then(Entityfinyearsdata => { + // generate new financials data array for given FY with entity_id let fin_data_array = []; - for (let i = 1; i < 120; i++) + for (let i = 1; i <= 120; i++) { fin_data_obj = { "entity_id":req.body.entityid,"st_type":req.body.st_type,"itemid":i,"fy":req.body.fy,"value":0,"is_active":1,"createdby":4} fin_data_array.push(fin_data_obj); @@ -473,79 +703,7 @@ exports.createFinancialYear = async (req, res) => { res.status(404).send({'status':404, message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" }); }); // end of findOne Entityfinyears - - -}; - - - - -exports.ConsolidatedSummary = async (req, res) => { - - const losid = req.query.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+"'") - .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,e.is_summary,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,is_summary 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,e.is_summary ORDER BY e.statement asc , e.section asc , e.id asc") - .then(sum_data =>{ - // is_summary filter from fin_summary data - let is_summary_item_array = []; - const summary_data = sum_data[0]; - summary_data.forEach((value, key)=>{ - if(value.is_summary == 1) - { - obj_data = value; - is_summary_item_array.push(obj_data); - } - }); - setTimeout(function() - { - res.send({'status':200,message: "success" ,"summary": is_summary_item_array ,'data': sum_data }); - }, 3000); - // 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,e.is_summary,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,is_summary 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,e.is_summary ORDER BY e.statement asc , e.section asc , e.id asc") - .then(sum_data =>{ - // is_summary filter from fin_summary data - let is_summary_item_array = []; - const summary_data = sum_data[0]; - summary_data.forEach((value, key)=>{ - if(value.is_summary == 1) - { - obj_data = value; - is_summary_item_array.push(obj_data); - } - }); - setTimeout(function() - { - res.send({'status':200,message: "success" ,"summary": is_summary_item_array ,'data': sum_data }); - }, 3000); - //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" }); - }); }; @@ -578,330 +736,182 @@ exports.ConsolidatedSummary = async (req, res) => { -// testing api's -exports.test = async (req, res) => { - const losid = req.query.losid; - try - { - - new Promise((resolve,reject) =>{ - - //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 => { - - //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) - }); - - - }).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 - - //return {'status':200,'message':"success",'data':"No data"}; // success message - resolve(losid); - - }) - .then(function(value){ - - Statementsmaster.findAll({ where :{is_active : 1} , include: { all: true, nested: true , where :{is_active : 1} , 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 - - // 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 - Promise.resolve(res.send({'status':200,'message':"success",'data':data})) - - }); // end of findall EntitiesData - }); // end of findall masters datas - - }) -} catch(err) { - res.status(500).send({'status':404, - message: err.message || "Some error occurred while inserting statements." ,'data': "No data" - }); } - -}; - -exports.testwo = async (req, res) => { - const losid = req.query.losid; - const api_call = 0; - var promise = (losid) => new Promise((resolve,reject) =>{ - if(api_call == 1) - { - console.log(1); - console.log(losid); - } - resolve(losid) - }) - promise(losid).then((losid) => { - console.log(2); - console.log(losid); - return ({'losid':losid,'status':200,'message':"success",'data':"No data"}); // success message - - }) - .then(function(value){ - console.log(3); - console.log(losid); - //setTimeout(function(){ - console.log(4); - console.log(losid); - data = "output"; - Promise.resolve(res.send({'status':200,'message':"success",'data':data})) - //},1000); - }) - -}; - -exports.menu = async (req, res) => { - const losid = req.query.losid; - try - { -let promise = Promise.resolve(); -//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} - ]; - - Pro42Data.forEach((Pro42Datavalue, key) => { - promise = promise.then(() => { - // 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 => { - - //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) - }); - - - }).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 - }); -}); - -promise.then(() => { - setTimeout(function(){ - Statementsmaster.findAll({ where :{is_active : 1} , include: { all: true, nested: true , where :{is_active : 1} , 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 - if(EntitiesData.length > 1) - { - // 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 - Promise.resolve(res.send({'status':200,'message':"success",'data':data})) - - }); // end of findall EntitiesData - }); // end of findall masters datas - },1000); -}) -} catch(err) { - res.status(500).send({'status':404, - message: err.message || "Some error occurred while inserting statements." ,'data': "No data" - }); } -}; - - - - -exports.camunda = async (req, res) => { - const losid = "MW112233"; - 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")) - - } catch(err) { - res.status(500).send({'status':404, - message: err.message || "Some error occurred while inserting statements." ,'data': "No data" - }); } -}; -exports.syncTest = async (req, res) => { - const losid = req.query.losid; - try - { - - - } catch(err) { - res.status(500).send({'status':404, - message: err.message || "Some error occurred while inserting statements." ,'data': "No data" - }); } -}; - - -exports.testthree = async (req, res) => { - - Sync(function() - { - try - { - const losid = req.query.losid; - console.log("start"); - -Entities.findAll({where : { losid } , attributes: [ 'id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' , 'process_instance_id' ] }) -.then(EntitiesData => { - Sync(function(){ - 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); - console.log(formVariableResult); - }); - }); - }); -}); // end of EntitiesData foreach - -console.log("end"); - -}); + // exports.demoone = (req, res) => { + // Sync(function() + // { + // try + // { + // cin = "L74120MH1985PLC035308"; + // // //probe42 api call + // financials_data_api_response = ApiCallHelper.probe42ApiCall(cin); + // financials_data_api_response.then(function(result){ + // //filter lineitems from api responce and construct to needed format + // lineItem_data = Probe42DataMappingHelper.lineItemFetching(result); + // lineItem_data.then(function(lineItem_result){ console.log(lineItem_result); + // lineItem_result.forEach((value,index,array) => { + // // mapping of probe42 api lineItem with itemMaster primary key + // final_array = Probe42DataMappingHelper.lineItemMapping(value,entityid); + // final_array.then(function(update_array_data){ console.log(update_array_data) + // console.log(update_array_data.length) + // // update mapped lineitem value here + // //Probe42DataMappingHelper.lineItemUpdate(update_array_data); + // });//end of lineItemUpdate helper call + // });//end of lineItem mapping with itemMaster primary key helper call + // });//end of lineItem filter from api response helper call + // });//end of probe42 api call + // // final logic ********************************************** + // } 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 sync function + + // }; - - } catch(err) { - res.status(500).send({'status':404, - message: err.message || "Some error occurred while inserting statements." ,'data': "No data" - }); } - });// end of sync -}; \ No newline at end of file + + + + // menulist before api implementation + // exports.MenuList = (req, res) => { + // Sync(function() + // { + // try + // { + // const losid = req.query.losid; + // //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} + // ]; + + // var EntityInsert = new Promise((resolve, reject) => { + // // insert pro42data into entities table using using foreach + // Pro42Data.forEach((Pro42Datavalue, key,array)=>{ + // // 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 + // if (key === array.length -1) {resolve();} + // } + // 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 entityid = 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: entityid }}); + // }); + + // // call and get financial year wise data for entity + // const crnt_year = new Date().getFullYear(); + // const Y1 = crnt_year - 1; + // const Y2 = Y1-1; + // const Y3 = Y2-1; + // const financial_years_api_response_data =[{'fy':Y1,'st_type':2},{'fy':Y2,'st_type':2},{'fy':Y3,'st_type':2}]; + + // //create financial table and entityfinyear table record here + // financial_years_api_response_data.forEach((value, key)=>{ + + // //create Entityfinyears data + // Entityfinyear.create({ "losid":Entitydata.dataValues.losid,"entityid":Entitydata.dataValues.id,"FY":value.fy,"st_type":value.st_type}) + // .then(Entityfinyearsdata => { + + // // create skeletion + // // generate financials data array + // let fin_data_array = []; + // for (let i = 1; i < 120; i++) + // { + // fin_data_obj = { "entity_id":Entityfinyearsdata.dataValues.entityid,"st_type":Entityfinyearsdata.dataValues.st_type,"itemid":i,"fy":Entityfinyearsdata.dataValues.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); + + // }).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 + + // });//end of foreach + + // if (key === array.length -1) {resolve();} + + // }).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 + + // }); // end of promise + + + + + // EntityInsert.then(() => { + // setTimeout(()=>{ + // Statementsmaster.findAll({ where :{is_active : 1} , include: { all: true, nested: true , where :{is_active : 1} , 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 Time = 2000; + // let data = []; + // EntitiesData.forEach((value, key)=>{ + // Time = Time + 500; + // instancesid = value.dataValues.process_instance_id; + // taskid = camundaHelper.financialsListOfProcessInstances(instancesid); + // taskid.then(function(result){ + // Time = Time + 500; + // 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}); + // },Time) + // }); // end of findall EntitiesData + // }); // end of findall masters datas + // },2000) + // }); + + // } 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 sync function + + // }; \ No newline at end of file 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/models/Entityfinyears.js b/app/models/Entityfinyears.js deleted file mode 100644 index 6e38fee..0000000 --- a/app/models/Entityfinyears.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict' -const { Model } = require('sequelize') -module.exports = (sequelize, DataTypes) => { - class Entityfinyears extends Model { - - - } - Entityfinyears.init( - { - losid: { type: DataTypes.STRING }, - entityid: { 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 }, - additional_year_type: { type: DataTypes.INTEGER }, - createdby: { type: DataTypes.INTEGER }, - updatedby: { type: DataTypes.INTEGER }, - - }, - { - sequelize, - tableName: 'entity_fin_years', - modelName: 'Entityfinyears', - createdAt: 'createdon', - updatedAt: 'updatedon', - - } - ) - return Entityfinyears -} diff --git a/app/models/Financials.js b/app/models/Financials.js index 05dbf20..7cf381f 100644 --- a/app/models/Financials.js +++ b/app/models/Financials.js @@ -21,6 +21,7 @@ module.exports = (sequelize, DataTypes) => { fy: { type: DataTypes.STRING }, st_type:{ type: DataTypes.STRING }, itemid: { type: DataTypes.INTEGER }, + is_editable: { type: DataTypes.INTEGER }, is_active: { type: DataTypes.INTEGER }, value: { type: DataTypes.INTEGER }, createdby: { type: DataTypes.INTEGER }, diff --git a/app/models/Itemsmaster.js b/app/models/Itemsmaster.js index cc7e5d3..70acf76 100644 --- a/app/models/Itemsmaster.js +++ b/app/models/Itemsmaster.js @@ -29,6 +29,7 @@ module.exports = (sequelize, DataTypes) => { section: { type: DataTypes.INTEGER }, subsection: { type: DataTypes.INTEGER }, itemtext: { type: DataTypes.STRING }, + pvtltditemkey: { type: DataTypes.STRING }, is_active: { type: DataTypes.INTEGER }, pvtltd: { type: DataTypes.INTEGER }, llp: { type: DataTypes.INTEGER }, diff --git a/app/routes/routes.js b/app/routes/routes.js index 8b51a47..5d416d5 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -8,9 +8,7 @@ module.exports = app => { var router = require("express").Router(); - // router.get("/camunda", financials.camunda); - // router.get("/test", financials.test); - + /** * @swagger * /api/ConsolidatedSummary: diff --git a/app/services/financials.apicall.helper.js b/app/services/financials.apicall.helper.js new file mode 100644 index 0000000..4ab5d8c --- /dev/null +++ b/app/services/financials.apicall.helper.js @@ -0,0 +1,42 @@ +const request = require('request'); +const PROBE42_URL = process.env.PROBE42_URL +PROBE42_USER_ID = process.env.PROBE42_USER_ID +PROBE42_PASSWORD = process.env.PROBE42_PASSWORD +PROBE42_APPLICATION_NAME = process.env.PROBE42_APPLICATION_NAME + + function probe42ApiCall(cin) + { + try + { + const probe_url = PROBE42_URL+"companycomprehensivedetails"; + const myJSONObject = { "UserId": PROBE42_USER_ID, + "Password": PROBE42_PASSWORD, + "ApplicationName": PROBE42_APPLICATION_NAME, + "Cin": cin }; + return new Promise((resolve, reject) => { + request({ + url: probe_url, + method: "POST", + json: true, + body: myJSONObject + }, function (error, response, body){ + let data = body + financial_data = data.data.financials; + resolve(financial_data); + }); + + }); + } + catch (error) + { + console.log(error); + } + } + + + + module.exports = { + probe42ApiCall : probe42ApiCall + + + } \ No newline at end of file diff --git a/app/services/probe42lineitem.mapping.helper.js b/app/services/probe42lineitem.mapping.helper.js new file mode 100644 index 0000000..f91f595 --- /dev/null +++ b/app/services/probe42lineitem.mapping.helper.js @@ -0,0 +1,107 @@ +const { sequelize, Financials , Itemsmaster } = require('../models') +const { Op } = require("sequelize"); +const { logMsg } = require('../services/logger.js'); + function lineItemFetching(financials_data) + { + try + { + return new Promise((resolve, reject) => { + let data = []; + financials_data.forEach((value, index, array) => { + if(value.nature == "STANDALONE" && index == 0 || index == 1 || index == 2) + { + let object = {}; + current_year_in_object = value.year; + fin_data_year = current_year_in_object.substring(0, 4); + let year = {"year": fin_data_year }; + // get balance sheet line items here + let balance_sheet = value.bs; + for (const [bs_key, bs_value ] of Object.entries(balance_sheet)) { + if(bs_key === "assets" || bs_key === "liabilities" || bs_key === "subTotals") + { + Object.assign(object, year, bs_value) + } + } // end of balance_sheet object for loop + // get profit and loss line items here + let profit_and_loss = value.pnl; + for (const [pnl_key, pnl_value ] of Object.entries(profit_and_loss)) { + if(pnl_key === "lineItems" || pnl_key === "subTotals") + { + Object.assign(object, year, pnl_value) + } + } // end of profit_and_loss object for loop + setTimeout(() => { data.push(object); }, 100); + } // end of if condition + + }); // end of financials data foreach + setTimeout(() => { + resolve(data); + }, 500); + }); + } + catch (error) + { + console.log(error); + } + } + + function lineItemMapping(financials_lineitems_data_object,entityid) + { + try + { + return new Promise((resolve, reject) => { + Itemsmaster.findAll({where : { pvtltditemkey: {[Op.ne]: 'NULL'} } , attributes: [ 'id','pvtltditemkey' ] }) + .then(ItemsmasterData => { + let data = []; + + year = financials_lineitems_data_object.year; + ItemsmasterData.forEach((element , key) => { + + for (const [key, item_value ] of Object.entries(financials_lineitems_data_object)) { + remove_underscore = key.replace(/_/g, ""); + converted_item_key = remove_underscore.toLowerCase(); + if(element.dataValues.pvtltditemkey === converted_item_key) + { + let obj = {entityid : entityid ,itemid : element.dataValues.id , value : item_value , year : year}; + data.push(obj); + } + } + + }); + setTimeout(() => { resolve(data); }, 500); + }); + + }); + } + catch (error) + { + console.log(error); + } + } + + + function lineItemUpdate(update_array_data) + { + try + { + update_array_data.forEach((value,index) => { + if(value.value != null) + { + Financials.update( { value: value.value , is_editable : 0 } , { where: { entity_id: value.entityid , itemid: value.itemid , fy:value.year} }) + .then(data => { logMsg.info("update success : "+ data); }) + .catch(err => { logMsg.info("update failed : " + err); }); + } + }); + } + catch (error) + { + console.log(error); + } + } + + + module.exports = { + lineItemFetching : lineItemFetching , + lineItemMapping : lineItemMapping , + lineItemUpdate :lineItemUpdate + } \ No newline at end of file