diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index 71c3c62..bb8b3a0 100644 --- a/app/controllers/financial.controller.js +++ b/app/controllers/financial.controller.js @@ -2,7 +2,7 @@ //const Entities = db.tutorials; const { Op } = require("sequelize"); -const { sequelize, Entities , Financials , Statementsmaster ,Sectionsmaster , Subsectionsmaster } = require('../models') +const { sequelize, Entities , Financials , Statementsmaster ,Sectionsmaster , Subsectionsmaster , Brokenperiods } = require('../models') const { logMsg } = require('../services/logger.js'); @@ -43,24 +43,6 @@ exports.MenuList = async (req, res) => { }; -// Retrieve all Entities from the database. -exports.findAllEntities = (req, res) => { - - Entities.findAll() - .then(data => { - res.send({'status':200,'message':"success",'data':data}); - - logMsg.info("Success :"(data)); - }) - .catch(err => { - res.status(500).send({ - message: - err.message || "Some error occurred while retrieving tutorials." - }); - }); -}; - - // FinantialsSummary exports.FinantialsSummary = async (req, res) => { @@ -91,8 +73,71 @@ exports.FinantialsSummary = async (req, res) => { }); }; - - +// Broken period list api +exports.BrokenPeriodsList = (req, res) => { + const entityid = req.params.entityid + Brokenperiods.findAll({where : { entity_id : entityid } }) + .then(data => { + res.send({'status':200,'message':"success",'data':data}); + logMsg.info("Success :"(data)); + }) + .catch(err => { + res.status(404).send({'status':404, + message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" }); + }); +}; + +// Broken period Insert OR Update +exports.BrokenPeriods = (req, res) => { + const obj = req.body + if (obj.hasOwnProperty("id")) + { + // update broken periods + const Id = req.body.id + Brokenperiods.update( { + entity_id: req.body.entity_id, + from: req.body.from, + to: req.body.to, + months: req.body.months, + cy: req.body.cy, + py: req.body.py, + variation: req.body.variation, + updatedby: req.body.updatedby, + } , { where: { id: Id } }) + .then(data => { + res.send({'status':200,'message':"success",'data':data}); + }) + .catch(err => { + res.status(404).send({'status':404, + message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" + }); + }); + + } + else + { + // create broken period + Brokenperiods.create({ + entity_id: req.body.entity_id, + from: req.body.from, + to: req.body.to, + months: req.body.months, + cy: req.body.cy, + py: req.body.py, + variation: req.body.variation, + createdby: req.body.createdby, + }) + .then(data => { + res.send({'status':200,'message':"success",'data':data}); + }) + .catch(err => { + res.status(404).send({'status':404, + message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" + }); + }); + } + +}; diff --git a/app/models/Brokenperiods.js b/app/models/Brokenperiods.js index 0833818..63344dc 100644 --- a/app/models/Brokenperiods.js +++ b/app/models/Brokenperiods.js @@ -17,6 +17,8 @@ module.exports = (sequelize, DataTypes) => { Brokenperiods.init( { entity_id: { type: DataTypes.INTEGER }, + from: { type: DataTypes.DATE }, + to: { type: DataTypes.DATE }, months: { type: DataTypes.INTEGER }, cy: { type: DataTypes.INTEGER }, py: { type: DataTypes.INTEGER }, diff --git a/app/routes/routes.js b/app/routes/routes.js index 9d28a2a..15f8adf 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -14,15 +14,18 @@ module.exports = app => { * 200: * description: Returns a mysterious string. */ - // Retrieve all Tutorials - router.get("/EntitiesList", financials.findAllEntities); + // insert or update broken periods + router.post("/BrokenPeriods", financials.BrokenPeriods); - // get statment master data + // get financials summary router.get("/FinantialsSummary/:id", financials.FinantialsSummary); - // get statment master data + // get menu list router.get("/MenuList/:losid", financials.MenuList); + // Retrieve all Broken periods + router.get("/BrokenPeriodsList/:entityid", financials.BrokenPeriodsList); + //master.controller api's // get statment master data