- 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 DailyResultModel extends Model
|
|
{
|
|
protected $table = 'daily_result';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
protected $allowedFields = ['controlid', 'testid', 'resdate', 'resvalue', 'rescomment'];
|
|
protected $useTimestamps = false;
|
|
|
|
public function getByMonth($controlid, $testid, $yearMonth)
|
|
{
|
|
$startDate = $yearMonth . '-01';
|
|
$endDate = $yearMonth . '-31';
|
|
|
|
$builder = $this->db->table('daily_result');
|
|
$builder->select('*');
|
|
$builder->where('controlid', $controlid);
|
|
$builder->where('testid', $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('daily_result');
|
|
$builder->select('*');
|
|
$builder->where('controlid', $controlid);
|
|
$builder->where('resdate >=', $startDate);
|
|
$builder->where('resdate <=', $endDate);
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
public function saveResult($data)
|
|
{
|
|
$builder = $this->db->table('daily_result');
|
|
$existing = $builder->select('*')
|
|
->where('controlid', $data['controlid'])
|
|
->where('testid', $data['testid'])
|
|
->where('resdate', $data['resdate'])
|
|
->get()
|
|
->getRowArray();
|
|
|
|
if ($existing) {
|
|
return $builder->where('id', $existing['id'])->update($data);
|
|
} else {
|
|
return $builder->insert($data);
|
|
}
|
|
}
|
|
}
|