- CodeIgniter 4 framework setup with SQL Server database config - Models: Control, Test, Dept, Result, Daily/ Monthly entry models - Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints - Views: CRUD pages with modal dialogs, dashboard, reports - Database: Migrations for control test and daily/monthly result tables - Legacy v1 PHP application preserved in /v1 directory - Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class DictControlModel extends Model
|
|
{
|
|
protected $table = 'dict_controls';
|
|
protected $primaryKey = 'control_id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
protected $allowedFields = ['control_id', 'dept_ref_id', 'name', 'lot', 'producer', 'expdate'];
|
|
protected $useTimestamps = false;
|
|
|
|
public function getByDept($deptId)
|
|
{
|
|
return $this->where('dept_ref_id', $deptId)->findAll();
|
|
}
|
|
|
|
public function getWithDept()
|
|
{
|
|
$builder = $this->db->table('dict_controls c');
|
|
$builder->select('c.*, d.name as dept_name');
|
|
$builder->join('dict_depts d', 'd.dept_id = c.dept_ref_id', 'left');
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
public function getActiveByDate($date, $deptId = null)
|
|
{
|
|
$builder = $this->db->table('dict_controls c');
|
|
$builder->select('c.*');
|
|
$builder->where('c.expdate >=', $date);
|
|
if ($deptId) {
|
|
$builder->where('c.dept_ref_id', $deptId);
|
|
}
|
|
$builder->orderBy('c.name', 'ASC');
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
}
|