feat: round 4 helpers
Universal: Auto Version Bump / Version Bump (push) Successful in 9s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 10s

This commit is contained in:
Jonathan Miller
2026-06-21 17:48:41 -05:00
parent 706f345e16
commit fdd89a1b8a
@@ -0,0 +1,91 @@
<?php
namespace Moko\Plugin\System\MokoSuiteAuto\Helper;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
/**
* Service department — repair orders, vehicle history, technician assignment.
*/
class ServiceDeptHelper
{
/**
* Create a service repair order.
*/
public static function createRO(string $vin, int $contactId, string $concern, string $type = 'repair'): object
{
$allowedTypes = ['repair', 'maintenance', 'warranty', 'recall', 'inspection'];
if (!in_array($type, $allowedTypes, true)) $type = 'repair';
$db = Factory::getContainer()->get(DatabaseInterface::class);
$filter = \Joomla\Filter\InputFilter::getInstance();
$ro = (object) [
'vin' => strtoupper($vin),
'contact_id' => $contactId,
'concern' => $filter->clean($concern, 'STRING'),
'type' => $type,
'status' => 'open',
'created_at' => Factory::getDate()->toSql(),
];
$db->insertObject('#__mokosuiteauto_service_orders', $ro, 'id');
return (object) ['success' => true, 'ro_id' => (int) $ro->id];
}
/**
* Get service history for a VIN.
*/
public static function getVehicleHistory(string $vin): array
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$db->setQuery($db->getQuery(true)
->select('so.id, so.type, so.concern, so.diagnosis, so.status, so.created_at, so.completed_at')
->select('cd.name AS customer_name')
->from($db->quoteName('#__mokosuiteauto_service_orders', 'so'))
->join('LEFT', $db->quoteName('#__contact_details', 'cd') . ' ON cd.id = so.contact_id')
->where($db->quoteName('so.vin') . ' = ' . $db->quote(strtoupper($vin)))
->order('so.created_at DESC'));
return $db->loadObjectList() ?: [];
}
/**
* Get open repair orders.
*/
public static function getOpenOrders(): array
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$db->setQuery($db->getQuery(true)
->select('so.*, cd.name AS customer_name, cd.telephone')
->select('TIMESTAMPDIFF(HOUR, so.created_at, NOW()) AS hours_open')
->from($db->quoteName('#__mokosuiteauto_service_orders', 'so'))
->join('LEFT', $db->quoteName('#__contact_details', 'cd') . ' ON cd.id = so.contact_id')
->where($db->quoteName('so.status') . ' IN (' . $db->quote('open') . ',' . $db->quote('in_progress') . ',' . $db->quote('waiting_parts') . ')')
->order('so.created_at ASC'));
return $db->loadObjectList() ?: [];
}
/**
* Get service department dashboard.
*/
public static function getDashboard(): object
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$db->setQuery($db->getQuery(true)
->select('COUNT(*) AS total_open')
->select('SUM(CASE WHEN status = ' . $db->quote('open') . ' THEN 1 ELSE 0 END) AS awaiting')
->select('SUM(CASE WHEN status = ' . $db->quote('in_progress') . ' THEN 1 ELSE 0 END) AS in_progress')
->select('SUM(CASE WHEN status = ' . $db->quote('waiting_parts') . ' THEN 1 ELSE 0 END) AS waiting_parts')
->from('#__mokosuiteauto_service_orders')
->where($db->quoteName('status') . ' NOT IN (' . $db->quote('completed') . ',' . $db->quote('cancelled') . ')'));
return $db->loadObject() ?: (object) ['total_open' => 0];
}
}