Merge branch 'ConstructionConsent/add-faulty-owner-view' into 'master'
added faulty owner view See merge request fronk/thetool!1373
This commit is contained in:
@@ -30,6 +30,7 @@ class ConstructionConsentController extends mfBaseController {
|
||||
}
|
||||
|
||||
$filter = [];
|
||||
$hasFaultyEntries = false;
|
||||
|
||||
if(is_array($this->request->filter)) {
|
||||
$filter = $this->request->filter;
|
||||
@@ -41,6 +42,7 @@ class ConstructionConsentController extends mfBaseController {
|
||||
} else {
|
||||
$_SESSION[MFAPPNAME . '-ConstructionConsent-filter-project-' . $filter["project_id"]] = $filter;
|
||||
}
|
||||
$hasFaultyEntries = ConstructionConsentProject::hasFaultyOwnerEntries($filter["project_id"]);
|
||||
} else {
|
||||
$_SESSION[MFAPPNAME . '-ConstructionConsent-filter'] = $filter;
|
||||
}
|
||||
@@ -59,6 +61,7 @@ class ConstructionConsentController extends mfBaseController {
|
||||
//var_dump($_SESSION, $filter);exit;
|
||||
|
||||
$this->layout->set("allowed_projects", $this->constructionConsentProjects);
|
||||
$this->layout->set("hasFaultyEntries", $hasFaultyEntries);
|
||||
$this->layout->set("filter", $filter);
|
||||
$filter = $this->getPreparedFilter($filter);
|
||||
|
||||
@@ -1373,4 +1376,37 @@ class ConstructionConsentController extends mfBaseController {
|
||||
self::returnJson(["success" => true]);
|
||||
}
|
||||
|
||||
protected function faultyEntriesAction() {
|
||||
// Get project ID from request if available
|
||||
$projectId = isset($_GET['project_id']) ? intval($_GET['project_id']) : null;
|
||||
if ($projectId === null) {
|
||||
$this->layout()->setFlash("Projekt nicht gefunden", "error");
|
||||
$this->redirect("ConstructionConsentProject");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Get faulty owner entries
|
||||
$faultyEntries = ConstructionConsentProject::getFaultyOwnerEntries($projectId);
|
||||
|
||||
$JSGlobals = [
|
||||
"BASE_URL" => self::getUrl(""),
|
||||
"DASHBOARD_URL" => self::getUrl("Dashboard"),
|
||||
"MFAPPNAME" => MFAPPNAME_SLUG,
|
||||
"PAGE_TITLE" => "Fehlerhafte Einträge - Zustimmungserklärungen",
|
||||
"PATH" => [
|
||||
["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")],
|
||||
["text" => "Zustimmungserklärungen", "href" => self::getUrl("ConstructionConsent")],
|
||||
["text" => "Fehlerhafte Einträge", "href" => self::getUrl("ConstructionConsent", "faultyEntries")],
|
||||
],
|
||||
"FAULTY_ENTRIES" => $faultyEntries,
|
||||
"SELECTED_PROJECT" => $projectId,
|
||||
"IS_ADMIN" => $this->me->is("Admin"),
|
||||
];
|
||||
|
||||
$this->layout()->set("vueViewName", "ConstructionConsentFaultyEntries");
|
||||
$this->layout()->set("JSGlobals", $JSGlobals);
|
||||
$this->layout()->setTemplate("VueViews/Vue");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class ConstructionConsentOwner extends mfBaseModel {
|
||||
$model = new ConstructionConsentOwner();
|
||||
|
||||
$table_fields = [
|
||||
"constructionconsent_id", "title", "firstname", "lastname", "street", "zip", "city", "country",
|
||||
"constructionconsent_id", "title", "company", "firstname", "lastname", "street", "zip", "city", "country",
|
||||
"phone", "phone2", "birthdate", "fax", "email", "status", "result", "create_by","edit_by","create","edit"
|
||||
];
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ class ConstructionConsentOwnerController extends mfBaseController
|
||||
$data["constructionconsent_id"] = $cc_id;
|
||||
$data["title"] = $r->title;
|
||||
$data["firstname"] = $r->firstname;
|
||||
$data["company"] = $r->company;
|
||||
$data["lastname"] = $r->lastname;
|
||||
$data["street"] = $r->street;
|
||||
$data["zip"] = $r->zip;
|
||||
@@ -123,7 +124,7 @@ class ConstructionConsentOwnerController extends mfBaseController
|
||||
} else {
|
||||
$journal = ConstructionConsentJournal::create([
|
||||
"constructionconsent_id" => $cc->id,
|
||||
"text" => "Eigentümer " . $item->firstname . " " . $item->lastname . " wurde hinzugefügt"
|
||||
"text" => "Eigentümer " . ($item->company ? $item->company : $item->firstname . " " . $item->lastname) . " wurde hinzugefügt"
|
||||
]);
|
||||
$journal->save();
|
||||
|
||||
@@ -151,7 +152,7 @@ class ConstructionConsentOwnerController extends mfBaseController
|
||||
}
|
||||
|
||||
foreach($owner->files as $file) {
|
||||
$file->file->delete();
|
||||
if ($file->file) $file->file->delete();
|
||||
$file->delete();
|
||||
}
|
||||
|
||||
|
||||
@@ -237,4 +237,179 @@ class ConstructionConsentProject extends mfBaseModel {
|
||||
//var_dump($filter, $where);exit;
|
||||
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;
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$sql = "SELECT 1
|
||||
FROM ConstructionConsentOwner cco
|
||||
JOIN ConstructionConsent cc ON cc.id = cco.constructionconsent_id
|
||||
WHERE cc.constructionconsentproject_id = $projectId
|
||||
AND (
|
||||
(
|
||||
(
|
||||
(cco.company IS NOT NULL AND TRIM(cco.company) <> '') OR
|
||||
(
|
||||
(cco.firstname IS NOT NULL AND TRIM(cco.firstname) <> '') AND
|
||||
(cco.lastname IS NOT NULL AND TRIM(cco.lastname) <> '')
|
||||
)
|
||||
) OR
|
||||
(cco.city IS NULL OR TRIM(cco.city) = '')
|
||||
)
|
||||
AND
|
||||
(
|
||||
(
|
||||
(LOWER(cco.country) = 'österreich' OR LOWER(cco.country) = 'austria') AND
|
||||
(cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{4}')
|
||||
)
|
||||
OR
|
||||
/* For other countries: ZIP must not be empty */
|
||||
(
|
||||
(LOWER(cco.country) != 'österreich' AND LOWER(cco.country) != 'austria') AND
|
||||
(cco.zip IS NULL OR TRIM(cco.zip) = '')
|
||||
)
|
||||
)
|
||||
)
|
||||
LIMIT 1";
|
||||
|
||||
$res = $db->query($sql);
|
||||
|
||||
return ($res->num_rows > 0);
|
||||
}
|
||||
|
||||
public static function getFaultyOwnerEntries($projectId = null) {
|
||||
$faultyEntries = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$whereClause = "";
|
||||
if (!empty($projectId)) {
|
||||
$projectId = (int)$projectId;
|
||||
$whereClause = "WHERE cc.constructionconsentproject_id = $projectId";
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
cco.id as owner_id,
|
||||
cco.firstname,
|
||||
cco.lastname,
|
||||
cco.title,
|
||||
cco.street,
|
||||
cco.zip,
|
||||
cco.city,
|
||||
cco.country,
|
||||
cco.email,
|
||||
cco.phone,
|
||||
cco.status,
|
||||
cco.result,
|
||||
cc.id as consent_id,
|
||||
cc.name as building_name,
|
||||
cc.object_type,
|
||||
ccp.id as project_id,
|
||||
ccp.name as project_name,
|
||||
cco.create,
|
||||
cco.edit
|
||||
FROM
|
||||
ConstructionConsentOwner cco
|
||||
JOIN
|
||||
ConstructionConsent cc ON cc.id = cco.constructionconsent_id
|
||||
JOIN
|
||||
ConstructionConsentProject ccp ON ccp.id = cc.constructionconsentproject_id
|
||||
$whereClause
|
||||
AND (
|
||||
(
|
||||
(cco.company IS NOT NULL AND TRIM(cco.company) <> '') OR
|
||||
(
|
||||
(cco.firstname IS NOT NULL AND TRIM(cco.firstname) <> '') AND
|
||||
(cco.lastname IS NOT NULL AND TRIM(cco.lastname) <> '')
|
||||
)
|
||||
) OR
|
||||
(cco.city IS NULL OR TRIM(cco.city) = '')
|
||||
) -- Fixed parenthesis balance here
|
||||
AND (
|
||||
(
|
||||
(LOWER(cco.country) = 'österreich' OR LOWER(cco.country) = 'austria') AND
|
||||
(cco.zip IS NULL OR cco.zip NOT REGEXP '^[0-9]{4}')
|
||||
)
|
||||
OR
|
||||
(
|
||||
(LOWER(cco.country) != 'österreich' AND LOWER(cco.country) != 'austria') AND
|
||||
(cco.zip IS NULL OR TRIM(cco.zip) = '')
|
||||
)
|
||||
)
|
||||
ORDER BY
|
||||
ccp.name, cc.name, cco.lastname, cco.firstname
|
||||
|
||||
";
|
||||
|
||||
$res = $db->query($sql);
|
||||
|
||||
while($data = $res->fetch_assoc()) {
|
||||
$errors = [];
|
||||
|
||||
// Check if company is empty, OR if both firstname and lastname are empty
|
||||
if (empty(trim($data['company']))) {
|
||||
if (empty(trim($data['firstname']))) {
|
||||
$errors[] = 'firstname';
|
||||
}
|
||||
if (empty(trim($data['lastname']))) {
|
||||
$errors[] = 'lastname';
|
||||
}
|
||||
}
|
||||
|
||||
// Existing city check (assuming it's still relevant for faulty entries)
|
||||
if (empty(trim($data['city']))) {
|
||||
$errors[] = 'city';
|
||||
}
|
||||
|
||||
// Check ZIP based on country
|
||||
$isAustria = (strtolower($data['country']) === 'österreich' || strtolower($data['country']) === 'austria');
|
||||
|
||||
if ($isAustria && (!isset($data['zip']) || !preg_match('/^[0-9]{4}$/', $data['zip']))) {
|
||||
$errors[] = 'zip';
|
||||
} elseif (!$isAustria && empty(trim($data['zip']))) {
|
||||
$errors[] = 'zip';
|
||||
}
|
||||
|
||||
$faultyEntries[] = [
|
||||
'owner_id' => $data['owner_id'],
|
||||
'consent_id' => $data['consent_id'],
|
||||
'project_id' => $data['project_id'],
|
||||
'project_name' => $data['project_name'],
|
||||
'building_name' => $data['building_name'],
|
||||
'object_type' => $data['object_type'],
|
||||
'title' => $data['title'],
|
||||
'firstname' => $data['firstname'],
|
||||
'lastname' => $data['lastname'],
|
||||
'street' => $data['street'],
|
||||
'zip' => $data['zip'],
|
||||
'city' => $data['city'],
|
||||
'country' => $data['country'],
|
||||
'email' => $data['email'],
|
||||
'phone' => $data['phone'],
|
||||
'status' => $data['status'],
|
||||
'result' => $data['result'],
|
||||
'create' => $data['create'],
|
||||
'edit' => $data['edit'],
|
||||
'errors' => $errors
|
||||
];
|
||||
}
|
||||
|
||||
return $faultyEntries;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user