352 lines
16 KiB
PHP
Executable File
352 lines
16 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">Product List <?= isset($manufacturer_id) && !empty($manufacturer_id) ? $manufacturer_name : '' ?></h4>
|
|
<div class="page-title-right">
|
|
<ol class="breadcrumb m-0">
|
|
<?php if(!$manufacturer_id) { ?>
|
|
<li class="">
|
|
<a href="<?= base_url() . "product_categories"; ?>" class="btn btn-primary waves-effect">Categories View</a>
|
|
<a href="<?= base_url() . "add_new_product"; ?>" class="btn btn-primary waves-effect"> Add New Product</a>
|
|
</li>
|
|
<?php } ?>
|
|
</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-buttons2" class="table table-striped dt-responsive nowrap w-100"
|
|
style="width:100% !important;">
|
|
<thead>
|
|
<tr >
|
|
<td style="border: none;">
|
|
<input class="form-control form-control-sm" type="text" id="searchSKUId" placeholder=" SKU Id">
|
|
</td>
|
|
<td style="border: none;">
|
|
<input class="form-control form-control-sm" type="text" id="searchProductName" placeholder=" Product Name">
|
|
</td>
|
|
<td style="border: none;">
|
|
<input class="form-control form-control-sm" type="text" id="searchManufacturerName" placeholder=" Manufacturer Name">
|
|
</td>
|
|
<td>
|
|
<input class="form-control form-control-sm" type="text" id="searchCategory" placeholder=" Category">
|
|
</td>
|
|
<td>
|
|
<input class="form-control form-control-sm" type="text" id="searchUnitPrice" placeholder=" Unit Price">
|
|
</td>
|
|
<td>
|
|
<input class="form-control form-control-sm" type="text" id="searchQtyStock" placeholder=" Qty in Stock">
|
|
</td>
|
|
<td>
|
|
<input class="form-control form-control-sm" type="text" id="searchRackNo" placeholder=" Rack No">
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<th>SKU Id</th>
|
|
<th>Product Name</th>
|
|
<th>Manufacturer Name</th>
|
|
<th>Category</th>
|
|
<th>Unit Price</th>
|
|
<th>Qty in Stock</th>
|
|
<th>Rack No</th>
|
|
<?php if(!$manufacturer_id) { ?><th>Actions</th><?php } ?>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($products as $index => $value) :
|
|
if ($value) :
|
|
$color = '';
|
|
if($value['isactive'] == 0){
|
|
$color ='red';
|
|
}?>
|
|
<tr class="product_tr_<?php echo $index+1; ?>" style="color:<?php echo $color; ?>" >
|
|
<td><?= $value['sku_id']; ?></td>
|
|
<td>
|
|
<!-- <i class="ri-information-fill product_addtional_details" id="<?= $value['product_id']; ?>" ></i> -->
|
|
<?= $value['product_name']; ?>
|
|
|
|
</td>
|
|
<td><?= isset($value['manufacturer_name']) ? $value['manufacturer_name'] : ''; ?></td>
|
|
<td><?= $value['product_category']; ?></td>
|
|
<td><?= number_format($value['unit_price']); ?></td>
|
|
<td><?= $value['qty_stock']; ?></td>
|
|
<td><?= $value['rack_number']; ?></td>
|
|
<!-- Call the model method -->
|
|
<?php if(!$manufacturer_id) { ?>
|
|
<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 ">
|
|
<?php if($value['isactive'] == 1){ ?>
|
|
<a href="<?= "edit_product/" . $value['product_id']; ?>" class="dropdown-item edit-button" onclick="setSessionPagination('product_tr_<?php echo $index+1; ?>')"><i class="ri-pencil-line mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
|
|
<?php } if($value['isactive'] == 1): ?>
|
|
<a class="dropdown-item" data-id="<?php echo $value['product_id']; ?>" data-isactive="<?php echo $value['isactive']; ?>" title="Deactivate" onclick="statusChange(this), setSessionPagination('product_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['product_id']; ?>" data-isactive="<?php echo $value['isactive']; ?>" title="Activate" onclick="statusChange(this), setSessionPagination('product_tr_<?php echo $index+1; ?>')" ><i class="fa fa-user mr-2" style="font-size:20px"></i>Activate</a>
|
|
<?php endif; ?> </div>
|
|
</div>
|
|
</td>
|
|
<?php } ?>
|
|
<?php endif?>
|
|
<?php endforeach; ?>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div> <!-- end table-responsive-->
|
|
</div>
|
|
</div> <!-- end card -->
|
|
</div> <!-- end col -->
|
|
</div>
|
|
|
|
|
|
|
|
<div id="accordion-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content p-0">
|
|
<div id="accordion">
|
|
<div class="card mb-0">
|
|
<div class="card-header" id="headingOne">
|
|
<h5 class="m-0">
|
|
<a href="#collapseOne" class="text-dark" data-toggle="collapse" aria-expanded="true" aria-controls="collapseOne">
|
|
Product supporting Models
|
|
</a>
|
|
</h5>
|
|
</div>
|
|
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
|
|
<div class="card-body" id="modelNames">
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card mb-0">
|
|
<div class="card-header" id="headingTwo">
|
|
<h5 class="m-0">
|
|
<a href="#collapseTwo" class="collapsed text-dark" data-toggle="collapse" aria-expanded="false" aria-controls="collapseTwo">
|
|
Additional name of the products
|
|
</a>
|
|
</h5>
|
|
</div>
|
|
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
|
|
<div class="card-body" id="additionalNames">
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div><!-- /.modal-content -->
|
|
</div><!-- /.modal-dialog -->
|
|
</div><!-- /.modal -->
|
|
|
|
|
|
|
|
<?php include('layout/footer.php'); ?>
|
|
|
|
<script>
|
|
var data_table_set ='';
|
|
$(document).ready(function() {
|
|
data_table_set = $('#datatable-buttons2').DataTable({
|
|
"order": [[1, 'asc']], // Set initial sorting to descending on the first column
|
|
"dom": 'Bfrtip', // Show export buttons
|
|
"buttons": [{extend: 'pdfHtml5',title: 'Products', text: 'PDF', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6] }},
|
|
{extend: 'print',title: 'Products',text: 'Print', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6] }},
|
|
{extend: 'copy',text: 'Copy', titleAttr: 'Copy', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6] }},
|
|
{extend: 'csv',text: 'CSV', title: 'Products', exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6] }}],
|
|
"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 = data_table_set.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
|
|
data_table_set.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 setSessionPagination(value) {
|
|
|
|
// console.log(value);
|
|
|
|
// var currentPage = data_table_set.page.info().page;
|
|
// sessionStorage.setItem('currentPage', currentPage);
|
|
// sessionStorage.setItem('hightlight_tr', value);
|
|
|
|
// }
|
|
|
|
// Event listener for input changes in search fields
|
|
$('input[type="text"]').on('input', function() {
|
|
var searchTextSKU = $('#searchSKUId').val().toLowerCase();
|
|
var searchTextProductName = $('#searchProductName').val().toLowerCase();
|
|
var searchTextManufacturerName = $('#searchManufacturerName').val().toLowerCase();
|
|
var searchTextCategory = $('#searchCategory').val().toLowerCase();
|
|
var searchTextUnitPrice = $('#searchUnitPrice').val().toLowerCase();
|
|
var searchTextQtyStock = $('#searchQtyStock').val().toLowerCase();
|
|
var searchTextRackNo = $('#searchRackNo').val().toLowerCase();
|
|
|
|
$('#datatable-buttons2 tbody tr').each(function() {
|
|
var cellTextSKU = $(this).find('td:nth-child(1)').text().toLowerCase();
|
|
var cellTextProductName = $(this).find('td:nth-child(2)').text().toLowerCase();
|
|
var cellTextManufacturerName = $(this).find('td:nth-child(3)').text().toLowerCase();
|
|
var cellTextCategory = $(this).find('td:nth-child(4)').text().toLowerCase();
|
|
var cellTextUnitPrice = $(this).find('td:nth-child(5)').text().toLowerCase();
|
|
var cellTextQtyStock = $(this).find('td:nth-child(6)').text().toLowerCase();
|
|
var cellTextRackNo = $(this).find('td:nth-child(7)').text().toLowerCase();
|
|
|
|
// Show the row if all search fields match
|
|
if (cellTextSKU.includes(searchTextSKU) &&
|
|
cellTextProductName.includes(searchTextProductName) &&
|
|
cellTextManufacturerName.includes(searchTextManufacturerName) &&
|
|
cellTextCategory.includes(searchTextCategory) &&
|
|
cellTextUnitPrice.includes(searchTextUnitPrice) &&
|
|
cellTextQtyStock.includes(searchTextQtyStock) &&
|
|
cellTextRackNo.includes(searchTextRackNo)) {
|
|
$(this).show();
|
|
} else { $(this).hide();}
|
|
});
|
|
});
|
|
});
|
|
|
|
function setSessionPagination(value) {
|
|
var currentPage = data_table_set.page.info().page;
|
|
sessionStorage.setItem('currentPage', currentPage);
|
|
sessionStorage.setItem('hightlight_tr', value);
|
|
}
|
|
|
|
function statusChange(params) {
|
|
var status = params.getAttribute('data-isactive');
|
|
var product_id = params.getAttribute('data-id');
|
|
if(status == 1){
|
|
var isactive= 0;
|
|
}else{
|
|
var isactive= 1;
|
|
}
|
|
|
|
var formData = {
|
|
product_id: product_id,
|
|
isactive: isactive
|
|
};
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '<?php echo base_url()."status_product"?>',
|
|
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);
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
|
|
$('.product_addtional_details').click(function () {
|
|
var product_id = $(this).attr('id');
|
|
|
|
$.ajax({
|
|
url: '<?php echo base_url()."get_product_addtional_details/"?>'+product_id,
|
|
method: 'GET',
|
|
success: function(response) {
|
|
var data = JSON.parse(response);
|
|
|
|
if (data) {
|
|
|
|
var modelNames = '';
|
|
data.modelNames.forEach(function(name) {
|
|
modelNames += name.model_name+' , ';
|
|
});
|
|
$("#modelNames").html(modelNames);
|
|
|
|
var additionalNames = '';
|
|
data.additionalNames.forEach(function(name) {
|
|
additionalNames += name.additional_product_name+' , ';
|
|
});
|
|
$("#additionalNames").html(additionalNames);
|
|
|
|
|
|
|
|
$('#accordion-modal').modal('show');
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('Error occurred while deleting the item:', error);
|
|
}
|
|
});
|
|
|
|
})
|
|
</script>
|
|
|