Просмотр исходного кода

course - aggiunto controllo tipo pagamento all'update

ferrari 2 месяцев назад
Родитель
Сommit
cfeb62cf02
1 измененных файлов с 46 добавлено и 27 удалено
  1. 46 27
      app/Http/Livewire/Course.php

+ 46 - 27
app/Http/Livewire/Course.php

@@ -359,33 +359,52 @@ class Course extends Component
     {
     {
         $this->validate();
         $this->validate();
         try {
         try {
-            \App\Models\Course::whereId($this->dataId)->update([
-                'name' => $this->name,
-                'parent_id' => $this->parent_id,
-                'course_type_id' => $this->course_type_id,
-                'course_duration_id' => $this->course_duration_id,
-                'course_frequency_id' => $this->course_frequency_id,
-                'course_level_id' => $this->course_level_id,
-                'date_from' => $this->date_from,
-                'date_to' => $this->date_to,
-                'category_id' => $this->category_id,
-                'causal_id' => $this->causal_id,
-                'sub_causal_id' => $this->sub_causal_id,
-                'max_members' => $this->max_members,
-                'instructor_id' => $this->instructor_id,
-                'year' => $this->year,
-                'price' => currencyToDouble($this->price),
-                'subscription_price' => currencyToDouble($this->subscription_price),
-                'months' => json_encode($this->months),
-                'type' => $this->type,
-                'when' => json_encode($this->when),
-                'prices' => json_encode($this->prices),
-                'enabled' => $this->enabled
-            ]);
-            session()->flash('success','Corso aggiornato');
-            $this->resetFields();
-            $this->update = false;
-            $this->emit('setEdit', false);
+            $this->msgPrices = '';
+            $this->msgWhen = '';
+
+            if ($this->type == 'standard') {
+                if ($this->when[0]['from'] == '')
+                    $this->msgWhen = 'Devi inserire almeno un giorno';
+            }
+    
+            if ($this->prices[0]['course_subscription_id'] == null)
+                $this->msgPrices = 'Devi inserire almeno un prezzo';
+            
+            $subscriptions = array_column($this->prices, 'course_subscription_id');
+            $unique_subscriptions = array_unique($subscriptions);
+            if (count($subscriptions) != count($unique_subscriptions))
+                $this->msgPrices = 'È possibile aggiungere solo un abbonamento per ciascun tipo';
+
+            if ($this->msgPrices == '' &&  $this->msgWhen == '')
+            {
+                \App\Models\Course::whereId($this->dataId)->update([
+                    'name' => $this->name,
+                    'parent_id' => $this->parent_id,
+                    'course_type_id' => $this->course_type_id,
+                    'course_duration_id' => $this->course_duration_id,
+                    'course_frequency_id' => $this->course_frequency_id,
+                    'course_level_id' => $this->course_level_id,
+                    'date_from' => $this->date_from,
+                    'date_to' => $this->date_to,
+                    'category_id' => $this->category_id,
+                    'causal_id' => $this->causal_id,
+                    'sub_causal_id' => $this->sub_causal_id,
+                    'max_members' => $this->max_members,
+                    'instructor_id' => $this->instructor_id,
+                    'year' => $this->year,
+                    'price' => currencyToDouble($this->price),
+                    'subscription_price' => currencyToDouble($this->subscription_price),
+                    'months' => json_encode($this->months),
+                    'type' => $this->type,
+                    'when' => json_encode($this->when),
+                    'prices' => json_encode($this->prices),
+                    'enabled' => $this->enabled
+                ]);
+                session()->flash('success','Corso aggiornato');
+                $this->resetFields();
+                $this->update = false;
+                $this->emit('setEdit', false);
+            }
         } catch (\Exception $ex) {
         } catch (\Exception $ex) {
             session()->flash('error','Errore (' . $ex->getMessage() . ')');
             session()->flash('error','Errore (' . $ex->getMessage() . ')');
         }
         }