Browse code

Adjust be booking list and make use of new units

Benjamin Roth authored on25/07/2024 16:45:51
Showing9 changed files
... ...
@@ -97,7 +97,7 @@ $GLOBALS['TL_DCA']['tl_vr_wa_reservation'] = array
97 97
     'palettes' => array
98 98
     (
99 99
         '__selector__' => array(),
100
-        'default' => 'pid,uid,behaelter,sorten,lage,ernteart,upload'
100
+        'default' => 'pid,uid,unit,amount,behaelter,upload'
101 101
     ),
102 102
 
103 103
     // Subpalettes
... ...
@@ -146,11 +146,42 @@ $GLOBALS['TL_DCA']['tl_vr_wa_reservation'] = array
146 146
             'sql'       => "blob NULL",
147 147
             'relation'   => array('type' => 'hasMany', 'load' => 'lazy', 'table'=>'tl_vr_wa_lage')
148 148
         ),
149
+        'unit' => array
150
+        (
151
+            'exclude'                 => true,
152
+            'inputType'               => 'select',
153
+            'eval'                    => array
154
+            (
155
+                'mandatory' => false,
156
+                'includeBlankOption' => true,
157
+                'blankOptionLabel' => &$GLOBALS['TL_LANG']['MSC']['wa_container'],
158
+                'tl_class' => 'clr w50',
159
+            ),
160
+            'sql' => "int(10) unsigned NOT NULL default '0'",
161
+            'relation' => array
162
+            (
163
+                'table' => 'tl_vr_wa_units',
164
+                'load' => 'lazy',
165
+                'type' => 'hasOne',
166
+                'field' => 'id'
167
+            )
168
+        ),
169
+        'amount'         => array
170
+        (
171
+            'exclude'                 => true,
172
+            'inputType'               => 'text',
173
+            'eval'       => array
174
+            (
175
+                'rgxp'=>'natural',
176
+                'tl_class'=>'w50',
177
+            ),
178
+            'sql'        => "smallint(3) unsigned NOT NULL default 0",
179
+        ),
149 180
         'behaelter'         => array
150 181
         (
151 182
             'exclude'                 => true,
152 183
             'inputType'               => 'text',
153
-            'eval'       => array('rgxp'=>'natural','tl_class'=>'w50'),
184
+            'eval'       => array('rgxp'=>'natural','tl_class'=>'clr w50','readonly'=>true),
154 185
             'sql'        => "smallint(3) unsigned NOT NULL default 0",
155 186
         ),
156 187
         'sorten'       => array
... ...
@@ -88,7 +88,7 @@ $GLOBALS['TL_DCA']['tl_vr_wa_slottypes'] = array
88 88
     // Palettes
89 89
     'palettes' => array
90 90
     (
91
-        'default' => '{title_legend},title;{config_legend},duration,containers,units;{expert_legend},default'
91
+        'default' => '{title_legend},title;{config_legend},duration,containers;{expert_legend},default'
92 92
     ),
93 93
 
94 94
     // Subpalettes
... ...
@@ -157,19 +157,6 @@ $GLOBALS['TL_DCA']['tl_vr_wa_slottypes'] = array
157 157
             ),
158 158
             'sql'                     => "int(4) NOT NULL default 0"
159 159
         ),
160
-        'units' => array
161
-        (
162
-            'exclude'                 => true,
163
-            'inputType'               => 'checkbox',
164
-            'foreignKey'              => "tl_vr_wa_units.title",
165
-            'eval'                    => array
166
-            (
167
-                'mandatory' => false,
168
-                'multiple'  => true,
169
-                'tl_class' => 'clr'
170
-            ),
171
-            'sql'                     => "blob NULL"
172
-        ),
173 160
         'default' => array
174 161
         (
175 162
             'exclude'                 => true,
... ...
@@ -110,7 +110,7 @@ $GLOBALS['TL_DCA']['tl_vr_wa_standort'] = array
110 110
     'palettes' => array
111 111
     (
112 112
         '__selector__' => ['nc_enable'],
113
-        'default' => '{title_legend},title;{notification_legend},nc_enable'
113
+        'default' => '{title_legend},title;{units_legend},units;{notification_legend},nc_enable'
114 114
     ),
115 115
 
116 116
     // Subpalettes
... ...
@@ -143,6 +143,24 @@ $GLOBALS['TL_DCA']['tl_vr_wa_standort'] = array
143 143
             ),
144 144
             'sql'                     => "varchar(255) NOT NULL default ''"
