Merge branch 'master' of bitbucket.org:venbainformationtechnology/smc_cet_otherincome_backend

This commit is contained in:
suseendhiran17 2022-07-28 10:31:46 +05:30
commit 88dfb4011a
7 changed files with 68 additions and 9 deletions

View File

@ -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=>{});
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
};

25
app/models/Master.js Normal file
View File

@ -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
}

View File

@ -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 }
},
{

View File

@ -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 }

View File

@ -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 }

View File

@ -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 },

View File

@ -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: