the_mechanic/app/Views/purchase_list.php

295 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;
}
.created-status {
color: blue;
}
.paid-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">Purchase Order List </h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class=""> <a href="<?= base_url() . "new_purchase/0"; ?>" class="btn btn-primary waves-effect"> Add Purchase Order</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-purchase-order" class="table table-striped dt-responsive nowrap w-100"
style="width:100% !important;">
<thead>
<tr>
<th>PO Id</th>
<th>Order Number</th>
<th>Vendor Name</th>
<th>Order Date</th>
<th>Contact Details</th>
<!-- <th>Contact Person Mobile</th> -->
<th>Items Details</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($purchase as $index => $value) :
if ($value['isactive'] == 1) : ?>
<tr class="purchase_tr_<?php echo $index+1;?>">
<td><?= $value['purchase_order_id']; ?></td>
<td><?= $value['order_number']; ?></td>
<td><?= $value['vendor_name']; ?></td>
<td><?= date('j F Y', strtotime($value['order_date'])); ?></td>
<td><?= $value['contact_person_name']; ?><br>
<?= $value['contact_person_mobile']; ?>
</td>
<td><?= "Product : <b>".$value['product_count']." </b>"; ?><br>
<?= "Tot Qty : <b>".$value['purchase_qty']." </b>"; ?><br>
<?= (isset($value['received_qty']) && $value['received_qty'] != '')? "Rcvd Qty : <b>".$value['received_qty']." </b>" : "Rcvd Qty : <b>0 </b>"; ?>
</td>
<td class="<?php
if ($value['status'] == 'Cancel') {
echo 'cancelled-status';
} elseif ($value['status'] == 'Draft') {
echo 'created-status';
} elseif ($value['status'] == 'Received') {
echo 'paid-status';
}
?>">
<?= $value['status']; ?>
</td>
<!-- Call the model method -->
<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_purchase/" . $value['purchase_order_id']; ?>" class="edit-button dropdown-item" onclick="datatablePurchaseOrder('purchase_tr_<?php echo $index+1; ?>')"><i class="ri-pencil-line"></i>Edit</a>
<a href="<?= "delete_purchase/" . $value['purchase_order_id']; ?>" class="delete-button dropdown-item" onclick="datatablePurchaseOrder('purchase_tr_<?php echo $index+1; ?>')"><i class="ri-delete-bin-line"></i>Delete</a>
<?php if($value['status'] != "PO Issued") { ?>
<a href="<?= "reorder_purchase/" . $value['purchase_order_id']; ?>" class="dropdown-item" onclick="datatablePurchaseOrder('purchase_tr_<?php echo $index+1; ?>')"><i class="fa fa-retweet"></i>Pending Reorder</a>
<?php } ?>
<a href="#" data-purchase_order-id="<?= $value['purchase_order_id']; ?>" class="dropdown-item preview-purchaseorder" href="#" title="Preview PurchaseOrder"><i class="ri-book-read-line"></i>Preview PO</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="PreviewPurchaseOrderModal" tabindex="-1" role="dialog" aria-labelledby="PreviewPurchaseOrderModalLabel" 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="PreviewPurchaseOrderModalLabel"></h5>
<a href="#" class="ri-download-2-fill ml-3 text-muted font-18" id="downloadPurchaseButton" title="Download Purchase"></a>
<a href="#" class="ri-printer-fill ml-3 text-muted font-18" id="printPurchaseButton" 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_purchase_order ='';
$(document).ready(function() {
datatable_purchase_order = $('#datatable-purchase-order').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
}, "columnDefs": [
{
"targets": [0], // Target the first column (PO Id)
"visible": false, // Hide the column
"searchable": false // Make it non-searchable (optional)
}
]
});
$(document).on('click', '.preview-purchaseorder', function() {
var Id = $(this).data('purchase_order-id');
console.log(Id);
$.ajax({
type: 'GET',
url: 'preview_purchase/'+Id,
dataType: 'json',
success: function(response) {
if (response.status == "success") {
$('#PreviewPurchaseOrderModal').modal('show');
$('#PreviewPurchaseOrderModalLabel').text('Purchase Order Preview ');
$('#PreviewPurchaseOrderModal .modal-body').html(response.data);
$('#downloadPurchaseButton').attr('href', '<?= base_url("download_purchase/") ?>' + Id);
$('#printPurchaseButton').attr('data-id', Id);
}else{
$('#PreviewPurchaseOrderModal').modal('hide');
$('#PreviewPurchaseOrderModalLabel').text('');
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
$('#PreviewPurchaseOrderModal').modal('hide');
$('#PreviewPurchaseOrderModalLabel').text('');
}
});
});
$(document).on('click', '#printPurchaseButton', function() {
var Id = $(this).data('id');
$.ajax({
type: 'GET',
url: 'preview_purchase/'+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{
$('#PreviewPurchaseModal').modal('hide');
$('#PreviewPurchaseModalLabel').text('');
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
$('#PreviewPurchaseModal').modal('hide');
$('#PreviewPurchaseModalLabel').text('');
}
});
});
//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_purchase_order.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_purchase_order.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 datatablePurchaseOrder(value) {
console.log(value);
var currentPage = datatable_purchase_order.page.info().page;
sessionStorage.setItem('currentPage', currentPage);
sessionStorage.setItem('hightlight_tr', value);
}
</script>
<script>
<?php if(isset($_SESSION['mail_status']) && $_SESSION['mail_status'] == 200) { ?>
toastr.success("Mail Send Successfully", 'Success');
<?php } else if(isset($_SESSION['mail_status']) && $_SESSION['mail_status'] != 200) { ?>
toastr.error('Mail Send Attempt Unsuccessful', 'Error');
<?php } ?>
</script>