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> <tr>
<?php foreach($bagStockDetails as $bagStockIndex => $bagStock){ ?> <?php foreach($bagStockDetails as $bagStockIndex => $bagStock){ ?>
<?php if ($bagStockIndex == 0): ?> <?php if ($bagStockIndex == 0): ?>
<?php
$startDate =DateTime::createFromFormat('Y-m-d', $bagStock['date'])->format('d-m-Y');
?>
<td class="celda_normal"> <td class="celda_normal">
<?= $bagStock['date'] ?> <?= $startDate ?>
</td> </td>
<?php endif; ?> <?php endif; ?>
@ -290,15 +295,19 @@
<td class="celda_normal openingStock" <td class="celda_normal openingStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>" data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
oninput="openingStockChange(this)"
<?php if ($groupedBagStockDetailsIndex == 0): ?> <?php if ($groupedBagStockDetailsIndex == 0): ?>
oninput="openingStockChange(this)"
contenteditable="true" contenteditable="true"
<?php endif; ?> <?php endif; ?>
><?= $bagStock['opening']?> ><?= $bagStock['opening']?>
</td> </td>
<td class="celda_normal receiptStock" <td class="celda_normal receiptStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"> data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">
<?= $bagStock['receipt']?> <?= $bagStock['receipt']?>
</td> </td>
@ -322,49 +331,80 @@
<?php <?php
$date = DateTime::createFromFormat('M-Y', $month); $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');
<th class="celda_normal" colspan="1"><?= $startDate?> </th> $endDate = $date->modify('last day of this month')->format('Y-m-d');
<?php foreach($bagMaterials as $bagMaterial){ ?> $datesInMonth = [];
<!-- this will loop till materials present -->
<td class="celda_normal" style="display:none">
<?= $startDate?>
</td>
<td class="celda_normal" style="display:none" $period = new DatePeriod(
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>"> new DateTime($startDate),
<?= $bagMaterial['MaterialCode']?> new DateInterval('P1D'),
</td> (new DateTime($endDate))->modify('+1 day')
);
<td class="celda_normal" style="display:none"> foreach ($period as $day) {
<?= $bagMaterial['customers']?> $datesInMonth[] = $day->format('Y-m-d');
</td> }
<td class="celda_normal openingStock" ?>
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>"
oninput="openingStockChange(this)"
contenteditable="true">0</td>
<td class="celda_normal receiptStock" <?php foreach($datesInMonth as $datesInMonthIndex => $dateInMonth){ ?>
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>" <tr>
oninput="openingStockChange(this)" <?php
contenteditable="true">0</td>>0</td> foreach($bagMaterials as $bagMaterialIndex => $bagMaterial){ ?>
<!-- this will loop till materials present -->
<td class="celda_normal usedStock" <?php if ($bagMaterialIndex == 0): ?>
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>" <?php
oninput="usedStockChange(this)" $startDate =DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y');
contenteditable="true">0</td> ?>
<td class="celda_normal">
<?= $startDate ?>
</td>
<?php endif; ?>
<td class="celda_normal balanceStock" <td class="celda_normal" style="display:none">
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>" <?= $dateInMonth?>
oninput="usedStockChange(this)" </td>
contenteditable="true">0</td>
<?php } ?> <td class="celda_normal" style="display:none"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>">
<?= $bagMaterial['MaterialCode']?>
</td>
<td class="celda_normal" style="display:none">
<?= $bagMaterial['customers']?>
</td>
<td class="celda_normal openingStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
<?php if($datesInMonthIndex == 0){ ?>
oninput="openingStockChange(this)"
contenteditable="true"
<?php }?>
>0</td>
<td class="celda_normal receiptStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">0</td>
<td class="celda_normal usedStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
oninput="usedStockChange(this)"
contenteditable="true">0</td>
<td class="celda_normal balanceStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
>0</td>
<?php } ?>
</tr>
<?php } ?>
<?php }?> <?php }?>
@ -401,13 +441,13 @@
$(document).ready(function () { $(document).ready(function () {
$('#saveId').click(function () { $('#saveId').click(function () {
//table to json function //table to json function
var updateBagStockDetails = tableToJson(); var updateBagStockDetails = tableToJson();
alert('Updation may take a while, And we appreciate your patience..!!'); alert('Updation may take a while, And we appreciate your patience..!!');
$('#loader').show(); $('#loader').show();
@ -441,7 +481,6 @@
}); });
}); });
</script> </script>
@ -477,38 +516,56 @@
return JSON.stringify(rows, null, 2); return JSON.stringify(rows, null, 2);
} }
</script> </script>
<script> <script>
function openingStockChange(tdElement) { function openingStockChange(tdElement) {
try{ try{
let dataId = tdElement.getAttribute('data-id'); let dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' '); let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
let openingStock = tdElement.innerText; let openingStock = tdElement.innerText;
let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText; let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText;
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText; let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText;
let currentBalanceStock = (Number(openingStock) + Number(receiptStock)) - Number(usedStock); let currentBalanceStock = (Number(openingStock) + Number(receiptStock)) - Number(usedStock);
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock; document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
updateStockValue( date,materialCode,currentBalanceStock ) updateStockValue( date,materialCode,currentBalanceStock )
} catch(error){ } catch(error){
console.error("There is an error updating stock ..!!" + error); console.error("There is an error updating stock ..!!" + error);
} }
} }
function usedStockChange(tdElement) { 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;
try { 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 dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' '); let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
let openingStock = document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText; let openingStock = document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText;
@ -520,14 +577,12 @@
updateStockValue( date,materialCode,currentBalanceStock ) updateStockValue( date,materialCode,currentBalanceStock )
} catch (error) { } catch (error) {
console.error("There is an error updating stock ..!!" + error); console.error("There is an error updating stock ..!!" + error);
} }
}
}
</script> </script>
<script> <script>
@ -539,7 +594,7 @@
table.find('tbody tr').each(function() { table.find('tbody tr').each(function() {
const rowCells = $(this).find('td'); 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 if( new Date(otherDate) > new Date(date) ){ //other records present after it