... | ... |
@@ -67,7 +67,7 @@ |
67 | 67 |
<select id="res-behaelter" name="behaelter" required> |
68 | 68 |
<option value="">-</option> |
69 | 69 |
{% for option in buchen.behaelter %} |
70 |
- {% if option > slot.behaelter %} |
|
70 |
+ {% if option > slot.behaelterAvailable %} |
|
71 | 71 |
<option value="{{ option }}"{{ buchung.amount == option ? ' selected' : '' }}>{{ option }} ({{ 'MSC.wa_overbooking'|trans([], 'contao_default') }})</option> |
72 | 72 |
{% else %} |
73 | 73 |
<option value="{{ option }}"{{ buchung.amount == option ? ' selected' : '' }}>{{ option }}</option> |
... | ... |
@@ -298,6 +298,7 @@ class SlotAjaxController extends AbstractController |
298 | 298 |
|
299 | 299 |
$intAvailableBehaelter = max(0,$Slot->getAvailableBehaelter()); |
300 | 300 |
$intBookableBehaelter = $Slot->getAvailableBehaelter() + $Slot->getOvercapacityBehaelter(); |
301 |
+ $intUnitAmount = $intBookableBehaelter+$Booking->behaelter; |
|
301 | 302 |
$arrUnits = []; |
302 | 303 |
|
303 | 304 |
if (($Site = $Slot->getRelated('pid')) !== null) |
... | ... |
@@ -310,6 +311,16 @@ class SlotAjaxController extends AbstractController |
310 | 311 |
} |
311 | 312 |
} |
312 | 313 |
|
314 |
+ if ($Booking->unit > 0 && \in_array($Booking->unit, array_keys($arrUnits))) |
|
315 |
+ { |
|
316 |
+ if (($Unit = WeinanlieferungUnitsModel::findByPk($Booking->unit)) === null) |
|
317 |
+ { |
|
318 |
+ return new Response('Could not load unit data', 500); |
|
319 |
+ } |
|
320 |
+ |
|
321 |
+ $intUnitAmount = floor($intUnitAmount / max(1, $Unit->containers)); |
|
322 |
+ } |
|
323 |
+ |
|
313 | 324 |
} |
314 | 325 |
|
315 | 326 |
$arrData = array_merge($arrData,[ |
... | ... |
@@ -317,13 +328,13 @@ class SlotAjaxController extends AbstractController |
317 | 328 |
'id' => $Booking->id, |
318 | 329 |
'slot' => array_merge($Slot->row(),[ |
319 | 330 |
'anmerkungen' => $insertTagService->replace($Slot->anmerkungen ?? ''), |
320 |
- 'behaelterAvailable' => $intAvailableBehaelter, |
|
331 |
+ 'behaelterAvailable' => $intAvailableBehaelter + $Booking->behaelter, |
|
321 | 332 |
]), |
322 | 333 |
'buchung' => $Booking->row(), |
323 | 334 |
'standort' => $Slot->getRelated('pid'), |
324 | 335 |
'buchen' => [ |
325 | 336 |
'buchbar' => (boolean) $intBookableBehaelter, |
326 |
- 'behaelter' => range(min($intBookableBehaelter,1),$intBookableBehaelter+$Booking->behaelter), |
|
337 |
+ 'behaelter' => $intUnitAmount ? range(1,$intUnitAmount) : [], |
|
327 | 338 |
'units' => $arrUnits, |
328 | 339 |
] |
329 | 340 |
]); |
... | ... |
@@ -556,7 +567,6 @@ class SlotAjaxController extends AbstractController |
556 | 567 |
|
557 | 568 |
protected function renderAvailableUnitAmount(): Response |
558 | 569 |
{ |
559 |
- // Todo: Respect the overcapacity feature |
|
560 | 570 |
if (empty($_REQUEST['id'])) |
561 | 571 |
{ |
562 | 572 |
return new Response('Required parameter missing',412); |
... | ... |
@@ -569,6 +579,11 @@ class SlotAjaxController extends AbstractController |
569 | 579 |
|
570 | 580 |
$intAvailableBehaelter = max(0,$Slot->getAvailableBehaelter()); |
571 | 581 |
$intAmount = $intAvailableBehaelter; |
582 |
+ if ($intAvailableBehaelter > 0) |
|
583 |
+ { |
|
584 |
+ $intOvercapacityBehaelter = $Slot->getOvercapacityBehaelter(); |
|
585 |
+ $intAmount += $intOvercapacityBehaelter; |
|
586 |
+ } |
|
572 | 587 |
|
573 | 588 |
if (!empty($_REQUEST['unit']) && intval($_REQUEST['unit']) > 0) |
574 | 589 |
{ |
... | ... |
@@ -584,7 +599,12 @@ class SlotAjaxController extends AbstractController |
584 | 599 |
<option value=\"\">-</option>\n"; |
585 | 600 |
for ($i = 1; $i <= $intAmount; $i++) |
586 | 601 |
{ |
587 |
- $strOutput .= "<option value=\"$i\">$i</option>\n"; |
|
602 |
+ if ($intAvailableBehaelter < $i) |
|
603 |
+ { |
|
604 |
+ $strOutput .= "<option value=\"$i\">$i (".$this->translator->trans('MSC.wa_overbooking',[], 'contao_default').")</option>\n"; |
|
605 |
+ } else { |
|
606 |
+ $strOutput .= "<option value=\"$i\">$i</option>\n"; |
|
607 |
+ } |
|
588 | 608 |
} |
589 | 609 |
$strOutput .= "</select>\n"; |
590 | 610 |
|
... | ... |
@@ -593,7 +613,6 @@ class SlotAjaxController extends AbstractController |
593 | 613 |
|
594 | 614 |
protected function renderAvailableBookingUnitAmount(): Response |
595 | 615 |
{ |
596 |
- // Todo: Respect the overcapacity feature |
|
597 | 616 |
if (empty($_REQUEST['id'])) |
598 | 617 |
{ |
599 | 618 |
return new Response('Required parameter missing',412); |
... | ... |
@@ -606,6 +625,11 @@ class SlotAjaxController extends AbstractController |
606 | 625 |
|
607 | 626 |
$intAvailableBehaelter = max(0,$Slot->getAvailableBehaelter())+$Reservation->behaelter; |
608 | 627 |
$intAmount = $intAvailableBehaelter; |
628 |
+ if ($intAvailableBehaelter > 0) |
|
629 |
+ { |
|
630 |
+ $intOvercapacityBehaelter = $Slot->getOvercapacityBehaelter(); |
|
631 |
+ $intAmount += $intOvercapacityBehaelter; |
|
632 |
+ } |
|
609 | 633 |
|
610 | 634 |
if (!empty($_REQUEST['unit']) && intval($_REQUEST['unit']) > 0) |
611 | 635 |
{ |
... | ... |
@@ -621,7 +645,12 @@ class SlotAjaxController extends AbstractController |
621 | 645 |
<option value=\"\">-</option>\n"; |
622 | 646 |
for ($i = 1; $i <= $intAmount; $i++) |
623 | 647 |
{ |
624 |
- $strOutput .= "<option value=\"$i\">$i</option>\n"; |
|
648 |
+ if ($intAvailableBehaelter < $i) |
|
649 |
+ { |
|
650 |
+ $strOutput .= "<option value=\"$i\">$i (".$this->translator->trans('MSC.wa_overbooking',[], 'contao_default').")</option>\n"; |
|
651 |
+ } else { |
|
652 |
+ $strOutput .= "<option value=\"$i\">$i</option>\n"; |
|
653 |
+ } |
|
625 | 654 |
} |
626 | 655 |
$strOutput .= "</select>\n"; |
627 | 656 |
|
... | ... |
@@ -146,11 +146,28 @@ class WeinanlieferungSlotsModel extends Model |
146 | 146 |
$intReserved += $intOffset; |
147 | 147 |
} |
148 | 148 |
|
149 |
- return (int) $this->behaelter + $intOvercapacity - $intReserved; |
|
149 |
+ return (int) max(0,$this->behaelter + $intOvercapacity - $intReserved); |
|
150 | 150 |
} |
151 | 151 |
|
152 |
- public function getOvercapacityBehaelter() |
|
152 |
+ public function getOvercapacityBehaelter(bool $blnGross=false) |
|
153 | 153 |
{ |
154 |
- return round($this->behaelter/100*$this->overcapacity); |
|
154 |
+ $intOvercapacity = round($this->behaelter/100*$this->overcapacity); |
|
155 |
+ |
|
156 |
+ if ($blnGross) |
|
157 |
+ { |
|
158 |
+ return $intOvercapacity; |
|
159 |
+ } |
|
160 |
+ |
|
161 |
+ /** @var Connection $db */ |
|
162 |
+ $db = Controller::getContainer()->get('database_connection'); |
|
163 |
+ |
|
164 |
+ $ReservedBehaelter = $db->prepare("SELECT SUM(behaelter) FROM tl_vr_wa_reservation WHERE pid = ?") |
|
165 |
+ ->executeQuery([$this->id]); |
|
166 |
+ |
|
167 |
+ $intReserved = $ReservedBehaelter->fetchOne(); |
|
168 |
+ |
|
169 |
+ $intAmount = min($intOvercapacity,$this->behaelter+$intOvercapacity-$intReserved); |
|
170 |
+ |
|
171 |
+ return $intAmount; |
|
155 | 172 |
} |
156 | 173 |
} |