From 17ae3a9c83be1c411be37657bea2752607cac934 Mon Sep 17 00:00:00 2001 From: surya Date: Fri, 22 Oct 2021 19:26:20 +0530 Subject: [PATCH] itemmaster changes --- app/controllers/master.controller.js | 214 ++++++++++++++++++++++----- app/controllers/test.controller.js | 77 ++++++++++ app/models/Itemsmaster.js | 1 + app/routes/routes.js | 63 +++++++- 4 files changed, 311 insertions(+), 44 deletions(-) diff --git a/app/controllers/master.controller.js b/app/controllers/master.controller.js index ad6dd94..ec0320b 100644 --- a/app/controllers/master.controller.js +++ b/app/controllers/master.controller.js @@ -272,6 +272,7 @@ exports.Insertitem = (req, res) => { others: req.body.others, formula: req.body.formula, is_calculated: req.body.is_calculated, + is_summary: is_summary, createdby: req.body.createdby, updatedby: req.body.updatedby, }; @@ -722,46 +723,179 @@ exports.makerComplete = (req, res) => { //promise -// const doWorkPromise = new Promise((resolve, reject) => { -// setTimeout(() => { -// resolve([7, 4, 1]) -// // reject('Things went wrong!') -// }, 2000) -// }) - -// doWorkPromise.then((result) => { -// console.log('Success!', result) -// }).catch((error) => { -// console.log('Error!', error) -// }) - - - - -// public function reassign(Request $request) -// { -// $gst_data = $request->all(); - -// $gstin_id = $gst_data['gstin_id']; -// $process_instance_id = GSTIN::select('process_instance_id') -// ->where( 'id', '=', $gstin_id )->first(); - - -// if($process_instance_id) -// { -// $instance_id = $process_instance_id['process_instance_id']; -// $json = [ 'json' => [ "processInstanceIdIn" => [ $instance_id ] ] ]; -// //get taskid from gstListOfProcessInstances camunda Api with process_instance_id -// $get_task_id = CamundaHelper::gstListOfProcessInstances($json); -// // $taskid = count($get_task_id)? $get_task_id[0]['id'] : NULL; -// $taskid = $get_task_id[0]['id']; -// //calling GstTaskComplete camunda Api with taskid -// $value = false; -// CamundaHelper::GstTaskComplete($taskid,$value); -// return ResponseBuilder::sendResponse(200,'success'); - -// } -// } + +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/controllers/test.controller.js b/app/controllers/test.controller.js index fc0fea4..fb6c2e0 100644 --- a/app/controllers/test.controller.js +++ b/app/controllers/test.controller.js @@ -2,6 +2,8 @@ const { response } = require('express'); const { sequelize, Entities , Financials , Statementsmaster , Sectionsmaster , Subsectionsmaster , Brokenperiods , Entityfinyears } = require('../models') const { logMsg } = require('../services/logger.js'); +const financialControllerHelper = require('../services/financial.controller.helper.js'); +const camundaHelper = require('../services/camunda.helper.js'); @@ -436,3 +438,78 @@ function testhree(req , res) { + + + +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} , + attributes: ['id', 'statement', 'is_active'], + include :[{ + association: 'sectionsmasterData' , + where :{is_active : 1} , + attributes: ['id', 'section', 'is_active'], + include :[{ + association: 'subsectionsmasterData' , + where :{is_active : 1} , + attributes: ['id', 'subsection','itemtext', 'is_active'], + required :false + }], + required :false + }], + required :false + }) + .then(MasterData => { + Entities.findAll({where : { losid } , attributes: [ 'id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' , 'process_instance_id' ] }) + .then(EntitiesData => { + let data = []; + EntitiesData.forEach((value, key)=>{ + + instancesid = value.dataValues.process_instance_id; + taskid = camundaHelper.financialsListOfProcessInstances(instancesid); + taskid.then(function(result){ + formVariable = camundaHelper.financialsFormVariables(result); + formVariable.then(function(form_result){ + formVariableResult = JSON.parse(form_result); + if(formVariableResult.type){ camunda_status = {"process_status":"NULL"}; } else { camunda_status =JSON.parse(form_result); } + obj_data = { ...value.dataValues ,status:camunda_status , statementsmasterrData:MasterData } + data.push(obj_data); + }); + }); + // obj_data = { ...value.dataValues , statementsmasterrData:MasterData } + // data.push(obj_data); + + }); // end of EntitiesData foreach + + setTimeout(()=>{ + // below code for overall sum object push process + sum_data = { ...{'losid':losid,'bizname':"Consolidated Financials Summary",'is_consolidated_api_call':1} , statementsmasterrData:MasterData }; + data.push(sum_data); + // send respose to FE + res.send({'status':200,'message':"success",'data':data}); + },5000) + }); // end of findall EntitiesData + }); // end of findall masters datas + } // end of starter function if condition + },5000) + } catch (err) { + console.log(err) + return res.status(500).json({'status':404,'message':"failed",'data':"No data"}) + } + +}; + + diff --git a/app/models/Itemsmaster.js b/app/models/Itemsmaster.js index c8c9eb5..cc7e5d3 100644 --- a/app/models/Itemsmaster.js +++ b/app/models/Itemsmaster.js @@ -35,6 +35,7 @@ module.exports = (sequelize, DataTypes) => { others: { type: DataTypes.INTEGER }, formula: { type: DataTypes.INTEGER }, is_calculated: { type: DataTypes.INTEGER }, + is_summary: { type: DataTypes.INTEGER }, createdby: { type: DataTypes.INTEGER }, updatedby: { type: DataTypes.INTEGER }, diff --git a/app/routes/routes.js b/app/routes/routes.js index b6ee749..b1ebd6d 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -652,6 +652,10 @@ module.exports = app => { * type: integer * description: is_calculated - it shows the field need to be calculate or not * example: 1 +* is_summary: +* type: integer +* description: is_calculated - it shows the field need to be shows on summary page or not +* example: 1 * is_active: * type: integer * description: the state of section(0 means inactive,1 means active) @@ -921,7 +925,7 @@ module.exports = app => { * description: Reassign * parameters: * - in: query -* name: id +* name: entityid * schema: * type: integer * required: true @@ -935,13 +939,62 @@ module.exports = app => { router.get("/Reassign", master.Reassign); - + /** +* @swagger +* /api/makerComplete: +* get: +* summary: makerComplete +* description: makerComplete +* parameters: +* - in: query +* name: losid +* schema: +* type: string +* required: true +* description: losid +* example: MW112233 +* - in: query +* name: entityid +* schema: +* type: integer +* required: true +* description: primary id +* example: 6 +* responses: +* 200: +* description: success +*/ router.get("/makerComplete", master.makerComplete); + /** +* @swagger +* /api/checkerComplete: +* get: +* summary: checkerComplete +* description: checkerComplete +* parameters: +* - in: query +* name: losid +* schema: +* type: string +* required: true +* description: losid +* example: MW112233 +* - in: query +* name: entityid +* schema: +* type: integer +* required: true +* description: primary id +* example: 6 +* responses: +* 200: +* description: success +*/ router.get("/checkerComplete", master.checkerComplete); - + router.get("/test", master.test); @@ -968,4 +1021,6 @@ array.forEach((value, key)=>{ // routes started here app.use('/api', router); -}; \ No newline at end of file +}; + +