ria/app/Views/editrequisitionform.php

996 lines
31 KiB
PHP
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;
}
?>
<script type="text/javascript">
window.onload = function() {
var serviceScheduleType = '<?php echo $serviceSchedule; ?>';
if (serviceScheduleType != '') {
if (serviceScheduleType != 'Recurring') {
$('#DisplayScheduleDiv').show();
$('#ServicePeriodOption').hide();
$('#NoServices').hide();
} else {
$('#DisplayScheduleDiv').show();
$('#ServicePeriodOption').hide();
$('#NoServices').hide();
}
} else {
document.getElementById('DisplayScheduleDiv').style.display = 'none';
$('#ServicePeriodOption').hide();
$('#NoServices').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>
</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);
?>
<input type="hidden" name="txtReqNo" id="txtReqNo" value="<?php echo $ReqNo ?>" />
</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"');
?>
</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 $seletedSch) :
if ($serviceSchedule == $seletedSch) {
$SchType[$seletedSch] = $seletedSch;
}
endforeach;
foreach ($Schdule as $Sch) :
if ($serviceSchedule != $Sch) {
$SchType[$Sch] = $Sch;
}
endforeach;
}
echo form_dropdown('ScheduleType', $SchType, set_value('ScheduleType'), 'id="ScheduleType"', 'class = "form-control"');
?>
</div>
<div class="form-group col-md-3" id="ServicePeriodOption" 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 class="form-group col-md-3" id="DisplayScheduleDiv" style="display:none;">
<label for="ServiceNo" class="col-form-label">Number of Services</label>
<?php
$data = array('name' => 'ServiceNo', 'value' => set_value('ServiceNo', $noOfService), 'id' => 'ServiceNo', 'class' => 'form-control', 'onkeypress' => 'return isNumberKey(event);');
echo form_input($data);
?>
</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>SNo</th>
<th>Material Code</th>
<th>Material Name</th>
<th>Uom</th>
<th>RequestedQuantity</th>
<th>PoQuantity</th>
<th>Status</th>
<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="left"><?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="left"><?php echo $record->MaterialCode; ?></td>
<td align="left"><?php echo $record->MaterialName; ?></td>
<td align="left"><?php echo $record->UOM; ?></td>
<td align="left"><?php echo $record->Quantity; ?></td>
<td align="left"><?php echo $record->POQTY; ?></td>
<td align="left"><?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="AvlBudgetAmount" id="AvlBudgetAmount" />
</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;
<a class="btn-primary waves-effect Save" ID="Save" onclick="Save(0)">&nbsp;&nbsp;<span class="bold">Save As Draft</span></a>
<a class="btn-primary waves-effect submit" ID="submit" onclick="Save(1)">&nbsp;&nbsp;<span class="bold">Submit</span></a>
<a class="btn-soft-primary waves-effect waves-light submit" ID="submit" onclick="Save(2)">&nbsp;&nbsp;<span class="bold">Approve</span></a>
<?php } else if ($Status == REQ_PENDING_APPROVAL) { ?>
<input type="reset" value="Reset" class="btn btn-secondary waves-effect" onclick="window.location.reload();">&nbsp;&nbsp;
<a class="btn-primary waves-effect Save" ID="submit" onclick="Save(1)">&nbsp;&nbsp;<span class="bold">Submit</span></a>
<a class="btn-soft-primary waves-effect waves-light submit" ID="submit" onclick="Save(2)">&nbsp;&nbsp;<span class="bold">Approve</span></a>
<?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"');
?>
</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', '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">
<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() {
$("#CostCenter").select2();
$("#drpMaterial").select2();
$("#EditMaterialCode").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();
//Initialize Select2 Elements
$(".select2").select2();
var id = '<?php echo $CostCenterCode ?>';
var ReqType = '<?php echo $strReqPOType ?>';
var urlval = '';
urlval = "<?php echo base_url() ?>serviceAvilBudgetAmount";
$('#content').loader('show');
$.ajax({
data: {id: id,type: ReqType},
type: "POST",
url: urlval,
success: function(data) {
if (data) {
$('#content').loader('hide');
$("#AvlBudgetAmount").val(parseFloat(data).toFixed(2));
if (parseFloat($("#AvlBudgetAmount").val()) <= 0) {
$('#AlertImg').removeAttr("style");
} else {
$('#AlertImg').attr("style", "display:none;");
}
} else {
$('#content').loader('hide');
// alert("Error");
}
}
});
$('#CostCenter').change(function() {
var id = $('#CostCenter').val();
$("#AvlBudgetAmount").val('');
var ReqType = '<?php echo $strReqPOType ?>';
var urlval = '';
if (ReqType == '<?php echo IMPORT ?>') {
urlval = "<?php echo base_url() ?>servicepurchaseorder/GetAvailableImportBudgetAmount?ReqType=" + ReqType;
} else {
urlval = "<?php echo base_url() ?>serviceAvilBudgetAmount";
}
if (id != '-1') {
$('#content').loader('show');
$.ajax({
data: {
id: id,
type: ReqType
},
type: "POST",
url: urlval,
success: function(data) {
if (data != '0') {
$('#content').loader('hide');
$("#AvlBudgetAmount").val(parseFloat(data).toFixed(2));
if (parseFloat($("#AvlBudgetAmount").val()) <= 0) {
$('#AlertImg').removeAttr("style");
} else {
$('#AlertImg').attr("style", "display:none;");
}
} else {
$('#content').loader('hide');
// alert("Error");
}
}
});
} else {
alert('Please select the Employee 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')) {
$('#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;
}
});
});
</script>
<script type="text/html" id="tempList">
<tr id="<%=index%>">
<td align="left"><%=index%></td>
<td align="left"><%=MaterialCode%></td>
<td align="left"><%=MaterialName%></td>
<td align="left"><%=UOM%></td>
<td align="left"><%=Quantity%></td>
<td align="left">0.00</td>
<td align="left">NEW</td>
<td><a data-target='#edit-req-modal' data-id="<%=index%>" data-userid="<%=index%>" data-toggle="modal" href="#edit-req-modal"><i class="fa fa-pencil" data-toggle="tooltip" title="Click here to view/Edit the <%=MaterialCode%> Material details"></i>&nbsp;&nbsp;&nbsp;</a> <a href='#' onclick="DeleteRow(index)" class="link" data-id="<%=index%>" data-userid="<%=index%>" id="Del"><span class="glyphicon glyphicon-trash"></span></a></td>
</tr>
</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 = '';
}
}
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 = '';
}
$.ajax({
data: $('.requistion').serialize() + "&serviceSchedule=" + serviceSchedule + "&servicePeriod=" + servicePeriod + "&noOfService=" + noOfService,
type: "POST",
url: "<?php echo base_url() ?>EditRequisition",
success: function(data) {
if (data) {
$('#content').loader('hide');
alert(data);
$('#txtRowCount').val('');
$('#txtDeletedRow').val('');
window.location = "Requisition";
} else {
alert("Error");
}
}
});
}
}
}
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);
$.ajax({
data: {id: id},
type: "POST",
url: "<?php echo base_url() ?>DeleteRequistionForm",
success: function(data) {
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 qty = parseInt(document.getElementById('Quantity').value);
if (isNaN(qty) || qty < 1) {
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 template = jQuery("#tempList").html();
if (materialdescription == '') {
$('#tempAppend').append(_.template(template, {
index: temp,
MaterialCode: materialCode,
MaterialName: materialName,
UOM: uom,
Quantity: quantity
}));
} else {
$('#tempAppend').append(_.template(template, {
index: temp,
MaterialCode: materialCode,
MaterialName: materialdescription,
UOM: uom,
Quantity: quantity
}));
}
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);
}
});
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();
}
});
$("#edit-req-modal").on("shown.bs.modal", function(e) {
userid = $(e.relatedTarget).data('userid');
//alert(userid);
var tr = document.getElementById(userid);
var cellval = tr.cells;
//var desc=cellval[2].innerHTML;
var check = cellval[2].innerHTML;
var upcheck = check.toUpperCase();
// var decs= <?php echo json_encode($materialdesc, JSON_PRETTY_PRINT) ?>;
//alert(decs)
//var desc= cellval[8].innerHTML
//alert(desc)
var decs = $('#materialdesc' + userid).val();
// alert(upcheck)
if (upcheck == 'SERVICE') {
$('#EditotherDescription').show();
$('#EditotherD').val(decs)
} else {
$('#EditotherDescription').hide();
$('#EditotherD').val('')
}
//alert(x[1].innerHTML);
$('#EditMaterialCode').val(cellval[1].innerHTML);
$('#EditDescription').val(cellval[2].innerHTML);
$('#EditUOM').val(cellval[3].innerHTML);
$('#EditQuantity').val(cellval[4].innerHTML);
});
$('.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 tr = document.getElementById(userid);
var cellval = tr.cells;
cellval[1].innerHTML = editMaterialCode;
cellval[2].innerHTML = editDescription;
cellval[3].innerHTML = editUOM;
cellval[4].innerHTML = editQuantity;
$('#MaterialCode' + userid).val(editMaterialCode);
$('#Description' + userid).val(editDescription);
$('#UOM' + userid).val(editUOM);
$('#Quantity' + userid).val(editQuantity);
}
});
$(function() {
$('#Items').DataTable({
"paging": false,
"lengthChange": true,
"searching": false,
"ordering": false,
"info": false,
"autoWidth": true
});
});
$("#ScheduleType").change(function() {
if ($('#ScheduleType').val().trim() != 'Recurring') {
$('#ServicePeriodOption').hide();
$('#NoServices').hide();
} else {
$('#ServicePeriodOption').hide();
$('#NoServices').hide();
}
});
</script>