303 lines
15 KiB
PHP
Executable File
303 lines
15 KiB
PHP
Executable File
<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: 10pt;
|
||
}
|
||
}
|
||
#pdfPreviewModal .modal-dialog {
|
||
max-width: 148mm; /* A5 width */
|
||
width: auto;
|
||
margin: 1.75rem auto;
|
||
}
|
||
#pdfPreviewModal .modal-body {
|
||
font-family: 'Calibri', 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 {
|
||
max-width: 678px;
|
||
}
|
||
.modal-body {
|
||
font-size: 1.3em !important;
|
||
}
|
||
|
||
</style>
|
||
<!-- /* CSS for modal content */
|
||
#pdfPreviewModal .modal-body {
|
||
font-family: 'Apple System', 'BlinkMacSystemFont', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||
font-size:12px;
|
||
}
|
||
.table-responsive{
|
||
font-family: 'Apple System', 'BlinkMacSystemFont', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||
font-size:12px;
|
||
}
|
||
#printPdfButton .ri-printer-line {
|
||
font-size: 8px;
|
||
}
|
||
</style> -->
|
||
|
||
<div class="row">
|
||
<div class="col-12">
|
||
<div class="card">
|
||
<div class="card-body">
|
||
<div class="float-right">
|
||
<a href="<?= base_url() . "new_book_invoice/0"; ?>" class="btn btn-primary"><i class="ri-currency-line"></i> Add Invoice </a>
|
||
</div>
|
||
<!-- HTML for the "Add New" button -->
|
||
|
||
<!-- <div id="standard-modal">
|
||
<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">Continue</button>
|
||
</div>
|
||
</div>< /.modal-content
|
||
</div>
|
||
</div>
|
||
</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">×</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">×</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>Invoice 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 ($row['invoice_type'] == 1) : // Check if it's a subscription invoice
|
||
$invoice_date = date('d/m/Y', strtotime($row['invoice_date']));
|
||
if (empty($row['order_number'])) : // Check if order_number is empty ?>
|
||
<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: 67px;" 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>
|
||
<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; endif; endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div> <!-- end card body-->
|
||
</div> <!-- end card -->
|
||
</div><!-- end col-->
|
||
</div><!-- end row-->
|
||
<!-- PDF Preview Modal -->
|
||
<!-- PDF Preview Modal -->
|
||
<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-content">
|
||
<div class="modal-header">
|
||
<a href="#" class="" id="downloadPdfButton" title="Invoice PDF" style="font-size: large;"><i class="ri-file-download-line"></i> </a>
|
||
<a href="#" class="" id="editInvoiceButton" title="Edit Invoice"style="font-size: large;margin-left: 8px;"><i class="ri-pencil-line"></i> </a>
|
||
<a href="#" class="ri-printer-line" id="printPdfButton" title="Print Invoice"style="font-size: large;margin-left: 8px;"></a>
|
||
<h5 class="modal-title" id="pdfPreviewModalLabel"></h5>
|
||
<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">×</span>
|
||
</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<!-- 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>
|
||
function openPdfInNewTab(pdfUrl) {
|
||
window.open(pdfUrl, '_blank');
|
||
}
|
||
</script>
|
||
<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"] ],
|
||
"columnDefs": [{ "targets": [actionColumnIndex], "orderable": false }]
|
||
// Other DataTables configuration options
|
||
});
|
||
});
|
||
</script>
|
||
<script>
|
||
|
||
$(document).on('click', '.preview-pdf', function() {
|
||
var invoiceId = $(this).data('invoice-id');
|
||
|
||
// 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
|
||
// console.log(response);
|
||
$('#pdfPreviewModal .modal-body').html(response);
|
||
$('#downloadPdfButton').attr('href', '<?= base_url("generate_invoice_pdf/") ?>' + invoiceId);
|
||
$('#printPdfButton').val(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() {
|
||
var invoiceId = $(this).val();
|
||
$.ajax({
|
||
url: '<?= base_url('generate_invoice_print_preview/') ?>' + invoiceId,
|
||
type: 'GET',
|
||
dataType: 'html',
|
||
success: function(response) {
|
||
|
||
var modifiedContent = '<html><head><title>Print Preview</title><style>body { font-size: 8px; } .watermark { font-family:math; position: fixed;top:29%;left: 9%;transform: rotate(-50deg);font-size: 300px;opacity: 0.2;}</style></head><body>' + response + '</body></html>';
|
||
|
||
var printWindow = window.open('', '_blank');
|
||
|
||
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>
|
||
|
||
|