ria/app/Models/FactoryMachineModel.php
2025-03-05 18:55:58 +05:30

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', 'desc')
->get()
->getResultArray();
return $result ;
}
public function getSelectedDieselMachines($distinctMachineId){
$result = $this->db->table('t_factorymachinemaster')
->whereIn('id', $distinctMachineId)
->orderBy('id', 'asc')
->get()
->getResultArray();
return $result;
}
}