fixed date filter issues

This commit is contained in:
Luca Haid
2026-02-02 10:37:10 +01:00
parent 57cf39979f
commit 4f75985e3c
2 changed files with 39 additions and 8 deletions

View File

@@ -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,

View File

@@ -137,7 +137,7 @@ Vue.component('workorder-dashboard', {
<tt-select sm label="Mandant" :value="selectedTenant" :options="[{value: '', text: 'Bitte wählen...'}, ...filterOptions.tenants]" @input="onTenantChange" />
<tt-date-picker sm label="Zeitraum" :value="dateRange" :date-range="true" :time-picker="false" @input="onDateRangeChange" />
<tt-select sm label="Firma" :value="selectedCompany" :options="[{value: '', text: 'Alle'}, ...filterOptions.companies]" @input="selectedCompany = $event; onFilterChange()" />
<tt-select sm label="Status" :value="selectedStatus" :options="[{value: '', text: 'Alle'}, ...filterOptions.statuses]" @input="selectedStatus = $event; onFilterChange()" />
<tt-select sm label="Status" :value="selectedStatuses" :options="filterOptions.statuses" @input="selectedStatuses = $event; onFilterChange()" multiple />
<tt-select sm label="Kampagne" :value="selectedCampaign" :options="[{value: '', text: 'Alle'}, ...filterOptions.campaigns]" @input="selectedCampaign = $event; onFilterChange()" />
<button class="btn btn-primary btn-sm refresh-btn" @click="fetchDashboardData" :disabled="!selectedTenant || loading">
<i class="fas fa-sync-alt" :class="{ 'fa-spin': loading }"></i> Aktualisieren
@@ -210,7 +210,7 @@ Vue.component('workorder-dashboard', {
`,
data() {
return {
selectedTenant: '', dateRange: null, selectedCompany: '', selectedStatus: '', selectedCampaign: '',
selectedTenant: '', dateRange: null, selectedCompany: '', selectedStatuses: [], selectedCampaign: '',
filterOptions: { tenants: [], companies: [], statuses: [], campaigns: [] },
kpis: null, statusDistribution: [], companyPerformance: [], timeTrends: [],
companyStatusCampaign: [], interventionRates: [], statusTransitions: [],
@@ -257,7 +257,7 @@ Vue.component('workorder-dashboard', {
dateFrom: this.dateRange?.from || null,
dateTo: this.dateRange?.to || null,
companyIds: this.selectedCompany ? [this.selectedCompany] : [],
statuses: this.selectedStatus ? [this.selectedStatus] : [],
statuses: this.selectedStatuses,
campaignIds: this.selectedCampaign ? [this.selectedCampaign] : []
});
this.kpis = response.data.kpis;