From e011e967eaaf407a0a70c19ea652ec8f3c5e9067 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Fri, 24 Jan 2025 17:51:33 +0530 Subject: [PATCH 1/7] stock module latest today vadivel J 24-01-2025 --- app/Views/bagStockDetails.php | 145 +++++++++--------- app/Views/dieselStockDetails.php | 136 ++++++++--------- app/Views/drierMachineDetails.php | 1 + app/Views/dustAndRoughStockDetails.php | 195 +++++++++++++++++++------ app/Views/resinStockDetails.php | 147 ++++++++++--------- app/Views/trpSandUseStockDetails.php | 176 +++++++++++++++------- 6 files changed, 508 insertions(+), 292 deletions(-) diff --git a/app/Views/bagStockDetails.php b/app/Views/bagStockDetails.php index 06a27484..ae0a1a0a 100644 --- a/app/Views/bagStockDetails.php +++ b/app/Views/bagStockDetails.php @@ -97,29 +97,7 @@ padding-bottom: 8px; padding-top: 8px; width: 100%; - } - - - .celda_encabezado_general { - background-color: #00a65a; - border: 1px solid #ccc; - color: #ffffff; - font-weight: bold; - padding: 6px 10px;; - text-align: center; - } - - - .celda_encabezado_total { - background-color:#ffffff; - border: 1px solid #ccc; - color: #ffffff; - font-weight: bold; - padding: 6px 10px; - ; - text-align: center; - } - + } ._Separador { background-color: #fff; @@ -133,14 +111,6 @@ width: 4px; } - .celda_normal { - /*background-color: #fff;*/ - /* */ - text-align: center; - border: 1px solid #ccc; - padding: 2px 4px; - } - /*style excel*/ .excel_cell { border: 1px solid #CCC; @@ -167,37 +137,82 @@ height: 20px; } - #bagStockDetailsTableId th:nth-child(1), - #bagStockDetailsTableId td:nth-child(1) { - position: sticky; - left: 0; + + + .celda_encabezado_general { background-color: #00a65a; - z-index: 2; - border-right: 2px solid #ddd; + border: 1px solid #ccc; color: #ffffff; + font-weight: bold; + padding: 6px 10px; + text-align: center; } + .celda_encabezado_total { + background-color:#ffffff !important; + border: 1px solid #ffffff; + color: #ffffff !important; + font-weight: bold; + padding: 6px 10px; + text-align: center; + } + .celda_normal { + /*background-color: #fff;*/ + /* */ + text-align: center; + border: 1px solid #ccc; + padding: 10px 6px; + } - #bagStockDetailsTableSummaryId th:nth-child(1), - #bagStockDetailsTableSummaryId td:nth-child(1) { + + /* Make entire thead sticky */ + .fht-table thead { + position: sticky; + top: 0; + z-index: 20; /* Ensure the entire header stays above table rows */ + background-color: #00a65a; /* Header background color */ + } + + .dropdown-menu { + z-index :25 ; + } + + + + /* Ensure each in thead stays sticky */ + .fht-table thead th { + position: sticky; + top: 0; + z-index: 11; /* Higher than table rows but lower than first column */ + background-color: #00a65a; /* Green background */ + color: #ffffff; + border: 1px solid #ddd; + padding: 10px; + } + + /* Sticky First Column */ + .fht-table th:nth-child(1), + .fht-table td:nth-child(1) { position: sticky; left: 0; background-color: #00a65a; - z-index: 2; + z-index: 15; /* Ensures it stays above other cells */ border-right: 2px solid #ddd; color: #ffffff; } - - + /* Table Wrapper for Scrolling */ .table-responsive { - overflow-y: auto; + overflow-x: auto; + overflow-y: auto; + max-height: 450px; /* Adjust as needed */ + position: relative; } - .fht-table thead th { - top: 0; - z-index: 5!important; + td{ + min-width: 100px; + max-width: 100px; } @@ -395,7 +410,7 @@ contenteditable="true" - > + > - + - + - + @@ -461,7 +476,7 @@ Receipt Used Balance Stock - + @@ -540,20 +555,20 @@ contenteditable="true" - > + > - + contenteditable="true"> - + oninput="usedStockChange(this)" contenteditable="true"> + > @@ -812,7 +827,7 @@ 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 == 0 ? " " : currentBalanceStock; updateStockValue( date,materialCode,currentBalanceStock ) @@ -839,7 +854,7 @@ 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 = ccurrentBalanceStock == 0 ? " " : currentBalanceStock ; updateStockValue( date,materialCode,currentBalanceStock ) @@ -869,7 +884,7 @@ 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 == 0 ? " " : currentBalanceStock ; updateStockValue( date,materialCode,currentBalanceStock ) @@ -901,7 +916,7 @@ let dataId = `${otherDate} ${materialCode}`; - document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText=currentBalanceStock; + document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText = currentBalanceStock == 0 ? " " : currentBalanceStock; let usedStock = validateInput(document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText); @@ -909,10 +924,8 @@ 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 == 0 ? " " : currentBalanceStock; - // console.log( 'other date' , new Date(otherDate)); - // console.log('new balance stock' , currentBalanceStock) } }) diff --git a/app/Views/dieselStockDetails.php b/app/Views/dieselStockDetails.php index 9632fba0..d04ba620 100644 --- a/app/Views/dieselStockDetails.php +++ b/app/Views/dieselStockDetails.php @@ -100,25 +100,6 @@ } - .celda_encabezado_general { - background-color: #00a65a; - border: 1px solid #ccc; - color: #ffffff; - font-weight: bold; - padding: 6px 10px; - text-align: center; - } - - .celda_encabezado_total { - background-color:#ffffff !important; - border: 1px solid #ffffff; - color: #ffffff !important; - font-weight: bold; - padding: 6px 10px; - text-align: center; - } - - ._Separador { background-color: #fff; height: 12px; @@ -131,13 +112,7 @@ width: 4px; } - .celda_normal { - /*background-color: #fff;*/ - /* */ - text-align: center; - border: 1px solid #ccc; - padding: 10px 6px; - } + /*style excel*/ .excel_cell { @@ -166,54 +141,81 @@ } -/* Make entire thead sticky */ -.fht-table thead { - position: sticky; - top: 0; - z-index: 20; /* Ensure the entire header stays above table rows */ - background-color: #00a65a; /* Header background color */ -} + .celda_encabezado_general { + background-color: #00a65a; + border: 1px solid #ccc; + color: #ffffff; + font-weight: bold; + padding: 6px 10px; + text-align: center; + } -.dropdown-menu { - z-index :25 ; -} + .celda_encabezado_total { + background-color:#ffffff !important; + border: 1px solid #ffffff; + color: #ffffff !important; + font-weight: bold; + padding: 6px 10px; + text-align: center; + } + + .celda_normal { + /*background-color: #fff;*/ + /* */ + text-align: center; + border: 1px solid #ccc; + padding: 10px 6px; + } + + + /* Make entire thead sticky */ + .fht-table thead { + position: sticky; + top: 0; + z-index: 20; /* Ensure the entire header stays above table rows */ + background-color: #00a65a; /* Header background color */ + } + + .dropdown-menu { + z-index :25 ; + } -/* Ensure each in thead stays sticky */ -.fht-table thead th { - position: sticky; - top: 0; - z-index: 11; /* Higher than table rows but lower than first column */ - background-color: #00a65a; /* Green background */ - color: #ffffff; - border: 1px solid #ddd; - padding: 10px; -} + /* Ensure each in thead stays sticky */ + .fht-table thead th { + position: sticky; + top: 0; + z-index: 11; /* Higher than table rows but lower than first column */ + background-color: #00a65a; /* Green background */ + color: #ffffff; + border: 1px solid #ddd; + padding: 10px; + } -/* Sticky First Column */ -.fht-table th:nth-child(1), -.fht-table td:nth-child(1) { - position: sticky; - left: 0; - background-color: #00a65a; - z-index: 15; /* Ensures it stays above other cells */ - border-right: 2px solid #ddd; - color: #ffffff; -} + /* Sticky First Column */ + .fht-table th:nth-child(1), + .fht-table td:nth-child(1) { + position: sticky; + left: 0; + background-color: #00a65a; + z-index: 15; /* Ensures it stays above other cells */ + border-right: 2px solid #ddd; + color: #ffffff; + } -/* Table Wrapper for Scrolling */ -.table-responsive { - overflow-x: auto; - overflow-y: auto; - max-height: 450px; /* Adjust as needed */ - position: relative; -} + /* Table Wrapper for Scrolling */ + .table-responsive { + overflow-x: auto; + overflow-y: auto; + max-height: 450px; /* Adjust as needed */ + position: relative; + } -td{ - min-width: 100px; - max-width: 100px; -} + td{ + min-width: 100px; + max-width: 100px; + } diff --git a/app/Views/drierMachineDetails.php b/app/Views/drierMachineDetails.php index eccfebc6..f555dd8b 100644 --- a/app/Views/drierMachineDetails.php +++ b/app/Views/drierMachineDetails.php @@ -885,6 +885,7 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); $('#loader').hide(); alert(data); + window.location.reload(); } diff --git a/app/Views/dustAndRoughStockDetails.php b/app/Views/dustAndRoughStockDetails.php index 395ac55e..9fbd1d66 100644 --- a/app/Views/dustAndRoughStockDetails.php +++ b/app/Views/dustAndRoughStockDetails.php @@ -98,17 +98,7 @@ padding-top: 8px; width: 100%; } - - - .celda_encabezado_general { - background-color: #00a65a; - border: 1px solid #ccc; - color: #ffffff; - font-weight: bold; - padding: 6px 10px;; - text-align: center; - } - + ._Separador { background-color: #fff; @@ -122,13 +112,7 @@ width: 4px; } - .celda_normal { - /*background-color: #fff;*/ - /* */ - text-align: center; - border: 1px solid #ccc; - padding: 2px 4px; - } + /*style excel*/ .excel_cell { @@ -156,18 +140,11 @@ height: 20px; } - #dustAndRoughStockDetailsTableId th:nth-child(1), - #dustAndRoughStockDetailsTableId td:nth-child(1) { - position: sticky; - left: 0; - background-color: #00a65a; - z-index: 2; - border-right: 2px solid #ddd; - color: #ffffff; - } + - .celda_encabezado_total { - background-color:#ffffff; + + .celda_encabezado_general { + background-color: #00a65a; border: 1px solid #ccc; color: #ffffff; font-weight: bold; @@ -175,9 +152,79 @@ text-align: center; } - .modal { - padding-right: 30% ! important; + .celda_encabezado_total { + background-color:#ffffff !important; + border: 1px solid #ffffff; + color: #ffffff !important; + font-weight: bold; + padding: 6px 10px; + text-align: center; } + + .celda_normal { + /*background-color: #fff;*/ + /* */ + text-align: center; + border: 1px solid #ccc; + padding: 10px 6px; + } + + + /* Make entire thead sticky */ + .fht-table thead { + position: sticky; + top: 0; + z-index: 20; /* Ensure the entire header stays above table rows */ + background-color: #00a65a; /* Header background color */ + } + + .dropdown-menu { + z-index :25 ; + } + + + + /* Ensure each in thead stays sticky */ + .fht-table thead th { + position: sticky; + top: 0; + z-index: 11; /* Higher than table rows but lower than first column */ + background-color: #00a65a; /* Green background */ + color: #ffffff; + border: 1px solid #ddd; + padding: 10px; + } + + /* Sticky First Column */ + .fht-table th:nth-child(1), + .fht-table td:nth-child(1) { + position: sticky; + left: 0; + background-color: #00a65a; + z-index: 15; /* Ensures it stays above other cells */ + border-right: 2px solid #ddd; + color: #ffffff; + } + + /* Table Wrapper for Scrolling */ + .table-responsive { + overflow-x: auto; + overflow-y: auto; + max-height: 450px; /* Adjust as needed */ + position: relative; + } + + td{ + min-width: 150px; + max-width: 150px; + } + + + + + + +
@@ -223,6 +270,18 @@
+
+
+ +
@@ -277,17 +336,17 @@ data-id="" oninput="finalRoughStockChange(this)" contenteditable="true" - > + > + > + >
@@ -308,7 +367,7 @@ $summary['finalRough'] += $dustAndRoughStockDetail['finalRough'] == "-" ? 0 : (float) $dustAndRoughStockDetail['finalRough'] ; $summary['dust'] += $dustAndRoughStockDetail['dust'] == "-" ? 0 : (float) $dustAndRoughStockDetail['dust'] ; - $summary['total'] += $dustAndRoughStockDetail['total'] == "-" ? 0 :(float) $dustAndRoughStockDetail['total'] ; + $summary['total'] += $dustAndRoughStockDetail['total'] == "-" ? 0 : (float) $dustAndRoughStockDetail['total'] ; } ?> @@ -377,17 +436,17 @@ data-id="" oninput="finalRoughStockChange(this)" contenteditable="true" - > + > + > + > 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 9a2da2d6..71e07a48 100644 --- a/app/Views/resinStockDetails.php +++ b/app/Views/resinStockDetails.php @@ -100,26 +100,6 @@ } - .celda_encabezado_general { - background-color: #00a65a; - border: 1px solid #ccc; - color: #ffffff; - font-weight: bold; - padding: 6px 10px; - ; - text-align: center; - } - - .celda_encabezado_total { - background-color:#ffffff; - border: 1px solid #ccc; - color: #ffffff; - font-weight: bold; - padding: 6px 10px; - ; - text-align: center; - } - ._Separador { background-color: #fff; @@ -133,14 +113,6 @@ width: 4px; } - .celda_normal { - /*background-color: #fff;*/ - /* */ - text-align: center; - border: 1px solid #ccc; - padding: 2px 4px; - } - /*style excel*/ .excel_cell { border: 1px solid #CCC; @@ -167,36 +139,81 @@ height: 20px; } - #resinStockDetailsTableId th:nth-child(1), - #resinStockDetailsTableId td:nth-child(1) { - position: sticky; - left: 0; + + .celda_encabezado_general { background-color: #00a65a; - z-index: 2; - border-right: 2px solid #ddd; + border: 1px solid #ccc; color: #ffffff; + font-weight: bold; + padding: 6px 10px; + text-align: center; } - + .celda_encabezado_total { + background-color:#ffffff !important; + border: 1px solid #ffffff; + color: #ffffff !important; + font-weight: bold; + padding: 6px 10px; + text-align: center; + } + + .celda_normal { + /*background-color: #fff;*/ + /* */ + text-align: center; + border: 1px solid #ccc; + padding: 10px 6px; + } - #resinStockDetailsTableSummaryId th:nth-child(1), - #resinStockDetailsTableSummaryId td:nth-child(1) { + + /* Make entire thead sticky */ + .fht-table thead { position: sticky; - left: 0; - background-color: #00a65a; - z-index: 2; - border-right: 2px solid #ddd; - color: #ffffff; + top: 0; + z-index: 20; /* Ensure the entire header stays above table rows */ + background-color: #00a65a; /* Header background color */ } - .table-responsive { - overflow-y: auto; + .dropdown-menu { + z-index :25 ; } + + + /* Ensure each in thead stays sticky */ .fht-table thead th { position: sticky; top: 0; - z-index: 5!important; + z-index: 11; /* Higher than table rows but lower than first column */ + background-color: #00a65a; /* Green background */ + color: #ffffff; + border: 1px solid #ddd; + padding: 10px; + } + + /* Sticky First Column */ + .fht-table th:nth-child(1), + .fht-table td:nth-child(1) { + position: sticky; + left: 0; + background-color: #00a65a; + z-index: 15; /* Ensures it stays above other cells */ + border-right: 2px solid #ddd; + color: #ffffff; + } + + /* Table Wrapper for Scrolling */ + .table-responsive { + overflow-x: auto; + overflow-y: auto; + max-height: 450px; /* Adjust as needed */ + position: relative; + } + + td{ + min-width: 100px; + max-width: 100px; } @@ -365,13 +382,14 @@ foreach ($period as $day) { + class="materialCode"> + - + oninput="openingStockChange(this)" contenteditable="true" - > + > - + + contenteditable="true"> - + @@ -421,10 +439,10 @@ foreach ($period as $day) { // Sum values for the material ; - $summary[$materialCode]['opening'] = "-" ; - $summary[$materialCode]['receipt'] += $resinStock['receipt'] == '-' ? 0 :$resinStock['receipt'] ; - $summary[$materialCode]['used'] += $resinStock['used'] == '-' ? 0 :$resinStock['used'] ; - $summary[$materialCode]['balanceStock'] = $resinStock['balanceStock'] == '-' ? 0 :$resinStock['balanceStock'] ; + $summary[$materialCode]['opening'] = "-" ; + $summary[$materialCode]['receipt'] += is_numeric($resinStock['receipt']) ? $resinStock['receipt'] : 0; + $summary[$materialCode]['used'] += is_numeric($resinStock['used']) ? $resinStock['used'] : 0; + $summary[$materialCode]['balanceStock'] = is_numeric($resinStock['balanceStock']) ? $resinStock['balanceStock'] : 0; } ?> @@ -522,20 +540,20 @@ foreach ($period as $day) { oninput="openingStockChange(this)" contenteditable="true" - > + > - + contenteditable="true"> - + contenteditable="true"> + data-id=" "> @@ -816,9 +834,9 @@ foreach ($period as $day) { 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; @@ -876,7 +894,7 @@ foreach ($period as $day) { let dataId = `${otherDate} ${materialCode}`; - document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText = currentBalanceStock; + document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText = currentBalanceStock == 0 ? " " : currentBalanceStock; let usedStock = validateInput(document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText); @@ -884,8 +902,7 @@ foreach ($period as $day) { 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 == 0 ? " " : currentBalanceStock; } }) diff --git a/app/Views/trpSandUseStockDetails.php b/app/Views/trpSandUseStockDetails.php index f80b7894..7f60fcc4 100644 --- a/app/Views/trpSandUseStockDetails.php +++ b/app/Views/trpSandUseStockDetails.php @@ -98,16 +98,6 @@ padding-top: 8px; width: 100%; } - - - .celda_encabezado_general { - background-color: #00a65a; - border: 1px solid #ccc; - color: #ffffff; - font-weight: bold; - padding: 6px 10px;; - text-align: center; - } ._Separador { @@ -122,13 +112,7 @@ width: 4px; } - .celda_normal { - /*background-color: #fff;*/ - /* */ - text-align: center; - border: 1px solid #ccc; - padding: 2px 4px; - } + /*style excel*/ .excel_cell { @@ -156,18 +140,10 @@ height: 20px; } - #trpSandUseStockDetailsTableId th:nth-child(1), - #trpSandUseStockDetailsTableId td:nth-child(1) { - position: sticky; - left: 0; - background-color: #00a65a; - z-index: 2; - border-right: 2px solid #ddd; - color: #ffffff; - } - .celda_encabezado_total { - background-color:#ffffff; + + .celda_encabezado_general { + background-color: #00a65a; border: 1px solid #ccc; color: #ffffff; font-weight: bold; @@ -175,9 +151,77 @@ text-align: center; } - .modal { - padding-right: 30% ! important; + .celda_encabezado_total { + background-color:#ffffff !important; + border: 1px solid #ffffff; + color: #ffffff !important; + font-weight: bold; + padding: 6px 10px; + text-align: center; } + + .celda_normal { + /*background-color: #fff;*/ + /* */ + text-align: center; + border: 1px solid #ccc; + padding: 10px 6px; + } + + + /* Make entire thead sticky */ + .fht-table thead { + position: sticky; + top: 0; + z-index: 20; /* Ensure the entire header stays above table rows */ + background-color: #00a65a; /* Header background color */ + } + + .dropdown-menu { + z-index :25 ; + } + + + + /* Ensure each in thead stays sticky */ + .fht-table thead th { + position: sticky; + top: 0; + z-index: 11; /* Higher than table rows but lower than first column */ + background-color: #00a65a; /* Green background */ + color: #ffffff; + border: 1px solid #ddd; + padding: 10px; + } + + /* Sticky First Column */ + .fht-table th:nth-child(1), + .fht-table td:nth-child(1) { + position: sticky; + left: 0; + background-color: #00a65a; + z-index: 15; /* Ensures it stays above other cells */ + border-right: 2px solid #ddd; + color: #ffffff; + } + + /* Table Wrapper for Scrolling */ + .table-responsive { + overflow-x: auto; + overflow-y: auto; + max-height: 450px; /* Adjust as needed */ + position: relative; + } + + td{ + min-width: 150px; + max-width: 150px; + } + + + + + @@ -234,7 +278,7 @@
- + @@ -281,26 +325,26 @@ data-id="" oninput="roughStockChange(this)" contenteditable="true" - > + > + > + > + > + > @@ -318,17 +362,18 @@ $summary['rough_kgs'] += $trpSandUseStockDetail['rough_kgs'] == "-" ? 0 : (float) $trpSandUseStockDetail['rough_kgs'] ; $summary['fine_kgs'] += $trpSandUseStockDetail['fine_kgs'] == "-" ? 0 : (float) $trpSandUseStockDetail['fine_kgs'] ; $summary['total_kgs'] += $trpSandUseStockDetail['total_kgs'] == "-" ? 0 :(float) $trpSandUseStockDetail['total_kgs'] ; - } ?> + + } ?>
Trp Sand To Use Coating Sand
- - - - + + + + @@ -394,31 +439,31 @@ data-id="" oninput="roughStockChange(this)" contenteditable="true" - > + > + > + > + > + > 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; + + } + + + + From 0307cc14114b52f5e745097d0a24683a2d807e61 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Sat, 25 Jan 2025 10:37:46 +0530 Subject: [PATCH 2/7] stock module latest today vadivel J 25-01-2025 --- app/Views/drierMachineDetails.php | 102 ++++++++++++++++++------------ 1 file changed, 60 insertions(+), 42 deletions(-) diff --git a/app/Views/drierMachineDetails.php b/app/Views/drierMachineDetails.php index f555dd8b..2f4739d1 100644 --- a/app/Views/drierMachineDetails.php +++ b/app/Views/drierMachineDetails.php @@ -187,57 +187,75 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); - #drierTable th:nth-child(1), - #drierTable td:nth-child(1) { - position: sticky; - left: 0; - background-color: #00a65a; - z-index: 2; - border-right: 2px solid #ddd; - color: #ffffff; -} - - - #drierTableSummaryId td:nth-child(1) { - position: sticky; - left: 0; - background-color: #ffffff; - z-index: 2; - border-right: 2px solid #ddd; - color: #ffffff; - } - - .fht-table th:nth-child(1) - { - position: sticky; - left: 0; - top: 0; - background-color: #00a65a; - z-index: 7!important; - border-right: 2px solid #ddd; - color: #ffffff; - } - - - .fht-table td:nth-child(1) - { - position: sticky; - left: 0; + .celda_encabezado_general { background-color: #00a65a; - z-index: 2; - border-right: 2px solid #ddd; + border: 1px solid #ccc; color: #ffffff; + font-weight: bold; + padding: 6px 10px; + text-align: center; } - .table-responsive { - overflow-y: auto; - max-height: 450px; + .celda_encabezado_total { + background-color:#ffffff !important; + border: 1px solid #ffffff; + color: #ffffff !important; + font-weight: bold; + padding: 6px 10px; + text-align: center; + } + + .celda_normal { + /*background-color: #fff;*/ + /* */ + text-align: center; + border: 1px solid #ccc; + padding: 10px 6px; } + + /* Make entire thead sticky */ + .fht-table thead { + position: sticky; + top: 0; + z-index: 20; /* Ensure the entire header stays above table rows */ + background-color: #00a65a; /* Header background color */ + } + + .dropdown-menu { + z-index :25 ; + } + + + + /* Ensure each - -
Total Rough Kgs Fine Kgs Total Kgs Total Rough Kgs Fine Kgs Total Kgs
in thead stays sticky */ .fht-table thead th { position: sticky; top: 0; - z-index: 5!important; + z-index: 11; /* Higher than table rows but lower than first column */ + background-color: #00a65a; /* Green background */ + color: #ffffff; + border: 1px solid #ddd; + padding: 10px; + } + + /* Sticky First Column */ + .fht-table th:nth-child(1), + .fht-table td:nth-child(1) { + position: sticky; + left: 0; + background-color: #00a65a; + z-index: 15; /* Ensures it stays above other cells */ + border-right: 2px solid #ddd; + color: #ffffff; + } + + /* Table Wrapper for Scrolling */ + .table-responsive { + overflow-x: auto; + overflow-y: auto; + max-height: 450px; /* Adjust as needed */ + position: relative; } From 830db88b7be903d426d261ed9275212911be70c7 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Sat, 25 Jan 2025 17:26:48 +0530 Subject: [PATCH 3/7] stock module latest today vadivel J 25-01-2025 --- app/Config/Routes.php | 7 - app/Controllers/StockController.php | 486 +++--- app/Models/PowerConsumptionSummaryModel.Php | 30 + app/Views/powerConsumptionDetails.php | 1619 ++++++++++++++----- 4 files changed, 1413 insertions(+), 729 deletions(-) create mode 100644 app/Models/PowerConsumptionSummaryModel.Php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 7b075eb5..94478251 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -463,16 +463,9 @@ $routes->post('updateDieselMachineDetails' , 'StockController::updateDieselMachi //power consumption details $routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'powerConsumptionDetails', 'StockController::powerConsumptionDetails'); -$routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'addOrEditPowerConsumptionDetails', 'StockController::addOrEditPowerConsumptionDetails'); - - -//new power consumption details -$routes->match(['GET','POST'] , 'newPowerConsumptionDetails' , 'StockController::newPowerConsumptionDetails'); $routes->post('updatePowerConsumptionDetails','StockController::updatePowerConsumptionDetails'); - - //incoming Silica Sand Detaails $routes->match(['GET', 'POST'], 'incomingSilicaSandDetails', 'StockController::loadView_incomingSilicaSandDetails'); $routes->post('updateIncomingSilicaSandDetails', 'StockController::updateIncomingSilicaSandDetails'); diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index 456ce71b..ed5e3c56 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -22,6 +22,7 @@ use App\Models\TrpProductionModel; use App\Models\TrpProductionMaintenanceModel; use App\Models\TrpProductionWasteModel; use App\Models\Employeedetails_model; +use App\Models\PowerConsumptionSummaryModel; @@ -36,6 +37,7 @@ class StockController extends BaseController protected $supplier_model; protected $powerConsumptionDetails_model; + protected $powerConsumptionSummary_model; protected $coatingMachineDetails_model; protected $drierMachineDetails_model; protected $factoryMachine_model; @@ -109,6 +111,8 @@ class StockController extends BaseController $this->employeedetails_model = new Employeedetails_model(); + $this->powerConsumptionSummary_model = new PowerConsumptionSummaryModel(); + $this->session = session(); helper('form'); @@ -1702,12 +1706,6 @@ class StockController extends BaseController return $times; } - - - - - - public function drierMachineDetails() { @@ -1892,131 +1890,224 @@ class StockController extends BaseController return $dateInput; } + public function powerConsumptionDetails(){ - - + + if ($this->request->getMethod() === 'POST') { - public function powerConsumptionDetails() - { - $currentMonth = $this->request->getPost('month') ? $this->request->getPost('month') : date('M-Y'); + $month = $this->request->getPost('month'); - $monthData = $this->getMonthDatesFromInput($currentMonth); + $date = DateTime::createFromFormat('M-Y', $month); - $data['startDate'] = $monthData[0]['database']; - $data['endDate'] = $monthData[count($monthData) - 1]['database']; - $data['datefordropdown'] = $currentMonth; + $formattedDate = $date->format('Y-m'); - //Machine Details - $data['machineDetails'] = $this->factoryMachine_model->where('energy_type', 'electric')->where('is_active', 1)->findAll(); - if (!count([$data['machineDetails']])) { - return $this->response->setBody(""); + $month = $formattedDate; + } else { + + // $month = '2024-12'; + + $month = date('Y-m'); } + $data = []; + + $data['month'] = $month; + + $this->global['pageTitle'] = 'Power Consumption Stock Details'; - //Diesel Consumption Details - $data['powerConsumptionDetails'] = $this->getElectricConsumptionPivot($data['machineDetails'], $data['startDate'], $data['endDate']); - if (!count($data['powerConsumptionDetails'])) { - //insert empty data - $tempInsert = []; - foreach ($monthData as $key => $value) { - array_push($tempInsert, ['date' => $value['database'], 'machine_id' => $data['machineDetails'][0]['id']]); + // Get the previous month's last date power consumption stock details for next month updation + + $previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m'); + $previousMonthStartDate = "$previousMonth-01"; + $previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate)); + + $data['previousMonthPowerConsumptionStockDetails'] = $this->powerConsumptionDetails_model + ->select(['machine_id', 'date', 'closing_units']) + ->distinct() + ->where('date =', $previousMonthEndDate) + ->groupBy(['machine_id', 'date']) + ->orderBy('date', 'desc') + ->orderBy('machine_id', 'asc') + ->findAll(); + + $data['previousMonthTotalPowerMachineStockDetails'] = $this->powerConsumptionSummary_model + ->select(['id', 'date', 'final_reading']) + ->distinct() + ->where('date =', $previousMonthEndDate) + ->groupBy(['id', 'date']) + ->orderBy('date', 'desc') + ->findAll(); + + + + // checking in database if the data is available for the month + + $startDate = "$month-01"; + $endDate = date("Y-m-t", strtotime($startDate)); + + $data['powerConsumptionStockDetails'] = $this->powerConsumptionDetails_model + ->where('date >=', $startDate) + ->where('date <=', $endDate) + ->groupBy(['machine_id', 'date']) + ->orderBy('date', 'asc') + ->orderBy('machine_id', 'asc') + ->findAll(); + + $data['totalPower'] = $this->powerConsumptionSummary_model + ->where('date >=', $startDate) + ->where('date <=', $endDate) + ->orderBy('date', 'asc') + ->findAll(); + + // Initialize an empty array to hold the grouped data + $data['groupedPowerConsumptionStockDetails'] = []; + + // Temporary array to store grouped data by date + $groupedByDate = []; + + // Group by 'date' + foreach ($data['powerConsumptionStockDetails'] as $detail) { + $date = $detail['date']; + + // Initialize the outer array for this date if it doesn't exist + if (!isset($groupedByDate[$date])) { + $groupedByDate[$date] = []; } - $this->powerConsumptionDetails_model->insertBatch($tempInsert); - $data['powerConsumptionDetails'] = $this->getElectricConsumptionPivot($data['machineDetails'], $data['startDate'], $data['endDate']); + /******************************************************************************************************************* + creating an sub array (inner array) for date wise and append the detail into an array as sub-array + + $groupedByDate[] outer array + + $groupedByDate[$date] + will look like [[material1],[material2],[material3],[material4],[material5]] inner array + + the above process is done for single row (date wise) and the same process is repeated for all the rows + *******************************************************************************************************************/ + + $groupedByDate[$date][] = $detail; + } + + // Reset the structure to have indexed arrays without the date keys + $data['groupedPowerConsumptionStockDetails'] = array_values($groupedByDate); + + + // getting electric machines for creating table headers + // checking already existing stock if yes then get the electric machines id from the existing stock + // if not get all the electric machines from the factory Machine master table + + if (!empty($data['groupedPowerConsumptionStockDetails'])) { + + $result = $groupedByDate[$date]; + + $distinctMachineId = []; + + foreach ($result as $index => $eachResult) { + $distinctMachineId[] = $result[$index]['machine_id']; + } + + $electricMachines = $this->factoryMachine_model + ->whereIn('id', $distinctMachineId) + ->orderBy('id', 'asc') + ->get() + ->getResultArray(); + + + } else { + + $electricMachines = $this->factoryMachine_model + ->where('is_active', 1) + ->where('energy_type', 'Diesel') + ->orderBy('id', 'asc') + ->get() + ->getResultArray(); + } + $electricMachinesCount = count($electricMachines); - $data['machineName'] = array_column($data['machineDetails'], 'machine_name'); + $data['electricMachinesCount'] = $electricMachinesCount; + $data['electricMachines'] = $electricMachines; + + $date = DateTime::createFromFormat('Y-m', $month); + + $formattedDate = $date->format('M-Y'); + + $data['month'] = $formattedDate; + + // return $this->response->setJSON(['status' =>'success' ,'message' => $data['electricMachines']]); + + return $this->loadViews("powerConsumptionDetails", $this->global, $data, NULL); - $this->global['pageTitle'] = 'Power Consumption Details'; - $this->loadViews("powerConsumptionDetails", $this->global, $data, NULL); } - public function getElectricConsumptionPivot($machineDetails, $startDate, $endDeate) - { - $machineIds = array_column($machineDetails, 'id'); + public function updatePowerConsumptionDetails(){ + + + $postData = $this->request->getPost(); - if (empty($machineIds)) { - return []; - } + $updatePowerConsumptionDetailsData = json_decode($postData['updatePowerConsumptionDetails'], true); - $fields = ['opening_units', 'closing_units', 'total_units']; + $updates = []; - $pivotColumns = []; - foreach ($machineIds as $machineId) { - foreach ($fields as $field) { - $pivotColumns[] = "MAX(CASE WHEN machine_id = $machineId THEN $field ELSE 0 END) AS {$field}_{$machineId}"; - } - } + $inserts = []; - $pivotColumnString = implode(", ", $pivotColumns); + foreach ($updatePowerConsumptionDetailsData as $data) { - $sql = "SELECT `date`, $pivotColumnString FROM `t_powerConsumptionDetails` - WHERE machine_id IN (" . implode(",", $machineIds) . ") AND `date` >= ? AND `date` <= ? - GROUP BY `date`"; - - $query = $this->db->query($sql, [$startDate, $endDeate]); - $result = $query->getResultArray(); - - return $result; - } - - public function addOrEditPowerConsumptionDetails() - { - $electricMachineTableData = json_decode($this->request->getPost('electricMachineTableData'), true); - - $transformedData = []; - foreach ($electricMachineTableData as $entry) { - $date = $entry['date']; - - foreach ($entry as $key => $value) { - - if ($key === 'date') { - continue; - } - - preg_match('/(.*?)_(\d+)$/', $key, $matches); - - if (count($matches) === 3) { - $field = $matches[1]; - $machineId = $matches[2]; - - $insertKey = "{$date}_{$machineId}"; - if (!isset($transformedData[$insertKey])) { - $transformedData[$insertKey] = [ - 'date' => DateTime::createFromFormat('d-m-Y', $date)->format('Y-m-d'), - 'machine_id' => $machineId, - 'opening_units' => 0.00, - 'closing_units' => 0.00, - 'total_units' => 0.00 - ]; - } - - $transformedData[$insertKey][$field] = (float) $value; - } - } - } + $date = $data['date']; + $machineId = $data['machine_id']; - foreach ($transformedData as $row) { + $dbData = [ + 'date' => $data['date'], + 'machine_id' => $data['machine_id'], + 'opening_units' => $data['opening'], + 'closing_units' => $data['receipt'], + 'total_units' => $data['used'] + ]; - $existingRow = $this->powerConsumptionDetails_model->where('date', $row['date'])->where('machine_id', $row['machine_id'])->first(); - if ($existingRow) { - $this->powerConsumptionDetails_model->update($existingRow['id'], $row); + $resultExists = $this->factoryVehicleDieselDetails_model + ->where('date', $date) + ->where('machine_id', $machineId) + ->first(); + + + if (empty($resultExists)) { + $inserts[] = $dbData; } else { - $this->powerConsumptionDetails_model->insert($row); + $dbData['id'] = $resultExists['id']; + $updates[] = $dbData; } } - echo "Data successfully saved."; + if (!empty($inserts)) { + $this->factoryVehicleDieselDetails_model->insertBatch($inserts); + } + + if (!empty($updates)) { + + $updateResult = $this->factoryVehicleDieselDetails_model->updateBatch($updates, 'id'); + + if ($updateResult === FALSE) { + echo "Error during update"; + } else { + echo "Data Updated Successfully"; + return; + } + } + + echo "Data Saved Successfully"; + + + } + public function dieselMachineStockDetails(){ @@ -2290,208 +2381,7 @@ class StockController extends BaseController } } - public function newPowerConsumptionDetails(){ - - - if ($this->request->getMethod() === 'POST') { - - $month = $this->request->getPost('month'); - - $date = DateTime::createFromFormat('M-Y', $month); - - $formattedDate = $date->format('Y-m'); - - $month = $formattedDate; - } else { - - // $month = '2024-12'; - - $month = date('Y-m'); - } - - $data = []; - - $data['month'] = $month; - - $this->global['pageTitle'] = 'Power Consumption Stock Details'; - - - // Get the previous month's last date power consumption stock details for next month updation - - $previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m'); - $previousMonthStartDate = "$previousMonth-01"; - $previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate)); - - $data['previousMonthPowerConsumptionStockDetails'] = $this->powerConsumptionDetails_model - ->select(['machine_id', 'date', 'closing_units']) - ->distinct() - ->where('date =', $previousMonthEndDate) - ->groupBy(['machine_id', 'date']) - ->orderBy('date', 'desc') - ->orderBy('machine_id', 'asc') - ->findAll(); - - - - // checking in database if the data is available for the month - - $startDate = "$month-01"; - $endDate = date("Y-m-t", strtotime($startDate)); - - $data['powerConsumptionStockDetails'] = $this->powerConsumptionDetails_model - ->where('date >=', $startDate) - ->where('date <=', $endDate) - ->groupBy(['machine_id', 'date']) - ->orderBy('date', 'asc') - ->orderBy('machine_id', 'asc') - ->findAll(); - - // Initialize an empty array to hold the grouped data - $data['groupedPowerConsumptionStockDetails'] = []; - - // Temporary array to store grouped data by date - $groupedByDate = []; - - // Group by 'date' - foreach ($data['powerConsumptionStockDetails'] as $detail) { - $date = $detail['date']; - - // Initialize the outer array for this date if it doesn't exist - if (!isset($groupedByDate[$date])) { - $groupedByDate[$date] = []; - } - - /******************************************************************************************************************* - creating an sub array (inner array) for date wise and append the detail into an array as sub-array - - $groupedByDate[] outer array - - $groupedByDate[$date] - will look like [[material1],[material2],[material3],[material4],[material5]] inner array - - the above process is done for single row (date wise) and the same process is repeated for all the rows - *******************************************************************************************************************/ - - $groupedByDate[$date][] = $detail; - } - - // Reset the structure to have indexed arrays without the date keys - $data['groupedPowerConsumptionStockDetails'] = array_values($groupedByDate); - - - // getting electric machines for creating table headers - // checking already existing stock if yes then get the electric machines id from the existing stock - // if not get all the electric machines from the factory Machine master table - - if (!empty($data['groupedPowerConsumptionStockDetails'])) { - - $result = $groupedByDate[$date]; - - $distinctMachineId = []; - - foreach ($result as $index => $eachResult) { - $distinctMachineId[] = $result[$index]['machine_id']; - } - - $electricMachines = $this->factoryMachine_model - ->whereIn('id', $distinctMachineId) - ->orderBy('id', 'asc') - ->get() - ->getResultArray(); - - - } else { - - $electricMachines = $this->factoryMachine_model - ->where('is_active', 1) - ->where('energy_type', 'Diesel') - ->orderBy('id', 'asc') - ->get() - ->getResultArray(); - - } - - - - $electricMachinesCount = count($electricMachines); - - $data['electricMachinesCount'] = $electricMachinesCount; - $data['electricMachines'] = $electricMachines; - - $date = DateTime::createFromFormat('Y-m', $month); - - $formattedDate = $date->format('M-Y'); - - $data['month'] = $formattedDate; - - return $this->response->setJSON(['status' =>'success' ,'message' => $data['electricMachines']]); - - // return $this->loadViews("powerConsumptionStockDetails", $this->global, $data, NULL); - - } - - public function updatePowerConsumptionDetails(){ - - - $postData = $this->request->getPost(); - - $updatePowerConsumptionDetailsData = json_decode($postData['updatePowerConsumptionDetails'], true); - - $updates = []; - - $inserts = []; - - foreach ($updatePowerConsumptionDetailsData as $data) { - - $date = $data['date']; - $machineId = $data['machine_id']; - - - $dbData = [ - 'date' => $data['date'], - 'machine_id' => $data['machine_id'], - 'opening_units' => $data['opening'], - 'closing_units' => $data['receipt'], - 'total_units' => $data['used'] - ]; - - $resultExists = $this->factoryVehicleDieselDetails_model - ->where('date', $date) - ->where('machine_id', $machineId) - ->first(); - - - if (empty($resultExists)) { - $inserts[] = $dbData; - } else { - $dbData['id'] = $resultExists['id']; - $updates[] = $dbData; - } - } - - - if (!empty($inserts)) { - $this->factoryVehicleDieselDetails_model->insertBatch($inserts); - } - - if (!empty($updates)) { - - $updateResult = $this->factoryVehicleDieselDetails_model->updateBatch($updates, 'id'); - - if ($updateResult === FALSE) { - echo "Error during update"; - } else { - echo "Data Updated Successfully"; - return; - } - } - - echo "Data Saved Successfully"; - - - - } - + diff --git a/app/Models/PowerConsumptionSummaryModel.Php b/app/Models/PowerConsumptionSummaryModel.Php new file mode 100644 index 00000000..80aff61d --- /dev/null +++ b/app/Models/PowerConsumptionSummaryModel.Php @@ -0,0 +1,30 @@ + + modify('first day of this month')->format('Y-m-d'); $endDate = $date->modify('last day of this month')->format('Y-m-d'); @@ -184,7 +240,7 @@ $datesInMonth = []; $period = new DatePeriod( new DateTime($startDate), new DateInterval('P1D'), - (new DateTime($endDate))->modify('+1 day') + (new DateTime($endDate))->modify('+1 day') ); foreach ($period as $day) { @@ -195,55 +251,6 @@ foreach ($period as $day) { - - - - - - - -
@@ -257,7 +264,7 @@ foreach ($period as $day) {
@@ -274,136 +281,526 @@ foreach ($period as $day) {
+
-
+
+
- - -
- -
- - - -
-
- -
- -
- -
- -
- - +
+
+ - - - - - - - - -
- - function formatHeader($key) - { - $parts = explode('_', $key); - if (is_numeric(end($parts))) { array_pop($parts); } - return ucwords(implode(' ', $parts)); - - } - ?> +
- - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + - - $row): ?> - - - $powerStockDetails) { + + + + ?> + format('d-m-Y'); + if ($dateInMonthDmYFormat === $currentDate) { + echo 'style="background: #cef0ad;"'; + } + ?>> + + + format('d-m-Y'); + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + $powerStock) { ?> + + + + + + + + + + + + + + " - style="" - > - $column): ?> - - - - - - - - - - - - - - - + //before closing inner loop we just adding the total values inside it + $machineId = $powerStock['machine_id']; // Unique identifier + + + // Initialize the material entry if it doesn't exist + if (!isset($summary["machineId_$machineId"])) { + $summary["machineId_$machineId"] = [ + 'opening_units' => "-" , + 'closing_units' => 0 , + 'total_units' => 0 , + ]; + } + + // Sum values for the material + + $summary["machineId_$machineId"]['opening_units'] = 0 ; + $summary["machineId_$machineId"]['closing_units'] += is_numeric($powerStock['closing_units']) ? $powerStock['closing_units'] : 0 ; + $summary["machineId_$machineId"]['total_units'] += is_numeric($powerStock['total_units']) ? $powerStock['total_units'] : 0 ; + + + + + + + + } ?> + + + + + +
+
Machine + 150 KW Power + + + + Others +
Date Opening Reading Final ReadingTotal ReadingTotal Units Average PFPresent PFMD MF *60Opening UnitsFinal UnitsTotal Units
+ + + oninput="openingTPStockChange(this)" + contenteditable="true" + + + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + oninput="openingUnitsChange(this)" + contenteditable="true" + > + + + + + + + + + + + + + - format('d-m-Y'); ?> - style="padding: 5px;">
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Date Opening Reading Final ReadingTotal ReadingTotal Units Average PFPresent PFMD MF *60Opening UnitsFinal UnitsTotal Units
+ Total +
+
+ + + + + + $dateInMonth) { ?> + format('d-m-Y'); + if ($dateInMonthDmYFormat === $currentDate) { + echo 'style="background: #cef0ad;"'; + } + ?> > + + format('d-m-Y'); + + ?> + + + + + + + + + oninput="openingTPStockChange(this)" + contenteditable="true" + + + + > + + + + + + + + + + + + + + + + + + + + + + + + $powerMachine) { + ?> + + + + + + + + + + + + + + + oninput="openingUnitsChange(this)" + contenteditable="true" + + + + > + + + + + + + + + + + + + + - - -
+
- +
@@ -419,157 +816,531 @@ foreach ($period as $day) { +
+ +
- + + + + \ No newline at end of file + 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; + } + + + + + + + + \ No newline at end of file From 496834541a0e9cfa601b991ebde22a0f0d7e9f4a Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Mon, 27 Jan 2025 15:53:13 +0530 Subject: [PATCH 4/7] stock module latest today vadivel J 27-01-2025 --- app/Controllers/StockController.php | 157 +++++++---- app/Views/powerConsumptionDetails.php | 387 +++++++++++--------------- 2 files changed, 272 insertions(+), 272 deletions(-) diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index ed5e3c56..553668ba 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -2018,7 +2018,7 @@ class StockController extends BaseController $electricMachines = $this->factoryMachine_model ->where('is_active', 1) - ->where('energy_type', 'Diesel') + ->where('energy_type', 'Electric') ->orderBy('id', 'asc') ->get() ->getResultArray(); @@ -2045,64 +2045,121 @@ class StockController extends BaseController } public function updatePowerConsumptionDetails(){ + + //pm stands for power machine $postData = $this->request->getPost(); $updatePowerConsumptionDetailsData = json_decode($postData['updatePowerConsumptionDetails'], true); - $updates = []; + $updateTotalPmDetailsData = $updatePowerConsumptionDetailsData[0]; + $updatePmDetailsData = $updatePowerConsumptionDetailsData[1]; + + //PmR stands for power machine readings - $inserts = []; - - foreach ($updatePowerConsumptionDetailsData as $data) { - - $date = $data['date']; - $machineId = $data['machine_id']; - - - $dbData = [ - 'date' => $data['date'], - 'machine_id' => $data['machine_id'], - 'opening_units' => $data['opening'], - 'closing_units' => $data['receipt'], - 'total_units' => $data['used'] - ]; - - $resultExists = $this->factoryVehicleDieselDetails_model - ->where('date', $date) - ->where('machine_id', $machineId) - ->first(); - - - if (empty($resultExists)) { - $inserts[] = $dbData; - } else { - $dbData['id'] = $resultExists['id']; - $updates[] = $dbData; - } - } - - - if (!empty($inserts)) { - $this->factoryVehicleDieselDetails_model->insertBatch($inserts); - } - - if (!empty($updates)) { - - $updateResult = $this->factoryVehicleDieselDetails_model->updateBatch($updates, 'id'); - - if ($updateResult === FALSE) { - echo "Error during update"; - } else { - echo "Data Updated Successfully"; - return; - } - } - - echo "Data Saved Successfully"; + $updatesPmR = []; + $insertsPmR = []; + $updatesTotalPmR = []; + $insertsTotalPmR = []; + // Fetch existing records in bulk for power machine details + $dates = array_column($updatePmDetailsData, 'date'); + $machineIds = array_column($updatePmDetailsData, 'machine_id'); + $existingPmRecords = $this->powerConsumptionDetails_model + ->whereIn('date', $dates) + ->whereIn('machine_id', $machineIds) + ->findAll(); + + $existingPmMap = []; + foreach ($existingPmRecords as $record) { + $existingPmMap[$record['date']][$record['machine_id']] = $record; + } + + foreach ($updatePmDetailsData as $data) { + $date = $data['date']; + $machineId = $data['machine_id']; + + $dbData = [ + 'date' => $data['date'], + 'machine_id' => $data['machine_id'], + 'opening_units' => $data['opening_units'], + 'closing_units' => $data['closing_units'], + 'total_units' => $data['total_units'], + ]; + + if (isset($existingPmMap[$date][$machineId])) { + $dbData['id'] = $existingPmMap[$date][$machineId]['id']; + $updatesPmR[] = $dbData; + } else { + $insertsPmR[] = $dbData; + } + } + + // Fetch existing records in bulk for power stock summary + $dates = array_column($updateTotalPmDetailsData, 'date'); + $existingTotalPmRecords = $this->powerConsumptionSummary_model + ->whereIn('date', $dates) + ->findAll(); + + $existingTotalPmMap = []; + foreach ($existingTotalPmRecords as $record) { + $existingTotalPmMap[$record['date']] = $record; + } + + foreach ($updateTotalPmDetailsData as $data) { + $date = $data['date']; + + $dbData = [ + 'date' => $data['date'], + 'opening_reading' => $data['opening_reading'], + 'final_reading' => $data['final_reading'], + 'total_reading' => $data['total_reading'], + 'total_units' => $data['total_units'], + 'average_pf' => $data['average_pf'], + 'present_pf' => $data['present_pf'], + 'md' => $data['md'], + 'mf' => $data['mf'] + ]; + + if (isset($existingTotalPmMap[$date])) { + $dbData['id'] = $existingTotalPmMap[$date]['id']; + $updatesTotalPmR[] = $dbData; + } else { + $insertsTotalPmR[] = $dbData; + } + } + + // Start the transaction + $this->db->transBegin(); + + try { + if (!empty($insertsPmR)) { + $this->powerConsumptionDetails_model->insertBatch($insertsPmR); + } + + if (!empty($updatesPmR)) { + $this->powerConsumptionDetails_model->updateBatch($updatesPmR, 'id'); + } + + if (!empty($insertsTotalPmR)) { + $this->powerConsumptionSummary_model->insertBatch($insertsTotalPmR); + } + + if (!empty($updatesTotalPmR)) { + $this->powerConsumptionSummary_model->updateBatch($updatesTotalPmR, 'id'); + } + + // Commit the transaction if all operations are successful + $this->db->transCommit(); + echo "Data Saved Successfully"; + + } catch (\Exception $error) { + // Rollback the transaction in case of any errors + $this->db->transRollback(); + echo "An error occurred: " . $error->getMessage(); + } } diff --git a/app/Views/powerConsumptionDetails.php b/app/Views/powerConsumptionDetails.php index 38392f3b..5b8faea9 100644 --- a/app/Views/powerConsumptionDetails.php +++ b/app/Views/powerConsumptionDetails.php @@ -335,11 +335,6 @@ foreach ($period as $day) { - - Others - - - @@ -377,7 +372,7 @@ foreach ($period as $day) { $summary = []; - foreach ($groupedPowerConsumptionStockDetails as $groupedPowerConsumptionStockDetailsIndex => $powerStockDetails) { + foreach ($groupedPowerConsumptionStockDetails as $groupedIndex => $powerStockDetails) { @@ -395,7 +390,7 @@ foreach ($period as $day) { format('d-m-Y'); + $startDate = DateTime::createFromFormat('Y-m-d', $totalPower[$groupedIndex]['date'])->format('d-m-Y'); ?> @@ -404,72 +399,73 @@ foreach ($period as $day) { + oninput="openingTPStockChange(this)" contenteditable="true" - > + > - + + data-id="" > - + - + - + - + - + - + @@ -479,7 +475,7 @@ foreach ($period as $day) { //before closing outer loop if (!isset($summary['openingReading'])) { - $summary['openingReading'] = '-' ; + $summary['openingReading'] = 0 ; $summary['finalReading'] = 0 ; $summary['totalReading'] = 0 ; $summary['totalUnits'] = 0 ; @@ -489,15 +485,19 @@ foreach ($period as $day) { $summary['mf'] = 0 ; } - $summary['openingReading'] += $totalPower[$groupedPowerConsumptionStockDetailsIndex]['openingReading'] == '-' ? 0 : $totalPower[$groupedPowerConsumptionStockDetailsIndex]['openingReading'] ; - $summary['finalReading'] += $totalPower[$groupedPowerConsumptionStockDetailsIndex]['finalReading'] == '-' ? 0 : $totalPower[$groupedPowerConsumptionStockDetailsIndex]['finalReading'] ; - $summary['totalReading'] += $totalPower[$groupedPowerConsumptionStockDetailsIndex]['totalReading'] == '-' ? 0 : $totalPower[$groupedPowerConsumptionStockDetailsIndex]['totalReading'] ; - $summary['totalUnits'] += $totalPower[$groupedPowerConsumptionStockDetailsIndex]['totalUnits'] == '-' ? 0 : $totalPower[$groupedPowerConsumptionStockDetailsIndex]['totalUnits'] ; - $summary['averagePf'] += $totalPower[$groupedPowerConsumptionStockDetailsIndex]['averagePf'] == '-' ? 0 : $totalPower[$groupedPowerConsumptionStockDetailsIndex]['averagePf'] ; - $summary['presentPf'] += $totalPower[$groupedPowerConsumptionStockDetailsIndex]['presentPf'] == '-' ? 0 : $totalPower[$groupedPowerConsumptionStockDetailsIndex]['balance_stock'] ; - $summary['md'] += $totalPower[$groupedPowerConsumptionStockDetailsIndex]['md'] == '-' ? 0 : $totalPower[$groupedPowerConsumptionStockDetailsIndex]['md'] ; - $summary['mf'] += $totalPower[$groupedPowerConsumptionStockDetailsIndex]['mf'] == '-' ? 0 : $totalPower[$groupedPowerConsumptionStockDetailsIndex]['mf'] ; - + + + $summary['openingReading'] = " " ; + $summary['finalReading'] = is_numeric($totalPower[$groupedIndex]['final_reading']) ? $totalPower[$groupedIndex]['final_reading'] : 0 ; + $summary['totalReading'] += is_numeric($totalPower[$groupedIndex]['total_reading']) ? $totalPower[$groupedIndex]['total_reading'] : 0 ; + $summary['totalUnits'] += is_numeric($totalPower[$groupedIndex]['total_units']) ? $totalPower[$groupedIndex]['total_units'] : 0 ; + $summary['averagePf'] = " " ; + $summary['presentPf'] = " "; + $summary['md'] = " " ; + $summary['mf'] = " " ; + + + ?> @@ -521,7 +521,7 @@ foreach ($period as $day) { + oninput="openingUnitsChange(this)" contenteditable="true" > @@ -570,8 +570,8 @@ foreach ($period as $day) { // Sum values for the material - $summary["machineId_$machineId"]['opening_units'] = 0 ; - $summary["machineId_$machineId"]['closing_units'] += is_numeric($powerStock['closing_units']) ? $powerStock['closing_units'] : 0 ; + $summary["machineId_$machineId"]['opening_units'] = " " ; + $summary["machineId_$machineId"]['closing_units'] = " " ; $summary["machineId_$machineId"]['total_units'] += is_numeric($powerStock['total_units']) ? $powerStock['total_units'] : 0 ; @@ -592,25 +592,25 @@ foreach ($period as $day) { - + - - - - - - - - - + + + + + + + + + - + - - - - - + + + + + @@ -728,21 +728,22 @@ foreach ($period as $day) { > - - - - @@ -829,9 +830,9 @@ foreach ($period as $day) {
- - +
- + @@ -868,11 +869,11 @@ foreach ($period as $day) { + + + \ No newline at end of file diff --git a/app/Views/drierMachineDetails.php b/app/Views/drierMachineDetails.php index 2f4739d1..b21eada8 100644 --- a/app/Views/drierMachineDetails.php +++ b/app/Views/drierMachineDetails.php @@ -846,7 +846,7 @@ $datefordropdown = format_date($datefordropdown, 0, 'M-Y'); document.getElementById('drierMachineDetailsExport').addEventListener('click',function(){ - exportTableToExcel(tableId,'drierMachineDetails.xlsx'); + exportTableToExcel(tableId,'drierMachineDetails_.xlsx'); }) diff --git a/app/Views/incomingSilicaSandDetails.php b/app/Views/incomingSilicaSandDetails.php index c90d89c7..f276108b 100644 --- a/app/Views/incomingSilicaSandDetails.php +++ b/app/Views/incomingSilicaSandDetails.php @@ -1729,7 +1729,7 @@ $(document).ready(function() { document.getElementById('incomingSilicaSandDetailsExport').addEventListener('click',function(){ - exportTableToExcel(tableId,'incomingSilicaSandDetails.xlsx'); + exportTableToExcel(tableId,'incomingSilicaSandDetails_.xlsx'); })
Date Opening Reading Final ReadingTotal ReadingTotal Units Average PFPresent PFMD MF *60Date Opening Reading Final ReadingTotal ReadingTotal Units Average PFPresent PFMD MF *60 Opening UnitsFinal UnitsTotal UnitsOpening UnitsFinal UnitsTotal Units