diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index f7df68f5..f5525652 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -676,8 +676,7 @@ class Invoice extends BaseController ## To Generate Invoice PDF based on invoice ID public function generate_invoice_pdf($id) { - // echo "hello"; die; - // Fetch the invoice data based on $invoice_id + $model = new InvoiceModel(); $data = $model->getInvoiceData($id); $invoiceItems = $model->getInvoiceItems($id, 'groupby'); @@ -687,16 +686,12 @@ class Invoice extends BaseController $invoiceItems[$index]->imgs = $productImgs; } - - // print_r($invoiceItems);die(); $invoice_type = $data[0]->invoice_type; - // print_r($invoiceItems);die(); - // Create an mPDF object $mpdf = new Mpdf([ 'mode' => '', - 'format' => 'A5', + 'format' => [148, 210], // Set custom width and height in millimeters 'default_font_size' => 0, 'default_font' => '', 'margin_left' => 2, @@ -709,7 +704,6 @@ class Invoice extends BaseController ]); - $mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true; // Set PDF properties @@ -749,6 +743,7 @@ class Invoice extends BaseController // $mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D'); $mpdf->Output("invoice_" . $data[0]->invoice_number . '.pdf', 'D'); } + public function generate_invoice_pdf_preview($id) { // Load required model @@ -774,49 +769,6 @@ class Invoice extends BaseController echo $html; } - // public function generate_invoice_pdf($id) - // { - // // Fetch the invoice data based on $invoice_id - // $model = new InvoiceModel(); - // $data = $model->getInvoiceData($id); - // $invoiceItems = $model->getInvoiceItems($id, 'groupby'); - - // foreach ($invoiceItems as $index => $singleItem) { - // $productImgs = $model->getProductImgs($singleItem->product); - // $invoiceItems[$index]->imgs = $productImgs; - // } - // $invoice_type = $data[0]->invoice_type; - // // Create a DOMPDF instance - // $dompdf = new Dompdf(); - - // // Set PDF properties - // $options = $dompdf->getOptions(); - // $options->set("isHtml5ParserEnabled", true); - - // // Set paper size and orientation - // $dompdf->setPaper('A5', 'portrait'); - - // // Generate the PDF content (HTML) - // if ($data[0]->status === 'Draft') { - // // Add a watermark for draft status - // $dompdf->set_option('page_script', function ($pageNumber, $pageCount, $canvas) { - // $canvas->text(20, 20, 'Draft'); - // }); - - // } - - // // Generate the PDF content (HTML) with data - // $html = view('invoice_pdf_template', ['data' => $data, 'invoiceItems' => $invoiceItems, 'invoice_type' => $invoice_type, 'invoiceTerms' => $data]); - - // // Load HTML into the DOMPDF instance - // $dompdf->loadHtml($html); - - // // Render PDF (first pass to get the number of pages) - // $dompdf->render(); - - // // Output the PDF to the browser for download - // $dompdf->stream('invoice_' . date('Y-m-d H-i-s') . '.pdf', array('Attachment' => 0)); - // } public function print_address($id) { @@ -1053,91 +1005,18 @@ class Invoice extends BaseController } - - // public function generate_invoice_pdf($id) - // { - // // Load the mPDF library - // $mpdf = new \Mpdf\Mpdf(); - - // // Fetch invoice data - // $invoice = $this->find($id); - - // if ($invoice) { - // // Fetch related invoice items - // $invoiceItems = $this->getInvoiceItems($id); - - // // Create the HTML content for the PDF - // $html = view('pdf/invoice_template', ['invoice' => $invoice, 'invoiceItems' => $invoiceItems]); - - // // Load HTML content into mPDF - // $mpdf->WriteHTML($html); - - // // Set PDF filename - // $pdfFileName = 'invoice_' . $invoice->invoice_number . '.pdf'; - - // // Output the PDF for download - // $mpdf->Output($pdfFileName, 'D'); - // } - // } - - // public function getInvoiceItems($invoiceId) - // { - // // Fetch invoice items related to the given invoice ID - // return $this->db->table('invoice_items')->where('invoice_id', $invoiceId)->get()->getResult(); - // } - - - // Fetch the invoice data based on $invoice_id + ## Child Function Called in approve_notifications public function download_invoice_pdf($md5Hash) { $model = new InvoiceModel(); - // Retrieve the invoice ID from the MD5 hash $invoice_id = $model->getInvoiceIdByMd5($md5Hash); - // Check if the MD5 hash is valid and the invoice ID exists if ($invoice_id) { - // Fetch the invoice data based on $invoice_id - - $data = $model->getInvoiceData($invoice_id); - $invoiceItems = $model->getInvoiceItems($invoice_id, 'groupby'); - foreach ($invoiceItems as $index => $singleItem) { - $productImgs = $model->getProductImgs($singleItem->product); - $invoiceItems[$index]->imgs = $productImgs; - } - - $invoice_type = $data[0]->invoice_type; - - // Create an mPDF object - $mpdf = new Mpdf(); - $mpdf->autoLangToFont = true; - $mpdf->autoScriptToLang = true; - - // Set PDF properties - $mpdf->SetTitle('Invoice'); - $mpdf->SetAuthor($data[0]->company_name); - $mpdf->SetCreator(''); - $htmlFooter = '
'; - $mpdf->setHTMLFooter($htmlFooter); - - // Generate the PDF content (HTML) with data - $html = view('invoice_pdf_template', ['data' => $data, 'invoiceItems' => $invoiceItems, 'invoice_type' => $invoice_type, 'invoiceTerms' => $data]); - - // Load HTML into the mPDF instance - $mpdf->WriteHTML($html); - - // Output the PDF to the browser for download - // $mpdf->Output("invoice_" . date('Y-m-d H-i-s') . '.pdf', 'D'); - $mpdf->Output("invoice_" . $data[0]->invoice_number . '.pdf', 'D'); - + $this->generate_invoice_pdf($invoice_id); } else { echo "no code works"; } } - // private function getInvoiceIdByMd5($md5Hash) - // { - // // Assuming you have a table named 'invoices' with columns 'invoice_id' and 'md5_hash' - // $result = $this->db->table('invoices')->select('invoice_id')->where('md5_hash', $md5Hash)->get()->getRow(); - // return $result ? $result->invoice_id : null; - // } + public function saveBook() { // Retrieve book details from POST data diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index 88f5b5dd..c19a4539 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -268,7 +268,7 @@
- min="0"> + >
diff --git a/app/Views/invoice_list.php b/app/Views/invoice_list.php index 742ec1d7..4a4ca368 100644 --- a/app/Views/invoice_list.php +++ b/app/Views/invoice_list.php @@ -1,15 +1,30 @@ ' + printableContent + ''; diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php index 38ed7232..aa052508 100644 --- a/app/Views/invoice_pdf_template.php +++ b/app/Views/invoice_pdf_template.php @@ -4,6 +4,9 @@