the_mechanic/app/Views/jobs_list.php

360 lines
17 KiB
PHP
Executable File

<?php include('layout/header.php'); ?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
<style>
.dataTables_wrapper button{
background: #f1f5f7;
color: #343a40;
border-width: 0;
}
.dataTables_wrapper .dt-buttons{
float:left;
}
.issued-status{
color:red;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<?php
$admins = $logged_user_role == 'Administrator' || $logged_user_role == 'Job Card Manager' || $logged_user_role == "Floor Manager";
?>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Job Card List</h4>
<?php if($admins) { ?>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="">
<a href="<?= base_url() . "download_os"; ?>" class="btn btn-secondary waves-effect">Out Source</a>
<a href="<?= base_url() . "new_jobcard/0"; ?>" class="btn btn-primary waves-effect">New Job Card</a>
</li>
</ol>
</div>
<?php } ?>
</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-jobcard" class="table table-striped dt-responsive nowrap w-100"
style="width:100% !important;">
<thead>
<tr>
<th>Order Number</th>
<th>Vehicle No</th>
<th>Client</th>
<th>Estimate</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($jobs as $index => $value) : if ($value['isactive'] == 1) : ?>
<tr class="job_tr_<?php echo $index+1; ?>">
<td><?= $value['order_number']; ?></td>
<td><?= $value['reg_no']; ?></td>
<td><?= $value['client_name']; ?><br><?= $value['client_mobile_no']; ?></td>
<td><?= $value['total']; ?></td>
<td class="<?php
if ($value['status'] == 'Issued') {
echo 'issued-status';
} elseif ($value['status'] == 'Created') {
echo 'created-status';
} elseif ($value['status'] == 'Paid') {
echo 'paid-status';
}
?>"><?= ($value['is_rework'] == 1) ? 'Rework/'.$value['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="<?= "new_jobcard/" . $value['job_card_id']; ?>" class="dropdown-item edit-button" onclick="datatableJobCard('job_tr_<?php echo $index+1; ?>')"><i class="ri-pencil-line mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<?php if($admins) { ?>
<a href="#" data-job-card-id="<?= $value['job_card_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="<?= "download_jobcard_invoice/" . $value['job_card_id']; ?>" class="dropdown-item edit-button"><i class="ri-download-2-fill mr-2 text-muted font-18 vertical-middle"></i>Download Invoice</a> -->
<?php } ?>
<a href="#" data-job-card-id="<?= $value['job_card_id']; ?>" class="dropdown-item preview-jobcard" href="#" title="Preview Jobcard"><i class="ri-book-read-line mr-2 text-muted font-18 vertical-middle"></i>Preview Jobcard</a>
<!-- <a href="<?= base_url() ."download_jobcard/" . $value['job_card_id']; ?>" class="dropdown-item download-button"><i class="ri-download-2-fill mr-2 text-muted font-18 vertical-middle"></i>Download Jobcard</a> -->
<?php if($value['status'] == 'Paid' && $admins && $value['is_rework'] == 0) { ?>
<a href="<?= "new_jobcard/" . $value['job_card_id'] . "/re-work" ?>" class="dropdown-item edit-button"><i class="ri-registered-fill mr-2 text-muted font-18 vertical-middle"></i>Rework</a>
<?php } ?>
<?php if($value['os_count'] > 0) { ?>
<a href="<?= "individual_download_os/" . $value['job_card_id'] ?>" class="dropdown-item edit-button"><i class="ri-download-fill mr-2 text-muted font-18 vertical-middle"></i>Out Source</a>
<?php } ?>
</div>
</div>
</td>
<?php endif?>
<?php endforeach; ?>
</tr>
</tbody>
</table>
</div> <!-- end table-responsive-->
</div>
</div> <!-- end card -->
</div> <!-- end col -->
</div>
<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;">
<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>
<div class="modal fade" id="PreviewJobcardModal" tabindex="-1" role="dialog" aria-labelledby="PreviewJobcardModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content" style="width: 794px; height: 1123px;">
<div class="modal-header">
<h5 class="modal-title" id="PreviewJobcardModalLabel"></h5>
<a href="#" class="ri-download-2-fill ml-3 text-muted font-18" id="downloadJobcardButton" title="Download Jobcard"></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>
<?php include('layout/footer.php'); ?>
<script>
var datatable_jobcard ='';
$(document).ready(function() {
datatable_jobcard= $('#datatable-jobcard').DataTable({
"order": [[0, 'desc']], // Set initial sorting to descending on the first column
"dom": 'Bfrtip', // Show export buttons
"buttons": [{extend: 'pdfHtml5',title: 'Products', text: 'PDF',},
{extend: 'print',title: 'Products',text: 'Print',},
{extend: 'copy',text: 'Copy', titleAttr: 'Copy',},
{extend: 'csv',text: 'CSV', title: 'Products', }],
"language": {
"search": "Search: " // Customize search label
},
});
//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_jobcard.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_jobcard.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');
//End DataTable Paging is session is set
})
function datatableJobCard(value) {
console.log(value);
var currentPage = datatable_jobcard.page.info().page;
sessionStorage.setItem('currentPage', currentPage);
sessionStorage.setItem('hightlight_tr', value);
}
</script>
<script>
$(document).ready(function() {
var msg = "<?= session()->getFlashdata('download_os'); ?>";
if (msg) {
toastr.warning(msg);
}
})
</script>
<script>
$(document).on('click', '.preview-invoice', function() {
var jobCardId = $(this).data('job-card-id');
$.ajax({
type: 'GET',
url: 'preview_jobcard_invoice/'+jobCardId,
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', '<?= base_url("download_jobcard_invoice/") ?>' + jobCardId);
$('#printInvoiceButton').attr('data-id', jobCardId);
}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', '.preview-jobcard', function() {
var jobCardId = $(this).data('job-card-id');
$.ajax({
type: 'GET',
url: 'preview_jobcard/'+jobCardId,
dataType: 'json',
success: function(response) {
if (response.status == "success") {
$('#PreviewJobcardModal').modal('show');
$('#PreviewJobcardModalLabel').text('Preview Jobcard Modal');
$('#PreviewJobcardModal .modal-body').html(response.data);
$('#downloadJobcardButton').attr('href', '<?= base_url("download_jobcard/") ?>' + jobCardId);
}else{
$('#PreviewJobcardModal').modal('hide');
$('#PreviewJobcardModalLabel').text('');
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
$('#PreviewJobcardModal').modal('hide');
$('#PreviewJobcardModalLabel').text('');
}
});
});
$(document).on('click', '#printInvoiceButton', function() {
var jobCardId = $(this).data('id');
$.ajax({
type: 'GET',
url: 'preview_jobcard_invoice/'+jobCardId,
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', '.print-jobcard', function() {
var jobCardId = $(this).data('job-card-id');
$.ajax({
type: 'GET',
url: 'preview_jobcard/'+jobCardId,
dataType: 'json',
success: function(response) {
if (response.status == "success") {
$('#PreviewJobcardModal').modal('show');
$('#PreviewJobcardModalLabel').text('Preview Jobcard Modal');
$('#PreviewJobcardModal .modal-body').html(response.data);
$('#downloadJobcardButton').attr('href', '<?= base_url("download_jobcard/") ?>' + jobCardId);
}else{
$('#PreviewJobcardModal').modal('hide');
$('#PreviewJobcardModalLabel').text('');
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
$('#PreviewJobcardModal').modal('hide');
$('#PreviewJobcardModalLabel').text('');
}
});
});
</script>