ria/app/Views/viewIGRDetails.php
2024-07-20 11:42:45 +00:00

1336 lines
43 KiB
PHP

<style>
.modal {
padding-right: 25% ! important;
}
.num {
text-align: right;
}
.modal-content {
width: 825px ! important;
}
.modal-footer .btn {
margin-right: 10px;
/* Add some spacing between buttons */
}
.modal-footer {
border-top-color: #fff ! important;
}
</style>
<div class="content-wrapper">
<section class="content"><br />
<div class="box">
<div class="box-header">
<center><b>
<h3 class="box-title">View Inward Gate Register</h3>
</b></center>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 text-right" style="margin-bottom:-3%;">
<div class="form-group">
<a class="btn btn-success" onclick="Test()" href="<?php echo base_url(); ?>Addigr">Add New </a>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<table id="Inwardgateregistertable" class="table table-bordered table-hover" style="background-color:#fff;font-size:12px;">
<thead style="background-color:#ddd;">
<tr>
<!-- <th>S.No</th> -->
<th>Date of IGR Created</th>
<th>IGR No</th>
<th>PO No</th>
<th>Supplier Name</th>
<th>Invoice No</th>
<th>Date of Invoice</th>
<th>Vechicle No</th>
<th>IGR Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
if (!empty($IGR)) {
$index = 0;
// print_r($IGR);
// die;
foreach ($IGR as $record) {
$index = $index + 1;
?>
<tr id="<?php echo $index ?>">
<!-- <td style="text-align: center;"><?php echo $index ?></td> -->
<!-- <td><a data-toggle="modal" data-target="#Igrshow" data-id="<%=index%>" data-userid="<?php // echo $record->IGRNO ?>"> <u><?php // echo $record->IGRNO ?></u></a></td> -->
<td align="right"><?php
$createddate = new DateTime($record->CreatedDate);
echo $createddate->format('d-m-Y h:i A'); ?></td> <td><a data-toggle="modal" data-target="#Igrshow" data-id="<%=index%>" data-userid="<?php echo $record->IGRNO ?>" data-igrstatus="<?php echo $record->IGRStatus ?>" title="View Generated IGR details/edit Draft IGR details"> <u><?php echo $record->IGRNO ?></u></a></td>
<td><?php echo $record->PONO ?></a></td>
<td><?php echo $record->SupplierName ?></td>
<td><?php echo $record->DeliveryChellanOrInvoiceNo ?></td>
<td align="right"><?php
$date = new DateTime($record->DeliveryChellanDate);
echo $date->format('d-m-Y'); ?></td>
<td><?php echo $record->VehicleNo ?></td>
<td><?php
echo $record->IGRStatus == 'ST074' ? 'Draft' : 'Completed';
echo (int)$record->IsOpenOrder == 1 ? " (Open order po)" : " (Ordered po Quantity)";
?></td>
<td> <?php if (!empty($record->FilePath)) { ?>
<!-- <a target="_blank" href="<?php echo base_url() . $record->file ?>"><i class="fa fa-download" ></i></a> -->
<a target="_blank" data-toggle="modal" data-target="#Fileshow" data-id="<%=index%>" title="Attachment Available for Download/View" data-igrno="<?php echo $record->IGRNO ?>" data-pono="<?php echo $record->PONO ?>"><i class="fa fa-download" style="text-align: center;"></i></a>
<?php
} else if (!empty($record->file)) { ?>
<a target="_blank" data-toggle="modal" data-target="#Fileshow" data-id="<%=index%>" title="Attachment Available for Download/View" data-igrno="<?php echo $record->IGRNO ?>" data-pono="<?php echo $record->PONO ?>"><i class="fa fa-download" style="text-align: center;"></i></a>
<?php } else { ?>
<!-- echo "NO FILE"; -->
<a target="_blank" data-toggle="modal" data-target="#Fileshow" data-id="<%=index%>" title="Attachment Available for Upload" data-igrno="<?php echo $record->IGRNO ?>" data-pono="<?php echo $record->PONO ?>"><i class="fa fa-pencil" style="text-align: center;"></i></a>
<?php }
?>
&nbsp;&nbsp;&nbsp;
<a target="_blank" data-toggle="modal" data-target="#Historyshow" data-id="<%=index%>" title="IGR History" data-igrno="<?php echo $record->IGRNO ?>" data-pono="<?php echo $record->PONO ?>"><i class="fa fa-history" style="text-align: center;"></i></a>
</td>
<!--<td><?php echo $record->file ?></td>-->
</tr>
<?php
//$SNo++;
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- ######################################Fileshow########################### -->
<div class="modal fade" id="Fileshow" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<form id="igrfileform">
<div class="modal-content" style="width:800px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<center>
<h4>Inward Gate File Details</h4>
</center> <!-- IGR number should display here-->
</div>
<!-- Table to show the line item of po -->
<div id="contents"> </div>
<table class="table table-bordered" id="Inwardgateregisterfile" style="background-color:#fff;font-size:12px;">
<thead style="background-color:#ddd;">
<tr>
<th>SNo</th>
<th>BillNO</th>
<th>PONO</th>
<th>FileName</th>
<th>Action</th>
</tr>
</thead>
<tbody id="tblefile">
</tbody>
</table>
<div class="col-md-12">
<div class="col-md-offset-10 col-md-8">
<input type="button" class="btn btn-primary" id="addmorebutton" value=" ADD FILES..">
</div>
<div id="newdiv"></div>
<input type="hidden" name="hidecounter" id="hidecounter" value="0" />
<!-- <input type="hidden" name="hideconstant" id="hideconstant" value="0" /> -->
<input type="hidden" name="hiddenIGRNO" id="hiddenIGRNO" />
<input type="hidden" name="hiddenPONO" id="hiddenPONO" />
</div>
<div class="modal-footer">
<!-- <a class="btn btn-primary" data-dismiss="modal" id='editfileadd' value="">ADD</a> -->
<br>
</br>
<a class="btn btn-primary" data-dismiss="modal" value="Cancel">Cancel</a>
</div>
</div>
</form>
</div>
</div>
<div class="modal fade" id="Historyshow" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" style="width:800px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<center>
<h4>IGR History Details <span id="HisTitle"></span></h4>
</center> <!-- IGR number should display here-->
</div>
<div id="contents"> </div>
<table class="table table-bordered" id="Inwardgateregisterhistory" style="background-color:#fff;font-size:12px;">
<tbody id="tblehistory"></tbody>
</table>
<div style="text-align: right; margin:5px;">
<a class="btn btn-success" data-dismiss="modal" value="Close">Close</a>
</div>
<br />
</div>
</div>
</div>
<!-- ######################################billModel################### -->
<div class="modal fade" id="billModel" role="dialog" data-backdrop-limit="1" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content" style="width:950px;">
<div class="modal-header">
<h4 class="modal-title">Update Bill Details</h4>
</div>
<form class="tagForm" id="tag-form" method="post" enctype="multipart/form-data">
<div class="modal-body" style="padding:0px;">
<div class="col-md-12">
<div class="col-md-5">
<!-- onChange="filecheck();" -->
<input type="file" size="20" input accept=".docx,.pdf,.doc.JPG,.PNG,.jpg" id="billimag" name="images" />
<label for="images">Select file <br /><small>(only .pdf,.excel,.doc,.png,.jpg)</small></label>
</div>
</div>
<input type="hidden" name="hideoldfile" id="hideoldfile" class="form-control" readonly>
<input type="hidden" name="hidebillno" id="hidebillno" class="form-control" readonly>
</div><!-- /.modal body -->
<div class="modal-footer">
<div class="col-md-12 text-right">
<div class="col-md-4 col-md-offset-8">
<a class="btn btn-success" onclick="fileupdate()">&nbsp;&nbsp;<span class="bold">Update</span>
<a class="btn btn-success" data-dismiss="modal" value="Cancel">Cancel</a>
</div>
</div>
</div><!-- /.modal footer -->
</form>
</div><!-- /.modal content -->
</div><!-- /.modal dialog -->
</div><!-- /#filemodal -->
<!-- ######################################Igrshow################### -->
<div class="modal fade" id="Igrshow" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<form>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<center>
<h4>Inward Gate Register Details..</h4>
</center> <!-- IGR number should display here-->
</div>
<input type="hidden" id="counts">
<!--<div class="col-md-12">
<div class="col-md-3">
<label>IGR Number :</label>
</div>
<div class="col-md-3">
<input type="text" id="IGRNO1" readonly>
</div>
<div class="col-md-3">
<label> Purchase Order Number:</label>
</div>
<div class="col-md-3">
<input type="text" id="PONo" readonly>
</div>
</div>
<div class="col-md-12">
<div class="col-md-3">
<label>Delivery Challan/Invoice NO :</label>
</div>
<div class="col-md-3">
<input type="text" id="Invoice_No" readonly>
</div>
<div class="col-md-3">
<label>Delivery Challan / Invoice Date:</label>
</div>
<div class="col-md-3">
<input type="text" id="Invoice_Date" readonly>
</div>
</div>
<br/>
<div class="col-md-12">
<div class="col-md-3">
<label>Supplier Name :</label>
</div>
<div class="col-md-3">
<input type="text" id="Supplier" readonly>
</div>
</div>-->
<div class="col-md-12">
<div class="col-md-4">
<label>IGR Number </label>
<?php
$data = array('name' => 'IGRNumber', 'value' => set_value('IGRNumber'), 'id' => 'IGRNO1', 'class' => 'form-control', 'required=>"true"', 'readonly' => 'true');
echo form_input($data);
?>
</div>
<div class="col-md-4">
<label>Purchase Order Number </label>
<?php
$data = array('name' => 'PurchaseOrderNumber', 'value' => set_value('PurchaseOrderNumber'), 'id' => 'PONo', 'class' => 'form-control', 'required=>"true"', 'readonly' => 'true');
echo form_input($data);
?>
</div>
<div class="col-md-4">
<label>Supplier Name </label>
<?php
$data = array('name' => 'SupplierName', 'value' => set_value('SupplierName'), 'id' => 'Supplier', 'class' => 'form-control', 'required=>"true"', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
<div class="col-md-12" style=" padding-bottom: 10px;">
<div class="col-md-4">
<label> Invoice Number <!-- Delivery Challan/Invoice NO --> </label>
<?php
$data = array('name' => 'InvoiceNO', 'value' => set_value('InvoiceNO'), 'id' => 'Invoice_No', 'class' => 'form-control', 'required=>"true"', 'readonly' => 'true');
echo form_input($data);
?>
</div>
<div class="col-md-4">
<label>Invoice Date </label>
<?php
$data = array('name' => 'InvoiceDate', 'value' => set_value('InvoiceDate'), 'id' => 'Invoice_Date', 'class' => 'form-control', 'required=>"true"', 'readonly' => 'true');
echo form_input($data);
?>
</div>
<div class="col-md-4">
<label>Material Received Date </label>
<?php
$data = array('name' => 'MaterialRcvdDate', 'value' => set_value('MaterialRcvdDate'), 'id' => 'MaterialRcvdDate', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
<div class="col-md-12" style=" padding-bottom: 10px;">
<div class="col-md-4">
<label>Vehicle Number</label>
<?php
$data = array('name' => 'VehicleNo', 'value' => set_value('VehicleNo'), 'id' => 'Vehicle_No', 'class' => 'form-control');
echo form_input($data);
?>
</div>
<div class="col-md-4">
<label>Driver Name </label>
<?php
$data = array('name' => 'DriverName', 'value' => set_value('DriverName'), 'id' => 'Driver_Name', 'class' => 'form-control');
echo form_input($data);
?>
</div>
<div class="col-md-4">
<label>Driver Mobile Number </label>
<?php
$data = array('name' => 'DriverMobileNumber', 'value' => set_value('DriverMobileNumber'), 'id' => 'DriverMobileNumber', 'class' => 'form-control');
echo form_input($data);
?>
</div>
</div>
<!-- Table to show the line item of po -->
<div id="content"> </div>
<table class="table table-bordered" id="Inwardgateregistertable1" style="font-size:12px;">
<thead style="background-color:#ddf">
<tr>
<th>SNo</th>
<th>Item Code</th>
<th>Item Description</th>
<th>UOM</th>
<th>Ordred Quantity</th>
<th>Received Quantity</th>
<th id="pendingQuantityHeader" style="display:none;">Pending Quantity</th>
<th>Remarks</th>
<th></th>
</tr>
</thead>
<tbody id="tbleAppend1">
<!-- <tr>
<td>1</td>
<td>RM002</td>
<td>Raw sand</td>
<td>Kgs</td>
<td>10000</td>
<td>10000</td>
<td>Received</td>
</tr>-->
</tbody>
</table>
<div class="modal-footer">
<a class="btn btn-primary" data-dismiss="modal" value="Cancel">Cancel</a>
</div>
</div>
</form>
</div>
</div>
<!-- ######################################WeightCalculator################### -->
<div class="modal fade" id="WeightCalculator" role="dialog">
<div class="modal-dialog modal_style">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<center><h4>Weight Calculator</h4><div id="material"></div></center>
<div class="pull-right hidden-xs">
<b><div id="clock"></div></b>
</div>
</div>
<div class="col-md-12"> <br/>
<!-- <center><label style="font-size:40px;">Default</label> </center> -->
<!-- <div class="container"> -->
<div class="form-group row">
<label for="GrossWeight" class="col-md-2 col-form-label">Gross Weight</label>
<div class="col-md-5">
<?php
$data = array('name' => 'GrossWeight', 'value' => set_value('GrossWeight'), 'id' => 'GrossWeight', 'class' => 'form-control', 'onkeypress' => 'return isNumberKey(event);', 'maxlength' => '50', 'onchange' => 'WeightDiffer(this);' , 'placeholder' => 'Gross Weight Value (A)');
echo form_input($data);
?>
</div>
<div class="col-md-5">
<?php
$data = array('name' => 'GrossWeightDate', 'value' => set_value('GrossWeightDate'), 'id' => 'GrossWeightDate', 'class' => 'form-control', 'readonly' => true , 'placeholder' => 'Gross Weight Date/Timing');
echo form_input($data);
?>
</div>
</div>
<div class="form-group row">
<label for="TareWeight" class="col-md-2 col-form-label">Tare Weight</label>
<div class="col-md-5">
<?php
$data = array('name' => 'TareWeight', 'value' => set_value('TareWeight'), 'id' => 'TareWeight', 'class' => 'form-control', 'onkeypress' => 'return isNumberKey(event);', 'maxlength' => '50', 'onchange' => 'WeightDiffer(this);' ,'placeholder' => 'Enter your username','placeholder' => 'Tare Weight Value (B)');
echo form_input($data);
?>
</div>
<div class="col-md-5">
<?php
$data = array('name' => 'TareWeightDate', 'value' => set_value('TareWeightDate'), 'id' => 'TareWeightDate', 'class' => 'form-control', 'readonly' => true , 'placeholder' => 'Tare Weight Date/Timing',);
echo form_input($data);
?>
</div>
</div>
<div class="form-group row">
<label for="NetWeight" class="col-md-2 col-form-label">Net Weight</label>
<div class="col-md-5">
<input type="hidden" id="CurrentInx" name="CurrentInx" readonly>
<?php
$data = array('name' => 'NetWeight', 'value' => set_value('NetWeight'), 'id' => 'NetWeight', 'class' => 'form-control', 'maxlength' => '50', 'readonly' => true , 'placeholder' => 'Net Weight Value (A-B)');
echo form_input($data);
?>
</div>
</div>
<!-- </div> -->
</div>
<div class="modal-footer">
<center>
<a class="btn btn-primary" onclick="modalSave()" id="modalsave">&nbsp;&nbsp;<span class="bold">Save</span>
<a class="btn btn-primary" data-dismiss="modal" value="Close">Close</a>
</center>
</div><!-- footer div closed -->
</div><!-- modal content div closed-->
</div><!-- modal content closed-->
</div><!-- modal fade closed-->
</div>
</section>
<script>
function filecheck() {
var sizef = document.getElementById('billimag').files[0].size;
var file = $('#billimag').val();
if (file != '' && sizef < 2100000) { // alert('Your file added successfully');
} else {
alert('Sorry Your File is Large To 2MB');
$('#billimag').val('');
}
}
function fileupdate() {
var formData = new FormData();
//var file = document.getElementById('billimag').files[0];
var file = $("#billimag").prop('files')[0];
var param1 = $('#hidebillno').val();
// alert(param1);
var param2 = $('#hideoldfile').val();
// alert(param2);
// var filename = $("#billimag").val();
// filename = filename.split('\\');
formData.append('file', file);
formData.append('param1', param1);
formData.append('param2', param2);
$('.content').loader('show');
$.ajax({
data: formData,
type: "POST",
url: "<?php echo base_url() ?>inwardgateregister/edituploadfile",
cache: false,
contentType: false,
processData: false,
success: function(data) {
if (data) {
alert(data);
window.location.reload();
$('.content').loader('hide');
// $('#spl').find('td').eq(5).text(filename[2]);
$('#billModel').modal('hide');
}
}
});
}
//$(function () {
$(document).ready(function() {
$("#Fileshow").on("shown.bs.modal", function(e) {
//var id = $(this).attr('id');
var id = $(this).attr('id');
// alert(id);
// SIA/2018-2019/10243.01
// IGRNO0505
var igr = $(e.relatedTarget).data('igrno');
// alert(igr);
var po = $(e.relatedTarget).data('pono');
//alert(po);
$("#hiddenIGRNO").val(igr);
$("#hiddenPONO").val(po);
if (igr != "" && po != "") {
$.ajax({
data: {
id: igr,
id1: po
},
type: "POST",
//dataType: 'json',
url: "<?php echo base_url() ?>inwardgateregister/ViewIGRfile",
success: function(file) {
$("#counts").val(JSON.parse(file).length);
var trHTML = '';
var FilePath = '';
var Filename = '';
var PONO = '';
var BillNO = '';
$.each(JSON.parse(file), function(i, item) {
if (item.file == null) {
if (item.Remarks == null) {
//alert()
PONO = item.PONO;
BillNO = item.BillNo;
Filename = item.FilePath;
FilePath = "<?php echo base_url() ?>public/uploads/Igrfiles/" + item.FilePath;
} else {
Filename = "BillDetails";
PONO = item.PONO;
BillNO = item.BillNo;
FilePath = item.FilePath;
}
} else {
Filename = item.file;
PONO = item.pono;
BillNO = '-';
FilePath = item.file;
}
if (Filename != null) {
i = i + 1;
trHTML += '<tr id=' + i + '>' +
'<td align="right">' + i + '</td>' +
'<td id="billno' + i + '">' + BillNO + '</td>' +
'<td>' + PONO + '</td>' +
'<td id="file' + i + '"><a target="_blank" href = ' + FilePath + '>' + Filename + '</a></td>' +
'<td name="filepathname" id="filepathname" onclick="openbillmodel(' + i + ');"><i class="fa fa-pencil"></i></td>' +
'</tr>';
}
});
$("#tblefile").empty();
if (trHTML == '') {
trHTML = '<tr><td colspan="5" style="text-align: center;">NO FILE</td></tr>';
}
$("#tblefile").append(trHTML);
}
});
}
});
$("#Historyshow").on("shown.bs.modal", function(e) {
// alert("Historyshow");
var igr = $(e.relatedTarget).data('igrno');
$('#HisTitle').text(" (" + igr + ") ");
$("#tblehistory").empty();
if (igr != "") {
$.ajax({
data: {
igr: igr
},
type: "POST",
//dataType: 'json',
url: "<?php echo base_url() ?>inwardgateregister/ViewIGRHistory",
success: function(data) {
if (data && data.length > 0) {
var output = '';
data.forEach(function(record) {
var sentence = constructSentence(record);
output += '<p>' + sentence + '</p>';
});
trHTML = '<tr><td style="text-align: center;">' + output + '</td></tr>';
$("#tblehistory").append(trHTML);
} else {
trHTML = '<tr><td style="text-align: center;">No History Data Available</td></tr>';
$("#tblehistory").append(trHTML);
}
},
error: function(xhr, status, error) {
trHTML = '<tr><td style="text-align: center;">No History Data Available</td></tr>';
$("#tblehistory").append(trHTML);
console.error('AJAX Error: ' + status + error);
}
});
} else {
trHTML = '<tr><td style="text-align: center;">No History Data Available.</td></tr>';
$("#tblehistory").append(trHTML);
}
});
});
function openbillmodel(i) {
// alert(i);
// return false;
var igr = $("#tblefile").find('tr').find('td').eq(2).text();
// alert(igr);
var Billno = $("#billno" + i).text();
// alert(Billno);
var file = $("#file" + i).text();
//alert(file);
$("#billModel").modal("show");
$("#bill").text(Billno);
$("#hideoldfile").val(file);
$("#hidebillno").val(Billno);
}
function constructSentence(record) {
let fieldName = record.field.replace(/_/g, ' ').replace(/\b\w/g, char => char.toUpperCase());
let sentence = "'" + fieldName + "' ";
sentence += "=> '" + record.new_data + "' ";
sentence += (record.old_data) ? "(old data: '" + record.old_data + "'), " : ", ";
if (parseInt(record.is_add) === 1) {
sentence += "was added by ";
} else if (parseInt(record.is_edit) === 1) {
sentence += "was edited by ";
} else if (parseInt(record.is_delete) === 1) {
sentence += "was deleted by ";
}
sentence += record.FullName + ".";
sentence += "<br>Details for references: <br>&emsp;";
sentence += "IGR No: " + record.IGR_No;
sentence += (record.IGRItem_No) ? " and IGR Item No: " + record.IGRItem_No : "";
sentence += ".<br>Recorded on " + formatDateTime(record.history_dated) + ".";
sentence += "<hr>";
return sentence;
}
</script>
<script src="https://cdn.datatables.net/plug-ins/1.10.16/sorting/datetime-moment.js"></script>
<script>
//<!-- script for table , It works under the datatable plugin-->
$(function() {
$.fn.dataTable.moment('DD-MM-YYYY');
$('#Inwardgateregistertable').DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"aaSorting": [
[0, "desc"]
],
"info": true,
"autoWidth": true
});
});
</script>
<script>
$("#Igrshow").on("shown.bs.modal", function(e) {
var inx = $(e.relatedTarget).data('id');
var igr = $(e.relatedTarget).data('userid');
var igrstatus = $(e.relatedTarget).data('igrstatus');
// alert(igrstatus);
var buttonContainer = $("#buttonContainer");
var modal = $(this); // Reference to the modal itself
var invoiceDateInput = modal.find('#Invoice_Date');
var MaterialRcvdDateInput = modal.find('#MaterialRcvdDate');
var VehicleNoInput = modal.find('#Vehicle_No');
var DriverInput = modal.find('#Driver_Name');
var DriverMobileNumberInput = modal.find('#DriverMobileNumber');
if (igrstatus == "ST074") {
// Show buttons in the container
buttonContainer.find("#draftIGR, #generateIGR").css("display", "inline-block");
// Changed into Readonly = false
// invoiceDateInput.prop('readonly', false);
// MaterialRcvdDateInput.prop('readonly', false);
VehicleNoInput.prop('readonly', false);
DriverInput.prop('readonly', false);
DriverMobileNumberInput.prop('readonly', false);
} else {
// Hide buttons in the container
buttonContainer.find("#draftIGR, #generateIGR").css("display", "none");
// Changed into Readonly = true
// invoiceDateInput.prop('readonly', true);
// MaterialRcvdDateInput.prop('readonly', true);
VehicleNoInput.prop('readonly', true);
DriverInput.prop('readonly', true);
DriverMobileNumberInput.prop('readonly', true);
}
$("#tbleAppend1").empty();
$('#content').loader('show');
$.ajax({
data: { id: igr },
type: "POST",
//dataType: 'json',
url: "<?php echo base_url() ?>inwardgateregister/ViewIGR",
success: function(data) {
// success:function(data) {
$('#content').loader('hide');
var trHTML = '';
$.each(JSON.parse(data), function(i, item) {
if (igr == item.IGRNO) {
$("#IGRNO1").val(item.IGRNO);
$("#IGRItemNo").val(item.IGRItemNo);
var baseUrl = '<?php echo base_url(); ?>purchaseorder/CreatePOPrint';
var newUrl = baseUrl + '?PONO=' + item.PONO + '&ReqType=' + item.POType;
$('#printLink').attr('href', newUrl);
$("#Vehicle_No").val(item.VehicleNo);
$("#Driver_Name").val(item.DriverName);
$("#DriverMobileNumber").val(item.DriverMobileNumber);
$("#IGRStatus").val(item.IGRStatus);
$("#PONo").val(item.PONO);
$("#Supplier").val(item.SupplierName);
$("#Add1").val(item.Address);
$("#Invoice_No").val(item.DeliveryChellanOrInvoiceNo);
//alert(item.DeliveryChellanDate);
var dcd = new Date(item.DeliveryChellanDate);
//alert(dcd.getDate()+ '.' + (dcd.getMonth() + 1)+ '.' + dcd.getFullYear());
var dcd2 = (dcd.getDate() + '/' + (dcd.getMonth() + 1) + '/' + dcd.getFullYear());
$("#Invoice_Date").val(dcd2);
if (item.MaterialRcvdDate === null) {
var Mat_rcv_date = ' ';
} else {
var MR_dt = new Date(item.MaterialRcvdDate);
var Mat_rcv_date = (MR_dt.getDate() + '/' + (MR_dt.getMonth() + 1) + '/' + MR_dt.getFullYear());
}
$("#MaterialRcvdDate").val(Mat_rcv_date);
if (item.GrossWeightDate === null) {
var gross_rcv_date = ' ';
} else {
var G_dt = new Date(item.GrossWeightDate);
var gross_rcv_date = formatDateTime(G_dt);
}
$("#ser").val(item.ServiceDescription);
i = i + 1;
if (igrstatus == "ST074") {
// document.getElementById('pendingQuantityHeader').style.display = 'table-cell';
$("#pendingQuantityHeader").css("display", "table-cell");
trHTML += '<tr>' +
'<td align="right">' + i + '</td>' +
'<td name="MaterialName" onchange="test(' + i + ')">' + item.MaterialCode + '</td>' +
'<td>' + item.MaterialName + '</td>' +
'<td name="UOM">' + item.UOM + '</td>' +
'<td align="right" id="Quantity' + i + '" name="Quantity">' + parseInt(item.Quantity) + '</td>' +
'<td align="right" data-name="sel" ><input type="text" onchange="validateReceivedQuantity(' + i + ')"id="QuantityAsPerInvoice' + i + '" name="QuantityAsPerInvoice' + i + '" value="' + parseInt(item.QuantityAsPerInvoice) + '" onkeypress="return isNumberKey(event);"></td>' +
'<td name="PendingQuantity' + i + '" id="PendingQuantity' + i + '">' + parseInt(item.Quantity - item.QuantityAsPerInvoice) + '</td>' +
'<td><input type="text" id="Remark' + i + '" name="Remark' + i + '" class="form" onchange="SetRemarks(' + i + ')"> </td>' +
'<td><a target="_blank" data-toggle="modal" data-target="#WeightCalculator" title="Weight Calculator" data-index="'+i+'" data-material="'+item.MaterialName+'" data-igrstatus = "'+igrstatus+'"><i class="fa fa-solid fa-calculator" style="text-align: center;"></i></a> </td>' +
'<input type="hidden" id="IGRNO' + i + '" name="IGRNO' + i + '" value="' + item.IGRNO + '">' +
'<input type="hidden" id="IGRItemNo' + i + '" name="IGRItemNo' + i + '" value="' + item.IGRItemNo + '">' +
'<input type="hidden" id="MaterialCode' + i + '" name="MaterialCode' + i + '" value="' + item.MaterialCode + '">' +
'<input type="hidden" id="txtQuantityAsPerInvoice' + i + '" name="txtQuantityAsPerInvoice' + i + '" value="' + item.QuantityAsPerInvoice + '">' +
'<input type="hidden" id="txtOrderedQuantity' + i + '" name="txtOrderedQuantity' + i + '" value="' + item.Quantity + '">' +
'<input type="hidden" id="txtGrossWeight' + i + '" name="txtGrossWeight' + i + '" value="' + item.GrossWeight + '">' +
'<input type="hidden" id="txtGrossWeightDate' + i + '" name="txtGrossWeightDate' + i + '" value="' + item.GrossWeightDate + '">' +
'<input type="hidden" id="txtTareWeight' + i + '" name="txtTareWeight' + i + '" value="' + item.TareWeight + '">' +
'<input type="hidden" id="txtTareWeightDate' + i + '" name="txtTareWeightDate' + i + '" value="' + item.TareWeightDate + '">' +
'<input type="hidden" id="txtNetWeight' + i + '" name="txtNetWeight' + i + '"value="' + item.NetWeight + '">' +
'<input type="hidden" id="txtRemarks' + i + '" name="txtRemarks' + i + '">'; // Example with no initial value
'</tr>';
//alert(item.PendingQty);
if ((item.Quantity - item.QuantityAsPerInvoice) == 0.00) {
$('#QuantityAsPerInvoice' + i).attr('readonly', 'true');
}
// console.log("Ifpart ... ");
} else {
$("#pendingQuantityHeader").css("display", "none");
// console.log("elsepart ... ");
trHTML += '<tr>' +
'<td align="right">' + i + '</td>' +
'<td name="MaterialName" id="MaterialCode" onchange="test(' + i + ')">' + item.MaterialCode + '</td>' +
'<td>' + item.MaterialName + '</td>' +
'<td name="UOM">' + item.UOM + '</td>' +
'<td align="right" name="Quantity">' + item.Quantity + '</td>' +
'<td align="right" data-name="sel" >' + item.QuantityAsPerInvoice + '</td>' +
'<td>' + item.Remarks + '</td>' +
'<td><a target="_blank" data-toggle="modal" data-target="#WeightCalculator" title="Weight Calculator" data-index="'+i+'" data-material="'+item.MaterialName+'" data-igrstatus = "'+igrstatus+'"><i class="fa fa-solid fa-calculator" style="text-align: center;"></i></a> </td>' +
'<input type="hidden" id="txtGrossWeight' + i + '" name="txtGrossWeight' + i + '" value="' + item.GrossWeight + '">' +
'<input type="hidden" id="txtGrossWeightDate' + i + '" name="txtGrossWeightDate' + i + '" value="' + item.GrossWeightDate + '">' +
'<input type="hidden" id="txtTareWeight' + i + '" name="txtTareWeight' + i + '" value="' + item.TareWeight + '">' +
'<input type="hidden" id="txtTareWeightDate' + i + '" name="txtTareWeightDate' + i + '" value="' + item.TareWeightDate + '">' +
'<input type="hidden" id="txtNetWeight' + i + '" name="txtNetWeight' + i + '"value="' + item.NetWeight + '">' +
'</tr>';
}
//alert(item.QuantityAsPerInvoice);
}
});
$("#tbleAppend1").empty();
$('#Inwardgateregistertable1 > tbody').append(trHTML);
}
});
});
</script>
<script>
var counter = 0;
//var counterConstant = 0;
$("#addmorebutton").click(function() {
var file_count = $("#counts").val();
counter++;
var bil_count = +counter + +file_count;
// alert(bil_count);
// alert(file_count);
if (bil_count >= 6) {
alert("You have to upload five files only"); //this allows only 5 files;
$('#addmorebutton').hide();
return false;
}
var div = document.createElement('div');
div.id = "divid";
div.className = "row";
//alert(counter);
div.innerHTML = '<div class="col-md-12">' +
// '<div class="col-md-3">'+
// '<label>File Name</label>'+
// '<input type="text" id="maint_filename'+counterConstant+'" name="filename'+counterConstant+'" class="form-control" onkeypress="return false;" readonly/>'+
// '</div>'+
'<div class="col-md-3">' +
'<label><br></label>' +
'<input type="file" name="browseFiles" id="images' + counter + '" ><br>' +
'</div>' +
// '<div class="col-md-3">'
// '<label><br><br></label>'+
// '<button class="btn btn-danger remove remove_this" id="removebtn'+counterConstant+'" onclick="removeRow(this.id)"><i class="fa fa-trash"></i> Remove</button></div>'+
'<div class="col-md-2">' +
'<label><br><br></label>' +
'<button class="btn btn-success" type ="button" id="addbtn" onclick="addRow()">ADD</button></div>' +
'</div>' +
'</div>';
$('#newdiv').append(div);
$('#hidecounter').val(counter);
if (counter > 1) {
alert("Add button click here"); //this allows only 5 files;
return false;
} else {
$('#addmorebutton').hide();
}
//}
});
function addRow() {
//var file = $('#imag').val();
var file = $('#images' + counter).val();
if (file == '') {
alert('File not found');
} else {
fileupload(counter);
}
}
// function Copyfilename(id)
// {
// var size = $('input[name='+id+']')[0].files[0].size;
// var number = id.replace(/[^0-9]+/ig,"");
// if(size > 2100000){
// //alert(id);
// alert('Sorry Your File is Large To 2MB');
// removeRow(id);
// //$('input[name = browseFiles'+number+']').val(' ');
// }else {
// var name = $('input[name='+id+']')[0].files[0].name;
// //alert(name);
// $("#maint_filename"+number).val(name);
// }
// }
function fileupload(counter) {
//alert(counter);
var formData = new FormData();
// var file = $("#images"+counter).prop('file')[0];
var file = document.getElementById('images' + counter).files[0];
// alert(file);
var PONO = $('#hiddenPONO').val();
// alert(PONO);
var igr = $('#hiddenIGRNO').val();
//alert(igr);
formData.append('file', file);
formData.append('PONO', PONO);
formData.append('count', counter);
formData.append('igr', igr);
$('.content').loader('show');
$.ajax({
data: formData,
type: "POST",
url: "<?php echo base_url() ?>inwardgateregister/addloadfile",
cache: false,
contentType: false,
processData: false,
success: function(data) {
if (data) {
alert(data);
window.location.reload();
$('.content').loader('hide');
// $('#spl').find('td').eq(5).text(filename[2]);
$('#billModel').modal('hide');
}
}
});
}
</script>
<script>
function SetRemarks(RowId) {
var remks = $("#Remark" + RowId).val();
if (remks != '') {
$("#txtRemarks" + RowId).val(remks);
}
}
function validateReceivedQuantity(Rowid) {
var InvoiceQty = parseFloat($('#QuantityAsPerInvoice' + Rowid).val() || '0.00'); // working fine
var OrderedQty = parseFloat($("#Quantity" + Rowid).text());
if (parseInt(OrderedQty) !== 0) {
if ((InvoiceQty) > OrderedQty) {
alert("Pending Quantity is exceeding the Ordered Quantity. Please contact the Purchase Team for further process.");
$("#QuantityAsPerInvoice" + Rowid).focus().val('');
return false;
} else if ((InvoiceQty) - OrderedQty > 0.00) {
alert("Order is completed.");
$("#QuantityAsPerInvoice" + Rowid).focus().val('');
return false;
} else {
var PendingQty = OrderedQty - (InvoiceQty);
$('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0));
$('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0));
$('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2));
return true;
}
} else {
var PendingQty = OrderedQty - (InvoiceQty);
$('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0));
$('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0));
$('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2));
return true;
}
}
</script>
<script>
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode != 46 && charCode > 31 &&
(charCode < 48 || charCode > 57))
return false;
return true;
}
</script>
<script>
function setStatusAndSubmit(status) {
var statuscode = (status == "draft") ? 'ST074' : 'ST027';
alert('updated function entered');
$('#content').loader('show');
var igrno = $("#IGRNO1").val();
var VehicleNo = $("#Vehicle_No").val();
var DriverName = $("#Driver_Name").val();
var DriverMobileNumber = $("#DriverMobileNumber").val();
var GrossWeight = $("#GrossWeight").val()
var TareWeight = $("#TareWeight").val()
var NetWeight = $("#NetWeight").val()
var GrossWeightDate = $("#GrossWeightDate").val()
var TareWeightDate = $("#TareWeightDate").val()
var dataToSend = [];
$('#tbleAppend1 tr').each(function(index, row) {
var rowData = {};
$(row).find('input[type="hidden"]').each(function() {
var fieldName = $(this).attr('name');
var fieldValue = $(this).val();
rowData[fieldName] = fieldValue;
});
dataToSend.push(rowData);
});
console.log(dataToSend);
$.ajax({
url: "<?php echo base_url() ?>inwardgateregister/updateIGRLineItem",
type: "POST",
dataType: 'json',
data: {
IGRNO: igrno,
IGRStatus: statuscode,
VehicleNo: VehicleNo,
DriverName: DriverName,
DriverMobileNumber: DriverMobileNumber,
GrossWeight: GrossWeight,
TareWeight: TareWeight,
NetWeight: NetWeight,
GrossWeightDate: GrossWeightDate,
TareWeightDate: TareWeightDate,
data: JSON.stringify(dataToSend)
},
success: function(response) {
$('#content').loader('hide');
console.log('Data saved successfully:', response);
alert(response.message);
// Close the modal
$('#Igrshow').modal('hide');
// location.reload();
setTimeout(function() {
location.reload();
}, 500);
},
error: function(jqXHR, textStatus, errorThrown) {
$('#content').loader('hide');
console.error('Error saving data:', textStatus, errorThrown);
alert(response.message);
$('#Igrshow').modal('hide');
}
});
}
</script>
<script>
function WeightDiffer(element) {
// console.log(element);
var v1 = $("#GrossWeight").val();
var v2 = $("#TareWeight").val();
var v3 = v1 - v2;
$("#NetWeight").val(v3);
if (element.id === 'GrossWeight') {
$("#GrossWeightDate").val($("#clock").text());
}
if (element.id === 'TareWeight') {
$("#TareWeightDate").val($("#clock").text());
}
}
function updateTime() {
const now = new Date();
const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, '0');
const todaydate = now.getDate().toString().padStart(2, '0');
const hours = now.getHours().toString().padStart(2, '0');
const minutes = now.getMinutes().toString().padStart(2, '0');
const seconds = now.getSeconds().toString().padStart(2, '0');
const dateString = todaydate + '-' + month + '-' + year;
const timeString = hours + ":" + minutes + ":" + seconds;
document.getElementById('clock').textContent = dateString + " " + timeString;
}
setInterval(updateTime, 1000); // Update every second
updateTime(); // Initial call to display time immediately
</script>
<script>
function formatDateTime(dateString) {
// Check if the date string is null
if (dateString === null) {
return ' ';
} else {
// Create a new Date object from the date string
var date = new Date(dateString);
// Extract date components
var day = date.getDate().toString().padStart(2, '0');
var month = (date.getMonth() + 1).toString().padStart(2, '0'); // Months are zero-based
var year = date.getFullYear();
// Extract time components
var hours = date.getHours().toString().padStart(2, '0');
var minutes = date.getMinutes().toString().padStart(2, '0');
var seconds = date.getSeconds().toString().padStart(2, '0');
// Format the date and time in DD-MM-YYYY HH:MM:SS format
var formattedDate = `${day}-${month}-${year} ${hours}:${minutes}:${seconds}`;
return formattedDate;
}
}
</script>
<script>
$("#WeightCalculator").on("shown.bs.modal", function(e) {
var inx = $(e.relatedTarget).data('index');
var material = $(e.relatedTarget).data('material');
var igrstatus = $(e.relatedTarget).data('igrstatus');
document.getElementById('material').textContent = " ( "+material+" )";
// Clear the modal inputs
$("#GrossWeight").val('');
$("#GrossWeightDate").val('');
$("#TareWeight").val('');
$("#TareWeightDate").val('');
$("#NetWeight").val('');
// Retrieve values from hidden inputs
var v1 = $("#txtGrossWeight" + inx).val();
var v2 = $("#txtGrossWeightDate" + inx).val();
var v3 = $("#txtTareWeight" + inx).val();
var v4 = $("#txtTareWeightDate" + inx).val();
var v5 = $("#txtNetWeight" + inx).val();
// Debugging alerts
// console.log("v1:", v1);
// console.log("v2:", v2);
// console.log("v3:", v3);
// console.log("v4:", v4);
// console.log("v5:", v5);
console.log("Selected values for index:", typeof inx,inx);
// Set modal inputs with the retrieved values
$("#GrossWeight").val(v1);
$("#GrossWeightDate").val(v2);
$("#TareWeight").val(v3);
$("#TareWeightDate").val(v4);
$("#NetWeight").val(v5);
$("#CurrentInx").val(inx);
if (igrstatus !== "ST074") {
// $("#Vehicle_No").attr('readonly', true);
// $("#Driver_Name").attr('readonly', true);
// $("#DriverMobileNumber").attr('readonly', true);
$("#GrossWeight").attr('readonly', true);
$("#TareWeight").attr('readonly', true);
$("#modalsave").hide();
}
});
function modalSave() {
var v1 = $("#GrossWeight").val();
var v2 = $("#GrossWeightDate").val();
var v3 = $("#TareWeight").val();
var v4 = $("#TareWeightDate").val();
var v5 = $("#NetWeight").val();
var v6 = $("#CurrentInx").val();
// Debugging alerts
// console.log("v1:", v1);
// console.log("v2:", v2);
// console.log("v3:", v3);
// console.log("v4:", v4);
// console.log("v5:", v5);
if (v6 !== undefined && v6 !== '') {
console.log("Saving values for index:", v6);
// Set the values back to the hidden inputs
$("#txtGrossWeight" + v6).val(v1);
$("#txtGrossWeightDate" + v6).val(v2);
$("#txtTareWeight" + v6).val(v3);
$("#txtTareWeightDate" + v6).val(v4);
$("#txtNetWeight" + v6).val(v5);
// Clear modal inputs
$("#GrossWeight").val('');
$("#GrossWeightDate").val('');
$("#TareWeight").val('');
$("#TareWeightDate").val('');
$("#NetWeight").val('');
// Close the modal
$("#WeightCalculator").modal('hide');
} else {
console.log("Saving values for index: "+v6+" undefined");
}
}
</script>