stock module latest today vadivel J 11-1-2025

This commit is contained in:
vadivelJ96 2025-01-11 14:31:37 +05:30
parent 5f24a5d177
commit 5a4077507e
4 changed files with 399 additions and 362 deletions

View File

@ -869,11 +869,11 @@ class StockController extends BaseController
// getting customer for creating table headers
// checking already existing stock if yes then get customer from the existing stock
// if not set customer as '' empty string
// if not set customer in db , then set '' empty string
foreach ($resinMaterials as $key => $resinMaterial) {
$materialCode = $resinMaterial['MaterialCode'];
$resinMaterials[$key]['customers'] = $this->bagStockDetails_model
$resinMaterials[$key]['customers'] = $this->resinStockDetails_model
->select('customer')
->where('date >=', $startDate)
->where('date <=', $endDate)

View File

@ -32,30 +32,5 @@ class BagStockDetailsModel extends Model
* @param array $data Array of records to be updated in bulk.
* @return bool
*/
public function updateBatchWithCompositeKey(array $data)
{
$db = \Config\Database::connect();
$db->transBegin();
foreach ($data as $record) {
$db->table($this->table)
->where('date', $record['date'])
->where('materialCode', $record['materialCode'])
->update([
'customer' => $record['customer'],
'opening' => $record['opening'],
'receipt' => $record['receipt'],
'used' => $record['used'],
'balanceStock' => $record['balanceStock']
]);
}
if ($db->transStatus() === FALSE) {
$db->transRollback();
return false;
} else {
$db->transCommit();
return true;
}
}
}

View File

