From 320e56ececf400b5fd80d779395a7fdf9f0a0b61 Mon Sep 17 00:00:00 2001 From: sriramv Date: Sat, 7 May 2022 13:04:37 +0530 Subject: [PATCH] finalcialInfo:GWM --- app/controllers/salespd.controller.js | 74 +++++++++++++------ ...{BreifOfBusiness.js => BriefOfBusiness.js} | 0 app/models/FinancialInformation.js | 6 ++ 3 files changed, 57 insertions(+), 23 deletions(-) rename app/models/{BreifOfBusiness.js => BriefOfBusiness.js} (100%) diff --git a/app/controllers/salespd.controller.js b/app/controllers/salespd.controller.js index 8808718..7b15a85 100644 --- a/app/controllers/salespd.controller.js +++ b/app/controllers/salespd.controller.js @@ -18,27 +18,43 @@ exports.PullSalesPdData = async (req, res) => const len = Object.keys(tempData).length - 1; for (const [keys, values] of Object.entries(tempData)) { count++; - console.log(values); + if (Array.isArray(values) == true ) { + pre_year_sales = 0; + pre_year_net_profit = 0; + pre_year_net_pro_loss_per = 0; values.forEach(async(values) => { if (keys == 'section1') { Object.assign(values, { ref_no: req.body.pdid , product :req.body.product , case_no :req.body.caseno}); await GeneralSection.create( values ) .then((successData)=>{logMsg.info("GeneralSection insert success ,PdId= "+successData.dataValues.pd_id);}) .catch((err)=>{ logMsg.info("GeneralSection insert failed ,PdId(ref_no)= "+req.body.pdid); }); - storeId = await GeneralSection.findOne({ where : { ref_no : req.body.pdid , is_active : 1 }}); + storeId = await GeneralSection.findOne({ where : { ref_no : req.body.pdid ,case_no :req.body.caseno, is_active : 1 }}); }; - if (keys == 'section2') { Object.assign(values, { pd_id: storeId.pd_id }); await FundRequirement.create( values ).then((successData)=>{logMsg.info("FundRequirement insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FundRequirement insert failed ,PdId= "+storeId.pd_id); }); }; - if (keys == 'section3') { Object.assign(values, { pd_id: storeId.pd_id }); await DetailsOfKeyShareHolder.create( values).then((successData)=>{logMsg.info("DetailsOfKeyShareHolder insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("DetailsOfKeyShareHolder insert failed ,PdId= "+storeId.pd_id);}); }; - if (keys == 'section4') { Object.assign(values, { pd_id: storeId.pd_id }); await BriefOfBusiness.create( values).then((successData)=>{logMsg.info("BreifOfBusiness insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("BreifOfBusiness insert failed ,PdId= "+storeId.pd_id);}); }; + if (keys == 'section2') { Object.assign(values, { pd_id: storeId.pd_id }); await FundRequirement.create( values ).then((successData)=>{logMsg.info("FundRequirement insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FundRequirement insert failed ,PdId= "+storeId.pd_id+" Error = "+err); }); }; + if (keys == 'section3') { Object.assign(values, { pd_id: storeId.pd_id }); await DetailsOfKeyShareHolder.create( values).then((successData)=>{logMsg.info("DetailsOfKeyShareHolder insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("DetailsOfKeyShareHolder insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); }; + if (keys == 'section4') { Object.assign(values, { pd_id: storeId.pd_id }); await BriefOfBusiness.create( values).then((successData)=>{logMsg.info("BreifOfBusiness insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("BreifOfBusiness insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); }; if (keys == 'section5') { Object.assign(values, { pd_id: storeId.pd_id }); Object.assign(values, values[0]); - await FinancialInformation.create( values).then((successData)=>{logMsg.info("FinancialInformation insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FinancialInformation insert failed ,PdId= "+storeId.pd_id);}); }; - if (keys == 'section6') { Object.assign(values, { pd_id: storeId.pd_id }); await PropertyInformation.create( values).then((successData)=>{logMsg.info("PropertyInformation insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("PropertyInformation insert failed ,PdId= "+storeId.pd_id);}); }; - if (keys == 'section7') { Object.assign(values, { pd_id: storeId.pd_id }); await FinalRemarks.create( values).then((successData)=>{logMsg.info("FinalRemarks insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FinalRemarks insert failed ,PdId= "+storeId.pd_id);}); }; - if (keys == 'section8') { Object.assign(values, { pd_id: storeId.pd_id }); await OfficerDetails.create( values).then((successData)=>{logMsg.info("OfficerDetails insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("OfficerDetails insert failed ,PdId= "+storeId.pd_id);}); }; + net_profit_net_loss_to_sales = parseFloat(((values.net_profit / values.sales_revenue) * 100)).toFixed(2); + income_considered_per_month = parseFloat((values.income_considered / 12)).toFixed(2); + sales_over_py = parseFloat((((values.sales_revenue - pre_year_sales) / pre_year_sales ) * 100)).toFixed(2); + net_profit_over_py = parseFloat((((values.net_profit - pre_year_net_profit) / pre_year_net_profit ) * 100)).toFixed(2); + net_profit_percentage_over_py = parseFloat(((( ((values.net_profit / values.sales_revenue ) * 100 ) - pre_year_net_pro_loss_per) / pre_year_net_pro_loss_per ) * 100)).toFixed(2); + // assign all calculated values + if(sales_over_py == "Infinity"){sales_over_py=null;}if(net_profit_over_py == "Infinity"){net_profit_over_py=null;}if(net_profit_percentage_over_py == "Infinity"){net_profit_percentage_over_py=null;} + Object.assign(values,{net_profit_net_loss_to_sales:net_profit_net_loss_to_sales , income_considered_per_month:income_considered_per_month , sales_over_py:sales_over_py , net_profit_over_py:net_profit_over_py , net_profit_percentage_over_py:net_profit_percentage_over_py}); + await FinancialInformation.create( values).then((successData)=>{logMsg.info("FinancialInformation insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FinancialInformation insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); + pre_year_sales = values.sales_revenue; + pre_year_net_profit = values.net_profit; + pre_year_net_pro_loss_per = ((values.net_profit / values.sales_revenue ) * 100 ); + + }; + if (keys == 'section6') { Object.assign(values, { pd_id: storeId.pd_id }); await PropertyInformation.create( values).then((successData)=>{logMsg.info("PropertyInformation insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("PropertyInformation insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); }; + if (keys == 'section7') { Object.assign(values, { pd_id: storeId.pd_id }); await FinalRemarks.create( values).then((successData)=>{logMsg.info("FinalRemarks insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FinalRemarks insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); }; + if (keys == 'section8') { Object.assign(values, { pd_id: storeId.pd_id }); await OfficerDetails.create( values).then((successData)=>{logMsg.info("OfficerDetails insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("OfficerDetails insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); }; // if (keys == 'section10') { Object.assign(values, { pd_id: storeId.pd_id }); await InstitutionDetail.create( values).then((successData)=>{logMsg.info("InstitutionDetail insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("InstitutionDetail insert failed ,PdId= "+storeId.pd_id);}); }; // if (keys == 'section11') { Object.assign(values, { pd_id: storeId.pd_id }); await ProductInformation.create( values).then((successData)=>{logMsg.info("ProductInformation insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("ProductInformation insert failed ,PdId= "+storeId.pd_id);}); }; }); @@ -51,18 +67,30 @@ exports.PullSalesPdData = async (req, res) => .then((successData)=>{logMsg.info("GeneralSection insert success ,PdId= "+successData.dataValues.pd_id);}) .catch((err)=>{ logMsg.info("GeneralSection insert failed ,PdId(ref_no)= "+req.body.pdid); }); - storeId = await GeneralSection.findOne({ where : { ref_no : req.body.pdid , is_active : 1 }}); + storeId = await GeneralSection.findOne({ where : { ref_no : req.body.pdid ,case_no :req.body.caseno, is_active : 1 }}); }; - if (keys == 'section2') { Object.assign(values, { pd_id: storeId.pd_id }); await FundRequirement.create( values ).then((successData)=>{logMsg.info("FundRequirement insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FundRequirement insert failed ,PdId= "+storeId.pd_id);}); }; - if (keys == 'section3') { Object.assign(values, { pd_id: storeId.pd_id }); await DetailsOfKeyShareHolder.create( values).then((successData)=>{logMsg.info("DetailsOfKeyShareHolder insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("DetailsOfKeyShareHolder insert failed ,PdId= "+storeId.pd_id);}); }; - if (keys == 'section4') { Object.assign(values, { pd_id: storeId.pd_id }); await BriefOfBusiness.create( values).then((successData)=>{logMsg.info("BreifOfBusiness insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("BreifOfBusiness insert failed ,PdId= "+storeId.pd_id);}); }; + if (keys == 'section2') { Object.assign(values, { pd_id: storeId.pd_id }); await FundRequirement.create( values ).then((successData)=>{logMsg.info("FundRequirement insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FundRequirement insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); }; + if (keys == 'section3') { Object.assign(values, { pd_id: storeId.pd_id }); await DetailsOfKeyShareHolder.create( values).then((successData)=>{logMsg.info("DetailsOfKeyShareHolder insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("DetailsOfKeyShareHolder insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); }; + if (keys == 'section4') { Object.assign(values, { pd_id: storeId.pd_id }); await BriefOfBusiness.create( values).then((successData)=>{logMsg.info("BreifOfBusiness insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("BreifOfBusiness insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); }; if (keys == 'section5') { - Object.assign(values, { pd_id: storeId.pd_id }); - Object.assign(values, values[0]); - await FinancialInformation.create( values).then((successData)=>{logMsg.info("FinancialInformation insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FinancialInformation insert failed ,PdId= "+storeId.pd_id);}); }; - if (keys == 'section6') { Object.assign(values, { pd_id: storeId.pd_id }); await PropertyInformation.create( values).then((successData)=>{logMsg.info("PropertyInformation insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("PropertyInformation insert failed ,PdId= "+storeId.pd_id);}); }; - if (keys == 'section7') { Object.assign(values, { pd_id: storeId.pd_id }); await FinalRemarks.create( values).then((successData)=>{logMsg.info("FinalRemarks insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FinalRemarks insert failed ,PdId= "+storeId.pd_id);}); }; - if (keys == 'section8') { Object.assign(values, { pd_id: storeId.pd_id }); await OfficerDetails.create( values).then((successData)=>{logMsg.info("OfficerDetails insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("OfficerDetails insert failed ,PdId= "+storeId.pd_id);}); }; + pre_year_sales = 0; + pre_year_net_profit = 0; + pre_year_net_pro_loss_per = 0; + Object.assign(values, { pd_id: storeId.pd_id }); + Object.assign(values, values[0]); + net_profit_net_loss_to_sales = parseFloat(((values.net_profit / values.sales_revenue) * 100)).toFixed(2); + income_considered_per_month = parseFloat((values.income_considered / 12)).toFixed(2); + sales_over_py = parseFloat((((values.sales_revenue - pre_year_sales) / pre_year_sales ) * 100)).toFixed(2); + net_profit_over_py = parseFloat((((values.net_profit - pre_year_net_profit) / pre_year_net_profit ) * 100)).toFixed(2); + net_profit_percentage_over_py = parseFloat(((( ((values.net_profit / values.sales_revenue ) * 100 ) - pre_year_net_pro_loss_per) / pre_year_net_pro_loss_per ) * 100)).toFixed(2); + // assign all calculated values + if(sales_over_py == "Infinity"){sales_over_py=null;}if(net_profit_over_py == "Infinity"){net_profit_over_py=null;}if(net_profit_percentage_over_py == "Infinity"){net_profit_percentage_over_py=null;} + Object.assign(values,{net_profit_net_loss_to_sales:net_profit_net_loss_to_sales , income_considered_per_month:income_considered_per_month , sales_over_py:sales_over_py , net_profit_over_py:net_profit_over_py , net_profit_percentage_over_py:net_profit_percentage_over_py}); + await FinancialInformation.create( values).then((successData)=>{logMsg.info("FinancialInformation insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FinancialInformation insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); + } + if (keys == 'section6') { Object.assign(values, { pd_id: storeId.pd_id }); await PropertyInformation.create( values).then((successData)=>{logMsg.info("PropertyInformation insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("PropertyInformation insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); }; + if (keys == 'section7') { Object.assign(values, { pd_id: storeId.pd_id }); await FinalRemarks.create( values).then((successData)=>{logMsg.info("FinalRemarks insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("FinalRemarks insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); }; + if (keys == 'section8') { Object.assign(values, { pd_id: storeId.pd_id }); await OfficerDetails.create( values).then((successData)=>{logMsg.info("OfficerDetails insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("OfficerDetails insert failed ,PdId= "+storeId.pd_id+" Error = "+err);}); }; // if (keys == 'section10') { Object.assign(values, { pd_id: storeId.pd_id }); await InstitutionDetail.create( values).then((successData)=>{logMsg.info("InstitutionDetail insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("InstitutionDetail insert failed ,PdId= "+storeId.pd_id);}); }; // if (keys == 'section11') { Object.assign(values, { pd_id: storeId.pd_id }); await ProductInformation.create( values).then((successData)=>{logMsg.info("ProductInformation insert success ,PdId= "+storeId.pd_id);}).catch((err)=>{ logMsg.info("ProductInformation insert failed ,PdId= "+storeId.pd_id);}); }; } @@ -87,14 +115,14 @@ exports.PullSalesPdPhotographsData = async (req, res) => { try { - GeneralSectionData = await GeneralSection.findOne({ where : { ref_no : req.body.pdid , is_active : 1 }}); + GeneralSectionData = await GeneralSection.findOne({ where : { ref_no : req.body.pdid ,case_no :req.body.caseno, is_active : 1 }}); PdId = GeneralSectionData.dataValues.pd_id; const Photographdata =req.body.data; for(const value of Photographdata) { - Object.assign(value, { pd_id: PdId }); + Object.assign(value, { pd_id: PdId , ref_no :req.body.pdid}); await Photograph.create( value) .then((successData)=>{logMsg.info("Photograph insert success ,PdId= "+PdId);}) .catch((err)=>{ logMsg.info("Photograph insert failed ,PdId= "+PdId);}); @@ -191,10 +219,10 @@ exports.SectionList = async (req, res) => { applicantDetails = await ApiCallHelper.MainApplicantDetails(req.query.losid); MainApplicantDetails = JSON.parse(applicantDetails); - + if(MainApplicantDetails.status == 200) { - GeneralSection.findAll({ where:{losid:req.query.losid,main_loan_applicant:MainApplicantDetails.data.name,is_active : 1}, + GeneralSection.findAll({ where:{main_loan_applicant:MainApplicantDetails.data.name,is_active : 1}, include: [ {model: FundRequirement }, {model: DetailsOfKeyShareHolder }, {model: FinancialInformation }, {model: FinalRemarks }, {model: BriefOfBusiness }, {model: PropertyInformation }, {model: OfficerDetails }, {model: Photograph }] }) .then(data => { diff --git a/app/models/BreifOfBusiness.js b/app/models/BriefOfBusiness.js similarity index 100% rename from app/models/BreifOfBusiness.js rename to app/models/BriefOfBusiness.js diff --git a/app/models/FinancialInformation.js b/app/models/FinancialInformation.js index a1a55a6..386857e 100644 --- a/app/models/FinancialInformation.js +++ b/app/models/FinancialInformation.js @@ -14,6 +14,12 @@ module.exports = (sequelize, DataTypes) => { income_assessment_program_recommended: { type: DataTypes.STRING }, fixed_obligations: { type: DataTypes.INTEGER }, equipment_contribution_turnover: { type: DataTypes.STRING }, + net_profit_net_loss_to_sales : { type: DataTypes.INTEGER }, + income_considered_per_month : { type: DataTypes.INTEGER }, + sales_over_py : { type: DataTypes.INTEGER }, + net_profit_over_py : { type: DataTypes.INTEGER }, + net_profit_percentage_over_py : { type: DataTypes.INTEGER }, + createdby: { type: DataTypes.INTEGER }, updatedby: { type: DataTypes.INTEGER }