465 lines
20 KiB
PHP
Executable File
465 lines
20 KiB
PHP
Executable File
<style>
|
||
.autocomplete-suggestion {
|
||
cursor: pointer;
|
||
background-color: skyblue;
|
||
/* background-color: darkgrey; */
|
||
outline: 1px solid slategrey;
|
||
}
|
||
</style>
|
||
<script>
|
||
$(function() {
|
||
$("#Date").datepicker({
|
||
//minDate :'now',
|
||
//maxDate : 'now',
|
||
dateFormat: 'dd-mm-yy',
|
||
changeMonth: true,
|
||
changeYear: true,
|
||
yearRange: '-100:+1'
|
||
});
|
||
});
|
||
</script>
|
||
<script type="text/javascript" src="<?php echo base_url(); ?>public/assets/Autocomplete/jquery.autocomplete.js"></script>
|
||
|
||
|
||
<div class="content-page">
|
||
<div class="content">
|
||
<!-- Start Content-->
|
||
<div class="container-fluid">
|
||
<!-- start page title -->
|
||
<div class="row">
|
||
<div class="col-12">
|
||
<div class="page-title-box page-title-box-alt">
|
||
<h4 class="page-title">Add Material Details</h4>
|
||
<a class="btn btn-secondary" href="<?php echo base_url(); ?>rawmaterialListing"><span class="bold">Back</span></a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<!-- end page title -->
|
||
<div class="row">
|
||
<div class="col-12">
|
||
<div class="card">
|
||
<div class="card-body">
|
||
<div class="row">
|
||
<div class="col-12">
|
||
<div class="p-2">
|
||
<form role="form" id="addMaterialForm" action="<?php echo base_url() ?>addNewRawmaterial" method="post">
|
||
<div class="box-body">
|
||
<!-- Supplier Information -->
|
||
<div class="col-md-12" style="margin-bottom: 27px;">
|
||
<div class="form-row">
|
||
<div class=" col-md-3">
|
||
<label class="col-form-label" for="MaterialName">Material Name<span class="badge">*</span></label>
|
||
<input type="text" class="form-control required " required id="MaterialName" name="MaterialName" maxlength="255">
|
||
</div>
|
||
<div class=" col-md-3">
|
||
<label class="col-form-label" for="MaterialType">Material Type<span class="badge">*</span></label>
|
||
<select class="form-control select2" required id="MaterialType" name="MaterialType">
|
||
<option value="" required>Select Material Type</option>
|
||
<?php
|
||
if (!empty($material)) {
|
||
foreach ($material as $SID) {
|
||
?>
|
||
<option value="<?php echo $SID->ConfigValue ?>"><?php echo $SID->ConfigValue ?></option>
|
||
<?php
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class=" col-md-3">
|
||
<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
|
||
if (!empty($materialCategoryList)) {
|
||
foreach ($materialCategoryList as $record) {
|
||
?>
|
||
<option value="<?php echo $record['category_name']?>"><?php echo $record['category_name']?></option>
|
||
<?php
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="col-md-3">
|
||
<label class="col-form-label" for="UnitofMeasurement">Unit of Measurement<span class="badge">*</span></label>
|
||
<select class="form-control required select2" id="UOM" name="UOM">
|
||
<option value="" required>Select UOM</option>
|
||
<?php
|
||
if (!empty($UOM)) {
|
||
foreach ($UOM as $SID) {
|
||
?>
|
||
<option value="<?php echo $SID->ConfigValue; ?>"><?php echo $SID->ConfigValue ?>
|
||
<?php
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="form-row" style="margin-top:20px">
|
||
<div class="col-md-3">
|
||
<label for="HSNcode">HSN code</label>
|
||
<input type="text" class="form-control" id="HSNcode" onkeypress="return isNumberKey(event)" name="HSNcode" maxlength="8">
|
||
</div>
|
||
<div class="col-md-3">
|
||
<label for="OpeningStock">Opening Stock</label>
|
||
<input type="text" class="form-control" id="openstock" name="openstock" maxlength="255">
|
||
</div>
|
||
<div class="col-md-3">
|
||
<label for="OpenStockDate">Open Stock Date</label>
|
||
<?php
|
||
$data = array('name' => 'Date', 'value' => set_value('Date'), 'id' => 'Date', 'class' => 'form-control', 'onkeypress' => 'return false;');
|
||
echo form_input($data);
|
||
?>
|
||
</div>
|
||
<div class="col-md-3">
|
||
<label for="ReorderLevel">Reorder Level</label>
|
||
<input type="text" class="form-control" id="reorder" name="reorder" maxlength="255">
|
||
</div>
|
||
</div>
|
||
<div class="form-row" style="margin-top:20px">
|
||
<div class="col-md-3">
|
||
<label for="Remarks">Remarks</label>
|
||
<input type="text" class="form-control" id="remarks" name="remarks" maxlength="255">
|
||
</div>
|
||
</div>
|
||
|
||
|
||
|
||
</div>
|
||
<div class="col-md-12 text-right">
|
||
<input type="reset" id="reset" class="btn btn-reset" style="background-color: red;color: white; margin-right: 15px;width: 80px;" value="Reset" />
|
||
<input type="button" id="addMaterialBtnId" value="Submit" class="btn btn-success">
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<?php
|
||
$listErrors = session()->getFlashdata('listErrors');
|
||
if ($listErrors) {
|
||
?>
|
||
<div class="row">
|
||
<div class="col-md-12">
|
||
<div class="alert alert-danger alert-dismissable">
|
||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||
<?php echo session()->getFlashdata('listErrors'); ?>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php } ?>
|
||
|
||
</div>
|
||
<?php
|
||
helper('form');
|
||
$error = session()->getFlashdata('error');
|
||
if ($error) {
|
||
?>
|
||
<div class="alert alert-danger alert-dismissable">
|
||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||
<?php echo session()->getFlashdata('error'); ?>
|
||
</div>
|
||
<?php } ?>
|
||
|
||
<?php
|
||
$success = session()->getFlashdata('success');
|
||
if ($success) {
|
||
?>
|
||
<div class="alert alert-success alert-dismissable">
|
||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||
<?php echo session()->getFlashdata('success'); ?>
|
||
</div>
|
||
<?php } ?>
|
||
<!-- end row -->
|
||
</div>
|
||
</div> <!-- end card -->
|
||
</div><!-- end col -->
|
||
</div>
|
||
<!-- end row -->
|
||
</div> <!-- container -->
|
||
</div> <!-- content -->
|
||
</div>
|
||
|
||
|
||
|
||
|
||
|
||
<!-- addMaterialCaterogyModal -->
|
||
|
||
<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">×</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 = [];
|
||
$(document).ready(function() {
|
||
$("#MaterialType").select2();
|
||
$('#MatCate').select2();
|
||
|
||
// $("#MaterialCategory").select2();
|
||
$("#UOM").select2();
|
||
// $('#MatCate').autocomplete({
|
||
|
||
// onSearchStart: function(query) {
|
||
// //alert(query);
|
||
// $('#MatCate').autocomplete("option", "minLength", 0);
|
||
// },
|
||
|
||
// serviceUrl: "<?php echo base_url(); ?>rawmaterialdetailsautocomplete",
|
||
// onSelect: function(suggestion) {
|
||
// var data = suggestion.ConfigValue;
|
||
|
||
// }
|
||
// });
|
||
|
||
});
|
||
|
||
|
||
|
||
function isNumberKey(evt) {
|
||
var charCode = (evt.which) ? evt.which : evt.keyCode;
|
||
if (charCode != 46 && charCode > 31 &&
|
||
(charCode < 48 || charCode > 57))
|
||
return false;
|
||
|
||
return true;
|
||
}
|
||
|
||
function onlyAlphabets(evt) {
|
||
var charCode;
|
||
if (window.event)
|
||
charCode = window.event.keyCode; //for IE
|
||
else
|
||
charCode = evt.which; //for firefox
|
||
if (charCode == 32) //for <space> symbol
|
||
return true;
|
||
if (charCode > 31 && charCode < 65) //for characters before 'A' in ASCII Table
|
||
return false;
|
||
if (charCode > 90 && charCode < 97) //for characters between 'Z' and 'a' in ASCII Table
|
||
return false;
|
||
if (charCode > 122) //for characters beyond 'z' in ASCII Table
|
||
return false;
|
||
return true;
|
||
}
|
||
|
||
|
||
|
||
|
||
$('#addMaterialBtnId').click(function() {
|
||
|
||
|
||
//validate
|
||
|
||
let validation = Validate();
|
||
|
||
if(!validation){
|
||
return false;
|
||
}
|
||
|
||
var materialName = $('#MaterialName').val().trim();
|
||
var materialCode = '';
|
||
var materialCategory = $('#MatCate').val();
|
||
if(materialName == ''){
|
||
return;
|
||
}
|
||
|
||
var material = materialName.replace(/ /g, '');
|
||
|
||
$('#loader').show();
|
||
$.ajax({
|
||
data: {
|
||
materialCode,
|
||
materialName,materialCategory
|
||
},
|
||
type: "POST",
|
||
url: "<?php echo base_url(); ?>materialExist",
|
||
success: function(data) {
|
||
|
||
if (data && data.length >= 1) {
|
||
$('#loader').hide();
|
||
|
||
if(data[0]?.IsActive == 1){
|
||
alert('Material name already existed ! ');
|
||
$('#MaterialName').val('');
|
||
}else{
|
||
alert('Material name already existing in the deleted section.!!');
|
||
$('#MaterialName').val('');
|
||
}
|
||
|
||
var related_name = "" ;
|
||
$.each(data, function(i, obj) {
|
||
|
||
related_name += obj.MaterialCode + " - " + obj.MaterialName + " - " + obj.MaterialType + " - " + obj.Category + "\n";
|
||
|
||
});
|
||
|
||
alert("'" + materialName + "' - related materials are , " + " \n \n" + related_name);
|
||
$("#MaterialName").val('');
|
||
$("#MaterialName").focus();
|
||
|
||
|
||
} else{
|
||
console.log("Material name is unique");
|
||
$('#loader').hide();
|
||
|
||
$('#addMaterialForm').submit();
|
||
}
|
||
|
||
},
|
||
error: function(error) {
|
||
$('#loader').hide();
|
||
alert("Error Occur" ,error);
|
||
},
|
||
complete: function(){
|
||
$('#loader').hide();
|
||
console.log("Ajax completed..!!");
|
||
}
|
||
});
|
||
});
|
||
|
||
function Validate() {
|
||
|
||
if ($("#MaterialName").val().length < 1) {
|
||
alert('Please Enter MaterialName');
|
||
$("#MaterialName").focus();
|
||
return false;
|
||
}
|
||
|
||
if ($("option:selected", $("#UOM")).val() == "") {
|
||
alert('Please Select UOM ');
|
||
$("#UOM").focus();
|
||
return false;
|
||
}
|
||
if ($("option:selected", $("#MaterialCategory")).val() == "") {
|
||
alert('Please Select Material Category');
|
||
$("#MaterialCategory").focus();
|
||
return false;
|
||
}
|
||
if ($("option:selected", $("#MaterialType")).val() == "") {
|
||
alert('Please Select Material Type');
|
||
$("#MaterialType").focus();
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
</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 if(response.status=="409"){
|
||
|
||
$("#addMaterialCaterogyModal").modal('hide');
|
||
|
||
$('#MatCate').val(materialCategory);
|
||
|
||
$('#MatCate').trigger('change');
|
||
|
||
setTimeout(()=>{ alert(`${response.message}`) },1000)
|
||
|
||
|
||
}
|
||
else{
|
||
$("#addMaterialCaterogyModal").modal('hide');
|
||
|
||
setTimeout(()=>{ alert('Error Adding Category..!!'); },1000)
|
||
|
||
}
|
||
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
// Handle errors
|
||
alert('Error adding category');
|
||
console.log(error);
|
||
}
|
||
});
|
||
|
||
|
||
}
|
||
</script>
|
||
|
||
|
||
<script>
|
||
|
||
$(document).on('keydown', function(event) {
|
||
if (event.key === 'Enter') {
|
||
event.preventDefault(); // Prevent default Enter key behavior
|
||
}
|
||
});
|
||
|
||
</script>
|