437 lines
14 KiB
JavaScript
437 lines
14 KiB
JavaScript
const { sequelize,Test,ObligationMaster,ObligationBankStatement,EmiTracking,RepaymentTrackRecordMaster,RepaymentDropdownMaster,RepaymentTrackRecord} = require('../models')
|
|
const { logMsg } = require('../services/logger.js');
|
|
var swaggerSpecToPdf = require("swagger-spec-to-pdf");
|
|
const { Console } = require('winston/lib/winston/transports');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
|
|
// get all Obligation master data
|
|
exports.ObligationMaster = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
await ObligationMaster.findAll({where : {is_active : 1} })
|
|
.then(data =>
|
|
{
|
|
res.send({'status':200,'message':"success",'data':data});
|
|
logMsg.info("Master Data List api call Success");
|
|
})
|
|
.catch(err => {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while fetching Obligation masterdata." ,'data': "No data" });
|
|
});
|
|
} catch(err) {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while fetching Obligation masterdata masterdata." ,'data': "No data"
|
|
});
|
|
} //end of try catch
|
|
|
|
};
|
|
|
|
// get all Obligation bank statement
|
|
exports.GetObligationBankStatement = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
ObligationBankStatement.findAll({where : {los_id : req.query.los_id , is_active : 1},order: [['item_order', 'ASC']] })
|
|
.then(data =>
|
|
{
|
|
res.send({'status':200,'message':"success",'data':data});
|
|
logMsg.info("Master Data List api call Success");
|
|
})
|
|
.catch(err => {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while fetching Obligation bank statement." ,'data': "No data" });
|
|
});
|
|
|
|
} catch(err) {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while fetching Obligation masterdata bank statement." ,'data': "No data"
|
|
});
|
|
} //end of try catch
|
|
|
|
};
|
|
|
|
// create new Obligation master
|
|
exports.CreateObligationMaster = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
await ObligationMaster.create(req.body)
|
|
.then(data =>
|
|
{
|
|
res.send({'status':200,'message':"success",'data': data});
|
|
})
|
|
.catch(err => {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while create Obligation masterdata." ,'data': "No data" });
|
|
});
|
|
|
|
} catch(err) {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while create Obligation masterdata." ,'data': "No data"
|
|
});
|
|
} //end of try catch
|
|
};
|
|
|
|
// create new Obligation bank statement
|
|
exports.CreateObligationBankStatement = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
await ObligationBankStatement.create(req.body)
|
|
.then(data =>
|
|
{
|
|
res.send({'status':200,'message':"success",'data': data});
|
|
})
|
|
.catch(err => {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while create Obligation Burear BankStatement masterdata." ,'data': "No data" });
|
|
});
|
|
|
|
}
|
|
catch(err) {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while create Obligation Burear BankStatement masterdata." ,'data': "No data"
|
|
});
|
|
} //end of try catch
|
|
};
|
|
|
|
// update Obligation Bank Statement
|
|
exports.UpdateObligationBankStatement = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
req.body.forEach( async (element , index ) =>
|
|
{
|
|
ObligationBankStatement.update( element , { where: { id: element.id }}).then(data =>
|
|
{
|
|
if (req.body.length - 1 == index)
|
|
{
|
|
res.send({'status':200,'message':"success",'data':data});
|
|
}
|
|
})
|
|
.catch(err => {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" });
|
|
});
|
|
})
|
|
} catch(err) {
|
|
res.send({'status':404,message: err.message || "Some error occurred while inserting statements." ,'data': "No data" });
|
|
} //end of try catch
|
|
|
|
}
|
|
|
|
|
|
|
|
// get all Obligation bank statement
|
|
exports.GetEmiTrackingMonth = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
await EmiTracking.findOne({where : {los_id : req.query.los_id , is_active : 1} })
|
|
.then(data =>
|
|
{
|
|
res.send({'status':200,'message':"success",'data':data});
|
|
logMsg.info("Obligation Emi Tracking Month List api call Success");
|
|
})
|
|
.catch(err => {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while fetching Obligation Emi Tracking Month." ,'data': "No data" });
|
|
});
|
|
|
|
} catch(err) {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while fetching Obligation Emi Tracking Month." ,'data': "No data"
|
|
});
|
|
} //end of try catch
|
|
|
|
};
|
|
|
|
|
|
// create new Obligation master
|
|
exports.CreateObligationEmiTrackingMonth = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
var dateStore = [ ]
|
|
var date = new Date(req.body.month_6);
|
|
for (let i = 0; i < 5; i++)
|
|
{
|
|
var a = date.setMonth(date.getMonth() - 1);
|
|
var b = date.toLocaleDateString("en-GB")
|
|
var yourdate = b.split("/").reverse().join("-");
|
|
dateStore.push(yourdate)
|
|
}
|
|
EmiTracking.create({los_id : req.body.los_id , month_1 : dateStore[4] , month_2 : dateStore[3] , month_3 : dateStore[2] ,month_4 : dateStore[1] , month_5 : dateStore[0] , month_6 : req.body.month_6 })
|
|
.then(data =>
|
|
{
|
|
res.send({'status':200,'message':"success",'data': data});
|
|
})
|
|
.catch(err => {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while create Obligation EmiTracking." ,'data': "No data" });
|
|
});
|
|
|
|
} catch(err) {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while create Obligation EmiTracking." ,'data': "No data"
|
|
});
|
|
} //end of try catch
|
|
};
|
|
|
|
|
|
// update EMi Tracking
|
|
exports.UpdateObligationEmiTracking = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
var dateArr = [ ];
|
|
var dateObj = { };
|
|
var mon_6_date = new Date(req.body.month_6);
|
|
for (let i = 0; i < 5; i++)
|
|
{
|
|
mon_6_date.setMonth(mon_6_date.getMonth() - 1);
|
|
get_local_date = mon_6_date.toLocaleDateString("en-GB");
|
|
get_all_dates = get_local_date.split("/").reverse().join("-");
|
|
dateArr.push(get_all_dates)
|
|
}
|
|
Object.assign(dateObj, { los_id : req.body.los_id, month_1: dateArr[4], month_2: dateArr[3], month_3: dateArr[2], month_4: dateArr[1], month_5: dateArr[0], month_6: req.body.month_6 })
|
|
EmiTracking.update(dateObj , {where: { id: req.body.id , is_active : 1 } })
|
|
.then(data =>
|
|
{
|
|
res.send({'status':200,'message':"success",'data':data});
|
|
})
|
|
.catch(err => {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while retrieving statements." ,'data': "No data" });
|
|
});
|
|
|
|
} catch(err) {
|
|
res.send({'status':404,message: err.message || "Some error occurred while inserting statements." ,'data': "No data" });
|
|
} //end of try catch
|
|
|
|
}
|
|
|
|
|
|
|
|
// get all Obligation repayment dropdown master data
|
|
exports.RepaymentTrackRecordMaster = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
await RepaymentTrackRecordMaster.findAll({where : { is_active : 1},
|
|
include : [ {model: RepaymentDropdownMaster }]
|
|
})
|
|
.then(data =>
|
|
{
|
|
res.send({'status':200,'message':"success",'data':data});
|
|
logMsg.info("Master Data List api call Success");
|
|
})
|
|
.catch(err => {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while fetching Repayment TrackRecord masterdata." ,'data': "No data" });
|
|
});
|
|
} catch(err) {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while fetching Repayment TrackRecord masterdata masterdata." ,'data': "No data"
|
|
});
|
|
} //end of try catch
|
|
|
|
};
|
|
|
|
// create new RepaymentTrackRecordMaster
|
|
exports.CreateRepaymentTrackRecordMaster = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
await RepaymentTrackRecord.create(req.body)
|
|
.then(data =>
|
|
{
|
|
res.send({'status':200,'message':"success",'data': data});
|
|
})
|
|
.catch(err => {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while create Obligation RepaymentTrackRecord." ,'data': "No data" });
|
|
});
|
|
|
|
} catch(err) {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while create Obligation RepaymentTrackRecord." ,'data': "No data"
|
|
});
|
|
} //end of try catch
|
|
};
|
|
|
|
|
|
// updat RepaymentTrackRecord
|
|
exports.UpdateRepaymentTrackRecord = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
req.body.forEach(async(element,index,array) => {
|
|
id = element.id;
|
|
delete element.id
|
|
RepaymentTrackRecord.update(element,{ where: { id: id }})
|
|
.then(data=>{
|
|
if (array.length - 1 == index )
|
|
{
|
|
res.send({'status':200,'message':"success",'data':data});
|
|
}
|
|
})
|
|
.catch(err=>{
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while create Obligation RepaymentTrackRecord." ,'data': "No data" });
|
|
})
|
|
});
|
|
|
|
} catch(err) {
|
|
res.send({'status':404,message: err.message || "Some error occurred while inserting statements." ,'data': "No data" });
|
|
} //end of try catch
|
|
|
|
}
|
|
|
|
|
|
// get all Obligation repayment track record data
|
|
exports.GetRepaymentTrackRecord = async (req, res) =>
|
|
{
|
|
try
|
|
{
|
|
await RepaymentTrackRecord.findAll({where : { los_id : req.query.los_id , is_active : 1}
|
|
})
|
|
.then(data =>
|
|
{
|
|
res.send({'status':200,'message':"success",'data':data});
|
|
logMsg.info("Master Data List api call Success");
|
|
})
|
|
.catch(err => {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while fetching Repayment TrackRecord data." ,'data': "No data" });
|
|
});
|
|
} catch(err) {
|
|
res.send({'status':404,
|
|
message: err.message || "Some error occurred while fetching Repayment TrackRecord masterdata data." ,'data': "No data"
|
|
});
|
|
} //end of try catch
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.readLogFileName = async (req , res) =>
|
|
{
|
|
try
|
|
{
|
|
folderName = req;
|
|
const logFilePath = 'storage/log';
|
|
|
|
const fileNames = fs.readdirSync(logFilePath);
|
|
// Remove the first element (0th index)
|
|
const [, ...data] = fileNames;
|
|
return data;
|
|
|
|
}
|
|
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.readLogFile = async (req , res) =>
|
|
{
|
|
try
|
|
{
|
|
folderName = req.body.folder;
|
|
fileName = req.body.file;
|
|
const logFilePath = 'storage/log/'+fileName;
|
|
|
|
fs.readFile(logFilePath, 'utf8', (err, data) => {
|
|
if (err) {
|
|
console.error(err);
|
|
res.status(500).send({'status':404,'message': err.message || "Error reading log file." ,'data': "No data"});
|
|
}
|
|
res.send({'status':200 , message:"Success." ,'data': data});
|
|
});
|
|
|
|
}
|
|
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.viewLandingPage = async (req , res) =>
|
|
{
|
|
try
|
|
{
|
|
moduleName = [ { "module":"OBLIGATION","folder":"smc_cet_obligation_backend"} ];
|
|
img = []
|
|
for(const [index,val] of moduleName.entries())
|
|
{
|
|
fileName = await this.readLogFileName(val.folder);
|
|
for (let i = 0; i < fileName.length; i++)
|
|
{
|
|
filePath = 'storage/log/'+fileName[i];
|
|
const logData = fs.readFileSync(filePath);
|
|
// Convert the file content to Base64
|
|
const base64Data = logData.toString('base64');
|
|
// Create Base64 URL from Base64 data
|
|
const base64Url = `data:application/octet-stream;base64,${encodeURIComponent(base64Data)}`;
|
|
img.push(base64Url)
|
|
}
|
|
moduleName[index] = await Object.assign(val,{'file':fileName , 'img':img});
|
|
};
|
|
res.render( 'module' , { 'data' : moduleName } ,function (err, html ) {
|
|
res.send(html)
|
|
})
|
|
}
|
|
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.deleteLogFile = async (req , res) =>
|
|
{
|
|
try
|
|
{
|
|
folderName = req.body.folder;
|
|
fileName = req.body.file;
|
|
|
|
// folderName = 'smc_cet_creditpd_backend';
|
|
// fileName = 'msg.log.2023-07-10';
|
|
const logFilePath = 'storage/log/'+fileName;
|
|
fs.unlink(logFilePath, (err) => {
|
|
if (err) {
|
|
console.error(`Error deleting file: ${err}`);
|
|
return;
|
|
}
|
|
|
|
console.log('File deleted successfully.');
|
|
res.send({'status':200 , message:"Success." ,'data': 'No data'});
|
|
});
|
|
|
|
}
|
|
catch(err)
|
|
{
|
|
res.status(500).send({'status':404,
|
|
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
|
});
|
|
} //end of try catch
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|