895 lines
37 KiB
PHP
895 lines
37 KiB
PHP
<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: #00a65a;
|
||
color: #ffffff;
|
||
}
|
||
|
||
.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%;
|
||
}
|
||
|
||
|
||
.celda_encabezado_general {
|
||
background-color: #00a65a;
|
||
border: 1px solid #ccc;
|
||
color: #ffffff;
|
||
font-weight: bold;
|
||
padding: 6px 10px;;
|
||
text-align: center;
|
||
}
|
||
|
||
|
||
._Separador {
|
||
background-color: #fff;
|
||
height: 12px;
|
||
border-left: 1px solid #ccc;
|
||
border-right: 1px solid #ccc;
|
||
width: 7px;
|
||
}
|
||
|
||
._Separador div {
|
||
width: 4px;
|
||
}
|
||
|
||
.celda_normal {
|
||
/*background-color: #fff;*/
|
||
/* <!-- ad9271 into ffffff brown-light to green-light --> */
|
||
text-align: center;
|
||
border: 1px solid #ccc;
|
||
padding: 2px 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;
|
||
}
|
||
|
||
#gasStockDetailsTableId th:nth-child(1),
|
||
#gasStockDetailsTableId td:nth-child(1)
|
||
{
|
||
position: sticky;
|
||
left: 0;
|
||
background-color: #00a65a;
|
||
z-index: 2;
|
||
border-right: 2px solid #ddd;
|
||
color: #ffffff;
|
||
}
|
||
|
||
|
||
</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">
|
||
<div class="card-body">
|
||
|
||
|
||
<form action="<?= base_url('gasStockDetails'); ?>" method="post">
|
||
<div class="row">
|
||
|
||
<div class="col-md-3">
|
||
<input type="text" name="month" id="month" value="<?php echo "$month" ?>"
|
||
class="form-control mt-2" data-provide="datepicker"
|
||
data-date-format="M-yyyy" data-date-min-view-mode="1">
|
||
</div>
|
||
<div class="form-group col-md-3">
|
||
<button type="submit" class="btn btn-success"> Change Month </button>
|
||
</div>
|
||
|
||
<div class="col-6">
|
||
<div class="dropdown float-right">
|
||
<a href="#" class="dropdown-toggle arrow-none" data-toggle="dropdown"
|
||
aria-expanded="false">
|
||
<i class="mdi mdi-dots-vertical m-0 text-muted h3"></i>
|
||
</a>
|
||
<div class="dropdown-menu dropdown-menu-right">
|
||
<a style="cursor:pointer"
|
||
class="dropdown-item" data-toggle="modal" data-target="#filterModalId">Filter</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
</form>
|
||
|
||
|
||
|
||
<div class="table-responsive">
|
||
<table id="gasStockDetailsTableId" class="fht-table table-striped">
|
||
|
||
<thead class="celda_encabezado_general" style="padding: 10px;">
|
||
|
||
<tr>
|
||
|
||
<th class="celda_encabezado_general" colspan="14">SEP- GAS CONSUMPTION-422 & 425 kg </th>
|
||
</tr>
|
||
|
||
|
||
|
||
<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">10 Ton</th>
|
||
<th class="celda_encabezado_general">Sand Dried</th>
|
||
<th class="celda_encabezado_general">Coating Machine</th>
|
||
<th class="celda_encabezado_general">Sand Coated</th>
|
||
<th class="celda_encabezado_general">Trp Machine </th>
|
||
<th class="celda_encabezado_general">Sand TRP</th>
|
||
<th class="celda_encabezado_general">Rotary Drier </th>
|
||
</tr>
|
||
|
||
<tr>
|
||
<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>
|
||
<th class="celda_encabezado_general">Consumption </th>
|
||
<th class="celda_encabezado_general">ton </th>
|
||
<th class="celda_encabezado_general">Consumption</th>
|
||
<th class="celda_encabezado_general">ton </th>
|
||
<th class="celda_encabezado_general">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){
|
||
|
||
$date = Datetime::createFromFormat('Y-m-d',$gasStockDetail['date'])->format('d-m-Y')
|
||
?>
|
||
<!-- implementing date highlighter -->
|
||
<tr
|
||
|
||
<?php
|
||
|
||
$currentDate = date('d-m-Y');
|
||
if ($date === $currentDate) { echo 'style="background: #cef0ad;"'; }
|
||
?>
|
||
|
||
>
|
||
<td class="celda_normal"><?=$date??'-'?></td>
|
||
|
||
<!-- 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 class="celda_normal purchaseBharath"
|
||
oninput="purchaseBharathStockChange(this)"
|
||
data-id="<?=$gasStockDetail['date']?>"
|
||
contenteditable="true"><?=$gasStockDetail['purchaseBharath'] ?? ' '?></td>
|
||
|
||
<td class="celda_normal purchaseIndian"
|
||
oninput="purchaseIndianStockChange(this)"
|
||
data-id="<?=$gasStockDetail['date']?>"
|
||
contenteditable="true"><?=$gasStockDetail['purchaseIndian'] ?? ' '?></td>
|
||
|
||
<td class="celda_normal total"
|
||
data-id="<?=$gasStockDetail['date']?>"
|
||
><?=$gasStockDetail['total'] ?? ' '?></td>
|
||
<td class="celda_normal consumption"
|
||
data-id="<?=$gasStockDetail['date']?>"
|
||
><?=$gasStockDetail['consumption'] ?? ' '?></td>
|
||
<td class="celda_normal balanceStock"
|
||
data-id="<?=$gasStockDetail['date']?>"
|
||
><?=$gasStockDetail['balanceStock'] ?? ' '?></td>
|
||
<td class="celda_normal tenTonGasConsumption"
|
||
data-id="<?=$gasStockDetail['date']?>"
|
||
><?=$gasStockDetail['drierMachineGasConsumption'] ?? ' '?></td>
|
||
<td class="celda_normal">
|
||
<?=$gasStockDetail['sandDried'] ?? ' '?></td>
|
||
<td class="celda_normal coatingGasConsumption"
|
||
data-id="<?=$gasStockDetail['date']?>" >
|
||
<?=$gasStockDetail['coatingMachineGasconsumption'] ?? ' '?></td>
|
||
<td class="celda_normal">
|
||
<?=$gasStockDetail['coatedSand'] ?? ' '?></td>
|
||
|
||
<td class="celda_normal trpGasConsumption"
|
||
data-id="<?=$gasStockDetail['date']?>"
|
||
oninput = "gasConsumptionChange(this)"
|
||
contenteditable="true" >
|
||
<?=$gasStockDetail['trpMachineGasconsumption'] ?? ' '?></td>
|
||
|
||
<td class="celda_normal"
|
||
contenteditable="true" >
|
||
<?=$gasStockDetail['sandTrp'] ?? ' '?>
|
||
</td>
|
||
|
||
<td class="celda_normal rotaryGasConsumption"
|
||
data-id="<?=$gasStockDetail['date']?>"
|
||
oninput = "gasConsumptionChange(this)"
|
||
contenteditable="true" >
|
||
<?=$gasStockDetail['rotaryDrierMachineGasconsumption'] ?? ' '?>
|
||
</td>
|
||
|
||
</tr>
|
||
<?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) {
|
||
|
||
$dateInMonthDmYFormat = Datetime::createFromFormat('Y-m-d',$dateInMonth)->format('d-m-Y');
|
||
|
||
?>
|
||
|
||
<!-- implementing date highlighter -->
|
||
<tr
|
||
|
||
<?php
|
||
|
||
$currentDate = date('d-m-Y');
|
||
if ($dateInMonthDmYFormat === $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"> </td>
|
||
<td class="celda_normal coatingGasConsumption"
|
||
data-id="<?=$dateInMonth?>"
|
||
> </td>
|
||
<td class="celda_normal"> </td>
|
||
<td class="celda_normal trpGasConsumption"
|
||
data-id="<?=$dateInMonth?>"
|
||
contenteditable="true"
|
||
oninput = "gasConsumptionChange(this)"
|
||
> </td>
|
||
<td class="celda_normal"
|
||
contenteditable="true"
|
||
> </td>
|
||
<td class="celda_normal rotaryGasConsumption"
|
||
data-id="<?=$dateInMonth?>"
|
||
contenteditable="true"
|
||
oninput = "gasConsumptionChange(this)"
|
||
> </td>
|
||
</tr>
|
||
<?php }
|
||
}?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<div class="row">
|
||
<div class="col-md-12 text-right">
|
||
<input type="button" class="btn btn-success" id="saveId" value="save">
|
||
</div>
|
||
</div>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div>
|
||
|
||
</div> <!-- End card-body -->
|
||
</div> <!-- End card -->
|
||
</div> <!-- End col -->
|
||
</div> <!-- End row -->
|
||
</div>
|
||
</div> <!-- End container-fluid -->
|
||
</div>
|
||
</div>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<!-- Modal -->
|
||
|
||
<!-- 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">
|
||
<?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">
|
||
<?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 -->
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<script type="text/javascript">
|
||
|
||
|
||
$(document).ready(function () {
|
||
|
||
$('#saveId').click(function () {
|
||
|
||
//table to json function
|
||
|
||
var updateGasStockDetails = tableToJson();
|
||
|
||
|
||
alert('Updation may take a while, And we appreciate your patience..!!');
|
||
|
||
$('#loader').show();
|
||
$.ajax({
|
||
data: {
|
||
updateGasStockDetails
|
||
},
|
||
type: "POST",
|
||
url: "<?php echo base_url() ?>updateGasStockDetails",
|
||
|
||
success: function (data) {
|
||
if (data) {
|
||
$('#loader').hide();
|
||
console.log(data);
|
||
alert(data);
|
||
window.location.reload();
|
||
}
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
|
||
alert("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() {
|
||
$('#loader').hide();
|
||
}
|
||
});
|
||
|
||
|
||
});
|
||
|
||
});
|
||
|
||
</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()|| ' '
|
||
};
|
||
|
||
rows.push(rowData);
|
||
|
||
|
||
});
|
||
|
||
return JSON.stringify(rows, null, 2);
|
||
}
|
||
|
||
</script>
|
||
|
||
<script>
|
||
|
||
function openingStockChange(tdElement) {
|
||
|
||
try{
|
||
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 )
|
||
|
||
|
||
} catch(error){
|
||
|
||
console.error("There is an error updating stock ..!!" + error);
|
||
|
||
}
|
||
}
|
||
|
||
function purchaseBharathStockChange(tdElement) {
|
||
try{
|
||
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 )
|
||
|
||
|
||
} catch(error){
|
||
|
||
console.error("There is an error updating stock ..!!" + error);
|
||
|
||
}
|
||
}
|
||
|
||
function purchaseIndianStockChange(tdElement) {
|
||
|
||
try{
|
||
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 )
|
||
|
||
|
||
} catch(error){
|
||
|
||
console.error("There is an error updating stock ..!!" + error);
|
||
|
||
}
|
||
}
|
||
|
||
function gasConsumptionChange(tdElement) {
|
||
|
||
try{
|
||
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 trpGasConsumption = validateInput(document.querySelector(`td.trpGasConsumption[data-id="${dataId}"]`).innerText);
|
||
let rotaryGasConsumption = validateInput(document.querySelector(`td.rotaryGasConsumption[data-id="${dataId}"]`).innerText);
|
||
|
||
let toatalGasConsumption = Number(tenTonGasConsumption) + Number (coatingGasConsumption) + Number(trpGasConsumption) + 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 )
|
||
|
||
} catch(error){
|
||
console.error("There is an error updating stock ..!!" + error);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
</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) {
|
||
alert('Invalid input! Please enter a valid number.');
|
||
return 0;
|
||
}
|
||
|
||
return input;
|
||
}
|
||
|
||
</script>
|