- 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
62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class ResultModel extends Model
|
|
{
|
|
protected $table = 'results';
|
|
protected $primaryKey = 'result_id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
protected $allowedFields = ['result_id', 'control_ref_id', 'test_ref_id', 'resdate', 'resvalue', 'rescomment'];
|
|
protected $useTimestamps = false;
|
|
|
|
public function getByMonth($controlId, $testId, $yearMonth)
|
|
{
|
|
$startDate = $yearMonth . '-01';
|
|
$endDate = $yearMonth . '-31';
|
|
|
|
$builder = $this->db->table('results');
|
|
$builder->select('*');
|
|
$builder->where('control_ref_id', $controlId);
|
|
$builder->where('test_ref_id', $testId);
|
|
$builder->where('resdate >=', $startDate);
|
|
$builder->where('resdate <=', $endDate);
|
|
$builder->orderBy('resdate', 'ASC');
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
public function getByControlMonth($controlId, $yearMonth)
|
|
{
|
|
$startDate = $yearMonth . '-01';
|
|
$endDate = $yearMonth . '-31';
|
|
|
|
$builder = $this->db->table('results');
|
|
$builder->select('*');
|
|
$builder->where('control_ref_id', $controlId);
|
|
$builder->where('resdate >=', $startDate);
|
|
$builder->where('resdate <=', $endDate);
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
public function saveResult($data)
|
|
{
|
|
$builder = $this->db->table('results');
|
|
$existing = $builder->select('*')
|
|
->where('control_ref_id', $data['control_ref_id'])
|
|
->where('test_ref_id', $data['test_ref_id'])
|
|
->where('resdate', $data['resdate'])
|
|
->get()
|
|
->getRowArray();
|
|
|
|
if ($existing) {
|
|
return $builder->where('result_id', $existing['result_id'])->update($data);
|
|
} else {
|
|
return $builder->insert($data);
|
|
}
|
|
}
|
|
}
|