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

280 lines
13 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">Manufacturer List</h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="">
<a href="#" data-toggle="modal" data-target="#manufacturer_modal" class="btn btn-primary waves-effect" onclick="clearDetials(this)"> Add Manufacturer</a>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<table id="datatable-manufacturer" class="table table-striped dt-responsive nowrap w-100" style="width:100% !important;text-align: center;width: 100%;">
<thead>
<tr>
<th>Manufacturer </th>
<th>Quality</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($manufacturer as $index => $item):
$color = '';
if($item['isactive'] == 0){
$color ='red';
}?>
<tr class="manufacturer_tr_<?php echo $index+1; ?>" style="color:<?php echo $color; ?>" >
<td class="manufacturer_name"><?php echo $item['manufacturer_name']; ?></td>
<td class="quality"><?php echo $item['quality']; ?></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">
<?php if($item['isactive'] == 1){ ?>
<a data-toggle="modal" data-target="#manufacturer_modal" data-value="<?php echo $item['manufacturer_id']; ?>" class="dropdown-item edit-button" onclick="editManufacturer(this), datatableManufacturer('manufacturer_tr_<?php echo $index+1; ?>')"><i class="ri-pencil-line mr-2 text-muted font-18 vertical-middle" ></i>Edit</a>
<a href="<?= "product_index/" . $item['manufacturer_id']; ?>" class="dropdown-item view-list-button" title="Model List" onclick="datatableManufacturer('manufacturer_tr_<?php echo $index+1; ?>')">
<i class="ri-list-check-2 mr-2 text-muted font-18 vertical-middle" ></i>Product List
</a> <?php } if($item['isactive'] == 1): ?>
<a class="dropdown-item" data-id="<?php echo $item['manufacturer_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Deactivate" onclick="statusChange(this), datatableManufacturer('manufacturer_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 $item['manufacturer_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Activate" onclick="statusChange(this), datatableManufacturer('manufacturer_tr_<?php echo $index+1; ?>')" ><i class="fa fa-user mr-2" style="font-size:20px"></i>Activate</a>
<?php endif; ?> </div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Start Biake Mnufacturer Create Pop-UP -->
<div id="manufacturer_modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="text-center mt-2 mb-4">
<h4 id="form_add_edit">Add Manufacturer</h4>
</div>
<form id="model_form_data" class="px-3">
<div class="form-group">
<label for="manufacturername">Manufacturer Name </label>
<input type="text" id="manufacturer_id" hidden>
<input class="form-control" type="text" id="manufacturer_name" required="" placeholder="Manufacturer Name....">
</div>
<div class="form-group">
<label for="manufacturername">Quality</label>
<select name="quality" id="quality" class="form-control" style="border-color: lightgray;color: #6c757d;" required="true">
<option value="Q1">Q1</option>
<option value="Q2">Q2</option>
<option value="Q3">Q3</option>
<option value="Q4">Q4</option>
</select>
</div>
<div class="form-group text-center">
<button class="btn btn-rounded btn-primary" id="manufacturer_submit" type="submit" onclick="submitManufacturer(this)">Submit</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- End Bike Make Create Pop-UP -->
<?php include('layout/footer.php'); ?>
<script>
function submitManufacturer(params) {
var formData = {
manufacturername: $('#manufacturer_name').val(),
quality: $('#quality').val()
};
var edit_manufacturer_id = $('#manufacturer_id').val();
if (!edit_manufacturer_id) {
edit_manufacturer_id =0;
}
if (!$('#manufacturer_name').val() || !$('#quality').val()) {
return false;
}
$('#manufacturer_submit').attr('disabled','true').text('Processing...');
$.ajax({
type: 'POST',
url: '<?php echo base_url()."create_manufacturer/"?>'+edit_manufacturer_id,
data: formData,
dataType: 'json',
success: function(response) {
console.log(response);
if (response.code === 404) {
toastr.warning(response.data, 'Warning');
$('#manufacturer_submit').attr('disabled', false).text('Submit');
return;
}
if (response.code === 200) {
$('#manufacturer_modal').modal('hide');
$('#bike_make_name').val('');
toastr.success(response.data, 'Success');
window.location.reload();
} else {
toastr.warning(response.data || "Unexpected error occurred!", 'Warning');
$('#manufacturer_submit').attr('disabled', false).text('Submit');
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
let errorMessage = "An error occurred while processing your request.";
if (xhr.responseJSON && xhr.responseJSON.data) {
errorMessage = xhr.responseJSON.data;
}
toastr.warning(errorMessage, 'Warning');
$('#manufacturer_submit').attr('disabled', false).text('Submit');
}
});
}
function editManufacturer(params) {
$('#manufacturer_id').val($(params).data('value'));
$('#form_add_edit').text('Edit Manufacturer');
var full_div = $(params).closest('tr')[0];
$('#manufacturer_name').val($(full_div).find('.manufacturer_name').text());
$('#quality').val($(full_div).find('.quality').text());
}
function clearDetials(params) {
$('#form_add_edit').text('Add Manufacturer');
$('#manufacturer_name').val('');
$('#quality').val(0);
}
</script>
<script>
var datatable_manufacturer ='';
$(document).ready(function() {
datatable_manufacturer = $('#datatable-manufacturer').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_manufacturer.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_manufacturer.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 datatableManufacturer(value) {
// console.log(value);
var currentPage = datatable_manufacturer.page.info().page;
sessionStorage.setItem('currentPage', currentPage);
sessionStorage.setItem('hightlight_tr', value);
}
function statusChange(params) {
var status = params.getAttribute('data-isactive');
var manufacturer_id = params.getAttribute('data-id');
if(status == 1){
var isactive= 0;
}else{
var isactive= 1;
}
var formData = {
manufacturer_id: manufacturer_id,
isactive: isactive
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."status_manufacturer"?>',
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>