145 145
         ),
146
+        'units' => array
147
+        (
148
+            'exclude'                 => true,
149
+            'inputType'               => 'checkbox',
150
+            'foreignKey'              => "tl_vr_wa_units.title",
151
+            'eval'                    => array
152
+            (
153
+                'mandatory' => false,
154
+                'multiple'  => true,
155
+                'tl_class' => 'clr'
156
+            ),
157
+            'sql'                     => "blob NULL",
158
+            'relation' => array
159
+            (
160
+                'type' => 'hasMany',
161
+                'load' => 'lazy'
162
+            )
163
+        ),
146 164
         'nc_enable' => array
147 165
         (
148 166
             'exclude'                 => true,
... ...
@@ -12,6 +12,10 @@ $GLOBALS['TL_LANG']['tl_vr_wa_reservation']['pid'][0] = 'Zeitslot';
12 12
 $GLOBALS['TL_LANG']['tl_vr_wa_reservation']['pid'][1] = 'Der gebuchte Zeitslot.';
13 13
 $GLOBALS['TL_LANG']['tl_vr_wa_reservation']['behaelter'][0] = 'Behälteranzahl';
14 14
 $GLOBALS['TL_LANG']['tl_vr_wa_reservation']['behaelter'][1] = 'Die Anzahl an Behälter, die der Winzer anliefert.';
15
+$GLOBALS['TL_LANG']['tl_vr_wa_reservation']['amount'][0] = 'Anzahl';
16
+$GLOBALS['TL_LANG']['tl_vr_wa_reservation']['amount'][1] = 'Die Anzahl der ausgewählten Einheit, die der Winzer anliefert.';
17
+$GLOBALS['TL_LANG']['tl_vr_wa_reservation']['unit'][0] = 'Behältereinheit';
18
+$GLOBALS['TL_LANG']['tl_vr_wa_reservation']['unit'][1] = 'Die Behältereinheit, die der Winzer anliefert.';
15 19
 $GLOBALS['TL_LANG']['tl_vr_wa_reservation']['sorten'][0] = 'Sorten';
16 20
 $GLOBALS['TL_LANG']['tl_vr_wa_reservation']['sorten'][1] = 'Die Sorten, die der Winzer anliefert.';
17 21
 $GLOBALS['TL_LANG']['tl_vr_wa_reservation']['lage'][0] = 'Lage';
... ...
@@ -18,6 +18,8 @@ $GLOBALS['TL_LANG']['tl_vr_wa_slot']['behaelter'][0] = 'Behälter';
18 18
 $GLOBALS['TL_LANG']['tl_vr_wa_slot']['behaelter'][1] = 'Anzahl der Behälter, die verarbeitet werden können.';
19 19
 $GLOBALS['TL_LANG']['tl_vr_wa_slot']['lage'][0] = 'Lage';
20 20
 $GLOBALS['TL_LANG']['tl_vr_wa_slot']['lage'][1] = 'Lage der angelieferten Reben.';
21
+$GLOBALS['TL_LANG']['tl_vr_wa_slot']['units'][0] = 'Zusätzliche Container-Einheiten';
22
+$GLOBALS['TL_LANG']['tl_vr_wa_slot']['units'][1] = 'Zusätzlich wählbare Behältereinheiten für die Slotbuchung.';
21 23
 $GLOBALS['TL_LANG']['tl_vr_wa_slot']['leseart'][0] = 'Leseart';
22 24
 $GLOBALS['TL_LANG']['tl_vr_wa_slot']['leseart'][1] = 'Die verwendete Leseart.';
23 25
 $GLOBALS['TL_LANG']['tl_vr_wa_slot']['sorten'][0] = 'Rebsorten';
... ...
@@ -10,12 +10,15 @@
10 10
 
11 11
 $GLOBALS['TL_LANG']['tl_vr_wa_standort']['title'][0] = 'Titel';
12 12
 $GLOBALS['TL_LANG']['tl_vr_wa_standort']['title'][1] = 'Der Name des Anlieferungs-Standorts.';
13
+$GLOBALS['TL_LANG']['tl_vr_wa_standort']['units'][0] = 'Zusätzliche Behälter-Einheiten';
14
+$GLOBALS['TL_LANG']['tl_vr_wa_standort']['units'][1] = 'Zusätzlich wählbare Behältereinheiten für die Slotbuchung.';
13 15
 $GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_enable'][0] = 'Benachrichtigungen aktivieren';
14 16
 $GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_enable'][1] = 'Ermöglicht das Versenden von Benachrichtigungen beim Veröffentlichen neuer Nachrichten.';
15 17
 $GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_notification'][0] = 'Benachrichtigung';
16 18
 $GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_notification'][1] = 'Die zu versendende Benachrichtigung.';
17 19
 
18 20
 $GLOBALS['TL_LANG']['tl_vr_wa_standort']['title_legend'] = 'Standort';
21
+$GLOBALS['TL_LANG']['tl_vr_wa_standort']['units_legend'] = 'Einheiten-Einstellungen';
19 22
 $GLOBALS['TL_LANG']['tl_vr_wa_standort']['notification_legend'] = 'Benachrichtigung-Einstellungen';
20 23
 
21 24
 $GLOBALS['TL_LANG']['tl_vr_wa_standort']['rebsorte'] = 'Rebsorten';
... ...
@@ -50,19 +50,15 @@
50 50
                                             <div class="t-label">Standort</div>
51 51
                                             {{ standort.standort }}
52 52
                                         </div>
53
-                                        <div class="col-3">
53
+                                        <div class="col">
54 54
                                             <div class="t-label">Verfügbare Behälterkapazität</div>
55 55
                                             {{ bookings.behaelterAvailable }}
56 56
                                         </div>
57
-                                        <div class="col">
58
-                                            <div class="t-label">Verarbeitete Sorten</div>
59
-                                            {{ bookings.sorten|join(', ') }}
60
-                                        </div>
61 57
                                     </h3>
62 58
                                     <div class="bookings u-row-striped">
63 59
                                         {% for booking in bookings.items %}
64 60
                                             <div class="row u-items-center">
65
-                                                <div class="col-1 time icon-uhr-outline">
61
+                                                <div class="col-2 time icon-uhr-outline">
66 62
                                                     <div class="t-label">Uhrzeit</div>
67 63
                                                     {{ booking.slot.time|date('H:i') }}
68 64
                                                     <div class="t-label">Standort</div>
... ...
@@ -71,16 +67,10 @@
71 67
                                                 <div class="col-3 behaelter icon-behaelter-outline">
72 68
                                                     <div class="t-label">Gebuchte Behälterkapazität</div>
73 69
                                                     {{ booking.behaelter }}
74
-                                                    <div class="t-label">Ernteart</div>
75
-                                                    {{ booking.ernteart|join(', ') }}
76
-                                                </div>
77
-                                                <div class="col-3 behaelter icon-behaelter-outline">
78
-                                                    <div class="t-label">Anliefernde Sorten</div>
79
-                                                    {{ booking.sorte|join(', ') }}
80
-                                                    <div class="t-label">Lage</div>
81
-                                                    {{ booking.lage|join(', ') }}
70
+                                                    <div class="t-label">Anlieferungseinheit</div>
71
+                                                    {{ booking.amount }} x {{ booking.unit }}
82 72
                                                 </div>
83
-                                                <div class="col-3 rebsorten icon-reben-outline">
73
+                                                <div class="col-5 rebsorten icon-reben-outline">
84 74
                                                     <div class="t-label">Mitglied</div>
85 75
                                                     {% if booking.member is not null %}
86 76
                                                         {% if booking.member.memberno is defined %}
... ...
@@ -24,6 +24,7 @@ use Doctrine\DBAL\Connection;
24 24
 use Symfony\Component\HttpFoundation\RequestStack;
25 25
 use Symfony\Component\HttpFoundation\Response;
26 26
 use Symfony\Component\Routing\Annotation\Route;
27
+use Symfony\Contracts\Translation\TranslatorInterface;
27 28
 use Twig\Environment as TwigEnvironment;
28 29
 use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungLeseartModel;
29 30
 use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungRebsorteModel;
... ...
@@ -39,13 +40,15 @@ class WeinanlieferungBookingsController extends AbstractController
39 40
     private $tokenManager;
40 41
     private $request;
41 42
     private $db;
43
+    private $translator;
42 44
 
43
-    public function __construct(TwigEnvironment $twig, ContaoCsrfTokenManager $tokenManager, RequestStack $requestStack, Connection $db)
45
+    public function __construct(TwigEnvironment $twig, ContaoCsrfTokenManager $tokenManager, RequestStack $requestStack, Connection $db, TranslatorInterface $translator)
44 46
     {
45 47
         $this->twig = $twig;
46 48
         $this->tokenManager = $tokenManager;
47 49
         $this->request = $requestStack->getCurrentRequest();
48 50
         $this->db = $db;
51
+        $this->translator = $translator;
49 52
 
50 53
         $container = System::getContainer();
51 54
         $objSession = $container->get('session');
... ...
@@ -192,11 +195,19 @@ class WeinanlieferungBookingsController extends AbstractController
192 195
                         $strStandort = $Standort->title;
193 196
                     }
194 197
 
198
+                    // Unit
199
+                    $unitLabel = $this->translator->trans('tl_vr_wa_units.containers.0', [], 'contao_tl_vr_wa_units');
200
+                    if (($Unit = $booking->getRelated('unit')) !== null)
201
+                    {
202
+                        $unitLabel = $Unit->title;
203
+                    }
204
+
195 205
                     $arrData['days'][$day->dayBegin][$Slot->pid]['times'][$Slot->time]['items'][] = array_merge($booking->row(), [
196 206
                         'sorte'              => $arrSorten,
197 207
                         'ernteart' => $arrErnteart,
198 208
                         'lage' => $arrLagen,
199 209
                         'slot'  => $Slot->row(),
210
+                        'unit' => $unitLabel,
200 211
                         'standort' => $strStandort,
201 212
                         'member' => $booking->getRelated('uid') !== null ? $booking->getRelated('uid')->row() : null
202 213
                     ]);
... ...
@@ -15,20 +15,27 @@ namespace vonRotenberg\WeinanlieferungBundle\EventListener\DataContainer;
15 15
 use Contao\CoreBundle\ServiceAnnotation\Callback;
16 16
 use Contao\DataContainer;
17 17
 use Contao\Date;
18
+use Contao\Input;
18 19
 use Contao\StringUtil;
19 20
 use Doctrine\DBAL\Connection;
21
+use Symfony\Contracts\Translation\TranslatorInterface;
20 22
 use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungLeseartModel;
21 23
 use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungRebsorteModel;
22 24
 use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungSlotsModel;
25
+use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungUnitsModel;
23 26
 
24 27
 class WeinanlieferungReservationContainerListener
25 28
 {
26 29
     /** @var Connection */
27 30
     protected $db;
28 31
 
29
-    public function __construct(Connection $db)
32
+    private $translator;
33
+
34
+
35
+    public function __construct(Connection $db,TranslatorInterface $translator)
30 36
     {
31 37
         $this->db = $db;
38
+        $this->translator = $translator;
32 39
     }
33 40
 
34 41
 
... ...
@@ -145,4 +152,52 @@ class WeinanlieferungReservationContainerListener
145 152
 
146 153
         return $arrData;
147 154
     }
155
+
156
+    /**
157
+     * @Callback(table="tl_vr_wa_reservation", target="fields.unit.options")
158
+     */
159
+    public function onUnitsOptionsCallback(DataContainer $dc)
160
+    {
161
+        $arrOptions = [];
162
+
163
+        if (
164
+            ($Slot = WeinanlieferungSlotsModel::findByPk($dc->activeRecord->pid)) !== null
165
+            && ($Site = $Slot->getRelated('pid')) !== null
166
+        )
167
+        {
168
+            if (($Units = $Site->getRelated('units')) !== null)
169
+            {
170
+                foreach ($Units as $unit)
171
+                {
172
+                    $arrOptions[$unit->id] = $unit->title . ' (' . $unit->containers . ' '.$this->translator->trans('tl_vr_wa_units.containers.0', [], 'contao_tl_vr_wa_units').')';
173
+                }
174
+            }
175
+
176
+        }
177
+
178
+
179
+        return $arrOptions;
180
+    }
181
+
182
+    /**
183
+     * @Callback(table="tl_vr_wa_reservation", target="fields.amount.save")
184
+     */
185
+    public function adjustContainers($varValue, DataContainer $dc)
186
+    {
187
+        $intUnit = (Input::post('unit') !== null) ? intval(Input::post('unit')) : intval($dc->activeRecord->unit);
188
+
189
+        $intContainers = $varValue;
190
+
191
+        if ($intUnit)
192
+        {
193
+            if (($Unit = WeinanlieferungUnitsModel::findByPk($intUnit)) !== null)
194
+            {
195
+                $intContainers = intval($varValue) * intval($Unit->containers);
196
+            }
197
+        }
198
+
199
+        $this->db->update($dc->table,['behaelter'=>$intContainers],['id'=>$dc->activeRecord->id]);
200
+
201
+        return $varValue;
202
+    }
148 203
 }