diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index f64aa43..0705fba 100644 --- a/app/controllers/financial.controller.js +++ b/app/controllers/financial.controller.js @@ -50,6 +50,11 @@ exports.MasterDatas = async (req, res) => { + + + + + exports.MenuList = (req, res) => { Sync(function() { @@ -69,9 +74,10 @@ exports.MenuList = (req, res) => { { // insert pro42data into entities table using using foreach redirectionApiData.forEach((Pro42Datavalue, key,array)=>{ - + + let cin_number = Pro42Datavalue.ciN_LLPIN.toUpperCase(); // check if the Pro42Data (entity) already inserted - Entities.findOne({ where: { losid : Pro42Datavalue.loginNo , pan : Pro42Datavalue.pan , cin : Pro42Datavalue.ciN_LLPIN } }).then(Entity => { + Entities.findOne({ where: { losid : Pro42Datavalue.loginNo , pan : Pro42Datavalue.pan , cin : cin_number } }).then(Entity => { if(Entity) { // skip inserting @@ -80,7 +86,7 @@ exports.MenuList = (req, res) => { else { - Entities.create({ "losid":Pro42Datavalue.loginNo,"pan":Pro42Datavalue.pan,"cin":Pro42Datavalue.ciN_LLPIN,"bizname":Pro42Datavalue.entityName,"entity_type":Pro42Datavalue.entityType,"probe42_data_status":1,"is_verified":0,"createdby":Pro42Datavalue.createdby}) + Entities.create({ "losid":Pro42Datavalue.loginNo,"pan":Pro42Datavalue.pan,"cin":cin_number,"bizname":Pro42Datavalue.entityName,"entity_type":Pro42Datavalue.entityType,"probe42_data_status":1,"is_verified":0,"createdby":Pro42Datavalue.createdby}) .then(Entitydata => { const cin = Entitydata.dataValues.cin; @@ -174,10 +180,10 @@ exports.MenuList = (req, res) => { 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' , 'probe42_data_status' ,'is_verified' ] }) + Entities.findAll({where : { losid } , attributes: [ 'id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' , 'process_instance_id' , 'probe42_data_status' ,'is_verified' ], order: [['id', 'ASC']] }) .then(EntitiesData => { let Time = 2000; @@ -209,7 +215,7 @@ exports.MenuList = (req, res) => { },Time) }); // end of findall EntitiesData }); // end of findall masters datas - },2000) + }); } catch(err) { @@ -225,64 +231,6 @@ exports.MenuList = (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) -// { -// 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)=>{ - -// 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"}) -// } - -// }; - - - @@ -382,6 +330,9 @@ sequelize.query("select a.losid,a.entityid,a.FY,a.st_type as st_type_id, b.state + + + //ConsolidatedSummary exports.ConsolidatedSummary = async (req, res) => { @@ -447,6 +398,10 @@ exports.ConsolidatedSummary = async (req, res) => { + + + + // Broken period list api exports.BrokenPeriodsList = (req, res) => { const entityid = req.query.entityid @@ -471,6 +426,7 @@ exports.BrokenPeriodsList = (req, res) => { + // Broken period Insert OR Update exports.BrokenPeriods = (req, res) => { const obj = req.body @@ -565,7 +521,7 @@ exports.createFinancials = (req, res) => { - +// this api not in use exports.updateFinancials = (req, res) => { const req_array_data = req.body; try @@ -660,7 +616,6 @@ exports.createFinancialYear = async (req, res) => { exports.refreshApi = (req, res) => { - try { const cin = req.body.cin; @@ -670,6 +625,7 @@ exports.refreshApi = (req, res) => { // 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){ + // check if(result == false) { res.send({'status':404,message: "Failed" ,'data': "No data for this cin number from probe42" }); @@ -678,21 +634,71 @@ exports.refreshApi = (req, res) => { { //filter lineitems from api responce and construct to needed format lineItem_data = Probe42DataMappingHelper.lineItemFetching(result); - lineItem_data.then(function(lineItem_result){ + lineItem_data.then(function(lineItem_result){ var SkeletonUpdate = new Promise((resolve, reject) => { - //create financial table and entityfinyear table record here - lineItem_result.forEach((value, index)=>{ - - // 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); - // promise resolve check - if (index === update_array_data.length -1) { resolve(); } - });//end of lineItemUpdate helper call + //create financial table and entityfinyear table record here + lineItem_result.forEach((value, index , lineItem_result_array)=>{ + + Entityfinyear.findOne({raw : true , where:{losid : losid , entityid : entityid , FY : value.year}}) + .then((data)=>{ + if(data) + { console.log(value.year + "exist"); + // 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); + // promise resolve check + if (index === lineItem_result_array.length -1) { resolve(); } + });//end of lineItemUpdate helper call + + } + else + { console.log(value.year + " not exist"); + // create skeleton for missing year and update financials values + + Entityfinyear.create({ "losid":losid,"entityid":entityid,"FY":value.year,"st_type": 1 }) + .then(Entityfinyearsdata => { + // create skeletion with itemmaster data (itemmaster(id) == financial(itemid)) + Itemsmaster.findAll({ where :{is_active : 1},attributes: ['id'] , order: [['id', 'ASC']] }) + .then(ItemsmasterData => { + //construct lineitem array for bulk insert using itemmaster primarykey (id) + var SkeletonInsert = new Promise((resolve, reject) => { + let fin_data_array = []; + ItemsmasterData.forEach( (itemvalue , index , itemvaluearray) => { + fin_data_obj = { "entity_id":Entityfinyearsdata.dataValues.entityid,"st_type":Entityfinyearsdata.dataValues.st_type,"itemid":itemvalue.dataValues.id,"fy":Entityfinyearsdata.dataValues.FY,"value":0,"is_active":1,"createdby":4} + fin_data_array.push(fin_data_obj); + if (index === itemvaluearray.length -1) { resolve(fin_data_array); } + }) + }); + SkeletonInsert.then((Query_data)=>{ + Financials.bulkCreate(Query_data).then(data=>{ + logMsg.info("Skeleton created successfully for entityid : "+ entityid +" year : " +value.year); + // 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); + // promise resolve check + if (index === lineItem_result_array.length -1) { resolve(); } + });//end of lineItemUpdate helper call + }).catch(err=>(console.log(err))); //skeleton bulk create query + }); + }).catch(err=>(console.log(err))); //itemmaster query + + + + }).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 line item foreach }); @@ -701,12 +707,10 @@ exports.refreshApi = (req, res) => { res.status(200).send({'status':200,message: "success" ,'data': "No data" }); }, 2000); }); - - - - - });//end of lineItem filter from api response helper call + + });//end of lineItem filter from api response helper call } // end of probe42 api responce success else condition + });//end of probe42 api call @@ -720,29 +724,142 @@ exports.refreshApi = (req, res) => { - exports.demo = (req, res) => { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + exports.demo = async (req, res) => { try { - // const probe42_data_status = req.body.probe42_data_status; - // const entityid = req.body.entityid; - var today = new Date(); - var year = today.getFullYear(); - console.log(year) - this.MenuList('MW112233') + losid = req.query.losid + + // 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' , 'probe42_data_status' ,'is_verified' ] }) + // .then(EntitiesData => { + + + // let data = []; + // var getCamundaStatus = new Promise(async (resolve, reject) => { + + // await EntitiesData.forEach(async (value, key , array)=>{ + + // instancesid = value.dataValues.process_instance_id; + // taskid = await camundaHelper.financialsListOfProcessInstances(instancesid); + + // formVariable = await camundaHelper.financialsFormVariables(taskid); + + // formVariableResult = await JSON.parse(formVariable); + // if(formVariableResult.type){ camunda_status = {"process_status":"NULL"}; } else { camunda_status = formVariableResult; } + // obj_data = { ...value.dataValues ,status:camunda_status , statementsmasterrData:MasterData } + // data.push(obj_data); + // if (key === array.length -1) { resolve(); } + // }); // end of EntitiesData foreach + + // }); + + // getCamundaStatus.then(()=>{ + // // 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}); + // }); + + // }); // end of findall EntitiesData + // }); // end of findall masters datas + + + + + + + + + + + // redirectionApi = ApiCallHelper.redirectionApiCall(losid); + // redirectionApi.then(function(redirectionApiData){ + + // cin = redirectionApiData[0].ciN_LLPIN; + // cin_no = cin.toUpperCase(); + // console.log(cin_no) + // financials_data_api_response = ApiCallHelper.probe42ApiCall(cin_no); + // financials_data_api_response.then(function(result){ console.log(result) + // //filter lineitems from api responce and construct to needed format + // lineItem_data = Probe42DataMappingHelper.lineItemFetching(result); + // lineItem_data.then(function(lineItem_result){ + // lineItem_result.forEach((value,index,array) => { + // // mapping of probe42 api lineItem with itemMaster primary key + // entityid = 00000; + // 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 + // }); }catch(err) { res.send({'status':404,message: err.message || "Some error occurred while inserting statements." ,'data': "No data"}); } - }; - - + }; + @@ -778,7 +895,7 @@ exports.refreshApi = (req, res) => { // });//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, @@ -796,3 +913,8 @@ exports.refreshApi = (req, res) => { + + + + + \ No newline at end of file diff --git a/app/controllers/master.controller.js b/app/controllers/master.controller.js index 93d3c8b..1b6f017 100644 --- a/app/controllers/master.controller.js +++ b/app/controllers/master.controller.js @@ -705,201 +705,6 @@ exports.makerComplete = (req, res) => { }; -// exports.test = (req, res) => { - -// try -// { -// const processInstanceId = "fb2b8cd9-271e-11ec-a4f4-42010a800002"; - -// task_id = camundaHelper.financialsListOfProcessInstances(processInstanceId); - -// res.send({'status':200,'message':"success",'data':"No data"}); -// logMsg.info("Cheker Completed Success"); -// } -// catch(err) { -// res.status(500).send({'status':404, -// message: err.message || "Some error occurred while Cheker Complete." ,'data': "No data" -// }); } - -// }; - - - -//promise - - -exports.test = (req, res) => -{ - const losid = req.query.losid; - try - { - const losid = req.query.losid; - const doWorkPromise = new Promise((resolve, reject) => { - - 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 - - resolve('success'); - - - }) - - doWorkPromise.then((val)=> - { - const losid = req.query.losid - // call starter function here - 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 - - - // 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}); - - }); // end of findall EntitiesData - }); // end of findall masters datas - // end of starter function if condition - - - }).catch((error) => { - console.log('Error!', error) - }) - // .then((result) => { - // console.log('Success!', result) - // }).catch((error) => { - // console.log('Error!', error) - // }) - res.send({'status':200,'message':"success",'data':"No data"}); - logMsg.info("Cheker Completed Success"); - - } - - - - catch(err) { - res.status(500).send({'status':404, - message: err.message || "Some error occurred while Cheker Complete." ,'data': "No data" - }); } - //try -}; - - - - - - diff --git a/app/routes/routes.js b/app/routes/routes.js index 9c76d01..277a920 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -1028,7 +1028,7 @@ module.exports = app => { */ router.get("/checkerComplete", master.checkerComplete); - router.get("/test", master.test); + diff --git a/app/services/financial.controller.helper.js.js b/app/services/financial.controller.helper.js.js index caf5897..5b988ac 100644 --- a/app/services/financial.controller.helper.js.js +++ b/app/services/financial.controller.helper.js.js @@ -36,8 +36,8 @@ function createSkeleton(losid,entityid) // create skeletion with itemmaster data (itemmaster(id) == financial(itemid)) Itemsmaster.findAll({ where :{is_active : 1},attributes: ['id'] , order: [['id', 'ASC']] }) .then(ItemsmasterData => { - var today = new Date(); - var year = today.getFullYear(); + + var year = new Date().getFullYear(); year_data = [{fy:year - 1},{fy:year - 2},{fy:year - 3}]; year_data.forEach(year_value => {