From 4d9d9399bbc03a59e391fe9b9bb51b46686f024f Mon Sep 17 00:00:00 2001 From: sriramv Date: Tue, 24 Aug 2021 10:12:58 +0530 Subject: [PATCH 1/3] fin_insert:GWM --- app/controllers/financial.controller.js | 18 +++++++++++++++++- app/models/Financials.js | 1 + app/routes/routes.js | 5 ++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index b5bbecc..2979d84 100644 --- a/app/controllers/financial.controller.js +++ b/app/controllers/financial.controller.js @@ -172,5 +172,21 @@ exports.BrokenPeriods = (req, res) => { - +exports.createFinancials = (req, res) => { + let req_array_data = req.body; + req_array_data.forEach((value, key)=>{ + Financials.update({ is_active : 0 },{ where: { id: value.id }}); + delete value.id; + }); + Financials.bulkCreate(req_array_data) + .then(data => { + res.send({'status':200,'message':"success",'data':data}); + logMsg.info("Success :"(data)); + }) + .catch(err => { + res.status(500).send({'status':404, + message: err.message || "Some error occurred while inserting statements." ,'data': "No data" + }); + }); +}; diff --git a/app/models/Financials.js b/app/models/Financials.js index bdf5ef6..05dbf20 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_active: { type: DataTypes.INTEGER }, value: { type: DataTypes.INTEGER }, createdby: { type: DataTypes.INTEGER }, updatedby: { type: DataTypes.INTEGER }, diff --git a/app/routes/routes.js b/app/routes/routes.js index 295d2aa..5b411cf 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -27,8 +27,11 @@ module.exports = app => { // Retrieve all Broken periods router.get("/BrokenPeriodsList/:entityid", financials.BrokenPeriodsList); - // fetchind all master data + // fetching all master data router.get("/MasterDatas", financials.MasterDatas); + + // create financials data + router.post("/createFinancials", financials.createFinancials); //master.controller api's From da9a9d7752adf12dc809303808ee6a5b1bfc4720 Mon Sep 17 00:00:00 2001 From: sriramv Date: Wed, 25 Aug 2021 11:49:57 +0530 Subject: [PATCH 2/3] fim_summary:GWM --- app/controllers/financial.controller.js | 17 ++++++++++++++--- app/routes/routes.js | 20 ++++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index 2979d84..e53bf35 100644 --- a/app/controllers/financial.controller.js +++ b/app/controllers/financial.controller.js @@ -63,6 +63,7 @@ exports.MenuList = async (req, res) => { obj_data = { ...value.dataValues , statementsmasterrData:MasterData} data.push(obj_data); }); + res.send({'status':200,'message':"success",'data':data}); logMsg.info("MenuList api working"); } catch (err) { @@ -86,11 +87,13 @@ exports.FinantialsSummary = async (req, res) => { const Year_1 = data[0].dataValues.fy const Year_2 = data[1].dataValues.fy const Year_3 = data[2].dataValues.fy + const years_data = {'Y1':Year_1 , 'Y2':Year_2 , 'Y3':Year_3} //sequelize.query("Select a.entity_id,a.itemid,e.statement as statement_id ,e.section as section_id ,e.itemtext as items , a.value as fy_"+Year_1+" , b.value fy_"+Year_2+" , c.value fy_"+Year_3+" FROM financials a JOIN ( SELECT id,statement,section, itemtext FROM itemsmaster) e ON a.itemid = e.id JOIN ( SELECT entity_id, itemid, value, fy FROM financials WHERE fy = "+Year_3+") c ON a.entity_id = c.entity_id and a.itemid = c.itemid JOIN ( SELECT entity_id, itemid, value, fy FROM financials WHERE fy = "+Year_2+") b ON a.entity_id = b.entity_id and a.itemid = b.itemid AND a.fy = "+Year_1+" WHERE a.entity_id = "+id) //sequelize.query("Select a.entity_id,x.id as statement_id,x.statement as statement,y.id as section_id,y.section as section,a.itemid,e.itemtext as items,a.value as fy_"+Year_1+",b.value fy_"+Year_2+",c.value fy_"+Year_3+" FROM financials a JOIN ( SELECT id, itemtext ,statement 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.statement = y.id JOIN ( SELECT entity_id, itemid, value, fy FROM financials WHERE fy = "+Year_3+") c ON a.entity_id = c.entity_id and a.itemid = c.itemid JOIN ( SELECT entity_id, itemid, value, fy FROM financials WHERE fy = "+Year_2+") b ON a.entity_id = b.entity_id and a.itemid = b.itemid AND a.fy = "+Year_1+" WHERE a.entity_id = "+id+" order by x.id asc , y.id asc , a.itemid asc ") - 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,a.itemid,e.itemtext as items,e.formula,e.is_calculated,f.statement_name as st_type,a.id as id_"+Year_1+" ,a.value as fy_"+Year_1+" , b.id id_"+Year_2+" ,b.value fy_"+Year_2+" ,c.id as id_"+Year_3+" ,c.value fy_"+Year_3+" FROM financials a JOIN ( SELECT id,itemtext,statement,section,subsection,formula,is_calculated FROM itemsmaster ) e ON a.itemid = e.id JOIN ( SELECT id, statement_name FROM statement_type ) f ON a.st_type = f.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 JOIN ( SELECT id,entity_id, itemid, value,fy,is_active FROM financials WHERE fy = "+Year_3+" and is_active = 1) c ON a.entity_id = c.entity_id and a.itemid = c.itemid JOIN ( SELECT id,entity_id, itemid, value,fy,is_active FROM financials WHERE fy = "+Year_2+" and is_active = 1) b ON a.entity_id = b.entity_id and a.itemid = b.itemid AND a.fy = "+Year_1+" WHERE a.entity_id = "+id+" and a.is_active = 1 order by x.id asc , y.id asc , a.itemid asc ") + 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,a.itemid,e.itemtext as items,e.formula,e.is_calculated,f.statement_name as st_type,a.id as Y1_id ,a.value as Y1_value , b.id Y2_id ,b.value Y2_value ,c.id as Y3_id ,c.value Y3_value FROM financials a JOIN ( SELECT id,itemtext,statement,section,subsection,formula,is_calculated FROM itemsmaster ) e ON a.itemid = e.id JOIN ( SELECT id, statement_name FROM statement_type ) f ON a.st_type = f.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 JOIN ( SELECT id,entity_id, itemid, value,fy,is_active FROM financials WHERE fy = "+Year_3+" and is_active = 1) c ON a.entity_id = c.entity_id and a.itemid = c.itemid JOIN ( SELECT id,entity_id, itemid, value,fy,is_active FROM financials WHERE fy = "+Year_2+" and is_active = 1) b ON a.entity_id = b.entity_id and a.itemid = b.itemid AND a.fy = "+Year_1+" WHERE a.entity_id = "+id+" and a.is_active = 1 order by x.id asc , y.id asc , a.itemid asc ") .then(result => { - res.send({'status':200,'message':"success",'data':result}); + const arr = {"years" : years_data , "summary" : result } + res.send({'status':200,'message':"success",'data':{"years" : years_data , "summary" : result } }); }).catch(err => { res.status(500).send({'status':404, message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" }); @@ -174,10 +177,18 @@ exports.BrokenPeriods = (req, res) => { exports.createFinancials = (req, res) => { let req_array_data = req.body; + let req_array_id = []; req_array_data.forEach((value, key)=>{ - Financials.update({ is_active : 0 },{ where: { id: value.id }}); + req_array_id.push(value.id); delete value.id; }); + Financials.update({ is_active : 0 },{ where: { id: req_array_id }}) + .then(data => { + logMsg.info("Is_active 0 update Success for :"(data)); + }) + .catch(err => { + logMsg.info("Is_active update failed ,meaasge :"(err.message)); + }); Financials.bulkCreate(req_array_data) .then(data => { res.send({'status':200,'message':"success",'data':data}); diff --git a/app/routes/routes.js b/app/routes/routes.js index c44f88a..420a464 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -231,10 +231,22 @@ module.exports = app => { // third party api call example router.get('/third_party_api', (req, res) => { - const options = { - url: "http://localhost:4000/api/MenuList/MW112233", - }; - request.get(options).pipe(res); +// const options = { +// url: "http://localhost:8000/api/MenuList/MW112233", +// }; +// request.get(options).pipe(res); +// console.log(options.status); + +request('http://localhost:8000/api/MenuList/MW112233', function (error, response, body) { + console.error('error:', error); // Print the error if one occurred + console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received + let data = JSON.parse(body); + let array = data.data; + array.forEach((value, key)=>{ + console.log('result :',value.statementsmasterrData ); // Print the HTML for the Google homepage. + }); + +}); }) // routes started here From 809a6beb1d460b552a461ffb92ba08b61ae7cc0d Mon Sep 17 00:00:00 2001 From: sriramv Date: Wed, 25 Aug 2021 16:40:15 +0530 Subject: [PATCH 3/3] fin_update:GWM --- app/controllers/financial.controller.js | 19 ++++++++++++++++++- app/routes/routes.js | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index e53bf35..779e8ac 100644 --- a/app/controllers/financial.controller.js +++ b/app/controllers/financial.controller.js @@ -57,7 +57,7 @@ exports.MenuList = async (req, res) => { }); - const EntitiesData = await Entities.findAll({where : { losid } , attributes: ['id', 'losid' , 'pan' , 'cin' , 'bizname'] }); + const EntitiesData = await Entities.findAll({where : { losid } , attributes: ['id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' ] }); let data = []; EntitiesData.forEach((value, key)=>{ obj_data = { ...value.dataValues , statementsmasterrData:MasterData} @@ -201,3 +201,20 @@ exports.createFinancials = (req, res) => { }); }; + +exports.updateFinancials = (req, res) => { + const req_array_data = req.body; + try + { + req_array_data.forEach((value, key)=>{ + const id = value.id; + Financials.update({ "entity_id":value.entity_id,"sy_type":value.sy_type,"itemid":value.itemid,"fy":value.fy,"value":value.value,"is_active":value.is_active,"updatedby":value.updatedby },{ where: { id:id }}) + }); + res.send({'status':200,'message':"success",'data':"No data"}); + logMsg.info("multiple financials update Success"); + }catch(err) { + res.status(500).send({'status':404, + message: err.message || "Some error occurred while inserting statements." ,'data': "No data" + }); } + +}; \ No newline at end of file diff --git a/app/routes/routes.js b/app/routes/routes.js index 420a464..eec51cc 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -32,6 +32,9 @@ module.exports = app => { // create financials data router.post("/createFinancials", financials.createFinancials); + + // update financials data + router.post("/updateFinancials", financials.updateFinancials); //master.controller api's