@ -349,11 +349,12 @@
</td>
<td class="celda_normal openingStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
<?php if ($groupedBagStockDetailsIndex == 0): ?>
oninput="openingStockChange(this)"
contenteditable="true"
contenteditable="true"
<?php endif; ?>
><?= $bagStock['opening']?>
@ -362,14 +363,18 @@
<td class="celda_normal receiptStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">
contenteditable="true"
>
<?= $bagStock['receipt']?>
</td>
<td class="celda_normal usedStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
oninput="usedStockChange(this)"
contenteditable="true"><?= $bagStock['used']?>
contenteditable="true"
>
<?= $bagStock['used']?>
</td>
<td class="celda_normal balanceStock"
@ -432,21 +437,20 @@
contenteditable="true"
<?php }?>
><?= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'0' ?></td>
><?= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'-' ?></td>
<td class="celda_normal receiptStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">0</td>
contenteditable="true"> - </td>
<td class="celda_normal usedStock"
<td class="celda_normal usedStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
oninput="usedStockChange(this)"
contenteditable="true">0</td>
oninput="usedStockChange(this)" contenteditable="true"> - </td>
<td class="celda_normal balanceStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
><?= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'0' ?></td>
><?= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'-' ?></td>
<?php } ?>
</tr>
<?php } ?>
@ -694,11 +698,17 @@
try{
let dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
let openingStock = tdElement.innerText;
let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText;
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText;
let openingStock = validateInput( tdElement.innerText );
let usedStock = validateInput(document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText);
let receiptStock = validateInput(document.querySelector(`td.receiptStock[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 )
@ -713,12 +723,19 @@
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 openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText);
let receiptStock = validateInput(tdElement.innerText);
let usedStock = validateInput(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 )
@ -736,12 +753,19 @@
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;
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText;
let usedStock = tdElement.innerText;
let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText);
let receiptStock = validateInput(document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText);
let usedStock = validateInput(tdElement.innerText);
let currentBalanceStock = ( Number(openingStock) + Number(receiptStock) ) - Number(usedStock);
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
updateStockValue( date,materialCode,currentBalanceStock )
@ -776,9 +800,9 @@
document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText;
let usedStock = validateInput(document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText);
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText;
let receiptStock = validateInput(document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText);
currentBalanceStock = (Number(currentBalanceStock) + Number(receiptStock)) - Number(usedStock);
@ -800,6 +824,31 @@
})
}
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>

View File

@ -105,10 +105,11 @@
border: 1px solid #ccc;
color: #ffffff;
font-weight: bold;
padding: 6px 10px;;
padding: 6px 10px;
;
text-align: center;
}
._Separador {
background-color: #fff;
@ -173,27 +174,27 @@
<?php
<?php
$date = DateTime::createFromFormat('M-Y', $month);
$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');
$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 = [];
$datesInMonth = [];
$period = new DatePeriod(
new DateTime($startDate),
new DateInterval('P1D'),
(new DateTime($endDate))->modify('+1 day')
);
$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 ($period as $day) {
$datesInMonth[] = $day->format('Y-m-d');
}
?>
?>
@ -242,207 +243,204 @@
<button type="submit" class="btn btn-success"> Change Month </button>
</div>
<div class="col-md-1"></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 class="dropdown-item" data-toggle="modal" data-target="#bs-example-modal-lg">Navigation</a>
<a class="dropdown-item" href="#">Export</a>
</div>
</div>
</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 class="dropdown-item" data-toggle="modal" data-target="#bs-example-modal-lg">Navigation</a>
<a class="dropdown-item" href="#">Export</a>
</div>
</div>
</div>
</div>
</form>
<div class="table-responsive">
<table id="resinStockDetailsTableId" class="fht-table table-striped">
<thead class="celda_encabezado_general" style="padding: 10px;">
<tr>
<th class="celda_encabezado_general" colspan="1">material </th>
<?php foreach($resinMaterials as $resinMaterial){ ?>
<!-- this will loop till materials present -->
<th class="celda_encabezado_general" colspan="4">
<?= $resinMaterial['MaterialName']?>
<!-- (<?= $resinMaterial['MaterialCode']?>) -->
<th class="celda_encabezado_general" colspan="1">material </th>
<?php foreach ($resinMaterials as $resinMaterial) { ?>
<!-- this will loop till materials present -->
<th class="celda_encabezado_general" colspan="4">
<?= $resinMaterial['MaterialName'] ?>
<!-- (<?= $resinMaterial['MaterialCode'] ?>) -->
</th>
<?php } ?>
<?php } ?>
</tr>
<tr>
<th class="celda_encabezado_general" colspan="1">Date </th>
<?php foreach($resinMaterials as $resinMaterial){ ?>
<!-- this will loop till materials present -->
<th class="celda_encabezado_general" style="display:none">Date</th>
<th class="celda_encabezado_general" style="display:none"> material</th>
<th class="celda_encabezado_general" style="display:none"> customer</th>
<th class="celda_encabezado_general">Opening Stock</th>
<th class="celda_encabezado_general">Receipt</th>
<th class="celda_encabezado_general">Used</th>
<th class="celda_encabezado_general">Balance Stock</th>
<?php } ?>
<tr>
<th class="celda_encabezado_general" colspan="1">Date </th>
<?php foreach ($resinMaterials as $resinMaterial) { ?>
<!-- this will loop till materials present -->
<th class="celda_encabezado_general" style="display:none">Date</th>
<th class="celda_encabezado_general" style="display:none"> material</th>
<th class="celda_encabezado_general" style="display:none"> customer</th>
<th class="celda_encabezado_general">Opening Stock</th>
<th class="celda_encabezado_general">Receipt</th>
<th class="celda_encabezado_general">Used</th>
<th class="celda_encabezado_general">Balance Stock</th>
<?php } ?>
</tr>
</thead>
<tbody style="background-color: #fff;" >
<tbody style="background-color: #fff;">
<?php if(!empty($groupedResinStockDetails))
{
//dd($groupedResinStockDetails);
foreach($groupedResinStockDetails as $groupedResinStockDetailsIndex => $resinStockDetails){
?>
<tr
<?php
$currentDate = date('d-m-Y');
$dateInMonthDmYFormat= DateTime::createFromFormat('Y-m-d', $resinStockDetails[0]['date'])->format('d-m-Y');
if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';}
?>
>
<?php foreach($resinStockDetails as $resinStockIndex => $resinStock){ ?>
<?php if ($resinStockIndex == 0): ?>
<?php
$startDate =DateTime::createFromFormat('Y-m-d', $resinStock['date'])->format('d-m-Y');
?>
<td class="celda_normal">
<?= $startDate ?>
</td>
<?php endif; ?>
<td style="display:none">
<?= $resinStock['date']?>
</td>
<td style="display:none"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
class="materialCode" ><?= $resinStock['materialCode']?>
</td>
<td style="display:none" class="celda_normal customer"
data-materialCode="<?=$resinStock['materialCode']?>"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>">
<?= $resinStock['customer']?>
</td>
<td class="celda_normal openingStock"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
<?php if ($groupedResinStockDetailsIndex == 0): ?>
oninput="openingStockChange(this)"
contenteditable="true"
<?php endif; ?>
><?= $resinStock['opening']?>
</td>
<td class="celda_normal receiptStock"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">
<?= $resinStock['receipt']?>
</td>
<td class="celda_normal usedStock"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
oninput="usedStockChange(this)"
contenteditable="true"><?= $resinStock['used']?>
</td>
<td class="celda_normal balanceStock"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>">
<?= $resinStock['balanceStock']?>
</td>
<?php } ?>
</tr>
<?php } ?>
<!-- this else condition work if groupedBagStockDetails is empty and creating new records
with initial values 0 for entire month -->
<?php } else { ?>
<?php foreach($datesInMonth as $datesInMonthIndex => $dateInMonth){ ?>
<tr
<?php if (!empty($groupedResinStockDetails)) {
//dd($groupedResinStockDetails);
foreach ($groupedResinStockDetails as $groupedResinStockDetailsIndex => $resinStockDetails) {
?>
<tr
<?php
$currentDate = date('d-m-Y');
$dateInMonthDmYFormat= DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y');
if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';}
?>
>
<?php
foreach($resinMaterials as $resinMaterialIndex => $resinMaterial){ ?>
<!-- this will loop till materials present -->
$dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $resinStockDetails[0]['date'])->format('d-m-Y');
if ($dateInMonthDmYFormat === $currentDate) {
echo 'style="background: #cef0ad;"';
}
?>>
<?php foreach ($resinStockDetails as $resinStockIndex => $resinStock) { ?>
<?php if ($resinStockIndex == 0): ?>
<?php
$startDate = DateTime::createFromFormat('Y-m-d', $resinStock['date'])->format('d-m-Y');
?>
<td class="celda_normal">
<?= $startDate ?>
</td>
<?php endif; ?>
<?php if ($resinMaterialIndex == 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">
<?= $dateInMonth?>
<td style="display:none">
<?= $resinStock['date'] ?>
</td>
<td style="display:none"
data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>"
class="materialCode"><?= $resinStock['materialCode'] ?>
</td>
<td class="celda_normal" style="display:none"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>">
<?= $resinMaterial['MaterialCode']?>
</td>
<td class="celda_normal customer" style="display:none"
data-materialCode="<?=$resinMaterial['MaterialCode']?>"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>">
<?= $resinMaterial['customers']?>
<td style="display:none" class="celda_normal customer"
data-materialCode="<?= $resinStock['materialCode'] ?>"
data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>">
<?= $resinStock['customer'] ?>
</td>
<td class="celda_normal openingStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
<?php if($datesInMonthIndex == 0){ ?>
oninput="openingStockChange(this)"
contenteditable="true"
data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>"
<?php }?>
><?= $previousMonthResinStockDetails[$resinMaterialIndex]['balanceStock']??'0' ?></td>
<?php if ($groupedResinStockDetailsIndex == 0): ?>
oninput="openingStockChange(this)"
contenteditable="true"
<?php endif; ?>><?= $resinStock['opening'] ?>
</td>
<td class="celda_normal receiptStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">0</td>
data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>"
oninput="receiptStockChange(this)"
contenteditable="true">
<?= $resinStock['receipt'] ?>
</td>
<td class="celda_normal usedStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
oninput="usedStockChange(this)"
contenteditable="true">0</td>
data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>"
oninput="usedStockChange(this)"
contenteditable="true"><?= $resinStock['used'] ?>
</td>
<td class="celda_normal balanceStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
><?= $previousMonthResinStockDetails[$resinMaterialIndex]['balanceStock']??'0' ?></td>
data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>">
<?= $resinStock['balanceStock'] ?>
</td>
<?php } ?>
</tr>
<?php } ?>
<!-- this else condition work if groupedBagStockDetails is empty and creating new records
with initial values 0 for entire month -->
<?php } else { ?>
<?php foreach ($datesInMonth as $datesInMonthIndex => $dateInMonth) { ?>
<tr
<?php
$currentDate = date('d-m-Y');
$dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y');
if ($dateInMonthDmYFormat === $currentDate) {
echo 'style="background: #cef0ad;"';
}
?>>
<?php
foreach ($resinMaterials as $resinMaterialIndex => $resinMaterial) { ?>
<!-- this will loop till materials present -->
<?php if ($resinMaterialIndex == 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">
<?= $dateInMonth ?>
</td>
<td class="celda_normal" style="display:none"
data-id="<?= $dateInMonth ?> <?= $resinMaterial['MaterialCode'] ?>">
<?= $resinMaterial['MaterialCode'] ?>
</td>
<td class="celda_normal customer" style="display:none"
data-materialCode="<?= $resinMaterial['MaterialCode'] ?>"
data-id="<?= $dateInMonth ?> <?= $resinMaterial['MaterialCode'] ?>">
<?= $resinMaterial['customers'] ?>
</td>
<td class="celda_normal openingStock"
data-id="<?= $dateInMonth ?> <?= $resinMaterial['MaterialCode'] ?>"
<?php if ($datesInMonthIndex == 0) { ?>
oninput="openingStockChange(this)"
contenteditable="true"
<?php } ?>><?= $previousMonthResinStockDetails[$resinMaterialIndex]['balanceStock'] ?? '-' ?></td>
<td class="celda_normal receiptStock"
data-id="<?= $dateInMonth ?> <?= $resinMaterial['MaterialCode'] ?>"
oninput="receiptStockChange(this)"
contenteditable="true">-</td>
<td class="celda_normal usedStock"
data-id="<?= $dateInMonth ?> <?= $resinMaterial['MaterialCode'] ?>"
oninput="usedStockChange(this)"
contenteditable="true">-</td>
<td class="celda_normal balanceStock"
data-id="<?= $dateInMonth ?> <?= $resinMaterial['MaterialCode'] ?>"><?= $previousMonthResinStockDetails[$resinMaterialIndex]['balanceStock'] ?? '-' ?></td>
<?php } ?>
</tr>
<?php } ?>
<?php }?>
<?php } ?>
</tbody>
</table>
</div>
@ -465,58 +463,58 @@
</div>
<div >
<div class="modal fade" id="bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" >
<div class="modal-content" >
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Navigation Options</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="row">
<!-- bag Dropdown -->
<div class="col-md-6">
<div class="form-group">
<label for="resinDropdown">Select Bag</label>
<select id="resinDropdown" class="form-control">
<option value="">Select Resin</option>
<?php foreach($resinMaterials as $resinMaterial): ?>
<option value=" <?= $resinMaterial['MaterialName']?>">
<?= $resinMaterial['MaterialName']?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<!-- Date Dropdown -->
<div class="col-md-6">
<div class="form-group">
<label for="dateDropdown">Select Date</label>
<select id="dateDropdown" class="form-control">
<?php foreach($datesInMonth as $selectDate): ?>
<?php $selectDate=DateTime::createFromFormat('Y-m-d', $selectDate)->format('d-m-Y'); ?>
<option value="<?=$selectDate?>"><?=$selectDate?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div>
<div class="modal fade" id="bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Navigation Options</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<button class="btn btn-primary float-right" onclick="navigateToResin()">Navigate</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="modal-body">
<div class="row">
<!-- bag Dropdown -->
<div class="col-md-6">
<div class="form-group">
<label for="resinDropdown">Select Bag</label>
<select id="resinDropdown" class="form-control">
<option value="">Select Resin</option>
<?php foreach ($resinMaterials as $resinMaterial): ?>
<option value=" <?= $resinMaterial['MaterialName'] ?>">
<?= $resinMaterial['MaterialName'] ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<!-- Date Dropdown -->
<div class="col-md-6">
<div class="form-group">
<label for="dateDropdown">Select Date</label>
<select id="dateDropdown" class="form-control">
<?php foreach ($datesInMonth as $selectDate): ?>
<?php $selectDate = DateTime::createFromFormat('Y-m-d', $selectDate)->format('d-m-Y'); ?>
<option value="<?= $selectDate ?>"><?= $selectDate ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<button class="btn btn-primary float-right" onclick="navigateToResin()">Navigate</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
<script>
<script>
function navigateToResin() {
$('.close').click();
const resinDropdown = document.getElementById('resinDropdown');
@ -547,7 +545,7 @@
rows.forEach(row => {
const dateCell = row.querySelector('td:first-child');
if (dateCell && dateCell.textContent.trim() === selectedDate) {
targetRow = row;
}
});
@ -559,9 +557,9 @@
console.log(targetColumnIndex);
console.log(targetRow);
targetColumnIndex = targetColumnIndex * 7;
targetRow.cells[targetColumnIndex].scrollIntoView({
@ -571,7 +569,7 @@
});
const highlightDuration = 10000;
for (let i = targetColumnIndex-4 ; i <= targetColumnIndex ; i++) {
for (let i = targetColumnIndex - 4; i <= targetColumnIndex; i++) {
const cell = targetRow.cells[i];
if (cell) {
@ -586,20 +584,17 @@
}
</script>
<script type="text/javascript">
$(document).ready(function() {
$(document).ready(function () {
$('#saveId').click(function () {
$('#saveId').click(function() {
//table to json function
var updateResinStockDetails = tableToJson();
alert('Updation may take a while, And we appreciate your patience..!!');
@ -611,7 +606,7 @@
type: "POST",
url: "<?php echo base_url() ?>updateResinStockDetails",
success: function (data) {
success: function(data) {
if (data) {
$('#loader').hide();
console.log(data);
@ -620,14 +615,14 @@
},
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);
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();
$('#loader').hide();
}
});
@ -635,7 +630,6 @@
});
});
</script>
<script>
@ -646,134 +640,153 @@
//this table to json is customized for bagstock not for all
table.find('tbody tr').each(function() {
const rowCells = $(this).find('td');
const date = rowCells.eq(0).text().trim();
const rowCells = $(this).find('td');
const date = rowCells.eq(0).text().trim();
/** we get eight entries against a material so we loop from 1 to 7 and so on
in a single row **/
for (let i = 1; i < rowCells.length; i += 7) {
for (let i = 1; i < rowCells.length; i += 7) {
const rowData = {
date: rowCells.eq(i).text().trim(),
materialCode: rowCells.eq(i+1).text().trim(),
customer: rowCells.eq(i+2).text().trim(),
opening: rowCells.eq(i+3).text().trim(),
receipt: rowCells.eq(i+4).text().trim(),
used: rowCells.eq(i+5).text().trim(),
materialCode: rowCells.eq(i + 1).text().trim(),
customer: rowCells.eq(i + 2).text().trim(),
opening: rowCells.eq(i + 3).text().trim(),
receipt: rowCells.eq(i + 4).text().trim(),
used: rowCells.eq(i + 5).text().trim(),
balanceStock: rowCells.eq(i + 6).text().trim()
};
rows.push(rowData);
}
});
return JSON.stringify(rows, null, 2);
return JSON.stringify(rows, null, 2);
}
</script>
<script>
function openingStockChange(tdElement) {
try{
try {
let dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
let openingStock = tdElement.innerText;
let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText;
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText;
let currentBalanceStock = (Number(openingStock) + Number(receiptStock)) - Number(usedStock);
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
let [date, materialCode] = tdElement.getAttribute('data-id').split(' ');
let openingStock = validateInput(tdElement.innerText);
let usedStock = validateInput(document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText);
let receiptStock = validateInput(document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText);
let currentBalanceStock = validateInput((Number(openingStock) + Number(receiptStock)) - Number(usedStock));
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 receiptStockChange(tdElement) {
try{
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 [date, materialCode] = tdElement.getAttribute('data-id').split(' ');
let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText);
let receiptStock = validateInput(tdElement.innerText);
let usedStock = validateInput(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);
}
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) {
function usedStockChange(tdElement) {
try {
try {
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 receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText;
let usedStock = tdElement.innerText;
let currentBalanceStock = ( Number(openingStock) + Number(receiptStock) ) - Number(usedStock);
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
updateStockValue( date,materialCode,currentBalanceStock )
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 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;
}
} catch (error) {
console.error("There is an error updating stock ..!!" + error);
}
}
</script>
<script>
function updateStockValue( date, materialCode, currentBalanceStock ){
function updateStockValue(date, materialCode, currentBalanceStock) {
const table = $('#resinStockDetailsTableId');
const rows = [];
const rows = [];
table.find('tbody tr').each(function() {
const rowCells = $(this).find('td');
const rowCells = $(this).find('td');
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
/**this data-id ,openingStock ,used stock , current Balance Stock
is for changing subsequent dates not the earlier one **/
let dataId = `${otherDate} ${materialCode}`;
document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText = currentBalanceStock;
let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText;
let usedStock = validateInput(document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText);
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText;
let receiptStock = validateInput(document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText);
currentBalanceStock = (Number(currentBalanceStock) + Number(receiptStock)) - Number(usedStock);
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText = currentBalanceStock;
}
})
}
</script>
</script>