640 lines
16 KiB
PHP
640 lines
16 KiB
PHP
<!-- 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;
|
|
|
|
});
|
|
</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">Gas Cylinder Completed </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=""
|
|
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=""
|
|
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>
|
|
<!-- basic details -->
|
|
<th>Full Cylinder Date</th>
|
|
<th>IGR No</th>
|
|
<th>Supplier</th>
|
|
<th>Bill/Invoice No</th>
|
|
<th>Cylinder Name</th>
|
|
|
|
<!-- cylinderdetails -->
|
|
|
|
<th>Gross Weight</th>
|
|
<th>Empty Cylinder Date</th>
|
|
<th>Tare Weight</th>
|
|
<th>Net Weight</th>
|
|
<th>Actual Weight</th>
|
|
<th>Shortage</th>
|
|
<th>Cylinder Count</th>
|
|
<th>Cylinder Pending</th>
|
|
|
|
|
|
<!-- least details -->
|
|
<th>Bill Date</th>
|
|
<th>Driver Name</th>
|
|
<th>Vehicle No</th>
|
|
<th>Download</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
|
|
<?php if (empty($gasCylinderReturnedList)) { ?>
|
|
<p align="center"> No Gas Cylinder Returned in the Given Dates..!!</p>
|
|
<?php } else { ?>
|
|
|
|
<?php foreach ($gasCylinderReturnedList as $index => $gasCylinder):
|
|
$gasCylinder['MaterialRcvdDate'] = date('d-m-Y', strtotime($gasCylinder['MaterialRcvdDate']));
|
|
$gasCylinder['DeliveryChellanDate'] = date('d-m-Y', strtotime($gasCylinder['DeliveryChellanDate']));
|
|
$gasCylinder['emptyCylinderDate'] = date('d-m-Y', strtotime($gasCylinder['emptyCylinderDate']));
|
|
?>
|
|
|
|
<tr>
|
|
|
|
<!-- basic details -->
|
|
<td><?= $gasCylinder['MaterialRcvdDate'] ?></td>
|
|
<td><?= $gasCylinder['IGRNO-'] ?></td>
|
|
<td><?= $gasCylinder['SupplierName'] ?></td>
|
|
<td><?= $gasCylinder['DeliveryChellanOrInvoiceNo'] ?></td>
|
|
<td><?= $gasCylinder['MaterialName'] ?></td>
|
|
|
|
<!-- cylinderdetails -->
|
|
<td><?= $gasCylinder['grossWeight'] ?></td>
|
|
<td><?= $gasCylinder['emptyCylinderDate'] ?></td>
|
|
<td><?= $gasCylinder['tareWeight'] ?></td>
|
|
<td><?= $gasCylinder['netWeight'] ?></td>
|
|
<td><?= $gasCylinder['actualWeight'] ?></td>
|
|
<td><?= $gasCylinder['shortage'] ?></td>
|
|
<td><?= $gasCylinder['gasCylinderCount'] ?></td>
|
|
<td><?= $gasCylinder['gasCylinderPendingCount'] ?></td>
|
|
|
|
|
|
|
|
<!-- least details -->
|
|
<td><?= $gasCylinder['DeliveryChellanDate'] ?></td>
|
|
<td><?= $gasCylinder['DriverName'] ?></td>
|
|
<td><?= $gasCylinder['VehicleNo'] ?></td>
|
|
<td style="text-align: center;">
|
|
<i class="fa fa-download"
|
|
onclick="downloadExcel(this)"
|
|
title="Download" aria-hidden="true"
|
|
style="font-size:large;
|
|
cursor:pointer;
|
|
color:rgb(23, 162, 162);">
|
|
</i>
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php endforeach ?>
|
|
|
|
<?php } ?>
|
|
|
|
</tbody>
|
|
</table>
|
|
|
|
<div>
|
|
<div style="display: none;" id="excelTableDiv"></div>
|
|
</div>
|
|
|
|
|
|
</div> <!-- end card body-->
|
|
</div> <!-- end card -->
|
|
</div><!-- end col-->
|
|
</div>
|
|
</div>
|
|
</div> <!-- container -->
|
|
</div> <!-- content -->
|
|
</div>
|
|
<!-- box closed here -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- format date time helper -->
|
|
<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 = 0;
|
|
var minutes = 0;
|
|
var seconds = 0;
|
|
|
|
|
|
if(timeParts){
|
|
// Extract time components
|
|
hours = parseInt(timeParts[0], 10);
|
|
minutes = parseInt(timeParts[1], 10);
|
|
seconds = parseInt(timeParts[2], 10);
|
|
}
|
|
|
|
|
|
// Create a new Date object
|
|
var date = new Date(year, month, day, hours, minutes, seconds);
|
|
|
|
// Extract date components
|
|
day = date.getDate().toString().padStart(2, '0');
|
|
month = (date.getMonth() + 1).toString().padStart(2, '0'); // Months are zero-based
|
|
year = date.getFullYear();
|
|
|
|
// Extract time components
|
|
hours = date.getHours().toString().padStart(2, '0');
|
|
minutes = date.getMinutes().toString().padStart(2, '0');
|
|
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>
|
|
|
|
<!-- number validation -->
|
|
<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>
|
|
|
|
<!-- data table related initialization -->
|
|
<script>
|
|
$(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
|
|
}
|
|
}
|
|
});
|
|
|
|
// Reset button functionality
|
|
$("#resetButton").click(function() {
|
|
$("#fromDate").val('');
|
|
$("#toDate").val('');
|
|
window.location = "gasCylinderReturned"
|
|
});
|
|
|
|
// 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>
|
|
|
|
|
|
<!-- data table related date filter -->
|
|
<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('');
|
|
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
function downloadExcel(clickedElement) {
|
|
|
|
var row = $(clickedElement).closest("tr");
|
|
var igrNo = row.find("td:eq(1)").text().trim();
|
|
var cylinderPendingCount = row.find("td:eq(12)").text().trim();
|
|
|
|
cylinderPendingCount = parseInt(cylinderPendingCount, 10);
|
|
|
|
if (cylinderPendingCount > 0) {
|
|
alert("Please clear the " + cylinderPendingCount + " pending cylinders before downloading the Excel file.");
|
|
return false;
|
|
}
|
|
|
|
|
|
$("#loader").show();
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "<?php echo base_url() ?>gasCylindersByIgr",
|
|
data: {
|
|
IGRNO: igrNo
|
|
},
|
|
success: function(response) {
|
|
$("#loader").hide();
|
|
if (response.status === "success") {
|
|
console.log(response.data); // Debugging - Check if data is correct
|
|
|
|
let tableHTML = `
|
|
<table border="1" id="excelTable" >
|
|
<thead>
|
|
<tr>
|
|
<th>IGRNO</th>
|
|
<th>Full Cylinder Date</th>
|
|
<th>Cylinder No</th>
|
|
<th>Gross Weight</th>
|
|
<th>Empty Cylinder Return Date</th>
|
|
<th>Tare Weight</th>
|
|
<th>Net Weight</th>
|
|
<th>Actual Weight</th>
|
|
<th>Shortage</th>
|
|
<th>Bill No</th>
|
|
<th>Bill Date</th>
|
|
<th>Driver Name</th>
|
|
<th>Vehicle No</th>
|
|
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
`;
|
|
|
|
let totalShortage = 0;
|
|
let totalNetWeight = 0;
|
|
let totalActualWeight = 0;
|
|
|
|
response.data.forEach(item => {
|
|
|
|
totalShortage += Number(item.shortage);
|
|
|
|
totalNetWeight += Number(item.netWeight);
|
|
|
|
totalActualWeight += Number(item.actualWeight);
|
|
|
|
item.fullCylinderDate = formatDateTime(item.fullCylinderDate, 1);
|
|
item.emptyCylinderDate = formatDateTime(item.emptyCylinderDate, 1);
|
|
item.DeliveryChellanDate = formatDateTime(item.DeliveryChellanDate, 1);
|
|
|
|
tableHTML += `
|
|
|
|
<tr>
|
|
<td>${item.IGRNO}</td>
|
|
<td>${item.fullCylinderDate}</td>
|
|
<td>${item.cylinderNo}</td>
|
|
<td align="right">${item.grossWeight}</td>
|
|
<td>${item.emptyCylinderDate}</td>
|
|
<td align="right">${item.tareWeight}</td>
|
|
<td align="right">${item.netWeight}</td>
|
|
<td align="right">${item.actualWeight}</td>
|
|
<td align="right">${item.shortage}</td>
|
|
<td>${item.invoiceNo}</td>
|
|
<td>${item.DeliveryChellanDate}</td>
|
|
<td>${item.DriverName}</td>
|
|
<td>${item.VehicleNo}</td>
|
|
</tr>
|
|
|
|
`;
|
|
});
|
|
|
|
tableHTML += `
|
|
</tbody>
|
|
<tfoot>
|
|
<tr class="empty-row">
|
|
<td colspan="13"> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td align="right"> Weight</td>
|
|
<td align="right">${totalNetWeight}</td>
|
|
<td align="right">${totalActualWeight}</td>
|
|
<td align="right">${totalShortage}</td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
</tfoot>
|
|
</table>
|
|
`;
|
|
|
|
$("#excelTableDiv").html(tableHTML);
|
|
|
|
let table = document.getElementById('excelTable');
|
|
|
|
let filename = "GasCylinderReturned_" + igrNo + ".xlsx";
|
|
|
|
let rows = [];
|
|
|
|
// Extract table data row-by-row
|
|
$(table).find('tr').each(function(rowIndex) {
|
|
let rowData = [];
|
|
|
|
$(this).find('th, td').each(function(colIndex) {
|
|
// Skip hidden columns
|
|
if ($(this).css('display') === 'none') return;
|
|
let cellText = $(this).text().trim();
|
|
rowData.push(cellText);
|
|
});
|
|
|
|
// Add the cleaned row only if it has data
|
|
if (rowData.length > 0) {
|
|
rows.push(rowData);
|
|
}
|
|
});
|
|
|
|
// Create a worksheet from array (no DOM needed!)
|
|
let ws = XLSX.utils.aoa_to_sheet(rows);
|
|
|
|
// Define column widths (in character units)
|
|
const columnWidth = 15; // Set your desired width here
|
|
const wscols = [];
|
|
for (let i = 0; i < Object.keys(response.data[0]).length; i++) {
|
|
wscols.push({
|
|
wch: columnWidth
|
|
});
|
|
}
|
|
ws['!cols'] = wscols;
|
|
|
|
let wb = XLSX.utils.book_new();
|
|
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
|
|
XLSX.writeFile(wb, filename || 'export.xlsx');
|
|
}
|
|
},
|
|
|
|
error: function(xhr, status, error) {
|
|
console.log(xhr.responseText);
|
|
alert("Something went wrong! Please try again.");
|
|
},
|
|
complete: function() {
|
|
console.log("AJAX request completed.");
|
|
$("#loader").hide(); // Hide loader
|
|
}
|
|
});
|
|
}
|
|
</script>
|