FIX_product category changes
This commit is contained in:
parent
9e1dc43772
commit
0fb4554e4e
@ -228,3 +228,10 @@ $routes->get('dashboard', 'Users::dashboard');
|
||||
$routes->post('status_outsource', 'Outsourcing::status_outsource');
|
||||
|
||||
// Complaint End's
|
||||
|
||||
// product category //
|
||||
$routes->get('product_category_index', 'ProductCategory::index');
|
||||
$routes->post('create_product_category/(:any)', 'ProductCategory::create_product_category/$1');
|
||||
$routes->post('status_product_category', 'ProductCategory::status_product_category');
|
||||
|
||||
// product category End's //
|
||||
101
app/Controllers/ProductCategory.php
Normal file
101
app/Controllers/ProductCategory.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\ProductCategoryModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
|
||||
class ProductCategory extends BaseController
|
||||
{
|
||||
|
||||
public $session;
|
||||
use ResponseTrait;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->session = session();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// print_r($this->session->get());die;
|
||||
$ProductCategoryModel = new ProductCategoryModel();
|
||||
$productcategory = $ProductCategoryModel->orderBy('product_category_id')->findAll();
|
||||
$data['productcategory']=$productcategory;
|
||||
return view('product_category_list',$data);
|
||||
}
|
||||
|
||||
public function create_product_category($product_category_id)
|
||||
{
|
||||
$logged_user = $this->session->get('logged_user');
|
||||
try {
|
||||
$product_category_name = $this->request->getPost('product_category_name');
|
||||
$ProductCategoryModel = new ProductCategoryModel();
|
||||
$data = [
|
||||
'product_category_name' => $product_category_name
|
||||
];
|
||||
if (!$product_category_id) {
|
||||
try {
|
||||
$data['business_id'] = $this->session->get('logged_user_business_id');
|
||||
$data['created_by'] = $logged_user;
|
||||
$inserted = $ProductCategoryModel->insert($data);
|
||||
} catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) {
|
||||
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $e->getMessage()],200);
|
||||
}
|
||||
|
||||
if ($inserted) {
|
||||
$result = $data;
|
||||
$product_category_list = $ProductCategoryModel->orderBy('product_category_id','asc')->findAll();
|
||||
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result,'product_category_list'=>$product_category_list],200);
|
||||
} else {
|
||||
$result = "No Match's";
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
|
||||
}
|
||||
}else{
|
||||
$data['updated_by'] = $logged_user;
|
||||
$updated = $ProductCategoryModel->update($product_category_id,$data);
|
||||
if ($updated) {
|
||||
$result = $data;
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
|
||||
} else {
|
||||
$result = "No Match's";
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e],500);
|
||||
}
|
||||
}
|
||||
|
||||
public function status_product_category()
|
||||
{
|
||||
|
||||
try {
|
||||
$product_category_id = $this->request->getPost('productcategory_id');
|
||||
$isactive = $this->request->getPost('isactive');
|
||||
$updated_by = $this->session->get('logged_user');
|
||||
|
||||
$ProductCategoryModel = new ProductCategoryModel();
|
||||
$data = [
|
||||
'isactive' => $isactive,
|
||||
'updated_by' => $updated_by
|
||||
];
|
||||
$updated = $ProductCategoryModel->update($product_category_id, $data);
|
||||
|
||||
if ($updated) {
|
||||
$result = $data;
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
|
||||
} else {
|
||||
$result = "No Match's";
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -7,6 +7,7 @@ use App\Models\ProductModel;
|
||||
use App\Models\VendorModel;
|
||||
use App\Models\BikemodelsModel;
|
||||
use App\Models\ManufacturerModel;
|
||||
use App\Models\ProductCategoryModel;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
@ -75,6 +76,9 @@ class Products extends BaseController
|
||||
|
||||
$data['manufacturers']=$ManufacturerModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('manufacturer_name')->findAll();
|
||||
$data['page_name']="Add Product";
|
||||
$ProductCategoryModel = new ProductCategoryModel();
|
||||
$productcategory = $ProductCategoryModel->orderBy('product_category_id')->findAll();
|
||||
$data['productcategory']=$productcategory;
|
||||
$data['vendorsProduct'] =[];
|
||||
} else if ($product_id !== '0') {
|
||||
$data['page_name']="Edit Product";
|
||||
@ -130,7 +134,10 @@ class Products extends BaseController
|
||||
// print_r($data);die;
|
||||
}
|
||||
$data['product_id'] = $product_id;
|
||||
|
||||
$ProductCategoryModel = new ProductCategoryModel();
|
||||
$productcategory = $ProductCategoryModel->orderBy('product_category_id')->findAll();
|
||||
$data['productcategory']=$productcategory;
|
||||
// print_r($data);die;
|
||||
// echo "<pre>";
|
||||
// print_r($data['manufacturers']);die;
|
||||
|
||||
@ -154,7 +161,7 @@ class Products extends BaseController
|
||||
|
||||
$data = [
|
||||
'product_name' => $this->request->getPost('productname'),
|
||||
'product_category' => $this->request->getPost('productcategory'),
|
||||
'product_category' => $this->request->getPost('hiddenproductcategory'),
|
||||
'mfr_part_no' => $this->request->getPost('mfr_part_no'),
|
||||
|
||||
'unit_price' => $this->request->getPost('unit_price'),
|
||||
@ -186,7 +193,7 @@ class Products extends BaseController
|
||||
|
||||
$product_id = $this->request->getPost('product_id');
|
||||
|
||||
|
||||
// print_r($data);die;
|
||||
if (!empty($product_id)) {
|
||||
|
||||
$ProductModel->update($product_id, $data);
|
||||
|
||||
9
app/Models/ProductCategoryModel.php
Normal file
9
app/Models/ProductCategoryModel.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use CodeIgniter\Model;
|
||||
class ProductCategoryModel extends Model
|
||||
{
|
||||
protected $table = 'product_category';
|
||||
protected $primaryKey = 'product_category_id';
|
||||
protected $allowedFields = ['product_category_id','product_category_name','business_id','created_at','created_by','updated_at','updated_by','isactive'];
|
||||
}
|
||||
@ -326,6 +326,12 @@
|
||||
<span> Make & Models</span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="<?php echo base_url('product_category_index') ?>">
|
||||
<i class="fas fa-luggage-cart"></i>
|
||||
<span>Product Category</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
|
||||
275
app/Views/product_category_list.php
Normal file
275
app/Views/product_category_list.php
Normal file
@ -0,0 +1,275 @@
|
||||
<?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">Product Category List</h4>
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="">
|
||||
<a href="#" data-toggle="modal" data-target="#product_category_modal" class="btn btn-primary waves-effect" onclick="clearDetials(this)">
|
||||
Add Product Category
|
||||
</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-productcategory" class="table table-striped dt-responsive nowrap w-100" style="width:100% !important;text-align: center;width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Product Category</th>
|
||||
<th>Status</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($productcategory as $index => $item): ?>
|
||||
<tr class="productcategory_tr_<?php echo $index+1; ?>">
|
||||
<td class="productcategory"><?php echo $item['product_category_name']; ?></td>
|
||||
<td>
|
||||
<?php if($item['isactive'] == 1): ?>
|
||||
<span style="color:green">Active</span>
|
||||
<?php else: ?>
|
||||
<span style="color:red">Inactive</span>
|
||||
<?php endif; ?>
|
||||
</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 data-toggle="modal" data-target="#product_category_modal" data-value="<?php echo $item['product_category_id']; ?>" class="dropdown-item edit-button" onclick="editProductCategory(this), datatablePC('productcategory_tr_<?php echo $index+1; ?>')"><i class="ri-pencil-line mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
|
||||
<?php if($item['isactive'] == 1): ?>
|
||||
<a class="dropdown-item" data-id="<?php echo $item['product_category_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Deactivate" onclick="statusChange(this), datatablePC('productcategory_tr_<?php echo $index+1; ?>')" ><i class=" ri-close-circle-line mr-2 text-muted font-18 vertical-middle" style="font-size:20px"></i><span class="vertical-middle"> Deactivate </span> </a>
|
||||
<?php else: ?>
|
||||
<a class="dropdown-item" data-id="<?php echo $item['product_category_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Activate" onclick="statusChange(this), datatablePC('productcategory_tr_<?php echo $index+1; ?>')" ><i class="ri-checkbox-circle-line mr-2 text-muted font-18 vertical-middle" style="font-size:20px"></i><span class="vertical-middle"> Activate </span> </a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Start Product Category Add/edit Pop-UP -->
|
||||
<div id="product_category_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 Product Category </h4>
|
||||
</div>
|
||||
|
||||
<!-- <form id="model_form_data" class="px-3"> -->
|
||||
|
||||
<div class="form-group">
|
||||
<label for="productcategoryname">Product Category Name </label>
|
||||
<input type="text" id="product_category_id" hidden>
|
||||
<input class="form-control" type="text" id="product_category_name" required="" placeholder="Product Category Name....">
|
||||
</div>
|
||||
|
||||
<div class="form-group text-center">
|
||||
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitproductcategory(this)">Submit</button>
|
||||
</div>
|
||||
|
||||
<!-- </form> -->
|
||||
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
<!-- End Product Category Pop-UP -->
|
||||
|
||||
|
||||
<?php include('layout/footer.php'); ?>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
function setproductcategoryname(params) {
|
||||
|
||||
$('#product_category_id').val(params.getAttribute('data-id'));
|
||||
$('#product_category_name').val(params.getAttribute('data-value'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
function submitproductcategory(params) {
|
||||
// Get the value of the Product Category Name input field
|
||||
var productcategoryname = $('#product_category_name').val().trim();
|
||||
|
||||
// Check if Product Category Name is empty
|
||||
if (productcategoryname === '') {
|
||||
// Display error message
|
||||
toastr.error('Please enter a Product Category Name.', 'Error');
|
||||
return; // Stop further execution of the function
|
||||
}
|
||||
var formData = {
|
||||
product_category_name: $('#product_category_name').val()
|
||||
};
|
||||
var product_category_id = $('#product_category_id').val();
|
||||
if (!product_category_id) {
|
||||
product_category_id =0;
|
||||
}
|
||||
console.log(formData);
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'create_product_category/'+product_category_id,
|
||||
data: formData,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.status == "failed") {
|
||||
toastr.warning(response.data, 'Warning');
|
||||
}else{
|
||||
$('#product_category_modal').modal('hide');
|
||||
$('#product_category_name').val('');
|
||||
toastr.success(response.data, 'Success');
|
||||
console.log(response);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error response here
|
||||
console.error(xhr.responseText);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function editProductCategory(params) {
|
||||
$('#product_category_id').val($(params).data('value'));
|
||||
$('#form_add_edit').text('Edit Product Category');
|
||||
var full_div = $(params).closest('tr')[0];
|
||||
$('#product_category_name').val($(full_div).find('.productcategory').text());
|
||||
}
|
||||
|
||||
function clearDetials(params) {
|
||||
$('#form_add_edit').text('Add Product Category');
|
||||
$('#product_category_name').val('');
|
||||
}
|
||||
|
||||
function statusChange(params) {
|
||||
var status = params.getAttribute('data-isactive');
|
||||
var productcategory_id = params.getAttribute('data-id');
|
||||
// var logged_user = sessionStorage.getItem('logged_user');
|
||||
if(status == 1){
|
||||
var isactive= 0;
|
||||
}else{
|
||||
var isactive= 1;
|
||||
}
|
||||
|
||||
var formData = {
|
||||
productcategory_id: productcategory_id,
|
||||
isactive: isactive
|
||||
};
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '<?php echo base_url()."status_product_category"?>',
|
||||
data: formData,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
if (response.status == "failed") {
|
||||
toastr.warning(response.data, 'Warning');
|
||||
}else{
|
||||
$('#product_category_modal').modal('hide');
|
||||
$('#product_category_name').val('');
|
||||
toastr.success(response.data, 'Success');
|
||||
console.log(response);
|
||||
window.location.reload();
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error response here
|
||||
console.error(xhr.responseText);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
var datatable_make ='';
|
||||
$(document).ready(function() {
|
||||
|
||||
datatable_make = $('#datatable-productcategory').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_make.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_make.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');
|
||||
sessionStorage.removeItem('hightlight_tr');
|
||||
//End DataTable Paging is session is set
|
||||
|
||||
|
||||
|
||||
})
|
||||
function datatablePC(value) {
|
||||
console.log(value);
|
||||
|
||||
var currentPage = datatable_make.page.info().page;
|
||||
sessionStorage.setItem('currentPage', currentPage);
|
||||
sessionStorage.setItem('hightlight_tr', value);
|
||||
|
||||
}
|
||||
</script>
|
||||
@ -103,7 +103,7 @@
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="inputEmail4" class="col-form-label">Product Category<span class="text-danger">*</span></label>
|
||||
<select class="form-control status-select SelExample" name="productcategory" required data-toggle="select2">
|
||||
<!-- <select class="form-control status-select SelExample" name="productcategory" required data-toggle="select2">
|
||||
<option value="" >Select Category</option>
|
||||
<option value="Bearings" <?= (isset($products['product_category']) && $products['product_category'] == 'Tanks') ? 'selected' : '' ?>>Tanks</option>
|
||||
<option value="Bearings" <?= (isset($products['product_category']) && $products['product_category'] == 'Bearings') ? 'selected' : '' ?>>Bearings</option>
|
||||
@ -154,8 +154,34 @@
|
||||
<option value="Grip" <?= (isset($products['product_category']) && $products['product_category'] == 'Grip') ? 'selected' : '' ?>>Grip</option>
|
||||
<option value="Rubber" <?= (isset($products['product_category']) && $products['product_category'] == 'Rubber') ? 'selected' : '' ?>>Rubber</option>
|
||||
<option value="Cables" <?= (isset($products['product_category']) && $products['product_category'] == 'Cables') ? 'selected' : '' ?>>Cables</option>
|
||||
</select>
|
||||
|
||||
</select> -->
|
||||
<select class="form-control status-select SelExample" name="productcategory" required data-toggle="select2">
|
||||
<option value="">Select Category</option>
|
||||
<?php
|
||||
if (isset($products['product_id']) && $products['product_id']) {
|
||||
foreach ($productcategory as $category) :
|
||||
$isDisabled = ((int)$category['isactive'] == 0);
|
||||
$isSelected = (isset($products['product_category']) && $products['product_category'] === $category['product_category_name']); ?>
|
||||
|
||||
<option value="<?= $category['product_category_name'] ?>"
|
||||
<?php if ($isSelected) echo "selected"; ?>
|
||||
<?= $isDisabled ? 'disabled' : ''; ?>>
|
||||
<?= $category['product_category_name'] . ($isDisabled ? " (Disabled)" : ""); ?>
|
||||
</option>
|
||||
|
||||
<?php endforeach;
|
||||
} else {
|
||||
foreach ($productcategory as $category) :
|
||||
if ((int)$category['isactive'] == 1) { ?>
|
||||
<option value="<?= $category['product_category_name'] ?>">
|
||||
<?= $category['product_category_name']; ?>
|
||||
</option>
|
||||
<?php }
|
||||
endforeach;
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<input type="hidden" class="form-control" name="hiddenproductcategory" value="<?= isset($products['product_category']) ? $products['product_category'] : '' ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="inputEmail4" class="col-form-label">Specification<span class="text-danger"></span></label>
|
||||
@ -369,6 +395,10 @@ $(document).ready(function() {
|
||||
$("input[name='total_amount'], select[name='tax']").change(function() {
|
||||
unitPriceReverseCalculation();
|
||||
});
|
||||
$("select[name='productcategory']").change(function() {
|
||||
// alert($(this).val());
|
||||
$("input[name='hiddenproductcategory']").val($(this).val());
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user