added material category addition in form -vadivel J

This commit is contained in:
vadivel J 2024-10-04 16:57:07 +05:30
parent a36060177b
commit 5c9d1bac14
3 changed files with 127 additions and 1 deletions

View File

@ -62,6 +62,7 @@ $routes->match(['GET', 'POST', 'PUT', 'DELETE'],'rawmaterialListing/(:num)', 'Ra
$routes->post('materialExist','Rawmaterialdetails::checkmaterial');
$routes->get('viewRawmaterial','Rawmaterialdetails::viewRawmaterial');
$routes->post('rawmaterialdetails/editRawmaterial', 'Rawmaterialdetails::editRawmaterial');
$routes->post('rawmaterialdetails/addMaterialCategories', 'Rawmaterialdetails::addMaterialCategories');
$routes->get('exportmaterial' , 'Rawmaterialdetails::exportmaterial');
$routes->get('rawmaterialdetailsautocomplete' , 'Rawmaterialdetails::autocomplete');

View File

@ -313,6 +313,29 @@ class Rawmaterialdetails extends BaseController
}
function addMaterialCategories(){
$data['category_name']=$this->request->getpost('category_name');
$insertResult=$this->materialCategories_model->insert($data);
if ($insertResult) {
// Send a success response as JSON
return $this->response->setJSON([
'status' => '201',
'message' => 'Category added successfully',
]);
} else {
// Send an error response as JSON
return $this->response->setJSON([
'status' => '400',
'message' => 'Failed to add category',
]);
}
}
function autocomplete()
{

View File

@ -68,7 +68,12 @@
</div>
<div class=" col-md-3">
<label class="col-form-label" for="MatCate">Material Caterogy<span class="badge">*</span></label>
<label class="col-form-label" for="MatCate">Material Caterogy
<span class="badge">*</span></label>
<i type="button" class="fe-plus-circle" id="addMaterialCaterogyModalButton"
style="font-size: 16px; color:rgb(15, 155, 218);" data-toggle="modal" data-target="#addMaterialCaterogyModal"
title="Add Material Caterogy">
</i>
<select class="form-control select2" required id="MatCate" name="MatCate">
<option value="" required>Select Material Caterogy </option>
<?php
@ -186,6 +191,55 @@
</div> <!-- content -->
</div>
<!-- Modal -->
<div class="modal fade" id="addMaterialCaterogyModal" tabindex="-1" aria-labelledby="addMaterialCaterogyModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addMaterialCaterogyModalLabel">Add Material Category</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form id="addMaterialCategoryForm">
<div class="form-group">
<label for="materialCategoryInput">Material Category</label>
<input type="text" class="form-control" id="materialCategoryInput" placeholder="Enter material category">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" onclick="addMaterialCategory()">Save Category</button>
</div>
</div>
</div>
</div>
<script src="<?php echo base_url(); ?>public/assets/js/addUser.js" type="text/javascript"></script>
<script>
//var tempARRAY = [];
@ -308,5 +362,53 @@
$("#MaterialType").focus();
return false;
}
}
</script>
<script>
function addMaterialCategory (){
$('#materialCategoryInput').val()
let materialCategory = $('#materialCategoryInput').val().trim();
if (materialCategory.length <= 2) {
alert('Material Category should have more than 2 letters.');
return false;
}
if (materialCategory.length > 20) {
alert('Material Category should have fewer than 20 letters.');
return false;
}
$.ajax({
url: "<?php echo base_url('/rawmaterialdetails/addMaterialCategories'); ?>",
type: 'POST',
data: {
category_name: materialCategory
},
success: function(response) {
if(response.status=="201"){
$("#addMaterialCaterogyModal").modal('hide');
$("#MatCate").append(`<option value="${materialCategory}" selected > ${materialCategory} </option>`)
}else{
$("#addMaterialCaterogyModal").modal('hide');
alert('Error Adding Category..!!');
}
},
error: function(xhr, status, error) {
// Handle errors
alert('Error adding category');
console.log(error);
}
});
}
</script>