<?php

if (!function_exists('formatJobNo')) {
    function formatJobNo($jobNo)
    {
        $jobNo = trim((string)$jobNo);

        // Remove JOB- if exists
        $jobNo = preg_replace('/^JOB-/', '', $jobNo);

        // Match 14 digits: YYYYMMDDHHMMSS
        if (preg_match('/^(\d{8})(\d{6})$/', $jobNo, $matches)) {
            $dateRaw = $matches[1];
            $timeRaw = $matches[2];

            $dateObj = DateTime::createFromFormat('Ymd', $dateRaw);
            $dateFormatted = $dateObj ? $dateObj->format('d/m/Y') : $dateRaw;

            return $dateFormatted . ' (' . $timeRaw . ')';
        }

        return $jobNo;
    }
}