ria/app/Views/stock/gasStockDetails.php
2025-04-24 17:43:24 +05:30

1616 lines
71 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<style type="text/css">
.num {
text-align: right;
}
.fht-table,
.fht-table thead,
.fht-table tfoot,
.fht-table tbody,
.fht-table tr,
.fht-table th,
.fht-table td {
margin: 0;
}
.fht-table td {
text-align: center;
}
.fht-table td:hover {
background-color: rgb(170, 222, 167);
color: rgb(2, 2, 2);
transform: scale(1.25);
/* Increases size by 25% */
transition: transform 0.5s ease-in-out;
/* Smooth scaling effect */
}
.fht-table tr:hover {
background-color: rgb(170, 222, 167);
color: rgb(2, 2, 2);
}
.fht-table {
border: 0 none;
height: auto;
width: auto;
border-collapse: collapse;
border-spacing: 0;
/*table-layout: fixed; Algoritmo de distribucion fijo */
white-space: nowrap;
}
.fht-table th,
.fht-table td {
overflow: hidden;
}
.fht-table-wrapper,
.fht-table-wrapper .fht-thead,
.fht-table-wrapper .fht-tfoot,
.fht-table-wrapper .fht-fixed-column .fht-tbody,
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: hidden;
position: relative;
}
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: auto;
}
.fht-table-wrapper .fht-table .fht-cell {
overflow: hidden;
height: 1px;
}
.fht-table-wrapper .fht-fixed-column,
.fht-table-wrapper .fht-fixed-body {
top: 0;
left: 0;
position: absolute;
}
.fht-table-wrapper .fht-fixed-column {
z-index: 1;
}
.fht-fixed-body .fht-thead table {
margin-right: 20px;
border: 0 none;
}
/*For Examples*/
.ContenedorTabla {
height: 500px;
margin: 0 auto;
overflow: auto;
width: auto;
position: relative;
}
.header,
.main {
display: inline-block;
height: auto;
width: 100%;
}
.titulosHeader {
border-bottom: 1px solid #e8bb25;
height: auto;
margin-bottom: 10px;
padding-bottom: 8px;
padding-top: 8px;
width: 100%;
}
._Separador {
background-color: #fff;
height: 12px;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
width: 7px;
}
._Separador div {
width: 4px;
}
/*style excel*/
.excel_cell {
border: 1px solid #CCC;
color: #222;
text-align: center;
font-size: 13px;
font-weight: normal;
padding: 4px;
white-space: pre-line;
empty-cells: show;
}
._cell_header {
background-color: #EEE;
}
._cell_Default {
background-color: #FFF;
text-align: left;
}
.excel_cell div {
width: 30px;
height: 20px;
}
.celda_encabezado_general {
background-color: #50bbd9;
border: 1px solid #ccc;
color: #ffffff;
font-weight: bold;
padding: 6px 10px;
text-align: center;
}
.celda_encabezado_total {
background-color: #ffffff !important;
border: 1px solid #ffffff;
color: #ffffff !important;
font-weight: bold;
padding: 6px 10px;
text-align: center;
}
.celda_normal {
/*background-color: #fff;*/
/* <!-- ad9271 into ffffff brown-light to green-light --> */
text-align: center;
border: 1px solid #ccc;
padding: 5px 6px;
}
/* Make entire thead sticky */
.fht-table thead {
position: sticky;
top: 0;
z-index: 20;
/* Ensure the entire header stays above table rows */
background-color: #50bbd9;
/* Header background color */
}
.dropdown-menu {
z-index: 25;
}
/* Ensure each <th> in thead stays sticky */
.fht-table thead th {
position: sticky;
top: 0;
z-index: 11;
/* Higher than table rows but lower than first column */
background-color: #50bbd9;
/* Green background */
color: #ffffff;
border: 2px solid ;
padding: 10px;
}
/* Sticky First Column */
.fht-table th:nth-child(1),
.fht-table td:nth-child(1) {
position: sticky;
left: 0;
background-color: #50bbd9;
z-index: 15;
/* Ensures it stays above other cells */
border-right: 2px solid #ddd;
color: #ffffff;
}
/* Table Wrapper for Scrolling */
.table-responsive {
overflow-x: auto;
overflow-y: auto;
max-height: 450px;
max-width: 100%;
position: relative;
}
/* Adjust heights based on screen zoom */
@media only screen and (min-height: 1400px) {
/* Approximate Zoom < 100% */
.table-responsive {
max-height: 425px;
}
}
@media only screen and (min-height: 1200px) {
/* Approximate Zoom ~ 90% */
.table-responsive {
max-height: 500px;
}
}
@media only screen and (min-height: 1000px) {
/* Approximate Zoom ~ 80% */
.table-responsive {
max-height: 600px;
}
}
@media only screen and (min-height: 800px) {
/* Approximate Zoom ~ 75% */
.table-responsive {
max-height: 650px;
}
}
td {
min-width: 100px;
max-width: 100px;
}
tfoot tr {
background-color: rgb(235, 236, 203);
}
body[data-layout-mode=horizontal] .container-fluid {
max-width: 100%;
}
.card-body {
padding-bottom: 0;
}
.card {
margin-bottom: 5px;
}
.hidden-row {
display: none;
}
</style>
<div class="content-page">
<div class="content">
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<div>
<div class="row">
<div class="col-6">
<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);">Stocks</a></li>
<li class="breadcrumb-item active">
<h4 class="page-title">Gas Stock Details </h4>
</li>
</ol>
</div>
</div>
</div>
<div class="col-6 text-right">
<!-- Right-aligned buttons or links can be added here -->
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card" id="fullscreenDiv">
<div class="card-body">
<div id="successMessage"
style="
display: none;
position: absolute;
top: 10px;
left: 50%;
transform: translateX(-50%);
background: green;
color: white;
padding: 10px;
border-radius: 5px;
z-index: 1000;">
</div>
<form id="changeMonthForm" action="<?= base_url('gasStockDetails'); ?>" method="post">
<div class="row">
<?php $today = date('M-Y'); ?>
<div class="col-2">
<input type="text" name="month" id="month" value="<?php echo "$month" ?>"
class="form-control "
readonly>
</div>
<div class="col-10 text-right d-flex" style="justify-content: end;">
<input type="text" id="searchInput" placeholder="Search..."
class="mt-2"
style="padding: 8px;margin-bottom: 10px;width: 250px; border: 2px solid rgb(123, 11, 214);
border-radius: 5px;margin-right:15px;">
<i class="fa fa-table btn-lg mt-2"
title="Date Range Filter"
style="font-size: x-large; cursor:pointer; color:rgb(95, 102, 105);"
data-toggle="modal"
data-target="#filterModalId">
</i>
<i class="fa fa-download btn-lg mt-2"
title="Excel Download"
style="font-size: x-large; cursor:pointer; color: #0b7cba;"
id="gasStockDetailsExport">
</i>
<i class="fe-maximize noti-icon btn-lg mt-2"
title="Full Screen"
style="font-size: x-large; cursor:pointer; color:rgb(241, 9, 136)"
onclick="toggleDivFullscreen()">
</i>
<i class="fa fa-save btn-lg mt-2 auditor-restricted-btn"
title="Save"
style="font-size: x-large; cursor:pointer; color:rgb(31, 132, 3)"
id="saveId">
</i>
</div>
</div>
</form>
<!-- filter modal -->
<div class="modal fade" id="filterModalId" tabindex="-1" role="dialog" aria-labelledby="filterModalLabelId" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="filterModalLabelId">Filter Options</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="row">
<?php
$currentDateInDmY = date('d-m-Y');
?>
<?php
$startDate = DateTime::createFromFormat('M-Y', $month);
if ($startDate) {
$startDate->modify('first day of this month');
$daysInMonth = $startDate->format('t');
$dateArray = [];
for ($i = 0; $i < $daysInMonth; $i++) {
$dateArray[] = $startDate->format('d-m-Y');
$startDate->modify('+1 day');
}
} else {
echo "Invalid date format.";
}
?>
<!-- From Date Filter -->
<div class="col-md-6">
<div class="form-group">
<label for="fromDateFilter">Select From Date</label>
<select id="fromDateFilter" name="fromDateFilter" class="form-control select2">
<?php if (!empty($dateArray)) : ?>
<?php foreach ($dateArray as $index => $date) : ?>
<option value="<?= $date ?>"><?= $date ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
<!-- To Date Filter -->
<div class="col-md-6">
<div class="form-group">
<label for="toDateFilter">Select Date</label>
<select id="toDateFilter" name="toDateFilter" class="form-control select2">
<?php if (!empty($dateArray)) : ?>
<?php foreach ($dateArray as $date) : ?>
<option value="<?= $date ?>" <?= ($date == $currentDateInDmY) || ($date == $dateArray[9]) ? "selected" : " " ?>><?= $date ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
</div>
<button class="btn btn-primary float-right" onclick="customFilterDate()">Filter</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<!-- filter modal end -->
<div class="table-responsive" id="table-responsive">
<table id="gasStockDetailsTableId" class="fht-table">
<thead class="celda_encabezado_general" style="padding: 10px;">
<tr>
<th class="celda_encabezado_general" rowspan="1" colspan="1">RIPL </th>
<th class="celda_encabezado_general" colspan="6">Gas Stock </th>
<th class="celda_encabezado_general" colspan="2">FBD 10 Ton Dryer</th>
<th class="celda_encabezado_general" colspan="2">Coating Machine</th>
<th class="celda_encabezado_general" colspan="2">TRP </th>
<th class="celda_encabezado_general">Sand TRP</th>
<th class="celda_encabezado_general">Rotary Drier </th>
</tr>
<tr>
<!-- gas stock details stored -->
<th class="celda_encabezado_general">Date </th>
<th class="celda_encabezado_general">Opening Stock</th>
<th class="celda_encabezado_general">Purchase(Bharath)</th>
<th class="celda_encabezado_general">Purchase(Indian)</th>
<th class="celda_encabezado_general">Total</th>
<th class="celda_encabezado_general">Consumption </th>
<th class="celda_encabezado_general">Balance Stock</th>
<!-- gas stock details stored -->
<th class="celda_encabezado_general">Consumption </th>
<th class="celda_encabezado_general">Sand Dried Qty(MT) </th>
<th class="celda_encabezado_general">Consumption</th>
<th class="celda_encabezado_general">Sand Coated Qty(Kg) </th>
<th class="celda_encabezado_general">Panel Consumption</th>
<th class="celda_encabezado_general">Physical Consumption</th>
<th class="celda_encabezado_general">Ton </th>
<th class="celda_encabezado_general">Consumption</th>
</tr>
</thead>
<tbody style="background-color: #fff;">
<?php if (!empty($gasStockDetails)) {
foreach ($gasStockDetails as $index => $gasStockDetail) {
$currentDate = date('Y-m-d');
$date = Datetime::createFromFormat('Y-m-d', $gasStockDetail['date'])->format('d-m-Y');
?>
<!-- implementing date highlighter -->
<tr class="<?=$gasStockDetail['date'] > $currentDate ? "hidden-row" : "" ?>"
<?php
if ($gasStockDetail['date'] === $currentDate) {
echo 'style="background: #cef0ad;"';
}
?>
>
<!-- td:eq(0) -->
<td class="celda_normal"><?= $date ?? '-' ?></td>
<!-- td:eq(1) -->
<!-- only setting opening stock editable for first day of the month -->
<td class="celda_normal openingStock"
<?php if ($index == 0) {
echo "contenteditable='true'";
} ?>
oninput="openingStockChange(this)"
data-id="<?= $gasStockDetail['date'] ?>"><?= $gasStockDetail['opening'] ?? ' ' ?>
</td>
<!-- td:eq(2) -->
<td class="celda_normal purchaseBharath"
oninput="purchaseBharathStockChange(this)"
data-id="<?= $gasStockDetail['date'] ?>"
contenteditable="true"><?= $gasStockDetail['purchaseBharath'] ?? ' ' ?>
</td>
<!-- td:eq(3) -->
<td class="celda_normal purchaseIndian"
oninput="purchaseIndianStockChange(this)"
data-id="<?= $gasStockDetail['date'] ?>"
contenteditable="true"><?= $gasStockDetail['purchaseIndian'] ?? ' ' ?>
</td>
<!-- td:eq(4) -->
<td class="celda_normal total"
data-id="<?= $gasStockDetail['date'] ?>"><?= $gasStockDetail['total'] ?? ' ' ?>
</td>
<!-- td:eq(5) -->
<td class="celda_normal consumption"
data-id="<?= $gasStockDetail['date'] ?>"><?= $gasStockDetail['consumption'] ?? ' ' ?>
</td>
<!-- td:eq(6) -->
<td class="celda_normal balanceStock"
data-id="<?= $gasStockDetail['date'] ?>"><?= $gasStockDetail['balanceStock'] ?? ' ' ?>
</td>
<!-- td:eq(7) -->
<td class="celda_normal tenTonGasConsumption"
data-id="<?= $gasStockDetail['date'] ?>"><?= $gasStockDetail['drierMachineGasConsumption'] ?? ' ' ?>
</td>
<!-- td:eq(8) -->
<td class="celda_normal sandDried"
data-id="<?= $gasStockDetail['date'] ?>">
<?= $gasStockDetail['sandDried'] ?? ' ' ?></td>
<!-- td:eq(9) -->
<td class="celda_normal coatingGasConsumption"
data-id="<?= $gasStockDetail['date'] ?>">
<?= $gasStockDetail['coatingMachineGasconsumption'] ?? ' ' ?>
</td>
<!-- td:eq(10) -->
<td class="celda_normal coatedSand"
data-id="<?= $gasStockDetail['date'] ?>">
<?= $gasStockDetail['coatedSand'] ?? ' ' ?>
</td>
<!-- td:eq(11) -->
<td class="celda_normal trpPanelGasConsumption"
data-id="<?= $gasStockDetail['date'] ?>"
oninput="gasConsumptionChange(this)"
contenteditable="true">
<?= $gasStockDetail['trp_panel_gas_consumption'] ?? ' ' ?>
</td>
<!-- td:eq(12) -->
<td class="celda_normal trpPhysicalGasConsumption"
data-id="<?= $gasStockDetail['date'] ?>"
oninput="gasConsumptionChange(this)"
contenteditable="true">
<?= $gasStockDetail['trp_physical_gas_consumption'] ?? ' ' ?>
</td>
<!-- td:eq(13) -->
<td class="celda_normal trpSandProduction"
data-id="<?= $gasStockDetail['date'] ?>"
contenteditable="true">
<?= $gasStockDetail['trp_sand_production'] ?? ' ' ?>
</td>
<!-- td:eq(14) -->
<td class="celda_normal rotaryGasConsumption"
data-id="<?= $gasStockDetail['date'] ?>"
oninput="gasConsumptionChange(this)"
contenteditable="true">
<?= $gasStockDetail['rotary_drier_consumption'] ?? ' ' ?>
</td>
</tr>
<?php
//before closing inner loop we just adding the total values inside it
// Initialize the material entry if it doesn't exist
if (!isset($summary["opening"])) {
$summary = [
'opening' => "-",
'purchaseBharath' => 0,
'purchaseIndian' => 0,
'total' => 0,
'consumption' => 0,
'balanceStock' => 0,
'drierMachineGasConsumption' => 0,
'sandDried' => 0,
'coatingMachineGasconsumption' => 0,
'coatedSand' => 0,
'trp_panel_gas_consumption' => 0,
'trp_physical_gas_consumption' => 0,
'trp_sand_production' => 0,
'rotary_drier_consumption' => 0
];
}
//
// Sum values for the material
$summary["opening"] = 0;
$summary["purchaseBharath"] += is_numeric($gasStockDetail['purchaseBharath']) ? $gasStockDetail['purchaseBharath'] : 0;
$summary["purchaseIndian"] += is_numeric($gasStockDetail['purchaseIndian']) ? $gasStockDetail['purchaseIndian'] : 0;
$summary["total"] += is_numeric($gasStockDetail['total']) ? $gasStockDetail['total'] : 0;
$summary["consumption"] += is_numeric($gasStockDetail['consumption']) ? $gasStockDetail['consumption'] : 0;
$summary["balanceStock"] += is_numeric($gasStockDetail['balanceStock']) ? $gasStockDetail['balanceStock'] : 0;
$summary["drierMachineGasConsumption"] += is_numeric($gasStockDetail['drierMachineGasConsumption']) ? $gasStockDetail['drierMachineGasConsumption'] : 0;
$summary["sandDried"] += is_numeric($gasStockDetail['sandDried']) ? $gasStockDetail['sandDried'] : 0;
$summary["coatingMachineGasconsumption"] += is_numeric($gasStockDetail['coatingMachineGasconsumption']) ? $gasStockDetail['coatingMachineGasconsumption'] : 0;
$summary["coatedSand"] += is_numeric($gasStockDetail['coatedSand']) ? $gasStockDetail['coatedSand'] : 0;
$summary["trp_panel_gas_consumption"] += is_numeric($gasStockDetail['trp_panel_gas_consumption']) ? $gasStockDetail['trp_panel_gas_consumption'] : 0;
$summary["trp_physical_gas_consumption"] += is_numeric($gasStockDetail['trp_physical_gas_consumption']) ? $gasStockDetail['trp_physical_gas_consumption'] : 0;
$summary["trp_sand_production"] += is_numeric($gasStockDetail['trp_sand_production']) ? $gasStockDetail['trp_sand_production'] : 0;
$summary["rotary_drier_consumption"] += is_numeric($gasStockDetail['rotary_drier_consumption']) ? $gasStockDetail['rotary_drier_consumption'] : 0;
} ?>
<tfoot>
<tr>
<td style="background-color:rgb(189, 9, 6); color:#ffff;">
<b> Total </b>
</td>
<td class="celda_normal openingStock"
data-id="footer openingStock"> </td>
<td class="celda_normal purchaseBharath"
data-id="footer purchaseBharath" ><?= $summary['purchaseBharath'] == 0 ? "" : $summary['purchaseBharath'] ?></td>
<td class="celda_normal purchaseIndian"
data-id="footer purchaseIndian"><?= $summary['purchaseIndian'] == 0 ? "" : $summary['purchaseIndian'] ?></td>
<td class="celda_normal total"
data-id="footer total"><?= $summary['total'] == 0 ? "" : $summary['total'] ?></td>
<td class="celda_normal consumption"
data-id="footer consumption"><?= $summary['consumption'] == 0 ? "" : $summary['consumption'] ?></td>
<td class="celda_normal balanceStock"
data-id="footer balanceStock" ></td>
<td class="celda_normal tenTonGasConsumption"
data-id="footer tenTonGasConsumption"><?= $summary['drierMachineGasConsumption'] == 0 ? "" : $summary['drierMachineGasConsumption'] ?></td>
<td class="celda_normal sandDried"
data-id="footer sandDried"><?= $summary['sandDried'] == 0 ? "" : $summary['sandDried'] ?></td>
<td class="celda_normal coatingGasConsumption"
data-id="footer coatingGasConsumption"><?= $summary['coatingMachineGasconsumption'] == 0 ? "" : $summary['coatingMachineGasconsumption'] ?></td>
<td class="celda_normal coatedSand"
data-id="footer coatedSand"><?= $summary['coatedSand'] == 0 ? "" : $summary['coatedSand'] ?></td>
<td class="celda_normal trpPanelGasConsumption"
data-id="footer trpPanelGasConsumption"><?= $summary['trp_panel_gas_consumption'] == 0 ? "" : $summary['trp_panel_gas_consumption'] ?></td>
<td class="celda_normal trpPhysicalGasConsumption"
data-id="footer trpPhysicalGasConsumption"><?= $summary['trp_physical_gas_consumption'] == 0 ? "" : $summary['trp_physical_gas_consumption'] ?></td>
<td class="celda_normal trpSandProduction"
data-id="footer trpSandProduction"><?= $summary['trp_sand_production'] == 0 ? "" : $summary['trp_sand_production'] ?></td>
<td class="celda_normal rotaryGasConsumption"
data-id="footer rotaryGasConsumption"><?= $summary['rotary_drier_consumption'] == 0 ? "" : $summary['rotary_drier_consumption'] ?></td>
</tr>
</tfoot>
<?php } else {
$date = DateTime::createFromFormat('M-Y', $month);
$startDate = $date->modify('first day of this month')->format('Y-m-d');
$endDate = $date->modify('last day of this month')->format('Y-m-d');
$datesInMonth = [];
$period = new DatePeriod(
new DateTime($startDate),
new DateInterval('P1D'),
(new DateTime($endDate))->modify('+1 day')
);
foreach ($period as $day) {
$datesInMonth[] = $day->format('Y-m-d');
}
foreach ($datesInMonth as $datesInMonthIndex => $dateInMonth) {
$currentDate = date('d-m-Y');
$dateInMonthDmYFormat = Datetime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y');
?>
<!-- implementing date highlighter -->
<tr class="<?=$dateInMonth > $currentDate ? "hidden-row" : "" ?>"
<?php
if ($dateInMonth === $currentDate) {
echo 'style="background: #cef0ad;"';
}
?>>
<td class="celda_normal"><?= $dateInMonthDmYFormat ?? '-' ?></td>
<!-- only setting opening stock editable for first day of the month -->
<td class="celda_normal openingStock"
<?php if ($datesInMonthIndex == 0) {
echo "contenteditable='true'";
} ?>
oninput="openingStockChange(this)"
data-id="<?= $dateInMonth ?>"><?= $previousMonthGasStockDetails[0]['balanceStock'] ?? ' ' ?></td>
<td class="celda_normal purchaseBharath"
oninput="purchaseBharathStockChange(this)"
data-id="<?= $dateInMonth ?>"
contenteditable="true"> </td>
<td class="celda_normal purchaseIndian"
oninput="purchaseIndianStockChange(this)"
data-id="<?= $dateInMonth ?>"
contenteditable="true"> </td>
<td class="celda_normal total"
data-id="<?= $dateInMonth ?>"> </td>
<td class="celda_normal consumption"
data-id="<?= $dateInMonth ?>"> </td>
<td class="celda_normal balanceStock"
data-id="<?= $dateInMonth ?>"><?= $previousMonthGasStockDetails[0]['balanceStock'] ?? ' ' ?></td>
<td class="celda_normal tenTonGasConsumption"
data-id="<?= $dateInMonth ?>"> </td>
<td class="celda_normal sandDried"
data-id="<?= $dateInMonth ?>"> </td>
<td class="celda_normal coatingGasConsumption"
data-id="<?= $dateInMonth ?>"> </td>
<td class="celda_normal coatedSand"
data-id="<?= $dateInMonth ?>"> </td>
<td class="celda_normal trpPanelGasConsumption"
data-id="<?= $dateInMonth ?>"
oninput="gasConsumptionChange(this)"
contenteditable="true"> </td>
<td class="celda_normal trpPhysicalGasConsumption"
data-id="<?= $dateInMonth ?>"
oninput="gasConsumptionChange(this)"
contenteditable="true"> </td>
<td class="celda_normal trpSandProduction"
data-id="<?= $dateInMonth ?>"
contenteditable="true"> </td>
<td class="celda_normal rotaryGasConsumption"
data-id="<?= $dateInMonth ?>"
oninput="gasConsumptionChange(this)"
contenteditable="true"> </td>
</tr>
<?php } ?>
<tfoot>
<tr>
<td style="background-color:rgb(189, 9, 6); color:#ffff;">
<b> Total </b>
</td>
<td class="celda_normal openingStock"
data-id="footer openingStock"> </td>
<td class="celda_normal purchaseBharath"
data-id="footer purchaseBharath" > </td>
<td class="celda_normal purchaseIndian"
data-id="footer purchaseIndian"></td>
<td class="celda_normal total"
data-id="footer total"></td>
<td class="celda_normal consumption"
data-id="footer consumption"> </td>
<td class="celda_normal balanceStock"
data-id="footer balanceStock" > </td>
<td class="celda_normal tenTonGasConsumption"
data-id="footer tenTonGasConsumption"> </td>
<td class="celda_normal sandDried"
data-id="footer sandDried"> </td>
<td class="celda_normal coatingGasConsumption"
data-id="footer coatingGasConsumption"> </td>
<td class="celda_normal coatedSand"
data-id="footer coatedSand"> </td>
<td class="celda_normal trpPanelGasConsumption"
data-id="footer trpPanelGasConsumption"> </td>
<td class="celda_normal trpPhysicalGasConsumption"
data-id="footer trpPhysicalGasConsumption"> </td>
<td class="celda_normal trpSandProduction"
data-id="footer trpSandProduction"> </td>
<td class="celda_normal rotaryGasConsumption"
data-id="footer rotaryGasConsumption"> </td>
</tr>
</tfoot>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div> <!-- End card-body -->
</div> <!-- End card -->
</div> <!-- End col -->
</div> <!-- End row -->
</div>
</div> <!-- End container-fluid -->
</div>
</div>
<!-- Modal -->
<script type="text/javascript">
$(document).ready(function() {
$('#saveId').click(function() {
//table to json function
var updateGasStockDetails = tableToJson();
showMessage('Updation may take a while, And we appreciate your patience..!!');
$.ajax({
data: {
updateGasStockDetails
},
type: "POST",
url: "<?php echo base_url() ?>updateGasStockDetails",
success: function(data) {
if (data) {
showMessage(data);
}
},
error: function(xhr, status, error) {
showMessage("An error occurred while processing the request. Please try again.");
console.error("Error Code:", xhr.status);
console.error("Error Message:", error);
console.error("Response Text:", xhr.responseText);
},
complete: function() {
console.log("Request completed.");
}
});
});
});
</script>
<script>
function tableToJson() {
const table = $('#gasStockDetailsTableId');
const rows = [];
table.find('tbody tr').each(function() {
const rowCells = $(this).find('td');
let date = rowCells.eq(0).text().trim().split('-');
date = `${date[2]}-${date[1]}-${date[0]}`;
const rowData = {
date,
opening: rowCells.eq(1).text().trim() || ' ',
purchaseBharath: rowCells.eq(2).text().trim() || ' ',
purchaseIndian: rowCells.eq(3).text().trim() || ' ',
total: rowCells.eq(4).text().trim() || ' ',
consumption: rowCells.eq(5).text().trim() || ' ',
balanceStock: rowCells.eq(6).text().trim() || ' ',
trpPanelGasConsumption: rowCells.eq(11).text().trim() || ' ',
trpPhysicalGasConsumption: rowCells.eq(12).text().trim() || ' ',
trpSandProduction: rowCells.eq(13).text().trim() || ' ',
rotaryDrierConsumption: rowCells.eq(14).text().trim() || ' ',
};
rows.push(rowData);
});
return JSON.stringify(rows, null, 2);
}
</script>
<script>
function openingStockChange(tdElement) {
try {
let basicCheck =checkIsNumber(tdElement.innerText.trim());
if(basicCheck == 0){
alert("Kindly Enter Numbers only..!!");
return ;
}
let dataId = tdElement.getAttribute('data-id');
let date = dataId;
let openingStock = validateInput(tdElement.innerText);
let purchaseBharathStock = validateInput(document.querySelector(`td.purchaseBharath[data-id="${dataId}"]`).innerText);
let purchaseIndianStock = validateInput(document.querySelector(`td.purchaseIndian[data-id="${dataId}"]`).innerText);
let toatalGasConsumption = validateInput(document.querySelector(`td.consumption[data-id="${dataId}"]`).innerText);
let totalGas = (Number(openingStock) + Number(purchaseBharathStock)) + Number(purchaseIndianStock);
let currentBalanceStock = Number(totalGas) - Number(toatalGasConsumption);
document.querySelector(`td.total[data-id="${dataId}"]`).innerText = totalGas;
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText = currentBalanceStock;
updateStockValue(date, currentBalanceStock);
let table = document.getElementById('gasStockDetailsTableId');
let column2 = "openingStock";
let column3 = "total";
let column4 = "balanceStock";
calculateTotal(table,dataId,column2);
calculateTotal(table,dataId,column3);
calculateTotal(table,dataId,column4);
} catch (error) {
console.error("There is an error updating stock ..!!" + error);
}
}
function purchaseBharathStockChange(tdElement) {
try {
let basicCheck =checkIsNumber(tdElement.innerText.trim());
if(basicCheck == 0){
alert("Kindly Enter Numbers only..!!");
return ;
}
let dataId = tdElement.getAttribute('data-id');
let date = dataId;
let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText);
let purchaseBharathStock = validateInput(tdElement.innerText);
let purchaseIndianStock = validateInput(document.querySelector(`td.purchaseIndian[data-id="${dataId}"]`).innerText);
let toatalGasConsumption = validateInput(document.querySelector(`td.consumption[data-id="${dataId}"]`).innerText);
let totalGas = (Number(openingStock) + Number(purchaseBharathStock)) + Number(purchaseIndianStock);
let currentBalanceStock = Number(totalGas) - Number(toatalGasConsumption);
document.querySelector(`td.total[data-id="${dataId}"]`).innerText = totalGas;
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText = currentBalanceStock;
updateStockValue(date, currentBalanceStock);
let table = document.getElementById('gasStockDetailsTableId');
let column1 = 'purchaseBharath';
let column2 = "openingStock";
let column3 = "total";
let column4 = "balanceStock";
calculateTotal(table,dataId,column1);
calculateTotal(table,dataId,column2);
calculateTotal(table,dataId,column3);
calculateTotal(table,dataId,column4);
} catch (error) {
console.error("There is an error updating stock ..!!" + error);
}
}
function purchaseIndianStockChange(tdElement) {
try {
let basicCheck =checkIsNumber(tdElement.innerText.trim());
if(basicCheck == 0){
alert("Kindly Enter Numbers only..!!");
return ;
}
let dataId = tdElement.getAttribute('data-id');
let date = dataId;
let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText);
let purchaseBharathStock = validateInput(document.querySelector(`td.purchaseBharath[data-id="${dataId}"]`).innerText);
let purchaseIndianStock = validateInput(tdElement.innerText);
let toatalGasConsumption = validateInput(document.querySelector(`td.consumption[data-id="${dataId}"]`).innerText);
let totalGas = (Number(openingStock) + Number(purchaseBharathStock)) + Number(purchaseIndianStock);
let currentBalanceStock = Number(totalGas) - Number(toatalGasConsumption);
document.querySelector(`td.total[data-id="${dataId}"]`).innerText = totalGas;
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText = currentBalanceStock;
updateStockValue(date, currentBalanceStock);
let table = document.getElementById('gasStockDetailsTableId') ;
let column1 = 'purchaseIndian' ;
let column2 = "openingStock" ;
let column3 = "total" ;
let column4 = "balanceStock" ;
calculateTotal(table,dataId,column1);
calculateTotal(table,dataId,column2);
calculateTotal(table,dataId,column3);
calculateTotal(table,dataId,column4);
} catch (error) {
console.error("There is an error updating stock ..!!" + error);
}
}
function gasConsumptionChange(tdElement) {
try {
let basicCheck =checkIsNumber(tdElement.innerText.trim());
if(basicCheck == 0){
alert("Kindly Enter Numbers only..!!");
return ;
}
let dataId = tdElement.getAttribute('data-id');
let date = dataId;
//total gas consumption
let tenTonGasConsumption = validateInput(document.querySelector(`td.tenTonGasConsumption[data-id="${dataId}"]`).innerText);
let coatingGasConsumption = validateInput(document.querySelector(`td.coatingGasConsumption[data-id="${dataId}"]`).innerText);
let trpPanelGasConsumption = validateInput(document.querySelector(`td.trpPanelGasConsumption[data-id="${dataId}"]`).innerText);
let trpPhysicalGasConsumption = validateInput(document.querySelector(`td.trpPhysicalGasConsumption[data-id="${dataId}"]`).innerText);
let rotaryGasConsumption = validateInput(document.querySelector(`td.rotaryGasConsumption[data-id="${dataId}"]`).innerText);
let toatalGasConsumption = Number(tenTonGasConsumption) + Number(coatingGasConsumption)
+ Number(trpPhysicalGasConsumption)
// + Number(trpPanelGasConsumption)
//panel gas is not used in consumption calculation but needed its value in sheet..!!
+ Number(rotaryGasConsumption);
//total gas purchase and opening addition
let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText);
let purchaseBharathStock = validateInput(document.querySelector(`td.purchaseBharath[data-id="${dataId}"]`).innerText);
let purchaseIndianStock = validateInput(document.querySelector(`td.purchaseIndian[data-id="${dataId}"]`).innerText);
let totalGas = (Number(openingStock) + Number(purchaseBharathStock)) + Number(purchaseIndianStock);
let currentBalanceStock = Number(totalGas) - (Number(toatalGasConsumption));
document.querySelector(`td.total[data-id="${dataId}"]`).innerText = totalGas;
document.querySelector(`td.consumption[data-id="${dataId}"]`).innerText = toatalGasConsumption;
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText = currentBalanceStock;
updateStockValue(date, currentBalanceStock);
let table = document.getElementById('gasStockDetailsTableId');
let column1 = tdElement.className.split(' ')[1];
let column2 = "openingStock";
let column3 = "total";
let column4 = "balanceStock";
let column5 = "consumption";
calculateTotal(table,dataId,column5);
calculateTotal(table,dataId,column1);
calculateTotal(table,dataId,column2);
calculateTotal(table,dataId,column3);
calculateTotal(table,dataId,column4);
} catch (error) {
console.error("There is an error updating stock ..!!" + error);
}
}
function checkIsNumber(input) {
const isValid = /^-?\d*\.?\d*$/.test(input);
if (!isValid) {
return 0;
}
}
</script>
<script>
function updateStockValue(date, currentBalanceStock) {
const table = $('#gasStockDetailsTableId');
const rows = [];
table.find('tbody tr').each(function() {
const rowCells = $(this).find('td');
let otherDate = rowCells.eq(0).text().trim().split('-');
otherDate = `${otherDate[2]}-${otherDate[1]}-${otherDate[0]}`;
if (new Date(otherDate) > new Date(date)) { //other records present after it
let dataId = `${otherDate}`;
document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText = currentBalanceStock;
let openingStock = currentBalanceStock;
let purchaseBharathStock = validateInput(document.querySelector(`td.purchaseBharath[data-id="${dataId}"]`).innerText);
let purchaseIndianStock = validateInput(document.querySelector(`td.purchaseIndian[data-id="${dataId}"]`).innerText);
let toatalGasConsumption = validateInput(document.querySelector(`td.consumption[data-id="${dataId}"]`).innerText);
let totalGas = (Number(openingStock) + Number(purchaseBharathStock)) + Number(purchaseIndianStock);
currentBalanceStock = Number(totalGas) - Number(toatalGasConsumption);
document.querySelector(`td.total[data-id="${dataId}"]`).innerText = totalGas;
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText = currentBalanceStock;
}
})
}
</script>
<script>
function customFilterDate() {
let fromDate = $('#fromDateFilter').val(); //01-12-2024
let toDate = $('#toDateFilter').val(); //05-12-2024
$('#gasStockDetailsTableId').find('tbody tr').each(function() {
const rowCells = $(this).find('td');
let tableDate = rowCells.eq(0).text();
let result = checkDateRange(fromDate, toDate, tableDate);
if (result) {
$(this).show();
} else {
$(this).hide();
}
});
$('#filterModalId').modal('hide');
}
function checkDateRange(fromDate, toDate, tableDate) {
// Convert the dates to a comparable format (YYYY-MM-DD)
let from = convertToDate(fromDate);
let to = convertToDate(toDate);
let table = convertToDate(tableDate);
// Return true if the table date is within the range
return table >= from && table <= to;
}
function convertToDate(dateString) {
// Convert from DD-MM-YYYY to YYYY-MM-DD for comparison
let parts = dateString.split('-');
return new Date(parts[2], parts[1] - 1, parts[0]); // Year, Month (0-based), Day
}
</script>
<script>
$(document).ready(function() {
$('#fromDateFilter ').select2();
$('#toDateFilter ').select2();
// initialFilterDate();
});
function initialFilterDate() {
let fromDate = $('#fromDateFilter').val(); //01-12-2024
let toDate = $('#toDateFilter').val(); //05-12-2024
console.log("from Date and to date ..!!")
console.log(fromDate, toDate);
$('#gasStockDetailsTableId').find('tbody tr').each(function() {
const rowCells = $(this).find('td');
let tableDate = rowCells.eq(0).text();
let result = checkDateRange(fromDate, toDate, tableDate);
if (result) {
$(this).show();
} else {
$(this).hide();
}
});
}
</script>
<script>
function validateInput(input) {
if (input == '' || input == ' ' || input == '-') {
return 0;
}
if (typeof input === 'string' && input.split('').map(char => char.charCodeAt(0))[0] == 10) {
return 0;
}
// Validate against the regex
const isValid = /^-?\d*\.?\d*$/.test(input);
if (!isValid) {
return 0;
}
return input;
}
</script>
<!-- excel export -->
<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();
}
});
// Format date in first column and left-align
$(cloneTable).find('tbody tr').each(function() {
let firstTd = $(this).find('td').eq(0);
let originalDate = firstTd.text().trim();
let parts = originalDate.split('-');
if (parts.length === 3) {
let formattedDate = `${parts[2]}-${parts[1]}-${parts[0]}`;
firstTd.text(formattedDate);
}
firstTd.css("text-align", "left");
});
// Convert modified table to worksheet
let ws = XLSX.utils.table_to_sheet(cloneTable);
// Dynamically get maximum column count
let colCount = 0;
$(cloneTable).find('tr').each(function() {
let count = $(this).find('th, td').length;
if (count > colCount) colCount = count;
});
// Set each column width to 10
const wscols = [];
for (let i = 0; i < colCount; i++) {
wscols.push({ wch: 10 });
}
ws['!cols'] = wscols;
// Create workbook and save
let wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
XLSX.writeFile(wb, filename || 'export.xlsx');
}
let tableId = 'gasStockDetailsTableId';
document.getElementById('gasStockDetailsExport').addEventListener('click', function() {
exportTableToExcel(tableId, 'gasStockDetails<?= $month ?>.xlsx');
});
});
</script>
<script>
document.addEventListener("keydown", function(event) {
if (event.key === "Enter") {
let activeElement = document.activeElement;
// Check if the focused element is inside a table
let cell = activeElement.closest("td, th");
let table = activeElement.closest("table");
if (table && cell) {
event.preventDefault(); // Prevent form submission
let columnIndex = cell.cellIndex; // Get the current column index
let currentRow = cell.parentElement; // Get the current row
let nextRow = currentRow.nextElementSibling; // Get the next row
// Move to the same column in the next row if available
if (nextRow) {
let nextCell = nextRow.cells[columnIndex];
if (nextCell) {
nextCell.focus();
}
}
}
}
});
</script>
<script>
$(document).ready(function() {
$('#month').change(function() {
$('#changeMonthForm').submit();
})
$('#month').datepicker({
format: 'M-yyyy',
viewMode: 'months',
minViewMode: 'months',
autoclose: true,
orientation: 'bottom',
startDate: new Date(2025, 0), // Jan is month 0
endDate: new Date() // current date as max
});
})
</script>
<script>
function toggleDivFullscreen() {
let div = document.getElementById("fullscreenDiv");
let tableResponsive = document.getElementById("table-responsive"); // Select the table container inside div
if (!document.fullscreenElement) {
div.requestFullscreen().then(() => {
div.style.width = "100vw"; // Full viewport width
div.style.height = "100vh"; // Full viewport height
// If .table-responsive exists, set its height to 90vh
if (tableResponsive) {
tableResponsive.style.maxHeight = "90vh";
tableResponsive.style.overflowY = "auto"; // Allow scrolling if needed
}
}).catch(err => console.log("Error enabling fullscreen:", err));
} else {
document.exitFullscreen().then(() => {
div.style.width = "100%";
div.style.height = "100%";
// Reset .table-responsive height when exiting fullscreen
// If .table-responsive exists, set its height to 90vh
if (tableResponsive) {
tableResponsive.style.maxHeight = "450px";
tableResponsive.style.overflowY = "auto"; // Allow scrolling if needed
}
}).catch(err => console.log("Error exiting fullscreen:", err));
}
}
$("#searchInput").on("keyup", function() {
let value = $(this).val().toLowerCase(); // Convert input to lowercase for case-insensitive search
$(".table-responsive tbody tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
});
</script>
<script>
$(document).ready(function() {
$('.select2').select2({
dropdownParent: $('#fullscreenDiv')
});
// Initialize Select2 when the modal is shown inside full screen
$('#filterModalId,').on('shown.bs.modal', function () {
$('.select2').select2({
dropdownParent: $(this) // This ensures Select2 works in the modal
});
});
});
</script>
<script>
//getting modal backdrop inside full screen
$(document).ready(function() {
function moveModalBackdropToFullscreen() {
setTimeout(() => {
$('.modal-backdrop').appendTo('#fullscreenDiv'); // Move backdrop inside fullscreen
}, 10); // Small delay ensures backdrop is created first
}
// Move the modal backdrop when a modal opens
$('#filterModalId').on('show.bs.modal', function () {
moveModalBackdropToFullscreen();
});
// Ensure modals work properly in fullscreen mode
document.addEventListener("fullscreenchange", function() {
setTimeout(() => {
$('.modal-backdrop').remove(); // Remove any existing backdrops
moveModalBackdropToFullscreen();
}, 200);
});
});
</script>
<script>
function showMessage(msg) {
let msgBox = document.getElementById("successMessage");
msgBox.innerText = msg; // Set API message
msgBox.style.display = "block";
// Hide message after 3 seconds
setTimeout(() => {
msgBox.style.display = "none";
}, 5000);
}
</script>
<script>
function calculateTotal(table,dataId,column) {
let columnTotal = 0;
let rows = table.querySelectorAll('tbody tr');
rows.forEach(row => {
let date = row.querySelector('td:first-child').innerText.trim().split('-');
date = date[2] + "-" + date[1] + "-" + date[0]; // Convert to YYYY-MM-DD format
let cell = null;
cell = row.querySelector(`td.${column}[data-id="${date}"]`);
if (cell) {
let value = parseFloat(cell.innerText.trim()) || 0;
columnTotal += value ;
}
});
// Update the total cell in the footer
let footerColumn = table.querySelector(`tfoot tr td.${column}[data-id="footer ${column}"]`);
if (footerColumn) {
footerColumn.innerText = columnTotal == 0 ? " " : columnTotal.toFixed(2);
}
let footerColumnOpeningStock = table.querySelector(`tfoot tr td.openingStock[data-id="footer openingStock`);
let footerColumnPurchaseBharath = table.querySelector(`tfoot tr td.purchaseBharath[data-id="footer purchaseBharath`);
let footerColumnPurchaseIndian = table.querySelector(`tfoot tr td.purchaseIndian[data-id="footer purchaseIndian`);
let footerColumnTotal = table.querySelector(`tfoot tr td.total[data-id="footer total`);
let footerColumnConsumption = table.querySelector(`tfoot tr td.consumption[data-id="footer consumption`);
let footerColumnBalanceStock = table.querySelector(`tfoot tr td.balanceStock[data-id="footer balanceStock`);
footerColumnTotal.innerText = isNaN(
parseFloat(footerColumnOpeningStock.innerText.trim() )
+
parseFloat(footerColumnPurchaseBharath.innerText.trim())
+
parseFloat(footerColumnPurchaseIndian.innerText.trim())
) == true
?
" " : (
parseFloat(footerColumnOpeningStock.innerText.trim() )
+
parseFloat(footerColumnPurchaseBharath.innerText.trim())
+
parseFloat(footerColumnPurchaseIndian.innerText.trim())
) ;
footerColumnBalanceStock.innerText = isNaN(
parseFloat(footerColumnTotal.innerText.trim())
-
parseFloat(footerColumnConsumption.innerText.trim())
) == true
?
" " : (
parseFloat(footerColumnTotal.innerText.trim())
-
parseFloat(footerColumnConsumption.innerText.trim())
) ;
}
</script>