fixed date filter issues
This commit is contained in:
@@ -38,10 +38,21 @@ class WorkorderDashboardController extends TTCrud
|
||||
{
|
||||
if ($this->user->isAdmin()) {
|
||||
$tenants = WorkorderTenantConfigModel::getAll([], null, 0, ['key' => 'name', 'order' => 'ASC']);
|
||||
$companies = WorkorderCompanyModel::getAll([], null, 0, ['key' => 'name', 'order' => 'ASC']);
|
||||
} else {
|
||||
$tenants = WorkorderTenantConfigModel::getAll(['addressId' => $this->user->address_id], null, 0, ['key' => 'name', 'order' => 'ASC']);
|
||||
$db = FronkDB::singleton();
|
||||
$userAddressId = intval($this->user->address_id);
|
||||
$sql = "SELECT * FROM thetool.WorkorderCompany
|
||||
WHERE visibleForAddressId IS NULL
|
||||
OR FIND_IN_SET('$userAddressId', visibleForAddressId) > 0
|
||||
ORDER BY name ASC";
|
||||
$result = $db->query($sql);
|
||||
$companies = [];
|
||||
while ($row = $result->fetch_object('WorkorderCompanyModel')) {
|
||||
$companies[] = $row;
|
||||
}
|
||||
}
|
||||
$companies = WorkorderCompanyModel::getAll([], null, 0, ['key' => 'name', 'order' => 'ASC']);
|
||||
|
||||
self::returnJson([
|
||||
'tenants' => array_map(fn($t) => ['value' => $t->id, 'text' => $t->name], $tenants),
|
||||
@@ -101,8 +112,18 @@ class WorkorderDashboardController extends TTCrud
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
$whereConditions = ["p.preordercampaign_id IN (" . implode(',', $tenantCampaignIds) . ")"];
|
||||
if ($dateFrom) $whereConditions[] = "w.`create` >= " . intval($dateFrom);
|
||||
if ($dateTo) $whereConditions[] = "w.`create` <= " . intval($dateTo);
|
||||
if ($dateFrom || $dateTo) {
|
||||
$dateFromInt = $dateFrom ? intval($dateFrom) : 0;
|
||||
$dateToInt = $dateTo ? intval($dateTo) : PHP_INT_MAX;
|
||||
$whereConditions[] = "(
|
||||
(w.`create` >= $dateFromInt AND w.`create` <= $dateToInt)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM thetool.WorkorderJournal wj
|
||||
WHERE wj.workorderId = w.id
|
||||
AND wj.`create` >= $dateFromInt AND wj.`create` <= $dateToInt
|
||||
)
|
||||
)";
|
||||
}
|
||||
if (!empty($companyIds)) $whereConditions[] = "w.companyId IN (" . implode(',', array_map('intval', $companyIds)) . ")";
|
||||
if (!empty($statuses)) $whereConditions[] = "w.status IN (" . implode(',', array_map(fn($s) => "'" . $db->escape($s) . "'", $statuses)) . ")";
|
||||
$whereClause = implode(' AND ', $whereConditions);
|
||||
@@ -201,8 +222,18 @@ class WorkorderDashboardController extends TTCrud
|
||||
private function getTimeTrends($db, $tenantCampaignIds, $dateFrom, $dateTo, $companyIds): array
|
||||
{
|
||||
$where = ["p.preordercampaign_id IN (" . implode(',', $tenantCampaignIds) . ")"];
|
||||
if ($dateFrom) $where[] = "w.`create` >= " . intval($dateFrom);
|
||||
if ($dateTo) $where[] = "w.`create` <= " . intval($dateTo);
|
||||
if ($dateFrom || $dateTo) {
|
||||
$dateFromInt = $dateFrom ? intval($dateFrom) : 0;
|
||||
$dateToInt = $dateTo ? intval($dateTo) : PHP_INT_MAX;
|
||||
$where[] = "(
|
||||
(w.`create` >= $dateFromInt AND w.`create` <= $dateToInt)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM thetool.WorkorderJournal wj
|
||||
WHERE wj.workorderId = w.id
|
||||
AND wj.`create` >= $dateFromInt AND wj.`create` <= $dateToInt
|
||||
)
|
||||
)";
|
||||
}
|
||||
if (!empty($companyIds)) $where[] = "w.companyId IN (" . implode(',', array_map('intval', $companyIds)) . ")";
|
||||
|
||||
$sql = "SELECT DATE(FROM_UNIXTIME(w.`create`)) as date, COUNT(*) as created,
|
||||
|
||||
Reference in New Issue
Block a user