From 928bc6117145c6813d92b88089ca4f1d85dee335 Mon Sep 17 00:00:00 2001 From: velz Date: Sat, 21 Dec 2024 18:13:09 +0530 Subject: [PATCH 1/3] CHNAGE_BDS_STMT_UPLOAD&OUTSTANDING --- app/Config/Routes.php | 3 + app/Controllers/EmployeeServiceController.php | 2 +- .../PolicyTransactionController.php | 111 ++++-- app/Models/COShareStmtDetailsModel.php | 38 ++ app/Models/InsurerStatements.php | 6 +- app/Models/InvPaymentDetailsModel.php | 1 + app/Models/PTCOShareDetailsModel.php | 14 +- app/Models/PolicyTransactionModel.php | 50 ++- app/Views/insurer_statement_list.php | 332 ++++++++++++++++-- app/Views/outstanding_report_list.php | 71 ++-- 10 files changed, 544 insertions(+), 84 deletions(-) create mode 100644 app/Models/COShareStmtDetailsModel.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6ad4f058..e02132a3 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -362,6 +362,8 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { $routes->get("deletePaymentEntry/(:any)", "PolicyTransactionController::deletePaymentEntry/$1"); $routes->get("downloadSampleInsurerStatement", "PolicyTransactionController::downloadSampleInsurerStatement"); $routes->get("getFileErr/(:any)", "PolicyTransactionController::getFileErr/$1"); + $routes->get("getInsurerStatementMonth", "PolicyTransactionController::getInsurerStatementMonth"); + $routes->get("deleteStatement/(:any)", "PolicyTransactionController::deleteStatement/$1"); }); }); @@ -375,6 +377,7 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) { $routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1"); $routes->get("featchLeadDataAndInsertClient/(:any)", "LeadsController::featchLeadDataAndInsertClient/$1"); $routes->get("featchClientPolicyFromLead/(:any)", "LeadsController::featchClientPolicyFromLead/$1"); + }); $routes->group("rfq", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index d5e6d6f7..f94d4f6e 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1328,7 +1328,7 @@ class EmployeeServiceController extends AdminController // } // dd($row[4]); //for emp table - $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']); + // $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']); // dd( $this->empEndorsementModel->getLastQuery()); // $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'change_event','old_value' => $data['change_event'],'new_value' => 'deletion','created_by' => $file['created_by'],'remarks' => 'general deletion']); diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 5e94b340..9d067f9d 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -31,6 +31,7 @@ use App\Models\InsurerStatements; use App\Models\InvPaymentDetailsModel; use App\Models\BatchFileModel; use App\Models\FileModel; +use App\Models\COShareStmtDetailsModel; use Kint; class PolicyTransactionController extends BaseController @@ -62,6 +63,7 @@ class PolicyTransactionController extends BaseController protected $invPaymentDetailsModel; protected $batchFileModel; protected $filesModel; + protected $coShareStmtDetailsModel; public function __construct() { @@ -91,11 +93,12 @@ class PolicyTransactionController extends BaseController $this->invPaymentDetailsModel = new InvPaymentDetailsModel(); $this->batchFileModel = new BatchFileModel(); $this->filesModel = new FileModel(); + $this->coShareStmtDetailsModel = new COShareStmtDetailsModel(); $this->invoiceStatus = [ 'pending' => 'Pending', 'generated' => 'Generated', 'sent' => 'Sent', - 'payment_received' => 'Payment Received', + 'payment_received' => 'Payment
Received', ]; } @@ -1531,20 +1534,17 @@ class PolicyTransactionController extends BaseController $end_date = $this->request->getGet('end_date'); $client_id = $this->request->getGet('client_id'); $insurer_id = $this->request->getGet('insurer_id'); - $policy_type_id = $this->request->getGet('policy_type_id'); - $date_type = $this->request->getGet('date_type'); - $issuer = $this->request->getGet('issuer'); + $insurer_branch_id = $this->request->getGet('insurer_branch_id'); - $start_date = (!isset($start_date) || $start_date === '' || $start_date === null) ? 0 : $start_date; - $end_date = (!isset($end_date) || $end_date === '' || $end_date === null) ? 0 : $end_date; + $start_date = (!isset($start_date) || $start_date === '' || $start_date === null) ? 0 : change_date_format($start_date,'d-m-Y','Y-m-01'); + $end_date = (!isset($end_date) || $end_date === '' || $end_date === null) ? 0 : change_date_format($end_date,'d-m-Y','Y-m-31'); + // dd([$start_date,$end_date]); - $client_id = (!isset($client_id) || $client_id === '' || $client_id === null) ? 0 : $client_id; $insurer_id = (!isset($insurer_id) || $insurer_id === '' || $insurer_id === null) ? 0 : $insurer_id; - $policy_type_id = (!isset($policy_type_id) || $policy_type_id === '' || $policy_type_id === null) ? 0 : $policy_type_id; - $date_type = (!isset($date_type) || $date_type === '' || $date_type === null) ? 0 : $date_type; - $issuer = (!isset($issuer) || $issuer === '' || $issuer === null) ? 0 : $issuer; + $insurer_branch_id = (!isset($insurer_branch_id) || $insurer_branch_id === '' || $insurer_branch_id === null) ? 0 : $insurer_branch_id; + - $data['outstanting_list'] = $this->policyTransactionModel->getOutstandingReportLIst($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer); + $data['outstanting_list'] = $this->policyTransactionModel->getOutstandingReportLIst($start_date, $end_date,$insurer_id, $insurer_branch_id); // dd($this->policyTransactionModel->getLastQuery()); // dd($data); $this->loadLayout('outstanding_report_list', $data); @@ -1556,7 +1556,7 @@ class PolicyTransactionController extends BaseController //insurer statement list page public function statementList() { - // dd($this->validateInsurerStatement(['file_id' => 30])); + // dd($this->updateInsurerStatement(['file_id' => 59])); // $data['insurers'] = $this->insurerModel->where('is_active',1)->findAll(); $today = date('Y-m-d'); $fromday = $from_date = date('Y-m-d', strtotime('-60 days', strtotime($today))); @@ -1576,7 +1576,7 @@ class PolicyTransactionController extends BaseController WHERE pt_co_share_details.is_active = 1 AND pt_co_share_details.statement_id = insurer_statements.id ) AS exp_inv_amt, - (SELECT SUM(inv_payment_details.inv_amt) + SUM(inv_payment_details.tds) + (SELECT SUM(inv_payment_details.inv_amt) + SUM(inv_payment_details.tds) + SUM(inv_payment_details.gst) FROM inv_payment_details WHERE inv_payment_details.is_active = 1 AND inv_payment_details.statement_id = insurer_statements.id @@ -1649,9 +1649,10 @@ class PolicyTransactionController extends BaseController $month = $month.'-01'; // print_r($month);die; $month = change_date_format($month,'Y-M-d','Y-m-d'); + $stmt_sno = $this->request->getPost('statement_no'); // print_r($month);die; - $file_id = $this->insurerStatements->insert(['insurer_id' => $insurer_id, 'branch_id' => $branch_id, 'file_name' => $filename,'month' => $month, 'created_by' => $loggedInUserID]); //here field policy_id have client_policy_id and not policy id from policy master + $file_id = $this->insurerStatements->insert(['insurer_id' => $insurer_id, 'branch_id' => $branch_id, 'file_name' => $filename,'month' => $month, 'created_by' => $loggedInUserID,'stmt_sno' => $stmt_sno]); //here field policy_id have client_policy_id and not policy id from policy master $this->myLogger->logme("error", '{file_id} statement uploaded success', ['file_id' => $file_id]); //validate file @@ -1739,11 +1740,11 @@ class PolicyTransactionController extends BaseController unset($excel_data[0]); // Kint::dump($excel_data); //get no of line items and update in DB - $line_items = count($excel_data); + $line_items = 0; // get uploaded month transactions data - $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(month:$month,year:$year,insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']); + $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']); // var_dump($source_data);die(); - // Kint::dump($source_data);//die(); + // print_rr($this->db->getLastQuery()->getQuery);die(); // check policy no,insurer and etc in DB for this month @@ -1765,7 +1766,9 @@ class PolicyTransactionController extends BaseController $source_endorsement_no = $source_row['endorsement_no'] !== null ? $source_row['endorsement_no'] : ""; if( ($policy_no == $source_row['policy_no']) && $endorsement_no == $source_endorsement_no && change_date_format($policy_start_date,'d-m-Y','Y-m-d') == $source_row['policy_start_date'] && change_date_format($policy_end_date,'d-m-Y','Y-m-d') == $source_row['policy_end_date'] && $client_name == $source_row['client_name']) { + $is_source_found = 1; + $line_items = $line_items + 1; unset($source_data[$source_key]); continue 2; } @@ -1842,7 +1845,7 @@ class PolicyTransactionController extends BaseController //get no of line items and update in DB $line_items = count($excel_data); // get uploaded month transactions data - $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(month:$month,year:$year,insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']); + $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']); // Kint::dump($source_data);die; // Kint::dump($excel_data); @@ -1934,7 +1937,7 @@ class PolicyTransactionController extends BaseController //find variance $variance_amt = $source_row['exp_amt'] - $total_amt; - $data_to_update[] = ['id' => $source_row['id'],'actual_bp_amt' => $actual_bp_amt,'actual_tp_amt' => $actual_tp_amt,'actual_tep_amt' => $actual_tep_amt,'actual_bp_per' => $actual_bp_per,'actual_tp_per' => $actual_tp_per,'actual_tep_per' => $actual_tep_per,'variance' => $variance_amt,'actual_tep_brokerage_amt' => $actual_tep_brokerage,'actual_tp_brokerage_amt' => $actual_tp_brokerage,'actual_bp_brokerage_amt' => $actual_bp_brokerage,'reward' => trim($excel_row[15]),'statement_id' => $file_id]; + $data_to_update[] = ['co_share_id' => $source_row['id'],'actual_bp_amt' => $actual_bp_amt,'actual_tp_amt' => $actual_tp_amt,'actual_tep_amt' => $actual_tep_amt,'actual_bp_per' => $actual_bp_per,'actual_tp_per' => $actual_tp_per,'actual_tep_per' => $actual_tep_per,'variance' => $variance_amt,'actual_tep_brokerage_amt' => $actual_tep_brokerage,'actual_tp_brokerage_amt' => $actual_tp_brokerage,'actual_bp_brokerage_amt' => $actual_bp_brokerage,'reward' => trim($excel_row[15]),'statement_id' => $file_id]; unset($source_data[$source_key]); continue 2; @@ -1944,7 +1947,7 @@ class PolicyTransactionController extends BaseController } } // dd($data_to_update); - $this->PTCOShareDetailsModel->updateBatch($data_to_update, 'id'); + $this->coShareStmtDetailsModel->insertBatch($data_to_update, 'id'); // dd($data_to_update); // if($error_data['error_code']) // { @@ -1966,8 +1969,25 @@ class PolicyTransactionController extends BaseController ->where('is_active',1) ->get() ->getResultArray(); + + if(!$inv_details['invoice_value']) + { + $stmt_level_value = $this->coShareStmtDetailsModel->select('sum(actual_tep_brokerage_amt) + sum(actual_tp_brokerage_amt) + sum(actual_bp_brokerage_amt) + sum(reward) as invoice_value') + ->where('statement_id',$statement_id) + ->groupBy('statement_id') + ->get() + ->getResultArray(); + // print_r($stmt_level_value); + if($stmt_level_value && count($stmt_level_value) && isset($stmt_level_value[0])) + { + $inv_details['invoice_value'] = $stmt_level_value[0]['invoice_value']; + } + } // ~dd($inv_details); $data = [ 'invoice_status' => $inv_details['invoice_status'], + 'gst_per' => $inv_details['gst_per'], + 'invoice_value' => $inv_details['invoice_value'], + 'gst_value' => $inv_details['gst_value'], 'invoice_no' => $inv_details['invoice_no'], 'invoice_amount' => $inv_details['invoice_amount'], 'invoice_date' => isset($inv_details['invoice_date']) ? change_date_format($inv_details['invoice_date'],'Y-m-d','d/m/Y') : null ]; @@ -1989,6 +2009,9 @@ class PolicyTransactionController extends BaseController $invoiceNo = $jsonData['invoice_no']; $invoiceDate = change_date_format($jsonData['invoice_date'],'d/m/Y','Y-m-d'); $invoice_amount = $jsonData['invoice_amount']; + $invoice_value = $jsonData['invoice_value']; + $gst_per = $jsonData['invoice_gst_per']; + $gst_value = $jsonData['invoice_gst']; //Update statement table $parentData = [ @@ -1996,6 +2019,9 @@ class PolicyTransactionController extends BaseController 'invoice_no' => $invoiceNo, 'invoice_date' => $invoiceDate, 'invoice_amount' => $invoice_amount, + 'gst_per' => $gst_per, + 'gst_value' => $gst_value, + 'invoice_value' => $invoice_value, 'updated_by' => get_session_userid() ]; @@ -2007,6 +2033,7 @@ class PolicyTransactionController extends BaseController $receivedAmounts = $jsonData['received_amount']; $utrNos = $jsonData['utr_no']; $tdsTotal = $jsonData['tds']; + $gstTotal = $jsonData['gst_amount']; $paymentDates = $jsonData['payment_date']; $pks = $jsonData['pk']; @@ -2014,6 +2041,7 @@ class PolicyTransactionController extends BaseController $pk = $pks[$index]; // Get the pk for the current record $utrNo = $utrNos[$index]; $tds = $tdsTotal[$index]; + $gst = $gstTotal[$index]; $paymentDate = $paymentDates[$index]; // Prepare data for insert/update @@ -2021,6 +2049,7 @@ class PolicyTransactionController extends BaseController 'inv_amt' => $receivedAmount, 'utr_no' => $utrNo, 'tds' => $tds, + 'gst' => $gst, 'received_date' => change_date_format($paymentDate,'d/m/Y','Y-m-d'), 'statement_id' => $hiddenStatementId ]; @@ -2120,5 +2149,45 @@ class PolicyTransactionController extends BaseController } + + public function getInsurerStatementMonth() + { + $insurer_id = $this->request->getGet('insurer_id'); + $month = $this->request->getGet('month'); + // echo $month; + $insurer_branch_id = explode('-',$insurer_id)[1]; + $insurer_id = explode('-',$insurer_id)[0]; + $month = $month.'-01'; + $month = change_date_format($month,'Y-M-d','Y-m-d'); + // echo $month; + + $res_data = $this->insurerStatements + ->where('insurer_id',$insurer_id) + ->where('branch_id',$insurer_branch_id) + ->where('month', $month) + ->where('is_active', 1) + ->where('file_status', 'success') + ->findAll(); + + return $this->respond(['dataStatus' => true, 'code' => 200,'data' => $res_data], 200); + + + } + + public function deleteStatement($id) + { + // echo $id;die(); + $this->coShareStmtDetailsModel->where('statement_id',$id) + ->set(['is_active' => 0]) + ->update(); + $this->invPaymentDetailsModel->where('statement_id',$id) + ->set(['is_active' => 0]) + ->update(); + $this->insurerStatements->where('id',$id) + ->set(['is_active' => 0]) + ->update(); + return $this->respond(['dataStatus' => true, 'code' => 200], 200); + } -} \ No newline at end of file +} + diff --git a/app/Models/COShareStmtDetailsModel.php b/app/Models/COShareStmtDetailsModel.php new file mode 100644 index 00000000..df007cf9 --- /dev/null +++ b/app/Models/COShareStmtDetailsModel.php @@ -0,0 +1,38 @@ +db->table('pt_co_share_details pt_co') ->select(' pt_co.id, @@ -93,12 +96,15 @@ class PTCOShareDetailsModel extends Model ->join('policy_transaction pt', 'pt_co.pt_id = pt.id') ->join('clients c', 'pt.client_id = c.id') ->where('pt_co.is_active', 1) - ->where('MONTH(pt.month)', $month) - ->where('YEAR(pt.month)', $year) + ->where('pt.is_active', 1) + // ->where('MONTH(pt.month)', $month) + // ->where('YEAR(pt.month)', $year) ->where('pt_co.insurer_id', $insurer_id) ->where('pt_co.insurer_branch_id', $insurer_branch_id) - ->where('pt_co.statement_id is null') + // ->where('pt_co.statement_id is null') ->where('pt.status','completed') + ->where('DATE(pt.created_at) >=', $sixMonthsAgo) + ->where('DATE(pt.created_at) <=', $currentDate) // ->where('pt_co.exp_amt', 0.00) // ->orWhere('pt_co.exp_amt is null') ->get() diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php index ba54a5ce..e25d7e46 100644 --- a/app/Models/PolicyTransactionModel.php +++ b/app/Models/PolicyTransactionModel.php @@ -694,7 +694,7 @@ class PolicyTransactionModel extends Model return $builder->get()->getResultArray(); } - public function getOutstandingReportList($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0) + public function getOutstandingReportList_OLD($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0) { $builder = $this->db->table('policy_transaction') ->select(" @@ -791,5 +791,53 @@ class PolicyTransactionModel extends Model return $builder->get()->getResultArray(); } + + public function getOutstandingReportList($start_date = 0, $end_date = 0, $insurer_id = 0,$insurer_branch_id = 0) + { + $builder = $this->db->table('insurer_statements s') + ->select(' + s.id, + s.insurer_id, + s.branch_id, + ins.short_name, + ib.branch_name, + s.month, + s.line_items, + s.stmt_sno, + s.invoice_status, + s.invoice_date, + s.invoice_no, + s.invoice_amount, + COALESCE(SUM(p.inv_amt) + SUM(p.tds) + SUM(p.gst), 0) AS total_paid, + (s.invoice_amount - COALESCE(SUM(p.inv_amt) + SUM(p.tds) + SUM(p.gst), 0)) AS outstanding_amount + ') + ->join('inv_payment_details p', 's.id = p.statement_id', 'left') + ->join('insurers ins', 's.insurer_id = ins.id') + ->join('insurer_branch ib', 's.branch_id = ib.id') + ->where('s.is_active', 1) + ->where('p.is_active', 1) + ->groupBy('s.id, s.invoice_no, s.invoice_date, s.invoice_amount') + ->having('outstanding_amount >', 0); + // ->get(); + + + // Date range filtering + if ($start_date != 0 && $end_date != 0) { + + $builder->where('s.month >=', $start_date) + ->where('s.month <=', $end_date); + } + + if ($insurer_id != 0) { + $builder->where('s.insurer_id', $insurer_id); + } + if ($insurer_branch_id != 0) { + $builder->where('s.branch_id', $insurer_branch_id); + } + + $builder->orderBy('s.id', 'desc'); + + return $builder->get()->getResultArray(); + } } diff --git a/app/Views/insurer_statement_list.php b/app/Views/insurer_statement_list.php index 1c41c568..a20a4638 100644 --- a/app/Views/insurer_statement_list.php +++ b/app/Views/insurer_statement_list.php @@ -103,6 +103,10 @@ table.dataTable tbody td { .slider.round:before { border-radius: 50%; } + + .disabled-option { + color: gray; + }
@@ -125,6 +129,7 @@ table.dataTable tbody td {
Insurer
Month
+
Statement
sno
Filename
Line
items
File
status
@@ -140,6 +145,7 @@ table.dataTable tbody td { + " data-exp-amt="" data-received-amt="" onclick="showInvoiceStatusModal(event)"> Invoice status + + Delete +
@@ -218,8 +227,24 @@ table.dataTable tbody td {
- +
+ +
+ + +
+
Download sample file @@ -255,7 +280,7 @@ table.dataTable tbody td {