modified faulty view

This commit is contained in:
Luca Haid
2025-05-20 14:08:38 +02:00
parent 288727f465
commit ee98270f8a
2 changed files with 95 additions and 41 deletions
@@ -238,18 +238,6 @@ class ConstructionConsentProject extends mfBaseModel {
return $where; return $where;
} }
/**
* Checks if there are faulty owner entries in the Construction Consent system
* for a specific project
*
* A faulty entry is defined as one where:
* - Title is empty AND (first name is empty OR last name is empty OR city is empty OR zip code is invalid)
* - For Austrian addresses, zip code must be exactly 4 digits
* - For other countries, zip code must not be empty
*
* @param int $projectId The ID of the construction consent project to check
* @return bool Returns true if faulty entries exist, false otherwise
*/
public static function hasFaultyOwnerEntries(int $projectId): bool { public static function hasFaultyOwnerEntries(int $projectId): bool {
if (empty($projectId)) return false; if (empty($projectId)) return false;
@@ -272,23 +260,41 @@ AND (
) )
AND AND
( (
/* Country must not contain any digits */
(cco.country REGEXP '[0-9]')
OR
/* For Austria or empty country: ZIP must be exactly 4 digits */
( (
(LOWER(cco.country) = 'österreich' OR LOWER(cco.country) = 'austria') AND (
(cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{4}') cco.country IS NULL OR
TRIM(cco.country) = '' OR
LOWER(cco.country) = 'österreich' OR
LOWER(cco.country) = 'austria'
) AND
(cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{4}$')
)
OR
/* For Germany: ZIP must be exactly 5 digits */
(
(LOWER(cco.country) = 'deutschland' OR LOWER(cco.country) = 'germany') AND
(cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{5}$')
) )
OR OR
/* For other countries: ZIP must not be empty */ /* For other countries: ZIP must not be empty */
( (
(LOWER(cco.country) != 'österreich' AND LOWER(cco.country) != 'austria') AND (
LOWER(cco.country) NOT IN ('österreich', 'austria', 'deutschland', 'germany') AND
cco.country IS NOT NULL AND
TRIM(cco.country) <> ''
) AND
(cco.zip IS NULL OR TRIM(cco.zip) = '') (cco.zip IS NULL OR TRIM(cco.zip) = '')
) )
) )
) )
LIMIT 1"; LIMIT 1";
$res = $db->query($sql); $result = $db->query($sql);
return $result->rowCount() > 0;
return ($res->num_rows > 0);
} }
public static function getFaultyOwnerEntries($projectId = null) { public static function getFaultyOwnerEntries($projectId = null) {
@@ -306,6 +312,7 @@ SELECT
cco.id as owner_id, cco.id as owner_id,
cco.firstname, cco.firstname,
cco.lastname, cco.lastname,
cco.company,
cco.title, cco.title,
cco.street, cco.street,
cco.zip, cco.zip,
@@ -338,21 +345,40 @@ AND (
) )
) OR ) OR
(cco.city IS NULL OR TRIM(cco.city) = '') (cco.city IS NULL OR TRIM(cco.city) = '')
) -- Fixed parenthesis balance here )
AND ( AND (
/* Country must not contain any digits */
(cco.country REGEXP '[0-9]')
OR
/* For Austria or empty country: ZIP must be exactly 4 digits */
( (
(LOWER(cco.country) = 'österreich' OR LOWER(cco.country) = 'austria') AND (
(cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{4}') cco.country IS NULL OR
TRIM(cco.country) = '' OR
LOWER(cco.country) = 'österreich' OR
LOWER(cco.country) = 'austria'
) AND
(cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{4}$')
) )
OR OR
/* For Germany: ZIP must be exactly 5 digits */
( (
(LOWER(cco.country) != 'österreich' AND LOWER(cco.country) != 'austria') AND (LOWER(cco.country) = 'deutschland' OR LOWER(cco.country) = 'germany') AND
(cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{5}$')
)
OR
/* For other countries: ZIP must not be empty */
(
(
LOWER(cco.country) NOT IN ('österreich', 'austria', 'deutschland', 'germany') AND
cco.country IS NOT NULL AND
TRIM(cco.country) <> ''
) AND
(cco.zip IS NULL OR TRIM(cco.zip) = '') (cco.zip IS NULL OR TRIM(cco.zip) = '')
) )
) )
ORDER BY ORDER BY
ccp.name, cc.name, cco.lastname, cco.firstname ccp.name, cc.name, cco.lastname, cco.firstname
"; ";
$res = $db->query($sql); $res = $db->query($sql);
@@ -370,17 +396,33 @@ ORDER BY
} }
} }
// Existing city check (assuming it's still relevant for faulty entries) // Existing city check
if (empty(trim($data['city']))) { if (empty(trim($data['city']))) {
$errors[] = 'city'; $errors[] = 'city';
} }
// Check ZIP based on country // Check country for numeric characters
$isAustria = (strtolower($data['country']) === 'österreich' || strtolower($data['country']) === 'austria'); if (isset($data['country']) && preg_match('/[0-9]/', $data['country'])) {
$errors[] = 'country';
}
if ($isAustria && (!isset($data['zip']) || !preg_match('/^[0-9]{4}$/', $data['zip']))) { // Check ZIP based on country
$errors[] = 'zip'; $country = strtolower($data['country'] ?? '');
} elseif (!$isAustria && empty(trim($data['zip']))) {
// Austria or empty country check - must have exactly 4 digits
if ($country === '' || $country === 'österreich' || $country === 'austria') {
if (!isset($data['zip']) || !preg_match('/^[0-9]{4}$/', $data['zip'])) {
$errors[] = 'zip';
}
}
// Germany check - must have exactly 5 digits
else if ($country === 'deutschland' || $country === 'germany') {
if (!isset($data['zip']) || !preg_match('/^[0-9]{5}$/', $data['zip'])) {
$errors[] = 'zip';
}
}
// Other countries - ZIP must not be empty
else if (empty(trim($data['zip']))) {
$errors[] = 'zip'; $errors[] = 'zip';
} }
@@ -394,6 +436,7 @@ ORDER BY
'title' => $data['title'], 'title' => $data['title'],
'firstname' => $data['firstname'], 'firstname' => $data['firstname'],
'lastname' => $data['lastname'], 'lastname' => $data['lastname'],
'company' => $data['company'],
'street' => $data['street'], 'street' => $data['street'],
'zip' => $data['zip'], 'zip' => $data['zip'],
'city' => $data['city'], 'city' => $data['city'],
@@ -3,12 +3,12 @@ Vue.component('construction-consent-faulty-entries', {
template: ` template: `
<div> <div>
<tt-card> <tt-card>
<tt-table :data="window['TT_CONFIG']['FAULTY_ENTRIES']" :config="FaultyEntriesTableConfig" excel-export> <tt-table :data="window['TT_CONFIG']['FAULTY_ENTRIES']" :config="FaultyEntriesTableConfig" excel-export>
<template v-slot:project_name="{ row }"> <template v-slot:project_name="{ row }">
{{ row.project_name }} {{ row.project_name }}
</template> </template>
<template v-slot:building_info="{ row }"> <template v-slot:building_info="{ row }">
<div> <div>
<strong>Name:</strong> {{ row.building_name || 'N/A' }} <br> <strong>Name:</strong> {{ row.building_name || 'N/A' }} <br>
@@ -31,7 +31,7 @@ Vue.component('construction-consent-faulty-entries', {
</div> </div>
</div> </div>
</template> </template>
<template v-slot:address_info="{ row }"> <template v-slot:address_info="{ row }">
<div> <div>
<div> <div>
@@ -39,19 +39,24 @@ Vue.component('construction-consent-faulty-entries', {
</div> </div>
<div :class="{'text-danger': row.errors.includes('zip')}"> <div :class="{'text-danger': row.errors.includes('zip')}">
<strong>PLZ:</strong> {{ row.zip || '⚠️ Fehlt' }} <strong>PLZ:</strong> {{ row.zip || '⚠️ Fehlt' }}
<span v-if="row.errors.includes('zip') && isAustria(row)" class="badge badge-warning"> <span v-if="row.errors.includes('zip')" class="badge badge-warning">
Muss 4-stellig sein <span v-if="isAustria(row)">Muss 4-stellig sein</span>
<span v-else-if="isGermany(row)">Muss 5-stellig sein</span>
<span v-else>Ungültig</span>
</span> </span>
</div> </div>
<div :class="{'text-danger': row.errors.includes('city')}"> <div :class="{'text-danger': row.errors.includes('city')}">
<strong>Stadt:</strong> {{ row.city || '⚠️ Fehlt' }} <strong>Stadt:</strong> {{ row.city || '⚠️ Fehlt' }}
</div> </div>
<div> <div :class="{'text-danger': row.errors.includes('country')}">
<strong>Land:</strong> {{ row.country || 'N/A' }} <strong>Land:</strong> {{ row.country || 'N/A' }}
<span v-if="row.errors.includes('country')" class="badge badge-warning">
Keine Zahlen erlaubt
</span>
</div> </div>
</div> </div>
</template> </template>
<template v-slot:contact_info="{ row }"> <template v-slot:contact_info="{ row }">
<div> <div>
<div> <div>
@@ -62,7 +67,7 @@ Vue.component('construction-consent-faulty-entries', {
</div> </div>
</div> </div>
</template> </template>
<template v-slot:status="{ row }"> <template v-slot:status="{ row }">
<span :class="getStatusBadgeClass(row.status)"> <span :class="getStatusBadgeClass(row.status)">
{{ formatStatus(row.status) }} {{ formatStatus(row.status) }}
@@ -72,7 +77,7 @@ Vue.component('construction-consent-faulty-entries', {
{{ formatResult(row.result) }} {{ formatResult(row.result) }}
</span> </span>
</template> </template>
<template v-slot:errors="{ row }"> <template v-slot:errors="{ row }">
<div class="error-list"> <div class="error-list">
<ul class="mb-0 pl-3"> <ul class="mb-0 pl-3">
@@ -82,7 +87,7 @@ Vue.component('construction-consent-faulty-entries', {
</ul> </ul>
</div> </div>
</template> </template>
<template v-slot:actions="{ row }"> <template v-slot:actions="{ row }">
<div class="btn-group btn-group-sm"> <div class="btn-group btn-group-sm">
<a :href="window['TT_CONFIG']['BASE_URL'] + '/ConstructionConsent/View?id=' + row.consent_id + '&highlight_owner_id=' + row.owner_id" <a :href="window['TT_CONFIG']['BASE_URL'] + '/ConstructionConsent/View?id=' + row.consent_id + '&highlight_owner_id=' + row.owner_id"
@@ -160,7 +165,8 @@ Vue.component('construction-consent-faulty-entries', {
'firstname': 'Fehlender Vorname', 'firstname': 'Fehlender Vorname',
'lastname': 'Fehlender Nachname', 'lastname': 'Fehlender Nachname',
'city': 'Fehlende Stadt', 'city': 'Fehlende Stadt',
'zip': 'Ungültige PLZ' 'zip': 'Ungültige PLZ',
'country': 'Ungültiges Land (enthält Zahlen)'
}; };
return errors[error] || error; return errors[error] || error;
}, },
@@ -184,7 +190,12 @@ Vue.component('construction-consent-faulty-entries', {
return classes[result] || 'badge badge-secondary'; return classes[result] || 'badge badge-secondary';
}, },
isAustria(row) { isAustria(row) {
return row.country && (row.country.toLowerCase() === 'österreich' || row.country.toLowerCase() === 'austria'); const country = (row.country || '').toLowerCase();
return country === 'österreich' || country === 'austria' || country === '';
},
isGermany(row) {
const country = (row.country || '').toLowerCase();
return country === 'deutschland' || country === 'germany';
}, },
filterByProject() { filterByProject() {
// Redirect to same page with project filter // Redirect to same page with project filter