surya 2021-08-25 18:22:00 +05:30
commit 53acca158b
3 changed files with 71 additions and 8 deletions

View File

@ -57,12 +57,13 @@ 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}
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" });
@ -172,5 +175,46 @@ exports.BrokenPeriods = (req, res) => {
exports.createFinancials = (req, res) => {
let req_array_data = req.body;
let req_array_id = [];
req_array_data.forEach((value, key)=>{
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});
logMsg.info("Success :"(data));
})
.catch(err => {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
});
});
};
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"
}); }
};

View File

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

View File

@ -28,9 +28,15 @@ 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);
// update financials data
router.post("/updateFinancials", financials.updateFinancials);
@ -512,10 +518,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