Browse code

Update newly introduced unit code to allow again for overcapacity booking.

Benjamin Roth authored on03/09/2025 10:25:55
Showing1 changed files
... ...
@@ -223,8 +223,8 @@ class SlotAjaxController extends AbstractController
223 223
             'lage' => $arrLage,
224 224
             'ernteart' => $arrErnteart,
225 225
             'buchen' => [
226
-                'buchbar' => (boolean) ($Slot->behaelter*3 > $intReservedBehaelter),
227
-                'behaelter' => range(min($intAvailableBehaelter,1),$Slot->behaelter*3-$intReservedBehaelter),
226
+                'buchbar' => (boolean) ($Slot->behaelter*1.5 > $intReservedBehaelter),
227
+                'behaelter' => range(min($intAvailableBehaelter,1),$Slot->behaelter*1.5-$intReservedBehaelter),
228 228
                 'units' => $this->getAvailableUnitsForCapacity($intAvailableBehaelter),
229 229
                 'sorten' => $arrSorten,
230 230
                 'lage' => $arrLage,
... ...
@@ -457,7 +457,7 @@ class SlotAjaxController extends AbstractController
457 457
             'standort' => $Slot->getRelated('pid'),
458 458
             'buchen' => [
459 459
                 'buchbar' => (boolean) $intAvailableBehaelter,
460
-                'behaelter' => range(min($intAvailableBehaelter,1),$Slot->behaelter*3-$Slot->getReservedBehaelter()+$Booking->behaelter),
460
+                'behaelter' => range(min($intAvailableBehaelter,1),$Slot->behaelter*1.5-$Slot->getReservedBehaelter()+$Booking->behaelter),
461 461
                 'units' => $this->getAvailableUnitsForCapacity($intAvailableBehaelter),
462 462
                 'sorten' => $arrSortenAvailable,
463 463
                 'ernteart' => $arrErnteartAvailable,
... ...
@@ -504,19 +504,23 @@ class SlotAjaxController extends AbstractController
504 504
             return new Response('Missing parameter',412);
505 505
         }
506 506
 
507
+        // recompute the base units
508
+        $unitId = (int) Input::post('unit_id');
509
+        $unitAmount = (int) Input::post('unit_amount');
510
+        $multiplier = 1;
511
+        if ($unitId > 0) {
512
+            if (($u = WeinanlieferungUnitModel::findByPk($unitId)) !== null) {
513
+                $multiplier = max(1, (int) $u->multiplier);
514
+            }
515
+        }
516
+
517
+        $intBehaelter = $unitAmount > 0 ? $unitAmount * $multiplier : (int) Input::post('behaelter');
518
+
507 519
         // Form validation and unit capacity
508 520
         if (($Slot = WeinanlieferungSlotsModel::findByPk($_REQUEST['id'])) !== null)
509 521
         {
510
-            $unitId = (int) Input::post('unit_id');
511
-            $unitAmount = (int) Input::post('unit_amount');
512
-            $multiplier = 1;
513
-            if ($unitId > 0) {
514
-                if (($u = WeinanlieferungUnitModel::findByPk($unitId)) !== null) {
515
-                    $multiplier = max(1, (int) $u->multiplier);
516
-                }
517
-            }
518
-            $baseUnitsRequested = $unitAmount > 0 ? $unitAmount * $multiplier : (int) Input::post('behaelter');
519
-            if ($baseUnitsRequested > $Slot->behaelter*3 - $Slot->getReservedBehaelter())
522
+
523
+            if ($intBehaelter > $Slot->behaelter*1.5 - $Slot->getReservedBehaelter())
520 524
             {
521 525
                 return $this->renderDetails(false,sprintf('<div class="toast toast--danger mx-0">Fehler: Es sind mittlerweile nur noch %s Behälter verfügbar.</div>',$Slot->getAvailableBehaelter()));
522 526
             }
... ...
@@ -573,7 +577,7 @@ class SlotAjaxController extends AbstractController
573 577
 
574 578
         $time = time();
575 579
 
576
-        if (Input::post('behaelter') > $Slot->behaelter - $Slot->getReservedBehaelter())
580
+        if ($intBehaelter > $Slot->behaelter - $Slot->getReservedBehaelter())
577 581
         {
578 582
             $arrData['approved'] = '';
579 583
             $arrData['approved_on'] = 0;
... ...
@@ -583,21 +587,11 @@ class SlotAjaxController extends AbstractController
583 587
         }
584 588
 
585 589
         // Determine fields to store
586
-        $unitId = (int) Input::post('unit_id');
587
-        $unitAmount = (int) Input::post('unit_amount');
588
-        $multiplier = 1;
589
-        if ($unitId > 0) {
590
-            if (($u = WeinanlieferungUnitModel::findByPk($unitId)) !== null) {
591
-                $multiplier = max(1, (int) $u->multiplier);
592
-            }
593
-        }
594
-        $baseUnits = $unitAmount > 0 ? $unitAmount * $multiplier : (int) Input::post('behaelter');
595
-
596 590
         $arrData = array_merge($arrData,[
597 591
             'pid' => $_REQUEST['id'],
598 592
             'tstamp' => $time,
599 593
             'uid' => FrontendUser::getInstance()->id,
600
-            'behaelter' => $baseUnits,
594
+            'behaelter' => $intBehaelter,
601 595
             'unit_id' => $unitId,
602 596
             'unit_amount' => $unitAmount,
603 597
             'sorten' => $arrSorten,
... ...
@@ -656,20 +650,23 @@ class SlotAjaxController extends AbstractController
656 650
             }
657 651
         }
658 652
 
653
+        // recompute base units
654
+        $unitId = (int) Input::post('unit_id');
655
+        $unitAmount = (int) Input::post('unit_amount');
656
+        $multiplier = 1;
657
+        if ($unitId > 0) {
658
+            if (($u = WeinanlieferungUnitModel::findByPk($unitId)) !== null) {
659
+                $multiplier = max(1, (int) $u->multiplier);
660
+            }
661
+        }
662
+
663
+        $intBehaelter = $unitAmount > 0 ? $unitAmount * $multiplier : (int) Input::post('behaelter');
664
+
659 665
         // Form validation
660 666
         /** @var WeinanlieferungSlotsModel $Slot */
661 667
         if (($Slot = $Reservation->getRelated('pid')) !== null)
662 668
         {
663
-            $unitId = (int) Input::post('unit_id');
664
-            $unitAmount = (int) Input::post('unit_amount');
665
-            $multiplier = 1;
666
-            if ($unitId > 0) {
667
-                if (($u = WeinanlieferungUnitModel::findByPk($unitId)) !== null) {
668
-                    $multiplier = max(1, (int) $u->multiplier);
669
-                }
670
-            }
671
-            $baseUnitsRequested = $unitAmount > 0 ? $unitAmount * $multiplier : (int) Input::post('behaelter');
672
-            if ($baseUnitsRequested > $Slot->behaelter*3 - $Slot->getReservedBehaelter() + $Reservation->behaelter)
669
+            if ($intBehaelter > $Slot->behaelter*1.5 - $Slot->getReservedBehaelter() + $Reservation->behaelter)
673 670
             {
674 671
                 return $this->renderBooking(false,sprintf('<div class="toast toast--danger mx-0">Fehler: Es sind mittlerweile nur noch %s Behälter verfügbar.</div>',$Slot->getAvailableBehaelter()+$Reservation->behaelter));
675 672
             }
... ...
@@ -723,7 +720,7 @@ class SlotAjaxController extends AbstractController
723 720
 
724 721
         $time = time();
725 722
 
726
-        if (Input::post('behaelter') > $Slot->behaelter - $Slot->getReservedBehaelter() + $Reservation->behaelter)
723
+        if ($intBehaelter > $Slot->behaelter - $Slot->getReservedBehaelter() + $Reservation->behaelter)
727 724
         {
728 725
             $Reservation->approved = '';
729 726
             $Reservation->approved_on = 0;
... ...
@@ -733,16 +730,7 @@ class SlotAjaxController extends AbstractController
733 730
         }
734 731
 
735 732
         $Reservation->tstamp = $time;
736
-        // recompute base units
737
-        $unitId = (int) Input::post('unit_id');
738
-        $unitAmount = (int) Input::post('unit_amount');
739
-        $multiplier = 1;
740
-        if ($unitId > 0) {
741
-            if (($u = WeinanlieferungUnitModel::findByPk($unitId)) !== null) {
742
-                $multiplier = max(1, (int) $u->multiplier);
743
-            }
744
-        }
745
-        $Reservation->behaelter = $unitAmount > 0 ? $unitAmount * $multiplier : (int) Input::post('behaelter');
733
+        $Reservation->behaelter = $intBehaelter;
746 734
         $Reservation->unit_id = $unitId;
747 735
         $Reservation->unit_amount = $unitAmount;
748 736
         $Reservation->sorten = $arrSorten;