ConsolidatedApi:GWM

This commit is contained in:
sriramv 2022-07-15 18:11:14 +05:30
parent da155b4d1b
commit 84c9af774f
7 changed files with 175 additions and 24 deletions

View File

@ -25,9 +25,6 @@ exports.LandingPageDetailsList =async (req, res) =>
exports.ActiveAndClosedLoansDetailsList =async (req, res) =>
{
try
@ -77,7 +74,7 @@ exports.SanctionAmtAndReplaceOfDeptDetailsList =async (req, res) =>
});
var query = "Select a.id,a.facility_type,a.total_amt,a.total_count,a.open_total_amt,a.open_total_count,a.closed_total_amt,a.closed_total_count "+select_items+" FROM out_sanction_amt_and_replacement_of_debt_p a "+sub_query+" WHERE a.losid = '"+req.query.losid+"' and ref_no = '"+req.query.ref_no+"'";
var query = "Select a.id,a.losid,a.facility_type,a.total_amt,a.total_count,a.open_total_amt,a.open_total_count,a.closed_total_amt,a.closed_total_count "+select_items+" FROM out_sanction_amt_and_replacement_of_debt_p a "+sub_query+" WHERE a.losid = '"+req.query.losid+"' and ref_no = '"+req.query.ref_no+"' and output_type = 1";
sequelize.query(query).then(async(data) => {
SanctionData = {monthRange : monthRangeArray ,SanctionAmountData : data};
@ -123,7 +120,7 @@ exports.EnquirySummaryDetailsList =async (req, res) =>
});
var query = "Select a.id,a.facility_type,a.total_amt,a.total_count "+select_items+" FROM out_enquity_amount_p a "+sub_query+" WHERE a.losid = '"+req.query.losid+"' and ref_no = '"+req.query.ref_no+"'";
var query = "Select a.id,a.losid,a.facility_type,a.total_amt,a.total_count "+select_items+" FROM out_enquity_amount_p a "+sub_query+" WHERE a.losid = '"+req.query.losid+"' and ref_no = '"+req.query.ref_no+"' and output_type = 1";
sequelize.query(query).then(async(data) => {
EnquiryData = {monthRange : monthRangeArray ,EnquiryAmountData : data};
@ -169,15 +166,38 @@ exports.SummaryViewOfCreditFacilities =async (req, res) =>
// consolidated api's
exports.ConsolidatedActiveAndClosedLoansDetailsList =async (req, res) =>
{
try
{
LoanData = await OutputActiveAndClosedLoans.findAll({raw : true , where:{losid:req.query.losid}});
if(LoanData.length != 0)
//ActiveLoanData = await OutputActiveAndClosedLoans.findAll({raw : true ,attributes:[ sequelize.literal("STRING_AGG(consumer_name,',')") ],attributes: {exclude: ['id','ref_no','is_active','createdAt','createdby','updatedAt','updatedby']} , where:{losid:req.query.losid , DateClosed:null },group: ['grp_str','losid','account_type','ownership','reported_and_certified_date','opened_date','sanctioned_amount','current_balance','repayment_tenure','emi_amount','overdue_amount','status','current_dpd','highest_dpd_month_wise_bucket_or_count_0_to_6','highest_dpd_month_wise_bucket_or_count_07_to_12','highest_dpd_month_wise_bucket_or_count_13_to_24','highest_dpd_month_wise_bucket_or_count_25_to_36','DateClosed','consumer_name']});
ActiveLoanData = await sequelize.query("SELECT [losid],STRING_AGG(consumer_name, ',') as consumer_name, [account_type], [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed], [grp_str] FROM [out_active_and_closed_loans_details] AS [OutputActiveAndClosedLoans] WHERE [OutputActiveAndClosedLoans].[losid] = N'MW112233' AND [OutputActiveAndClosedLoans].[DateClosed] IS NULL GROUP BY [grp_str], [losid], [account_type], [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed]");
//ClosedLoanData = await OutputActiveAndClosedLoans.findAll({raw : true ,attributes:[ sequelize.literal("STRING_AGG(consumer_name,',')") ],attributes: {exclude: ['id','ref_no','is_active','createdAt','createdby','updatedAt','updatedby']}, where:{losid:req.query.losid , DateClosed:{ [Op.ne]: null} },group: ['grp_str','losid','account_type','ownership','reported_and_certified_date','opened_date','sanctioned_amount','current_balance','repayment_tenure','emi_amount','overdue_amount','status','current_dpd','highest_dpd_month_wise_bucket_or_count_0_to_6','highest_dpd_month_wise_bucket_or_count_07_to_12','highest_dpd_month_wise_bucket_or_count_13_to_24','highest_dpd_month_wise_bucket_or_count_25_to_36','DateClosed','consumer_name']});
ClosedLoanData = await sequelize.query("SELECT [losid],STRING_AGG(consumer_name, ',') as consumer_name, [account_type], [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed], [grp_str] FROM [out_active_and_closed_loans_details] AS [OutputActiveAndClosedLoans] WHERE [OutputActiveAndClosedLoans].[losid] = N'MW112233' AND [OutputActiveAndClosedLoans].[DateClosed] IS NOT NULL GROUP BY [grp_str], [losid], [account_type], [ownership], [reported_and_certified_date], [opened_date], [sanctioned_amount], [current_balance], [repayment_tenure], [emi_amount], [overdue_amount], [status], [current_dpd], [highest_dpd_month_wise_bucket_or_count_0_to_6], [highest_dpd_month_wise_bucket_or_count_07_to_12], [highest_dpd_month_wise_bucket_or_count_13_to_24], [highest_dpd_month_wise_bucket_or_count_25_to_36], [DateClosed]");
if(ActiveLoanData.length != 0 || ClosedLoanData.length != 0)
{
LoanData = {ActiveLoanData:ActiveLoanData[0] , ClosedLoanData:ClosedLoanData[0]}
res.send({'status':200 , message:"Success." ,'data': LoanData});
}
else{
@ -204,7 +224,7 @@ exports.ConsolidatedSanctionAmtAndReplaceOfDeptDetailsList =async (req, res) =>
var select_items = "";
var sub_query = "";
const words = ['','one','two','three','four', 'five','six','seven','eight','nine','ten'];
monthRangeArray = [];
monthRangeArray = [];
SanctionAmtData.OutSanctionAmt_Cs.forEach((value,index) => {
monthRange = value.dataValues.months_range;
monthRange_aliseName = monthRange.replace(/[->]/g , '_');
@ -212,24 +232,24 @@ exports.ConsolidatedSanctionAmtAndReplaceOfDeptDetailsList =async (req, res) =>
monthRangeArray.push(obj);
key_addition = index + 1;
alisename = words[key_addition];
select_items += ",SUM("+alisename+".amt) as amt_"+monthRange_aliseName+",SUM("+alisename+".count) as count_"+monthRange_aliseName+",SUM("+alisename+".opening_amt) as opening_amt_"+monthRange_aliseName+",SUM("+alisename+".opening_count) as opening_count_"+monthRange_aliseName+",SUM("+alisename+".closing_amt) as closing_amt_"+monthRange_aliseName+",SUM("+alisename+".closing_count) as closing_count_"+monthRange_aliseName+" ";
sub_query += " JOIN ( SELECT sanction_amt_id,months_range,amt,count,opening_amt,opening_count,closing_amt,closing_count FROM out_sanction_amt_and_replacement_of_debt_c where months_range= '"+monthRange+"' group by sanction_amt_id,months_range,amt,count,opening_amt,opening_count,closing_amt,closing_count) "+alisename+" ON a.id = "+alisename+".sanction_amt_id";
select_items += ","+alisename+".months_range as months_range_"+monthRange_aliseName+","+alisename+".amt as amt_"+monthRange_aliseName+","+alisename+".count as count_"+monthRange_aliseName+","+alisename+".opening_amt as opening_amt_"+monthRange_aliseName+","+alisename+".opening_count as opening_count_"+monthRange_aliseName+","+alisename+".closing_amt as closing_amt_"+monthRange_aliseName+","+alisename+".closing_count as closing_count_"+monthRange_aliseName+" ";
sub_query += " JOIN ( SELECT id,sanction_amt_id,months_range,amt,count,opening_amt,opening_count,closing_amt,closing_count FROM out_sanction_amt_and_replacement_of_debt_c where months_range= '"+monthRange+"') "+alisename+" ON a.id = "+alisename+".sanction_amt_id";
});
var query = "Select a.facility_type,SUM(a.total_amt) as total_amt,SUM(a.total_count) as total_count,SUM(a.open_total_amt) as open_total_amt,SUM(a.open_total_count) as open_total_count ,SUM(a.closed_total_amt) as closed_total_amt,SUM(a.closed_total_count) as closed_total_count "+select_items+" FROM out_sanction_amt_and_replacement_of_debt_p a "+sub_query+" WHERE a.losid = '"+req.query.losid+"' group by a.facility_type";
console.log(query);
var query = "Select a.id,a.losid,a.facility_type,a.total_amt,a.total_count,a.open_total_amt,a.open_total_count,a.closed_total_amt,a.closed_total_count "+select_items+" FROM out_sanction_amt_and_replacement_of_debt_p a "+sub_query+" WHERE a.losid = '"+req.query.losid+"' and output_type = 2";
sequelize.query(query).then(async(data) => {
SanctionData = {monthRange : monthRangeArray ,SanctionAmountData : data};
res.send({'status':200 , message:"Success." ,'data':SanctionData});
}).catch(err=>{ logMsg.info(err); res.send({'status':400 , message: "Failed" ,'data': "Nodata"}); })
}).catch(err=>{ res.send({'status':400 , message: "Failed" ,'data': "Nodata"}); })
}
else
{
res.send({'status':400 , message:"Failed." ,'data': "Nodata"});
}
} catch(err) {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
@ -258,13 +278,13 @@ exports.ConsolidatedEnquirySummaryDetailsList =async (req, res) =>
monthRangeArray.push(obj);
key_addition = index + 1;
alisename = words[key_addition];
select_items += ",SUM("+alisename+".amt) as amt_"+monthRange_aliseName+",SUM("+alisename+".count) as count_"+monthRange_aliseName+" ";
sub_query += " JOIN ( SELECT enquiry_amount_id,months_range,amt,count FROM out_enquiry_amount_c where months_range= '"+monthRange+"' group by enquiry_amount_id,months_range,amt,count) "+alisename+" ON a.id = "+alisename+".enquiry_amount_id";
select_items += ","+alisename+".months_range as months_range_"+monthRange_aliseName+","+alisename+".amt as amt_"+monthRange_aliseName+","+alisename+".count as count_"+monthRange_aliseName+" ";
sub_query += " JOIN ( SELECT id,enquiry_amount_id,months_range,amt,count FROM out_enquiry_amount_c where months_range= '"+monthRange+"') "+alisename+" ON a.id = "+alisename+".enquiry_amount_id";
});
var query = "Select a.facility_type,SUM(a.total_amt) as total_amt,SUM(a.total_count) as total_count "+select_items+" FROM out_enquity_amount_p a "+sub_query+" WHERE a.losid = '"+req.query.losid+"' group by a.facility_type ";
var query = "Select a.id,a.losid,a.facility_type,a.total_amt,a.total_count "+select_items+" FROM out_enquity_amount_p a "+sub_query+" WHERE a.losid = '"+req.query.losid+"' and output_type = 2";
sequelize.query(query).then(async(data) => {
EnquiryData = {monthRange : monthRangeArray ,EnquiryAmountData : data};
res.send({'status':200 , message:"Success." ,'data':EnquiryData});
@ -275,7 +295,7 @@ exports.ConsolidatedEnquirySummaryDetailsList =async (req, res) =>
res.send({'status':400 , message:"Failed." ,'data': "Nodata"});
}
} catch(err) {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
@ -289,7 +309,7 @@ exports.ConsolidatedSummaryViewOfCreditFacilities =async (req, res) =>
try
{
sequelize.query("select count(*) as total_accounts_count,count(case when overdue_amount > 0 then 1 else null end) as overdue_amount_count,count(case when current_balance = 0 then 1 else null end) as zero_balance_count,count(case when overdue_amount <= 0 then 1 else null end) as nill_overdue_amount_count,SUM(sanctioned_amount) as high_credit,SUM(current_balance) as sum_current_balance ,SUM(overdue_amount) as sum_overdue_amount ,MAX(opened_date) as latest_opened_date ,MIN(opened_date) as oldest_opened_date from out_active_and_closed_loans_details where losid = '"+req.query.losid+"' and is_active = 1 " ).then(async(data) => {
sequelize.query("select count(*) as count_total , count(case when f.overdue_amount > 0 then 1 else null end) as overdue_amount_count,count(case when f.current_balance = 0 then 1 else null end) as zero_balance_count,count(case when f.overdue_amount <= 0 then 1 else null end) as nill_overdue_amount_count,SUM(f.sanctioned_amount) as high_credit ,SUM(f.current_balance) as sum_current_balance ,SUM(f.overdue_amount) as sum_overdue_amount ,MAX(f.opened_date) as latest_opened_date ,MIN(f.opened_date) as oldest_opened_date from (select count(*) as total_accounts_count , sanctioned_amount , current_balance , overdue_amount , opened_date from out_active_and_closed_loans_details where losid = '"+req.query.losid+"' and is_active = 1 group by grp_str,sanctioned_amount,current_balance,overdue_amount,opened_date ) as f" ).then(async(data) => {
res.send({'status':200 , message:"Success." ,'data':data});
@ -312,6 +332,17 @@ exports.ConsolidatedSummaryViewOfCreditFacilities =async (req, res) =>
exports.EnquiryAmountSplitUp =async (req, res) =>
{
try

View File

@ -17,3 +17,91 @@ exports.Welcome = (req, res) =>
};
exports.ConsolidatedSanctionAmtAndReplaceOfDeptDetailsList =async (req, res) =>
{
try
{
SanctionAmtData = await OutSanctionAmt_P.findOne({where:{losid:req.query.losid} , include: [ {model: OutSanctionAmt_C , attributes: ["months_range"], group: "months_range" }]});
if(SanctionAmtData && SanctionAmtData.OutSanctionAmt_Cs.length != 0)
{
var select_items = "";
var sub_query = "";
const words = ['','one','two','three','four', 'five','six','seven','eight','nine','ten'];
monthRangeArray = [];
SanctionAmtData.OutSanctionAmt_Cs.forEach((value,index) => {
monthRange = value.dataValues.months_range;
monthRange_aliseName = monthRange.replace(/[->]/g , '_');
obj = { "key" : monthRange_aliseName , "name" : monthRange}
monthRangeArray.push(obj);
key_addition = index + 1;
alisename = words[key_addition];
select_items += ",SUM("+alisename+".amt) as amt_"+monthRange_aliseName+",SUM("+alisename+".count) as count_"+monthRange_aliseName+",SUM("+alisename+".opening_amt) as opening_amt_"+monthRange_aliseName+",SUM("+alisename+".opening_count) as opening_count_"+monthRange_aliseName+",SUM("+alisename+".closing_amt) as closing_amt_"+monthRange_aliseName+",SUM("+alisename+".closing_count) as closing_count_"+monthRange_aliseName+" ";
sub_query += " JOIN ( SELECT sanction_amt_id,months_range,amt,count,opening_amt,opening_count,closing_amt,closing_count FROM out_sanction_amt_and_replacement_of_debt_c where months_range= '"+monthRange+"' group by sanction_amt_id,months_range,amt,count,opening_amt,opening_count,closing_amt,closing_count) "+alisename+" ON a.id = "+alisename+".sanction_amt_id";
});
var query = "Select a.facility_type,SUM(a.total_amt) as total_amt,SUM(a.total_count) as total_count,SUM(a.open_total_amt) as open_total_amt,SUM(a.open_total_count) as open_total_count ,SUM(a.closed_total_amt) as closed_total_amt,SUM(a.closed_total_count) as closed_total_count "+select_items+" FROM out_sanction_amt_and_replacement_of_debt_p a "+sub_query+" WHERE a.losid = '"+req.query.losid+"' and output_type = 2 group by a.facility_type";
console.log(query);
sequelize.query(query).then(async(data) => {
SanctionData = {monthRange : monthRangeArray ,SanctionAmountData : data};
res.send({'status':200 , message:"Success." ,'data':SanctionData});
}).catch(err=>{ logMsg.info(err); res.send({'status':400 , message: "Failed" ,'data': "Nodata"}); })
}
else
{
res.send({'status':400 , message:"Failed." ,'data': "Nodata"});
}
} catch(err) {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
}); } //end of try catch
};
exports.ConsolidatedEnquirySummaryDetailsList =async (req, res) =>
{
try
{
EnquiryAmtData = await OutEnquiryAmountP.findOne({where:{losid:req.query.losid} , include: [ {model: OutEnquiryAmountC , attributes: ["months_range"], group: "months_range" }]});
if(EnquiryAmtData && EnquiryAmtData.OutEnquiryAmountCs.length != 0)
{
var select_items = "";
var sub_query = "";
const words = ['','one','two','three','four', 'five','six','seven','eight','nine','ten'];
monthRangeArray = [];
EnquiryAmtData.OutEnquiryAmountCs.forEach((value,index) => {
monthRange = value.dataValues.months_range;
monthRange_aliseName = monthRange.replace(/[->]/g , '_');
obj = { "key" : monthRange_aliseName , "name" : monthRange}
monthRangeArray.push(obj);
key_addition = index + 1;
alisename = words[key_addition];
select_items += ",SUM("+alisename+".amt) as amt_"+monthRange_aliseName+",SUM("+alisename+".count) as count_"+monthRange_aliseName+" ";
sub_query += " JOIN ( SELECT enquiry_amount_id,months_range,amt,count FROM out_enquiry_amount_c where months_range= '"+monthRange+"' group by enquiry_amount_id,months_range,amt,count) "+alisename+" ON a.id = "+alisename+".enquiry_amount_id";
});
var query = "Select a.facility_type,SUM(a.total_amt) as total_amt,SUM(a.total_count) as total_count "+select_items+" FROM out_enquity_amount_p a "+sub_query+" WHERE a.losid = '"+req.query.losid+"' and output_type = 2 group by a.facility_type ";
sequelize.query(query).then(async(data) => {
EnquiryData = {monthRange : monthRangeArray ,EnquiryAmountData : data};
res.send({'status':200 , message:"Success." ,'data':EnquiryData});
}).catch(err=>{ res.send({'status':400 , message: "Failed" ,'data': "Nodata"}); })
}
else
{
res.send({'status':400 , message:"Failed." ,'data': "Nodata"});
}
} catch(err) {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
}); } //end of try catch
};

View File

@ -15,7 +15,8 @@ module.exports = (sequelize, DataTypes) => {
closed_total_amt : { type: DataTypes.INTEGER },
total_count : { type: DataTypes.INTEGER },
open_total_count : { type: DataTypes.INTEGER },
closed_total_count : { type: DataTypes.INTEGER },
closed_total_count : { type: DataTypes.INTEGER },
output_type :{type: DataTypes.INTEGER},
createdAt : { type: DataTypes.DATE },
createdby : { type: DataTypes.INTEGER },
updatedAt : { type: DataTypes.DATE },

View File

@ -26,6 +26,7 @@ module.exports = (sequelize, DataTypes) => {
highest_dpd_month_wise_bucket_or_count_13_to_24 : { type: DataTypes.STRING },
highest_dpd_month_wise_bucket_or_count_25_to_36 : { type: DataTypes.STRING },
DateClosed : {type: DataTypes.DATE},
grp_str : {type: DataTypes.STRING},
is_active : { type: DataTypes.INTEGER },
createdAt : { type: DataTypes.DATE },
createdby : { type: DataTypes.INTEGER },

View File

@ -11,7 +11,8 @@ module.exports = (sequelize, DataTypes) => {
ref_no : { type: DataTypes.STRING },
facility_type : { type: DataTypes.STRING },
total_amt : { type: DataTypes.INTEGER },
total_count : { type: DataTypes.INTEGER },
total_count : { type: DataTypes.INTEGER },
output_type :{type: DataTypes.INTEGER},
is_active : { type: DataTypes.INTEGER },
createdAt : { type: DataTypes.DATE },
createdby : { type: DataTypes.INTEGER },

View File

@ -156,12 +156,41 @@ function panListApiCall(losid) {
function getLoginToken() {
try {
const url = process.env.CIBIL_URL_TOKEN;
return new Promise((resolve, reject) => {
request({
url: url,
method: "GET"
}, function (error, response, body){
data = JSON.parse(body);
if(data.status === 200)
{
resolve(data.data.token);
}
else { resolve(false); }
})
});
}
catch (error) {
console.log(error);
}
}
module.exports = {
createSkeleton : createSkeleton ,
findBucketCount : findBucketCount,
cibilInputDataApiCall : cibilInputDataApiCall,
cibilOutputGenerateApiCall : cibilOutputGenerateApiCall,
panListApiCall : panListApiCall
panListApiCall : panListApiCall ,
getLoginToken : getLoginToken
}

View File

@ -991,7 +991,7 @@ function commercialDataInsert(data)
const Helper = require('../services/cibil.controller.helper.js');
const { InBorrowerDetail,InEnquiryDetail,InCreditFacility,InDpdTranscationTable} = require('../models')