From 1d2935e946fa94d84d7e2132429983a87dad07d2 Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Thu, 14 Nov 2024 17:45:20 +0530 Subject: [PATCH] FIX_PDF DOWNLOAD ISSUE --- .htaccess | 1 + app/Controllers/Invoice.php | 23 +++++-- app/Models/InvoiceModel.php | 69 +++++++++++++++---- app/Views/address_pdf_landscape_template.php | 33 +++++---- app/Views/dashboard.php | 10 ++- app/Views/invoice_form.php | 6 +- app/Views/invoice_list.php | 20 +++--- app/Views/invoice_pdf_template.php | 6 +- invoice_2024-2025-00000533.pdf | Bin 0 -> 59379 bytes 9 files changed, 118 insertions(+), 50 deletions(-) create mode 100644 invoice_2024-2025-00000533.pdf diff --git a/.htaccess b/.htaccess index dbed322f..b917c5b9 100755 --- a/.htaccess +++ b/.htaccess @@ -47,3 +47,4 @@ Options -Indexes # Disable server signature start ServerSignature Off # Disable server signature end +AddType application/pdf .pdf diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index 33fdc897..3ebc0645 100755 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -33,7 +33,7 @@ class Invoice extends BaseController $model = new InvoiceModel(); $data['page_name'] = 'Online Invoice Details'; - $data['invoice'] = $model->getJoinedData($where, ['I.invoice_date', 'DESC']); + $data['invoice'] = $model->getJoinedData($where, ['I.invoice_date', 'DESC']); $this->logger->info("Invoice: Listing Count ." . count($data['invoice'])); $this->render_page('invoice_list', $data); } else { @@ -889,7 +889,7 @@ public function create_or_update_subscription($invoice_id, $msg_flag_name = null $invoice_type = $data[0]->invoice_type; // Create an mPDF object - + ob_clean(); $mpdf = new Mpdf([ 'mode' => '', '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 '; $mpdf->setHTMLFooter($htmlFooter); + // Generate the PDF content (HTML) if ($data[0]->status === 'Draft') { // 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; // Load HTML into the mPDF instance // print_r($html);die; - $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'); + //$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) diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 84437ed1..540e2a58 100755 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -509,30 +509,75 @@ public function getInvoiceIdByMd5($md5Hash) 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 "
";
+//         // echo $this->db->getLastQuery();
+//         // echo "
";die; +// echo $this->db->getLastQuery(); +// die(); + +// return $result; + +// } public function getExpiredCustomers($f_date = null, $t_date = null) { - $now = date('Y-m-d'); - $query = $this->db->table('subscription as S'); // Define $query here + // Set timezone for accurate date calculation + 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) ->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 - ->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('books as B', 'B.book_id = S.scheme_id', 'left') - ->where('S.isactive', 1) - ->get() - ->getResultArray(); - // print_r($result); - // echo "
";
-        // echo $this->db->getLastQuery();
-        // echo "
";die; - return $result; + ->where('S.isactive', 1) // Only active subscriptions + ->get(); + // 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) { // Fetch invoice data diff --git a/app/Views/address_pdf_landscape_template.php b/app/Views/address_pdf_landscape_template.php index 2a3bff7e..68479364 100755 --- a/app/Views/address_pdf_landscape_template.php +++ b/app/Views/address_pdf_landscape_template.php @@ -10,29 +10,31 @@ box-sizing: border-box; } .label-container { - margin: 30px; + /* margin: 30px; padding: 30px; - border: 2px solid #000; + /* border: 2px solid #000; width: 100%; - height: 100%; - position: relative; + height: 100%; */ + /* position: relative; */ } .from-address, .to-address { - margin-bottom: 20px; + /* margin-bottom: 20px; */ } .from-address { text-align: left; float: left; width: 100%; - font-size: small; + font-size: 11px; } .to-address { float: right; - width: 40%; - clear: both; - /* margin-top: 20px; Adjust for spacing in landscape */ + position: absolute; + width: 48%; + /* clear: both; */ + /* padding-left: 90%; */ + margin-top: 80px; } @@ -42,8 +44,8 @@
- - + @@ -57,19 +59,20 @@ company_state . "."; ?>
company_mobile_no; ?> + -
- To :
+
+ To:
customer_name ?>
customer_ship_address && ($value->saddr_id !== null || $value->saddr_id !== '')){ ?> - customer_ship_address ? $value->customer_ship_address . " ,
" : "" ?> + customer_ship_address ? $value->customer_ship_address . ",
" : "" ?> customer_ship_city ? $value->customer_ship_city . " " : "" ?> customer_ship_postal_code ? " - " . $value->customer_ship_postal_code . "
" : ""; ?> customer_ship_state ? $value->customer_ship_state . ".
" : "" ?> saddr_id === null || $value->saddr_id === '') { echo $value->shipping_address ? $value->shipping_address.'
' : ''; } ?> - mobile_no ? "Mobile : " . $value->mobile_no . " ." : "" ?> + mobile_no ? "Mobile : " . $value->mobile_no . "." : "" ?>
diff --git a/app/Views/dashboard.php b/app/Views/dashboard.php index 511c7ee4..d5b9564f 100755 --- a/app/Views/dashboard.php +++ b/app/Views/dashboard.php @@ -171,15 +171,19 @@ $notifications = $e['notifications']; $emailNotifications = array_filter($notifications, function($notification) { return $notification['mode'] === 'Email'; - }); + }); $lastNotification = end($emailNotifications); $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'])){ + //log_message('info','start date - '.$startDate.'end date - '.$endDate.'notification date - '.$startDateTime); if ($startDateTime >= $startDate && $startDateTime <= $endDate) { - echo $startDateTime ; + echo $startDateTime->format('d/m/Y'); } } ?> diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index a1d72f34..ed147db3 100755 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -166,7 +166,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
Please select customer.
@@ -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 let message = "Earlier Membership : " + cm[0].title + " ( From: " + cm[0].formatted_from_subscription + " To: " + cm[0].formatted_to_subscription + " )" + text1 + text2; console.log(text1); - $("#schemeName").text(message); + // $("#schemeName").text(message); showAlert(message) } else { $(".subscribedetails").show(); // Change this line to use the class selector let message = "No Earlier Membership found"; - $("#schemeName").text(message); + //$("#schemeName").text(message); showAlert(message) } }, diff --git a/app/Views/invoice_list.php b/app/Views/invoice_list.php index 741da472..a0432097 100755 --- a/app/Views/invoice_list.php +++ b/app/Views/invoice_list.php @@ -14,24 +14,25 @@ } } #pdfPreviewModal .modal-dialog { - width: 595px; + /* width: 595px; height: 842px; top: -973px; left: 1018px; gap: 0px; - opacity: 0px; + opacity: 0px; */ - /* max-width: 148mm; /* A5 width */ - /* width: auto; - margin: 1.75rem auto; */ + max-width: 148mm; + width: auto; + margin: 1.75rem auto; } #pdfPreviewModal .modal-body { font-family: 'Times New Roman', Times, serif; font-size: 8pt; + } .table-responsive{ font-family: 'Apple System', 'BlinkMacSystemFont', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; - font-size: 14npx; + font-size: 14px; } #printPdfButton .ri-printer-line { font-size: 8px; @@ -155,10 +156,10 @@ - + @@ -207,7 +208,8 @@
From : + From: invoice_number == $value->wp_api_order_id ? "Order Number :" : "Invoice Number :"; ?> invoice_number; ?>