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>
@ -319,52 +328,83 @@
<?php } ?> <?php } ?>
<?php } else{?> <?php } else{?>
<?php <?php
$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');
}
?>
<?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; ?>
$date = DateTime::createFromFormat('M-Y', $month); <td class="celda_normal" style="display:none">
$month = $date->format('m-Y'); <?= $dateInMonth?>
$startDate = "01-$month"; </td>
?> <td class="celda_normal" style="display:none"
<th class="celda_normal" colspan="1"><?= $startDate?> </th> data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>">
<?= $bagMaterial['MaterialCode']?>
</td>
<?php foreach($bagMaterials as $bagMaterial){ ?> <td class="celda_normal" style="display:none">
<!-- this will loop till materials present --> <?= $bagMaterial['customers']?>
</td>
<td class="celda_normal" style="display:none">
<?= $startDate?>
</td>
<td class="celda_normal" style="display:none"
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>">
<?= $bagMaterial['MaterialCode']?>
</td>
<td class="celda_normal" style="display:none"> <td class="celda_normal openingStock"
<?= $bagMaterial['customers']?> data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
</td> <?php if($datesInMonthIndex == 0){ ?>
oninput="openingStockChange(this)"
contenteditable="true"
<td class="celda_normal openingStock" <?php }?>
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>" >0</td>
oninput="openingStockChange(this)"
contenteditable="true">0</td>
<td class="celda_normal receiptStock" <td class="celda_normal receiptStock"
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>" data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
oninput="openingStockChange(this)" oninput="receiptStockChange(this)"
contenteditable="true">0</td>>0</td> contenteditable="true">0</td>
<td class="celda_normal usedStock" <td class="celda_normal usedStock"
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>" data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
oninput="usedStockChange(this)" oninput="usedStockChange(this)"
contenteditable="true">0</td> contenteditable="true">0</td>
<td class="celda_normal balanceStock" <td class="celda_normal balanceStock"
data-id="<?=$startDate?> <?=$bagMaterial['MaterialCode']?>" data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
oninput="usedStockChange(this)" >0</td>
contenteditable="true">0</td> <?php } ?>
<?php } ?> </tr>
<?php } ?>
<?php }?> <?php }?>
@ -400,13 +440,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..!!');
@ -441,7 +481,6 @@
}); });
}); });
</script> </script>
@ -476,39 +515,57 @@
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){
console.error("There is an error updating stock ..!!" + error); } catch(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;
updateStockValue( date,materialCode,currentBalanceStock )
} catch(error){
console.error("There is an error updating stock ..!!" + error);
}
}
try {
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>
@ -535,12 +590,12 @@
function updateStockValue( date, materialCode, currentBalanceStock ){ function updateStockValue( date, materialCode, currentBalanceStock ){
const table = $('#bagStockDetailsTableId'); const table = $('#bagStockDetailsTableId');
const rows = []; const rows = [];
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