ria/app/Views/createPOfromRequistion.php

577 lines
18 KiB
PHP
Executable File

<?php $defaultDate = ''; ?>
<style>
.th-reqDate{
text-align:center !important;
}
.th-status{
text-align:center !important;
}
.modal-dialog-centered {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
.modal-content-custom-width {
width: 75%;
/* Adjust the width as needed */
}
.dataTables_paginate {
margin-top: -5%;
}
.dataTables_wrapper {
padding-bottom: 0px;
/* margin-top: -3%; */
}
.content-wrapper {
min-height: 733px;
}
#REQLIST_filter {
float: inline-end;
}
#REQLIST_wrapper .row .col-sm-4 {
flex-basis: 50%;
float: inline-end;
}
#REQLIST_paginate {
flex-basis: 50%;
float: inline-end;
}
</style>
<style>
#Requisition_filter {
float: inline-end;
}
#Requisition_wrapper .row .col-sm-4 {
flex-basis: 50%;
float: inline-end;
}
#Requisition_paginate .pagination {
flex-basis: 50%;
float: inline-end;
margin: 0 0 15px;
}
#Requisition_wrapper .row:nth-child(3),
#Requisition_wrapper .row:nth-child(1) {
padding: 0 15px;
}
#Requisition_info {
margin-top: 5px;
}
.dataTables_wrapper {
padding-bottom: 0;
}
span.highlight {
background-color: yellow;
}
</style>
<style>
.Date-filter-form {
display: flex;
align-items: center;
gap: 10px;
/* Adjust the gap as needed */
}
.Date-filter-form input,
.Date-filter-form button {
padding: 5px;
font-size: 14px;
}
.Date-filter-form button {
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
}
.Date-filter-form button:hover {
background-color: #0056b3;
}
.icon-button {
background: none;
border: none;
cursor: pointer;
color: #007bff;
font-size: 18px;
}
.icon-button:hover {
color: #0056b3;
}
</style>
<div class="content-page">
<div class="content">
<?php $attributes = array('class' => 'form-label-left CreatePO ', 'name' => 'CreatePO', 'id' => 'CreatePO', 'method' => 'post', 'role' => 'form');
echo form_open(base_url() . 'purchaseOrder', $attributes); ?>
<!-- Start Content-->
<div class="container-fluid">
<div class="modal fade" id="RequisitionDtlsModal" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<form>
<div class="modal-content">
<div class="modal-header">
<center>
<h4> Requisition Details - <label id="SelReqNo" name="SelReqNo"></label> </h4>
</center>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-4">
<label>Request Type</label>
<div class="form-group">
<?php
$data = array('name' => 'ReqType', 'value' => set_value('ReqType'), 'id' => 'ReqType', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
<div class="col-md-4">
<label>Requested By</label>
<div class="form-group">
<?php
$data = array('name' => 'ReqBy', 'value' => set_value('ReqBy'), 'id' => 'ReqBy', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
<div class="col-md-4">
<label>Designation</label>
<div class="form-group">
<?php
$data = array('name' => 'Desigination', 'value' => set_value('Desigination'), 'id' => 'Desigination', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label>Requested Date</label>
<div class="form-group">
<?php
$data = array('name' => 'RequistionDate', 'value' => set_value('RequistionDate'), 'id' => 'RequistionDate', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
<div class="col-md-4">
<label>Cost Center Code</label>
<div class="form-group">
<?php
$data = array('name' => 'CostCenter', 'value' => set_value('CostCenter'), 'id' => 'CostCenter', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data); ?>
</div>
</div>
<div class="col-md-4">
<label>Avl Budget Amt</label>&nbsp;<img id="AlertImg" src="<?php echo base_url(); ?>public/assets/dist/img/red.png" alt="your image" width="25px" style="display:none" />
<div class="form-group">
<?php
$data = array('name' => 'AvlBudgetAmount', 'value' => set_value('AvlBudgetAmount'), 'id' => 'AvlBudgetAmount', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
</div>
<div class="row">
<table class="table table-bordered editableTable" style="border:1px solid #fff">
<thead style="background-color: #ddd !important;">
<tr>
<th style="white-space: nowrap;">SNo</th>
<th style="white-space: nowrap;">Item Code</th>
<th style="white-space: nowrap;">Item Description</th>
<th style="white-space: nowrap;">UOM</th>
<th style="white-space: nowrap;">Requested Quantity</th>
<th style="white-space: nowrap;">Ordered Quantity</th>
<th style="white-space: nowrap;">Status</th>
</tr>
</thead>
<tbody id="tbleAppend"></tbody>
</table>
</div>
</div>
<div class="modal-footer">
<div class="col-md-12">
<a class="btn btn-info" data-dismiss="modal" value="Cancel" style="float: right;">Ok</a>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="modal fade" id="ImportPOCheck" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<center>
<h4>Do you want to create an Import PO for this Requisition?</h4>
</center>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<div class="row text-center">
<div class="col-md-3">
</div>
<div class="col-md-3">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="optImport" id="optImportYes" value="0">
<label class="form-check-label" for="optImportYes">YES</label>
</div>
</div>
<div class="col-md-3">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="optImport" id="optImportNo" value="1" checked>
<label class="form-check-label" for="optImportNo">NO</label>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<div class="col-md-12 text-center">
<a class="btn btn-dark waves-effect waves-light" data-dismiss="modal" style="background-color: gray;border-color: gray;margin-right: 10px;">Cancel</a>
<input type="button" class="btn btn-success" onclick="SetImportPO();" value="OK" />
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="javascript: void(0);">Purchase</a></li>
<li class="breadcrumb-item"><a href="javascript: void(0);">Requisition</a></li>
<li class="breadcrumb-item active">
<h4 class="page-title">Purchase Order from Requistion</h4>
</li>
</ol>
</div>
<a class="btn btn-success" onclick="Validate();">Create Purchase Order</a>
<input type="hidden" name="txtReqNo" id="txtReqNo" />
<input type="hidden" name="txtReqType" id="txtReqType" />
</div>
</div>
</div>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="card">
<span class="Date-filter-form" style="margin-top: 14px;margin-bottom: -11px;margin-left: 33px;">
<input type="hidden" name="table" value="requisition">
<label for="fromDate">From:</label>
<input class="form-control date_range form-date-search" id="fromDate" name="fromDate" placeholder="Select From Date" autocomplete="off" required>
<label for="toDate">To:</label>
<input class="form-control date_range to-date-search" id="toDate" name="toDate" placeholder="Select To Date" autocomplete="off" required>
<button type="button" class="range_search_button" id="DateRangeFilter"><i class="fe-search" aria-hidden="true" class="icon-button" title="Search"></i></button>
<i class="fe-rotate-cw range_reset_button" aria-hidden="true" class="icon-button" id="resetButton" title="Reset"></i>
<div class="error" id="error"></div>
</span>
<div class="card-body" >
<table id="create_po_from_requistion" class="table dt-responsive nowrap w-100">
<thead>
<tr>
<th>Select</th>
<th class="th-reqDate">Requested Date</th>
<th class="th-reqNo">Requistion Number</th>
<th class="th-reqType">Requistion Type </th>
<th class="th-reqBy">Requested By</th>
<th class="th-toTLineItems">Tot Line Items</th>
<th class="th-poLineItems">Po Line Items</th>
<th class="th-PartialPolineItems">Partial PO Line Items</th>
<th class="th-reqNewlineItems">New Line Items</th>
<th class="th-status">Status</th>
<th class="th-department">Department</th>
<th class="th-designation">Designation</th>
</tr>
</thead>
<tbody>
<?php if (!empty($ReqList)) { //alert($ReqList);
$index = 1;
foreach ($ReqList as $record) {
?>
<tr id="<?php echo $index; ?>">
<td align="center"><input type="checkbox" name="chk<?php echo $index; ?>" id="chk<?php echo $index; ?>" onclick="selectReqNo(<?php echo $index; ?>)" />&nbsp;</td>
<td align="center">
<?php
$dt = new DateTime($record->ReqDate);
$RequestedDate = $dt->format('d-m-Y');
echo $RequestedDate;
?>
</td>
<td align="center"><span data-toggle="modal"
style="cursor: pointer; color: #039985; text-decoration: none;"
data-target="#RequisitionDtlsModal" data-id="<%=index%>" data-userid="<?php echo $record->ReqNo ?>"><?php echo $record->ReqNo; ?></span></td>
<td align="center"><?php echo $record->ReqType; ?></td>
<td><?php echo $record->FirstName; ?></td>
<td align="center"><?php echo $record->TotalNoofLineItems; ?></td>
<td align="center"><?php echo $record->PolineItems; ?></td>
<td align="center"><?php echo $record->PartilallyLineItems; ?></td>
<td align="center"><?php echo $record->newLineItem; ?></td>
<td align="center"><?php echo $record->StatusName; ?></td>
<td align="center"><?php echo $record->DepartmentName; ?></td>
<td><?php echo $record->Designation; ?></td>
</tr>
<?php $index = $index + 1;
}
}
?>
</tbody>
</table>
</div> <!-- end card body-->
</div> <!-- end card -->
</div><!-- end col-->
</div>
</div> <!-- container -->
</div> <!-- content -->
</div>
<script src="https://cdn.datatables.net/plug-ins/1.10.11/sorting/date-eu.js"></script>
<script>
$(document).ready(function() {
$("#RequisitionDtlsModal").on("shown.bs.modal", function(e) {
var ReqId = $(e.relatedTarget).data('userid');
$('#SelReqNo').html(ReqId);
$('#loader').show();
$.ajax({
data: {
id: ReqId
},
type: "POST",
dataType: 'json',
url: "<?php echo base_url() ?>requisitionform/ViewRequest",
success: function(json) {
$('#loader').hide();
var getAvalAmt = json.AvilBudAmount;
getAvalAmt = getAvalAmt.replace(/\,/g, '');
$("#ReqType").val(json.Requist[0]['ReqType']);
$("#ReqBy").val(json.Requist[0]['FirstName']);
$("#RequistionDate").val(json.Requist[0]['ReqDate']);
$("#Desigination").val(json.Requist[0]['Designation']);
$("#CostCenter").val(json.Requist[0]['CostCenterCode']);
$("#AvlBudgetAmount").val(parseFloat(getAvalAmt).toFixed(2));
$("#tbleAppend").empty();
$("#tbleAppend").append(json.Items);
}
});
});
var table = $('#create_po_from_requistion').DataTable({
dom: 'Blfrtip',
buttons: [
'excel', 'pdf'
],
pageLength: 10,
lengthMenu: [
[10, 20, 30, 50, -1],
[10, 20, 30, 50, "All"]
],
responsive: false,
order: false,
scrollX: true,
language: {
paginate: {
next: '<i class="fas fa-angle-right"></i>', // Next button icon
previous: '<i class="fas fa-angle-left"></i>' // Previous button icon
}
}
});
$('#create_po_from_requistion_wrapper .dataTables_scrollBody').on('mousewheel', function(e) {
if (e.originalEvent.deltaY !== 0) {
this.scrollLeft += e.originalEvent.deltaY; // Use the vertical scroll to scroll horizontally
e.preventDefault();
}
});
// Date range filter function
$.fn.dataTable.ext.search.push(
function(settings, data, dataIndex) {
var fromDate = $('#fromDate').val();
var toDate = $('#toDate').val();
console.log(fromDate); // e.g., 01-09-2024
console.log(toDate); // e.g., 08-09-2024
if (!fromDate || !toDate) {
return true; // If no dates selected, don't filter
}
// Convert the fromDate and toDate from dd-mm-yyyy to Date objects
var fromParts = fromDate.split("-");
var toParts = toDate.split("-");
var startDate = new Date(fromParts[2], fromParts[1] - 1, fromParts[0]); // Year, month (0-based), day
var endDate = new Date(toParts[2], toParts[1] - 1, toParts[0]);
// Adjust startDate to include the day before the selected fromDate
startDate.setDate(startDate.getDate() - 1);
// Ensure endDate includes the entire end date by setting time to the end of the day
endDate.setHours(23, 59, 59, 999);
// Get the date from the DataTable row (assuming it's in the first column in dd-mm-yyyy format)
var dateStr = data[1];
var dateParts = dateStr.split("-");
var rowDate = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]);
// Return true if the row date is within the range
return rowDate >= startDate && rowDate <= endDate;
}
);
// Handle form submission for the date range filter
$("#DateRangeFilter").click(function(e) {
e.preventDefault();
table.draw(); // Redraw the table to apply the filter
});
// Reset button functionality
$("#resetButton").click(function() {
$("#fromDate").val('');
$("#toDate").val('');
table.draw(); // Redraw the table to clear the filter
});
// Automatically focus and open the To Date picker when From Date is selected
document.getElementById('fromDate').addEventListener('change', function() {
var fromDate = this.value;
var toDateInput = document.getElementById('toDate');
// Set the min attribute of the To Date input to the selected From Date
toDateInput.min = fromDate;
// Optionally reset the To Date input if the current value is before the new min date
if (toDateInput.value < fromDate) {
toDateInput.value = fromDate;
}
});
});
var POType = '';
function SetImportPO() {
POType = $("input:radio[name='optImport']:checked").val();
$('#ImportPOCheck').modal('hide');
$('#txtReqType').val(POType == 0 ? 'IMPORT' : '');
$('#CreatePO').submit();
}
$('#ReqDate').val('');
var Fromdt = '';
var Todt = '';
var baseurl = "<?php print base_url(); ?>";
//Date range picker
// $('#ReqDate').daterangepicker({
// locale: {
// format: 'YYYY/MM/DD'
// }
// });
var coll = [];
var RequistionList = {
Req: []
};
var Type = '';
var i = 0;
function selectReqNo(rowId) {
ckb = $('#chk' + rowId).is(':checked');
var tr = document.getElementById(rowId);
var cellval = tr.cells;
console.log(cellval)
//coo/kie_value_add = {};
if (!ckb) {
var removeItem = cellval[2].innerText;
$.each(RequistionList.Req, function(i, el) {
if (this.ReqNo == removeItem) { //Type = '';
RequistionList.Req.splice(i, 1);
}
});
} else {
var tr = document.getElementById(rowId);
var cellval = tr.cells;
//alert(RequistionList.Req.length);
console.log(RequistionList);
if (RequistionList.Req.length > 0) {
if (Type == cellval[3].innerText) {
RequistionList.Req.push({
"ReqNo": cellval[2].innerText,
"ReqType": cellval[3].innerText,
"ReqBy": cellval[4].innerText,
});
} else {
alert('Same type of Requistion only can be together.');
$('#chk' + rowId).prop('checked', false); // Properly uncheck the checkbox
}
} else {
RequistionList.Req.push({
"ReqNo": cellval[2].innerText,
"ReqType": cellval[3].innerText,
"ReqBy": cellval[4].innerText,
});
Type = cellval[3].innerText;
}
i = i + 1;
}
// console.log(JSON.stringify(RequistionList));
$('#txtReqNo').val(JSON.stringify(RequistionList));
}
function Validate() {
var ReqNo = $('#txtReqNo').val();
// console.log(ReqNo);
if (ReqNo.length <= 0) {
alert('Please select the Requisition Number to Create Purchase Order');
return false;
} else {
$('#ImportPOCheck').modal('show');
}
}
</script>