Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- 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
2026-01-14 16:49:27 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2026-01-15 10:44:09 +07:00
|
|
|
use App\Models\BaseModel;
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- 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
2026-01-14 16:49:27 +07:00
|
|
|
|
2026-01-15 10:44:09 +07:00
|
|
|
class DailyResultModel extends BaseModel
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- 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
2026-01-14 16:49:27 +07:00
|
|
|
{
|
|
|
|
|
protected $table = 'daily_result';
|
2026-01-15 10:44:09 +07:00
|
|
|
protected $primaryKey = 'daily_result_id';
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- 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
2026-01-14 16:49:27 +07:00
|
|
|
protected $useAutoIncrement = true;
|
|
|
|
|
protected $returnType = 'array';
|
2026-01-15 10:44:09 +07:00
|
|
|
protected $useSoftDeletes = true;
|
|
|
|
|
protected $useTimestamps = true;
|
|
|
|
|
protected $allowedFields = ['control_ref_id', 'test_ref_id', 'resdate', 'resvalue', 'rescomment'];
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- 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
2026-01-14 16:49:27 +07:00
|
|
|
|
2026-01-15 10:44:09 +07:00
|
|
|
public function getByMonth($controlId, $testId, $yearMonth)
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- 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
2026-01-14 16:49:27 +07:00
|
|
|
{
|
|
|
|
|
$startDate = $yearMonth . '-01';
|
|
|
|
|
$endDate = $yearMonth . '-31';
|
|
|
|
|
|
|
|
|
|
$builder = $this->db->table('daily_result');
|
|
|
|
|
$builder->select('*');
|
2026-01-15 10:44:09 +07:00
|
|
|
$builder->where('control_ref_id', $controlId);
|
|
|
|
|
$builder->where('test_ref_id', $testId);
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- 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
2026-01-14 16:49:27 +07:00
|
|
|
$builder->where('resdate >=', $startDate);
|
|
|
|
|
$builder->where('resdate <=', $endDate);
|
|
|
|
|
$builder->orderBy('resdate', 'ASC');
|
|
|
|
|
return $builder->get()->getResultArray();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 10:44:09 +07:00
|
|
|
public function getByControlMonth($controlId, $yearMonth)
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- 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
2026-01-14 16:49:27 +07:00
|
|
|
{
|
|
|
|
|
$startDate = $yearMonth . '-01';
|
|
|
|
|
$endDate = $yearMonth . '-31';
|
|
|
|
|
|
|
|
|
|
$builder = $this->db->table('daily_result');
|
|
|
|
|
$builder->select('*');
|
2026-01-15 10:44:09 +07:00
|
|
|
$builder->where('control_ref_id', $controlId);
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- 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
2026-01-14 16:49:27 +07:00
|
|
|
$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('*')
|
2026-01-15 10:44:09 +07:00
|
|
|
->where('control_ref_id', $data['control_ref_id'])
|
|
|
|
|
->where('test_ref_id', $data['test_ref_id'])
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- 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
2026-01-14 16:49:27 +07:00
|
|
|
->where('resdate', $data['resdate'])
|
|
|
|
|
->get()
|
|
|
|
|
->getRowArray();
|
|
|
|
|
|
|
|
|
|
if ($existing) {
|
2026-01-15 10:44:09 +07:00
|
|
|
return $builder->where('daily_result_id', $existing['daily_result_id'])->update($data);
|
Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- 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
2026-01-14 16:49:27 +07:00
|
|
|
} else {
|
|
|
|
|
return $builder->insert($data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|