vb_book/app/Views/invoice_list.php
2024-12-27 10:09:03 +05:30

284 lines
13 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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: 8pt;
}
}
#pdfPreviewModal .modal-dialog {
/* width: 595px;
height: 842px;
top: -973px;
left: 1018px;
gap: 0px;
opacity: 0px; */
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: 14px;
}
#printPdfButton .ri-printer-line {
font-size: 8px;
}
.modal-lg, .modal-xl {
Width : 595px;
Height : 842px;
Top : -973px;
Left : 1018px;
}
</style>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="float-right">
</div>
<br>
<h4 class="header-title mb-3"><?= $page_name; ?></h4>
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
<?php if (session()->getFlashdata('success')) : ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?= session('success') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php endif; ?>
<?php if (session()->getFlashdata('error')) : ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?= session('error') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php endif; ?>
<?php endif; ?>
<div class="table-responsive">
<table id="scroll-horizontal-datatable_wrapper" class="table w-100 nowrap">
<thead class="thead-light">
<tr>
<th hidden></th>
<th>Order Number</th>
<th>Invoice Date</th>
<th>Customer Name</th>
<th>Status</th>
<th style="text-align: center;">Total (₹)</th>
<th align="center" id="action-column">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($invoice as $row) :
if (!empty($row['order_number']) && $row['invoice_type'] == 1) :
$invoice_date = date('d/m/Y', strtotime($row['invoice_date']));
?>
<tr>
<td hidden><?= $row['invoice_date']; ?></td>
<td class="preview-pdf" data-order="<?= $row['invoice_number']; ?>" data-invoice-id="<?= $row['invoice_id']; ?>">
<a href="#" title="Preview PDF" style="text-decoration: underline dotted !important;"><?= $row['invoice_number']; ?></a>
</td>
<td class="preview-pdf" data-order="<?= strtotime($row['invoice_date']); ?>" data-invoice-id="<?= $row['invoice_id']; ?>"><?= $invoice_date; ?></td>
<td class="preview-pdf" data-order="<?= $row['customer_name']; ?>" data-invoice-id="<?= $row['invoice_id']; ?>"><?= $row['customer_name']; ?></td>
<td class="preview-pdf" data-order="<?= $row['status']; ?>;" id="status-column" data-invoice-id="<?= $row['invoice_id']; ?>"><?= $row['status']; ?></td>
<td style="text-align: right;padding-right: 47px;" class="preview-pdf" data-order="<?= $row['total_amount']; ?>" data-invoice-id="<?= $row['invoice_id']; ?>"><?= $row['total_amount']; ?></td>
<td>
<a href="<?= base_url("generate_invoice_pdf/{$row['invoice_id']}") ?>" class="download-pdf-button" title="Download the Invoice"><i class="ri-file-download-line"></i></a>&nbsp;
<a style="display: none;" href="<?= base_url("print_address/{$row['invoice_id']}") ?>" class="print-address-button" title="Print Address"><i class="ri-printer-line"></i></a>
<a href="<?= base_url("print_address_landscape/{$row['invoice_id']}") ?>" class="print-address-button" title="Print Address"><i class="ri-printer-fill"></i></a>
</td>
</tr>
<?php endif;
endforeach; ?>
</tbody>
</table>
</div>
</div> <!-- end card body-->
</div> <!-- end card -->
</div><!-- end col-->
</div><!-- end row-->
<!-- Modal for selecting invoice type -->
<div id="invoiceTypeModal" class="modal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="mySmallModalLabel">Select Invoice Type</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<label>
<input type="radio" name="invoiceType" value="subscription"> Subscription Invoice
</label>
<label>
<input type="radio" name="invoiceType" value="book"> Book Invoice
</label>
</div>
<div class="modal-footer">
<button id="confirmInvoiceType" class="btn btn-primary">Continue</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="pdfPreviewModal" tabindex="-1" role="dialog" aria-labelledby="pdfPreviewModalLabel" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="pdfPreviewModalLabel"></h5>
<!-- Placeholder for status -->
<a href="#" class="" id="downloadPdfButton" title="Invoice PDF" style="font-size: large;"><i class="ri-file-download-line"></i> </a>
<a href="#" class="ri-printer-line" id="printPdfButton" title="Print Invoice" style="font-size: large; margin-left: 8px;"></a>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="reloadBodyContent()" style="font-size: 27px; margin-bottom: 2px;">
<span id="statusText"></span>
<span aria-hidden="true">&times;</span>
</button>
</div>
<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>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$("#addNewButton").click(function() {
// Show the pop-up modal
$("#invoiceTypeModal").modal("show");
});
$("#confirmInvoiceType").click(function() {
// Get the selected invoice type
var selectedType = $("input[name='invoiceType']:checked").val();
// Redirect the user to the appropriate form based on the selected type
if (selectedType === "subscription") {
// Redirect to the subscription invoice form
window.location.href = "<?= base_url('new_subscription_invoice/0'); ?>"; // Update the URL as needed
} else if (selectedType === "book") {
// Redirect to the book invoice form
window.location.href = "<?= base_url('new_book_invoice/0'); ?>"; // Update the URL as needed
}
});
// Close the modal when the close button is clicked
$("#invoiceTypeModal .close").click(function() {
$("#invoiceTypeModal").modal("hide");
});
});
</script>
<script>
$(document).ready(function() {
var actionColumnIndex = $('#action-column').index();
$('#scroll-horizontal-datatable_wrapper').DataTable({
"order": [
[0, "desc"]
], // 4 is the column index of "created_on" in your table
"columnDefs": [{
"targets": [actionColumnIndex],
"orderable": false
}]
});
});
</script>
<script>
$(document).on('click', '.preview-pdf', function() {
var invoiceId = $(this).data('invoice-id');
console.log('invoice id '+invoiceId);
// Send AJAX request to controller
$.ajax({
url: '<?= base_url('generate_invoice_pdf_preview/') ?>' + invoiceId,
type: 'GET',
dataType: 'html',
success: function(response) {
// Display the PDF content in a modal or an iframe
$('#pdfPreviewModal .modal-body').html(response);
$('#downloadPdfButton').attr('href', '<?= base_url("generate_invoice_pdf/") ?>' + invoiceId);
// Get the status text
var status = $('.preview-pdf[data-invoice-id="' + invoiceId + '"]').closest('tr').find('#status-column').text().trim();
// Update the status in the modal header
$('#statusText').text('' + status);
// Hide the "Edit" button if the status is approved
if (status.toLowerCase() === 'approved') {
$('#editInvoiceButton').hide();
} else {
$('#editInvoiceButton').show();
$('#editInvoiceButton').attr('href', '<?= base_url("new_book_invoice/") ?>' + invoiceId);
}
$('#pdfPreviewModal').modal('show');
},
error: function(xhr, status, error) {
console.error(error);
alert('Failed to load PDF preview.');
}
});
});
</script>
<script>
// JavaScript click event handler for printing PDF
$(document).ready(function() {
$(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>';
// Create a new window for printing
var printWindow = window.open('', '_blank');
// Write the modified content to the new window
printWindow.document.open();
printWindow.document.write(modifiedContent);
printWindow.document.close();
// Wait for content to load before printing
printWindow.onload = function() {
printWindow.focus(); // Focus the new window
printWindow.print(); // Print the content
printWindow.close(); // Close the window after printing
};
});
});
function reloadBodyContent() {
console.log("Inside Reload Function");
fetch(window.location.href) // Fetch the current page's content
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
document.body.innerHTML = doc.body.innerHTML; // Replace the body content
// Reinitialize any required scripts if needed
})
.catch(error => console.error('Error reloading body:', error));
}
</script>