2026-01-19 06:37:37 +07:00
|
|
|
<?php
|
|
|
|
|
namespace App\Models\Master;
|
|
|
|
|
|
|
|
|
|
use App\Models\BaseModel;
|
|
|
|
|
|
|
|
|
|
class MasterControlsModel extends BaseModel {
|
|
|
|
|
protected $table = 'master_controls';
|
|
|
|
|
protected $primaryKey = 'control_id';
|
|
|
|
|
protected $allowedFields = [
|
|
|
|
|
'dept_id',
|
docs: add comprehensive documentation and refactor API structure
This commit introduces a complete documentation suite, refactors the API layer for
better consistency, and updates the database schema and seeding logic.
Key Changes:
- Documentation:
- Added `CLAUDE.md` with development guidelines and architecture overview.
- Created `docs/` directory with detailed guides for architecture, development,
and source tree analysis.
- Database & Migrations:
- Implemented `RenameMasterColumns` migration to standardize column naming
(e.g., `name` -> `dept_name`, `name` -> `control_name`).
- Added `CmodQcSeeder` to populate the system with realistic sample data
for depts, controls, tests, and results.
- Backend API:
- Created `DashboardApiController` with `getRecent()` for dashboard stats.
- Created `ReportApiController` for managed reporting access.
- Updated `app/Config/Routes.php` with new API groupings and documentation routes.
- Frontend & Views:
- Refactored master data views (`dept`, `test`, `control`) to use Alpine.js
and the updated API structure.
- Modernized `dashboard.php` and `main_layout.php` with improved UI/UX.
- Infrastructure:
- Updated `.gitignore` to exclude development-specific artifacts (`_bmad/`, `.claude/`).
2026-01-20 14:44:46 +07:00
|
|
|
'control_name',
|
2026-01-19 06:37:37 +07:00
|
|
|
'lot',
|
|
|
|
|
'producer',
|
|
|
|
|
'exp_date',
|
2026-03-04 09:21:41 +07:00
|
|
|
'is_active',
|
2026-01-19 06:37:37 +07:00
|
|
|
'created_at',
|
|
|
|
|
'updated_at',
|
|
|
|
|
'deleted_at'
|
|
|
|
|
];
|
|
|
|
|
protected $useTimestamps = true;
|
|
|
|
|
protected $useSoftDeletes = true;
|
|
|
|
|
|
2026-03-04 09:21:41 +07:00
|
|
|
public function search($keyword = null, $deptId = null, $isActive = null) {
|
2026-02-03 16:55:13 +07:00
|
|
|
$builder = $this->builder();
|
|
|
|
|
$builder->select('
|
|
|
|
|
master_controls.control_id as controlId,
|
|
|
|
|
master_controls.control_name as controlName,
|
|
|
|
|
master_controls.lot,
|
|
|
|
|
master_controls.producer,
|
|
|
|
|
master_controls.exp_date as expDate,
|
2026-03-04 09:21:41 +07:00
|
|
|
master_controls.is_active as isActive,
|
2026-02-03 16:55:13 +07:00
|
|
|
master_depts.dept_name as deptName
|
|
|
|
|
');
|
|
|
|
|
$builder->join('master_depts', 'master_depts.dept_id = master_controls.dept_id', 'left');
|
|
|
|
|
$builder->where('master_controls.deleted_at', null);
|
|
|
|
|
|
|
|
|
|
if ($deptId) {
|
|
|
|
|
$builder->where('master_controls.dept_id', $deptId);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 09:21:41 +07:00
|
|
|
if ($isActive !== null && $isActive !== '') {
|
|
|
|
|
$builder->where('master_controls.is_active', $isActive);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 06:37:37 +07:00
|
|
|
if ($keyword) {
|
2026-02-03 16:55:13 +07:00
|
|
|
$builder->groupStart()
|
|
|
|
|
->like('master_controls.control_name', $keyword)
|
|
|
|
|
->orLike('master_controls.lot', $keyword)
|
|
|
|
|
->orLike('master_controls.producer', $keyword)
|
|
|
|
|
->groupEnd();
|
2026-01-19 06:37:37 +07:00
|
|
|
}
|
2026-02-03 16:55:13 +07:00
|
|
|
|
|
|
|
|
$builder->orderBy('master_controls.control_name', 'ASC');
|
2026-03-04 09:21:41 +07:00
|
|
|
|
2026-02-03 16:55:13 +07:00
|
|
|
$results = $builder->get()->getResultArray();
|
2026-03-04 09:21:41 +07:00
|
|
|
|
2026-02-03 16:55:13 +07:00
|
|
|
foreach ($results as &$row) {
|
|
|
|
|
$row['deptName'] = $row['deptName'] ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $results;
|
2026-01-19 06:37:37 +07:00
|
|
|
}
|
|
|
|
|
}
|