Aging Statuses
ID Status ID Status Description Actions
Loading aging statuses...

A. General Usage

Purpose: The Aging Statuses feature allows Super Users to designate which TCT statuses have accountability with buyers. These statuses are tracked separately for aging analysis and reporting.

How to Use: Super Users can add or remove statuses from the aging list through the Aging Statuses tab.

Adding a Status:

  • Click the "Add Status" button
  • Select a status from the dropdown (populated from tct_status table)
  • Click "Save" to add it to the aging list

Editing a Status:

  • Click the pencil icon next to a status
  • Select a different status from the dropdown
  • Click "Save" to update the aging status

Removing a Status:

  • Click the trash icon next to a status
  • Confirm the deletion

Important Notes:

  • Only users with "Super User" role can access this page
  • Statuses must exist in the tct_status table to be added
  • Each status can only appear once in the aging list (duplicates are prevented)

B. Technical Details

Database Table: aging_statuses

  • id - Primary key (auto-increment INT)
  • status_id - Reference to tct_status.rec_id (INT, no FK constraint)
  • Index on status_id for query performance

Related Table: tct_status

  • rec_id - Primary key referenced by aging_statuses.status_id
  • tctstatus_id - Status identifier
  • tctstatus_desc - Status description

API Endpoint: /api/v1/aging-statuses.php

  • GET - Retrieve all aging statuses with descriptions
  • POST - Add new aging status (requires Super User)
  • PUT - Update existing aging status (requires Super User)
  • DELETE - Remove aging status by ID parameter (requires Super User)

Security:

  • Authentication required via session
  • Authorization: Only Super Users can access/manage aging statuses
  • Middleware checks session and Super User role before allowing access

Related Files:

  • api/v1/aging-statuses.php - API endpoint implementation
  • db/migrations/create_aging_statuses_table.sql - Database table schema
  • public/aging.php - UI for managing aging statuses
  • src/layouts/sidebar.php - Sidebar menu item
  • src/layouts/sidebar.js - Sidebar visibility control

C. Buyer List Aging Column

Purpose: The Aging column in the Buyer List (cases.php) displays the time elapsed since a buyer's last relevant status for accountability tracking.

Aging Column Algorithm:

  • Step 1: Start from the LATEST status (most recent in the buyer's status history)
  • Step 2: Check if that status is in the aging_statuses table
  • Step 3: If yes, find the NEXT status (chronologically later) that is NOT in the aging list
  • Step 4: That status is the aging status - use its endorsement date for aging calculation
  • Step 5: If no aging status is found in the entire history, fall back to the latest status '003' (List Of Buyers For Filing At BIR)
  • Step 6: If neither Aging Status nor 003 status exists, show "-" in the Aging column

Examples (assuming aging statuses are 005 and 007):

  • 001 = none (no aging status, no 003)
  • 001 003 = 003 (no aging status, use latest 003)
  • 001 003 005 007 008 010 = 008 (007 is aging status, next is 008)
  • 001 003 005 006 007 008 010 = 008 (007 is aging status, next is 008)
  • 001 003 007 005 010 003 = 010 (005 is aging status, next is 010)
  • 001 003 005 010 007 003 004 = 003 (no aging status found, use latest 003)

Technical Implementation:

  • Uses LEFT JOIN from tct_buyers to tct_buyer_status_history to find the most recent status
  • LEFT JOIN to batches table to get the endorsed_date via batches_id
  • Calculates elapsed time in days (hours/minutes currently disabled for display)
  • Display format: "X days" or "-" if no applicable status

Related Files:

  • public/cases.php - Buyer List table with Aging column
  • api/v1/tct-buyers.php - API endpoint with aging calculation logic