diff --git a/app/controllers/other.income.controller.js b/app/controllers/other.income.controller.js index dbd0eed..0378b15 100644 --- a/app/controllers/other.income.controller.js +++ b/app/controllers/other.income.controller.js @@ -1,18 +1,18 @@ -const { sequelize,MasterP , MasterC , OtherIncomeP , OtherIncomeC} = require('../models') +const { sequelize,MasterP , MasterC , OtherIncomeP , OtherIncomeC , Master} = require('../models') const { logMsg } = require('../services/logger.js'); exports.otherIncomeList = async (req, res) => { try { - OtherIncomeData = await OtherIncomeP.findAll({ where:{ losid:req.query.losid, is_active:1},include:[{model:OtherIncomeC}]}).catch(err=>{}); + OtherIncomeData = await OtherIncomeP.findAll({ where:{ losid:req.query.losid, is_active:1},order :[['order_id','ASC']],include:[{model:OtherIncomeC}]}).catch(err=>{}); if(OtherIncomeData.length != 0) { res.send({'status':200 , message:"Success." ,'data': OtherIncomeData}); - console.log("data already exist"); + } else { @@ -21,7 +21,7 @@ exports.otherIncomeList = async (req, res) => var MasterDataInsert = new Promise(async(resolve, reject) => { MasterData.forEach(async(master_value,index,array) => { - OtherIncomeP.create({losid:req.query.losid,table_name:master_value.table_name,particulars:master_value.particulars}) + OtherIncomeP.create({losid:req.query.losid,order_id:master_value.order_id,table_name:master_value.table_name,particulars:master_value.particulars}) .then(async(parent_data)=>{ master_value.MasterCs.forEach(async(child_data) => { await OtherIncomeC.create({other_income_id:parent_data.dataValues.id,column_name:child_data.column_name,value:child_data.value}) @@ -33,11 +33,14 @@ exports.otherIncomeList = async (req, res) => }); MasterDataInsert.then(async()=>{ - OtherIncomeData = await OtherIncomeP.findAll({ where:{ losid:req.query.losid, is_active:1},include:[{model:OtherIncomeC}]}).catch(err=>{}); - res.send({'status':200 , message:"Success." ,'data': OtherIncomeData}); + setTimeout(async() => { + OtherIncomeData = await OtherIncomeP.findAll({ where:{ losid:req.query.losid, is_active:1},order :[['order_id','ASC']],include:[{model:OtherIncomeC}]}).catch(err=>{}); + res.send({'status':200 , message:"Success." ,'data': OtherIncomeData}); + }, 500); + }); - console.log("create master data for losid"); + } @@ -81,6 +84,22 @@ exports.updateOtherIncome = async (req, res) => +exports.getMasterData = async (req, res) => +{ + try + { + data =await Master.findAll(); + res.send({'status':200 , message:"Success." ,'data': data}); + + } catch(err) { + res.status(500).send({'status':404, + message: err.message || "Some error occurred while inserting statements." ,'data': "No data" + }); } //end of try catch + +}; + + + diff --git a/app/models/Master.js b/app/models/Master.js new file mode 100644 index 0000000..6bf9a37 --- /dev/null +++ b/app/models/Master.js @@ -0,0 +1,25 @@ +'use strict' +const { Model } = require('sequelize') +module.exports = (sequelize, DataTypes) => { + class Master extends Model { + + + } + Master.init( + { + + order_id: { type: DataTypes.INTEGER }, + column_name: { type: DataTypes.STRING }, + master_value: { type: DataTypes.STRING }, + formula: { type: DataTypes.STRING } + + }, + { + sequelize, + tableName: 'master', + modelName: 'Master', + } + ) + + return Master +} diff --git a/app/models/MasterC.js b/app/models/MasterC.js index 1209e27..aea682d 100644 --- a/app/models/MasterC.js +++ b/app/models/MasterC.js @@ -9,7 +9,7 @@ module.exports = (sequelize, DataTypes) => { { master_id: { type: DataTypes.INTEGER }, column_name: { type: DataTypes.STRING }, - value: { type: DataTypes.INTEGER }, + value: { type: DataTypes.STRING }, is_active: { type: DataTypes.INTEGER } }, { diff --git a/app/models/MasterP.js b/app/models/MasterP.js index bcafa29..9e62668 100644 --- a/app/models/MasterP.js +++ b/app/models/MasterP.js @@ -7,6 +7,7 @@ module.exports = (sequelize, DataTypes) => { } MasterP.init( { + order_id: { type: DataTypes.INTEGER }, table_name: { type: DataTypes.STRING }, particulars: { type: DataTypes.STRING }, is_active: { type: DataTypes.INTEGER } diff --git a/app/models/OtherIncomeC.js b/app/models/OtherIncomeC.js index 2f67cd9..a017b4c 100644 --- a/app/models/OtherIncomeC.js +++ b/app/models/OtherIncomeC.js @@ -10,7 +10,7 @@ module.exports = (sequelize, DataTypes) => { other_income_id: { type: DataTypes.INTEGER }, column_name: { type: DataTypes.STRING }, - value: { type: DataTypes.INTEGER }, + value: { type: DataTypes.STRING }, is_active: { type: DataTypes.INTEGER }, createdby: { type: DataTypes.INTEGER }, updatedby: { type: DataTypes.INTEGER } diff --git a/app/models/OtherIncomeP.js b/app/models/OtherIncomeP.js index f5ff375..806c0de 100644 --- a/app/models/OtherIncomeP.js +++ b/app/models/OtherIncomeP.js @@ -8,6 +8,7 @@ module.exports = (sequelize, DataTypes) => { OtherIncomeP.init( { losid: { type: DataTypes.STRING }, + order_id: { type: DataTypes.INTEGER }, table_name: { type: DataTypes.STRING }, particulars: { type: DataTypes.STRING }, is_active: { type: DataTypes.INTEGER }, diff --git a/app/routes/routes.js b/app/routes/routes.js index 1633a3e..d5456c6 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -5,6 +5,19 @@ module.exports = app => { const { logMsg } = require('../services/logger.js'); var router = require("express").Router(); + +/** +* @swagger +* /api/getMasterData: +* get: +* summary: other Income data List +* description: +* responses: +* 200: +* description: success +*/ +router.get("/getMasterData", IncomeController.getMasterData); + /** * @swagger * /api/otherIncomeList: