FIX_PDF DOWNLOAD ISSUE

This commit is contained in:
Srinivas-Saravanan 2024-11-14 17:45:20 +05:30
parent c26f52990b
commit 1d2935e946
9 changed files with 118 additions and 50 deletions

View File

@ -47,3 +47,4 @@ Options -Indexes
# Disable server signature start # Disable server signature start
ServerSignature Off ServerSignature Off
# Disable server signature end # Disable server signature end
AddType application/pdf .pdf

View File

@ -889,7 +889,7 @@ public function create_or_update_subscription($invoice_id, $msg_flag_name = null
$invoice_type = $data[0]->invoice_type; $invoice_type = $data[0]->invoice_type;
// Create an mPDF object // Create an mPDF object
ob_clean();
$mpdf = new Mpdf([ $mpdf = new Mpdf([
'mode' => '', 'mode' => '',
'format' => [148, 210], // Set custom width and height in millimeters 'format' => [148, 210], // Set custom width and height in millimeters
@ -916,6 +916,7 @@ public function create_or_update_subscription($invoice_id, $msg_flag_name = null
<img src="https://cdn.pixabay.com/photo/2012/04/26/14/17/blue-42596_960_720.png"style=margin-top:70px;/> </div>'; <img src="https://cdn.pixabay.com/photo/2012/04/26/14/17/blue-42596_960_720.png"style=margin-top:70px;/> </div>';
$mpdf->setHTMLFooter($htmlFooter); $mpdf->setHTMLFooter($htmlFooter);
// Generate the PDF content (HTML) // Generate the PDF content (HTML)
if ($data[0]->status === 'Draft') { if ($data[0]->status === 'Draft') {
// Set the watermark text and options // Set the watermark text and options
@ -942,12 +943,24 @@ public function create_or_update_subscription($invoice_id, $msg_flag_name = null
// echo $html;die; // echo $html;die;
// Load HTML into the mPDF instance // Load HTML into the mPDF instance
// print_r($html);die; // print_r($html);die;
$mpdf->WriteHTML($html); $mpdf->WriteHTML($html);
// Output the PDF to the browser for download // Output the PDF to the browser for download
// $mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D'); // $mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D');
$mpdf->Output("invoice_" . $data[0]->invoice_number . '.pdf', 'D'); //$mpdf->Output("invoice_" . $data[0]->invoice_number . '.pdf', 'D');
$filename = 'invoice_' . $data[0]->invoice_number.'.pdf'; // Filename based on invoice number
// $mpdf->Output($filename . '.pdf', 'D'); // Generate and download the PDF with the specified filename
$mpdf->Output($filename, 'D'); // Generate and download the PDF with the specified filename
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="invoice_' . $data[0]->invoice_number . '.pdf"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
header('Cache-Control: private');
header('Pragma: private');
exit();
// Set headers to force download with the correct filename
} }
public function generate_invoice_pdf_preview($id) public function generate_invoice_pdf_preview($id)

View File

@ -509,30 +509,75 @@ public function getInvoiceIdByMd5($md5Hash)
return null; return null;
} }
// public function getExpiredCustomers($f_date = null, $t_date = null)
// {
// $now = date('Y-m-d');
// $futureDate = date('Y-m-d', strtotime($now . ' +30 days'));
// $query = $this->db->table('subscription as S'); // Define $query here
// if ($f_date !== null && $t_date !== null) {
// $query->where('S.to_subscription >=', $f_date)
// ->where('S.to_subscription <=', $t_date);
// }
// $result = $query
// ->select('S.customer_id,S.sub_id, S.from_subscription, S.to_subscription, C.first_name, C.last_name, C.email, C.mobile_no, S.scheme_id,B.short_code')
// ->join('customers as C', 'C.customer_id = S.customer_id', 'left')
// ->join('books as B', 'B.book_id = S.scheme_id', 'left')
// ->where('S.isactive', 1)
// ->where('S.to_subscription <', $futureDate)
// ->get()
// ->getResultArray();
// // print_r($result);
// // echo "<pre>";
// // echo $this->db->getLastQuery();
// // echo "</pre>";die;
// echo $this->db->getLastQuery();
// die();
// return $result;
// }
public function getExpiredCustomers($f_date = null, $t_date = null) public function getExpiredCustomers($f_date = null, $t_date = null)
{ {
$now = date('Y-m-d'); // Set timezone for accurate date calculation
$query = $this->db->table('subscription as S'); // Define $query here date_default_timezone_set('Asia/Kolkata');
if ($f_date !== null && $t_date !== null) { // Calculate the date 30 days from now
$futureDate = date('Y-m-d', strtotime('+30 days'));
// Initialize query builder
$query = $this->db->table('subscription as S');
// Apply custom date range filter if both $f_date and $t_date are provided
if (!empty($f_date) && !empty($t_date)) {
$query->where('S.to_subscription >=', $f_date) $query->where('S.to_subscription >=', $f_date)
->where('S.to_subscription <=', $t_date); ->where('S.to_subscription <=', $t_date);
} else {
$query->where('S.to_subscription >=', date('Y-m-d'))
->where('S.to_subscription <=', $futureDate);
} }
// Build the query
$result = $query $result = $query
->select('S.customer_id,S.sub_id, S.from_subscription, S.to_subscription, C.first_name, C.last_name, C.email, C.mobile_no, S.scheme_id,B.short_code') ->select('S.customer_id, S.sub_id, S.from_subscription, S.to_subscription,
C.first_name, C.last_name, C.email, C.mobile_no,
S.scheme_id, B.short_code')
->join('customers as C', 'C.customer_id = S.customer_id', 'left') ->join('customers as C', 'C.customer_id = S.customer_id', 'left')
->join('books as B', 'B.book_id = S.scheme_id', 'left') ->join('books as B', 'B.book_id = S.scheme_id', 'left')
->where('S.isactive', 1) ->where('S.isactive', 1) // Only active subscriptions
->get() ->get();
->getResultArray();
// print_r($result);
// echo "<pre>";
// echo $this->db->getLastQuery();
// echo "</pre>";die;
return $result;
// Debugging: output the generated SQL query
// echo $this->db->getLastQuery();
// die();
// Fetch results as an associative array
return $result->getResultArray();
} }
public function itemwise_report_data_with_publish_code($f_date = null, $t_date = null) public function itemwise_report_data_with_publish_code($f_date = null, $t_date = null)
{ {
// Fetch invoice data // Fetch invoice data

View File

@ -10,29 +10,31 @@
box-sizing: border-box; box-sizing: border-box;
} }
.label-container { .label-container {
margin: 30px; /* margin: 30px;
padding: 30px; padding: 30px;
border: 2px solid #000; /* border: 2px solid #000;
width: 100%; width: 100%;
height: 100%; height: 100%; */
position: relative; /* position: relative; */
} }
.from-address, .to-address { .from-address, .to-address {
margin-bottom: 20px; /* margin-bottom: 20px; */
} }
.from-address { .from-address {
text-align: left; text-align: left;
float: left; float: left;
width: 100%; width: 100%;
font-size: small; font-size: 11px;
} }
.to-address { .to-address {
float: right; float: right;
width: 40%; position: absolute;
clear: both; width: 48%;
/* margin-top: 20px; Adjust for spacing in landscape */ /* clear: both; */
/* padding-left: 90%; */
margin-top: 80px;
} }
</style> </style>
</head> </head>
@ -42,8 +44,8 @@
<div class="label-container"> <div class="label-container">
<table width="100%" style="border-collapse: collapse;"> <table width="100%" style="border-collapse: collapse;">
<tr> <tr>
<td width="30%" style="text-align: left;"><strong>From :</strong></td> <td width="30%" style="text-align: left;font-size: 11px;"><strong>From:</strong></td>
<td width="70%" style="text-align: right;"> <td width="70%" style="text-align: right;font-size: 11px;">
<?php $label = $value->invoice_number == $value->wp_api_order_id ? "Order Number :" : "Invoice Number :"; ?> <?php $label = $value->invoice_number == $value->wp_api_order_id ? "Order Number :" : "Invoice Number :"; ?>
<b><?= $label; ?></b> <?= $value->invoice_number; ?> <b><?= $label; ?></b> <?= $value->invoice_number; ?>
</td> </td>
@ -57,19 +59,20 @@
<?= $value->company_state . "."; ?><br> <?= $value->company_state . "."; ?><br>
<?= $value->company_mobile_no; ?> <?= $value->company_mobile_no; ?>
</div> </div>
<!-- To Address --> <!-- To Address -->
<div class="to-address"> <div class="to-address">
<strong>To :</strong><br> <strong>To:</strong><br>
<?= $value->customer_name ?><br> <?= $value->customer_name ?><br>
<?php if($value->customer_ship_address && ($value->saddr_id !== null || $value->saddr_id !== '')){ ?> <?php if($value->customer_ship_address && ($value->saddr_id !== null || $value->saddr_id !== '')){ ?>
<?= $value->customer_ship_address ? $value->customer_ship_address . " , <br>" : "" ?> <?= $value->customer_ship_address ? $value->customer_ship_address . ", <br>" : "" ?>
<?= $value->customer_ship_city ? $value->customer_ship_city . "&nbsp;" : "" ?> <?= $value->customer_ship_city ? $value->customer_ship_city . "&nbsp;" : "" ?>
<?= $value->customer_ship_postal_code ? " - " . $value->customer_ship_postal_code . "<br>" : ""; ?> <?= $value->customer_ship_postal_code ? " - " . $value->customer_ship_postal_code . "<br>" : ""; ?>
<?= $value->customer_ship_state ? $value->customer_ship_state . ". <br>" : "" ?> <?= $value->customer_ship_state ? $value->customer_ship_state . ". <br>" : "" ?>
<?php }else if ($value->saddr_id === null || $value->saddr_id === '') { <?php }else if ($value->saddr_id === null || $value->saddr_id === '') {
echo $value->shipping_address ? $value->shipping_address.'<br>' : ''; echo $value->shipping_address ? $value->shipping_address.'<br>' : '';
} ?> } ?>
<?= $value->mobile_no ? "Mobile : " . $value->mobile_no . " ." : "" ?> <?= $value->mobile_no ? "Mobile : " . $value->mobile_no . "." : "" ?>
</div> </div>
<div style="clear: both;"></div> <div style="clear: both;"></div>
</div> </div>

View File

@ -175,11 +175,15 @@
$lastNotification = end($emailNotifications); $lastNotification = end($emailNotifications);
$lastStartDateTime = ($lastNotification && isset($lastNotification['start_date_time'])) ? $lastNotification['start_date_time'] : ''; $lastStartDateTime = ($lastNotification && isset($lastNotification['start_date_time'])) ? $lastNotification['start_date_time'] : '';
$startDateTime = $lastStartDateTime ? date('d/m/Y', strtotime($lastStartDateTime)) : '';
$startDateTime = $lastStartDateTime ? date('d/m/Y', strtotime($lastStartDateTime)) : '';
$startDate = DateTime::createFromFormat('d/m/Y', $startDate); // Assuming format 'd/m/Y'
$endDate = DateTime::createFromFormat('d/m/Y', $endDate); // Assuming format 'd/m/Y'
$startDateTime = DateTime::createFromFormat('d/m/Y', $startDateTime);
if(isset($lastNotification['receiving_status'])){ if(isset($lastNotification['receiving_status'])){
//log_message('info','start date - '.$startDate.'end date - '.$endDate.'notification date - '.$startDateTime);
if ($startDateTime >= $startDate && $startDateTime <= $endDate) { if ($startDateTime >= $startDate && $startDateTime <= $endDate) {
echo $startDateTime ; echo $startDateTime->format('d/m/Y');
} }
} }
?> ?>

View File

@ -166,7 +166,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
<div class="invalid-feedback"> Please select customer. </div> <div class="invalid-feedback"> Please select customer. </div>
<div class="subscribedetails" style="display: none"> <div class="subscribedetails" style="display: none">
<div id="schemeName"></div> <!-- <div id="schemeName"></div> -->
</div> </div>
</div> </div>
@ -1544,12 +1544,12 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
$(".subscribedetails").show(); // Change this line to use the class selector $(".subscribedetails").show(); // Change this line to use the class selector
let message = "Earlier Membership : " + cm[0].title + " ( From: " + cm[0].formatted_from_subscription + " To: " + cm[0].formatted_to_subscription + " )" + text1 + text2; let message = "Earlier Membership : " + cm[0].title + " ( From: " + cm[0].formatted_from_subscription + " To: " + cm[0].formatted_to_subscription + " )" + text1 + text2;
console.log(text1); console.log(text1);
$("#schemeName").text(message); // $("#schemeName").text(message);
showAlert(message) showAlert(message)
} else { } else {
$(".subscribedetails").show(); // Change this line to use the class selector $(".subscribedetails").show(); // Change this line to use the class selector
let message = "No Earlier Membership found"; let message = "No Earlier Membership found";
$("#schemeName").text(message); //$("#schemeName").text(message);
showAlert(message) showAlert(message)
} }
}, },

View File

@ -14,24 +14,25 @@
} }
} }
#pdfPreviewModal .modal-dialog { #pdfPreviewModal .modal-dialog {
width: 595px; /* width: 595px;
height: 842px; height: 842px;
top: -973px; top: -973px;
left: 1018px; left: 1018px;
gap: 0px; gap: 0px;
opacity: 0px; opacity: 0px; */
/* max-width: 148mm; /* A5 width */ max-width: 148mm;
/* width: auto; width: auto;
margin: 1.75rem auto; */ margin: 1.75rem auto;
} }
#pdfPreviewModal .modal-body { #pdfPreviewModal .modal-body {
font-family: 'Times New Roman', Times, serif; font-family: 'Times New Roman', Times, serif;
font-size: 8pt; font-size: 8pt;
} }
.table-responsive{ .table-responsive{
font-family: 'Apple System', 'BlinkMacSystemFont', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; font-family: 'Apple System', 'BlinkMacSystemFont', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
font-size: 14npx; font-size: 14px;
} }
#printPdfButton .ri-printer-line { #printPdfButton .ri-printer-line {
font-size: 8px; font-size: 8px;
@ -155,10 +156,10 @@
<!-- PDF content will be loaded here --> <!-- PDF content will be loaded here -->
</div> </div>
<!-- <div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div> --> </div>
</div> </div>
</div> </div>
@ -207,6 +208,7 @@
<script> <script>
$(document).on('click', '.preview-pdf', function() { $(document).on('click', '.preview-pdf', function() {
var invoiceId = $(this).data('invoice-id'); var invoiceId = $(this).data('invoice-id');
console.log('invoice id '+invoiceId);
// Send AJAX request to controller // Send AJAX request to controller
$.ajax({ $.ajax({

View File

@ -10,11 +10,11 @@
} }
/* Add your CSS styles here to format the invoice for mPDF */ /* Add your CSS styles here to format the invoice for mPDF */
td { /* td { */
/* display: flex; /* display: flex;
*/ */
/* align-items: flex-start; */ /* align-items: flex-start; */
} /* } */
body { body {
/* font-family: 'Times New Roman', Times, sans-serif; */ /* font-family: 'Times New Roman', Times, sans-serif; */
@ -259,7 +259,7 @@
<?php $serialNumber = 1; ?> <?php $serialNumber = 1; ?>
<?php foreach ($invoiceItems as $item) : ?> <?php foreach ($invoiceItems as $item) : ?>
<tr> <tr>
<td style="display:flex;algin-items:flex-start"> <td style="display:flex;align-items:flex-start">
<?= $serialNumber++; ?> <?= $serialNumber++; ?>
</td> </td>
<td><span style="font-size:10pt"><?= $item->title ?></span><br> <td><span style="font-size:10pt"><?= $item->title ?></span><br>

Binary file not shown.