diff --git a/app/controllers/salespd.controller.js b/app/controllers/salespd.controller.js index 66e2f7d..8808718 100644 --- a/app/controllers/salespd.controller.js +++ b/app/controllers/salespd.controller.js @@ -1,6 +1,7 @@ -const { sequelize, GeneralSection , BreifOfBusiness , DetailsOfKeyShareHolder , FinalRemarks , FinancialInformation , FundRequirement , InstitutionDetail , OfficerDetails , Photograph , ProductInformation , PropertyInformation} = require('../models') +const { sequelize, GeneralSection , BriefOfBusiness , DetailsOfKeyShareHolder , FinalRemarks , FinancialInformation , FundRequirement , InstitutionDetail , OfficerDetails , Photograph , ProductInformation , PropertyInformation} = require('../models') const { logMsg } = require('../services/logger.js'); const ApiCallHelper = require('../services/apicallhelper.js'); +const request = require('request'); @@ -8,24 +9,181 @@ exports.PullSalesPdData = async (req, res) => { try { - res.send({'status':200,'message':"success",'data':data}); + + const tempData =JSON.parse(JSON.stringify(req.body.data)); + + var count = 0; + var generalSectionData = [ ]; + var storeId = [ ]; + const len = Object.keys(tempData).length - 1; + for (const [keys, values] of Object.entries(tempData)) { + count++; + console.log(values); + if (Array.isArray(values) == true ) + { + 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 }}); + }; + 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 == '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);}); }; + // 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);}); }; + }); + } + else + { + 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 }}); + }; + 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 == '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);}); }; + // 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);}); }; + } + if (len == count - 1 ) + { + setTimeout(() => { + res.send({'status':200,'message':"success",'data':"No Data"}); + }, 1000); + + } + } + } catch(err) { res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" }); } //end of try catch }; + + exports.PullSalesPdPhotographsData = async (req, res) => { try { - res.send({'status':200,'message':"success",'data':data}); + GeneralSectionData = await GeneralSection.findOne({ where : { ref_no : req.body.pdid , is_active : 1 }}); + PdId = GeneralSectionData.dataValues.pd_id; + + const Photographdata =req.body.data; + + for(const value of Photographdata) + { + Object.assign(value, { pd_id: PdId }); + await Photograph.create( value) + .then((successData)=>{logMsg.info("Photograph insert success ,PdId= "+PdId);}) + .catch((err)=>{ logMsg.info("Photograph insert failed ,PdId= "+PdId);}); + }; + setTimeout(() => { + res.send({'status':200,'message':"success",'data':"No data"}); + }, 1000); + } catch(err) { res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" }); } //end of try catch }; + +exports.DownloadPdReport = async (req, res) => +{ + try + { + pd_id = req.query.ref_no; + DownloadPdReportUrl = process.env.PD_REPORT_URL; + url = DownloadPdReportUrl+"getSalesPDReportforCETApp?sales_pd_id="+pd_id; + + + request({ + url: url, + method: "GET" + + }, function (error, response, body) { console.log(body); + if (body != undefined) { + data = JSON.parse(body); + if ( data.status == 200) { + + link = data.records; + res.send({'status':200,'message':"success",'data':link}); + }else{ + res.send({'status':404,'message':"failed",'data':"No data"}); + } + } + }); + + + + } catch(err) { + res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" }); + } //end of try catch + +}; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + //GeneralSection data List Api exports.SectionList = async (req, res) => { @@ -37,7 +195,7 @@ exports.SectionList = async (req, res) => if(MainApplicantDetails.status == 200) { GeneralSection.findAll({ where:{losid:req.query.losid,main_loan_applicant:MainApplicantDetails.data.name,is_active : 1}, - include: [ {model: FundRequirement }, {model: DetailsOfKeyShareHolder }, {model: FinancialInformation }, {model: FinalRemarks }, {model: BreifOfBusiness }, {model: PropertyInformation }, {model: OfficerDetails }, {model: Photograph }, {model: InstitutionDetail }, {model: ProductInformation }] }) + include: [ {model: FundRequirement }, {model: DetailsOfKeyShareHolder }, {model: FinancialInformation }, {model: FinalRemarks }, {model: BriefOfBusiness }, {model: PropertyInformation }, {model: OfficerDetails }, {model: Photograph }] }) .then(data => { section_name_obj = { @@ -47,8 +205,8 @@ exports.SectionList = async (req, res) => section2_name : "Fund Requirements", section3_key : "DetailsOfKeyShareHolders", section3_name : "Details Of Key Share Holders", - section4_key : "BreifOfBusinesses", - section4_name : "Breif Of Businesses", + section4_key : "BriefOfBusinesses", + section4_name : "Brief Of Businesses", section5_key : "FinancialInformations", section5_name : "Financial Informations", section6_key : "PropertyInformations", @@ -59,10 +217,10 @@ exports.SectionList = async (req, res) => section8_name : "Officer Details", section9_key : "Photographs", section9_name : "Photographs", - section10_key : "InstitutionDetails", - section10_name : "Institution Details", - section11_key : "ProductInformations", - section11_name : "Product Informations", + // section10_key : "InstitutionDetails", + // section10_name : "Institution Details", + // section11_key : "ProductInformations", + // section11_name : "Product Informations", }; if(data.length > 0) @@ -92,6 +250,37 @@ exports.SectionList = async (req, res) => }; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + //BreifOfBusiness data List Api exports.BreifOfBusinessList = async (req, res) => { diff --git a/app/models/BreifOfBusiness.js b/app/models/BreifOfBusiness.js index ba5f06b..7277a67 100644 --- a/app/models/BreifOfBusiness.js +++ b/app/models/BreifOfBusiness.js @@ -1,10 +1,10 @@ 'use strict' const { Model } = require('sequelize') module.exports = (sequelize, DataTypes) => { - class BreifOfBusiness extends Model { + class BriefOfBusiness extends Model { } - BreifOfBusiness.init( + BriefOfBusiness.init( { pd_id: { type: DataTypes.INTEGER }, nature_of_business : { type: DataTypes.STRING }, @@ -18,9 +18,9 @@ module.exports = (sequelize, DataTypes) => { { sequelize, tableName: 'sales_brief_of_the_business_or_service', - modelName: 'BreifOfBusiness', + modelName: 'BriefOfBusiness', } ) - return BreifOfBusiness + return BriefOfBusiness } \ No newline at end of file diff --git a/app/models/GeneralSection.js b/app/models/GeneralSection.js index 4700682..67cd458 100644 --- a/app/models/GeneralSection.js +++ b/app/models/GeneralSection.js @@ -13,6 +13,8 @@ module.exports = (sequelize, DataTypes) => { primaryKey: true }, ref_no: { type: DataTypes.INTEGER }, + product: { type: DataTypes.STRING }, + case_no: { type: DataTypes.STRING }, losid: { type: DataTypes.STRING }, application_id: { type: DataTypes.STRING }, main_loan_applicant: { type: DataTypes.STRING }, @@ -52,7 +54,7 @@ module.exports = (sequelize, DataTypes) => { foreignKey: 'pd_id', sourceKey : 'pd_id' }); - GeneralSection.hasMany(models.BreifOfBusiness, { + GeneralSection.hasMany(models.BriefOfBusiness, { foreignKey: 'pd_id', sourceKey : 'pd_id' }); diff --git a/app/routes/routes.js b/app/routes/routes.js index 5942da7..d1f3139 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -22,7 +22,7 @@ module.exports = app => { router.get("/demo", Mycontroller.Welcome); - router.get('/salespd',Mycontroller.SalesPd) + /** @@ -39,6 +39,10 @@ module.exports = app => { * type: string * description: product * example: LFMP +* caseno: +* type: string +* description: +* example: MW53315 * data: * type: string * description: json string @@ -99,6 +103,27 @@ module.exports = app => { * description: failed */ router.post("/PullSalesPdPhotographsData", SalesPdController.PullSalesPdPhotographsData); + +/** +* @swagger +* /api/DownloadPdReport: +* get: +* summary: Download Pd Report as pdf file +* description: Download Pd Report as pdf file +* parameters: +* - in: query +* name: ref_no +* schema: +* type: integer +* required: true +* example: 614 +* responses: +* 200: +* description: success +*/ +router.get("/DownloadPdReport", SalesPdController.DownloadPdReport); + + //GeneralSection List Api /** * @swagger