Merge branch 'ConstructionConsent/modify-faulty-view' into 'master'
modified faulty view See merge request fronk/thetool!1374
This commit is contained in:
@@ -238,18 +238,6 @@ class ConstructionConsentProject extends mfBaseModel {
|
||||
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 {
|
||||
if (empty($projectId)) return false;
|
||||
|
||||
@@ -272,23 +260,41 @@ 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
|
||||
/* 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) = '')
|
||||
)
|
||||
)
|
||||
)
|
||||
LIMIT 1";
|
||||
|
||||
$res = $db->query($sql);
|
||||
|
||||
return ($res->num_rows > 0);
|
||||
$result = $db->query($sql);
|
||||
return $result->rowCount() > 0;
|
||||
}
|
||||
|
||||
public static function getFaultyOwnerEntries($projectId = null) {
|
||||
@@ -306,6 +312,7 @@ SELECT
|
||||
cco.id as owner_id,
|
||||
cco.firstname,
|
||||
cco.lastname,
|
||||
cco.company,
|
||||
cco.title,
|
||||
cco.street,
|
||||
cco.zip,
|
||||
@@ -338,21 +345,40 @@ AND (
|
||||
)
|
||||
) OR
|
||||
(cco.city IS NULL OR TRIM(cco.city) = '')
|
||||
) -- Fixed parenthesis balance here
|
||||
)
|
||||
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) != 'ö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) = '')
|
||||
)
|
||||
)
|
||||
ORDER BY
|
||||
ccp.name, cc.name, cco.lastname, cco.firstname
|
||||
|
||||
";
|
||||
|
||||
$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']))) {
|
||||
$errors[] = 'city';
|
||||
}
|
||||
|
||||
// Check ZIP based on country
|
||||
$isAustria = (strtolower($data['country']) === 'österreich' || strtolower($data['country']) === 'austria');
|
||||
// Check country for numeric characters
|
||||
if (isset($data['country']) && preg_match('/[0-9]/', $data['country'])) {
|
||||
$errors[] = 'country';
|
||||
}
|
||||
|
||||
if ($isAustria && (!isset($data['zip']) || !preg_match('/^[0-9]{4}$/', $data['zip']))) {
|
||||
$errors[] = 'zip';
|
||||
} elseif (!$isAustria && empty(trim($data['zip']))) {
|
||||
// Check ZIP based on country
|
||||
$country = strtolower($data['country'] ?? '');
|
||||
|
||||
// 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';
|
||||
}
|
||||
|
||||
@@ -394,6 +436,7 @@ ORDER BY
|
||||
'title' => $data['title'],
|
||||
'firstname' => $data['firstname'],
|
||||
'lastname' => $data['lastname'],
|
||||
'company' => $data['company'],
|
||||
'street' => $data['street'],
|
||||
'zip' => $data['zip'],
|
||||
'city' => $data['city'],
|
||||
|
||||
@@ -3,12 +3,12 @@ Vue.component('construction-consent-faulty-entries', {
|
||||
template: `
|
||||
<div>
|
||||
<tt-card>
|
||||
|
||||
|
||||
<tt-table :data="window['TT_CONFIG']['FAULTY_ENTRIES']" :config="FaultyEntriesTableConfig" excel-export>
|
||||
<template v-slot:project_name="{ row }">
|
||||
{{ row.project_name }}
|
||||
</template>
|
||||
|
||||
|
||||
<template v-slot:building_info="{ row }">
|
||||
<div>
|
||||
<strong>Name:</strong> {{ row.building_name || 'N/A' }} <br>
|
||||
@@ -31,7 +31,7 @@ Vue.component('construction-consent-faulty-entries', {
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<template v-slot:address_info="{ row }">
|
||||
<div>
|
||||
<div>
|
||||
@@ -39,19 +39,24 @@ Vue.component('construction-consent-faulty-entries', {
|
||||
</div>
|
||||
<div :class="{'text-danger': row.errors.includes('zip')}">
|
||||
<strong>PLZ:</strong> {{ row.zip || '⚠️ Fehlt' }}
|
||||
<span v-if="row.errors.includes('zip') && isAustria(row)" class="badge badge-warning">
|
||||
Muss 4-stellig sein
|
||||
<span v-if="row.errors.includes('zip')" class="badge badge-warning">
|
||||
<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>
|
||||
</div>
|
||||
<div :class="{'text-danger': row.errors.includes('city')}">
|
||||
<strong>Stadt:</strong> {{ row.city || '⚠️ Fehlt' }}
|
||||
</div>
|
||||
<div>
|
||||
<div :class="{'text-danger': row.errors.includes('country')}">
|
||||
<strong>Land:</strong> {{ row.country || 'N/A' }}
|
||||
<span v-if="row.errors.includes('country')" class="badge badge-warning">
|
||||
Keine Zahlen erlaubt
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<template v-slot:contact_info="{ row }">
|
||||
<div>
|
||||
<div>
|
||||
@@ -62,7 +67,7 @@ Vue.component('construction-consent-faulty-entries', {
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<template v-slot:status="{ row }">
|
||||
<span :class="getStatusBadgeClass(row.status)">
|
||||
{{ formatStatus(row.status) }}
|
||||
@@ -72,7 +77,7 @@ Vue.component('construction-consent-faulty-entries', {
|
||||
{{ formatResult(row.result) }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
|
||||
<template v-slot:errors="{ row }">
|
||||
<div class="error-list">
|
||||
<ul class="mb-0 pl-3">
|
||||
@@ -82,7 +87,7 @@ Vue.component('construction-consent-faulty-entries', {
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<template v-slot:actions="{ row }">
|
||||
<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"
|
||||
@@ -160,7 +165,8 @@ Vue.component('construction-consent-faulty-entries', {
|
||||
'firstname': 'Fehlender Vorname',
|
||||
'lastname': 'Fehlender Nachname',
|
||||
'city': 'Fehlende Stadt',
|
||||
'zip': 'Ungültige PLZ'
|
||||
'zip': 'Ungültige PLZ',
|
||||
'country': 'Ungültiges Land (enthält Zahlen)'
|
||||
};
|
||||
return errors[error] || error;
|
||||
},
|
||||
@@ -184,7 +190,12 @@ Vue.component('construction-consent-faulty-entries', {
|
||||
return classes[result] || 'badge badge-secondary';
|
||||
},
|
||||
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() {
|
||||
// Redirect to same page with project filter
|
||||
|
||||
Reference in New Issue
Block a user