FEAT_IRBA_REPORTS_ADDED_SRINIVAS

This commit is contained in:
Srinivas-Saravanan 2025-01-23 18:57:16 +05:30
parent f99dd816d6
commit 560d4328a8
6 changed files with 555 additions and 4 deletions

View File

@ -482,3 +482,12 @@ $routes->get("getBackToEnrolledDetails", "EmployeeRestController::getBackToEnrol
// Ticketing System
// Ticketing System End's
//BDSReports
$routes->group("/bdsReport", ["filter" => "authMVC"], function ($routes) {
$routes->match( ['get', 'post'], 'irba_report','BDSReportController::irba_report');
$routes->get('insurer_wise_data/(:any)','BDSReportController::Insurer_wise_Data/$1');
$routes->get('bap_wise_data/(:any)','BDSReportController::Bap_Wise_Data/$1');
});

View File

@ -14,10 +14,16 @@ use App\Models\InsurerBranchModel;
use App\Models\PolicyTransactionModel;
use App\Models\PTCOShareDetailsModel;
use App\Models\COShareStmtDetailsModel;
use App\Models\PolicyTypeModel;
use CodeIgniter\API\ResponseTrait;
class BDSReportController extends BaseController
class BDSReportController extends AdminController
{
use ResponseTrait;
protected $myLogger;
protected $clientModel;
protected $clientPolicyModel;
@ -26,6 +32,7 @@ class BDSReportController extends BaseController
protected $policyTransactionModel;
protected $PTCOShareDetailsModel;
protected $coShareStmtDetailsModel;
protected $policyTypeModel;
public function __construct()
{
@ -38,13 +45,122 @@ class BDSReportController extends BaseController
$this->policyTransactionModel = new PolicyTransactionModel();
$this->PTCOShareDetailsModel = new PTCOShareDetailsModel();
$this->coShareStmtDetailsModel = new COShareStmtDetailsModel();
$this->policyTypeModel = new PolicyTypeModel();
}
public function index()
{
//
public function Insurer_wise_Data($insurerCategory,$fromDate,$toDate){
$fromDate = \DateTime::createFromFormat('d-m-Y', $fromDate)->format('Y-m-d');
$toDate = \DateTime::createFromFormat('d-m-Y', $toDate)->format('Y-m-d');
if($insurerCategory == 0 || $insurerCategory == 1){
$sql = "
select ins.id,ins.name as insurers,
COALESCE(SUM(CASE WHEN pt.action_type = 'inception' and pt.insurer_id = ins.id and ptp.policy_category = $insurerCategory THEN 1 ELSE 0 END), 0) AS Policies,
COALESCE(SUM(CASE WHEN stmt.co_share_id = pt_co.id and ptp.policy_category = $insurerCategory and pt_co.insurer_id = ins.id THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS Premium,
COALESCE(SUM(CASE WHEN stmt.co_share_id = pt_co.id and ptp.policy_category = $insurerCategory and pt_co.insurer_id = ins.id THEN stmt.reward + stmt.actual_bp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.actual_tp_brokerage_amt ELSE 0 END), 0) AS Revenue
from insurers ins
left join pt_co_share_details pt_co on ins.id = pt_co.insurer_id and pt_co.is_active = 1
left join co_share_stmt_details stmt on pt_co.id = stmt.co_share_id and stmt.is_active = 1
left join policy_transaction pt on pt_co.pt_id = pt.id and pt.is_active = 1 and pt.policy_issue_date >= $fromDate and pt.policy_issue_date <= $toDate
left join policy_type ptp on pt.policy_type_id = ptp.id and ptp.policy_category = $insurerCategory
where ins.is_active = 1 and (ptp.policy_category = $insurerCategory or ptp.policy_category is null)
group by ins.id
";
$data['insurer_wise_data'] = $this->insurerModel->query($sql)->getResultArray();
}else{
$data['message'] = 'Insurer Category Not Valid';
log_message('error',$data['message']);
return $data;
}
return view('bds_report_Insurer_wise_Data',$data);
}
public function Bap_Wise_Data($insurerCategory,$fromDate,$toDate){
$fromDate = \DateTime::createFromFormat('d-m-Y', $fromDate)->format('Y-m-d');
$toDate = \DateTime::createFromFormat('d-m-Y', $toDate)->format('Y-m-d');
if($insurerCategory == 0 || $insurerCategory == 1){
$sql = "
SELECT
pot.bap AS bap,
COALESCE(COUNT(DISTINCT pt.id), 0) AS Policies,
COALESCE(SUM(co.actual_bp_amt + co.actual_tep_amt + co.actual_tp_amt), 0) AS Premium,
COALESCE(SUM(co.reward + co.actual_bp_brokerage_amt + co.actual_tep_brokerage_amt + co.actual_tp_brokerage_amt), 0) AS Revenue
FROM policy_type AS pot
LEFT JOIN policy_transaction AS pt ON pot.id = pt.policy_type_id AND pt.is_active = 1 AND pt.action_type = 'inception' and pt.policy_issue_date >= $fromDate and pt.policy_issue_date <= $toDate
LEFT JOIN pt_co_share_details AS ptco ON pt.id = ptco.pt_id AND ptco.is_active = 1
LEFT JOIN co_share_stmt_details AS co ON ptco.id = co.co_share_id AND co.is_active = 1
WHERE pot.is_active = 1
AND pot.policy_category = $insurerCategory
GROUP BY pot.bap;
";
$data['bap_wise_data'] = $this->policyTypeModel->query($sql)->getResultArray();
}else{
$data['message'] = 'Insurer Category Not Valid';
log_message('error',$data['message']);
return $data;
}
return view('bds_report_bap_wise_data',$data);
}
public function irba_report(){
if ($this->request->getMethod()=='get'){
$default_start = new \DateTime();
$data['default_end'] = $default_start->format('d-m-Y');
$data['default_start'] = $default_start->modify('-90 days')->format('d-m-Y');
$data['categories'] = [
'Life' => 'life','Non Life'=>'nonLife'
];
$data['report_type'] = [
'Insurer'=> 'insurer',
'BAP' => 'bap',
'BAP-Client' => 'bapClient',
'BAP-Insurer' =>'bapInsurer',
'Client' =>'client'
];
return $this->loadLayout('irba_report',$data);
}else{
$fromDate = $this->request->getPost('fromDate');
$toDate = $this->request->getPost('toDate');
$category = $this->request->getPost('category');
$report_type = $this->request->getPost('report_type');
// log_message('error',json_encode($_POST));die();
if($report_type == 'insurer'){
$life = $category == 'life' ? 1:0;
$viewData = $this->Insurer_wise_Data($life,$fromDate,$toDate);
// Ensure $viewData is an array
if (!is_array($viewData)) {
$viewData = [];
}
$html = view('bds_report_Insurer_wise_Data', $viewData);
return $this->respond(['status'=>true, 'html'=>$html], 200);
}
else if($report_type == 'bap'){
$life = $category == 'life'?1:0;
$viewData = $this->Bap_wise_Data($life,$fromDate,$toDate);
// Ensure $viewData is an array
if (!is_array($viewData)) {
$viewData = [];
}
$html = view('bds_report_bap_wise_data', $viewData);
return $this->respond(['status'=>true, 'html'=>$html], 200);
}
}
}
// -----------------------------------------------------------------------------------------
}

View File

@ -0,0 +1,138 @@
<style>
.table th,
.table td {
padding: 8px;
}
table.dataTable tbody td {
padding: 4px 4px !important;
}
.col-12 {
max-width: 98% !important;
}
.dataTables_filter {
position: absolute;
}
.right-align-input {
text-align: right;
}
</style>
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row" style="padding-bottom: 10px;">
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">Employees</h4>
</div>
</div>
<div class="table-responsive">
<table id="scroll-horizontal-datatable" class="table w-100 nowrap">
<thead class="bg-light">
<tr>
<th>Insurer</th>
<th>Policies</th>
<th>Premium</th>
<th>Revenue</th>
</tr>
</thead>
<tbody>
<?php foreach($insurer_wise_data as $data): ?>
<tr>
<td><?= $data['insurers'] ?></td>
<td><?= $data['Policies'] ?></td>
<td><?= $data['Premium'] ?></td>
<td><?= $data['Revenue'] ?></td>
</tr>
<?php endforeach?>
</tbody>
<tfoot>
<tr>
<th>Total Amount</th>
<th></th>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
// Select the table and footer cells
const table = document.querySelector("#tickets-table");
const tbody = table.querySelector("tbody");
const footer = table.querySelector("tfoot tr");
let totalPolicies = 0;
let totalPremium = 0;
let totalRevenue = 0;
// Loop through each row in the table body and accumulate totals
tbody.querySelectorAll("tr").forEach(row => {
const policies = parseInt(row.cells[1].textContent) || 0;
const premium = parseFloat(row.cells[2].textContent.replace(/[^0-9.-]+/g, "")) || 0;
const revenue = parseFloat(row.cells[3].textContent.replace(/[^0-9.-]+/g, "")) || 0;
totalPolicies += policies;
totalPremium += premium;
totalRevenue += revenue;
});
// Append totals to the footer
footer.innerHTML = `
<th>Grand Total</th>
<th>${totalPolicies}</th>
<th>${totalPremium.toFixed(2)}</th>
<th>${totalRevenue.toFixed(2)}</th>
`;
});
</script>
<script>
$(document).ready(function() {
var ticketsTable = $('#scroll-horizontal-datatable');
if (ticketsTable.length) {
ticketsTable.DataTable({
scrollX: true,
dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'B>>" + // Filter left, buttons right
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>", // Pagination at the bottom, without page length selector
buttons: [
{
extend: 'csv',
text: 'CSV',
title: 'Policy-Tranction-BDS-List',
},
{
extend: 'excel',
text: 'Excel',
title: 'Policy-Tranction-BDS-List',
exportOptions: {
orthogonal: 'sort'
},
}
],
language: {
search: "_INPUT_",
searchPlaceholder: "Search..."
},
paging: true, // Enable pagination
pageLength: 10, // Set default number of rows per page (optional)
ordering: false,
});
} else {
console.error("Table atet found.");
}
});
</script>

View File

@ -0,0 +1,138 @@
<style>
.table th,
.table td {
padding: 8px;
}
table.dataTable tbody td {
padding: 4px 4px !important;
}
.col-12 {
max-width: 98% !important;
}
.dataTables_filter {
position: absolute;
}
.right-align-input {
text-align: right;
}
</style>
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row" style="padding-bottom: 10px;">
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">Employees</h4>
</div>
</div>
<div class="table-responsive">
<table id="scroll-horizontal-datatable" class="table w-100 nowrap"> <thead class="bg-light">
<tr>
<th>Insurer</th>
<th>Policies</th>
<th>Premium</th>
<th>Revenue</th>
</tr>
</thead>
<tbody>
<?php foreach($bap_wise_data as $data): ?>
<tr>
<td><?= $data['bap'] ?></td>
<td><?= $data['Policies'] ?></td>
<td><?= $data['Premium'] ?></td>
<td><?= $data['Revenue'] ?></td>
</tr>
<?php endforeach?>
</tbody>
<tfoot>
<tr>
<th>Total Amount</th>
<th></th>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
// Select the table and footer cells
const table = document.querySelector("#tickets-table");
const tbody = table.querySelector("tbody");
const footer = table.querySelector("tfoot tr");
let totalPolicies = 0;
let totalPremium = 0;
let totalRevenue = 0;
// Loop through each row in the table body and accumulate totals
tbody.querySelectorAll("tr").forEach(row => {
const policies = parseInt(row.cells[1].textContent) || 0;
const premium = parseFloat(row.cells[2].textContent.replace(/[^0-9.-]+/g, "")) || 0;
const revenue = parseFloat(row.cells[3].textContent.replace(/[^0-9.-]+/g, "")) || 0;
totalPolicies += policies;
totalPremium += premium;
totalRevenue += revenue;
});
// Append totals to the footer
footer.innerHTML = `
<th>Grand Total</th>
<th>${totalPolicies}</th>
<th>${totalPremium.toFixed(2)}</th>
<th>${totalRevenue.toFixed(2)}</th>
`;
});
</script>
<script>
$(document).ready(function() {
var ticketsTable = $('#scroll-horizontal-datatable');
if (ticketsTable.length) {
ticketsTable.DataTable({
scrollX: true,
dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'B>>" + // Filter left, buttons right
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>", // Pagination at the bottom, without page length selector
buttons: [
{
extend: 'csv',
text: 'CSV',
title: 'Policy-Tranction-BDS-List',
},
{
extend: 'excel',
text: 'Excel',
title: 'Policy-Tranction-BDS-List',
exportOptions: {
orthogonal: 'sort'
},
}
],
language: {
search: "_INPUT_",
searchPlaceholder: "Search..."
},
paging: true, // Enable pagination
pageLength: 10, // Set default number of rows per page (optional)
ordering: false,
});
} else {
console.error("Table atet found.");
}
});
</script>

