diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index cc235356..7b075eb5 100755
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -458,20 +458,14 @@ $routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'drierMachineDetails', 'StockCo
$routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'addOrEditdrierMachineDetails', 'StockController::addOrEditdrierMachineDetails');
//diesel machine details
-$routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'factoryVehicleDieselDetails', 'StockController::factoryVehicleDieselDetails');
-$routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'addOrEditfactoryVehicleDieselDetails', 'StockController::addOrEditfactoryVehicleDieselDetails');
+$routes->match(['GET','POST'] , 'dieselMachineDetails' , 'StockController::dieselMachineStockDetails') ;
+$routes->post('updateDieselMachineDetails' , 'StockController::updateDieselMachineDetails');
//power consumption details
$routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'powerConsumptionDetails', 'StockController::powerConsumptionDetails');
$routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'addOrEditPowerConsumptionDetails', 'StockController::addOrEditPowerConsumptionDetails');
-
-//new diesel machine details
-$routes->match(['GET','POST'] , 'dieselMachineDetails' , 'StockController::dieselMachineStockDetails') ;
-$routes->post('updateDieselMachineDetails' , 'StockController::updateDieselMachineDetails');
-
-
//new power consumption details
$routes->match(['GET','POST'] , 'newPowerConsumptionDetails' , 'StockController::newPowerConsumptionDetails');
$routes->post('updatePowerConsumptionDetails','StockController::updatePowerConsumptionDetails');
diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php
index 84eda4ac..456ce71b 100644
--- a/app/Controllers/StockController.php
+++ b/app/Controllers/StockController.php
@@ -1893,308 +1893,7 @@ class StockController extends BaseController
}
-
- public function factoryVehicleDieselDetails()
- {
- $currentMonth = $this->request->getPost('month') ? $this->request->getPost('month') : date('M-Y');
-
- $monthData = $this->getMonthDatesFromInput($currentMonth);
-
- $data['startDate'] = $monthData[0]['database'];
- $data['endDate'] = $monthData[count($monthData) - 1]['database'];
- $data['datefordropdown'] = $currentMonth;
-
- //Machine Details
- $data['machineDetails'] = $this->factoryMachine_model->where('energy_type', 'diesel')->where('is_active', 1)->findAll();
- if (!count([$data['machineDetails']])) {
- return $this->response->setBody("");
- }
-
- //Diesel Stock Summary Details
- $data['summaryDetails'] = $this->factoryVehicleDieselStockSummary_model->select('date,opening_stock as opening_stock_0,purchase_diesel as purchase_diesel_0,total_filling_diesel as total_filling_diesel_0,balance_stock as balance_stock_0')
- ->where('date >=', $data['startDate'])
- ->where('date <=', $data['endDate'])
- ->findAll();
-
- if (!count($data['summaryDetails'])) {
-
- //before insert check previous month data present?
-
- if (isset($data['startDate']) && !empty($data['startDate'])) {
- // Extract the year and month part from the startDate
- $startDate = substr($data['startDate'], 0, 7); // Get 'Y-m' part
- $date = DateTime::createFromFormat('Y-m', $startDate);
-
- if ($date) {
- $previousMonth = $date->modify('-1 month')->format('Y-m');
- $previousMonthStartDate = "$previousMonth-01";
- $previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate));
- }
- }
-
- // Now you can use $previousMonth, $previousMonthStartDate, and $previousMonthEndDate
-
- $previousMonthData = $this->factoryVehicleDieselStockSummary_model
- ->where('date >=', $previousMonthStartDate)
- ->where('date <=', $previousMonthEndDate)
- ->orderBy('date', 'desc')
- ->first();
-
- if (!empty($previousMonthData)) {
- //insert empty data
- $tempInsert = [];
- foreach ($monthData as $key => $value) {
- if($value['database'] == $previousMonthData['date']){ //add +1day to previous month date
-
- array_push($tempInsert, [
- 'date' => $value['database'],
- 'opening_stock' => $previousMonthData['balance_stock'],
- 'purchase_diesel' => 0.00,
- 'total_filling_diesel' => 0.00,
- 'balance_stock' => $previousMonthData['balance_stock']]);
- }else{
- array_push($tempInsert, ['date' => $value['database']]);
- }
- }
-
- $this->factoryVehicleDieselStockSummary_model->insertBatch($tempInsert);
-
- $data['summaryDetails'] = $this->factoryVehicleDieselStockSummary_model->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll();
-
-
-
- }else{
- //insert empty data
- $tempInsert = [];
- foreach ($monthData as $key => $value) {
- array_push($tempInsert, ['date' => $value['database']]);
- }
- $this->factoryVehicleDieselStockSummary_model->insertBatch($tempInsert);
-
- $data['summaryDetails'] = $this->factoryVehicleDieselStockSummary_model->where('date >=', $data['startDate'])->where('date <=', $data['endDate'])->findAll();
- }
-
- }
-
- //Diesel Consumption Details
- $data['dieselConsumptionDetails'] = $this->getDieselConsumptionPivot($data['machineDetails'],$data['startDate'], $data['endDate']);
-
- if (!count($data['dieselConsumptionDetails'])) {
-
- //before insert check previous month data present?
-
- if (isset($data['startDate']) && !empty($data['startDate'])) {
- // Extract the year and month part from the startDate
- $startDate = substr($data['startDate'], 0, 7); // Get 'Y-m' part
-
- $date = DateTime::createFromFormat('Y-m', $startDate);
-
- if ($date) {
- $previousMonth = $date->modify('-1 month')->format('Y-m');
- $previousMonthStartDate = "$previousMonth-01";
- $previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate));
- }
- }
-
- $previousMonthData = $this->factoryVehicleDieselDetails_model
- ->where('date >=', $previousMonthStartDate)
- ->where('date <=', $previousMonthEndDate)
- ->orderBy('date', 'desc')
- ->first();
-
-
-
- if (!empty($previousMonthData)) {
- //insert empty data
- $tempInsert = [];
- foreach ($monthData as $key => $value) {
-
- foreach($data['machineDetails'] as $machine){
-
-
- $previousMonthDataFetched = $this->factoryVehicleDieselDetails_model
- ->where('date >=', $previousMonthStartDate)
- ->where('date <=', $previousMonthEndDate)
- ->where('machine_id', $machine['id'])
- ->orderBy('date', 'desc')
- ->first();
-
-
- if($value['database'] == $previousMonthData['date']){ //add +1day to previous month date
-
- array_push($tempInsert, [
- 'date' => $value['database'],
- 'machine_id' => $machine['id'],
- 'opening_reading' => $previousMonthDataFetched['closing_reading'],
- 'closing_reading' => $previousMonthDataFetched['closing_reading'],
- 'filling_diesel' => 0.00,
- 'consumption' => 0.00,
- 'running_hours' => 0.00,
- 'mileage' => 0.00]);
-
-
- }else{
- array_push($tempInsert, [
- 'date' => $value['database'],
- 'machine_id' => $machine['id'],
- 'opening_reading' => 0.00,
- 'closing_reading' => 0.00,
- 'filling_diesel' => 0.00,
- 'consumption' => 0.00,
- 'running_hours' => 0.00,
- 'mileage' => 0.00]);
- }
-
- }
-
-
-
- }
- }else{
- $tempInsert = [];
- foreach ($monthData as $key => $value) {
-
- foreach($data['machineDetails'] as $machine){
- array_push( $tempInsert,
- ['date' => $value['database'],
- 'machine_id' => $machine['id'],
- 'opening_reading' => 0.00,
- 'closing_reading' => 0.00,
- 'filling_diesel' => 0.00,
- 'consumption' => 0.00,
- 'running_hours' => 0.00,
- 'mileage' => 0.00]);
- }
-
- }
- }
-
- $this->factoryVehicleDieselDetails_model->insertBatch($tempInsert);
-
-
- $data['dieselConsumptionDetails'] = $this->getDieselConsumptionPivot($data['machineDetails'], $data['startDate'], $data['endDate']);
-
- }
-
- // Merge the two arrays
- $mergedArray = [];
-
- // Loop through the first array
- foreach ($data['summaryDetails'] as $item1) {
- $date = $item1["date"];
-
- // Find the matching item in the second array by date
- foreach ($data['dieselConsumptionDetails'] as $item2) {
- if ($item2["date"] === $date) {
- // Merge the two arrays
- $mergedArray[] = array_merge($item1, $item2);
- break; // Stop once the matching date is found
- }
- }
- }
- $data['dieselConsumptionDetails'] = $mergedArray;
-
- $data['machineName'] = array_column($data['machineDetails'], 'machine_name');
-
- $this->global['pageTitle'] = 'Drier Details';
-
- $this->loadViews("factoryDieselMachineDetails", $this->global, $data, NULL);
-
- }
-
- public function getDieselConsumptionPivot($machineDetails, $startDate, $endDeate)
- {
- $machineIds = array_column($machineDetails, 'id');
-
- if (empty($machineIds)) {
- return [];
- }
-
- $fields = ['opening_reading', 'closing_reading', 'filling_diesel', 'consumption', 'running_hours', 'mileage'];
-
- $pivotColumns = [];
- foreach ($machineIds as $machineId) {
- foreach ($fields as $field) {
- $pivotColumns[] = "MAX(CASE WHEN machine_id = $machineId THEN $field ELSE 0 END) AS {$field}_{$machineId}";
- }
- }
-
- $pivotColumnString = implode(", ", $pivotColumns);
-
- $sql = "SELECT `date`, $pivotColumnString FROM `t_factoryVehicleDieselDetails`
- 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 addOrEditfactoryVehicleDieselDetails()
- {
- $dieselMachineTableData = json_decode($this->request->getPost('dieselMachineTableData'), true);
-
- $transformedData = [];
- foreach ($dieselMachineTableData 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_reading' => 0.00,
- 'closing_reading' => 0.00,
- 'filling_diesel' => 0.00,
- 'consumption' => 0.00,
- 'running_hours' => 0.00,
- 'mileage' => 0.00,
- ];
- }
-
- $transformedData[$insertKey][$field] = (float) $value;
- }
- }
- }
-
-
- foreach ($transformedData as $row) {
-
- if ($row['machine_id'] == 0) {
- // Summary data: if machine_id is 0, it indicates summary data. This distinction is used because these records will be stored in a separate table.
- $this->factoryVehicleDieselStockSummary_model->where('date', $row['date'])->set($row)->update();
- } else {
-
- // Diesel - factory vehicle data :
- $existingRow = $this->factoryVehicleDieselDetails_model->where('date', $row['date'])->where('machine_id', $row['machine_id'])->first();
- if ($existingRow) {
- $this->factoryVehicleDieselDetails_model->update($existingRow['id'], $row);
- } else {
- $this->factoryVehicleDieselDetails_model->insert($row);
- }
- }
- }
-
-
- echo "Data successfully saved.";
- }
-
-
-
public function powerConsumptionDetails()
diff --git a/app/Views/dieselStockDetails.php b/app/Views/dieselStockDetails.php
index 40648ada..c41ae5af 100644
--- a/app/Views/dieselStockDetails.php
+++ b/app/Views/dieselStockDetails.php
@@ -106,17 +106,15 @@
color: #ffffff;
font-weight: bold;
padding: 6px 10px;
- ;
text-align: center;
}
.celda_encabezado_total {
- background-color:#ffffff;
- border: 1px solid #ccc;
- color: #ffffff;
+ background-color:#ffffff !important;
+ border: 1px solid #ffffff;
+ color: #ffffff !important;
font-weight: bold;
padding: 6px 10px;
- ;
text-align: center;
}
@@ -138,7 +136,7 @@
/* */
text-align: center;
border: 1px solid #ccc;
- padding: 2px 4px;
+ padding: 10px 6px;
}
/*style excel*/
@@ -167,31 +165,62 @@
height: 20px;
}
- #dieselStockDetailsTableId th:nth-child(1),
- #dieselStockDetailsTableId td:nth-child(1) {
- position: sticky;
- left: 0;
- background-color: #00a65a;
- z-index: 2;
- border-right: 2px solid #ddd;
- color: #ffffff;
- }
-
- #dieselStockDetailsTableSummaryId th:nth-child(1),
- #dieselStockDetailsTableSummaryId td:nth-child(1) {
- position: sticky;
- left: 0;
- background-color: #ffffff;
- z-index: 2;
- border-right: 2px solid #ddd;
- color: #ffffff;
- }
+/* 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: 100px;
+ max-width: 100px;
+}
+
+
+
+
+
- .modal {
- padding-right: 30% ! important;
- }
@@ -259,6 +288,7 @@ foreach ($period as $day) {
"
class="form-control mt-2" data-provide="datepicker"
+ style="z-index:30;"
data-date-format="M-yyyy" data-date-min-view-mode="1">
|