diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 626ac5a7..2e8d6fb3 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -779,6 +779,8 @@ $routes->group('payout', function($routes) { $routes->get('invoices', 'PayoutController::invoices'); $routes->post('invoices/save', 'PayoutController::saveInvoice'); $routes->get('invoices/history', 'PayoutController::auditHistory'); + $routes->get('invoices/preview', 'PayoutController::preview'); + $routes->get('invoices/downloadPdf/(:any)', 'PayoutController::downloadPdf/$1'); $routes->get('invoice/generate-number/(:num)', 'PayoutController::generateInvoiceNumberAjax/$1'); }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 8ee13498..dadbc267 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -5652,11 +5652,9 @@ class ClientController extends AdminController public function sendextraparam() { - // $data = db_connect()->table('jobs')->where('id', 1677)->get()->getRowArray(); - // // dd($data); + // $return = db_connect()->table('jobs')->where('id', 1677)->get()->getRowArray(); // $return = $this->updatePolicyTransactionDataWhileClinetPolicyUpdate(json_decode($data['payload'], true)); // dd($return); - // die; // $ticket_id = 515; // $apiServiceController = new ApiServiceController(); @@ -5680,7 +5678,9 @@ class ClientController extends AdminController // $response = $ticketServiceController->extractExcelData("claims_dump_form_client.xlsx"); // dd($response); - // $TicketController = new TicketController(); + // ---------- TICKET SERVICE CONTROLLER -------------------------------------------------------------------------------- + + $TicketController = new TicketController(); // $response = $TicketController->getMoreInfo($requestFrom = 'rest', $ticket_id = 70); // dd($response); @@ -5689,7 +5689,7 @@ class ClientController extends AdminController $empServiceController = new EmployeeServiceController(); // $res = $empServiceController->excelFileFormatValidation(['file_id' => '1126']); // $res = $empServiceController->excelFileDataValidation(['file_id' => '865']); - // $res = $empServiceController->employeesOnboardPreprocess(['file_id' => 726]); + // $res = $empServiceController->employeesOnboardPreprocess(['file_id' => 1169]); // $res = $empServiceController->employeesOnboardProcess(['file_id' => 835]); // $res = $empServiceController->employeesEnrollmentInsert(['file_id' => 836]); // $res = $empServiceController->employeesSIEnhanceProcess(['file_id' => '1131']); @@ -5698,13 +5698,13 @@ class ClientController extends AdminController // $res = $empServiceController->compareMemberDataAndInceptionData(['file_id' => '1126']); // dd($res); + // ---------- EMP MULTI EVENT SERVICE CONTROLLER -------------------------------------------------------------------------------- + $EmployeeMultiEventServiceController = new EmployeeMultiEventServiceController(); // $res = $EmployeeMultiEventServiceController->constructMultiEventData(['file_id' => '1069']); // $res = $EmployeeMultiEventServiceController->excelMultieventFileFormateValidation(['file_id' => '2373']); // $res = $EmployeeMultiEventServiceController->excelMultieventFileDataValidation(['file_id' => '2373']); // $res = $EmployeeMultiEventServiceController->excelMultieventFileOnBoard(['file_id' => '1069']); - // dd($res); - // $res = $EmployeeMultiEventServiceController->getExcelErrorData(1069, $res); // $res['file_id'] = 1069; // echo view('excel_errors', $res); diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 690e9c08..cc5a3e86 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1387,6 +1387,9 @@ class EmployeeServiceController extends AdminController $family = array_merge($family,$existing_famility_details); $family = data_group_by_family($family)[ $emp_id ];// reason to call this again is bring self to first index of the array // dd($family); + // $self = current(array_filter($family, fn($r) => strtolower($r[5] ?? '') === 'self')); + // $premium = (int)($self['temp']['rata_premimum'] ?? 0); + // foreach ($family as &$r) if (strtolower($r[5] ?? '') !== 'self') $r['self_rata_premium'] = $premium; } // Kint::dump($family); diff --git a/app/Controllers/PayoutController.php b/app/Controllers/PayoutController.php index f00ec448..c4b3708b 100644 --- a/app/Controllers/PayoutController.php +++ b/app/Controllers/PayoutController.php @@ -11,6 +11,9 @@ use App\Models\InvoiceUtrModel; use App\Models\PolicyTransactionModel; use App\Models\AuditHistoryModel; +use Dompdf\Dompdf; +use Dompdf\Options; + class PayoutController extends BaseController { use ResponseTrait; @@ -500,4 +503,108 @@ class PayoutController extends BaseController } + // **************************************************************************************************************************************************************** + + public function preview($invoiceId = null) + { + $invoiceId = $this->request->getGet('invoice_id'); + + // Get invoice data from database + $invoiceData = $this->getInvoiceData($invoiceId); + + if (empty($invoiceData)) { + return $this->respond([ + 'status' => false, + 'code' => 404, + 'data' => '', + 'message' => 'Invoice not found' + ], 200); + } + + // Load view with data + $html = view('invoice_template_2', $invoiceData); + // echo $html; die; + + return $this->respond([ + 'status' => true, + 'code' => 200, + 'data' => $html + ], 200); + } + + public function downloadPdf($invoiceId = null, $type = 0) + { + // Get invoice data from database + $invoiceData = $this->getInvoiceData($invoiceId); + + if (empty($invoiceData)) { + return redirect()->back()->with('error', 'Invoice not found'); + } + + // Generate HTML + $html = view('invoice_template_2', $invoiceData); + + // Configure Dompdf + $options = new Options(); + $options->set('isHtml5ParserEnabled', true); + $options->set('isPhpEnabled', true); + $options->set('isRemoteEnabled', true); + $options->set('defaultFont', 'Arial'); + $options->set('chroot', FCPATH); + + // Initialize Dompdf + $dompdf = new Dompdf($options); + + // Load HTML + $dompdf->loadHtml($html); + + // Set paper size and orientation + $dompdf->setPaper('A4', 'portrait'); + + // Render PDF + $dompdf->render(); + + // Generate filename + $filename = 'Invoice_' . $invoiceData['invoice_no'] . '_' . date('Ymd') . '.pdf'; + + if($type == 0){ + // Download PDF + return $this->response + ->setHeader('Content-Type', 'application/pdf') + ->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"') + ->setBody($dompdf->output()); + }else{ + // View PDF + return $this->response + ->setHeader('Content-Type', 'application/pdf') + ->setHeader('Content-Disposition', 'inline; filename="' . $filename . '"') + ->setBody($dompdf->output()); + } + + + } + + 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; + } + } diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 15f41462..f371120c 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -1022,6 +1022,10 @@ if (!function_exists('transform_excel_data_to_db')) { $result['temp']['rata_premimum'] = isset($memArr['temp']['rata_premimum']) ? $memArr['temp']['rata_premimum'] : 0; $result['policy_details'] = $policy; + // if(isset($memArr['self_rata_premium'])){ + // $result['self_rata_premium'] = $memArr['self_rata_premium'] ?? 0; + // } + return $result; } } @@ -1839,6 +1843,16 @@ if (!function_exists('premium_calculation_manager')) { //set dependent si to 0 $emp_data['policy_details']['basic_cover_si'] = 0; $emp_data['policy_details']['premium'] = 0; + + // if(isset($emp_data['self_rata_premium']) && !empty($emp_data['self_rata_premium'])){ + // $self_rata_premium = (int)($emp_data['self_rata_premium'] ?? 0); + // $dependent_rata_premium = (int)($emp_data['policy_details']['rata_premimum'] ?? 0); + // $actual_rata_premium = abs($dependent_rata_premium - $self_rata_premium); + // $emp_data['policy_details']['rata_premimum'] = $actual_rata_premium; + // $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * ($gst / 100)), 2, '.', ''); + // } + + }else if(strtolower($emp_data['relationship']) != 'self' && $temp_slab_rates[0]['premium_type'] == 1 && ($emp_data['temp']['action'] == 'I' || $emp_data['temp']['action'] == 'A' || $emp_data['temp']['action'] == 'MI')){ $emp_data['policy_details']['basic_cover_si'] = 0; diff --git a/app/Views/invoice_policy_mapping.php b/app/Views/invoice_policy_mapping.php index 3741d1d8..3491db49 100644 --- a/app/Views/invoice_policy_mapping.php +++ b/app/Views/invoice_policy_mapping.php @@ -57,6 +57,20 @@ table.dataTable tbody td { padding: 4px 4px !important; } .policy-adjustment { -moz-appearance:textfield; } + +
@@ -153,9 +167,9 @@ table.dataTable tbody td { padding: 4px 4px !important; } --> -
+
+ +
@@ -250,6 +267,36 @@ table.dataTable tbody td { padding: 4px 4px !important; }
+ + + \ No newline at end of file + +function downloadInvoicePdf(){ + + let invoice_id = $('#invoiceID').val(); + if(!invoice_id){ + return toastr.warning('No data found', 'Warning'); + } + window.location.href = '' + invoice_id +} + +function fetchPreviewInvoiceDetails(invoice_id, invoice_no){ + + if (!invoice_id) { + toastr.warning("Invoice Id not found!", "WARNING"); + return false; + } + + let heading_text = ' - ( ' + invoice_no + ' )'; + + $('#invoicePreview').empty(); + $('#invoice_heading').text(heading_text); + $('#invoicePreview').append('
Loading...
'); + + var myModal = new bootstrap.Modal(document.getElementById('invoiceModal')); + myModal.show(); + + let url = ''; + + // Data to send in the AJAX request + let requestData = { + invoice_id: invoice_id, + }; + + + // Send AJAX request + sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) { + + console.log('Data fetched successfully:', response); + + $('#invoicePreview').empty(); + $('#invoice_heading').text(heading_text); + + if (response.status == true) { + $('#invoicePreview').append(response.data); + $('#row_invoice_id').val(invoice_id); + }else{ + $('#invoicePreview').append('
No data found
'); + } + + }, function(xhr, status, error) { + console.error('Error fetching data:', error); + console.error(xhr.responseText); + // toastr.error('An error occurred while fetching the data.', 'ERROR'); + $('#invoicePreview').empty(); + $('#invoicePreview').append('
No data found
'); + }); +} + + + + + + \ No newline at end of file diff --git a/app/Views/invoice_policy_mapping_add.php b/app/Views/invoice_policy_mapping_add.php index 6a604ebf..ca804873 100755 --- a/app/Views/invoice_policy_mapping_add.php +++ b/app/Views/invoice_policy_mapping_add.php @@ -293,6 +293,13 @@ table.dataTable tbody td { padding: 4px 4px !important; } filteredPolicies = allPolicies.filter(p => String(p.agentId) === String(agentId)); + // policy Till Date filter + filteredPolicies = allPolicies.filter(p => { + if (String(p.agentId) !== String(agentId)) return false; + if (policyTillDate && p.date_db > policyTillDate) return false; + return true; + }); + let rows = ''; filteredPolicies.forEach(p => { const idStr = String(p.id); diff --git a/app/Views/invoice_template.php b/app/Views/invoice_template.php new file mode 100644 index 00000000..865ab921 --- /dev/null +++ b/app/Views/invoice_template.php @@ -0,0 +1,430 @@ + + + + + + Agent Commission Invoice + + + +
+ +
+
+
+

+


+ , -
+ Email: | Phone:

+
+
+

Commission Statement

+
+
+
+ + +
+
+

Invoice Details

+
+ Invoice Number: + +
+
+ Invoice Date: + +
+
+ Period: + +
+
+
+

Agent Information

+
+ Agent Name: + +
+
+ Agent Code: + +
+
+ No. of Policies: + +
+
+ Policies Till Date: + +
+
+
+ + + + + + + + + + + + + + + $policy): + $total_premium += $policy['premium']; + $total_commission += $policy['commission']; + + // Add page break after certain records + $page_break_class = (($serial % $records_per_page) == 0 && $serial != count($policies)) ? 'page-break' : ''; + ?> + + + + + + + + + + + + + + +
Sr.Policy No.Customer NamePremium (₹)Issue DateCommission (₹)
+ + +
+
+
+ Total Premium: + +
+
+ Total Policies: + +
+
+ Total Commission: + +
+
+
+ + + +
+ + \ No newline at end of file diff --git a/app/Views/invoice_template_2.php b/app/Views/invoice_template_2.php new file mode 100644 index 00000000..93946a38 --- /dev/null +++ b/app/Views/invoice_template_2.php @@ -0,0 +1,158 @@ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Bill To:Invoice NoDate
+ NHANCE INDIA INSURANCE BROKING PVT LTD
+ 'Old No.76, New No.82, 'Sreshtha', First floor ,
+ 4th Avenue, Ashok Nagar, Chennai - 600083 +
+ + + + + + + + + + + + + + + + +
Sl NoDescriptionAmount-INR
1INSURANCE BROKING SERVICE (POINT OF SALE)
Total
+ +
+ Amount Payable in words : +
+ +
+ BANK ACCOUNT DETAILS
+ ACCOUNT NUMBER :
+ IFSC CODE :
+ Bank NAME : +
+ +
+ Authorised Signatory +
+
+ diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 557b63bf..b9f0fd5f 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -2019,13 +2019,13 @@
  • - + Payouts
  • - + Commission
  • diff --git a/app/Views/payout_list.php b/app/Views/payout_list.php index 0f8d1703..a60b63e5 100644 --- a/app/Views/payout_list.php +++ b/app/Views/payout_list.php @@ -23,11 +23,11 @@ } .badge-container { - background: #F0F0F0; - padding: 6px 12px; - border-radius: 6px; - font-size: 14px; - display: inline-block; + background: #F0F0F0; + padding: 6px 12px; + border-radius: 6px; + font-size: 14px; + display: inline-block; } .summary-box { @@ -179,6 +179,21 @@ + +
    @@ -216,6 +231,7 @@ UTR Edit Adjustment + Preview Invoice
    @@ -242,6 +258,37 @@
    + + + + \ No newline at end of file diff --git a/app/Views/payout_list_handler.php b/app/Views/payout_list_handler.php index 80315199..329645bd 100644 --- a/app/Views/payout_list_handler.php +++ b/app/Views/payout_list_handler.php @@ -128,6 +128,7 @@ $('#reportrange').val(''); $('#startDate').val(''); $('#endDate').val(''); + window.location.reload(true); }); });