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

This commit is contained in:
suseendhiran17 2022-05-07 11:17:27 +05:30
commit 33741b6cee
5 changed files with 338 additions and 32 deletions

View File

@ -1,6 +1,186 @@
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');
exports.PullSalesPdData = async (req, res) =>
{
try
{
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
{
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
};
@ -15,32 +195,32 @@ 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 = {
section1_key : "GeneralSection" ,
section1_name : "General Section" ,
section2_key : "FundRequirement",
section2_name : "Fund Requirement",
section3_key : "DetailsOfKeyShareHolder",
section3_name : "Details Of Key ShareHolder",
section4_key : "BreifOfBusiness",
section4_name : "Breif Of Business",
section5_key : "FinancialInformation",
section5_name : "Financial Information",
section6_key : "PropertyInformation",
section6_name : "Property Information",
section2_key : "FundRequirements",
section2_name : "Fund Requirements",
section3_key : "DetailsOfKeyShareHolders",
section3_name : "Details Of Key Share Holders",
section4_key : "BriefOfBusinesses",
section4_name : "Brief Of Businesses",
section5_key : "FinancialInformations",
section5_name : "Financial Informations",
section6_key : "PropertyInformations",
section6_name : "Property Informations",
section7_key : "FinalRemarks",
section7_name : "Final Remarks",
section8_key : "OfficerDetails",
section8_name : "Officer Details",
section9_key : "Photograph",
section9_name : "Photograph",
section10_key : "InstitutionDetail",
section10_name : "Institution Detail",
section11_key : "ProductInformation",
section11_name : "Product Information",
section9_key : "Photographs",
section9_name : "Photographs",
// section10_key : "InstitutionDetails",
// section10_name : "Institution Details",
// section11_key : "ProductInformations",
// section11_name : "Product Informations",
};
if(data.length > 0)
@ -70,6 +250,37 @@ exports.SectionList = async (req, res) =>
};
//BreifOfBusiness data List Api
exports.BreifOfBusinessList = async (req, res) =>
{

View File

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

View File

@ -12,6 +12,9 @@ module.exports = (sequelize, DataTypes) => {
autoIncrement : true,
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 },
@ -51,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'
});

View File

@ -7,13 +7,9 @@ module.exports = (sequelize, DataTypes) => {
Photograph.init(
{
pd_id: { type: DataTypes.INTEGER },
selfie_with_person_met: { type: DataTypes.STRING },
hospital_building: { type: DataTypes.STRING },
approach_to_pd_location: { type: DataTypes.STRING },
name_board_seen: { type: DataTypes.STRING },
stock_image: { type: DataTypes.STRING },
workplace_interior_image: { type: DataTypes.STRING },
institute_interior: { type: DataTypes.STRING },
ref_no: { type: DataTypes.INTEGER },
img: { type: DataTypes.STRING },
img_name: { type: DataTypes.STRING },
createdby: { type: DataTypes.INTEGER },
updatedby: { type: DataTypes.INTEGER }

View File

@ -9,7 +9,6 @@ module.exports = app => {
/**
* @swagger
* /api/demo:
@ -23,9 +22,106 @@ module.exports = app => {
router.get("/demo", Mycontroller.Welcome);
router.get('/salespd',Mycontroller.SalesPd)
/**
* @swagger
* definitions:
* PullSalesPdData:
* type: object
* properties:
* pdid:
* type: integer
* description: pdid
* example: 6646
* product:
* type: string
* description: product
* example: LFMP
* caseno:
* type: string
* description:
* example: MW53315
* data:
* type: string
* description: json string
* example:
*/
/**
* @swagger
* /api/PullSalesPdData:
* post:
* summary: Pull SalesPd Data
* description: Pull SalesPd Data
* requestBody:
* content:
* application/json:
* schema:
* $ref: '#/definitions/PullSalesPdData'
* responses:
* 200:
* description: success
* 500:
* description: failed
*/
router.post("/PullSalesPdData", SalesPdController.PullSalesPdData);
/**
* @swagger
* definitions:
* PullSalesPdPhotographsData:
* type: object
* properties:
* pdid:
* type: integer
* description: pdid
* example: 6646
* product:
* type: string
* description: product
* example: LFMP
* data:
* type: string
* description: json string
* example:
*/
/**
* @swagger
* /api/PullSalesPdPhotographsData:
* post:
* summary: Pull SalesPd Photographs Data
* description: Pull SalesPd Photographs Data
* requestBody:
* content:
* application/json:
* schema:
* $ref: '#/definitions/PullSalesPdPhotographsData'
* responses:
* 200:
* description: success
* 500:
* 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