the_mechanic/app/Views/invoice_list.php
venba-Inspriron-3558 78ba1fc582 CHANGE_Client Invoice
2025-11-13 15:28:52 +05:30

293 lines
14 KiB
PHP
Executable File

<?php include('layout/header.php'); ?>
<style>
.dataTables_wrapper button{
background: #f1f5f7;
color: #343a40;
border-width: 0;
}
.dataTables_wrapper .dt-buttons{
float:left;
}
.cancelled-status {
color: red;
}
.Draft-status {
color: blue;
}
.Approved-status {
color: green;
}
</style>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Invoices</h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class=""> <a href="<?= base_url() . "invoices/new/0"; ?>" class="btn btn-primary waves-effect"> Add Invoice </a></li>
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<!-- <h4 class="header-title">Business List</h4> -->
<table id="datatable_invoices" class="table table-striped dt-responsive nowrap w-100"
style="width:100% !important;">
<thead>
<tr>
<th>Invoice Id</th>
<th>Invoice Number</th>
<th>Vehicle Reg No</th>
<th>Client Name</th>
<th>Items</th>
<th>Qty</th>
<th>Total</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
foreach ($invoices as $index => $value) :
if ($value['isactive'] == 1) : ?>
<tr class="invoice_tr<?php echo $index+1; ?>">
<td><?= $value['invoice_id']; ?></td>
<td><?= $value['invoice_number']; ?></td>
<td><?= $value['reg_no']; ?></td>
<td><?= $value['client_name']; ?></td>
<td><?= $value['product_count'] ?? 0 ; ?></td>
<td><?= $value['product_qty'] ?? 0 ; ?></td>
<td><?= $value['total']; ?></td>
<td class="<?php if ($value['status'] == 'Cancelled') { echo 'cancelled-status'; } elseif ($value['status'] == 'Draft') { echo 'Draft-status'; } elseif ($value['status'] == 'Approved') { echo 'Approved-status';} ?>">
<?= $value['status']; ?>
</td>
<td>
<div class="btn-group dropdown">
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
<div class="dropdown-menu dropdown-menu-right">
<a href="<?= "invoices/new/" . $value['invoice_id']; ?>" class="dropdown-item edit-button" onclick="datatableInvoice('invoice_tr<?php echo $index+1; ?>')"><i class="ri-pencil-line mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<!-- <a href="<?= "invoices/delete/" . $value['invoice_id']; ?>" class="dropdown-item delete-button" onclick="datatableInvoice('invoice_tr<?php echo $index+1; ?>')"><i class="ri-delete-bin-line mr-2 text-muted font-18 vertical-middle"></i>Delete</a> -->
<a href="#" data-invoices-id="<?= $value['invoice_id']; ?>" data-enc-id="<?= base64_encode($value['invoice_id']); ?>" class="dropdown-item preview-invoice" href="#" title="Preview Invoice"><i class="ri-book-read-line mr-2 text-muted font-18 vertical-middle"></i>Preview Invoice</a>
<a href="#" data-invoices-id="<?= $value['invoice_id']; ?>" data-enc-id="<?= base64_encode($value['invoice_id']); ?>" class="dropdown-item pdf-invoice-link" href="#" title="Invoice pdf link"><i class="ri-file-copy-2-fill mr-2 text-muted font-18 vertical-middle"></i>Copy Invoice PDF as Link</a>
</div>
</div>
</td>
<?php endif?>
<?php endforeach; ?>
</tr>
</tbody>
</table>
</div> <!-- end table-responsive-->
</div>
</div> <!-- end card -->
</div> <!-- end col -->
</div>
<?php include('layout/footer.php'); ?>
<div class="modal fade" id="PreviewInvoiceModal" tabindex="-1" role="dialog" aria-labelledby="PreviewInvoiceModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<!-- <div class="modal-content" style="width: 794px; height: 1123px;"> MG-TL -->
<div class="modal-content" style="width: 794px; max-height: 1123px; overflow-y: auto;">
<div class="modal-header">
<h5 class="modal-title" id="PreviewInvoiceModalLabel"></h5>
<a href="#" class="ri-download-2-fill ml-3 text-muted font-18" id="downloadInvoiceButton" title="Download Invoice"></a>
<a href="#" class="ri-printer-fill ml-3 text-muted font-18" id="printInvoiceButton" title="Print Invoice"></a>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="font-size: 27px; margin-bottom: 2px;">
<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;">
</div>
</div>
</div>
</div>
<script>
var datatable_invoice ='';
$(document).ready(function() {
const totalColumns = $('#datatable_invoices thead th').length;
const exportColumns = [...Array(totalColumns).keys()].slice(0, -1); // Exclude last column
datatable_invoice = $('#datatable_invoices').DataTable({
"order": [[0, 'desc']], // Sort by Id (hidden column)
"dom": 'Bfrtip', // Show export buttons
"buttons": [
{extend: 'pdfHtml5', title: 'Products', text: 'PDF',exportOptions: {columns: exportColumns}},
{extend: 'print', title: 'Products', text: 'Print',exportOptions: {columns: exportColumns}},
{extend: 'copy', text: 'Copy', titleAttr: 'Copy',exportOptions: {columns: exportColumns}},
{extend: 'csv', text: 'CSV', title: 'Products',exportOptions: {columns: exportColumns}}
],
"language": {
"search": "Search: " // Customize search label
},
"columnDefs": [
{
"targets": [0], // Target the first column (Id)
"visible": false, // Hide the column
"searchable": false // Make it non-searchable (optional)
}
]
});
//Start DataTable Paging is session is set
var savedPage = sessionStorage.getItem('currentPage');
var hightlight_tr = sessionStorage.getItem('hightlight_tr');
// console.log(savedPage);
// console.log(hightlight_tr);
// Ensure savedPage is a number
savedPage = parseInt(savedPage);
// Check if savedPage is not null and adjust if necessary
if (savedPage !== null && !isNaN(savedPage)) {
// Check if the saved page number is within the bounds of the current DataTable
var totalPages = datatable_invoice.page.info().pages; // Total number of pages in the DataTable
if (savedPage >= totalPages) {
// adjust to the last page of the DataTable
savedPage = totalPages > 0 ? totalPages - 1 : 0;
}
// Move DataTable to the saved page and draw
datatable_invoice.page(savedPage).draw(false);
// Select the highlighted row
var $row = $('.' + hightlight_tr);
// Smoothly scroll to the row and center it in the viewport
$('html, body').animate({
scrollTop: $row.offset().top - ($(window).height() / 2) + ($row.height() / 2)
}, 500, function() {
// After focusing, change background color
$row.css('background', '#faf6ca');
// Remove background color after 4 seconds
setTimeout(function() {
$row.css('background', '');
}, 4000);
});
}
sessionStorage.removeItem('currentPage');
sessionStorage.removeItem('hightlight_tr');
//End DataTable Paging is session is set
})
function datatableInvoice(value) {
console.log(value);
var currentPage = datatable_invoice.page.info().page;
sessionStorage.setItem('currentPage', currentPage);
sessionStorage.setItem('hightlight_tr', value);
}
$(document).on('click', '.preview-invoice', function() {
var Id = $(this).data('invoices-id');
var encId = $(this).data('enc-id');
var link = '<?= base_url("invoices/download/") ?>' + encId;
$.ajax({
type: 'GET',
url: 'invoices/preview/'+Id,
dataType: 'json',
success: function(response) {
if (response.status == "success") {
$('#PreviewInvoiceModal').modal('show');
$('#PreviewInvoiceModalLabel').text('Invoice Preview ');
$('#PreviewInvoiceModal .modal-body').html(response.data);
$('#downloadInvoiceButton').attr('href', link);
$('#printInvoiceButton').attr('data-id', Id);
}else{
$('#PreviewInvoiceModal').modal('hide');
$('#PreviewInvoiceModalLabel').text('');
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
$('#PreviewInvoiceModal').modal('hide');
$('#PreviewInvoiceModalLabel').text('');
}
});
});
$(document).on('click', '#printInvoiceButton', function() {
var Id = $(this).data('id');
$.ajax({
type: 'GET',
url: 'invoices/preview/'+Id,
dataType: 'json',
success: function(response) {
if (response.status == "success") {
var newWin = window.open("", "_blank", "width=600,height=400");
newWin.document.write("<html><head><title>Print</title>");
newWin.document.write(`
<style>
@media print {
@page {
size: A4; /* Set default print size to A4 */
margin: 1cm; /* Set margin as per requirement */
}
body {
font-family: Arial, sans-serif;
}
}
</style>
`);
newWin.document.write("</head><body>");
newWin.document.write(response.data);
newWin.document.write("</body></html>");
newWin.document.close();
newWin.print();
newWin.close();
}else{
$('#PreviewInvoiceModal').modal('hide');
$('#PreviewInvoiceModalLabel').text('');
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
$('#PreviewInvoiceModal').modal('hide');
$('#PreviewInvoiceModalLabel').text('');
}
});
});
$(document).on('click', '.pdf-invoice-link', function(e) {
e.preventDefault();
var Id = $(this).data('invoices-id');
var encId = $(this).data('enc-id');
var link = '<?= base_url("invoices/download/") ?>' + encId;
// Copy the link to clipboard
navigator.clipboard.writeText(link).then(() => {
alert("Invoice link copied! You can paste it into WhatsApp.");
}).catch(() => {
alert("Failed to copy link.");
});
});
</script>