- New EntryApiController (app/Controllers/Api/EntryApiController.php)
- Centralized API for entry operations (daily/monthly data retrieval and saving)
- getControls() - Fetch controls with optional date-based expiry filtering
- getTests() - Get tests associated with a control
- getDailyData() - Retrieve daily results for a date/control
- getMonthlyData() - Retrieve monthly results with per-day data and comments
- saveDaily() - Batch save daily results with validation
- saveMonthly() - Batch save monthly results with statistics
- New Monthly Entry View (app/Views/entry/monthly.php)
- Calendar grid interface for entering monthly QC results
- Month selector with quick navigation (prev/next/current)
- Test selector to filter controls
- 31-day grid per control with inline editing
- Visual QC range indicators (green for in-range, red for out-of-range)
- Weekend highlighting
- Per-control monthly comment field
- Keyboard shortcut (Ctrl+S) for saving
- Change tracking with pending save indicator
- Route Updates (app/Config/Routes.php)
- Added /entry/monthly page route
- Added /api/entry/daily GET endpoint
- Model Updates
- ResultsModel: Added updateMonthly() for upserting monthly results
- ResultCommentsModel: Added upsertMonthly() for monthly comments
79 lines
2.4 KiB
PHP
79 lines
2.4 KiB
PHP
<?php
|
|
namespace App\Models\Qc;
|
|
|
|
use App\Models\BaseModel;
|
|
|
|
class ResultCommentsModel extends BaseModel {
|
|
protected $table = 'result_comments';
|
|
protected $primaryKey = 'result_comment_id';
|
|
protected $allowedFields = [
|
|
'control_id',
|
|
'test_id',
|
|
'comment_month',
|
|
'com_text',
|
|
'created_at',
|
|
'updated_at',
|
|
'deleted_at'
|
|
];
|
|
protected $useTimestamps = true;
|
|
protected $useSoftDeletes = true;
|
|
|
|
public function search($keyword = null) {
|
|
if ($keyword) {
|
|
return $this->groupStart()
|
|
->like('comment_month', $keyword)
|
|
->orLike('com_text', $keyword)
|
|
->groupEnd()
|
|
->findAll();
|
|
}
|
|
return $this->findAll();
|
|
}
|
|
|
|
/**
|
|
* Get comments by control, test and month
|
|
*/
|
|
public function getByControlTestMonth(int $controlId, int $testId, string $month): ?array {
|
|
return $this->where('control_id', $controlId)
|
|
->where('test_id', $testId)
|
|
->where('comment_month', $month)
|
|
->where('deleted_at', null)
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* Get all comments for a test and month
|
|
*/
|
|
public function getByTestMonth(int $testId, string $month): array {
|
|
return $this->where('test_id', $testId)
|
|
->where('comment_month', $month)
|
|
->where('deleted_at', null)
|
|
->findAll();
|
|
}
|
|
|
|
/**
|
|
* Upsert comment (insert or update based on control/test/month)
|
|
*/
|
|
public function upsertComment(array $data): int {
|
|
$existing = $this->where('control_id', $data['control_id'])
|
|
->where('test_id', $data['test_id'])
|
|
->where('comment_month', $data['comment_month'])
|
|
->where('deleted_at', null)
|
|
->first();
|
|
|
|
if ($existing) {
|
|
if (empty($data['com_text'])) {
|
|
// If text is empty, soft delete
|
|
$this->update($existing['result_comment_id'], ['deleted_at' => date('Y-m-d H:i:s')]);
|
|
return $existing['result_comment_id'];
|
|
}
|
|
$this->update($existing['result_comment_id'], $data);
|
|
return $existing['result_comment_id'];
|
|
} else {
|
|
if (empty($data['com_text'])) {
|
|
return 0; // Don't insert empty comments
|
|
}
|
|
return $this->insert($data, true);
|
|
}
|
|
}
|
|
}
|