stock module latest today vadivel J 16-1-2025
This commit is contained in:
parent
9dc77bdae9
commit
c929246f54
@ -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 @@
|
||||
# ]
|
||||
# }
|
||||
|
||||
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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";
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
1116
app/Views/dieselStockDetails.php
Normal file
1116
app/Views/dieselStockDetails.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -881,6 +881,8 @@
|
||||
|
||||
<a href="<?php echo base_url(); ?>factoryVehicleDieselDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>Diesel - Factory Vehicle </a>
|
||||
|
||||
<a href="<?php echo base_url(); ?>dieselMachineDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i> New Diesel - Factory Vehicle </a>
|
||||
|
||||
<a href="<?php echo base_url(); ?>powerConsumptionDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>Power Consumption </a>
|
||||
|
||||
<a href="<?php echo base_url(); ?>dustAndRoughStockDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>Dust And Rough Stock Details</a>
|
||||
|
||||
@ -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.");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user