ria/app/Views/editrequisitionform.php
2025-01-19 00:57:40 +05:30

972 lines
30 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
$ReqNo = '';
$ReqType = '';
$Requestedby = '';
$FirstName = '';
$Designation = '';
$DepartmentName = '';
$Status = '';
$CostCenterCode = '';
$RowCount = '';
$serviceSchedule = '';
$servicePeriod = '';
$noOfService = '';
$strReqPOType = '';
if (!empty($ReqDetails)) {
foreach ($ReqDetails as $Req) {
$ReqNo = $Req->ReqNo;
$ReqType = $Req->ReqType;
$Requestedby = $Req->Requestedby;
$FirstName = $Req->FirstName;
$Designation = $Req->Designation;
$DepartmentName = $Req->DepartmentName;
$Status = $Req->Status;
$CostCenterCode = $Req->CostCenterCode;
$serviceSchedule = $Req->Schedule_Type;
$servicePeriod = $Req->Service_Period;
$noOfService = $Req->NumberOfService;
}
}
$description = '';
if (!empty($ReqPOType)) {
$strReqPOType = $ReqPOType;
}
?>
<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;
}
td {
padding-left: 0;
padding-right: 0;
}
td {
padding-left: 0;
padding-right: 0;
}
.th-materialCode{
text-align:center !important;
width:15%;
}
.th-requestedQuantity{
text-align:center !important;
width:15%;
}
.th-PoQuantity{
text-align:center !important;
width:15%;
}
.th-Sno{
text-align:center !important;
width:5%;
}
.th-uom{
text-align:center !important;
width:10%;
}
.th-status{
text-align:center !important;
width:10%;
}
</style>
<script type="text/javascript">
window.onload = function() {
var serviceScheduleType = '<?php echo $serviceSchedule; ?>';
if (serviceScheduleType != '') {
$('#DisplayScheduleDiv').show();
} else {
$('#DisplayScheduleDiv').hide();
}
}
</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><?= "Edit Requisition"; ?><?= $ReqNo ? " - " . $ReqNo : ""; ?></h4>
<a href="<?php echo base_url(); ?>Requisition"><button type="button" class="btn btn-dark waves-effect waves-light">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() . 'EditRequisition', $attributes);
?>
<div class="form-row">
<div class="form-group col-md-3">
<label for="EmpID" class="col-form-label">Requested By</label>
<?php
$data = array('name' => 'EmpID', 'value' => set_value('EmpID', $FirstName), 'id' => 'EmpID', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
<div class="form-group col-md-3">
<label for="RequestType" class="col-form-label">Request Type</label>
<?php
$data = array('name' => 'RequestType', 'value' => set_value('RequestType', $ReqType), 'id' => 'RequestType', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</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($CostCenterCode => $CostCenterCode);
if (!empty($CostCenter)) {
foreach ($CostCenter as $SID) :
$Costs[$SID->CostCenterCode] = $SID->CostCenterCode . '-' . $SID->CostCenterName;
endforeach;
}
echo form_dropdown('CostCenter', $Costs, set_value('CostCenter'), 'id="CostCenter" class = "form-control searchabledropdown"');
?>
</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;
}
$selectedValue = set_value('ScheduleType') ? set_value('ScheduleType') : reset($SchType);
echo form_dropdown('ScheduleType', $SchType, $selectedValue, 'id="ScheduleType" class = "form-control searchabledropdown" data-toggle="select2"');
?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<?php if (count($MaterialCode) != 0) { ?>
<a data-toggle="modal" data-target="#add-req-modal" class="btn btn-primary waves-effect float-right">Add Line Item</a>
<?php } ?>
</div>
</div>
<div class="form-row">
<div class="table-responsive">
<table id="Items" class="table table-striped table-hover mb-0" style="font-size:12px;">
<thead>
<tr>
<th class="th th-Sno" >SNo</th>
<th class="th th-materialCode">Material Code</th>
<th class="th th-materialName">Material Name</th>
<th class="th th-uom">Uom</th>
<th class="th th-requestedQuantity">RequestedQuantity</th>
<th class="th th-PoQuantity">PoQuantity</th>
<th class="th th-status">Status</th>
<th class="th">Action</th>
</tr>
</thead>
<tbody id="tempAppend">
<?php
if (!empty($LineItem)) {
$index = 0;
foreach ($LineItem as $record) {
$index = $index + 1;
$materialdesc = isset($record->MaterialDescription) ? $record->MaterialDescription : "";
//echo $materialdesc;
?>
<tr id="<?php echo $index; ?>">
<td align="center"><?php echo $index; ?></td>
<input type="hidden" name="<?php echo 'te' . $index ?>" id="<?php echo 'te' . $index ?>" value="<?php echo $record->MaterialCode; ?>" />
<input type="hidden" name="<?php echo 'te' . $index ?>" id="<?php echo 'tes' . $index ?>" value="<?php echo $record->Quantity; ?>" />
<td align="center"><?php echo $record->MaterialCode; ?></td>
<td align="left"><?php echo $record->MaterialName; ?></td>
<td align="center"><?php echo $record->UOM; ?></td>
<td align="center"><?php echo $record->Quantity; ?></td>
<td align="center"><?php echo $record->POQTY; ?></td>
<td align="center"><?php echo $record->StatusName; ?></td>
<input type="hidden" name="<?php echo 'materialdesc' . $index ?>" id="<?php echo 'materialdesc' . $index ?>" value="<?php echo isset($record->MaterialDescription) ? $record->MaterialDescription : ''; ?>" />
<td>
<a data-id="<?php echo $index; ?>" data-userid="<?php echo $index; ?>" data-target='#edit-req-modal' data-toggle="modal" href="#edit-req-modal"><i class="ri-pencil-fill" data-toggle="tooltip" title="Click here to view/Edit the <?php echo $record->MaterialCode; ?> Material details"></i>&nbsp;&nbsp;&nbsp;</a> <a onclick="DeleteRow(<?php echo $index; ?>)" class="link" data-id="<?php echo $record->MaterialCode; ?>" data-userid="<?php echo $index; ?>" id="Del"><span class="ri-delete-bin-7-fill"></span></a>
</td>
</tr>
<?php $RowCount = $index;
}
} ?>
</tbody>
</table>
</div> <!-- end table-responsive-->
</div>
<div class="form-row">
<input type="hidden" name="txtStatus" id="txtStatus" />
<input type="hidden" name="txtDeletedRow" id="txtDeletedRow" />
<input type="hidden" name="txtRowCount" id="txtRowCount" value="<?php echo $RowCount; ?>" />
<!-- Available Budget Amt -->
<input type="hidden" name="txtReqNo" id="txtReqNo" value="<?php echo $ReqNo ?>" />
<?php
$data = array('name' => 'ServiceNo', 'value' => set_value('ServiceNo', $noOfService), 'id' => 'ServiceNo', 'class' => 'form-control', '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 $SerOptionsel) :
if ($servicePeriod == $SerOptionsel->ConfigValue) {
$ServiceOptions[$SerOptionsel->ConfigValue] = $SerOptionsel->ConfigValue;
}
endforeach;
foreach ($ServiceOption as $SerOption) :
if ($servicePeriod != $SerOption->ConfigValue) {
$ServiceOptions[$SerOption->ConfigValue] = $SerOption->ConfigValue;
}
endforeach;
}
echo form_dropdown('ServiceOptions', $ServiceOptions, set_value('ServiceOptions'), 'id="ServiceOptions"', 'class = "form-control"');
?>
</div>
</div>
<div class="form-row float-right">
<?php if ($Status == REQ_DRAFT) { ?>
<input type="reset" value="Reset" class="btn btn-secondary waves-effect" onclick="window.location.reload();">&nbsp;&nbsp;
<button type="button" class="btn btn-primary waves-effect Save" " id="Save">Save As Draft</button>&nbsp;&nbsp;
<button type="button" class="btn btn-primary waves-effect submit" id="submit1">Submit</button>&nbsp;&nbsp;
<button type="button" class="btn btn-soft-primary waves-effect waves-light submit" id="submit2">Approve</button>&nbsp;&nbsp;
<?php } else if ($Status == REQ_PENDING_APPROVAL) { ?>
<input type="reset" value="Reset" class="btn btn-secondary waves-effect" onclick="window.location.reload();">&nbsp;&nbsp;
<button type="button" class="btn btn-primary waves-effect submit" id="submit1">Submit</button>&nbsp;&nbsp;
<button type="button" class="btn btn-soft-primary waves-effect waves-light submit" id="submit2">Approve</button>&nbsp;&nbsp;
<?php } ?>
</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="drpMaterial" class="control-label">Material Code</label>
<?php
$options = array("0" => 'Material Code');
if (!empty($MaterialCode)) {
foreach ($MaterialCode as $MID) :
$options[$MID->MaterialCode] = $MID->MaterialCode . ' ' . ' - ' . ' ' . $MID->MaterialName;
endforeach;
}
echo form_dropdown('drpMaterial', $options, set_value('drpMaterial'), 'id="drpMaterial" class="form-control searchabledropdown"');
?>
</div>
</div>
</div>
<div class="row" id="category_div" >
<div class="col-md-12">
<div class="form-group">
<label for="otherD" class="control-label">Category</label>
<input type ="text" id="category" readonly class="form-control">
</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', 'onkeypress' => 'return isNumberKey(event)', 'maxlength' => '20', 'min' => '1');
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');
echo form_input($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('name' => 'EditMaterialCode', 'value' => set_value('EditMaterialCode'), 'id' => 'EditMaterialCode', 'class' => 'form-control searchabledropdown', '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', 'onkeypress' => 'return isNumberKey(event)', 'maxlength' => '20', 'min' => '1');
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>
$(document).ready(function() {
$(".searchabledropdown").select2();
});
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() {
var j = 0;
var ReqLineItem = <?php echo json_encode($LineItem, JSON_PRETTY_PRINT) ?>;
$.each(ReqLineItem, function(idx, obj) {
//$("#SupAddress").val(obj.Address);
j = j + 1;
$('<input>').attr({
type: 'hidden',
id: 'MaterialCode' + j,
name: 'MaterialCode' + j,
value: obj.MaterialCode
}).appendTo('form');
$('<input>').attr({
type: 'hidden',
id: 'Quantity' + j,
name: 'Quantity' + j,
value: obj.Quantity
}).appendTo('form');
});
$('#otherDescription').hide();
$('#EditotherDescription').hide();
var id = '<?php echo $CostCenterCode ?>';
var ReqType = '<?php echo $strReqPOType ?>';
$('#CostCenter').change(function() {
var id = $('#CostCenter').val();
if (id == '-1') {
alert('Please select the CostCenter details');
return false;
}
});
$('#drpMaterial').change(function() {
var id = $('#drpMaterial').val();
// var skillsSelect = document.getElementById("drpMaterial");
// var selectedText = skillsSelect.options[skillsSelect.selectedIndex].text;
var value = $("#drpMaterial option:selected").text();
answer = value.replace(/[^a-z]/gi, '');
var converttext = answer.toUpperCase();
//alert(converttext)
$("#Description").val('');
$("#UOM").val('');
if (id != '-1') {
if ((converttext != 'SERVICE')) {
$('#loader').show();
$.ajax({
data: {
id: id
},
dataType: 'json',
type: "POST",
url: "<?php echo base_url(); ?>getMaterialDetails",
success: function(json) {
$('#loader').hide();
//alert(json.MatDetail);
$("#Description").val(json.MatDetail[0]['MaterialName']);
$("#category").val(json.MatDetail[0]['Category']);
$("#UOM").val(json.MatDetail[0]['UOM']);
}
});
} else {
$('#otherDescription').show();
}
$('#loader').hide();
} else {
alert('Please select the RequestType');
return false;
}
});
});
</script>
<script>
var index = $('#txtRowCount').val();
var userid = '';
function removeHiddenRows(rowcount) {
var step;
//alert(rowcount);
for (step = 1; step < rowcount - 1; step++) {
var td = document.getElementById(step);
td.parentNode.removeChild(td);
$("#MaterialCode" + step).remove();
$("#Description" + step).remove();
$("#UOM" + step).remove();
$("#Quantity" + step).remove();
index = '1';
userid = '';
}
}
$(document).ready(function() {
$('#submit2').on('click', function() {
Save(2);
});
$('#submit1').on('click', function() {
Save(1);
});
$('#Save').on('click', function() {
Save(0);
});
function Save(status) {
if (status == '0') {
stat = '<?php echo REQ_DRAFT; ?>';
}
if (status == '1') {
stat = '<?php echo REQ_PENDING_APPROVAL; ?>';
}
if (status == '2') {
stat = '<?php echo REQ_APPROVED; ?>'
}
//alert($('#MaterialCode4').val());
if (validate()) {
if (document.getElementById('Items').rows.length < 2) {
alert('Please Select Line item to update the Requisition');
$('#Deliverydt').focus();
return false;
} else {
//alert(document.getElementById('Items').rows.length);
// $('#content').loader('show');
$('#txtStatus').val(stat);
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 = '';
}
$('#loader').show();
$.ajax({
data: $('.requistion').serialize() + "&serviceSchedule=" + serviceSchedule + "&servicePeriod=" + servicePeriod + "&noOfService=" + noOfService,
type: "POST",
url: "<?php echo base_url() ?>EditRequisition" ,
success: function(data) {
if (data) {
$('#loader').hide() ;
alert(data) ;
$('#txtRowCount').val('') ;
$('#txtDeletedRow').val('') ;
window.location = "Requisition" ;
} else {
$('#loader').hide();
alert("Error");
}
},
error : function (error){
console.log("Error occured ");
console.error(error);
},
complete(){
$('#loader').hide();
console.log("ajax call is completed..!!")
}
});
}
}
}
});
function validate() {
if ($("option:selected", $("#RequestType")).val() == '-1') {
alert('Please Select ReqType Names');
return false;
} else if ($("option:selected", $("#EmpID")).val() == '-1') {
alert('Please Select Reqby');
return false;
} else if (index < 1) {
alert('Please Add Line Item');
return false;
} else {
return true;
}
}
function DeleteRow(rowid) {
var id = [];
var tr = document.getElementById(rowid);
var cellval = tr.cells;
var MaterialCode = cellval[1].innerHTML;
// alert(cellval[1].innerHTML);
id[0] = $('#txtReqNo').val();
id[1] = MaterialCode;
var answer = confirm(" Do you want to delete the Item from the List?")
if (answer) {
// To delete the item from list
var x = <?php echo json_encode($LineItem, JSON_PRETTY_PRINT) ?>;
var result = '0';
//alert(x);
//alert(MaterialCode);
if (MaterialCode != "0") {
$.each(x, function(idx, obj) {
if (obj.MaterialCode === MaterialCode) {
result = '1';
return false;
}
});
}
if (result == '0') {
var DelRows = $('#txtDeletedRow').val();
tr.parentNode.removeChild(tr);
if (DelRows != '') {
DelRows = DelRows + ":" + rowid;
} else {
DelRows = "0" + ":" + rowid;
}
$('#txtDeletedRow').val(DelRows);
}
// To delete the value from Tables
else if (result == '1') {
var DelRows = $('#txtDeletedRow').val();
tr.parentNode.removeChild(tr);
if (DelRows != '') {
DelRows = DelRows + ":" + rowid;
} else {
DelRows = "0" + ":" + rowid;
}
$('#txtDeletedRow').val(DelRows);
$('#loader').show();
$.ajax({
data: {
id: id
},
type: "POST",
url: "<?php echo base_url() ?>DeleteRequistionForm",
success: function(data) {
$('#loader').hide();
if (data) {
// $('#content').loader('hide');
alert(data);
} else {
alert("Error");
}
}
});
}
}
}
$('.addClick').click(function() {
if ($("#drpMaterial option:selected").val() == '-1') {
alert('Please Select the MaterialCode ');
}
var drpMaterial = document.getElementById('drpMaterial').value;
if (drpMaterial == 0) {
$('#drpMaterial').focus();
$('#drpMaterial').select2('open');
alert('Please Select the Material');
return false;
}
var qty = parseInt(document.getElementById('Quantity').value);
if (isNaN(qty) || qty < 1) {
$('#Quantity').focus();
$('#Quantity').click();
alert('Please Enter the Vaild Quantity');
return false;
}
// if (document.getElementById('Quantity').value == '') {
// alert('Please Enter the Quantity');
// }
if ($("#drpMaterial option:selected").val() != '-1' && $('#Quantity').val() != '') {
var temp = parseInt(index) + 1;
var materialCode = $("#drpMaterial option:selected").val();
var materialName = $("#Description").val();
var uom = $("#UOM").val();
var quantity = $("#Quantity").val();
var materialdescription = $('#otherD').val();
$('#drpMaterial option[value=' + materialCode + ']').remove();
$('#Description').val('');
$('#UOM').val('');
$('#Quantity').val('');
$('#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">0.00</td>
<td align="center">NEW</td>
<td>
<a data-id="${temp}" data-userid="${temp}" data-target='#edit-req-modal' data-toggle="modal" href="#edit-req-modal">
<i class="ri-pencil-fill" data-toggle="tooltip" title="Click here to view/Edit the ${materialCode} Material details"></i>
&nbsp;&nbsp;&nbsp;
</a>
<a 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);
$('<input>').attr({
type: 'hidden',
id: 'MaterialCode' + temp,
name: 'MaterialCode' + temp,
value: materialCode
}).appendTo('form');
$('<input>').attr({
type: 'hidden',
id: 'Description' + temp,
name: 'Description' + temp,
value: materialName
}).appendTo('form');
$('<input>').attr({
type: 'hidden',
id: 'UOM' + temp,
name: 'UOM' + temp,
value: uom
}).appendTo('form');
$('<input>').attr({
type: 'hidden',
id: 'Quantity' + temp,
name: 'Quantity' + temp,
value: quantity
}).appendTo('form');
$('<input>').attr({
type: 'hidden',
id: 'otherD' + temp,
name: 'otherD' + temp,
value: materialdescription
}).appendTo('form');
$('#txtRowCount').val(temp);
$('#add-req-modal').modal('hide');
}
});
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);
}
$("#add-req-modal").on("shown.bs.modal", function(e) {
if ($("option:selected", $("#RequestType")).val() == '-1') {
alert('Please select the Request Type ');
e.close();
}
});
$(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');
var check = $cells.eq(2).text();
var upcheck = check.toUpperCase();
var decs = $('#materialdesc' + userid).val();
if (upcheck == 'SERVICE') {
$('#EditotherDescription').show();
$('#EditotherD').val(decs)
} else {
$('#EditotherDescription').hide();
$('#EditotherD').val('')
}
$('#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) {
alert('Please Enter the Vaild Quantity');
return false;
}
// if (document.getElementById('EditQuantity').value == '') {
// alert('Please Enter the Quantity');
// }
if ($('#EditQuantity').val() != '') {
var editMaterialCode = $("#EditMaterialCode").val();
var editDescription = $("#EditDescription").val();
var editUOM = $('#EditUOM').val();
var editQuantity = $('#EditQuantity').val();
var edituserid = $("#Edituserid").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');
}
});
$(function() {
$('#Items').DataTable({
"paging": false,
"lengthChange": true,
"searching": false,
"ordering": false,
"info": false,
"autoWidth": true
});
});
</script>