mahdahar 4ae2c75fdd feat: Add department filtering to Controls, Tests, and Entry pages
Implemented comprehensive department filtering across multiple pages in the QC
system to enable users to filter data by laboratory department.

## Backend Changes

**Models:**
- MasterControlsModel: Enhanced search() method to accept optional dept_id
  parameter, added LEFT JOIN with master_depts to include department info
- MasterTestsModel: Updated search() to support dept_id filtering with JOIN

**Controllers:**
- MasterControlsController: Modified index() to accept and pass dept_id parameter
- MasterTestsController: Modified index() to accept and pass dept_id parameter
- EntryApiController: Updated getControls() to filter by dept_id using model search,
  added debug logging for troubleshooting

## Frontend Changes

**Views Updated:**
1. Controls page (/master/control)
   - Added department dropdown with DaisyUI styling
   - Active filter badge and clear button
   - Fetch controls filtered by selected department
   - Added department field to control form dialog

2. Tests page (/master/test)
   - Added department dropdown with active state indication
   - Filter tests by department
   - Clear button to reset filter

3. Daily Entry page (/entry/daily)
   - Added department dropdown in filter section
   - Resets control selection when department changes
   - Fetches controls and tests filtered by department

4. Monthly Entry page (/entry/monthly)
   - Added department dropdown with month selector
   - Resets test selection when department changes
   - Fetches tests filtered by department

## Key Features

- Dropdown UI shows "All Departments" as default
- Selected department name displayed in dropdown button
- Clear button appears when filter is active
- Active department highlighted in dropdown menu
- Loading state while fetching departments
- Automatic reset of dependent selections when department changes
- Consistent UI pattern across all pages using DaisyUI components

## Bug Fixes

- Fixed syntax error in MasterControlsModel search() method
- Removed duplicate/corrupted code that was causing incorrect results
- Added proper deptName field to SELECT query in MasterControlsModel

## Important Note: Department IDs Required

**ACTION REQUIRED**: Existing controls and tests in the database must be assigned
to departments for the filter to work correctly.

To update existing records, run:
  UPDATE master_controls SET dept_id = 1 WHERE dept_id IS NULL;
  UPDATE master_tests SET dept_id = 1 WHERE dept_id IS NULL;

Replace '1' with a valid department ID from master_depts table.

Alternatively, edit each control/test through the UI to assign a department.

## Technical Details

- Alpine.js data binding for reactive department selection
- API expects 'dept_id' query parameter (snake_case)
- Internal state uses camelCase (deptId)
- Departments loaded on init via /api/master/depts
- Search requests include both keyword and dept_id parameters
2026-02-03 16:55:13 +07:00

TinyQC - Quality Control Management System

A CodeIgniter 4 PHP application for quality control data management in laboratory settings. Built with Tailwind CSS, Alpine.js, and DaisyUI.

Features

  • Dictionary Management: Maintain departments, tests, and control parameters
  • Control Management: Configure and manage quality control standards
  • Daily Entries: Record daily quality control test results
  • Monthly Entries: Aggregate and track monthly quality control data
  • Comments System: Add notes and comments to results
  • Reporting: Generate quality control reports and analysis

Technology Stack

Layer Technology
Backend CodeIgniter 4 (PHP 8.1+)
Database SQL Server
Frontend TailwindCSS + Alpine.js + DaisyUI
Icons FontAwesome 7
Testing PHPUnit

Requirements

  • PHP 8.1 or higher
  • SQL Server 2016+
  • Composer
  • Web server (Apache/Nginx/IIS)

Installation

  1. Clone the repository

    git clone <repository-url> tinyqc
    cd tinyqc
    
  2. Install dependencies

    composer install
    
  3. Configure environment

    copy env .env
    

    Edit .env with your database settings:

    database.default.hostname = localhost
    database.default.port = 1433
    database.default.database = tinyqc
    database.default.username = sa
    database.default.password = your_password
    database.default.DBDriver = SQLSRV
    
  4. Set up database

    • Create a new SQL Server database
    • Run migrations if applicable
    • Seed initial data if needed
  5. Configure web server Point your web server to the public directory:

    <VirtualHost *:80>
        ServerName tinyqc.local
        DocumentRoot "D:/data/www/tinyqc/public"
        <Directory "D:/data/www/tinyqc">
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    
  6. Access the application Open http://localhost in your browser

Project Structure

tinyqc/
├── app/
│   ├── Config/          # Configuration files
│   │   ├── Database.php # Database settings
│   │   └── Routes.php   # Route definitions
│   ├── Controllers/     # Application controllers
│   │   ├── Api/         # API controllers
│   │   ├── Dashboard.php
│   │   ├── Dept.php
│   │   ├── Test.php
│   │   ├── Control.php
│   │   ├── Entry.php
│   │   ├── PageController.php
│   │   └── Report.php
│   ├── Models/          # Database models
│   │   ├── DictDeptModel.php
│   │   ├── DictTestModel.php
│   │   ├── DictControlModel.php
│   │   ├── ControlModel.php
│   │   ├── ControlTestModel.php
│   │   ├── DailyResultModel.php
│   │   └── ...
│   └── Views/           # View templates
│       ├── layout/      # Layout templates
│       ├── dashboard.php
│       ├── dept/        # Department views
│       ├── test/        # Test views
│       ├── control/     # Control views
│       ├── entry/       # Entry views
│       └── report/      # Report views
├── public/              # Web root
├── tests/               # Unit tests
├── writable/            # Writable directory
├── env                  # Environment template
├── composer.json
└── phpunit.xml.dist

Usage

Dashboard

The main dashboard provides an overview of quality control status and quick access to all modules.

Dictionary Management

  • Departments: Manage department/category entries
  • Tests: Maintain test parameters and specifications
  • Controls: Configure control standards and limits

Data Entry

  • Daily Entry: Record daily QC test results
  • Monthly Entry: Aggregate monthly data and comments

Reports

Generate quality control reports based on:

  • Date ranges
  • Test types
  • Control parameters

API Endpoints

Method Endpoint Description
GET /api/dept List departments
GET /api/dept/:id Get department details
POST /api/dept Create department
PUT /api/dept/:id Update department
DELETE /api/dept/:id Delete department
GET /api/test List tests
GET /api/test/:id Get test details
POST /api/test Create test
PUT /api/test/:id Update test
DELETE /api/test/:id Delete test
GET /api/control List controls
GET /api/control/:id Get control details
POST /api/control Create control
PUT /api/control/:id Update control
DELETE /api/control/:id Delete control
GET /api/entry/controls Get controls for entry
GET /api/entry/tests Get tests for entry
POST /api/entry/daily Save daily result
POST /api/entry/monthly Save monthly entry
POST /api/entry/comment Save comment

Development

Running Tests

# Run all tests
./vendor/bin/phpunit

# Run with coverage
./vendor/bin/phpunit --coverage-html coverage/

Code Style

Follow these guidelines:

  • PSR-12 coding standards
  • CamelCase for variables/functions
  • PascalCase for classes
  • snake_case for database tables/columns

Adding New Features

  1. Create model in app/Models/
  2. Create API controller in app/Controllers/Api/
  3. Add routes in app/Config/Routes.php
  4. Create views in app/Views/[module]/
  5. Add menu item in layout if needed

Documentation

License

This project is proprietary software.

Support

For support, please contact the development team.

Description
No description provided
Readme MIT 4.5 MiB
Languages
PHP 90.9%
HTML 5.9%
Hack 1.1%
TSQL 0.9%
CSS 0.7%
Other 0.5%