enabled creating interest preorders without any wohneinheit

This commit is contained in:
Luca Haid
2025-07-15 14:03:23 +02:00
parent 26c0afce5d
commit 6d7260f917
2 changed files with 112 additions and 88 deletions
+13 -5
View File
@@ -197,13 +197,21 @@
if (!addressForm.housenumber) return;
isLoading.value = true;
try {
const params = { ...addressForm, ...areaIdentifierParams.value, format: 'flat' };
const params = { ...addressForm, ...areaIdentifierParams.value, format: 'flat', orderType: orderType.value };
const response = await api.get('/findAddress', { params });
const addresses = (response.data?.addresses || []).filter(a => a.preorderTypes?.includes(orderType.value));
const addresses = response.data?.addresses || [];
if (addresses.length === 0) { currentStep.value = 'noOrderPossible'; }
else if (addresses.length === 1) { selectAddress(addresses[0]); }
else { units.value = addresses; addressStep.value = 'unit'; }
if (addresses.length === 0) {
currentStep.value = 'noOrderPossible';
} else if (addresses.length === 1) {
// This path is taken for 'interest' orders (which return one building-level address)
// and for 'order' orders with only a single available unit.
selectAddress(addresses[0]);
} else {
// This path is only taken for 'order' types when multiple units are available.
units.value = addresses;
addressStep.value = 'unit';
}
} catch (e) { handleError(e, 'Adresse konnte nicht verifiziert werden.'); }
finally { isLoading.value = false; }
}
@@ -118,17 +118,34 @@ class PreorderIFrameModel extends mfBaseModel
$results = $this->db->fetch_all_assoc($this->db->query($query));
if (empty($results)) return [];
$orderType = $params['orderType'] ?? 'order';
// For 'interest' order type, return a single entry for the whole building.
if ($orderType === 'interest') {
$representativeAddress = $this->formatAddressRow($results[0]);
$representativeAddress['wohneinheit_id'] = null; // Critical: No specific unit
$representativeAddress['oaid'] = $results[0]['oaid']; // Use building OAID
$representativeAddress['showText'] = "Gesamtes Gebäude";
$representativeAddress['preorderTypes'] = ['interest'];
return [$representativeAddress]; // Return one item, so frontend proceeds directly.
}
// Original logic for 'order' type
$addresses = [];
$topCounter = 1;
if (count($results) > 1 && $results[0]['wohneinheit_id'] !== null) {
foreach ($results as $row) {
$addresses[] = array_merge($this->formatAddressRow($row), [
'showText' => $this->buildShowText($row, $topCounter++)
]);
$address = $this->formatAddressRow($row);
$address['showText'] = $this->buildShowText($row, $topCounter++);
$address['preorderTypes'] = ['order'];
$addresses[] = $address;
}
} else {
$addresses[] = $this->formatAddressRow($results[0]);
// Single unit or building without units
$address = $this->formatAddressRow($results[0]);
$address['preorderTypes'] = ['order'];
$addresses[] = $address;
}
return $addresses;
@@ -139,7 +156,7 @@ class PreorderIFrameModel extends mfBaseModel
return [
'oaid' => $row['unit_oaid'] ?? $row['oaid'],
'street' => $row['street'],
'housenumber' => $row['hausnummer'],
'housenumber' => $row['housenumber'],
'hausnummer_id' => $row['hausnummer_id'],
'wohneinheit_id' => $row['wohneinheit_id'],
'building_type' => intval($row['building_type']),
@@ -151,7 +168,6 @@ class PreorderIFrameModel extends mfBaseModel
'zusatz' => $row['zusatz'],
'building_unit_count' => $row['building_unit_count'],
'showText' => $this->buildShowText($row, 1),
'preorderTypes' => ['order', 'interest'] // Can be used for both
];
}