bag stock changes -vadivel J

This commit is contained in:
vadivel J 2024-11-06 17:18:47 +05:30
parent 4a28f03d1a
commit 3eef21a464

View File

@ -271,10 +271,15 @@
<tr>
<?php foreach($bagStockDetails as $bagStockIndex => $bagStock){ ?>
<?php if ($bagStockIndex == 0): ?>
<?php
$startDate =DateTime::createFromFormat('Y-m-d', $bagStock['date'])->format('d-m-Y');
?>
<td class="celda_normal">
<?= $bagStock['date'] ?>
<?= $startDate ?>
</td>
<?php endif; ?>
@ -290,15 +295,19 @@
<td class="celda_normal openingStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
oninput="openingStockChange(this)"
<?php if ($groupedBagStockDetailsIndex == 0): ?>
oninput="openingStockChange(this)"
contenteditable="true"
<?php endif; ?>
><?= $bagStock['opening']?>
</td>
<td class="celda_normal receiptStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>">
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">
<?= $bagStock['receipt']?>
</td>
@ -323,21 +332,46 @@
<?php
$date = DateTime::createFromFormat('M-Y', $month);
$month = $date->format('m-Y');
$startDate = "01-$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');
}
?>
<th class="celda_normal" colspan="1"><?= $startDate?> </th>
<?php foreach($bagMaterials as $bagMaterial){ ?>
<?php foreach($datesInMonth as $datesInMonthIndex => $dateInMonth){ ?>
<tr>
<?php
foreach($bagMaterials as $bagMaterialIndex => $bagMaterial){ ?>
<!-- this will loop till materials present -->
<?php if ($bagMaterialIndex == 0): ?>
<?php
$startDate =DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y');
?>
<td class="celda_normal">
<?= $startDate ?>
</td>
<?php endif; ?>
<td class="celda_normal" style="display:none">
<?= $startDate?>
<?= $dateInMonth?>
</td>
<td class="celda_normal" style="display:none"
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>">
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>">
<?= $bagMaterial['MaterialCode']?>
</td>
@ -346,24 +380,30 @@
</td>
<td class="celda_normal openingStock"
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
<?php if($datesInMonthIndex == 0){ ?>
oninput="openingStockChange(this)"
contenteditable="true">0</td>
contenteditable="true"
<?php }?>
>0</td>
<td class="celda_normal receiptStock"
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>"
oninput="openingStockChange(this)"
contenteditable="true">0</td>>0</td>
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">0</td>
<td class="celda_normal usedStock"
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
oninput="usedStockChange(this)"
contenteditable="true">0</td>
<td class="celda_normal balanceStock"
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>"
oninput="usedStockChange(this)"
contenteditable="true">0</td>
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
>0</td>
<?php } ?>
</tr>
<?php } ?>
<?php }?>
@ -401,13 +441,13 @@
$(document).ready(function () {
$('#saveId').click(function () {
//table to json function
var updateBagStockDetails = tableToJson();
alert('Updation may take a while, And we appreciate your patience..!!');
$('#loader').show();
@ -441,7 +481,6 @@
});
});
</script>
@ -477,9 +516,6 @@
return JSON.stringify(rows, null, 2);
}
</script>
<script>
@ -505,10 +541,31 @@
}
}
function receiptStockChange(tdElement) {
try{
let dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
let openingStock = document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText;
let receiptStock = tdElement.innerText;
let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText;
let currentBalanceStock = (Number(openingStock) + Number(receiptStock)) - Number(usedStock);
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
updateStockValue( date,materialCode,currentBalanceStock )
} catch(error){
console.error("There is an error updating stock ..!!" + error);
}
}
function usedStockChange(tdElement) {
try {
let dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
let openingStock = document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText;
@ -525,8 +582,6 @@
console.error("There is an error updating stock ..!!" + error);
}
}
</script>
@ -539,7 +594,7 @@
table.find('tbody tr').each(function() {
const rowCells = $(this).find('td');
const otherDate = rowCells.eq(0).text().trim();
const otherDate = rowCells.eq(1).text().trim();
if( new Date(otherDate) > new Date(date) ){ //other records present after it