From 5a4077507e77bb1ecd02146939f4b9c4372f2a8e Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Sat, 11 Jan 2025 14:31:37 +0530 Subject: [PATCH] stock module latest today vadivel J 11-1-2025 --- app/Controllers/StockController.php | 4 +- app/Models/BagStockDetailsModel.php | 25 -- app/Views/bagStockDetails.php | 91 +++- app/Views/resinStockDetails.php | 641 ++++++++++++++-------------- 4 files changed, 399 insertions(+), 362 deletions(-) diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index 0e4d43e9..61271b8a 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -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) diff --git a/app/Models/BagStockDetailsModel.php b/app/Models/BagStockDetailsModel.php index 4a4e9993..bb287b8c 100644 --- a/app/Models/BagStockDetailsModel.php +++ b/app/Models/BagStockDetailsModel.php @@ -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; - } - } } diff --git a/app/Views/bagStockDetails.php b/app/Views/bagStockDetails.php index ee9342db..33c2e357 100644 --- a/app/Views/bagStockDetails.php +++ b/app/Views/bagStockDetails.php @@ -349,11 +349,12 @@ oninput="openingStockChange(this)" - contenteditable="true" + contenteditable="true" > @@ -362,14 +363,18 @@ + contenteditable="true" + > + contenteditable="true" + + > + - > + > 0 + contenteditable="true"> - - 0 + oninput="usedStockChange(this)" contenteditable="true"> - + > @@ -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; +} + + + + diff --git a/app/Views/resinStockDetails.php b/app/Views/resinStockDetails.php index 6a298f35..e035e394 100644 --- a/app/Views/resinStockDetails.php +++ b/app/Views/resinStockDetails.php @@ -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 @@ - 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 @@
-
- -
+
+ +
- +
- + - - - - - + + + + - + - - - - - - - - - - - - - + + + + + + + + + + + + + - + - + - $resinStockDetails){ - ?> - format('d-m-Y'); - if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';} - ?> - > - $resinStock){ ?> - - format('d-m-Y'); - ?> - - - - - - - - - - - - - - - - - - - - - - - - - - $dateInMonth){ ?> - $resinStockDetails) { + ?> + format('d-m-Y'); - if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';} - ?> - > - $resinMaterial){ ?> - + $dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $resinStockDetails[0]['date'])->format('d-m-Y'); + if ($dateInMonthDmYFormat === $currentDate) { + echo 'style="background: #cef0ad;"'; + } + ?>> + $resinStock) { ?> + + format('d-m-Y'); + ?> + + - - format('d-m-Y'); - ?> - - - - + - - - + + oninput="openingStockChange(this)" + contenteditable="true" + > + + data-id="" + oninput="receiptStockChange(this)" + contenteditable="true"> + + + data-id="" + oninput="usedStockChange(this)" + contenteditable="true"> + + data-id=""> + + + + + + + + + + + + + $dateInMonth) { ?> + format('d-m-Y'); + if ($dateInMonthDmYFormat === $currentDate) { + echo 'style="background: #cef0ad;"'; + } + ?>> + $resinMaterial) { ?> + + + + format('d-m-Y'); + ?> + + + + + + + + + + + + + + + + - + + -
material - - + material + +
Date Opening StockReceiptUsedBalance Stock
Date Opening StockReceiptUsedBalance Stock
- - - - - oninput="openingStockChange(this)" - contenteditable="true" - - - > - - - - - -
+ + - - + + - - oninput="openingStockChange(this)" - contenteditable="true" + data-id=" " - - > 0 0
+ + + + oninput="openingStockChange(this)" + contenteditable="true" + + >--
@@ -465,58 +463,58 @@ -
-