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 @@ + + +
+ + += $broker_address ?? 'Company Address Line 1' ?>
+ = $broker_city ?? 'City' ?>, = $broker_state ?? 'State' ?> - = $broker_pincode ?? 'PIN' ?>
+ Email: = $broker_email ?? 'email@company.com' ?> | Phone: = $broker_phone ?? '+91-XXXXXXXXXX' ?>
Commission Statement
+| Sr. | +Policy No. | +Customer Name | +Premium (₹) | +Issue Date | +Commission (₹) | +
|---|---|---|---|---|---|
| = $serial ?> | += $policy['policy_no'] ?> | += $policy['customer_name'] ?> | += number_format($policy['premium'], 2) ?> | += date('d-M-Y', strtotime($policy['issue_date'])) ?> | += number_format($policy['commission'], 2) ?> | +
+ Invoice #= $invoice_number ?? 'INV-2024-0001' ?> - Continued+ |
+ |||||
| = $agent_name ?> | +||
| = $agent_address ?> | +||
| Bill To: | +Invoice No | +Date | +
|
+ NHANCE INDIA INSURANCE BROKING PVT LTD + 'Old No.76, New No.82, 'Sreshtha', First floor , + 4th Avenue, Ashok Nagar, Chennai - 600083 + |
+ = isset($invoice_no) && !empty($invoice_no) ? $invoice_no : "-" ?> | += isset($invoice_date) && !empty($invoice_date) ? change_date_format($invoice_date, 'Y-m-d', 'd/m/Y') : "-" ?> | +
| Sl No | +Description | +Amount-INR | +
|---|---|---|
| 1 | +INSURANCE BROKING SERVICE (POINT OF SALE) | += isset($invoice_no) && !empty($invoice_amount) ? format_indian_number($invoice_amount) : "-" ?> | +
| Total | += isset($invoice_no) && !empty($invoice_amount) ? format_indian_number($invoice_amount) : "-" ?> | +|