ria/app/Views/viewinwardgateregister.php

2873 lines
100 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.

<!-- Flatpickr CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<!-- Flatpickr JS -->
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<style>
.num {
text-align: right;
}
#Inwardgateregistertable1 thead tr th{
width: 150px;
word-wrap: break-word;
white-space: normal;
}
th {
white-space: nowrap;
}
.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>
<style>
th,
td {
white-space: nowrap;
}
</style>
<style>
.dataTables_wrapper .top {
display: flex;
justify-content: space-between;
align-items: center;
}
.dataTables_wrapper .dataTables_length {
float: left;
}
.footer-textarea {
width: 100%;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
}
.send-btn {
padding: 10px 20px;
background-color: #2ecc71; /* Green color */
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.send-btn:hover {
background-color: #27ae60; /* Darker green on hover */
}
</style>
<script>
$(function() {
var d = new Date();
var month = d.getMonth();
var day = d.getDate();
var year = d.getFullYear();
var SIAStartYear = year - 2015;
var mindt = year - 70;
var maxdt = year - 15;
// $("#Invoice_Date , #MaterialRcvdDate").datepicker({
// minDate: new Date(year - SIAStartYear, 1, 1),
// maxDate: 'now',
// dateFormat: 'dd-mm-yy',
// changeMonth: true,
// changeYear: true,
// yearRange: '-100:+0'
// });
});
</script>
<style>
.autocomplete-suggestion {
cursor: pointer;
background-color: skyblue;
/* background-color: darkgrey; */
outline: 1px solid slategrey;
}
.igr-remarks{
position: relative;
}
.igr-remarks i{
font-size: 14px;
}
.igr-remarks span{
position: absolute;
top: -5px;
right: -6px;
background-color: transparent;
border-radius: 50px!important;
font-weight: 600;
width: 14px;
box-shadow: 0 0 20px 0 rgba(0,0,0,0.2);
color:#35462c;
}
</style>
<script type="text/javascript" src="<?php echo base_url(); ?>public/assets/Autocomplete/jquery.autocomplete.js"></script>
<div class="content-page">
<div class="content">
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<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);">Inward</a></li>
<li class="breadcrumb-item active">
<h4 class="page-title">View Inward Gate Register</h4>
</li>
</ol>
</div>
</div>
</div>
</div>
<?php if (session()->getFlashdata('message')): ?>
<div class="alert alert-warning" role="alert">
<?= esc(session()->getFlashdata('message')); ?>
</div>
<?php endif; ?>
<div class="row">
<div class="col-12">
<div class="card">
<div class="row">
<div class="col-md-8">
<form class="Date-filter-form" style="margin-top: 14px;margin-bottom: -11px;margin-left: 33px;" method="post" action="<?= base_url('ViewIGR'); ?>">
<label for="fromDate">From:</label>
<input class="form-control date_range form-date-search"
value="<?= $fromDate?>"
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"
value="<?= $toDate ?>"
id="toDate" name="toDate" placeholder="Select To Date" autocomplete="off" required>
<button type="submit" class="range_search_button" >
<i class="fe-search" aria-hidden="true" class="icon-button" title="Search"></i>
</button>
<i class="fe-rotate-cw range_reset_button"
style="cursor:pointer;"
aria-hidden="true" class="icon-button" id="resetButton" title="Reset"></i>
<div class="error" id="error"></div>
</form>
</div>
<!-- <div class="col-md-4">
<button id="downloadExcel" class="btn btn-primary" style="margin-top: 14px;margin-bottom: -11px;margin-right: 25px;float: right;">Download Excel</button>
</div> -->
</div>
<div class="card-body" style="overflow-x:scroll;">
<table id="view_inward_gate_register" class="table table-bordered table-hover">
<thead>
<tr>
<th>IGR Date</th>
<th>IGR Time</th>
<th>IGR No</th>
<th>PO No</th>
<th>Supplier Name</th>
<th>Invoice No</th>
<th>Invoice Date </th>
<!--!!!!!..... Don't remove the comment ..!!!!!!!!!!!! -->
<!-- temporarily removed as per client requirement to remove item count -->
<th style="display:none;">Item Count</th>
<!-- Rec qty changed to invoice qty -->
<th>Invoice Qty</th>
<th>Net weight</th>
<th>Taxable Amt</th>
<th>Tax Amt</th>
<th>Total Amt</th>
<th>Vechicle No</th>
<th>Driver</th>
<th>Transporter</th>
<th>IGR Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
if(!empty($IGR))
{
$index = 0;
foreach($IGR as $record)
{ $index = $index +1;
$createddate = new DateTime($record->CreatedDate);
$date = $createddate->format('d-m-Y');
$time = $createddate->format('h:i A');
?>
<tr id="<?php echo $index ?>" >
<td align="left" style="padding-left: 0.4%"><?php echo $date; ?></td>
<td align="center"><?php echo $time; ?></td>
<td style="cursor:pointer; color:#0bb2b5" >
<a
class="edit-btn"
data-toggle="modal"
data-target="#Igrshow"
data-id="<?php echo $index;?>"
data-inx="<?php echo $index;?>"
data-userid="<?php echo $record->IGRNO ?>"
data-igrstatus="<?php echo $record->IGRStatus ?>">
<?php echo $record->IGRNO ?>
</a>
</td>
<td style="cursor:pointer; color:#0bb2b5" ><a data-toggle="modal" data-target="#CostCentershow" data-id="<?php echo $index;?>" data-igno="<?php echo $record->IGRNO;?>" data-pono="<?php echo $record->PONO ?>" target="_blank">
<?php echo $record->PONO ?></a>
</td>
<td><?php echo $record->SupplierName ?></td>
<td><?php echo $record->DeliveryChellanOrInvoiceNo ?></td>
<td align="left" style="padding-left: 0.4%"><?php
$invdate = $record->DeliveryChellanDate;
if(!$invdate || $invdate == 'null' || $invdate === '0000-00-00 00:00:00'){
echo "";
}else{
$date = new DateTime($invdate);
echo $date->format('d-m-Y'); } ?></td>
<td align="center"
style=" display : none ;"><?php echo $record->itemCount ?></td>
<!-- below one is currently shown as invoice qty -->
<td align="right"><?php echo (int)$record->ReceivedQuantity ?></td>
<td align="right"><?php echo (int)$record->NetWeight ?></td>
<td align="right"><?php echo (int)$record->taxable_value ?></td>
<td align="right"><?php echo number_format((float)$record->gst_amount, 2, '.', ''); ?></td>
<td align="right">
<?php
$total_amt = (float)$record->taxable_value + (float)$record->gst_amount;
echo number_format($total_amt, 2, '.', '');
?>
</td>
<td><?php echo $record->VehicleNo ?></td>
<td><?php echo $record->DriverName ?></td>
<td><?php echo $record->TransporterName ?></td>
<td><?php echo $record->IGRStatus == 'ST074' ? 'Draft' : 'Completed'; ?></td>
<td>
<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>
&nbsp;
<!-- <a class="a_tag_for_mrir" href="<?php echo base_url().'MRIRcontroller/igrdatavalues?IGRNO='.$record->IGRNO; ?>" target="_blank" data-id="<%=index%>" title="Generate MRIR"><i class="fa fa-external-link" style="text-align: center;"></i></a> -->
<?php if(($record->isIgrFilePresent)){ ?>
<a target="_blank" href="<?php echo base_url().'download-files?IGRNO='.$record->IGRNO; ?>">
<i class="fa fa-download" style="text-align: center;"></i>
</a>
&nbsp;
<?php } ?>
<a title="IGR Remarks" class="igr-remarks" data-igrno="<?php echo $record->IGRNO ?>" data-pono="<?php echo $record->PONO ?>">
<i class="fe-bell noti-icon"></i>
<span class="badge badge-danger rounded-circle noti-icon-badge"><?php echo $record->remark_count ?></span>
</a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div> <!-- end card body-->
</div> <!-- end card -->
</div><!-- end col-->
</div>
</div>
</div> <!-- container -->
</div> <!-- content -->
</div>
<!-- box closed here -->
<!-- modal1 - IGR Remarks modal -->
<div id="right-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-sm modal-right">
<div class="modal-content">
<div class="modal-header border-0">
<h5 class="modal-title" style="font-size: large;"></h5>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body" style="border-top: 1px solid #2ecc71;border-bottom: 1px solid #2ecc71;">
</div>
<div class="modal-footer">
<input type="hidden" id="selected_igr">
<textarea class="footer-textarea" id="igr_remark" placeholder="Enter your message here..."></textarea>
<button class="send-btn" id="save_remark">
Send Message..
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<!-- /.modal fade closed (IGR Remarks)-->
<!-- modal2 - Edit Igr modal -->
<div id="Igrshow" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal " style="width:1250px;">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Inward Gate Register Details <span id="IgrshowTitle"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body p-4">
<div class="pull-right hidden-xs">
<b>
<div id="clock"></div>
</b>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="d-flex justify-content-between align-items-center">
<label class="col-form-label">Purchase Order Number <span class="text-danger">*</span></label>
<a id="printLink" data-toggle="tooltip" href="" target="new" style="text-align: right;">
<i class="fa fa-print" data-toggle="tooltip" title="Click here to Print the Purchase Order details"></i>
</a>
</div>
<?php $data = array('name' => 'PurchaseOrderNumber', 'value' => set_value('PurchaseOrderNumber'), 'id' => 'PONo', 'class' => 'form-control', 'required=>"true"', 'readonly' => 'true');
echo form_input($data);
?>
<span class="help-block"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-form-label">Supplier Name <span class="text-danger">*</span></label>
<?php $data = array('name' => 'SupplierName', 'value' => set_value('SupplierName'), 'id' => 'Supplier', 'class' => 'form-control', 'required=>"true"', 'readonly' => 'true' ,'rows' => 2);
echo form_textarea($data);
?>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label class="col-form-label">Invoice Number <span class="text-danger">*</span></label>
<?php $data = array('name' => 'InvoiceNO', 'value' => set_value('InvoiceNO'), 'id' => 'Invoice_No', 'class' => 'form-control', 'required' =>true);
echo form_input($data);
?>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="col-form-label">Invoice Date <span class="text-danger">*</span></label>
<input type="date" class="form-control" id="InvoiceDate" name="InvoiceDate" required autocomplete="off" style="background-color: #fff !important">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="col-form-label">Material Received Date <span class="text-danger">*</span></label>
<input type="date" class="form-control" id="MaterialRcvdDate" name="MaterialRcvdDate" required autocomplete="off" style="background-color: #fff !important">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="col-form-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>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label class="col-form-label">Transporter Name</label>
<?php
$dropdown = '<select name="TransporterId" id="Transporter_Id" class="form-control select2">';
$dropdown .= '<option value=0>Transporter Name</option>';
if (!empty($transporter)) {
foreach ($transporter as $opt) {
$selected = set_value('TransporterId') == $opt->id ? 'selected' : '';
$disabled = $opt->isactive == 0 ? 'disabled' : '';
$label = $opt->isactive == 0 ? $opt->name . ' (Inactive)' : $opt->name;
$dropdown .= "<option value='{$opt->id}' $selected $disabled>{$label}</option>";
}
}
$dropdown .= '</select>';
echo $dropdown;
?>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="col-form-label">Driver Name </label>
<?php $data = array('name' => 'DriverName', 'value' => set_value('DriverName'), 'id' => 'Driver_Name', 'class' => 'form-control', 'maxlength' => '50', 'autocomplete' => 'off','list' => 'driverlist','onchange' => "fetchMobileNumber(this.value)");
echo form_input($data);
echo '<datalist id="driverlist">';
foreach ($driverlist as $driver) {
echo '<option value="' . $driver['DriverName'] . ( ( $driver['DriverMobileNumber'] ) ? ' - ' . $driver['DriverMobileNumber'] : '' ) . '" >';
}
echo '</datalist>';
?>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="col-form-label">Driver Mobile Number </label>
<?php
$data = array('name' => 'DriverMobileNumber','value' => set_value('DriverMobileNumber'),'id' => 'DriverMobileNumber','class' => 'form-control', 'maxlength' => '10');
echo form_input($data);
?>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="col-form-label">Remark<span class="text-danger">*</span></label>
<?php
$data = array('name' => 'MasterRemarks', 'value' => set_value('MasterRemarks'), 'id' => 'MasterRemarks', 'class' => 'form-control', 'autocomplete' => 'off','rows' => 3,'required' =>true);
echo form_textarea($data);
?>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table id="Inwardgateregistertable1" class="table table-bordered table-hover mb-0 editabletable IGR_Line" style="font-size:12px;">
<thead style="background-color:#ddd !important">
<tr>
<th style="width: 50px;">SNo</th>
<th style="width: 100px;">Item Code</th>
<th style="width: 150px;">Item Description</th>
<th style="width: 50px;">HSN/SAC</th>
<th style="width: 50px;">UOM</th>
<th style="width: 100px;">Ordered Qty</th>
<th style="width: 100px;">Received Qty</th>
<th id="pendingQuantityHeader" style="display:none; width: 100px;">Pending Qty</th>
<th style="width: 50px;">Rate</th>
<th style="width: 50px;">Tax (%)</th>
<th style="width: 50px;">Taxable Amt</th>
<th style="width: 50px;">Total Amt</th>
<th style="width: 150px;">Remarks </th>
<th style="width: 25px;">Net Weight</th>
</tr>
</thead>
<tbody id="tbleIGRAppend">
</tbody>
</table>
</div>
</div>
</div>
<br><br>
<div class="row text-left">
<br>
<div class="form-group col-md-5">
<label> Master IGR file</label>
<br>
<input type="file" name="MasterFile" id="MasterFile" onchange="filenames(this.name); ">
<label id="MasterFileLabel" style="display:none;" class="mt-1">
<a><span></span><small></small></a>
</label>
</div>
</div>
<div class="files ">
<div class="form-row float-right">
<div class="form-group">
<button type="button" class="btn btn-primary waves-effect btn-sm a1"
onclick="appendFilesFileds()" id="additionalfilebtn">
Add Additional File
</button>
</div>
</div>
<div class="form-row">
<div class="col-md-12" id="existingContainer"></div>
</div>
<div class="form-row">
<div class="col-md-12" id="filesContainer"></div>
</div>
</div><br>
<div class="row">
<div class="col-md-12">
<input type="hidden" name="hiddenIsOpenOrder" id="hiddenIsOpenOrder" />
<input type="hidden" id="IGRNO1" name="IGRNumber" readonly>
<input type="hidden" id="PONO1" name="PONumber" readonly>
</div>
</div>
</div>
<div class="modal-footer">
<div class="buttonContainer">
<a class="btn btn-secondary" data-dismiss="modal" value="Close">Close</a>
<a class="btn btn-primary auditor-restricted" id="generateIGR" value="generateIGR">Generate IGR</a>
<a class="btn btn-primary" id="draftIGR" value="draftIGR">Save as Draft IGR</a>
</div>
</div>
</div>
</div>
</div>
<!-- /.modal fade closed (Edit Igr)-->
<!-- modal3 - Weight Calculator modal -->
<div id="WeightCalculator" class="modal fade" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-lg">
<div class="modal-content" style="border: 1px solid #ddd; margin-top: 73px; box-shadow: 0 0 40px rgb(0 0 0 / 43%);">
<div class="modal-header">
<h4 class="modal-title">Weight Calculator <span id="WeightTitle"></span></h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
</div>
<div class="modal-body p-4">
<div class="text-right">
<b>
<div id="clock"></div>
</b>
</div>
<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' => 'validateTareWeight(this);', '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 class="col-md-5">
<input type="file" name="WeightFile" id="WeightFile" onchange="filenames(this.name); "><br>
<label id="WeightFileLabel" style="display:none;">
<a><span></span><small></small></a>
</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect"
data-dismiss="modal" value="Cancel">Cancel</button>
<?php if(session()->get('roleText') == 'System Administrator' || session()->get('roleText') == 'Security' || session()->get('roleText') == 'Auditor'){?>
<button type="button"
class="btn btn-info waves-effect waves-light" onclick="modalSave()">Save</button>
<?php } ?>
</div>
</div>
</div>
</div>
<!-- /.modal fade closed (Weight Calculator)-->
<!-- gas shortage list gasShortageList-->
<!-- Modal -->
<div id="gasShortageList" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gasShortageListLabel" aria-hidden="true">
<div class="modal-dialog modal-xl " role="document">
<div class="modal-content" style="border: 1px solid #ddd; margin-top: 73px; box-shadow: 0 0 40px rgb(0 0 0 / 43%);">
<div class="modal-header">
<h5 class="modal-title" id="gasShortageListLabel" align="center">List of Gas Shortages</h5>
<button type="button" class="btn btn-primary btn-sm" id="exportGasShortage" style="margin-left: 10px;">
Export &nbsp;
<i class="fa fa-download" style="color:white;"></i>
</button>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" >
<table id="gasShortageTable" class="table table-bordered table-hover">
<thead>
<tr>
<th>Full Cylinder Date</th>
<th>Empty Cylinder Date</th>
<th>Invoice No</th>
<th>Cylinder No</th>
<th>Gross Weight</th>
<th>Tare Weight</th>
<th>Net Weight</th>
<th>Actual Weight</th>
<th>Shortage</th>
<th style="display:none">ID</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- end of gas shortage list -->
<!-- gas Shortage Calculator modal gasShortageCalculator -->
<div id="gasShortageCalculator" data-form="add" class="modal fade" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-large">
<div class="modal-content" style="border: 1px solid #ddd; margin-top: 73px; box-shadow: 0 0 40px rgb(0 0 0 / 43%);">
<div class="modal-header">
<h4 class="modal-title">Add Gas Shortage </h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
</div>
<div class="modal-body p-4">
<form action="#">
<!-- first row full cylinder date and empty cylinder date -->
<div class="form-group row">
<div class="col-md-6">
<label for="fullCylinderDateId"> Full Cylinder Date</label>
<input type="date" class="form-control" id="fullCylinderDateId" name="fullCylinderDate" value="" required>
</div>
<div class="col-md-6">
<label for="emptyCylinderDateId"> Empty Cylinder Date</label>
<input type="date" class="form-control" id="emptyCylinderDateId" name="emptyCylinderDate" value="" required>
</div>
</div>
<!-- second row cylinder no and Invoice No-->
<div class="form-group row">
<div class="col-md-6">
<label for="invoiceNoId"> Invoice No / Bill No</label>
<input type="text" class="form-control" id="invoiceNoId" name="invoiceNo" value="" readonly>
</div>
<div class="col-md-6">
<label for="cylinderNoId"> Cylinder No </label>
<input type="text" class="form-control" id="cylinderNoId" name="cylinderNo" value="" required>
</div>
</div>
<!-- third row gross weight and tare weight -->
<div class="form-group row">
<div class="col-md-6">
<label for="grossWeightId"> Gross Weight </label>
<input type="text" class="form-control" id="grossWeightId" name="grossWeight" value="" required>
</div>
<div class="col-md-6">
<label for="tareWeightId"> Tare Weight </label>
<input type="text" class="form-control" id="tareWeightId" name="tareWeight" value="" required>
</div>
</div>
<!-- fourth row NetWeight and actual weight -->
<div class="form-group row">
<div class="col-md-6">
<label for="actualWeightId"> Actual Weight </label>
<input type="text" class="form-control" id="actualWeightId" name="actualWeight" value="" required>
</div>
<div class="col-md-6">
<label for="netWeightId"> Net Weight (Gross-Tare)</label>
<input type="text" class="form-control" id="netWeightId" name="netWeight" value="" readonly>
</div>
</div>
<!-- fifth row Gas Shortage -->
<div class="form-group row">
<div class="col-md-6">
<label for="shortageId"> Gas Shortage(Actual-Net)</label>
<input type="text" class="form-control" id="shortageId" name="shortage" value="" readonly>
</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="submit"
class="btn btn-info waves-effect waves-light" >Save</button>
</div>
</form>
</div>
</div>
</div>
<!-- end gas shortage calculator modal -->
<!-- Edit gas Shortage Calculator modal editgasShortageCalculator -->
<div id="editGasShortageCalculator" data-form="edit" class="modal fade" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-large">
<div class="modal-content" style="border: 1px solid #ddd; margin-top: 73px; box-shadow: 0 0 40px rgb(0 0 0 / 43%);">
<div class="modal-header">
<h4 class="modal-title">Update Gas Shortage </h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
</div>
<form action="#">
<div class="modal-body p-4">
<!-- first row full cylinder date and empty cylinder date -->
<div class="form-group row">
<div class="col-md-6">
<label for="editFullCylinderDateId"> Full Cylinder Date</label>
<input type="date" class="form-control" id="editFullCylinderDateId" name="fullCylinderDate" value="" required>
</div>
<div class="col-md-6">
<label for="editEmptyCylinderDateId"> Empty Cylinder Date</label>
<input type="date" class="form-control" id="editEmptyCylinderDateId" name="emptyCylinderDate" value="" required>
</div>
</div>
<!-- second row cylinder no and Invoice No-->
<div class="form-group row">
<div class="col-md-6">
<label for="editInvoiceNoId"> Invoice No / Bill No</label>
<input type="text" class="form-control" id="editInvoiceNoId" name="invoiceNo" value="" readonly>
</div>
<div class="col-md-6">
<label for="editCylinderNoId"> Cylinder No </label>
<input type="text" class="form-control" id="editCylinderNoId" name="cylinderNo" value="" required>
</div>
</div>
<!-- third row gross weight and tare weight -->
<div class="form-group row">
<div class="col-md-6">
<label for="editGrossWeightId"> Gross Weight </label>
<input type="text" class="form-control" id="editGrossWeightId" name="grossWeight" value="" required>
</div>
<div class="col-md-6">
<label for="editTareWeightId"> Tare Weight </label>
<input type="text" class="form-control" id="editTareWeightId" name="tareWeight" value="" required>
</div>
</div>
<!-- fourth row NetWeight and actual weight -->
<div class="form-group row">
<div class="col-md-6">
<label for="editActualWeightId"> Actual Weight </label>
<input type="text" class="form-control" id="editActualWeightId" name="actualWeight" value="" required>
</div>
<div class="col-md-6">
<label for="editNetWeightId"> Net Weight (Gross-Tare)</label>
<input type="text" class="form-control" id="editNetWeightId" name="netWeight" value="" readonly>
</div>
</div>
<!-- fifth row Gas Shortage -->
<div class="form-group row">
<div class="col-md-6">
<label for="editShortageId"> Gas Shortage(Actual-Net)</label>
<input type="text" class="form-control" id="editShortageId" name="shortage" value="" readonly>
</div>
</div>
<!-- hidden fields -->
<input type="hidden" id="editId" name="id" value="" >
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect"
data-dismiss="modal" value="Cancel">Cancel</button>
<button type="submit"
class="btn btn-info waves-effect waves-light" >Save</button>
</div>
</form>
</div>
</div>
</div>
<!-- end gas shortage calculator modal -->
<!-- modal4 - IGR history modal -->
<div id="Historyshow" class="modal fade" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">IGR History Details <span id="HisTitle"></span></h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
</div>
<div class="modal-body p-3">
<div class="row">
<div class="col-md-12">
<div id="HisStatement"></div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect"
data-dismiss="modal" value="Close">Close</button>
</div>
</div>
</div>
</div>
<!-- /.modal fade closed (IGR history)-->
<!-- modal5 - Cost Center modal -->
<div id="CostCentershow" 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">Cost Center List <span id="CCTitle"></span></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 id="CCStatement"></div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect"
data-dismiss="modal" value="Close">Close</button>
</div>
</div>
</div>
</div><!-- /.modal -->
<!-- /.modal fade closed (Cost Center)-->
<script>
$(document).ready(function() {
$("#DriverMobileNumber").on('input', function(e) {
this.value = this.value.replace(/\D/g, '');
});
$(document).on('click', '#save_remark', function(e) {
$('#loader').show();
e.preventDefault();
// Get the data attributes
let igrNo = $('#selected_igr').val();
let remark = $('#igr_remark').val();
// Prepare the data to send
let requestData = {
igr_no: igrNo,
remark: remark
};
// AJAX call
$.ajax({
url: "<?php echo base_url() ?>saveIGRRemarks",
type: 'POST',
data: requestData,
success: function(response) {
$('#loader').hide();
appendRemark(response);
},
error: function(xhr, status, error) {
$('#loader').hide();
alert('Failed to fetch remarks. Please try again.');
}
});
});
$(document).on('click', '.igr-remarks', function(e) {
$('#loader').show();
e.preventDefault();
// Get the data attributes
let igrNo = $(this).data('igrno');
let poNo = $(this).data('pono');
// Set the modal heading dynamically
$('#right-modal .modal-header .modal-title').text(`${igrNo} - Remarks`);
$('#selected_igr').val(igrNo);
// Prepare the data to send
let requestData = {
igr_no: igrNo,
po_no: poNo
};
// AJAX call
$.ajax({
url: "<?php echo base_url() ?>getIGRRemarks",
type: 'POST',
data: requestData,
success: function(response) {
$('#loader').hide();
appendRemark(response);
},
error: function(xhr, status, error) {
$('#loader').hide();
alert('Failed to fetch remarks. Please try again.');
}
});
});
function appendRemark(response)
{
$('#igr_remark').val('');
let remarks = JSON.parse(response);
let remarksHtml = remarks.map(remark => {
// Convert remark_on to the desired format
let remarkDate = new Date(remark.remark_on).toLocaleString('en-US', {
month: 'short', // Short month name (e.g., Dec)
day: '2-digit', // Two-digit day (e.g., 31)
year: 'numeric', // Full year (e.g., 2024)
hour: '2-digit', // Two-digit hour (e.g., 11)
minute: '2-digit', // Two-digit minute (e.g., 42)
hour12: true // 12-hour format with AM/PM
});
return `
<div class="remark-item mb-3" style="padding-bottom: 10px; border-bottom: 1px solid #ddd;">
<p style="margin-bottom: 5px;font-size: 16px;">${remark.remark}</p>
<div style="display: flex; justify-content: space-between; align-items: center; font-size: 14px;">
<span style="color: #555;font-size: 10px;">${remark.remark_by}</span>
<span style="color: #888;font-size: 10px;">${remarkDate}</span>
</div>
</div>
`;
}).join('');
// Inject remarks into the modal body
$('#right-modal .modal-body').html(`
<div class="remarks-container" style="max-height: 350px; overflow-y: auto;">
${remarksHtml}
</div>
`);
$('#right-modal').modal('show');
}
//recent work of adding gas shortage done here..!!
$("#Igrshow").on("shown.bs.modal", function(e) {
$('#Igrshow .modal-dialog').css({'max-width': '100%'});
$('#Igrshow .modal-dialog').show();
$('#loader').show();
var inx = $(e.relatedTarget).data('id');
var igr = $(e.relatedTarget).data('userid');
var igrstatus = $(e.relatedTarget).data('igrstatus');
var roleText = '<?php echo session()->get('roleText') ?>';
// alert(igrstatus);
var buttonContainer = $(".buttonContainer");
var modal = $(this); // Reference to the modal itself
var invoiceDateInput = modal.find('#InvoiceDate');
var invoiceNoInput = modal.find('#Invoice_No');
var MaterialRcvdDateInput = modal.find('#MaterialRcvdDate');
var VehicleNoInput = modal.find('#Vehicle_No');
var TransporterIdInput = modal.find('#Transporter_Id');
var DriverInput = modal.find('#Driver_Name');
var DriverMobileNumberInput = modal.find('#DriverMobileNumber');
var MasterFileInput = modal.find('#MasterFile');
modal.find('#MasterFileLabel').hide();
var userRole = "<?php echo (int)$userRole; ?>";
//based on user role some fields are just read only
if (userRole != 1) {
//based on status == ST074
if (igrstatus == "ST074") {
buttonContainer.find("#draftIGR, #generateIGR").css("display", "inline-block");
$(".a_tag_for_mrir").css("display", "block");
VehicleNoInput.prop('readonly', false);
DriverInput.prop('readonly', false);
DriverMobileNumberInput.prop('readonly', false);
MaterialRcvdDateInput.prop('readonly', false);
invoiceDateInput.prop('readonly', false);
invoiceNoInput.prop('readonly', false);
} else {
buttonContainer.find("#draftIGR, #generateIGR").css("display", "none");
$(".a_tag_for_mrir").css("display", "none");
VehicleNoInput.prop('readonly', true);
DriverInput.prop('readonly', true);
DriverMobileNumberInput.prop('readonly', true);
MaterialRcvdDateInput.prop('readonly', true);
invoiceDateInput.prop('readonly', true);
invoiceNoInput.prop('readonly', true);
}
} else {
$(".a_tag_for_mrir").css("display", "none");
if (igrstatus == "ST074") {
buttonContainer.find("#draftIGR, #generateIGR").css("display", "inline-block");
} else {
buttonContainer.find("#draftIGR").css("display", "none");
}
}
$("#tbleIGRAppend").empty();
// $('#content').loader('show');
$.ajax({
data: {
id: igr
},
type: "POST",
url: "<?php echo base_url() ?>ViewIGRDetails",
success: function(data) {
var parsedData = JSON.parse(data);
console.log(parsedData);
flatpickr("#InvoiceDate", { dateFormat: "d-m-Y",});
flatpickr("#MaterialRcvdDate", { dateFormat: "d-m-Y",});
if (parsedData['details'].length === 0) {
console.log("No data available");
// Reset all relevant fields and table
$('#IgrshowTitle').text('');
$("#IGRNO1").val('');
$("#PONO1").val('');
$("#txtIGRLineItem").val('');
$('#printLink').attr('href', '#');
$('.help-block').text('');
$("#Vehicle_No").val('');
$("#Transporter_Id").val('');
$("#Driver_Name").val('');
$("#DriverMobileNumber").val('');
$("#IGRStatus").val('');
$("#PONo").val('');
$("#Supplier").val('');
$("#Add1").val('');
$("#Invoice_No").val('');
$("#InvoiceDate").val('');
$("#MaterialRcvdDate").val('');
$("#MasterRemarks").val('');
$("#Remark").val('');
$("#ser").val('');
$("#tbleIGRAppend").empty(); // Clear the table
// Hide the MasterFileLabel if no data
modal.find('#MasterFileLabel').hide();
return; // Exit the function early
}
var trIGRHTML = '';
$.each(parsedData['details'], function(i, item) {
if (igr == item.IGRNO) {
console.log(item,"**");
//setting values in the igr modal.. particularly input fields
$('#IgrshowTitle').text(" ( " + item.IGRNO + " ) ");
$("#IGRNO1").val(item.IGRNO);
$("#PONO1").val(item.PONO);
$("#txtIGRLineItem").val(item.IGRItemNo);
var baseUrl = '<?php echo base_url(); ?>purchaseorder/CreatePOPrint';
var newUrl = baseUrl + '?PONO=' + item.PONO + '&ReqType=' + item.POType;
$('#printLink').attr('href', newUrl);
var isOpenOrder = parseInt(item.IsOpenOrder ? item.IsOpenOrder : "0", 2);
console.log(item.IsOpenOrder);
console.log(isOpenOrder);
var formatted_IsOpenOrder = (isOpenOrder === 0 || isNaN(isOpenOrder)) ? "" : "Open";
$('.help-block').text(formatted_IsOpenOrder);
var button_text_for_IGRDraft = (isOpenOrder === 0 || isNaN(isOpenOrder)) ? "Save as Draft IGR" : "Save as Open IGR";
$('#draftIGR').text(button_text_for_IGRDraft);
$("#hiddenIsOpenOrder").val(isOpenOrder);
$("#Vehicle_No").val(item.VehicleNo);
$("#Transporter_Id").val(item.TransporterId);
$("#Driver_Name").val(item.DriverName);
$("#DriverMobileNumber").val(item.DriverMobileNumber);
$("#IGRStatus").val(item.IGRStatus);
$("#PONo").val(item.PONO);
$("#Supplier").val(item.SupplierName + "\n" + item.Address);
$("#Add1").val(item.Address);
$("#Invoice_No").val(item.DeliveryChellanOrInvoiceNo);
$("#MasterRemarks").val(item.Remark);
console.log(typeof item.MasterFile);
modal.find('#MasterFileLabel').hide();
if (typeof item.MasterFile == 'string') {
if (item.MasterFile !== null && item.MasterFile !== undefined && item.MasterFile.trim() !== "") {
modal.find('#MasterFileLabel a').attr('href', '<?php echo base_url() ?>' + 'public/uploads/Igrfiles/' + item.MasterFile);
modal.find('#MasterFileLabel a').attr('title', 'Previous Upload IGR Master File');
modal.find('#MasterFileLabel a').attr('target', '_blank');
modal.find('#MasterFileLabel a span').text('Previous Upload - ');
modal.find('#MasterFileLabel a small').text(item.MasterFile);
modal.find('#MasterFileLabel').show();
}
} else {
modal.find('#MasterFileLabel').hide();
}
// Format dates
// (item.DeliveryChellanDate && item.DeliveryChellanDate !== "0000-00-00 00:00:00")
var dcd = (item.DeliveryChellanDate == 'null') ? ' ' : formatDateTime(item.DeliveryChellanDate, 1);
$("#InvoiceDate").val(dcd);
var Mat_rcv_date = (item.MaterialRcvdDate == 'null') ? ' ' : formatDateTime(item.MaterialRcvdDate, 1);
$("#MaterialRcvdDate").val(Mat_rcv_date);
// console.log(item.MaterialRcvdDate)
var gross_rcv_date = (item.GrossWeightDate == 'null') ? ' ' : formatDateTime(item.GrossWeightDate, 2);
$("#ser").val(item.ServiceDescription);
var amount = item.Rate*item.QuantityAsPerInvoice;
var tax_percentage = item.TaxInPercentage;
var tax_amount = (amount * tax_percentage) / 100;
var grand_total_amount = amount + tax_amount;
i = i + 1;
// userrole is system admin also know as admin (if)
//if role is system admin,
if (userRole == 1) {
$("#pendingQuantityHeader").css("display", "table-cell");
trIGRHTML += '<tr>' +
'<td style="width: 50px;" >' + i + '</td>' +
'<td style="width: 100px;" name="MaterialName" onchange="test(' + i + ')">' + item.MaterialCode + '</td>' +
'<td style="width: 150px; word-wrap: break-word; word-break: break-all; white-space: normal;">' + item.MaterialName + '</td>' +
'<td style="width: 50px;" name="HSNCODE">' + ((item.HSNCODE) ? item.HSNCODE : '') + '</td>' +
'<td style="width: 50px;" name="UOM">' + item.UOM + '</td>' +
'<td style="width: 100px;" id="Quantity' + i + '" name="Quantity">' + parseInt(item.Quantity) + '</td>' +
'<td style="width: 100px;" data-name="sel" ><input type="text" onchange="validateReceivedQuantity(' + i + ',' + isOpenOrder + ')"id="QuantityAsPerInvoice' + i + '" name="QuantityAsPerInvoice' + i + '" value="' + parseInt(item.QuantityAsPerInvoice) + '" onkeypress="return isNumberKey(event);" style="width: 75px;"></td>' +
'<td style="width: 100px;" name="PendingQuantity' + i + '" id="PendingQuantity' + i + '">' + ((isOpenOrder) ? 0 : parseInt(item.Quantity - item.QuantityAsPerInvoice)) + '</td>' +
'<td style="width: 50px;" id="Rate' + i + '" >' + Number(item.Rate).toFixed(2) + '</td>' +
'<td style="width: 50px;" id="tax_percentage' + i + '">' + tax_percentage + '</td>' +
'<td style="width: 50px;" id="amount' + i + '">' + Number(amount).toFixed(2) + '</td>' +
'<td style="width: 50px;" id="grand_total_amount' + i + '">' + Number(grand_total_amount).toFixed(2) + '</td>' +
'<td style="width: 100px;"><input type="text" id="Remark' + i + '" name="Remark' + i + '" class="form auditor-restricted-fieldgr" onchange="SetRemarks(' + i + ')" style="width: 75px;" value="' + item.Remarks + '"></td>'+
'<td style="width: 25px;"><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-truck" style="text-align: center;"></i></a> </td>' +
'<input type="hidden" id="IGRNO' + i + '" name="IGRNO' + i + '" value="' + item.IGRNO + '">' +
'<input type="hidden" id="MaterialCode' + i + '" name="MaterialCode' + i + '" value="' + item.MaterialCode + '">' +
'<input type="hidden" id="MaterialCategory' + i + '" name="MaterialCategory' + i + '" value="' + item.MaterialCategory + '">' +
'<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 + '"value="' + item.Remarks + '">' +
'<input type="hidden" id="txtIGRLineItem' + i + '" name="txtIGRLineItem' + i + '"value="' + item.IGRItemNo + '">' +
'<input type="file" id="txtWeightFile' + i + '" name="txtWeightFile' + i + '"value="' + item.WeightFile + '" style="display:none;">' +
'<input type="hidden" id="txtWeightFileName' + i + '" name="txtWeightFileName' + i + '"value="' + item.WeightFile + '">' ;
if ((item.Quantity - item.QuantityAsPerInvoice) == 0.00) {
$('#QuantityAsPerInvoice' + i).attr('readonly', 'true');
}
}
// other userrole(except admin). based on status we show and here (else if)
else if (userRole !== 1) {
if (igrstatus === "ST074") {
$("#pendingQuantityHeader").css("display", "table-cell");
trIGRHTML += '<tr>' +
'<td style="width: 50px;" >' + i + '</td>' +
'<td style="width: 100px;" name="MaterialName" onchange="test(' + i + ')">' + item.MaterialCode + '</td>' +
'<td style="width: 150px; word-wrap: break-word; word-break: break-all; white-space: normal;">' + item.MaterialName + '</td>' +
'<td style="width: 50px;" name="HSNCODE">' + ((item.HSNCODE) ? item.HSNCODE : '') + '</td>' +
'<td style="width: 50px;" name="UOM">' + item.UOM + '</td>' +
'<td style="width: 100px;" id="Quantity' + i + '" name="Quantity">' + parseInt(item.Quantity) + '</td>';
if (userRole == 5) { // 5 - lab staff
trIGRHTML += '<td style="width: 100px;"> ' + parseInt(item.QuantityAsPerInvoice) + ' </td>';
} else {
trIGRHTML += '<td style="width: 100px;" data-name="sel" ><input type="text" onchange="validateReceivedQuantity(' + i + ',' + isOpenOrder + ')"id="QuantityAsPerInvoice' + i + '" name="QuantityAsPerInvoice' + i + '" value="' + parseInt(item.QuantityAsPerInvoice) + '" onkeypress="return isNumberKey(event);" style="width: 75px;"></td>';
}
trIGRHTML += '<td style="width: 100px;" name="PendingQuantity' + i + '" id="PendingQuantity' + i + '">' + ((isOpenOrder) ? 0 : parseInt(item.Quantity - item.QuantityAsPerInvoice)) + '</td>' +
'<td style="width: 50px;" id="Rate' + i + '" >' + Number(item.Rate).toFixed(2) + '</td>' +
'<td style="width: 50px;" id="tax_percentage' + i + '">' + tax_percentage + '</td>' +
'<td style="width: 50px;" id="amount' + i + '">' + Number(amount).toFixed(2) + '</td>' +
'<td style="width: 50px;" id="grand_total_amount' + i + '">' + Number(grand_total_amount).toFixed(2) + '</td>' ;
if (userRole == 5) {
trIGRHTML += '<td style="width: 100px;">' + item.Remarks + '</td>';
} else {
trIGRHTML += '<td style="width: 100px;">' +
'<input type="text" id="Remark' + i + '" name="Remark' + i + '" class="form auditor-restricted-field" ' +
'onchange="SetRemarks(' + i + ')" style="width: 75px;" value="' + item.Remarks + '">' +
'</td>';
}
trIGRHTML += '<td style="width: 25px;">' + '<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-truck" style="text-align: center;"></i></a>' + '</td>' +
'<input type="hidden" id="IGRNO' + i + '" name="IGRNO' + i + '" value="' + item.IGRNO + '">' +
'<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 + '"value="' + item.Remarks + '">' +
'<input type="hidden" id="txtIGRLineItem' + i + '" name="txtIGRLineItem' + i + '"value="' + item.IGRItemNo + '">' +
'<input type="file" id="txtWeightFile' + i + '" name="txtWeightFile' + i + '"value="' + item.WeightFile + '" style="display:none;">' +
'<input type="hidden" id="txtWeightFileName' + i + '" name="txtWeightFileName' + i + '"value="' + item.WeightFile + '">' ;
if ((item.Quantity - item.QuantityAsPerInvoice) == 0.00) {
$('#QuantityAsPerInvoice' + i).attr('readonly', 'true');
}
} else {
$("#pendingQuantityHeader").css("display", "none");
trIGRHTML += '<tr>' +
'<td style="width: 50px;" >' + i + '</td>' +
'<td style="width: 100px;" name="MaterialName" id="MaterialCode" onchange="test(' + i + ')">' + item.MaterialCode + '</td>' +
'<td style="width: 150px; word-wrap: break-word; word-break: break-all; white-space: normal;">' + item.MaterialName + '</td>' +
'<td style="width: 50px;" name="HSNCODE">' + ((item.HSNCODE) ?item.HSNCODE : '') + '</td>' +
'<td style="width: 50px;" name="UOM">' + item.UOM + '</td>' +
'<td style="width: 100px;" name="Quantity">' + item.Quantity + '</td>' ;
if (userRole == 5) { // 5 - lab staff
trIGRHTML += '<td style="width: 100px;"> ' + Number(item.QuantityAsPerInvoice).toFixed(2) + ' </td>';
} else {
trIGRHTML += '<td style="width: 100px;" data-name="sel" >' + item.QuantityAsPerInvoice + '</td>';
}
trIGRHTML += '<td style="width: 50px;" id="Rate' + i + '" >' + Number(item.Rate).toFixed(2) + '</td>' +
'<td style="width: 50px;" id="tax_percentage' + i + '">' + tax_percentage + '</td>' +
'<td style="width: 50px;" id="amount' + i + '">' + Number(amount).toFixed(2) + '</td>' +
'<td style="width: 50px;" id="grand_total_amount' + i + '">' + Number(grand_total_amount).toFixed(2) + '</td>';
if (userRole == 5) {
trIGRHTML += '<td style="width: 100px;"> ' + item.Remarks + ' </td>';
} else {
trIGRHTML += '<td style="width: 100px;">' +
'<input type="text" id="Remark' + i + '" name="Remark' + i + '" class="form auditor-restricted-field" ' +
'onchange="SetRemarks(' + i + ')" style="width: 75px;" value="' + item.Remarks + '">' +
'</td>';
}
trIGRHTML += '<td style="width: 25px;"><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-truck" style="text-align: center;"></i></a> </td>' +
'<input type="hidden" id="IGRNO' + i + '" name="IGRNO' + i + '" value="' + item.IGRNO + '">' +
'<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 + '"value="' + item.Remarks + '">' +
'<input type="hidden" id="txtIGRLineItem' + i + '" name="txtIGRLineItem' + i + '"value="' + item.IGRItemNo + '">' +
'<input type="file" id="txtWeightFile' + i + '" name="txtWeightFile' + i + '"value="' + item.WeightFile + '">' +
'<input type="hidden" id="txtWeightFileName' + i + '" name="txtWeightFileName' + i + '"value="' + item.WeightFile + '">';
}
}
}
});
$("#tbleIGRAppend").empty();
$("#tbleIGRAppend").append(trIGRHTML);
if (parsedData['files'].length != 0) {
$.each(parsedData['files'], function(i, item) {
if(parseInt(item.Isactive)){
console.log(item);
appendExistingFilesFileds(item)
}
});
}
},
error: function(xhr, status, error) { // Error callback
console.error('AJAX Error:', status, error);
alert("An error occurred: " + error);
// Additional error handling (e.g., showing a custom message)
},
complete: function() { // Complete callback
$('#loader').hide();
console.log('AJAX request completed.');
// Any cleanup or final actions after success/error
}
});
});
});
</script>
<script>
$(document).ready(function(){
$('#Igrshow').on("hide.bs.modal", function(e){
$('#existingContainer').empty();
});
});
</script>
<script>
$('#update').click(function() {
// $('#content').loader('show');
var igrno = $("#IGRNO1").val();
var materialrcv_date = $("#MaterialRcvdDate").val();
var inv_date = $("#InvoiceDate").val();
$.ajax({
data: {
igr: igrno,
mrc: materialrcv_date,
invdate: inv_date
},
type: "POST",
url: "<?php echo base_url() ?>UpdateIGR",
success: function(data) {
alert(data);
}
});
});
$('#draftIGR').click(function() {
let remarks = $('#MasterRemarks').val().trim();
let rcvdDate = $('#MaterialRcvdDate').val().trim();
let invoiceDate = $('#InvoiceDate').val().trim();
let invoiceNo = $('#Invoice_No').val().trim();
// any are empty
if (!remarks || !rcvdDate || !invoiceDate || !invoiceNo) {
alert("Please fill all the required fields");
return; // Stop
}
console.log("All fields filled. Proceeding...");
// $('#content').loader('show');
var igrno = $("#IGRNO1").val();
var pono = $("#PONO1").val();
var status = 0;
var tableData = [];
$('#tbleIGRAppend tr').each(function(index) {
var row = $(this);
++index;
var rowData = {
Quantity: row.find('#txtOrderedQuantity' + index).val(),
QuantityAsPerInvoice: row.find('#txtQuantityAsPerInvoice' + index).val(),
Remarks: row.find('#txtRemarks' + index).val(),
GrossWeight: row.find('#txtGrossWeight' + index).val(),
GrossWeightDate: row.find('#txtGrossWeightDate' + index).val(),
TareWeight: row.find('#txtTareWeight' + index).val(),
TareWeightDate: row.find('#txtTareWeightDate' + index).val(),
NetWeight: row.find('#txtNetWeight' + index).val(),
IGRItemNo: row.find('#txtIGRLineItem' + index).val(),
WeightFile: row.find('#txtWeightFile' + index).val()
};
tableData.push(rowData);
});
var formData = new FormData();
// file_name[]
// emp_file[]
formData.append('igr', igrno);
formData.append('po', pono);
formData.append('mrc', $("#MaterialRcvdDate").val());
formData.append('invno', $("#Invoice_No").val());
formData.append('invdate', $("#InvoiceDate").val());
formData.append('vehicle_no', $('#Vehicle_No').val());
formData.append('Transporter_Id', $('#Transporter_Id').val());
formData.append('driver', $('#Driver_Name').val());
formData.append('driver_mobile', $('#DriverMobileNumber').val());
formData.append('status', status);
formData.append('tableData', JSON.stringify(tableData));
formData.append('isOpenOrder', $("#hiddenIsOpenOrder").val());
formData.append('MasterFile', $('#MasterFile')[0].files[0]);
formData.append('file_name[]', $('#file_name').val());
var empFiles = $('#emp_file')[0] ? $('#emp_file')[0].files : null;
if (empFiles) {
for (var i = 0; i < empFiles.length; i++) {
formData.append('emp_file[]', empFiles[i]);
console.log(empFiles[i]);
}
} else {
console.log("ajax call");
}
$.ajax({
data: formData,
type: "POST",
url: "<?php echo base_url() ?>UpdateIGR",
processData: false,
contentType: false,
success: function(data) {
alert(data);
location.reload();
}
});
});
$('#generateIGR').click(function() {
let remarks = $('#MasterRemarks').val().trim();
let rcvdDate = $('#MaterialRcvdDate').val().trim();
let invoiceDate = $('#InvoiceDate').val().trim();
let invoiceNo = $('#Invoice_No').val().trim();
// any are empty
if (!remarks || !rcvdDate || !invoiceDate || !invoiceNo) {
alert("Please fill all the required fields");
return; // Stop
}
console.log("All fields filled. Proceeding...");
var igrno = $("#IGRNO1").val();
var pono = $("#PONO1").val();
var status = 1;
var tableData = [];
$('#tbleIGRAppend tr').each(function(index) {
var row = $(this);
++index;
var rowData = {
Quantity: row.find('#txtOrderedQuantity' + index).val(),
QuantityAsPerInvoice: row.find('#txtQuantityAsPerInvoice' + index).val(),
Remarks: row.find('#txtRemarks' + index).val(),
GrossWeight: row.find('#txtGrossWeight' + index).val(),
GrossWeightDate: row.find('#txtGrossWeightDate' + index).val(),
TareWeight: row.find('#txtTareWeight' + index).val(),
TareWeightDate: row.find('#txtTareWeightDate' + index).val(),
NetWeight: row.find('#txtNetWeight' + index).val(),
IGRItemNo: row.find('#txtIGRLineItem' + index).val(),
WeightFile: row.find('#txtWeightFile' + index).val()
};
tableData.push(rowData);
});
var formData = new FormData();
formData.append('igr', igrno);
formData.append('po', pono);
formData.append('mrc', $("#MaterialRcvdDate").val());
formData.append('invno', $("#Invoice_No").val());
formData.append('invdate', $("#InvoiceDate").val());
formData.append('vehicle_no', $('#Vehicle_No').val());
formData.append('Transporter_Id', $('#Transporter_Id').val());
formData.append('driver', $('#Driver_Name').val());
formData.append('driver_mobile', $('#DriverMobileNumber').val());
formData.append('status', status);
formData.append('tableData', JSON.stringify(tableData));
formData.append('isOpenOrder', $("#hiddenIsOpenOrder").val());
formData.append('MasterFile', $('#MasterFile')[0].files[0]);
formData.append('MasterRemarks', $("#MasterRemarks").val());
$('input[name="file_name[]"]').each(function() {
formData.append('file_name[]', $(this).val());
});
$('input[name="emp_file[]"]').each(function() {
var empFiles = this.files;
for (var i = 0; i < empFiles.length; i++) {
formData.append('emp_file[]', empFiles[i]);
console.log(empFiles[i]);
}
});
//return false;
$('#loader').show();
$.ajax({
data: formData,
type: "POST",
url: "<?php echo base_url() ?>UpdateIGR",
processData: false,
contentType: false,
success: function(data) {
alert(data);
// setTimeout(function () {
// $("#Igrshow").modal('hide');
// }, 2000);
location.reload();
},
error: function(xhr, status, error) { // Error callback
console.error('AJAX Error:', status, error);
alert("An error occurred: " + error);
// Additional error handling (e.g., showing a custom message)
},
complete: function() { // Complete callback
$('#loader').hide();
console.log('AJAX request completed.');
// Any cleanup or final actions after success/error
}
});
});
</script>
<script>
$(document).ready(function() {
$("#Historyshow").on("shown.bs.modal", function(e) {
var igr = $(e.relatedTarget).data('igrno');
$('#HisTitle').text(" (" + igr + ") ");
$("#HisStatement").empty();
if (igr !== "") {
$.ajax({
data: {
igr: igr
},
type: "POST",
url: "<?php echo base_url() ?>ViewIGRHistory",
success: function(data) {
var output = '';
if (data && data.length > 0) {
data.forEach(function(record) {
var sentence = constructSentence(record);
console.log(sentence);
output += '<p>' + sentence + '</p>';
});
} else {
output = '<p style="text-align: center;">No History Data Available</p>';
}
$("#HisStatement").html(output);
},
error: function(xhr, status, error) {
var output = '<p style="text-align: center;">No History Data Available</p>';
$("#HisStatement").html(output);
console.error('AJAX Error: ' + status + error);
}
});
} else {
var output = '<p style="text-align: center;">No History Data Available</p>';
$("#HisStatement").html(output);
}
});
$("#CostCentershow").on("shown.bs.modal", function(e) {
var pono = $(e.relatedTarget).data('pono');
$('#CCTitle').text(" (" + pono + ") ");
$("#CCStatement").empty();
if (pono !== "") {
$.ajax({
data: {
pono: pono
},
type: "POST",
url: "<?php echo base_url() ?>getCostCenterData",
success: function(data) {
var output = '';
if (data && data.length > 0) {
data.forEach(function(record) {
output += '<p style="font-size:16px;"> <strong>' + record.ReqNo + '</strong> : ' + record.CostCenterName + '-' + record.CostCenterCode + ' </p>';
});
} else {
output = '<p style="text-align: center;">No Cost Center Data Available</p>';
}
$("#CCStatement").html(output);
},
error: function(xhr, status, error) {
var output = '<p style="text-align: center;">No Data Available</p>';
$("#CCStatement").html(output);
console.error('AJAX Error: ' + status + error);
}
});
} else {
var output = '<p style="text-align: center;">No Data Available</p>';
$("#CCStatement").html(output);
}
});
});
function constructSentence(record) {
// let str = record.field;
// let fieldName = str.replace(/([a-z])([A-Z])/g, '$1 $2');
let sentence = " ";
if (parseInt(record.is_add) === 1) {
sentence += record.IGR_No + " was Created by "+record.FullName+ " on "+record.indian_date+" at "+record.indian_time+" </br></br>";
if (record.field === "IGRStatus") {
str1 = record.new_data;
str2 = str1.replace(/\bIGR\b/i, '').trim();
str2 = str2 == "CREATED" ? "GENERATED" : str2;
sentence += record.IGR_No + " was <b> ` " + str2 + " ` </b> by " + record.FullName +
" on " + record.indian_date + " at " + record.indian_time;
} else {
sentence += record.IGR_No + " was <b> ` GENERATED ` </b> by " + record.FullName +
" on " + record.indian_date + " at " + record.indian_time;
}
} else if (parseInt(record.is_edit) === 1) {
let str = record.field;
if (str !== "UpdateBY" && str !== "MaterialRcvdDate" && str !== "DeliveryChellanDate") {
let fieldName = str.replace(/([a-z])([A-Z])/g, '$1 $2');
let displayOldData = record.old_data === null || record.old_data === "" ? " " : record.old_data;
let displayNewData = record.new_data === null || record.new_data === "" ? " " : record.new_data;
if (record.field === "IGRStatus") {
displayOldData = displayOldData.replace(/\bIGR\b/i, '').trim();
displayOldData = displayOldData == "CREATED" ? "GENERATED" : displayOldData;
displayNewData = displayNewData.replace(/\bIGR\b/i, '').trim();
displayNewData = displayNewData == "CREATED" ? "GENERATED" : displayNewData;
}
if(displayNewData || displayOldData ){
sentence += ((record.IGRItem_No) ? record.MaterialName+" ( "+ record.MaterialCode + " ) - " : "")+fieldName+" <b> ` "+ displayOldData + " ` </b> was Updated into <b> ` " + displayNewData + " ` </b> by "+record.FullName+ " on "+record.indian_date+" at "+record.indian_time;
}
}
} else if (parseInt(record.is_delete) === 1) {
let str = record.field;
let fieldName = str.replace(/([a-z])([A-Z])/g, '$1 $2');
sentence += fieldName+" "+record.new_data + " was deleted by "+record.FullName+ " on "+record.indian_date+" at "+record.indian_time;
}
return sentence;
}
</script>
<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('');
}
}
</script>
<script>
function validateTareWeight(element) {
var grossWeight = parseFloat(document.getElementById('GrossWeight').value);
var tareWeight = parseFloat(document.getElementById('TareWeight').value);
if (tareWeight > grossWeight) {
alert("Tare Weight must be less than or equal to Gross Weight.");
document.getElementById('TareWeight').value = '';
document.getElementById('TareWeightDate').value = '';
return false;
}
WeightDiffer(element)
return true;
}
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
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());
}
}
$(document).ready(function() {
$("#WeightCalculator").on("shown.bs.modal", function(e) {
var inx = $(e.relatedTarget).data('index');
var material = $(e.relatedTarget).data('material');
// console.log(material);// toolbox
var modal = $(this);
$('#WeightTitle').text(" ( " + material + " )");
// Clear the modal inputs
$("#GrossWeight").val('');
$("#GrossWeightDate").val('');
$("#TareWeight").val('');
$("#TareWeightDate").val('');
$("#NetWeight").val('');
$("#WeightFile").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();
var fileInput = $("#txtWeightFile" + inx)[0];
var fileName = $("#txtWeightFileName" + inx).val();
modal.find('#WeightFileLabel').hide();
console.log(typeof fileName);
if (fileName !== 'null' && fileName !== undefined && fileName.trim() !== "") {
modal.find('#WeightFileLabel a').attr('title', 'Previous Upload IGR Weight File');
modal.find('#WeightFileLabel a').attr('href', '<?php echo base_url() ?>' + 'public/uploads/Igrfiles/' + fileName);
modal.find('#WeightFileLabel a').attr('target', '_blank');
modal.find('#WeightFileLabel a span').text('Previous Upload - ');
modal.find('#WeightFileLabel a small').text(fileName);
modal.find('#WeightFileLabel').show();
}
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 (fileInput && fileInput.files.length > 0) {
var targetInput = $("#WeightFile")[0];
var file = fileInput.files[0];
// Create a new DataTransfer object
var dataTransfer = new DataTransfer();
dataTransfer.items.add(file);
// Set the file to the target input
targetInput.files = dataTransfer.files;
} else {
console.log("No file selected or file input not found.");
}
});
});
function modalSave() {
var v1 = $("#GrossWeight").val();
var v2 = $("#GrossWeightDate").val();
var v3 = $("#TareWeight").val();
var v4 = $("#TareWeightDate").val();
var v5 = $("#NetWeight").val();
var inx = $("#CurrentInx").val();
var IGRNO1 = $("#IGRNO1").val();
var fileInput = $("#WeightFile")[0];
if (inx !== undefined && inx !== '') {
var txtIGRLineItem = $("#txtIGRLineItem" + inx).val();
var formData = new FormData();
formData.append('GrossWeight', v1);
formData.append('GrossWeightDate', v2);
formData.append('TareWeight', v3);
formData.append('TareWeightDate', v4);
formData.append('NetWeight', v5);
formData.append('IGR', IGRNO1);
formData.append('IGRlineitem', txtIGRLineItem);
if (fileInput && fileInput.files.length > 0) {
var file = fileInput.files[0];
formData.append('WeightFile', file);
console.log("File selected:", file.name);
} else {
console.log("No file selected.");
}
$.ajax({
url: "<?php echo base_url('updateIGRWeight'); ?>",
type: "POST",
data: formData,
contentType: false,
processData: false,
success: function(data) {
alert(data);
$("#WeightCalculator").modal('hide');
},
error: function(xhr, status, error) {
console.log("Upload error:", error);
}
});
}
}
</script>
<script>
function formatDateTime(dateString, flag) {
// Note 1 means DATE only
// 2 means DATE and Time
// Check if the date string is null or empty
if (!dateString || dateString == 'null' || dateString === '0000-00-00 00:00:00') {
return '';
} else {
console.log("Received date string:", dateString);
// Split the date string into date and time components
var dateTimeParts = dateString.split(' ');
var dateParts = dateTimeParts[0].split('-');
var timeParts = dateTimeParts[1].split(':');
// Extract individual components
var year = parseInt(dateParts[0], 10);
var month = parseInt(dateParts[1], 10) - 1; // Months are zero-based in JavaScript
var day = parseInt(dateParts[2], 10);
var hours = parseInt(timeParts[0], 10);
var minutes = parseInt(timeParts[1], 10);
var seconds = parseInt(timeParts[2], 10);
// Create a new Date object
var date = new Date(year, month, day, hours, minutes, seconds);
// 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');
var formattedDate = '';
// Format the date and time in DD-MM-YYYY HH:MM:SS format
if (flag == 1) {
formattedDate = `${day}-${month}-${year}`;
} else if (flag == 2) {
formattedDate = `${day}-${month}-${year} ${hours}:${minutes}:${seconds}`;
}
return formattedDate;
}
}
</script>
<script>
function SetRemarks(RowId) {
var remks = $("#Remark" + RowId).val();
if (remks != '') {
$("#txtRemarks" + RowId).val(remks);
}
}
function validateReceivedQuantity(Rowid, isOpenOrder) {
console.log("validation");
var InvoiceQty = parseFloat($('#QuantityAsPerInvoice' + Rowid).val() || '0.00'); // working fine
var OrderedQty = parseFloat($("#Quantity" + Rowid).text());
var Rate = parseFloat($('#Rate' + Rowid).text() || '0.00');
console.log('#Rate' + Rowid+" Rate:", Rate);
var amount = Rate * InvoiceQty;
console.log('#amount' + Rowid+" amount:", amount);
var tax_percentage = parseFloat($('#tax_percentage' + Rowid).text() || '0.00');
var tax_amount = (amount * tax_percentage) / 100;
console.log('#tax_amount' + Rowid+" tax_amount:", tax_amount);
var grand_total_amount = amount + tax_amount; // tax_amount
console.log('#grand_total_amount' + Rowid+" grand_total_amount:", grand_total_amount);
if (isOpenOrder == 1) {
var PendingQty = 0;
$('#PendingQuantity' + Rowid).text(PendingQty.toFixed(0));
$('#txtPendingQty' + Rowid).val(PendingQty.toFixed(0));
$('#txtQuantityAsPerInvoice' + Rowid).val(InvoiceQty.toFixed(2));
$('#amount' + Rowid).text(amount.toFixed(2));
$('#tax_amount' + Rowid).text(tax_amount.toFixed(2));
$('#grand_total_amount' + Rowid).text(grand_total_amount.toFixed(2));
return true;
} else {
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('');
$('#amount' + Rowid).text(amount.toFixed(2));
$('#tax_amount' + Rowid).text(tax_amount.toFixed(2));
$('#grand_total_amount' + Rowid).text(grand_total_amount.toFixed(2));
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));
$('#amount' + Rowid).text(amount.toFixed(2));
$('#tax_amount' + Rowid).text(tax_amount.toFixed(2));
$('#grand_total_amount' + Rowid).text(grand_total_amount.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));
$('#amount' + Rowid).text(amount.toFixed(2));
$('#tax_amount' + Rowid).text(tax_amount.toFixed(2));
$('#grand_total_amount' + Rowid).text(grand_total_amount.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>
var counter = 0;
$("#addmorebutton").click(function() {
$('#newdiv').empty();
var file_count = $("#hidegrandcounter").val();
counter++;
var bil_count = +counter + +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";
div.innerHTML = '<div class="col-md-12">' +
'<div class="col-md-3">' +
'<label class="col-form-label"><br></label>' +
'<input type="file" name="browseFiles" id="images' + counter + '" ><br>' +
'</div>' +
'<div class="col-md-2">' +
'<label class="col-form-label"><br><br></label>' +
'<button class="btn btn-success" type ="button" id="addbtn" onclick="addRow(' + counter + ')">ADD</button></div>' +
'</div>' +
'</div>';
$('#newdiv').append(div);
$('#hidecounter').val(counter);
if (counter > 1) {
alert("Add button click here");
return false;
} else {
$('#addmorebutton').hide();
}
});
function addRow(counter) {
var file = $('#images' + counter).val();
if (file == '') {
alert('File not found');
} else {
fileupload(counter);
}
}
function fileupload(counter) {
var formData = new FormData();
var file = document.getElementById('images' + counter).files[0];
var PONO = $('#hiddenPONO').val();
var igr = $('#hiddenIGRNO').val();
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) {
const chars = data.split("-");
billNo = chars[1] != undefined ? chars[1] : "";
alert('File uploaded successfully.');
addToTable(counter, billNo, file.name);
// $('.content').loader('hide');
$('#billModel').modal('hide');
}
}
});
}
function addToTable(counter, billNo, fileName) {
var hidecounter = $("#hidecounter").val();
var file_count = $("#hidegrandcounter").val();
var newRow = '<tr id="row' + counter + '">' +
'<td>' + counter + '</td>' +
'<td>' + billNo + '</td>' +
'<td>' + $('#hiddenPONO').val() + '</td>' +
'<td>' + fileName + '</td>' +
'<td>' + '<a href="#" onclick="openbillmodel(' + counter + ')">' +
'<i class="fa fa-edit" style="margin-right: 10px;"></i>' +
'</a>' +
'<a href="#" onclick="deleteBill(' + billNo + ',' + counter + ')">' +
'<i class="fa fa-trash"></i>' +
'</a>' +
'</td>' +
'</tr>';
$('#tblefile').append(newRow);
}
function filenames(id) {
var size = $('input[name=' + id + ']')[0].files[0].size;
if (size > 2100000) {
alert('Sorry Your File is Large To 2MB');
} else {
var name = $('input[name=' + id + ']')[0].files[0].name;
}
}
</script>
<script src="https://cdn.datatables.net/plug-ins/1.10.11/sorting/date-eu.js"></script>
<script src="https://cdn.datatables.net/buttons/2.3.4/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.3.4/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.3.4/js/buttons.print.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.13.6/sorting/datetime-moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
<script>
// $(document).ready(function() {
// $.fn.dataTable.ext.type.order['date-eu-pre'] = function(date) {
// var dateSplit = date.split('-');
// return (dateSplit[2] + dateSplit[1] + dateSplit[0]) * 1;
// };
// });
function appendExistingFilesFileds(data) {
const base_url = '<?php echo base_url(); ?>';
var filePath = data != null && data != '' ? data.FilePath : '';
var fileName = data != null && data != '' ? data.Remarks : '';
var billNo = data != null && data != '' ? data.BillNo : '';
var downloadUrl = `${base_url}public/uploads/Igrfiles/${filePath}`;
var newRowHtml = `<div class="form-row pad mt-2 ">
<div class="col-md-4">
<span><b>File Name</b></span>
<input type="text" maxlength="255" class="form-control"
value="${fileName}" readonly>
</div>
<div class="col-md-1" style="margin-top: 25px;">
<a href="${downloadUrl}" download>
<i class="fa fa-download" aria-hidden="true"
style="font-size: 25px;"></i>
</a>
</div>
<div class="col-md-5" style="margin-top: 23px;">
<button type="button" class="btn btn-danger btn-sm"
value="${billNo}" onclick="removeContact(this)">Delete</button>
</div>
</div>`;
$('#existingContainer').append(newRowHtml);
}
function appendFilesFileds(data) {
var newRowHtml = `
<div class="form-row pad mt-2">
<div class=" col-md-4">
<label class="col-form-label">File name</label>
<input type="text" id="file_name" name="file_name[]" maxlength="255" class="form-control" value="${data != null && data != '' ? data.file_name : ''}">
</div>
<div class=" col-md-4">
<label class="col-form-label" for="emp_file">File</label>
<input type="file" id="emp_file" name="emp_file[]" multiple class="form-control">
</div>
<div class=" col-md-4" style="margin-top: 40px;">
<button type="button" class="btn btn-danger btn-sm" onclick="removeContact(this)">Remove</button>
<button type="button" class="btn btn-primary btn-sm a1" onclick="appendFilesFileds()">Add</button>
</div>
</div>`;
$('#filesContainer').append(newRowHtml);
$('.a1').hide();
$('#filesContainer .pad:last .a1').show();
}
function removeContact(button) {
if ( button.value != '') {
let deleteConfirmation=confirm("Do you wish to Delete the Selected File?");
if(deleteConfirmation){
$('#loader').show();
$.ajax({
data: {
id: button.value
},
type: "POST",
url: "<?php echo base_url(); ?>deleteAdditionalIGRFile",
success: function(data) {
if (data.status === 'success' && data.data === true)
{
$(button).closest('.pad').remove();
$('#filesContainer .a1').hide();
$('#filesContainer .pad:last .a1').show();
var filesContainer = $('#filesContainer .pad:last .a1');
filesContainer.length === 0 ? $('#additionalfilebtn').show() : $('#additionalfilebtn').hide();
return true;
} else {
console.log('Failed to delete: Check server response.');
}
},
error: function(xhr, status, error) {
console.error('AJAX Error:', status, error);
alert("An error occurred: " + error);
},
complete: function() {
$('#loader').hide();
console.log('AJAX request completed.');
}
});
}
}else{
$(button).closest('.pad').remove();
$('#filesContainer .a1').hide();
$('#filesContainer .pad:last .a1').show();
var len = $('#filesContainer .pad:last .a1')
var length = len.length;
if (length == 0) {
$('#additionalfilebtn').show()
} else {
$('#additionalfilebtn').hide()
}
}
}
$(document).ready(function() {
// this code for table date filed ordering
$.fn.dataTable.ext.type.order['date-dd-mm-yyyy-pre'] = function(date) {
if (!date) return 0;
var parts = date.split('-'); // Split the date into parts (DD, MM, YYYY)
return new Date(parts[2], parts[1] - 1, parts[0]).getTime(); // Convert to timestamp
};
var orderColumnIndex = <?php echo (session()->get('roleText') == 'Auditor') ? 6 : 0; ?>;
table = $('#view_inward_gate_register').DataTable({
dom: 'Blfrtip',
buttons: [
{
extend: 'excel',
text: 'Excel',
exportOptions: {
columns: ':not(:last-child)' // Exclude the last column
}
}
],
pageLength: 10,
lengthMenu: [
[10, 20, 30, 50, -1],
[10, 20, 30, 50, "All"]
],
responsive: false,
ordering: true,
columnDefs: [
{ targets: parseInt(orderColumnIndex), type: 'date-dd-mm-yyyy' } // Apply custom sorting
],
order: [[parseInt(orderColumnIndex), 'desc']],
language: {
paginate: {
next: '<i class="fas fa-angle-right"></i>', // Next button icon
previous: '<i class="fas fa-angle-left"></i>' // Previous button icon
}
}
});
$('#view_inward_gate_register').on('click', '.edit-btn', function () {
const pageInfo = table.page.info(); // Now this works
console.log("page number",pageInfo);
sessionStorage.setItem("datatablePage", pageInfo.page);
});
// Restore page
let startPage = sessionStorage.getItem("datatablePage");
console.log('startpage',startPage);
if (startPage !== null) {
table.page(parseInt(startPage)).draw('page');
sessionStorage.removeItem("datatablePage");
}
// Reset button functionality
$("#resetButton").click(function() {
$("#fromDate").val('');
$("#toDate").val('');
window.location="ViewIGR"
});
// 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;
}
});
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script>
// document.getElementById('downloadExcel').addEventListener('click', function() {
// var table = document.getElementById('InwardgateregistertableForDownload');
// var wb = XLSX.utils.table_to_book(table, { sheet: "Inward Gate Register" });
// XLSX.writeFile(wb, 'InwardGateRegister.xlsx');
// });
</script>
<script>
$(document).ready(function() {
$('#fromDate , #toDate').change(function() {
let fromDate = $('#fromDate').val();
let toDate = $('#toDate').val();
let fromDateObj = new Date(fromDate.split('-').reverse().join('-'));
let toDateObj = new Date(toDate.split('-').reverse().join('-'));
if (fromDateObj > toDateObj) {
alert('Incorrect Date Applied For Filter..!!');
$('#toDate').attr('min', fromDate);
$('#toDate').val('');
}
});
});
function fetchMobileNumber(selectedValue) {
let parts = selectedValue.split(" - ");
console.log(parts);
console.log(parts[0]);
if (parts.length === 2) {
document.getElementById("Driver_Name").value = parts[0];
document.getElementById("DriverMobileNumber").value = parts[1];
}else{
document.getElementById("Driver_Name").value = parts[0];
}
}
</script>
<!-- 28/02/2025 -->
<!-- add gas shortage calculator -->
<script>
$('#grossWeightId, #tareWeightId,#actualWeightId').change(function() {
console.log("fine here ");
let grossWeightVal = $('#grossWeightId').val().trim();
let tareWeightVal = $('#tareWeightId').val().trim();
// Ensure both fields have values before calculation
if (grossWeightVal === '' || tareWeightVal === '') {
return;
}
let grossWeight = validateNumber(grossWeightVal);
let tareWeight = validateNumber(tareWeightVal);
let netWeight = grossWeight - tareWeight;
$('#netWeightId').val(netWeight);
let actualWeightVal = $('#actualWeightId').val().trim();
// Ensure both fields have values before calculation
if (actualWeightVal === '' || netWeight === '') {
return;
}
let actualWeight = validateNumber(actualWeightVal);
let shortage = actualWeight - netWeight;
$('#shortageId').val(shortage);
});
function validateNumber(givenValue) {
givenValue = givenValue.trim();
if (/^\d+$/.test(givenValue)) {
return parseInt(givenValue, 10); // Convert string to number
} else {
alert('Please Enter a Valid Number..!!');
return 0; // Invalid number
}
}
</script>
<!-- while opening add gas shortage modal -->
<script>
$(document).ready(function(){
$('#gasShortageCalculator').on("shown.bs.modal", function(e){
//invoice needed to store it in the shortage table ,
// coz based on this we can limit the addition of shortage must not exceed than given qty
let invoiceNo = $('#Invoice_No').val();
let materialReceivedDate = $('#MaterialRcvdDate').val().split("-");
//converting it to y-m-d format;
console.log(`${materialReceivedDate[2]}-${materialReceivedDate[1]}-${materialReceivedDate[0]}`);
$('#invoiceNoId').val(invoiceNo);
$('#fullCylinderDateId').val(`${materialReceivedDate[2]}-${materialReceivedDate[1]}-${materialReceivedDate[0]}`);
});
});
</script>
<!-- while closing add gas shortage modal -->
<script>
$(document).ready(function(){
$('#gasShortageCalculator').on("hide.bs.modal", function(e){
$('#invoiceNoId').val(' ');
$('#fullCylinderDateId').val(" ");
$('#emptyCylinderDateId').val(" ");
$('#cylinderNoId').val(" ");
$('#grossWeightId').val(" ");
$('#tareWeightId').val(" ");
$('#actualWeightId').val(" ");
$('#netWeightId').val(" ");
$('#shortageId').val(" ");
});
});
</script>
<!-- end of add gas shortage calculator -->
<!-- edit gasShortageCalculator -->
<script>
$('#editGrossWeightId,#editTareWeightId,#editActualWeightId').change(function() {
let grossWeightVal = $('#editGrossWeightId').val().trim();
let tareWeightVal = $('#editTareWeightId').val().trim();
// Ensure both fields have values before calculation
if (grossWeightVal === '' || tareWeightVal === '') {
return;
}
let grossWeight = validateNumber(grossWeightVal);
let tareWeight = validateNumber(tareWeightVal);
let netWeight = grossWeight - tareWeight;
$('#editNetWeightId').val(netWeight);
let actualWeightVal = $('#editActualWeightId').val().trim();
// Ensure both fields have values before calculation
if (actualWeightVal === '' || netWeight === '') {
return;
}
let actualWeight = validateNumber(actualWeightVal);
let shortage = actualWeight - netWeight;
$('#editShortageId').val(shortage);
});
</script>
<!-- while opening edit gas shortage modal -->
<script>
$(document).ready(function(){
$('#editGasShortageCalculator').on("shown.bs.modal", function(e){
//invoice needed to store it in the shortage table ,
// coz based on this we can limit the addition of shortage must not exceed than given qty
let invoiceNo = $('#Invoice_No').val();
let materialReceivedDate = $('#MaterialRcvdDate').val().split("-");
//converting it to y-m-d format;
console.log(`${materialReceivedDate[2]}-${materialReceivedDate[1]}-${materialReceivedDate[0]}`);
$('#editInvoiceNoId').val(invoiceNo);
$('#editFullCylinderDateId').val(`${materialReceivedDate[2]}-${materialReceivedDate[1]}-${materialReceivedDate[0]}`);
});
});
</script>
<!-- while closing edit gas shortage modal -->
<script>
$(document).ready(function(){
$('#editGasShortageCalculator').on("hide.bs.modal", function(e){
$('#editInvoiceNoId').val(' ');
$('#editFullCylinderDateId').val(" ");
$('#editEmptyCylinderDateId').val(" ");
$('#editCylinderNoId').val(" ");
$('#editGrossWeightId').val(" ");
$('#editTareWeightId').val(" ");
$('#editActualWeightId').val(" ");
$('#editNetWeightId').val(" ");
$('#editShortageId').val(" ");
});
});
</script>
<!-- end of edit gasShortageCalculator -->
<!-- while opening gasShortageList -->
<script>
$(document).ready(function(){
$('#gasShortageList').on("shown.bs.modal",function(e){
let invoiceNo = $('#Invoice_No').val();
console.log("invoice no", invoiceNo);
$('#loader').show();
$.ajax({
type: "POST",
url: "<?php echo base_url()?>/gasShortageList", // 🔹 Change this to your actual backend endpoint
data: {invoiceNo},
dataType: "json",
success: function (response) {
if (response.status === "success") {
let data = response.data ;
let tableData = '';
data.forEach((val) => {
let fullCylinderDate = val.fullCylinderDate.split("-").reverse().join("-");
let emptyCylinderDate = val.emptyCylinderDate.split("-").reverse().join('-');
tableData += `
<tr>
<td>${fullCylinderDate}</td>
<td>${emptyCylinderDate}</td>
<td>${val.invoiceNo}</td>
<td>${val.cylinderNo}</td>
<td>${val.grossWeight}</td>
<td>${val.tareWeight}</td>
<td>${val.netWeight}</td>
<td>${val.actualWeight}</td>
<td>${val.shortage}</td>
<td style="display:none">${val.id}</td>
<td style="width: 25px; cursor: pointer;">
<i class="fa fa-solid fa-edit btnEditGasShortageCalculator"
style="text-align: center;"
data-toggle="modal"
data-target="#editGasShortageCalculator"
data-id="${val.id}"
title="Edit Gas Shortage List">
</i>
</td>
</tr>`;
});
// Assuming you have a table with ID "gasShortageTable"
$("#gasShortageTable tbody").html(tableData);
} else {
alert("Error: " + response.message);
}
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
alert("Something went wrong! Please try again.");
},
complete:function(){
console.log("ajax call is completed..!!");
$('#loader').hide();
}
});
})
})
</script>
<!-- while closing gasShortageList -->
<script>
$(document).ready(function(){
$('#gasShortageList').on("hide.bs.modal",function(){
$("#gasShortageTable tbody").html(" ");
})
})
</script>
<!-- ajax call for gas Shortage -->
<script>
$("#gasShortageCalculator, #editGasShortageCalculator").submit(function (event) {
event.preventDefault(); // Prevent form reload
let formData;
let method = $(this).closest(".modal").data("form");
// Prepare form data
let addFormData = {
fullCylinderDate: $('#fullCylinderDateId').val(),
emptyCylinderDate: $('#emptyCylinderDateId').val(),
invoiceNo: $('#invoiceNoId').val(),
cylinderNo: $('#cylinderNoId').val(),
grossWeight: $('#grossWeightId').val(),
tareWeight: $('#tareWeightId').val(),
actualWeight: $('#actualWeightId').val(),
netWeight: $('#netWeightId').val(),
shortage: $('#shortageId').val()
};
let editFormData = {
fullCylinderDate: $('#editFullCylinderDateId').val(),
emptyCylinderDate: $('#editEmptyCylinderDateId').val(),
invoiceNo: $('#editInvoiceNoId').val(),
cylinderNo: $('#editCylinderNoId').val(),
grossWeight: $('#editGrossWeightId').val(),
tareWeight: $('#editTareWeightId').val(),
actualWeight: $('#editActualWeightId').val(),
netWeight: $('#editNetWeightId').val(),
shortage: $('#editShortageId').val(),
id : $('#editId').val()
};
if(method == "add"){ formData = addFormData ;}
if(method == "edit"){ formData = editFormData ;}
$('#loader').show();
$.ajax({
type: "POST",
url: "<?php echo base_url()?>/updateGasShortage", // 🔹 Change this to your actual backend endpoint
data: formData,
dataType: "json",
success: function (response) {
if (response.status === "success") {
alert("Gas Shortage Data Saved Successfully!");
$('#gasShortageCalculator').modal('hide'); // Close modal
$('#editGasShortageCalculator').modal('hide');
} else {
alert("Error: " + response.message);
}
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
alert("Something went wrong! Please try again.");
},
complete:function(){
console.log("ajax call is completed..!!");
$('#loader').hide();
}
});
});
</script>
<script>
$(document).on("click", ".btnEditGasShortageCalculator", function () {
console.log("Edit modal opening place");
let id = $(this).data("id");
console.log("Editing ID:", id);
// Smooth transition: First hide, then show after 300ms
$("#gasShortageList").modal("hide");
setTimeout(() => {
$("#editGasShortageCalculator").modal("show");
}, 300);
$('#loader').show();
// AJAX request to fetch data
$.ajax({
type: "POST",
url: "<?php echo base_url()?>/getGasShortageDetail",
data: { id: id },
dataType: "json",
success: function (response) {
if (response.status === "success") {
let data = response.data;
console.log(data);
if(data.length > 0){
data = data[0];
console.log(data);
// Populate the modal fields
$("#editFullCylinderDateId").val(data.fullCylinderDate);
$("#editEmptyCylinderDateId").val(data.emptyCylinderDate);
$("#editInvoiceNoId").val(data.invoiceNo);
$("#editCylinderNoId").val(data.cylinderNo);
$("#editGrossWeightId").val(data.grossWeight);
$("#editTareWeightId").val(data.tareWeight);
$("#editNetWeightId").val(data.netWeight);
$("#editActualWeightId").val(data.actualWeight);
$("#editShortageId").val(data.shortage);
$("#editId").val(data.id); // Hidden field for ID
}
} else {
alert("Error: " + response.message);
}
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
alert("Something went wrong! Please try again.");
},
complete:function(){
console.log("ajax call is completed..!!");
$('#loader').hide();
}
});
});
</script>
<script>
$(document).ready(function(){
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let cloneTable = table.cloneNode(true); // Clone the table to modify
// Remove hidden rows
$(cloneTable).find('tr').filter(function () {
return $(this).css('display') === 'none';
}).remove();
// Remove hidden columns
$(cloneTable).find('th, td').each(function () {
if ($(this).css('display') === 'none') {
$(this).remove();
}
});
let ws = XLSX.utils.table_to_sheet(cloneTable); // Convert modified table to sheet
let wb = XLSX.utils.book_new(); // Create a new workbook
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1'); // Append sheet to workbook
XLSX.writeFile(wb, filename || 'export.xlsx'); // Save the file
}
let tableId = 'gasShortageTable';
document.getElementById('exportGasShortage').addEventListener('click',function(){
exportTableToExcel(tableId, 'gas_shortage_<?= $date->format('d-m-Y') ?>.xlsx');
})
})
</script>