reinitiateApi:GWM

This commit is contained in:
sriramv 2022-02-02 10:53:55 +05:30
parent 2aab778ffe
commit 7e12025250
5 changed files with 89 additions and 39 deletions

View File

@ -80,7 +80,7 @@ exports.MenuList = (req, res) => {
else
{
Entities.create({ "losid":Pro42Datavalue.loginNo,"pan":Pro42Datavalue.pan,"cin":Pro42Datavalue.ciN_LLPIN,"bizname":Pro42Datavalue.entityName,"entity_type":Pro42Datavalue.entityType,"createdby":Pro42Datavalue.createdby})
Entities.create({ "losid":Pro42Datavalue.loginNo,"pan":Pro42Datavalue.pan,"cin":Pro42Datavalue.ciN_LLPIN,"bizname":Pro42Datavalue.entityName,"entity_type":Pro42Datavalue.entityType,"probe42_data_status":1,"createdby":Pro42Datavalue.createdby})
.then(Entitydata => {
const cin = Entitydata.dataValues.cin;
@ -177,7 +177,7 @@ exports.MenuList = (req, res) => {
setTimeout(()=>{
Statementsmaster.findAll({ where :{is_active : 1} , include: { all: true, nested: true , where :{is_active : 1} , required:false}})
.then(MasterData => {
Entities.findAll({where : { losid } , attributes: [ 'id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' , 'process_instance_id' ] })
Entities.findAll({where : { losid } , attributes: [ 'id', 'losid' , 'pan' , 'cin' , 'bizname' , 'entity_type' , 'activity_group' , 'biz_act_desc' , 'process_instance_id' , 'probe42_data_status' ] })
.then(EntitiesData => {
let Time = 2000;
@ -699,16 +699,33 @@ exports.createFinancialYear = async (req, res) => {
.then(Entityfinyearsdata => {
// generate new financials data array for given FY with entity_id
Itemsmaster.findAll({ where :{is_active : 1},attributes: ['id'] , order: [['id', 'ASC']] })
.then(ItemsmasterData => {
//construct lineitem array for bulk insert using itemmaster primarykey (id)
var SkeletonInsert = new Promise((resolve, reject) => {
let fin_data_array = [];
for (let i = 1; i <= 120; i++)
{
fin_data_obj = { "entity_id":req.body.entityid,"st_type":req.body.st_type,"itemid":i,"fy":req.body.fy,"value":0,"is_active":1,"createdby":4}
ItemsmasterData.forEach( (itemvalue , index , itemvaluearray) => {
fin_data_obj = { "entity_id":Entityfinyearsdata.dataValues.entityid,"st_type":Entityfinyearsdata.dataValues.st_type,"itemid":itemvalue.dataValues.id,"fy":Entityfinyearsdata.dataValues.FY,"value":0,"is_active":1,"createdby":4}
fin_data_array.push(fin_data_obj);
}
//bulk financials data create
Financials.bulkCreate(fin_data_array);
if (index === itemvaluearray.length -1) { resolve(fin_data_array); }
})
});
SkeletonInsert.then((Query_data)=>{
Financials.bulkCreate(Query_data).then(data=>{
logMsg.info("Skeleton created for LosId ="+losid+" - EntityId = "+entityid);
//response
res.status(200).send({'status':200,'message':"success",'data':"No data"});
}).catch(err=>(console.log(err))); //skeleton bulk create query
});
}).catch(err=>(console.log(err))); //itemmaster query
}).catch(err => {
res.status(404).send({'status':404,
message: err.message || "Some error occurred while insertinging statements." ,'data': "No data" });
@ -941,27 +958,47 @@ exports.createFinancialYear = async (req, res) => {
exports.demoone = (req, res) => {
exports.ReInitiateApi = (req, res) => {
try
{
console.log("inside function");
losid = "MW00075486";
redirectionApi = ApiCallHelper.redirectionApiCall(losid);
redirectionApi.then(function(redirectionApiData){
res.send(redirectionApiData)
redirectionApiData.forEach(element => {
cin = element.ciN_LLPIN;
if(cin != "")
const cin = req.body.cin;
const losid = req.body.losid;
const entityid = req.body.entityid;
// call and get financial year wise data for entity (probe42 api call)
financials_data_api_response = ApiCallHelper.probe42ApiCall(cin);
financials_data_api_response.then(function(result){
if(result == false)
{
prob42 = ApiCallHelper.probe42ApiCall(cin)
prob42.then(function(prob42Date){
console.log(prob42Date)
})
// create skeleton here
//financialControllerHelper.createSkeleton(losid,entityid);
}
});
})
else
{
//filter lineitems from api responce and construct to needed format
lineItem_data = Probe42DataMappingHelper.lineItemFetching(result);
lineItem_data.then(function(lineItem_result){
console.log(lineItem_result)
//create financial table and entityfinyear table record here
lineItem_result.forEach((value, key)=>{
//line item data update
// mapping of probe42 api lineItem with itemMaster primary key
final_array = Probe42DataMappingHelper.lineItemMapping(value,entityid);
final_array.then(function(update_array_data){
console.log(update_array_data)
// update mapped lineitem value here
//Probe42DataMappingHelper.lineItemUpdate(update_array_data);
});//end of lineItemUpdate helper call
});//end of line item foreach
setTimeout(() => {
res.status(200).send({'status':200,message: "success" ,'data': "No data" });
}, 5000);
});//end of lineItem filter from api response helper call
} // end of probe42 api responce success else condition
});//end of probe42 api call
}//try

View File

@ -24,6 +24,7 @@ module.exports = (sequelize, DataTypes) => {
entity_type: { type: DataTypes.STRING },
activity_group: { type: DataTypes.STRING },
biz_act_desc: { type: DataTypes.STRING },
probe42_data_status : {type : DataTypes.INTEGER},
createdby: { type: DataTypes.INTEGER },
updatedby: { type: DataTypes.INTEGER },

View File

@ -8,7 +8,7 @@ module.exports = app => {
var router = require("express").Router();
router.get("/demoone", financials.demoone);
router.post("/ReInitiateApi", financials.ReInitiateApi);
/**
* @swagger
* /api/ConsolidatedSummary:

View File

@ -54,6 +54,7 @@ function createSkeleton(losid,entityid)
SkeletonInsert.then((Query_data)=>{
Financials.bulkCreate(Query_data).then(data=>{
logMsg.info("Skeleton created for LosId ="+losid+" - EntityId = "+entityid);
Entities.update({ "probe42_data_status": 2 },{ where: { id: entityid }});
}).catch(err=>(console.log(err))); //skeleton bulk create query
});

View File

@ -1,4 +1,4 @@
const { sequelize, Financials , Itemsmaster } = require('../models')
const { sequelize, Financials , Itemsmaster , Entities} = require('../models')
const { Op } = require("sequelize");
const { logMsg } = require('../services/logger.js');
function lineItemFetching(financials_data)
@ -84,6 +84,11 @@ const { logMsg } = require('../services/logger.js');
{
try
{
entityid = update_array_data[0].entityid;
var LineItemUpdate = new Promise((resolve, reject) => {
update_array_data.forEach((value,index) => {
if(value.value != null)
{
@ -91,6 +96,12 @@ const { logMsg } = require('../services/logger.js');
.then(data => { logMsg.info("update success : "+ data); })
.catch(err => { logMsg.info("update failed : " + err); });
}
if (index === update_array_data.length -1) { resolve(); }
});
});
LineItemUpdate.then((Query_data)=>{
Entities.update({ "probe42_data_status": 0 },{ where: { id: entityid }});
});
}
catch (error)