ria/app/Views/requisitionform.php
2024-12-02 18:19:37 +05:30

833 lines
25 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$EmpID = "";
$Designation = "";
$DepartmentName = "";
$FirstName = "";
if (!empty($Emp)) {
foreach ($Emp as $Emp) {
$EmpID = $Emp->EmpID;
$FirstName = $Emp->FirstName;
$Designation = $Emp->Designation;
$DepartmentName = $Emp->DepartmentName;
}
}
?>
<style>
.btn-soft-primary {
color: white;
background-color: rgb(42, 206, 150);
border-color: rgb(42, 206, 150);
}
.btn-soft-primary:hover {
background-color: rgb(32, 176, 130); /* Slightly darker shade for hover */
border-color: rgb(32, 176, 130);
}
.th{
font-size: 14px;
text-align:center !important ;
}
</style>
<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><?= "Add Requisition"; ?></h4>
<a href="<?php echo base_url(); ?>Requisition"><button type="button" class="btn btn-secondary">Back</button></a>
</div>
</div>
</div>
<!-- end page title -->
<!-- Form row -->
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<?php $attributes = array('class' => 'form-label-left requistion ', 'name' => 'requistion', 'id' => 'requistion');
echo form_open(base_url() . 'Requisitionform::SearchRequistList', $attributes);
?>
<div class="form-row">
<div class="form-group col-md-3">
<label for="EmpID" class="col-form-label">Requested By<span class="text-danger">*</span></label>
<?php
$RequestByOpt = array("-1" => 'Select Requested By');
if (!empty($RequestBy)) {
foreach ($RequestBy as $EID) :
$RequestByOpt[$EID->EmpID] = $EID->Full_Name;
endforeach;
}
echo form_dropdown('EmpID', $RequestByOpt, set_value('EmpID'), 'id="EmpID" class = "form-control searchabledropdown" data-toggle="select2" required="true"');
?>
</div>
<div class="form-group col-md-3">
<label for="RequestType" class="col-form-label">Request Type<span class="text-danger">*</span></label>
<?php
$options = array("-1" => 'Select Request Type');
if (!empty($RequestType)) {
foreach ($RequestType as $RID) :
$options[$RID->ConfigValue] = $RID->ConfigValue;
endforeach;
}
echo form_dropdown('RequestType', $options, set_value('ConfigValue'), 'id="RequestType" class = "form-control searchabledropdown" data-toggle="select2"', 'required="true"');
?>
</div>
<div class="form-group col-md-3">
<label for="DeptName" class="col-form-label">Department Name</label>
<?php
$data = array('name' => 'DeptName', 'value' => set_value('DeptName', $DepartmentName), 'id' => 'DeptName', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
<div class="form-group col-md-3">
<label for="Designation" class="col-form-label">Designation</label>
<?php
$data = array('name' => 'Designation', 'value' => set_value('Designation', $Designation), 'id' => 'Designation', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="CostCenter" class="col-form-label">Cost Center Name<span class="text-danger">*</span></label>
<?php
$Costs = array("-1" => 'Select Cost Center Name');
if (!empty($CostCenter)) {
foreach ($CostCenter as $SID) :
$Costs[$SID->CostCenterCode] = $SID->CostCenterCode . '-' . $SID->CostCenterName;
endforeach;
}
echo form_dropdown(
'CostCenter',
$Costs,
set_value('CostCenter'),
'class="form-control searchabledropdown" id="CostCenter" data-toggle="select2"'
);
?>
</div>
<div class="form-group col-md-3" id="DisplayScheduleDiv" style="display:none;">
<label for="ScheduleType" class="col-form-label">Service Schedule Type</label>
<?php
$Schdule = array("One Time", "Recurring");
if (!empty($Schdule)) {
foreach ($Schdule as $Sch) :
$SchType[$Sch] = $Sch;
endforeach;
}
echo form_dropdown('ScheduleType', $SchType, set_value('ScheduleType'), 'id="ScheduleType" class = "form-control searchabledropdown" data-toggle="select2"');
?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<a onclick="return validateBeforeAdd();" class="btn btn-primary waves-effect float-right">Add Line Item</a>
</div>
</div>
<div class="form-row">
<div class="table-responsive">
<table id="Items" class="table table-bordered table-hover">
<thead>
<tr>
<th class="th">SNo</th>
<th class="th">Material Code</th>
<th class="th" style="text-align:left !important;">Material Name</th>
<th class="th">Uom</th>
<th class="th">Quantity</th>
<th class="th">Action</th>
</tr>
</thead>
<tbody id="tempAppend"></tbody>
</table>
</div> <!-- end table-responsive-->
</div>
<div class="form-row">
<input type="hidden" name="txtRowCount" id="txtRowCount" />
<input type="hidden" name="txtDeletedRow" id="txtDeletedRow" />
<?php
$data = array('name' => 'ServiceNo', 'value' => set_value('ServiceNo'), 'id' => 'ServiceNo', 'class' => 'form-control num', 'onkeypress' => 'return isNumberKey(event);');
echo form_hidden($data);
?>
<div style="display:none;">
<label for="ServiceOptions" class="col-form-label">Service Period Option</label>
<?php
if (!empty($ServiceOption)) {
foreach ($ServiceOption as $SerOption) :
$ServiceOptions[$SerOption->ConfigValue] = $SerOption->ConfigValue;
endforeach;
}
echo form_dropdown('ServiceOptions', $ServiceOptions, set_value('ServiceOptions'), 'id="ServiceOptions"', 'class = "form-control searchabledropdown"', 'data-toggle="select2"');
?>
</div>
</div>
<div class="form-row float-right">
<input type="reset" value="Reset" class="btn btn-secondary waves-effect" onclick="window.location.reload();">&nbsp;&nbsp;
<a class="btn btn-primary waves-effect Save" ID="Save" onclick="Save()">&nbsp;&nbsp;<span class="bold">Save As Draft</span></a>&nbsp;&nbsp;
<input type="submit" class="btn btn-soft-primary waves-effect waves-light" value="Approved">
</div>
<?php echo form_close(); ?>
</div>
</div>
</div>
</div>
<!-- end row -->
</div> <!-- container -->
<div id="add-req-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">
<div class="modal-header">
<h4 class="modal-title">Add Line Item</h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
</div>
<div class="modal-body p-4">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="MaterialCode" class="control-label">Material Code</label>
<?php
$options = array("0" => 'Material Code');
//print_r( $options);
if (!empty($MaterialList)) {
foreach ($MaterialList as $MID) :
$options[$MID->MaterialCode] = $MID->MaterialCode . ' ' . ' - ' . ' ' . $MID->MaterialName;
endforeach;
}
echo form_dropdown('MaterialCode', $options, set_value('MaterialCode'), 'id="MaterialCode" class="form-control searchabledropdown" ');
?>
</div>
</div>
</div>
<div class="row" id="otherDescription" style="display:none;">
<div class="col-md-12">
<div class="form-group">
<label for="otherD" class="control-label">Other Description</label>
<?php
$data = array('name' => 'otherD', 'value' => set_value('otherD'), 'id' => 'otherD', 'class' => 'form-control', 'rows' => '5', 'cols' => '70', 'maxlength' => '500');
echo Form_textarea($data);
?>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="UOM" class="control-label">UOM</label>
<?php
$data = array('name' => 'UOM', 'value' => set_value('UOM'), 'id' => 'UOM', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="Quantity" class="control-label">Quantity</label>
<?php $data = array('name' => 'Quantity', 'value' => set_value('Quantity'), 'id' => 'Quantity', 'class' => 'form-control num', 'onkeypress' => 'return isNumberKey(event)', 'min' => '1', 'maxlength' => '20');
echo form_input($data); ?>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="Description" class="control-label">Description</label>
<?php
$data = array('name' => 'Description', 'value' => set_value('Description'), 'id' => 'Description', 'class' => 'form-control', 'readonly' => 'true', 'style' => 'max-height: 50px;');
echo form_textarea($data);
?>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect"
data-dismiss="modal" value="Cancel">Cancel</button>
<button type="button"
class="btn btn-info waves-effect waves-light addClick">Add</button>
</div>
</div>
</div>
</div><!-- /.modal -->
<div id="edit-req-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">
<div class="modal-header">
<h4 class="modal-title">Edit Line Item</h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
</div>
<div class="modal-body p-4">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="EditMaterialCode" class="control-label">Material Code</label>
<?php
$data = array('value' => set_value('EditMaterialCode'), 'id' => 'EditMaterialCode', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12" id="EditotherDescription">
<div class="form-group">
<label for="EditotherD"
class="control-label">Other Description</label>
<?php
$data = array('name' => 'EditotherD', 'value' => set_value('EditotherD'), 'id' => 'EditotherD', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="EditUOM"
class="control-label">UOM</label>
<?php
$data = array('name' => 'EditUOM', 'value' => set_value('EditUOM'), 'id' => 'EditUOM', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="EditQuantity"
class="control-label">Quantity</label>
<?php
$data = array('name' => 'EditQuantity', 'value' => set_value('EditQuantity'), 'id' => 'EditQuantity', 'class' => 'form-control num', 'onkeypress' => 'return isNumberKey(event)', 'min' => '1', 'maxlength' => '20');
echo form_input($data);
?>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="EditDescription" class="control-label">Description</label>
<?php
$data = array('name' => 'EditDescription', 'value' => set_value('EditDescription'), 'id' => 'EditDescription', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<input type="hidden" name="Edituserid" id="Edituserid" />
<button type="button" class="btn btn-secondary waves-effect"
data-dismiss="modal" value="Cancel">Cancel</button>
<button type="button"
class="btn btn-info waves-effect waves-light EditClick">Edit</button>
</div>
</div>
</div>
</div><!-- /.modal -->
</div> <!-- content -->
</div>
<script>
$('#otherDescription').hide();
$('#EditotherDescription').hide();
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() {
//Initialize Select2 Elements
$(".searchabledropdown").select2();
$('#CostCenter').change(function() {
var id = $('#CostCenter').val();
var ReqType = $('#RequestType').val();
if (id == '-1' && ReqType == '-1') {
alert('Please select the Requistion Type');
$('#CostCenter').val("-1");
return false;
}
});
$('#RequestType').change(function() {
$('#txtRowCount').val('');
$('#txtDeletedRow').val('');
$("#Description").val('');
$("#UOM").val('');
// Get the ID of the first option
var firstOptionId = $('#CostCenter option:first').val();
// Reset the Select2 dropdown to the first option
$('#CostCenter').val(firstOptionId).select2('data', {
id: firstOptionId,
text: $('#CostCenter option:selected').text()
});
removeHiddenRows($('#Items').find('tr').length);
$('#tempAppend').empty();
var id = $('#RequestType').val();
if (id != '-1') {
// $('#content').loader('show');
$.ajax({
data: {
id: id
},
dataType: 'json',
type: "POST",
url: "<?php echo base_url(); ?>getMaterialCode",
success: function(json) {
console.log(json);
// $('#content').loader('hide');
$("#MaterialCode").empty();
$("#MaterialCode").append(json.Material);
// $("#Description").val(json.MaterialName);
// $("#UOM").val(json.UOM);
if (id != 'SERVICE') {
$('#DisplayScheduleDiv').hide();
} else {
$('#DisplayScheduleDiv').show();
}
}
});
//$('#content').loader('hide');
} else {
alert('Please select the RequestType');
return false;
}
});
$('#MaterialCode').change(function() {
var id = $('#MaterialCode').val();
var value = $("#MaterialCode option:selected").text();
answer = value.replace(/[^a-z]/gi, '');
var checkanswer = answer.toUpperCase();
// alert(checkanswer)
$("#Description").val('');
$("#UOM").val('');
if (id != '-1') {
if ((checkanswer != 'SERVICE')) {
// $('#content').loader('show');
$.ajax({
data: {
id: id
},
dataType: 'json',
type: "POST",
url: "<?php echo base_url(); ?>getMaterialDetails",
success: function(json) {
// $('#content').loader('hide');
//alert(json.MatDetail);
$("#Description").val(json.MatDetail[0]['MaterialName']);
$("#UOM").val(json.MatDetail[0]['UOM']);
}
});
} else {
$('#otherDescription').show();
}
//$('#content').loader('hide');
} else {
alert('Please select the RequestType');
return false;
}
});
});
var index = '1';
function removeHiddenRows(rowcount) {
var step;
if (rowcount > 2) {
for (step = 1; step < rowcount; step++) {
var td = document.getElementById(step);
td.parentNode.removeChild(td);
$("#MaterialCode" + step).remove();
$("#Description" + step).remove();
$("#UOM" + step).remove();
$("#Quantity" + step).remove();
index = '1';
}
}
}
</script>
<script>
function validateBeforeAdd() {
// var isChecked = $('#IsOpenOrder').is(':checked');
// isChecked ? $('#Quantity').val(0).prop('readonly', true).prop('required', false)
// : $('#Quantity').val('').prop('readonly', false).prop('required', true);
if ($("#RequestType").val() == '-1') {
alert('Please select the Request Type ');
$("#RequestType").focus();
return false;
} else if ($("#CostCenter").val() == '-1') {
alert('Please select the Cost center');
$("#CostCenter").focus();
return false;
} else {
$('#add-req-modal').modal('show');
$('#otherDescription').hide();
}
}
</script>
<script>
function Save() {
var id = '<?php echo REQ_DRAFT; ?>'
if (validate()) {
if (document.getElementById('Items').rows.length < 0) {
alert('Please Select Line item to Create Requisition');
$('#Deliverydt').focus();
return false;
} else {
var serviceSchedule = '';
var servicePeriod = '';
var noOfService = '';
if ($('#RequestType').val() == 'SERVICE') {
if ($('#ScheduleType').val() == 'Recurring') {
serviceSchedule = $('#ScheduleType').val();
servicePeriod = $('#ServiceOptions').val();
noOfService = $('#ServiceNo').val();
} else {
serviceSchedule = $('#ScheduleType').val();
servicePeriod = '';
noOfService = 0;
}
} else {
var serviceSchedule = '';
var servicePeriod = '';
noOfService = '';
}
// $('#content').loader('show');
$.ajax({
type: "POST",
data: $('.requistion').serialize() + "&serviceSchedule=" + serviceSchedule + "&servicePeriod=" + servicePeriod + "&noOfService=" + noOfService + "&ID=" + id,
url: "<?php echo base_url() ?>addNewRequisition",
success: function(data) {
if (data) {
// $('#content').loader('hide');
alert(data);
$('#txtRowCount').val('');
$('#txtDeletedRow').val('');
window.location = "Requisition";
} else {
alert("Error");
}
}
});
}
}
}
</script>
<script>
function validate() {
if ($("option:selected", $("#RequestType")).val() == '-1') {
alert('Please Select Request Type ');
return false;
} else if ($("option:selected", $("#EmpID")).val() == '-1') {
alert('Please Select Request by');
return false;
} else if ($("#txtRowCount").val().length < 1) {
alert('Please Add Line Item');
return false;
} else {
return true;
}
}
</script>
<script>
function Deleterow(rowid) {
var DelRows = $('#txtDeletedRow').val();
var answer = confirm(" Do you want to delete the Item from the List?")
if (answer) {
var td = document.getElementById(rowid);
td.parentNode.removeChild(td);
if (DelRows != '') {
DelRows = DelRows + ":" + rowid;
} else {
DelRows = "0" + ":" + rowid;
}
$('#txtDeletedRow').val(DelRows);
}
}
</script>
<script>
$('.addClick').click(function() {
if ($("#MaterialCode option:selected").val() == '-1') {
alert('Please Select The MaterialCode ');
return false;
}
var qty = parseInt(document.getElementById('Quantity').value);
if (isNaN(qty) || qty < 1) {
// if (document.getElementById('Quantity').value == '') {
alert('Please Enter The Vaild Quantity');
return false;
}
if ($("#MaterialCode option:selected").val() != '-1' && $('#Quantity').val() != '') {
var temp = index;
var materialCode = $("#MaterialCode option:selected").val();
var materialName = $("#Description").val();
var uom = $("#UOM").val();
var quantity = $("#Quantity").val();
var materialdescription = $('#otherD').val();
$('#MaterialCode option[value=' + materialCode + ']').remove();
$('#Description').val('');
$('#UOM').val('');
$('#Quantity').val('');
$('#otherDescription').hide();
$('#otherD').val('');
index = parseInt(index) + 1;
var rowHtml = `<tr id="${temp}">
<td align="center">${temp}</td>
<td align="center">${materialCode}</td>
<td align="left">${materialName}</td>
<td align="center">${uom}</td>
<td align="center">${quantity}</td>
<td align="center">
<a
data-id="${temp}"
data-userid="${temp}"
data-toggle="modal"
href="#edit-req-modal"
class="edit-modal-trigger">
<i class="ri-pencil-fill" data-toggle="tooltip" title="Click here to view/Edit the ${materialCode} Material details"></i>
</a>
&nbsp;&nbsp;&nbsp;
<a href='#' onclick="Deleterow(${temp})" class="link" data-id="${temp}" data-userid="${temp}" id="Del">
<span class="ri-delete-bin-7-fill"></span>
</a>
</td>
</tr>
`;
// Append the HTML to the table body
$('#tempAppend').append(rowHtml);
var theForm = $(".requistion");
addHidden(theForm, "MaterialCode" + temp, materialCode);
addHidden(theForm, "Description" + temp, materialName);
addHidden(theForm, "UOM" + temp, uom);
addHidden(theForm, "Quantity" + temp, quantity);
addHidden(theForm, "otherD" + temp, materialdescription);
$('#txtRowCount').val(temp);
$('#add-req-modal').modal('hide');
// toastr.success('Line Item Added!', 'Success');
}
});
</script>
<script>
function addHidden(theForm, key, value) {
// Create a hidden input element, and append it to the form:
var input = document.createElement('input');
input.type = 'hidden';
input.name = key;
'name-as-seen-at-the-server';
input.id = key;
'name-as-seen-at-the-server';
input.value = value;
theForm.append(input);
}
</script>
<script>
$("#add-req-modal").on("shown.bs.modal", function(e) {
if ($("option:selected", $("#RequestType")).val() == '-1') {
alert('Please select the Request Type ');
e.close();
}
});
</script>
<script>
$(document).ready(function() {
$("#edit-req-modal").on("shown.bs.modal", function(e) {
var $triggerElement = $(e.relatedTarget);
var userid = $triggerElement.data('userid');
var $tr = $('#' + userid);
var $cells = $tr.find('td');
$('#EditMaterialCode').val($cells.eq(1).text());
$('#EditDescription').val($cells.eq(2).text());
$('#EditUOM').val($cells.eq(3).text());
$('#EditQuantity').val($cells.eq(4).text());
$('#Edituserid').val(userid);
});
});
$('.EditClick').click(function() {
var editqty = parseInt(document.getElementById('EditQuantity').value);
if (isNaN(editqty) || editqty < 1) {
// if (document.getElementById('EditQuantity').value == '') {
alert('Please Enter the Vaild Quantity');
return false;
}
if ($('#EditQuantity').val() != '') {
var edituserid = $("#Edituserid").val();
var editMaterialCode = $("#EditMaterialCode").val();
var editDescription = $("#EditDescription").val();
var editUOM = $('#EditUOM').val();
var editQuantity = $('#EditQuantity').val();
var tr = $('#' + edituserid);
var cells = tr.find('td');
cells.eq(1).text(editMaterialCode);
cells.eq(2).text(editDescription);
cells.eq(3).text(editUOM);
cells.eq(4).text(editQuantity);
$('#MaterialCode' + edituserid).val(editMaterialCode);
$('#Description' + edituserid).val(editDescription);
$('#UOM' + edituserid).val(editUOM);
$('#Quantity' + edituserid).val(editQuantity);
$('#edit-req-modal').modal('hide');
// toastr.success('Line Item Updated!', 'Success');
}
});
</script>
<script>
$(".requistion").submit(function(e) {
// var id = '<?php //echo REQ_PENDING_APPROVAL;
?>' // don't delete 22/04/2022
var id = '<?php echo REQ_APPROVED; ?>'
e.preventDefault();
if (validate()) {
if (document.getElementById('Items').rows.length < 0) {
alert('Please Select Line item to Create Requisition');
$('#Deliverydt').focus();
return false;
} else {
var serviceSchedule = '';
var servicePeriod = '';
var noOfService = '';
if ($('#RequestType').val() == 'SERVICE') {
if ($('#ScheduleType').val() == 'Recurring') {
serviceSchedule = $('#ScheduleType').val();
servicePeriod = $('#ServiceOptions').val();
noOfService = $('#ServiceNo').val();
} else {
serviceSchedule = $('#ScheduleType').val();
servicePeriod = '';
noOfService = 0;
}
} else {
var serviceSchedule = '';
var servicePeriod = '';
var noOfService = '';
}
// $('#content').loader('show');
$.ajax({
data: $('.requistion').serialize() + "&serviceSchedule=" + serviceSchedule + "&servicePeriod=" + servicePeriod + "&noOfService=" + noOfService + "&ID=" + id,
type: "POST",
url: "<?php echo base_url() ?>addNewRequisition",
success: function(data) {
if (data) {
// $('#content').loader('hide');
alert(data);
$('#txtRowCount').val('');
$('#txtDeletedRow').val('');
window.location = "Requisition";
} else {
alert("Error");
}
}
});
}
}
});
</script>
<script>
$(function() {
$('#Items').DataTable({
"paging": false,
"lengthChange": true,
"searching": false,
"ordering": false,
"info": false,
"autoWidth": true
});
});
</script>
<script>
$("#ScheduleType").change(function() {
if ($('#ScheduleType').val().trim() != 'Recurring') {
$('#ServiceNo').val('');
} else {
$('#ServiceNo').val(1);
}
});
</script>