Files
MokoSuiteField/source/packages/com_mokosuitefield/admin/src/Model/EstimatesModel.php
T
Jonathan Miller 3ba79d4367 Add 7 admin models — WorkOrders, Technicians, Equipment, Vehicles, ServiceAgreements, Estimates, Dispatch
All use Joomla 6 BaseDatabaseModel with $this->getDatabase()
2026-06-15 00:50:26 -05:00

29 lines
1.1 KiB
PHP

<?php
namespace Moko\Component\MokoSuiteField\Administrator\Model;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
class EstimatesModel extends BaseDatabaseModel
{
public function getItems(string $status = '', string $search = '', int $techId = 0, int $limit = 50): array
{
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('e.*, cd.name AS customer_name, loc.address')
->from($db->quoteName('#__mokosuitefield_estimates', 'e'))
->join('LEFT', $db->quoteName('#__contact_details', 'cd') . ' ON cd.id = e.contact_id')
->join('LEFT', $db->quoteName('#__mokosuitefield_locations', 'loc') . ' ON loc.id = e.location_id')
->order('e.created DESC');
if ($status) $query->where($db->quoteName('e.status') . ' = ' . $db->quote($status));
if ($techId) $query->where('e.technician_id = ' . $techId);
if ($search) $query->where('(' . $db->quoteName('cd.name') . ' LIKE ' . $db->quote('%' . $search . '%')
. ' OR ' . $db->quoteName('e.estimate_number') . ' LIKE ' . $db->quote('%' . $search . '%') . ')');
$db->setQuery($query, 0, $limit);
return $db->loadObjectList() ?: [];
}
}