120 lines
3.1 KiB
PHP
120 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class FactoryMachineModel extends Model
|
|
{
|
|
// The table associated with this model
|
|
protected $table = 't_factoryMachineMaster';
|
|
|
|
// Primary key of the table
|
|
protected $primaryKey = 'id';
|
|
|
|
// Return type (you can use 'array' or 'object')
|
|
protected $returnType = 'array';
|
|
|
|
// Fields that are allowed to be inserted or updated
|
|
protected $allowedFields = ['machine_name', 'machine_type', 'energy_type', 'is_active', 'created_at', 'updated_at'];
|
|
|
|
// Enable automatic timestamps
|
|
protected $useTimestamps = true;
|
|
|
|
// Define custom timestamps columns, if necessary (optional)
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
|
|
// Validation rules (optional)
|
|
protected $validationRules = [
|
|
'machine_name' => 'required|max_length[255]',
|
|
'machine_type' => 'required|max_length[255]',
|
|
'energy_type' => 'required|max_length[255]',
|
|
|
|
];
|
|
|
|
// Validation messages (optional)
|
|
protected $validationMessages = [];
|
|
|
|
// Skip validation (set to true to skip validation rules)
|
|
protected $skipValidation = false;
|
|
|
|
public function checkMachineName($machineId,$machineName){
|
|
|
|
$builder = $this->db->table('t_factoryMachineMaster');
|
|
|
|
if(!empty($machineId)){
|
|
$builder = $builder->where('id !=' , $machineId);
|
|
}
|
|
|
|
$builder = $builder->where('REPLACE(machine_name, " ", "") ',$machineName);
|
|
|
|
$query = $builder->get();
|
|
|
|
|
|
if ($query->getNumRows() > 0) {
|
|
return $query->getResultArray();
|
|
} else {
|
|
return [];
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public function getAllActiveElectricMachines(){
|
|
|
|
$result = $this->db->table('t_factoryMachineMaster')
|
|
->where('is_active', 1)
|
|
->where('energy_type', 'electric')
|
|
->orderBy('id', 'asc')
|
|
->get()
|
|
->getResultArray();
|
|
|
|
return $result ;
|
|
|
|
}
|
|
|
|
public function getSelectedElectricMachines($distinctMachineId){
|
|
|
|
$result = $this->db->table('t_factoryMachineMaster')
|
|
->whereIn('id', $distinctMachineId)
|
|
->orderBy('id', 'asc')
|
|
->get()
|
|
->getResultArray();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
public function getAllActiveDieselMachines(){
|
|
|
|
$result = $this->db->table('t_factoryMachineMaster')
|
|
->where('is_active', 1)
|
|
->where('energy_type', 'diesel')
|
|
->orderBy('id', 'asc')
|
|
->get()
|
|
->getResultArray();
|
|
|
|
return $result ;
|
|
|
|
}
|
|
|
|
public function getSelectedDieselMachines($distinctMachineId){
|
|
|
|
$result = $this->db->table('t_factoryMachineMaster')
|
|
->whereIn('id', $distinctMachineId)
|
|
->orderBy('id', 'asc')
|
|
->get()
|
|
->getResultArray();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|