418 lines
13 KiB
PHP
418 lines
13 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
use App\Models\CoatingMachineDetailsModel;
|
|
use App\Models\DrierMachineDetailsModel;
|
|
use App\Models\FactoryMachineModel;
|
|
use App\Models\FactoryVehicleDieselDetailsModel;
|
|
use App\Models\FactoryVehicleDieselStockSummaryModel;
|
|
use App\Models\IncomingSilicaSandDetailsModel;
|
|
use App\Models\Inwardgateregister_model;
|
|
use App\Models\Rawmaterialdetails_model;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use DateTime;
|
|
|
|
class StockController extends BaseController
|
|
{
|
|
|
|
protected $coatingMachineDetails_model;
|
|
protected $drierMachineDetails_model;
|
|
protected $factoryMachine_model;
|
|
protected $factoryVehicleDieselDetails_model;
|
|
protected $factoryVehicleDieselStockSummary_model;
|
|
protected $session;
|
|
protected $incomingSilicaSandDetails_model;
|
|
protected $inwardGateRegister_model;
|
|
protected $rawmaterialdetails_model;
|
|
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->coatingMachineDetails_model = new CoatingMachineDetailsModel();
|
|
$this->drierMachineDetails_model = new DrierMachineDetailsModel();
|
|
$this->factoryMachine_model = new FactoryMachineModel();
|
|
$this->factoryVehicleDieselDetails_model = new FactoryVehicleDieselDetailsModel();
|
|
$this->factoryVehicleDieselStockSummary_model = new FactoryVehicleDieselStockSummaryModel();
|
|
$this->rawmaterialdetails_model = new Rawmaterialdetails_model();
|
|
$this->incomingSilicaSandDetails_model = new IncomingSilicaSandDetailsModel();
|
|
$this->inwardGateRegister_model = new Inwardgateregister_model();
|
|
|
|
$this->session = session();
|
|
helper('form');
|
|
|
|
$this->isLoggedIn();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
//
|
|
}
|
|
|
|
public function loadView_coatingMachineDetails(){
|
|
|
|
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 = date('Y-m');
|
|
}
|
|
|
|
$this->global['pageTitle'] = 'Coating Machine Details ';
|
|
|
|
$data['coatingMachineDetails']= $this->coatingMachineDetails_model
|
|
->where('is_active', 1)
|
|
->orderBy('created_at','DESC')
|
|
->like('created_at', $month, 'after')
|
|
->findAll();
|
|
|
|
$date = DateTime::createFromFormat('Y-m', $month);
|
|
|
|
$formattedDate = $date->format('M-Y');
|
|
|
|
$data['month']=$formattedDate;
|
|
|
|
return $this->loadViews("CoatingMachineDetail", $this->global, $data, NULL);
|
|
|
|
}
|
|
|
|
public function addNewCoatingMachineDetails(){
|
|
|
|
$postData=$this->request->getPost();
|
|
|
|
|
|
$inserted= $this->coatingMachineDetails_model->insert($postData);
|
|
|
|
if ($inserted) {
|
|
// Set flashdata for success message
|
|
return redirect()->to('/coatingMachineDetails')->with('success', 'Coating Machine details updated successfully');
|
|
} else {
|
|
// Set flashdata for error message
|
|
return redirect()->back()->with('error', 'Failed to update Coating machine details');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function updateCoatingMachineDetails(){
|
|
|
|
$putData=$this->request->getPost();
|
|
|
|
$id = $putData['editCoatingMachineDetailId'];
|
|
|
|
$updated= $this->coatingMachineDetails_model->update($id,$putData);
|
|
|
|
if ($updated) {
|
|
// Set flashdata for success message
|
|
return redirect()->to('/coatingMachineDetails')->with('success', 'Coating Machine details updated successfully');
|
|
} else {
|
|
// Set flashdata for error message
|
|
return redirect()->back()->with('error', 'Failed to update Coating machine details');
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function deleteCoatingMachineDetails(){
|
|
|
|
$id = $this->request->getGet('id');
|
|
|
|
$data['is_active']=0;
|
|
|
|
$updated = $this->coatingMachineDetails_model->update($id,$data);
|
|
|
|
if ($updated) {
|
|
// Set flashdata for success message
|
|
return redirect()->to('/coatingMachineDetails')->with('success', 'Coating Machine details deleted successfully');
|
|
} else {
|
|
// Set flashdata for error message
|
|
return redirect()->back()->with('error', 'Failed to delete Coating machine details');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function loadView_incomingSilicaSandDetails(){
|
|
|
|
$month='2024-09';
|
|
$data['month']=$month;
|
|
|
|
$this->global['pageTitle']='Incoming Silica Sand Details';
|
|
|
|
$materialCodes = $this->rawmaterialdetails_model->getAllSilicaRawMaterialCode();
|
|
|
|
if (!empty($materialCodes)) {
|
|
$data['igrDetails'] = $this->inwardGateRegister_model->findIgrDetailsForIncomingSilicaSand($materialCodes,$month);
|
|
|
|
} else {
|
|
$data['igrDetails'] = [];
|
|
}
|
|
|
|
return $this->loadViews("incomingSilicaSandDetails", $this->global, $data, NULL);
|
|
|
|
}
|
|
|
|
public function updateIncomingSilicaSandDetails(){
|
|
|
|
$postData = $this->request->getPost();
|
|
|
|
$incomingSilicaSandDetailsData = json_decode($postData['incomingSilicaSandDetailsData'], true);
|
|
|
|
|
|
foreach($incomingSilicaSandDetailsData as $data){
|
|
|
|
$IGRNO=$data['IGR No'];
|
|
$materialCode=$data['MaterialCode'];
|
|
|
|
|
|
$dbData=[
|
|
'igrNo_fk'=>$data['IGR No'],
|
|
'materialCode'=>$data['MaterialCode'],
|
|
'grade'=>$data['Grade'],
|
|
'gradeCondition'=>$data['Grade Condition'],
|
|
'_10'=>$data['___10___'],
|
|
'_20'=>$data['___20___'],
|
|
'_30'=>$data['___30___'],
|
|
'_40'=>$data['___40___'],
|
|
'_50'=>$data['___50___'],
|
|
'_70'=>$data['___70___'],
|
|
'_100'=>$data['___100___'],
|
|
'_140'=>$data['___140___'],
|
|
'_200'=>$data['___200___'],
|
|
'_300'=>$data['___300___'],
|
|
'pan'=>$data['PAN'],
|
|
'total'=>$data['Total'],
|
|
'afsSpec'=>$data['AFS Spec'],
|
|
'afsActual'=>$data['AFS Actual'],
|
|
'plus20loss'=>$data['Plus 20 loss%'],
|
|
'plus30Loss'=>$data['Plus 30 Loss %'],
|
|
'moistureSpec'=>$data['Moisture % Spec'],
|
|
'moistureActual'=>$data['Moisture Actual'],
|
|
'moistureLoss'=>$data['Moisture Loss'],
|
|
'moistureLossQty'=>$data['Moisture loss Qty'],
|
|
'sieveLossQty'=>$data['Sieve Loss Qty'],
|
|
'salableQty'=>$data['Salable Qty'],
|
|
'remark'=>$data['Remark']
|
|
|
|
|
|
];
|
|
|
|
$resultExists=$this->incomingSilicaSandDetails_model
|
|
->where('igrNo_fk',$IGRNO)
|
|
->where('materialCode',$materialCode)
|
|
->first();
|
|
|
|
|
|
|
|
if(!empty($resultExists)){
|
|
|
|
$updated = $this->incomingSilicaSandDetails_model
|
|
->where('igrNo_fk', $IGRNO)
|
|
->where('materialCode', $materialCode)
|
|
->set($dbData)
|
|
->update();
|
|
|
|
}else{
|
|
$inserted = $this->incomingSilicaSandDetails_model->insert($dbData);
|
|
}
|
|
|
|
}
|
|
|
|
echo "Data Saved Successfully";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------gwm----------------------------------------------
|
|
|
|
|
|
function getMonthDatesFromInput($monthYear) {
|
|
|
|
$date = DateTime::createFromFormat('M-Y', $monthYear);
|
|
|
|
if (!$date) {
|
|
return "Invalid date format. Use 'M-yyyy' format.";
|
|
}
|
|
|
|
$year = $date->format('Y');
|
|
$month = $date->format('m');
|
|
|
|
$totalDays = cal_days_in_month(CAL_GREGORIAN, $month, $year);
|
|
|
|
$dates = [];
|
|
for ($day = 1; $day <= $totalDays; $day++) {
|
|
|
|
$currentDate = DateTime::createFromFormat('Y-m-d', "$year-$month-$day");
|
|
|
|
$dates[] = [
|
|
'readable' => $currentDate->format('d-m-Y'),
|
|
'database' => $currentDate->format('Y-m-d')
|
|
];
|
|
}
|
|
|
|
return $dates;
|
|
}
|
|
|
|
function fillMissingDates($monthData, $drierDetails) {
|
|
|
|
$filledDetails = [];
|
|
|
|
$drierDetailsByDate = [];
|
|
foreach ($drierDetails as $detail) {
|
|
$drierDetailsByDate[$detail['date']] = $detail;
|
|
}
|
|
|
|
foreach ($monthData as $day) {
|
|
$date = $day['database'];
|
|
|
|
if (isset($drierDetailsByDate[$date])) {
|
|
$filledDetails[] = $drierDetailsByDate[$date];
|
|
} else {
|
|
$filledDetails[] = [
|
|
'id' => null,
|
|
'date' => $date,
|
|
'drier_on_time' => null,
|
|
'drier_off_time' => null,
|
|
'drier_running_hours' => '0.00',
|
|
'supplier_name' => null,
|
|
'input_sand_moisture' => '0.00',
|
|
'total_gas_consumption' => '0.00',
|
|
'gas_per_ton' => '0.00',
|
|
'input_sand_qty' => '0.00',
|
|
'moisture_loss_qty' => '0.00',
|
|
'sand_dried_qty' => '0.00',
|
|
'qty_per_hours' => '0.00',
|
|
'dust_qty' => '0.00',
|
|
'customer_name' => null,
|
|
'created_at' => null,
|
|
'updated_at' => null
|
|
];
|
|
}
|
|
}
|
|
return $filledDetails;
|
|
}
|
|
|
|
function generateTimeOptions() {
|
|
$times = [];
|
|
$start = strtotime('00:00'); // Start at midnight (12:00 AM)
|
|
$end = strtotime('23:45'); // End at 11:45 PM
|
|
|
|
while ($start <= $end) {
|
|
$timeValue = date('H:i', $start); // 24-hour format for value
|
|
$timeLabel = date('h:i A', $start); // 12-hour format with AM/PM for display
|
|
$times[$timeValue] = $timeLabel; // Store time in associative array
|
|
$start = strtotime('+15 minutes', $start); // Increment by 15 minutes
|
|
}
|
|
|
|
return $times;
|
|
}
|
|
|
|
function drierMachineDetails()
|
|
{
|
|
|
|
|
|
$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['timeDropdown'] = $this->generateTimeOptions();
|
|
|
|
$data['drierDetails'] = $this->drierMachineDetails_model
|
|
->where('date >=', $data['startDate'])
|
|
->where('date <=', $data['endDate'])
|
|
->findAll();
|
|
$data['datefordropdown'] = $currentMonth;
|
|
|
|
$data['data'] = $this->fillMissingDates($monthData, $data['drierDetails']);
|
|
|
|
|
|
$this->global['pageTitle'] = 'Drier Details';
|
|
$this->loadViews("drierMachineDetails", $this->global, $data, NULL);
|
|
}
|
|
|
|
public function addOrEditdrierMachineDetails()
|
|
{
|
|
$drierData = json_decode($this->request->getPost('drierData'), true);
|
|
|
|
if (empty($drierData)) {
|
|
echo "No data received.";
|
|
return;
|
|
}
|
|
|
|
foreach ($drierData as $row) {
|
|
$data = [
|
|
'date' => DateTime::createFromFormat('d-m-Y', $row['Date'])->format('Y-m-d'),
|
|
'drier_on_time' => $row['Drier On Time'],
|
|
'drier_off_time' => $row['Drier Off Time'],
|
|
'drier_running_hours' => $row['Running Hrs'],
|
|
'supplier_name' => $row['Supplier Name'],
|
|
'input_sand_moisture' => $row['i/p Sand Moisture(%)'],
|
|
'total_gas_consumption'=> $row['Tot Gas Consumption'],
|
|
'gas_per_ton' => $row['Gas Pre Ton'],
|
|
'input_sand_qty' => $row['i/p Sand Qty'],
|
|
'moisture_loss_qty' => $row['Moisture Loss Qty'],
|
|
'sand_dried_qty' => $row['Sand Dried Qty'],
|
|
'qty_per_hours' => $row['Qty Per Hrs'],
|
|
'dust_qty' => $row['Dust Qty'],
|
|
'customer_name' => $row['Customer Name']
|
|
];
|
|
|
|
// Check if a row with the same date already exists
|
|
$existingRow = $this->drierMachineDetails_model->where('date', $data['date'])->first();
|
|
|
|
|
|
if ($existingRow) {
|
|
// If exists, update the row
|
|
$this->drierMachineDetails_model->update($existingRow['id'], $data);
|
|
} else {
|
|
// If not, insert a new row
|
|
$this->drierMachineDetails_model->insert($data);
|
|
}
|
|
}
|
|
|
|
echo "Data successfully saved.";
|
|
}
|
|
|
|
|
|
public function factoryVehicleDieselDetails()
|
|
{
|
|
|
|
$machine = $this->factoryMachine_model->where('energy_type', 'diesel')->where('is_active', 1)->findAll();
|
|
|
|
dd($machine);
|
|
|
|
}
|
|
|
|
}
|