diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d2a077fd..00c54d85 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -777,6 +777,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'); }); //PARTNER COMMISSION diff --git a/app/Controllers/PayoutController.php b/app/Controllers/PayoutController.php index 5c86ff39..059fcbeb 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; @@ -451,4 +454,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/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/payout_list.php b/app/Views/payout_list.php index 5f789fb2..865660cd 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