147
app/Views/irba_report.php Normal file
View File

@ -0,0 +1,147 @@
<div class="row">
<div class="col-xl-12">
<div id="accordion" class="mb-3">
<div class="card mb-1">
<h5 class="m-1">
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne"
aria-expanded="true">
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
</a>
</h5>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
<!-- <div class="text-center"> -->
<div class="form-row">
<div class="form-group col-md-4" id="date_div">
<label>Date<span class="text-danger"></span></label>
<div id="reportrange" class="form-control" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%">
<i class="fa fa-calendar"></i>&nbsp;
<span></span> <i class="fa fa-caret-down"></i>
</div>
<input type="hidden" id="startDate" value=<?=$default_start?>>
<input type="hidden" id="endDate" value=<?= $default_end?>>
</div>
<div class="form-group col-md-4">
<label>Category<span class="text-danger"> *</span></label> <br />
<select name="category" class="form-control" id="category" required>
<option value="">Select</option>
<?php foreach ($categories as $category => $key) : ?>
<option value="<?=$key?>"><?= $category?></option>
<?php endforeach ?>
</select>
</div>
<div class="form-group col-md-4">
<label>Report Type<span class="text-danger"> *</span></label> <br />
<select class="form-control" id="report_type" required>
<option value="0">Select</option>
<?php foreach ($report_type as $reports => $key) : ?>
<option value="<?=$key?>"><?= $reports?></option>
<?php endforeach?>
</select>
</div>
</div>
<div class="row justify-content-end">
<div class="col-auto">
<a href="#" class="btn btn-primary waves-effect waves-light" id="get-report-page" onclick="fetchReportPage(event);">Submit</a>
</div>
</div>
<!-- </div> -->
</div>
</div>
</div>
</div>
</div>
</div>
<div id="report"></div>
<script>
$(function() {
var start = $('#startDate').val();
var end = $('#endDate').val();
var start = moment(start, 'DD/MM/YYYY');
var end = moment(end, 'DD/MM/YYYY');
function cb(start, end) {
$('#reportrange span').html(start.format('D-MM-YYYY') + ' - ' + end.format('D-MM-YYYY'));
$('#startDate').val(start.format('DD-MM-YYYY'));
$('#endDate').val(end.format('DD-MM-YYYY'));
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
}, cb);
cb(start, end);
});
</script>
<script>
$('#category').on('click', function(){
var choosed_option = $('#category').val();
if (choosed_option == 'life' ){
$("#report_type option[value='insurer']").show();
$("#report_type option[value='bap']").hide();
$("#report_type option[value='bapClient']").hide();
$("#report_type option[value='bapInsurer']").hide();
$("#report_type option[value='client']").show();
}else if (choosed_option == 'nonLife'){
$("#report_type option[value='insurer']").show();
$("#report_type option[value='bap']").show();
$("#report_type option[value='bapClient']").show();
$("#report_type option[value='bapInsurer']").show();
$("#report_type option[value='client']").hide();
}
})
function fetchReportPage(){
var fromDate = $('#startDate').val();
var toDate = $('#endDate').val();
var category = $('#category').val();
var report_type = $('#report_type').val();
var requestData = {
fromDate:fromDate,
toDate: toDate,
category: category,
report_type: report_type
};
console.log(typeof fromDate);
var url = '<?= base_url('/bdsReport/irba_report') ?>';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
if (response.status == true){
$('#report').html(response.html);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
toastr.error('An error occurred while fetching the report page.', 'ERROR');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
});
}
</script>

View File

@ -717,6 +717,9 @@
<li>
<a href="<?= base_url('/policy_tranction/report/report-outstanding-list') ?>">Outstanding</a>
</li>
<li>
<a href="<?= base_url('/bdsReport/irba_report') ?>">IRBA Reports</a>
</li>
<?php } ?>
</ul>