the_mechanic/app/Views/vendor_list.php
2025-01-04 03:07:18 +00:00

197 lines
10 KiB
PHP
Executable File

<?php include('layout/header.php'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Vendor List</h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="">
<a href="<?= base_url() . "new_vendor/0"; ?>" class="btn btn-primary waves-effect" > Add Vendor</a></li>
<!-- <li class="breadcrumb-item"><a href="javascript: void(0);">Tables</a></li>
<li class="breadcrumb-item active">Datatables</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">User List</h4> -->
<!--
<a href="<?= base_url() . "new_user/0"; ?>" class="btn btn-primary waves-effect" style="margin-top: -48px;
margin-left: 823px;"> <i class="ri-add-line"></i></a> -->
<table id="datatable-vendor" class="table dt-responsive nowrap w-100">
<thead>
<tr>
<th>Vendor Name</th>
<th>Mobile No</th>
<th>Category</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($vendor as $index => $value) :
if ($value) :
$color = '';
if($value['isactive'] == 0){
$color ='red';
}
?>
<tr class="vendor_tr_<?php echo $index+1; ?>" style="color:<?php echo $color; ?>" >
<td><?= $value['vendor_name']; ?></td>
<td><?= $value['contact_person_mobile1']; ?></td>
<td><?= $value['category']; ?></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">
<?php if($value['isactive'] == 1){ ?>
<a href="<?= "new_vendor/" . $value['vendor_id']; ?>" class="dropdown-item edit-button" onclick="datatableVendor('vendor_tr_<?php echo $index+1; ?>')"><i class="ri-pencil-line mr-2 text-muted font-18 vertical-middle" style="font-size:20px;"></i>Edit</a>
<?php } if($value['isactive'] == 1): ?>
<a class="dropdown-item" data-id="<?php echo $value['vendor_id']; ?>" data-isactive="<?php echo $value['isactive']; ?>" title="Deactivate" onclick="statusChange(this), datatableVendor('vendor_tr_<?php echo $index+1; ?>')" ><i class="fa fa-user" style="font-size:20px"></i><i class="fa fa-times mr-2 " style="font-size: x-small;" style="font-size:20px"></i>Deactivate</a>
<?php else: ?>
<a class="dropdown-item" data-id="<?php echo $value['vendor_id']; ?>" data-isactive="<?php echo $value['isactive']; ?>" title="Activate" onclick="statusChange(this), datatableVendor('vendor_tr_<?php echo $index+1; ?>')" ><i class="fa fa-user mr-2 text-muted font-18 vertical-middle" style="font-size:20px"></i>Activate</a>
<?php endif; ?> </div>
</div>
</td>
<?php endif?>
<?php endforeach; ?>
</tr>
</tbody>
</table>
</div> <!-- end table-responsive-->
</div>
</div> <!-- end card -->
</div> <!-- end col -->
<?php if (session()->getFlashdata('warning')): ?>
<script>
$(document).ready(function() {
toastr.warning("<?= session()->getFlashdata('warning'); ?>", "Warning");
});
</script>
<?php endif; ?>
<?php if (session()->getFlashdata('success')): ?>
<script>
$(document).ready(function() {
toastr.success("<?= session()->getFlashdata('success'); ?>", "Success");
});
</script>
<?php endif; ?>
<?php include('layout/footer.php'); ?> </div>
<script>
var datatable_vendor ='';
$(document).ready(function() {
datatable_vendor = $('#datatable-vendor').DataTable({
"order": [[0, 'asc']], // 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_vendor.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_vendor.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 datatableVendor(value) {
console.log(value);
var currentPage = datatable_vendor.page.info().page;
sessionStorage.setItem('currentPage', currentPage);
sessionStorage.setItem('hightlight_tr', value);
}
function statusChange(params) {
var status = params.getAttribute('data-isactive');
var vendor_id = params.getAttribute('data-id');
if(status == 1){
var isactive= 0;
}else{
var isactive= 1;
}
var formData = {
vendor_id: vendor_id,
isactive: isactive
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."status_vendor"?>',
data: formData,
dataType: 'json',
success: function(response) {
console.log(response);
if (response.status == "success") {
window.location.reload();
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
</script>