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 // getting customer for creating table headers
// checking already existing stock if yes then get customer from the existing stock // 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) { foreach ($resinMaterials as $key => $resinMaterial) {
$materialCode = $resinMaterial['MaterialCode']; $materialCode = $resinMaterial['MaterialCode'];
$resinMaterials[$key]['customers'] = $this->bagStockDetails_model $resinMaterials[$key]['customers'] = $this->resinStockDetails_model
->select('customer') ->select('customer')
->where('date >=', $startDate) ->where('date >=', $startDate)
->where('date <=', $endDate) ->where('date <=', $endDate)

View File

@ -32,30 +32,5 @@ class BagStockDetailsModel extends Model
* @param array $data Array of records to be updated in bulk. * @param array $data Array of records to be updated in bulk.
* @return bool * @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,6 +349,7 @@
</td> </td>
<td class="celda_normal openingStock" <td class="celda_normal openingStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>" data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
<?php if ($groupedBagStockDetailsIndex == 0): ?> <?php if ($groupedBagStockDetailsIndex == 0): ?>
@ -362,14 +363,18 @@
<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)" oninput="receiptStockChange(this)"
contenteditable="true"> contenteditable="true"
>
<?= $bagStock['receipt']?> <?= $bagStock['receipt']?>
</td> </td>
<td class="celda_normal usedStock" <td class="celda_normal usedStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>" data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
oninput="usedStockChange(this)" oninput="usedStockChange(this)"
contenteditable="true"><?= $bagStock['used']?> contenteditable="true"
>
<?= $bagStock['used']?>
</td> </td>
<td class="celda_normal balanceStock" <td class="celda_normal balanceStock"
@ -432,21 +437,20 @@
contenteditable="true" contenteditable="true"
<?php }?> <?php }?>
><?= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'0' ?></td> ><?= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'-' ?></td>
<td class="celda_normal receiptStock" <td class="celda_normal receiptStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>" data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
oninput="receiptStockChange(this)" 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']?>" data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
oninput="usedStockChange(this)" oninput="usedStockChange(this)" contenteditable="true"> - </td>
contenteditable="true">0</td>
<td class="celda_normal balanceStock" <td class="celda_normal balanceStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>" data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
><?= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'0' ?></td> ><?= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'-' ?></td>
<?php } ?> <?php } ?>
</tr> </tr>
<?php } ?> <?php } ?>
@ -694,11 +698,17 @@
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 usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText; let openingStock = validateInput( tdElement.innerText );
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).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); 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 )
@ -713,12 +723,19 @@
function receiptStockChange(tdElement) { function receiptStockChange(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 = document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText;
let receiptStock = tdElement.innerText; let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText);
let usedStock = document.querySelector(`td.usedStock[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); 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 )
@ -736,12 +753,19 @@
function usedStockChange(tdElement) { function usedStockChange(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 = document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText;
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText; let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText);
let usedStock = tdElement.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); 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 )
@ -776,9 +800,9 @@
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); 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> </script>

View File

@ -105,7 +105,8 @@
border: 1px solid #ccc; border: 1px solid #ccc;
color: #ffffff; color: #ffffff;
font-weight: bold; font-weight: bold;
padding: 6px 10px;; padding: 6px 10px;
;
text-align: center; text-align: center;
} }
@ -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'); $startDate = $date->modify('first day of this month')->format('Y-m-d');
$endDate = $date->modify('last 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( $period = new DatePeriod(
new DateTime($startDate), new DateTime($startDate),
new DateInterval('P1D'), new DateInterval('P1D'),
(new DateTime($endDate))->modify('+1 day') (new DateTime($endDate))->modify('+1 day')
); );
foreach ($period as $day) { foreach ($period as $day) {
$datesInMonth[] = $day->format('Y-m-d'); $datesInMonth[] = $day->format('Y-m-d');
} }
?> ?>
@ -242,18 +243,18 @@
<button type="submit" class="btn btn-success"> Change Month </button> <button type="submit" class="btn btn-success"> Change Month </button>
</div> </div>
<div class="col-md-1"></div> <div class="col-md-1"></div>
<div class="col-6"> <div class="col-6">
<div class="dropdown float-right"> <div class="dropdown float-right">
<a href="#" class="dropdown-toggle arrow-none" data-toggle="dropdown" <a href="#" class="dropdown-toggle arrow-none" data-toggle="dropdown"
aria-expanded="false"> aria-expanded="false">
<i class="mdi mdi-dots-vertical m-0 text-muted h3"></i> <i class="mdi mdi-dots-vertical m-0 text-muted h3"></i>
</a> </a>
<div class="dropdown-menu dropdown-menu-right"> <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" data-toggle="modal" data-target="#bs-example-modal-lg">Navigation</a>
<a class="dropdown-item" href="#">Export</a> <a class="dropdown-item" href="#">Export</a>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</form> </form>
@ -266,181 +267,178 @@
<tr> <tr>
<th class="celda_encabezado_general" colspan="1">material </th> <th class="celda_encabezado_general" colspan="1">material </th>
<?php foreach($resinMaterials as $resinMaterial){ ?> <?php foreach ($resinMaterials as $resinMaterial) { ?>
<!-- this will loop till materials present --> <!-- this will loop till materials present -->
<th class="celda_encabezado_general" colspan="4"> <th class="celda_encabezado_general" colspan="4">
<?= $resinMaterial['MaterialName']?> <?= $resinMaterial['MaterialName'] ?>
<!-- (<?= $resinMaterial['MaterialCode']?>) --> <!-- (<?= $resinMaterial['MaterialCode'] ?>) -->
</th> </th>
<?php } ?> <?php } ?>
</tr> </tr>
<tr> <tr>
<th class="celda_encabezado_general" colspan="1">Date </th> <th class="celda_encabezado_general" colspan="1">Date </th>
<?php foreach($resinMaterials as $resinMaterial){ ?> <?php foreach ($resinMaterials as $resinMaterial) { ?>
<!-- this will loop till materials present --> <!-- this will loop till materials present -->
<th class="celda_encabezado_general" style="display:none">Date</th> <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"> material</th>
<th class="celda_encabezado_general" style="display:none"> customer</th> <th class="celda_encabezado_general" style="display:none"> customer</th>
<th class="celda_encabezado_general">Opening Stock</th> <th class="celda_encabezado_general">Opening Stock</th>
<th class="celda_encabezado_general">Receipt</th> <th class="celda_encabezado_general">Receipt</th>
<th class="celda_encabezado_general">Used</th> <th class="celda_encabezado_general">Used</th>
<th class="celda_encabezado_general">Balance Stock</th> <th class="celda_encabezado_general">Balance Stock</th>
<?php } ?> <?php } ?>
</tr> </tr>
</thead> </thead>
<tbody style="background-color: #fff;" > <tbody style="background-color: #fff;">
<?php if(!empty($groupedResinStockDetails)) <?php if (!empty($groupedResinStockDetails)) {
{ //dd($groupedResinStockDetails);
//dd($groupedResinStockDetails); foreach ($groupedResinStockDetails as $groupedResinStockDetailsIndex => $resinStockDetails) {
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 <tr
<?php <?php
$currentDate = date('d-m-Y'); $currentDate = date('d-m-Y');
$dateInMonthDmYFormat= DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y'); $dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $resinStockDetails[0]['date'])->format('d-m-Y');
if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';} if ($dateInMonthDmYFormat === $currentDate) {
?> echo 'style="background: #cef0ad;"';
> }
<?php ?>>
foreach($resinMaterials as $resinMaterialIndex => $resinMaterial){ ?> <?php foreach ($resinStockDetails as $resinStockIndex => $resinStock) { ?>
<!-- this will loop till materials present --> <?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): ?> <td style="display:none">
<?php <?= $resinStock['date'] ?>
$startDate =DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y'); </td>
?> <td style="display:none"
<td class="celda_normal"> data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>"
<?= $startDate ?> class="materialCode"><?= $resinStock['materialCode'] ?>
</td>
<?php endif; ?>
<td class="celda_normal" style="display:none">
<?= $dateInMonth?>
</td> </td>
<td class="celda_normal" style="display:none" <td style="display:none" class="celda_normal customer"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"> data-materialCode="<?= $resinStock['materialCode'] ?>"
<?= $resinMaterial['MaterialCode']?> data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>">
</td> <?= $resinStock['customer'] ?>
<td class="celda_normal customer" style="display:none"
data-materialCode="<?=$resinMaterial['MaterialCode']?>"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>">
<?= $resinMaterial['customers']?>
</td> </td>
<td class="celda_normal openingStock" <td class="celda_normal openingStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>" data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>"
<?php if($datesInMonthIndex == 0){ ?>
oninput="openingStockChange(this)" <?php if ($groupedResinStockDetailsIndex == 0): ?>
contenteditable="true" oninput="openingStockChange(this)"
contenteditable="true"
<?php }?> <?php endif; ?>><?= $resinStock['opening'] ?>
><?= $previousMonthResinStockDetails[$resinMaterialIndex]['balanceStock']??'0' ?></td> </td>
<td class="celda_normal receiptStock" <td class="celda_normal receiptStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>" data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>"
oninput="receiptStockChange(this)" oninput="receiptStockChange(this)"
contenteditable="true">0</td> contenteditable="true">
<?= $resinStock['receipt'] ?>
</td>
<td class="celda_normal usedStock" <td class="celda_normal usedStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>" data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>"
oninput="usedStockChange(this)" oninput="usedStockChange(this)"
contenteditable="true">0</td> contenteditable="true"><?= $resinStock['used'] ?>
</td>
<td class="celda_normal balanceStock" <td class="celda_normal balanceStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>" data-id="<?= $resinStock['date'] ?> <?= $resinStock['materialCode'] ?>">
><?= $previousMonthResinStockDetails[$resinMaterialIndex]['balanceStock']??'0' ?></td> <?= $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 } ?> <?php } ?>
</tr> </tr>
<?php } ?> <?php } ?>
<?php }?> <?php } ?>
</tbody> </tbody>
@ -465,52 +463,52 @@
</div> </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 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-dialog modal-lg">
<div class="modal-content" > <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Navigation Options</h4> <h4 class="modal-title" id="myLargeModalLabel">Navigation Options</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <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>
<button class="btn btn-primary float-right" onclick="navigateToResin()">Navigate</button> <div class="modal-body">
</div> <div class="row">
</div><!-- /.modal-content --> <!-- bag Dropdown -->
</div><!-- /.modal-dialog --> <div class="col-md-6">
</div><!-- /.modal --> <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> </div>
@ -571,7 +569,7 @@
}); });
const highlightDuration = 10000; const highlightDuration = 10000;
for (let i = targetColumnIndex-4 ; i <= targetColumnIndex ; i++) { for (let i = targetColumnIndex - 4; i <= targetColumnIndex; i++) {
const cell = targetRow.cells[i]; const cell = targetRow.cells[i];
if (cell) { if (cell) {
@ -586,15 +584,12 @@
} }
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() {
$('#saveId').click(function() {
$(document).ready(function () {
$('#saveId').click(function () {
//table to json function //table to json function
@ -611,7 +606,7 @@
type: "POST", type: "POST",
url: "<?php echo base_url() ?>updateResinStockDetails", url: "<?php echo base_url() ?>updateResinStockDetails",
success: function (data) { success: function(data) {
if (data) { if (data) {
$('#loader').hide(); $('#loader').hide();
console.log(data); console.log(data);
@ -635,7 +630,6 @@
}); });
}); });
</script> </script>
<script> <script>
@ -655,11 +649,11 @@
for (let i = 1; i < rowCells.length; i += 7) { for (let i = 1; i < rowCells.length; i += 7) {
const rowData = { const rowData = {
date: rowCells.eq(i).text().trim(), date: rowCells.eq(i).text().trim(),
materialCode: rowCells.eq(i+1).text().trim(), materialCode: rowCells.eq(i + 1).text().trim(),
customer: rowCells.eq(i+2).text().trim(), customer: rowCells.eq(i + 2).text().trim(),
opening: rowCells.eq(i+3).text().trim(), opening: rowCells.eq(i + 3).text().trim(),
receipt: rowCells.eq(i+4).text().trim(), receipt: rowCells.eq(i + 4).text().trim(),
used: rowCells.eq(i+5).text().trim(), used: rowCells.eq(i + 5).text().trim(),
balanceStock: rowCells.eq(i + 6).text().trim() balanceStock: rowCells.eq(i + 6).text().trim()
}; };
@ -670,79 +664,101 @@
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 = validateInput(tdElement.innerText);
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);
let currentBalanceStock = (Number(openingStock) + Number(receiptStock)) - Number(usedStock); let currentBalanceStock = validateInput((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 receiptStockChange(tdElement) { function receiptStockChange(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 = document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText; let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText);
let receiptStock = tdElement.innerText; let receiptStock = validateInput(tdElement.innerText);
let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText; let usedStock = validateInput(document.querySelector(`td.usedStock[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 usedStockChange(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 = document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText; let openingStock = document.querySelector(`td.openingStock[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 usedStock = tdElement.innerText; let usedStock = tdElement.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);
}
}
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;
}
console.error("There is an error updating stock ..!!" + error);
}
}
</script> </script>
<script> <script>
function updateStockValue(date, materialCode, currentBalanceStock) {
function updateStockValue( date, materialCode, currentBalanceStock ){
const table = $('#resinStockDetailsTableId'); const table = $('#resinStockDetailsTableId');
const rows = []; const rows = [];
@ -752,28 +768,25 @@
const otherDate = rowCells.eq(1).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
/**this data-id ,openingStock ,used stock , current Balance Stock /**this data-id ,openingStock ,used stock , current Balance Stock
is for changing subsequent dates not the earlier one **/ is for changing subsequent dates not the earlier one **/
let dataId = `${otherDate} ${materialCode}`; 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); 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>