From 70f8ed7fd89fe19ab1ca697075087ae4c2781cbc Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Thu, 18 Dec 2025 11:56:15 +0530 Subject: [PATCH] FIX_Invoice Module Agent Replaced by POS - Changes --- app/Controllers/PayoutController.php | 66 ++++++++++++--- app/Models/InvoiceModel.php | 59 ++++++++++---- app/Views/invoice_policy_mapping.php | 118 ++++++++++++++++++++------- app/Views/invoice_template_2.php | 45 +++++++++- app/Views/payout_list.php | 11 ++- app/Views/payout_list_handler.php | 29 +++++-- 6 files changed, 262 insertions(+), 66 deletions(-) diff --git a/app/Controllers/PayoutController.php b/app/Controllers/PayoutController.php index 29e8b555..90d501dc 100644 --- a/app/Controllers/PayoutController.php +++ b/app/Controllers/PayoutController.php @@ -51,12 +51,14 @@ class PayoutController extends BaseController $data = $this->request->getPost(); // print_r($data); die; - $agent_id = $data['agent_id'] ?? null; + // $agent_id = $data['agent_id'] ?? null; because dropdown hided + $pos_id = $data['pos_id'] ?? null; $status_id = $data['status_id'] ?? null; $start_date = $data['start_date'] ?? null; $end_date = $data['end_date'] ?? null; - $payout_data = $this->invoiceModel->invoiceList($agent_id, $status_id, $start_date, $end_date); + // $payout_data = $this->invoiceModel->invoiceList($agent_id, $status_id, $start_date, $end_date); // because dropdown hided + $payout_data = $this->invoiceModel->invoiceList($pos_id, $status_id, $start_date, $end_date); $payout_data['payout_list_data'] = $payout_data; $payout_data = view('payout_list', $payout_data); @@ -86,7 +88,8 @@ class PayoutController extends BaseController // for list $data['payout_status'] = $this->payout_status; - $data['agent_list'] = $this->invoiceModel->agentList(); + // $data['agent_list'] = $this->invoiceModel->agentList(); // because dropdown hided + $data['pos_list'] = $this->invoiceModel->posList(); $data['page_name'] = "Invoices"; $payout_data['payout_list_data'] = $this->invoiceModel->invoiceList(); $data['payout_list'] = view('payout_list', $payout_data); @@ -204,8 +207,9 @@ class PayoutController extends BaseController $title = $type === 'add' ? 'Add Payouts' : ($type === 'edit' ? 'Edit Payouts' + : ($type === 'view' ? 'View Payouts' : ($type === 'adjustment' ? 'Payouts Adjustment' - : 'Payouts')); + : 'Payouts'))); $data['tab_name'] = $title; $data['page_name'] = $title; @@ -215,10 +219,12 @@ class PayoutController extends BaseController if($type == 'add') { $data['agents'] = $this->invoiceModel->agentList(['is_active' => 1]); // common both add and edit + $data['pos_list'] = $this->invoiceModel->posList(['is_active' => 1]); // common both add and edit } else { $data['agents'] = $this->invoiceModel->agentList(); // common both add and edit + $data['pos_list'] = $this->invoiceModel->posList(); // common both add and edit } // $data['checked_policy_numbers'] = []; // $data['invoice'] = []; @@ -236,16 +242,21 @@ class PayoutController extends BaseController return $this->loadLayout('invoice_policy_mapping_add', $data); } - if (($type === 'edit' || $type === 'adjustment') && !empty($id)) { + if (($type === 'edit' || $type === 'view' || $type === 'adjustment') && !empty($id)) { $invoice = $this->invoiceModel->where('id', $id)->first(); + // print_r($invoice);die; $data['freeze_edit'] = $this->auditHistory->where('table_name', 'partner_invoice')->where('pk', $id)->countAllResults(); - + if($type === 'view'){ $data['freeze_edit'] = 1; } - $agentId = $invoice['agent_id'] ?? null; + // $agentId = $invoice['agent_id'] ?? null; + $posId = $invoice['pos_id'] ?? null; - $data['payouts'] = $this->invoiceModel->payoutList(2 ,$agentId,$id); - $data['extra_payouts'] = $agentId ? $this->invoiceModel->payoutList(3, $agentId) : []; + // $data['payouts'] = $this->invoiceModel->payoutList(2 ,$agentId,$id); + // $data['extra_payouts'] = $agentId ? $this->invoiceModel->payoutList(3, $agentId) : []; + $data['payouts'] = $this->invoiceModel->payoutList(2 ,$posId,$id); + // print_r($data['payouts']);die; + $data['extra_payouts'] = $posId ? $this->invoiceModel->payoutList(3, $posId) : []; $invoice_items = $this->invoiceItemModel->where('invoice_id', $id)->findAll(); @@ -518,6 +529,7 @@ class PayoutController extends BaseController // Get invoice data from database $invoiceData = $this->getInvoiceData($invoiceId); + // print_r($invoiceData);die; if (empty($invoiceData)) { return $this->respond([ @@ -591,6 +603,27 @@ class PayoutController extends BaseController } + // private function getInvoiceData($invoiceId) + // { + // $invoice_data = $this->invoiceModel + // ->select(' + // partner_invoice.*, + // pa.name as agent_name, + // pa.email as agent_email, + // pa.mobile as agent_mobile, + // pa.address as agent_address, + // pa.agent_code, + // pa.certificate_file_name, + // pa.commission_retain + // ') + // ->join('partner_agent pa', 'partner_invoice.agent_id = pa.id') + // ->where('partner_invoice.is_active', 1) + // ->where('partner_invoice.id', $invoiceId) + // ->first(); + + // return $invoice_data; + // } + private function getInvoiceData($invoiceId) { $invoice_data = $this->invoiceModel @@ -604,9 +637,20 @@ class PayoutController extends BaseController pa.address as agent_address, pa.agent_code, pa.certificate_file_name, - pa.commission_retain + pa.commission_retain, + pos.name as pos_name, + pos.email as pos_email, + pos.mobile as pos_mobile, + pos.address as pos_address, + pos.city as pos_city, + pos.pincode as pos_pincode, + pos.state as pos_state, + pos.pos_code, + pos.certificate_file_name as pos_certificate_file_name, + pos.bank_name,pos.account_holder_name,pos.account_number,pos.ifsc_code, ') - ->join('partner_agent pa', 'partner_invoice.agent_id = pa.id') + ->join('partner_agent pa', 'partner_invoice.agent_id = pa.id','left') + ->join('partner_pos pos', 'partner_invoice.pos_id = pos.id') ->where('partner_invoice.is_active', 1) ->where('partner_invoice.id', $invoiceId) ->first(); diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index bebd0022..a2e241dc 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -75,8 +75,8 @@ class InvoiceModel extends Model return $data; } - - public function invoiceList($agent_id = null, $status_id = null, $start_date = null, $end_date = null) + // public function invoiceList($agent_id = null, $status_id = null, $start_date = null, $end_date = null) because dropdown hided + public function invoiceList($pos_id = null, $status_id = null, $start_date = null, $end_date = null) { $data = $this->select(" partner_invoice.*, @@ -105,14 +105,21 @@ class InvoiceModel extends Model WHEN payout_status = 2 THEN 'Completed' END AS status_text, - partner_agent.name as agent_name + partner_agent.name as agent_name, + partner_pos.name as pos_name + ") - ->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id') + ->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id','left') + ->join('partner_pos', 'partner_invoice.pos_id = partner_pos.id') ->where('partner_invoice.is_active', 1) ->where('partner_invoice.broker_id', 1); - if(!empty($agent_id)){ - $data->where('partner_invoice.agent_id', $agent_id); + // if(!empty($agent_id)){ + // $data->where('partner_invoice.agent_id', $agent_id); + // } // because dropdown hided + + if(!empty($pos_id)){ + $data->where('partner_invoice.pos_id', $pos_id); } if(!empty($status_id)){ @@ -128,7 +135,8 @@ class InvoiceModel extends Model ->where('partner_invoice.invoice_date <=', $endDate); } - if(!empty($agent_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){ + // if(!empty($agent_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){ + if(!empty($pos_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){ $fromDate = date('Y-m-d', strtotime('-60 days')); $toDate = date('Y-m-d 23:59:59'); @@ -153,6 +161,21 @@ class InvoiceModel extends Model return $this->db->table('partner_agent')->get()->getResultArray(); } + public function posList(array $params = []) + { + $builder = $this->db->table('partner_pos') + ->select('partner_pos.*, partner_staff.name AS manager_name') + ->join('partner_staff', 'partner_staff.id = partner_pos.manager_id', 'left') + ->orderBy('partner_pos.id', 'DESC'); + + if (isset($params['is_active'])) { + $builder->where('partner_pos.is_active', $params['is_active']); + } + + return $builder->get()->getResultArray(); + } + + public function utrSummary($invoice_id) { $data = $this->select(" @@ -194,7 +217,7 @@ class InvoiceModel extends Model } - public function payoutList($flag, $agentId = null, $invoiceId = null) + public function payoutList($flag, $posId = null, $invoiceId = null) { $builder = $this->db->table('policy_transaction pt') ->select(' @@ -210,13 +233,15 @@ class InvoiceModel extends Model pii.commission_amount as paid_amount, pi.payout_status, pp.id as partner_policy_id, - pp.policy_transaction_id + pp.policy_transaction_id, + pt.pos_id as posId ') ->join('partner_invoice_items pii','pii.policy_no = pt.policy_no','left') ->join('partner_invoice pi','pi.id = pii.invoice_id','left') ->join('partner_policy pp','pt.policy_no = pp.policy_number AND pt.agent_id = pp.agent_id AND pt.id = pp.policy_transaction_id') ->where('pt.is_active',1) - ->where('pt.agent_id IS NOT NULL'); + ->where('pt.pos_id IS NOT NULL'); + // ->where('pt.agent_id IS NOT NULL'); if ($flag == 1) { // Add mode // EXCLUDE all policies that exist in partner_invoice_items @@ -230,16 +255,22 @@ class InvoiceModel extends Model if ($invoiceId) { $builder->where('pi.id', $invoiceId); // only policies of this invoice } - if ($agentId) { - $builder->where('pt.agent_id', $agentId); + // if ($agentId) { + // $builder->where('pt.agent_id', $agentId); + // } + if ($posId) { + $builder->where('pt.pos_id', $posId); } } if ($flag == 3) { // Extra policies // Policies not assigned to any invoice $builder->where('pii.id IS NULL', null, false); - if ($agentId) { - $builder->where('pt.agent_id', $agentId); + // if ($agentId) { + // $builder->where('pt.agent_id', $agentId); + // } + if ($posId) { + $builder->where('pt.pos_id', $posId); } } diff --git a/app/Views/invoice_policy_mapping.php b/app/Views/invoice_policy_mapping.php index 3491db49..c103ec1d 100644 --- a/app/Views/invoice_policy_mapping.php +++ b/app/Views/invoice_policy_mapping.php @@ -98,7 +98,7 @@ table.dataTable tbody td { padding: 4px 4px !important; } -
+ +
+ + +
@@ -481,17 +498,20 @@ table.dataTable tbody td { padding: 4px 4px !important; } } - // ---- Filter policies by agent/date ---- + // ---- Filter policies by agent/POS/date ---- function filterPolicies() { const fromDate = getEl('fromDate')?.value || ''; const toDate = getEl('toDate')?.value || ''; - const agentId = getEl('agentSelect')?.value || ''; + // const agentId = getEl('agentSelect')?.value || ''; + const posId = getEl('posSelect')?.value || ''; const policyTillDate = getEl('policyTillDate')?.value || ''; - if (!agentId || agentId === '0') return toastr.warning('Please select an agent', 'Required'); + // if (!agentId || agentId === '0') return toastr.warning('Please select an agent', 'Required'); + if (!posId || posId === '0') return toastr.warning('Please select an POS', 'Required'); filteredPolicies = window.allPolicies.filter(p => { - if (String(p.agentId) !== String(agentId)) return false; + // if (String(p.agentId) !== String(agentId)) return false; + // if (String(p.posId) !== String(posId)) return false; if (policyTillDate && p.date_db > policyTillDate) return false; if (fromDate && p.date_db < fromDate) return false; if (toDate && p.date_db > toDate) return false; @@ -503,7 +523,9 @@ table.dataTable tbody td { padding: 4px 4px !important; } // ---- Load policies for selected agent ---- function loadPolicies() { - const agentId = getEl('agentSelect')?.value || ''; + // const agentId = getEl('agentSelect')?.value || ''; + const posId = getEl('posSelect')?.value || ''; + console.log('-->',posId); const policyTillDate = getEl('policyTillDate')?.value || ''; const list = getEl('policyListBody'); if (!list) return; @@ -518,16 +540,30 @@ table.dataTable tbody td { padding: 4px 4px !important; } list.innerHTML = ''; - if (!agentId || agentId === '0') { - list.innerHTML = `Please select an agent`; + // if (!agentId || agentId === '0') { + // list.innerHTML = `Please select an agent`; + // updateSummary(); + // reloadDataTable(); + // return; + // } + + // Filter policies for the selected agent + // filteredPolicies = window.allPolicies.filter(p => { + // if (String(p.agentId) !== String(agentId)) return false; + // if (policyTillDate && p.date_db > policyTillDate) return false; + // return true; + // }); + + if (!posId || posId === '0') { + list.innerHTML = `Please select a POS`; updateSummary(); reloadDataTable(); return; } - // Filter policies for the selected agent + // Filter policies for the selected POS filteredPolicies = window.allPolicies.filter(p => { - if (String(p.agentId) !== String(agentId)) return false; + if (String(p.posId) !== String(posId)) return false; if (policyTillDate && p.date_db > policyTillDate) return false; return true; }); @@ -652,8 +688,11 @@ table.dataTable tbody td { padding: 4px 4px !important; } // ---- Show More Policies ---- function showMorePolicies() { - const agentId = getEl('agentSelect')?.value || ''; - if (!agentId) return toastr.warning('Please select an agent', 'Required'); + // const agentId = getEl('agentSelect')?.value || ''; + // if (!agentId) return toastr.warning('Please select an agent', 'Required'); + + const posId = getEl('posSelect')?.value || ''; + if (!posId) return toastr.warning('Please select an POS', 'Required'); if (!window.extraPolicies || window.extraPolicies.length === 0) { return toastr.info('No more policies available.', 'Information'); @@ -664,11 +703,13 @@ table.dataTable tbody td { padding: 4px 4px !important; } // Filter extraPolicies: same agent + not already in filteredPolicies const newPolicies = window.extraPolicies.filter(p => { - return String(p.agentId) === String(agentId) && !existingPolicyIds.has(p.id); + // return String(p.agentId) === String(agentId) && !existingPolicyIds.has(p.id); + return String(p.posId) === String(posId) && !existingPolicyIds.has(p.id); }); if (newPolicies.length === 0) { - toastr.info('No more policies available for this agent.', 'Information'); + // toastr.info('No more policies available for this agent.', 'Information'); + toastr.info('No more policies available for this POS.', 'Information'); return; } @@ -690,13 +731,15 @@ table.dataTable tbody td { padding: 4px 4px !important; } // ---- Save invoice ---- function saveInvoice() { - const agentId = getEl('agentSelect')?.value || ''; + // const agentId = getEl('agentSelect')?.value || ''; + const posId = getEl('posSelect')?.value || ''; const invoiceNo = getEl('invoiceNo')?.value || ''; const invoiceDate = getEl('invoiceDate')?.value || ''; const policyTillDate = getEl('policyTillDate')?.value || ''; const invoiceID = getEl('invoiceID')?.value || ''; - if (!agentId || agentId === '0') return toastr.warning('Please select an agent', 'Required'); + // if (!agentId || agentId === '0') return toastr.warning('Please select an agent', 'Required'); + if (!posId || posId === '0') return toastr.warning('Please select an pos', 'Required'); if (!invoiceDate) return toastr.warning('Please select invoice date', 'Required'); if (selectedPolicies.size === 0) return toastr.warning('Please select at least one policy', 'Required'); @@ -728,10 +771,11 @@ table.dataTable tbody td { padding: 4px 4px !important; } const invoiceData = { invoice_id: invoiceID, invoice_no: invoiceNo, - agent_id: agentId, + // agent_id: agentId, invoice_date: invoiceDate, invoice_amount: totalAmount, - policies: policies + policies: policies, + pos_id: posId }; // console.log(invoiceData);return true; @@ -774,7 +818,8 @@ table.dataTable tbody td { padding: 4px 4px !important; } const invoiceDateEl = getEl('invoiceDate'); const policyTillDateEl = getEl('policyTillDate'); - const agentSelectEl = getEl('agentSelect'); + // const agentSelectEl = getEl('agentSelect'); + const posSelectEl = getEl('posSelect'); // Set max date (today) if (invoiceDateEl) invoiceDateEl.max = today; @@ -783,20 +828,25 @@ table.dataTable tbody td { padding: 4px 4px !important; } if (invoiceType == 'add') { // -------- ADD MODE -------- - if (agentSelectEl) agentSelectEl.value = ''; + // if (agentSelectEl) agentSelectEl.value = ''; + if (posSelectEl) posSelectEl.value = ''; if (invoiceDateEl) invoiceDateEl.required = true; if (policyTillDateEl) policyTillDateEl.required = true; - if (agentSelectEl) agentSelectEl.required = true; + // if (agentSelectEl) agentSelectEl.required = true; + if (posSelectEl) posSelectEl.required = true; // Enable Select2 - $('#agentSelect').prop('disabled', false).select2(); + // $('#agentSelect').prop('disabled', false).select2(); + $('#posSelect').prop('disabled', false).select2(); } else { // -------- EDIT,ADJUSTMENT MODE -------- - if (agentSelectEl) agentSelectEl.readOnly = true; + // if (agentSelectEl) agentSelectEl.readOnly = true; + if (posSelectEl) posSelectEl.readOnly = true; // Disable Select2 (readonly) - $('#agentSelect').prop('disabled', true); + // $('#agentSelect').prop('disabled', true); + $('#posSelect').prop('disabled', true); // Remove red star (*) from label const agentLabel = document.querySelector('label[for="agents"] .text-danger'); @@ -810,9 +860,16 @@ table.dataTable tbody td { padding: 4px 4px !important; } if (getEl('policyTillDate')) getEl('policyTillDate').valueAsDate = new Date(); } - const agentEl = getEl('agentSelect'); - if (agentEl) { - agentEl.addEventListener('change', () => { + // const agentEl = getEl('agentSelect'); + // if (agentEl) { + // agentEl.addEventListener('change', () => { + // selectedPolicies.clear(); + // loadPolicies(); + // }); + // } + const posEl = getEl('posSelect'); + if (posEl) { + posEl.addEventListener('change', () => { selectedPolicies.clear(); loadPolicies(); }); @@ -826,10 +883,12 @@ table.dataTable tbody td { padding: 4px 4px !important; } if (policyTillDateEl) policyTillDateEl.addEventListener('change', loadPolicies); - if (agentEl && agentEl.value && agentEl.value !== '0') loadPolicies(); + // if (agentEl && agentEl.value && agentEl.value !== '0') loadPolicies(); + if (posEl && posEl.value && posEl.value !== '0') loadPolicies(); else { const body = getEl('policyListBody'); - if (body) body.innerHTML = `Please select an agent`; + // if (body) body.innerHTML = `Please select an agent`; + if (body) body.innerHTML = `Please select a POS`; reloadDataTable(); } }); @@ -843,6 +902,7 @@ document.addEventListener('DOMContentLoaded', function () { // Determine if we should freeze edits const shouldFreeze = + (freeze > 0 && type === 'view') || (freeze > 0 && type === 'edit') || (payout_status === 2 && (type === 'adjustment' || type === 'edit')); diff --git a/app/Views/invoice_template_2.php b/app/Views/invoice_template_2.php index 93946a38..8713f2ef 100644 --- a/app/Views/invoice_template_2.php +++ b/app/Views/invoice_template_2.php @@ -95,6 +95,7 @@
+ + + + + + + + $pos_c, $pos_s - $pos_p."; + } elseif ($pos_a && $pos_c && $pos_s) { $address = "$pos_a,
$pos_c, $pos_s."; + } elseif ($pos_a && $pos_c && $pos_p) { $address = "$pos_a,
$pos_c - $pos_p."; + } elseif ($pos_a && $pos_s && $pos_p) { $address = "$pos_a,
$pos_s - $pos_p."; + } elseif ($pos_a && $pos_c) { $address = "$pos_a,
$pos_c."; + } elseif ($pos_a && $pos_s) { $address = "$pos_a,
$pos_s."; + } elseif ($pos_a && $pos_p) { $address = "$pos_a - $pos_p."; + } elseif ($pos_c && $pos_s && $pos_p) { $address = "$pos_c, $pos_s - $pos_p."; + } elseif ($pos_c && $pos_s) { $address = "$pos_c, $pos_s."; + } elseif ($pos_c && $pos_p) { $address = "$pos_c - $pos_p."; + } elseif ($pos_s && $pos_p) { $address = "$pos_s - $pos_p."; + } elseif ($pos_a) { $address = "$pos_a
"; + } elseif ($pos_c) { $address = "$pos_c."; + } elseif ($pos_s) { $address = "$pos_s."; + } elseif ($pos_p) { $address = "$pos_p."; + } else { $address = '-';} + ?> + + + + @@ -144,11 +180,18 @@ Amount Payable in words : -
+ +
+ BANK ACCOUNT DETAILS
+ ACCOUNT HOLDER NAME :
+ ACCOUNT NUMBER :
+ IFSC CODE :
+ Bank NAME :
diff --git a/app/Views/payout_list.php b/app/Views/payout_list.php index e81a2897..ab2bca29 100644 --- a/app/Views/payout_list.php +++ b/app/Views/payout_list.php @@ -209,7 +209,8 @@
- + + @@ -224,15 +225,17 @@ - + + diff --git a/app/Views/payout_list_handler.php b/app/Views/payout_list_handler.php index 329645bd..270ced48 100644 --- a/app/Views/payout_list_handler.php +++ b/app/Views/payout_list_handler.php @@ -14,7 +14,7 @@
-
+ +
+ +
@@ -72,7 +83,8 @@ let utrHasBeenChanged = false; $(document).ready(function(){ - $('#agent_id').select2(); + // $('#agent_id').select2(); because dropdown hided + $('#pos_id').select2(); $('#startDate').val(''); $('#endDate').val(''); $('#reportrange').val(''); @@ -121,7 +133,8 @@ $('#clear-filters').on('click', function() { // Reset all select dropdowns to the first option - $('#agent_id').val('').change(); + // $('#agent_id').val('').change(); because dropdown hided + $('#pos_id').val('').change(); $('#status_id').val('').change(); // Clear the date range inputs @@ -135,14 +148,15 @@ function fetchPayoutList(internalCall = false) { - let agent_id = $('#agent_id').val(); + // let agent_id = $('#agent_id').val(); because dropdown hided + let pos_id = $('#pos_id').val(); let status_id = $('#status_id').val(); let start_date = $('#startDate').val(); let end_date = $('#endDate').val(); - console.log({agent_id, status_id, start_date, end_date, internalCall, utrHasBeenChanged}); + console.log({pos_id, status_id, start_date, end_date, internalCall, utrHasBeenChanged}); if(!internalCall){ - if (!agent_id && !status_id && !start_date && !end_date) { + if (!pos_id && !status_id && !start_date && !end_date) { toastr.warning("Please select any one filter!", "WARNING"); return false; } @@ -152,7 +166,8 @@ // Data to send in the AJAX request let requestData = { - agent_id: agent_id, + // agent_id: agent_id, because dropdown hided + pos_id: pos_id, status_id: status_id, start_date: start_date, end_date: end_date,
Bill To: Invoice No UTR Total Amount Balance StatusAgentPOS Action