diff --git a/api_test.http b/api_test.http
index 00cf2d13..cef1449c 100644
--- a/api_test.http
+++ b/api_test.http
@@ -1,8 +1,13 @@
+ # GET http://localhost/ci4/ria/dieselMachineDetails
+
+ GET http://localhost/ci4/ria/dieselMachineDetails
+
// $routes->match(['GET', 'POST'], 'trpProductionDetails', 'StockController::trpProductionDetails');
- GET http://localhost/ci4/ria/trpProductionDetails
+ # GET http://localhost/ci4/ria/trpProductionDetails
+
// $routes->post('updateTrpProductionDetails', 'StockController::updateTrpProductionDetails');
@@ -1079,4 +1084,3 @@
# ]
# }
-
diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index dcdbd56e..cc235356 100755
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -457,13 +457,28 @@ $routes->get('deleteCoatingMachineDetails', 'StockController::deleteCoatingMachi
$routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'drierMachineDetails', 'StockController::drierMachineDetails');
$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');
+//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');
+
+
+
+
//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 789ffe79..8859cd74 100644
--- a/app/Controllers/StockController.php
+++ b/app/Controllers/StockController.php
@@ -2189,6 +2189,9 @@ class StockController extends BaseController
}
+
+
+
public function powerConsumptionDetails()
{
$currentMonth = $this->request->getPost('month') ? $this->request->getPost('month') : date('M-Y');
@@ -2308,4 +2311,495 @@ class StockController extends BaseController
echo "Data successfully saved.";
}
+
+
+ public function dieselMachineStockDetails(){
+
+
+ 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 = '2025-02';
+
+ $month = date('Y-m');
+ }
+
+ $data = [];
+
+ $data['month'] = $month;
+
+ $this->global['pageTitle'] = 'Diesel Machine Stock Details';
+
+
+ // Get the previous month's last date resin 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['previousMonthDieselMachineStockDetails'] = $this->factoryVehicleDieselDetails_model
+ ->select(['machine_id', 'date', 'closing_reading'])
+ ->distinct()
+ ->where('date =', $previousMonthEndDate)
+ ->groupBy(['machine_id', 'date'])
+ ->orderBy('date', 'desc')
+ ->orderBy('machine_id', 'asc')
+ ->findAll();
+
+
+ $data['previousMonthTotalDieselMachineStockDetails'] = $this->factoryVehicleDieselStockSummary_model
+ ->select(['id', 'date', 'balance_stock'])
+ ->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['dieselMachineStockDetails'] = $this->factoryVehicleDieselDetails_model
+ ->where('date >=', $startDate)
+ ->where('date <=', $endDate)
+ ->groupBy(['machine_id', 'date'])
+ ->orderBy('date', 'asc')
+ ->orderBy('machine_id', 'asc')
+ ->findAll();
+
+
+ $data['totalDiesel'] = $this->factoryVehicleDieselStockSummary_model
+ ->where('date >=', $startDate)
+ ->where('date <=', $endDate)
+ ->orderBy('date', 'asc')
+ ->findAll();
+
+ // Initialize an empty array to hold the grouped data
+ $data['groupedDieselMachineStockDetails'] = [];
+
+ // Temporary array to store grouped data by date
+ $groupedByDate = [];
+
+ // Group by 'date'
+ foreach ($data['dieselMachineStockDetails'] 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['groupedDieselMachineStockDetails'] = array_values($groupedByDate);
+
+
+
+ // getting diesel machines for creating table headers
+ // checking already existing stock if yes then get the diesel machines id from the existing stock
+ // if not get all the diesel machines from the factory Machine master table
+
+ if (!empty($data['groupedDieselMachineStockDetails'])) {
+
+ $result = $groupedByDate[$date];
+
+ $distinctMachineId = [];
+
+ foreach ($result as $index => $eachResult) {
+ $distinctMachineId[] = $result[$index]['machine_id'];
+ }
+
+ $dieselMachines = $this->factoryMachine_model
+ ->whereIn('id', $distinctMachineId)
+ ->orderBy('id', 'asc')
+ ->get()
+ ->getResultArray();
+
+
+ } else {
+
+ $dieselMachines = $this->factoryMachine_model
+ ->where('is_active', 1)
+ ->where('energy_type', 'Diesel')
+ ->orderBy('id', 'asc')
+ ->get()
+ ->getResultArray();
+
+ }
+
+
+
+
+
+
+ $dieselMachinesCount = count($dieselMachines);
+
+ $data['dieselMachinesCount'] = $dieselMachinesCount;
+ $data['dieselMachines'] = $dieselMachines;
+
+ $date = DateTime::createFromFormat('Y-m', $month);
+
+ $formattedDate = $date->format('M-Y');
+
+ $data['month'] = $formattedDate ;
+
+ // return $this->response->setJSON(['status' =>'success' ,'message' => $data['dieselMachines']]);
+
+ return $this->loadViews("dieselStockDetails", $this->global, $data, NULL);
+
+
+
+
+ }
+
+ public function updateDieselMachineDetails() {
+
+ $postData = $this->request->getPost();
+ $updateDmDetailsData = json_decode($postData['updateDieselMachineDetails'], true);
+
+ $updateTotalDmDetailsData = $updateDmDetailsData[0];
+ $updateDmDetailsData = $updateDmDetailsData[1];
+
+ $updatesDmR = [];
+ $insertsDmR = [];
+ $updatesTotalDmR = [];
+ $insertsTotalDmR = [];
+
+ // Fetch existing records in bulk for diesel machine details
+ $dates = array_column($updateDmDetailsData, 'date');
+ $machineIds = array_column($updateDmDetailsData, 'machine_id');
+ $existingDmRecords = $this->factoryVehicleDieselDetails_model
+ ->whereIn('date', $dates)
+ ->whereIn('machine_id', $machineIds)
+ ->findAll();
+
+ $existingDmMap = [];
+ foreach ($existingDmRecords as $record) {
+ $existingDmMap[$record['date']][$record['machine_id']] = $record;
+ }
+
+ foreach ($updateDmDetailsData as $data) {
+ $date = $data['date'];
+ $machineId = $data['machine_id'];
+
+ $dbData = [
+ 'date' => $data['date'],
+ 'machine_id' => $data['machine_id'],
+ 'opening_reading' => $data['opening_reading'],
+ 'closing_reading' => $data['closing_reading'],
+ 'filling_diesel' => $data['filling_diesel'],
+ 'consumption' => $data['consumption'],
+ 'running_hours' => $data['running_hours'],
+ 'mileage' => $data['mileage']
+ ];
+
+ if (isset($existingDmMap[$date][$machineId])) {
+ $dbData['id'] = $existingDmMap[$date][$machineId]['id'];
+ $updatesDmR[] = $dbData;
+ } else {
+ $insertsDmR[] = $dbData;
+ }
+ }
+
+ // Fetch existing records in bulk for diesel stock summary
+ $dates = array_column($updateTotalDmDetailsData, 'date');
+ $existingTotalDmRecords = $this->factoryVehicleDieselStockSummary_model
+ ->whereIn('date', $dates)
+ ->findAll();
+
+ $existingTotalDmMap = [];
+ foreach ($existingTotalDmRecords as $record) {
+ $existingTotalDmMap[$record['date']] = $record;
+ }
+
+ foreach ($updateTotalDmDetailsData as $data) {
+ $date = $data['date'];
+
+ $dbData = [
+ 'date' => $data['date'],
+ 'opening_stock' => $data['opening_stock'],
+ 'purchase_diesel' => $data['purchase_diesel'],
+ 'total_filling_diesel' => $data['total_filling_diesel'],
+ 'balance_stock' => $data['balance_stock']
+ ];
+
+ if (isset($existingTotalDmMap[$date])) {
+ $dbData['id'] = $existingTotalDmMap[$date]['id'];
+ $updatesTotalDmR[] = $dbData;
+ } else {
+ $insertsTotalDmR[] = $dbData;
+ }
+ }
+
+ // Start the transaction
+ $this->db->transBegin();
+
+ try {
+ if (!empty($insertsDmR)) {
+ $this->factoryVehicleDieselDetails_model->insertBatch($insertsDmR);
+ }
+
+ if (!empty($updatesDmR)) {
+ $this->factoryVehicleDieselDetails_model->updateBatch($updatesDmR, 'id');
+ }
+
+ if (!empty($insertsTotalDmR)) {
+ $this->factoryVehicleDieselStockSummary_model->insertBatch($insertsTotalDmR);
+ }
+
+ if (!empty($updatesTotalDmR)) {
+ $this->factoryVehicleDieselStockSummary_model->updateBatch($updatesTotalDmR, '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();
+ }
+ }
+
+ 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/Views/dieselStockDetails.php b/app/Views/dieselStockDetails.php
new file mode 100644
index 00000000..4dc84772
--- /dev/null
+++ b/app/Views/dieselStockDetails.php
@@ -0,0 +1,1116 @@
+
+
+
+
+modify('first day of this month')->format('Y-m-d');
+$endDate = $date->modify('last day of this month')->format('Y-m-d');
+
+$datesInMonth = [];
+
+
+$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');
+}
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Stocks
+ -
+
Diesel Machine Stock Details
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | machine |
+
+
+ Total Diesel
+ |
+
+
+
+
+
+ = $dieselMachine['machine_name'] ?>
+ |
+
+
+
+
+
+
+ | Date |
+ Opening |
+ Purchase Diesel |
+ Filling Diesel |
+ Balance Stock |
+
+
+
+
+ Date |
+ Machine Id |
+ Opening Reading |
+ Closing Reading |
+ Filling Diesel |
+ Consumption |
+ Running Hours |
+ Mileage |
+
+
+
+
+
+
+
+
+ $dieselStockDetails) {
+
+ ?>
+ format('d-m-Y');
+ if ($dateInMonthDmYFormat === $currentDate) {
+ echo 'style="background: #cef0ad;"';
+ }
+ ?>>
+
+
+ format('d-m-Y');
+ ?>
+
+ |
+ = $startDate ?>
+ |
+
+
+
+ oninput="openingTDStockChange(this)"
+ contenteditable="true"
+
+
+ >= $totalDiesel[$groupedDieselMachineStockDetailsIndex]['opening_stock'] ?> |
+
+
+
+
+ = $totalDiesel[$groupedDieselMachineStockDetailsIndex]['purchase_diesel'] ?>
+
+ |
+
+
+
+ = $totalDiesel[$groupedDieselMachineStockDetailsIndex]['total_filling_diesel'] ?>
+
+ |
+
+
+
+ = $totalDiesel[$groupedDieselMachineStockDetailsIndex]['balance_stock'] ?>
+
+ |
+
+
+
+
+ $dieselStock) { ?>
+
+
+ = $dieselStock['date'] ?>
+ |
+
+
+
+ = $dieselStock['machine_id'] ?>
+
+ |
+
+
+ oninput="openingReadingChange(this)"
+ contenteditable="true"
+ >
+
+ = $dieselStock['opening_reading'] ?>
+
+
+ |
+
+
+
+ = $dieselStock['closing_reading'] ?>
+
+ |
+
+
+
+ = $dieselStock['filling_diesel'] ?>
+
+ |
+
+
+
+ = $dieselStock['consumption'] ?>
+
+ |
+
+
+
+ = $dieselStock['running_hours'] ?>
+
+ |
+
+
+
+ = $dieselStock['mileage'] ?>
+
+ |
+
+
+
+
+
+
+
+
+
+
+ $dateInMonth) { ?>
+ format('d-m-Y');
+ if ($dateInMonthDmYFormat === $currentDate) {
+ echo 'style="background: #cef0ad;"';
+ }
+ ?> >
+
+ format('d-m-Y');
+
+ ?>
+
+ |
+ = $startDate ?>
+ |
+
+
+
+
+ oninput="openingTDStockChange(this)"
+ contenteditable="true"
+
+
+
+ >= $previousMonthTotalDieselMachineStockDetails[0]['balance_stock'] ?? 0 ?> |
+
+
+
+ 0 |
+
+ 0 |
+
+ = $previousMonthTotalDieselMachineStockDetails[0]['balance_stock'] ?? 0 ?> |
+
+
+
+ $dieselMachine) {
+ ?>
+
+
+
+
+
+ = $dateInMonth ?>
+ |
+
+
+ = $dieselMachine['id'] ?>
+ |
+
+
+
+ oninput="openingReadingChange(this)"
+ contenteditable="true"
+
+
+
+ >= $previousMonthDieselMachineStockDetails[$dieselMachineIndex]['closing_reading'] ?? '0' ?>
+ |
+
+ = $previousMonthDieselMachineStockDetails[$dieselMachineIndex]['closing_reading'] ?? '0' ?>
+ |
+
+ 0 |
+
+ 0 |
+
+ 0 |
+
+ 0 |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/Views/includes/new_header.php b/app/Views/includes/new_header.php
index 57e30454..90226e6d 100755
--- a/app/Views/includes/new_header.php
+++ b/app/Views/includes/new_header.php
@@ -881,6 +881,8 @@
Diesel - Factory Vehicle
+ New Diesel - Factory Vehicle
+
Power Consumption
Dust And Rough Stock Details
diff --git a/app/Views/incomingSilicaSandDetails.php b/app/Views/incomingSilicaSandDetails.php
index 02e359d6..6a8632fc 100644
--- a/app/Views/incomingSilicaSandDetails.php
+++ b/app/Views/incomingSilicaSandDetails.php
@@ -1393,7 +1393,7 @@ $(document).ready(function() {
},
success: function(data){
alert("Data Saved Successfully..!!");
- // window.location.reload();
+ window.location.reload();
},
error : function(xhr, status, error){
alert("An error occurred while processing the request. Please try again.");