diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php index ea37b3e3..47c3f76a 100644 --- a/app/Controllers/StockController.php +++ b/app/Controllers/StockController.php @@ -1011,7 +1011,7 @@ class StockController extends BaseController ->join( '(SELECT date, SUM(totalGasconsumption) AS coatingMachineGasconsumption, - SUM(totalCoatingSandInKg) / 1000 AS coatedSand + SUM(totalCoatingSandInKg) AS coatedSand FROM t_coatingmachinedetails WHERE is_active = 1 AND date >= ' . $this->db->escape($startDate) . ' @@ -1369,27 +1369,49 @@ class StockController extends BaseController //possible if no filter applied at all...!!! if(empty($existingCustomMachineCodes)){ - //no filter applied at all just present all active material codes - $existingCustomMachineCodes = $this ->factoryMachine_model - ->getAllActiveDieselMachines() ; - //add this active products in monthwisemachine stock table - $inserts = []; - foreach($existingCustomMachineCodes as $index => $customisedMachineCode){ + //no filter applied at all just present previous month material codes + + $previousMonth = date('Y-m-01', strtotime('-1 month', strtotime("$month-01"))); + + $previousMonthCustomMachineCodes = $this->monthWiseMachineInStockModel + ->select('machine_id') + ->where('date',"$previousMonth") + ->where('machine_category','diesel') + ->get() + ->getResultArray(); + + if(!empty($previousMonthCustomMachineCodes)){ + $existingCustomMachineCodes = $this->factoryMachine_model + ->getSelectedDieselMachines(array_column($previousMonthCustomMachineCodes, 'machine_id')); + }else{ + + // inserting all active if no previous month present + $existingCustomMachineCodes = $this ->factoryMachine_model + ->getAllActiveDieselMachines(); + + //add this active products in monthwisemachine stock table + $inserts = []; + + foreach($existingCustomMachineCodes as $index => $customisedMachineCode){ + + $inserts [] = [ + 'date' => "$month-01", + 'machine_category' => "diesel", + 'machine_id' => $customisedMachineCode['id'] + ]; + + } + + if(!empty($inserts)){ + //insert all the latest applied filter + $this->monthWiseMachineInStockModel->insertBatch($inserts); + + } - $inserts [] = [ - 'date' => "$month-01", - 'machine_category' => "diesel", - 'machine_id' => $customisedMachineCode['id'] - ]; - - } - if(!empty($inserts)){ - //insert all the latest applied filter - $this->monthWiseMachineInStockModel->insertBatch($inserts); - } + }else{ //if filter present,get that material codes $existingCustomMachineCodes = $this->factoryMachine_model @@ -1816,7 +1838,24 @@ class StockController extends BaseController //possible if no filter applied at all...!!! if(empty($existingCustomMachineCodes) ){ - //no filter applied at all just present all active material codes + + //no filter applied at all just present previous month material codes + + $previousMonth = date('Y-m-01', strtotime('-1 month', strtotime("$month-01"))); + + $previousMonthCustomMachineCodes = $this->monthWiseMachineInStockModel + ->select('machine_id') + ->where('date',"$previousMonth") + ->where('machine_category','electric') + ->get() + ->getResultArray(); + + if(!empty($previousMonthCustomMachineCodes)){ + $existingCustomMachineCodes = $this->factoryMachine_model + ->getSelectedDieselMachines(array_column($previousMonthCustomMachineCodes, 'machine_id')); + }else{ + + // inserting all active if no previous month present $existingCustomMachineCodes = $this->factoryMachine_model ->getAllActiveElectricMachines(); @@ -1839,7 +1878,7 @@ class StockController extends BaseController $this->monthWiseMachineInStockModel->insertBatch($inserts); } - + } }else{ @@ -2372,11 +2411,25 @@ class StockController extends BaseController //possible if no filter applied at all...!!! if(empty($existingCustomMaterialCodes)){ - //no filter applied at all just present all active material codes - $existingCustomMaterialCodes = $this->rawmaterialdetails_model->getAllResinMaterialCode(); + //no filter applied at all just present previous month material codes + $previousMonth = date('Y-m-01', strtotime('-1 month', strtotime("$month-01"))); + + $previousMonthCustomMachineCodes = $this->monthWiseMaterialInStockModel + ->select('materialCode') + ->where('date',"$previousMonth") + ->where('stock_category','resin') + ->get() + ->getResultArray(); + + if(!empty($previousMonthCustomMachineCodes)){ + $existingCustomMaterialCodes = $this->rawmaterialdetails_model + ->getSelectedResinMaterialCode(array_column($previousMonthCustomMachineCodes, 'materialCode')); + }else{ + + // inserting all active if no previous month present + $existingCustomMaterialCodes = $this->rawmaterialdetails_model->getAllResinMaterialCode(); - //if no filter already exists or removed current one , just add current filter for that month ....!! $inserts = []; foreach($existingCustomMaterialCodes as $index => $customisedMaterialCode){ @@ -2394,6 +2447,7 @@ class StockController extends BaseController $this->monthWiseMaterialInStockModel->insertBatch($inserts) ; } + } }else{ @@ -2787,11 +2841,28 @@ class StockController extends BaseController //possible if no filter applied at all...!!! if(empty($existingCustomMaterialCodes)){ - //no filter applied at all just present all active material codes + + //no filter applied at all just present previous month material codes + + $previousMonth = date('Y-m-01', strtotime('-1 month', strtotime("$month-01"))); + + $previousMonthCustomMachineCodes = $this->monthWiseMaterialInStockModel + ->select('materialCode') + ->where('date',"$previousMonth") + ->where('stock_category','packing_material') + ->get() + ->getResultArray(); + + if(!empty($previousMonthCustomMachineCodes)){ + $existingCustomMaterialCodes = $this->rawmaterialdetails_model + ->getSelectedResinMaterialCode(array_column($previousMonthCustomMachineCodes, 'materialCode')); + }else{ + + // inserting all active if no previous month present $existingCustomMaterialCodes = $this->rawmaterialdetails_model ->getAllBagMaterialCode(); - //if no filter already exists or removed current one , just add current filter for that month ....!! + //if no filter already exists or removed current one , just add current filter for that month ....!! $inserts = []; foreach($existingCustomMaterialCodes as $index => $customisedMaterialCode){ @@ -2809,6 +2880,8 @@ class StockController extends BaseController $this->monthWiseMaterialInStockModel->insertBatch($inserts) ; } + } + }else{ //if filter present,get that material codes @@ -2949,17 +3022,60 @@ 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 - + + // Collect all material codes to query in one go + $materialCodes = array_column($bagMaterials, 'MaterialCode'); + + // Get current month customers in bulk + $currentCustomers = $this->bagStockDetails_model + ->select('materialCode, customer') + ->where('date >=', $startDate) + ->where('date <=', $endDate) + ->whereIn('materialCode', $materialCodes) + ->findAll(); + + // Map them as materialCode => customer + $currentCustomerMap = []; + foreach ($currentCustomers as $row) { + $currentCustomerMap[$row['materialCode']] = $row['customer']; + } + + // Get previous month customers in bulk + $previousStartDate = date('Y-m-01', strtotime('-1 month', strtotime($startDate))); + $previousEndDate = date('Y-m-t', strtotime('-1 month', strtotime($startDate))); + + $previousCustomers = $this->bagStockDetails_model + ->select('materialCode, customer') + ->where('date >=', $previousStartDate) + ->where('date <=', $previousEndDate) + ->whereIn('materialCode', $materialCodes) + ->findAll(); + + // Map them as materialCode => customer + $previousCustomerMap = []; + foreach ($previousCustomers as $row) { + $previousCustomerMap[$row['materialCode']] = $row['customer']; + } + + // Now merge this data efficiently foreach ($bagMaterials as $key => $bagMaterial) { $materialCode = $bagMaterial['MaterialCode']; - $bagMaterials[$key]['customers'] = $this->bagStockDetails_model - ->select('customer') - ->where('date >=', $startDate) - ->where('date <=', $endDate) - ->where('materialCode', $materialCode) - ->first()['customer'] ?? ''; + + // First, check in current month + $customer = $currentCustomerMap[$materialCode] ?? ''; + + // If not found or empty/blank, check in previous month + if (trim($customer) === '') { + $customer = $previousCustomerMap[$materialCode] ?? ''; + } + + // Set final customer value + $bagMaterials[$key]['customers'] = $customer; + } + + // Sort each date's materials based on the custom order to set table header th if (!empty($customisedMaterialCodes)) { @@ -2984,6 +3100,8 @@ class StockController extends BaseController } + // dd($bagMaterials); + $bagMaterialcount = count($bagMaterials); diff --git a/app/Views/stock/CoatingMachineDetail.php b/app/Views/stock/CoatingMachineDetail.php index e81d289c..bd4d1c46 100644 --- a/app/Views/stock/CoatingMachineDetail.php +++ b/app/Views/stock/CoatingMachineDetail.php @@ -335,7 +335,11 @@ - getFlashdata('error')): ?> + getFlashdata('error')): ?>
getFlashdata('error'); ?>
@@ -999,15 +1003,15 @@ - + - + - + - + - + @@ -1077,11 +1081,11 @@ - - - - - - (A) - (A) + + + + (A) + (A) @@ -1715,8 +1719,10 @@ viewMode: 'months', minViewMode: 'months', autoclose: true, - orientation: 'bottom' - }) + orientation: 'bottom', + startDate: new Date(2025, 0), // Jan is month 0 + endDate: new Date() // current date as max + }); }) diff --git a/app/Views/stock/bagStockDetails.php b/app/Views/stock/bagStockDetails.php index 10b213b3..7e13766f 100644 --- a/app/Views/stock/bagStockDetails.php +++ b/app/Views/stock/bagStockDetails.php @@ -272,6 +272,11 @@ .card { margin-bottom: 5px; } + + .hidden-row { + display: none; + } + @@ -609,13 +614,14 @@ foreach ($period as $day) { foreach ($groupedBagStockDetails as $groupedBagStockDetailsIndex => $bagStockDetails) { + $currentDate = date('d-m-Y'); + $dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $bagStockDetails[0]['date'])->format('d-m-Y'); + ?> - " format('d-m-Y'); if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"'; } @@ -730,124 +736,128 @@ foreach ($period as $day) { - - - $dateInMonth) { ?> - + $dateInMonth) { + $currentDate = date('d-m-Y'); $dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y'); - if ($dateInMonthDmYFormat === $currentDate) { - echo 'style="background: #cef0ad;"'; - } - ?>> - $bagMaterial) { ?> - + ?> + + " - format('d-m-Y'); - ?> - - + + if ($dateInMonthDmYFormat === $currentDate) { + echo 'style="background: #cef0ad;"'; + } + + ?>> + $bagMaterial) { ?> + + + + format('d-m-Y'); + ?> + + + + + + + + + + + + + + + + + + + + oninput="openingStockChange(this)" + contenteditable="true" + + > + + $previousMonthBagStockDetail) { + if ($previousMonthBagStockDetail['materialCode'] == $bagMaterial['MaterialCode']) { + echo $previousMonthBagStockDetail['balanceStock']; + break; + } + } + ?> + + + + + + + + + $previousMonthBagStockDetail) { + if ($previousMonthBagStockDetail['materialCode'] == $bagMaterial['MaterialCode']) { + echo $previousMonthBagStockDetail['balanceStock']; + break; + } + } + ?> + + + + + + + + + + + + Total - - - - - - - - - - - - - - - - oninput="openingStockChange(this)" - contenteditable="true" - - > - - $previousMonthBagStockDetail) { - if ($previousMonthBagStockDetail['materialCode'] == $bagMaterial['MaterialCode']) { - echo $previousMonthBagStockDetail['balanceStock']; - break; - } - } + - - + + + + - + - - $previousMonthBagStockDetail) { - if ($previousMonthBagStockDetail['materialCode'] == $bagMaterial['MaterialCode']) { - echo $previousMonthBagStockDetail['balanceStock']; - break; - } - } - ?> - - - - - - - - - - - - Total - - - + + - - - - - - - - - - - - + @@ -1435,11 +1445,14 @@ foreach ($period as $day) { }) $('#month').datepicker({ - format: "M-yyyy", // Format as "Jan-2025" - minViewMode: 1, // Month-Year Picker - autoclose: true, - todayHighlight: true - }).on('focus', function() { + format: 'M-yyyy', + viewMode: 'months', + minViewMode: 'months', + autoclose: true, + orientation: 'bottom', + startDate: new Date(2025, 0), // Jan is month 0 + endDate: new Date() // current date as max + }).on('focus', function() { $(this).datepicker('show'); // Ensure it opens on focus }); }); diff --git a/app/Views/stock/dieselStockDetails.php b/app/Views/stock/dieselStockDetails.php index c48483f5..29cbd873 100644 --- a/app/Views/stock/dieselStockDetails.php +++ b/app/Views/stock/dieselStockDetails.php @@ -260,6 +260,13 @@ .card { margin-bottom: 5px; } + + .hidden-row { + display: none; + } + + + @@ -594,17 +601,18 @@ foreach ($period as $day) { foreach ($groupedDieselMachineStockDetails as $rowIndex => $dieselStockDetails) { + $currentDate = date('d-m-Y'); + $dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $dieselStockDetails[0]['date'])->format('d-m-Y'); + ?> - " format('d-m-Y'); - if ($dateInMonthDmYFormat === $currentDate) { - echo 'style="background: #cef0ad;"'; - } - ?>> + if ($dateInMonthDmYFormat === $currentDate) { + echo 'style="background: #cef0ad;"'; + } + ?> + > $dateInMonth) { ?> - $dateInMonth) { + + $currentDate = date('d-m-Y'); + $dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y'); + + ?> + + " format('d-m-Y'); if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"'; } @@ -1921,8 +1932,12 @@ foreach ($period as $day) { viewMode: 'months', minViewMode: 'months', autoclose: true, - orientation: 'bottom' - }) + orientation: 'bottom', + startDate: new Date(2025, 0), // Jan is month 0 + endDate: new Date() // current date as max + }); + + diff --git a/app/Views/stock/incomingSilicaSandDetails.php b/app/Views/stock/incomingSilicaSandDetails.php index ed986cc7..943a8e09 100644 --- a/app/Views/stock/incomingSilicaSandDetails.php +++ b/app/Views/stock/incomingSilicaSandDetails.php @@ -325,9 +325,6 @@ " class="form-control " - data-provide="datepicker" - data-date-format="M-yyyy" - data-date-min-view-mode="1" readonly> @@ -1979,6 +1976,15 @@ $('#month').change(function() { $('#changeMonthForm').submit(); }) + $('#month').datepicker({ + format: 'M-yyyy', + viewMode: 'months', + minViewMode: 'months', + autoclose: true, + orientation: 'bottom', + startDate: new Date(2025, 0), // Jan is month 0 + endDate: new Date() // current date as max + }); }) diff --git a/app/Views/stock/powerConsumptionDetails.php b/app/Views/stock/powerConsumptionDetails.php index 042e0386..8707adf8 100644 --- a/app/Views/stock/powerConsumptionDetails.php +++ b/app/Views/stock/powerConsumptionDetails.php @@ -266,6 +266,11 @@ /* Replace with your table's actual ID or selector */ border-collapse: collapse; } + + .hidden-row { + display: none; + } + @@ -605,15 +610,14 @@ foreach ($period as $day) { foreach ($groupedPowerConsumptionStockDetails as $groupedIndex => $powerStockDetails) { + $currentDate = date('d-m-Y'); + $dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $powerStockDetails[0]['date'])->format('d-m-Y'); - ?> - + " format('d-m-Y'); if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"'; } @@ -869,17 +873,20 @@ foreach ($period as $day) { - $dateInMonth) { ?> - $dateInMonth) { + $currentDate = date('d-m-Y'); + $dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y'); + + ?> + + " format('d-m-Y'); if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"'; } - ?>> + ?> + > format('d-m-Y'); @@ -1799,8 +1806,10 @@ foreach ($period as $day) { viewMode: 'months', minViewMode: 'months', autoclose: true, - orientation: 'bottom' - }) + orientation: 'bottom', + startDate: new Date(2025, 0), // Jan is month 0 + endDate: new Date() // current date as max + }); diff --git a/app/Views/stock/resinStockDetails.php b/app/Views/stock/resinStockDetails.php index 04e5c6bf..a13a4a7c 100644 --- a/app/Views/stock/resinStockDetails.php +++ b/app/Views/stock/resinStockDetails.php @@ -265,6 +265,13 @@ .card { margin-bottom: 5px; } + + + .hidden-row { + display: none; + } + + @@ -590,21 +597,28 @@ foreach ($period as $day) { $resinStockDetails) { - ?> - format('d-m-Y'); + + $backgroundColor = " "; + + ?> + " + + style=" "> - $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;"'; - } - ?>> + + $resinStock) { ?> @@ -721,17 +735,25 @@ foreach ($period as $day) { - $dateInMonth) { ?> - $dateInMonth) { + + $currentDate = date('d-m-Y'); + $dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y'); + + ?> + + + " format('d-m-Y'); + + if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad ;"'; } - ?>> + ?> + > $resinMaterial) { ?> @@ -1145,7 +1167,7 @@ foreach ($period as $day) { // Validate against the regex const isValid = /^-?\d*\.?\d*$/.test(input); if (!isValid) { - alert('Invalid input! Please enter a valid number.'); + return 0; } @@ -1409,8 +1431,10 @@ foreach ($period as $day) { viewMode: 'months', minViewMode: 'months', autoclose: true, - orientation: 'bottom' - }) + orientation: 'bottom', + startDate: new Date(2025, 0), // Jan is month 0 + endDate: new Date() // current date as max + }); diff --git a/app/Views/stock/trpSandUseStockDetails.php b/app/Views/stock/trpSandUseStockDetails.php index 8ddc616a..6cf79f5d 100644 --- a/app/Views/stock/trpSandUseStockDetails.php +++ b/app/Views/stock/trpSandUseStockDetails.php @@ -283,6 +283,11 @@ .card { margin-bottom: 5px; } + + .hidden-row { + display: none; + } + @@ -508,17 +513,17 @@ $summary = []; foreach ($trpSandUseStockDetails as $trpSandUseStockDetailsIndex => $trpSandUseStockDetail) { - + $currentDate = date('d-m-Y'); + $dateInMonthDmYFormat = DateTime::createFromFormat('Y-m-d', $trpSandUseStockDetail['date'])->format('d-m-Y'); ?> - " format('d-m-Y'); - if ($dateInMonthDmYFormat === $currentDate) { - echo 'style="background: #cef0ad;"'; - } - ?>> + if($dateInMonthDmYFormat === $currentDate) { + echo 'style="background: #cef0ad;"'; + } + ?> + > $dateInMonth) { - ?> - + + " + +