Bug Fixes : ps
This commit is contained in:
parent
6f4f9cbd5b
commit
758b959a29
@ -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 = '<div ><img src="https://cdn.pixabay.com/photo/2012/04/26/14/17/blue-42596_960_720.png"style=margin-left:70px;/> </div>';
|
||||
$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
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<div class="form-group col-md-6">
|
||||
<span style="<?= $shippingChargesStyle ?>">
|
||||
<label for="shippingCharges">Charge Amount </label>
|
||||
<input type="number" class="form-control" id="shippingCharges" name="shippingCharges" placeholder="Charges Amount" value="<?= isset($invoice_details['shipping_charge']) ? $invoice_details['shipping_charge'] : 0 ?>" oninput="calculateOverallTotals()" <?= $shippingChargesHidden ?> min="0">
|
||||
<input type="number" class="form-control" id="shippingCharges" name="shippingCharges" placeholder="Charges Amount" value="<?= isset($invoice_details['shipping_charge']) ? $invoice_details['shipping_charge'] : 0 ?>" oninput="calculateOverallTotals()" <?= $shippingChargesHidden ?> >
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,15 +1,30 @@
|
||||
<style>
|
||||
/* CSS for modal content */
|
||||
@media print {
|
||||
/* Set A5 size */
|
||||
@page {
|
||||
size: 148mm 210mm; /* Width Height */
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Apply font family and size */
|
||||
body {
|
||||
font-family: 'Times New Roman', Times, serif;
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
#pdfPreviewModal .modal-dialog {
|
||||
max-width: 210mm;
|
||||
max-width: 148mm !important;
|
||||
min-width: 148mm !important;
|
||||
width: 148mm !important;
|
||||
/* A5 width */
|
||||
width: auto;
|
||||
/* width: auto; */
|
||||
margin: 1.75rem auto;
|
||||
}
|
||||
|
||||
#pdfPreviewModal .modal-body {
|
||||
font-family: 'Apple System', 'BlinkMacSystemFont', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
font-family: 'Times New Roman', Times, sans-serif;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.table-responsive {
|
||||
@ -120,7 +135,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="pdfPreviewModal" tabindex="-1" role="dialog" aria-labelledby="pdfPreviewModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-dialog modal-md">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="pdfPreviewModalLabel"></h5>
|
||||
@ -133,7 +148,7 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="modal-body" style="font-family: Times New Roman, Times, sans-serif !important; font-size: 12px !important;">
|
||||
|
||||
<!-- PDF content will be loaded here -->
|
||||
</div>
|
||||
@ -229,7 +244,7 @@
|
||||
$(document).on('click', '#printPdfButton', function() {
|
||||
// Get the modal body content
|
||||
var printableContent = $('#pdfPreviewModal .modal-body').html();
|
||||
|
||||
|
||||
// Modify the font size of the content
|
||||
var modifiedContent = '<html><head><title>Print Preview</title><style>body { font-size: 8px; }</style></head><body>' + printableContent + '</body></html>';
|
||||
|
||||
|
||||
@ -4,6 +4,9 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
@page {
|
||||
size: 148mm 210mm; /* Width Height */
|
||||
}
|
||||
/* Add your CSS styles here to format the invoice for mPDF */
|
||||
body {
|
||||
|
||||
@ -348,10 +351,6 @@
|
||||
|
||||
|
||||
<!-- <img src="https://cdn.pixabay.com/photo/2012/04/26/14/17/blue-42596_960_720.png" /> -->
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user