diff --git a/app/Controllers/StockController.php b/app/Controllers/StockController.php
index 1dd877eb..b3ce6677 100644
--- a/app/Controllers/StockController.php
+++ b/app/Controllers/StockController.php
@@ -22,7 +22,7 @@ class StockController extends BaseController
protected $factoryMachine_model;
protected $factoryVehicleDieselDetails_model;
protected $factoryVehicleDieselStockSummary_model;
- protected $session;
+ protected $session;
protected $incomingSilicaSandDetails_model;
protected $inwardGateRegister_model;
protected $rawmaterialdetails_model;
@@ -32,6 +32,7 @@ class StockController extends BaseController
*/
public function __construct()
{
+ $this->db = \Config\Database::connect();
parent::__construct();
$this->coatingMachineDetails_model = new CoatingMachineDetailsModel();
$this->drierMachineDetails_model = new DrierMachineDetailsModel();
@@ -440,11 +441,63 @@ class StockController extends BaseController
public function factoryVehicleDieselDetails()
{
+ $currentMonth = $this->request->getPost('month') ? $this->request->getPost('month') : date('M-Y');
+
+ $monthData = $this->getMonthDatesFromInput($currentMonth);
- $machine = $this->factoryMachine_model->where('energy_type', 'diesel')->where('is_active', 1)->findAll();
+ $data['startDate'] = $monthData[0]['database'];
+ $data['endDate'] = $monthData[count($monthData)-1]['database'];
+ $data['datefordropdown'] = $currentMonth;
- dd($machine);
+ $data['machineDetails'] = $this->factoryMachine_model->where('energy_type', 'diesel')->where('is_active', 1)->findAll();
+ $data['summaryDetails'] = $this->factoryVehicleDieselStockSummary_model
+ ->where('date >=', $data['startDate'])
+ ->where('date <=', $data['endDate'])
+ ->findAll();
+ if(!count($data['summaryDetails']))
+ {
+
+ }
+
+ $data['dieselConsumptionDetails'] = $this->getDieselConsumptionPivot($data['machineDetails'] , $data['startDate'] , $data['endDate']);
+
+ $data['machineName'] = array_column($data['machineDetails'], 'machine_name');
+
+ $this->global['pageTitle'] = 'Drier Details';
+ // this is a code that i want to see in $this->global aiyo pakurane ena nu solrathu
+
+
+ $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;
+ }
+
+
}
diff --git a/app/Views/factoryDieselMachineDetails.php b/app/Views/factoryDieselMachineDetails.php
new file mode 100644
index 00000000..d0f7e101
--- /dev/null
+++ b/app/Views/factoryDieselMachineDetails.php
@@ -0,0 +1,349 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Stocks
+ -
+
Diesel - Factory Vehicle Details
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+ = $name; ?> |
+
+
+
+
+
+
+
+ | = formatHeader($column) ?> |
+
+
+
+
+
+
+
+ $column): ?>
+
+
+ | format('d-m-Y'); ?> |
+
+ = $row[$column] ?? 'N/A' ?> |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+