Bladeren bron

Merge branch 'master' into fabio_develop

FabioFratini 8 maanden geleden
bovenliggende
commit
cc86c924b7

+ 106 - 82
app/Http/Livewire/Course.php

@@ -32,6 +32,9 @@ class Course extends Component
 
     public $selectedYear = '';
 
+    public $msgPrices = '';
+    public $msgWhen = '';
+
     public $course_types = [];
     public $course_durations = [];
     public $course_frequencies = [];
@@ -51,16 +54,23 @@ class Course extends Component
 
     protected $rules = [
         'name' => 'required',
-        /*'course_type_id' => 'required',
-        'course_duration_id' => 'required',
         'course_frequency_id' => 'required',
         'course_level_id' => 'required',
+        'date_from' => 'required',
+        'date_to' => 'required',
+        'year' => 'required',
+        'subscription_price' => 'required|min:0|not_in:0',
+        /*'course_type_id' => 'required',
+        'course_duration_id' => 'required',
+        
         'causal_id' => 'required',
         'sub_causal_id' => 'required',*/
     ];
 
     protected $messages = [
         'name.required' => 'Il nome è obbligatorio',
+        'subscription_price.required' => 'Deve essere maggionre di zero',
+        'subscription_price.not_in' => 'Deve essere maggionre di zero',
         /*'causal_id' => 'Campo obbligatorio',
         'sub_causal_id' => 'Campo obbligatorio',*/
     ];
@@ -77,7 +87,7 @@ class Course extends Component
         $this->sub_causal_id = null;
         $this->max_members = 0;
         $this->instructor_id = null;
-        $this->year = date("Y");
+        $this->year = null;
         $this->price = 0;
         $this->subscription_price = 0;
         $this->date_from = null;
@@ -172,88 +182,102 @@ class Course extends Component
     {
         $this->validate();
         try {
-            $course = new \App\Models\Course();
-
-            $course->name = $this->name;
-            $course->parent_id = $this->parent_id;
-            $course->course_type_id = $this->course_type_id;
-            $course->course_duration_id = $this->course_duration_id;
-            $course->course_frequency_id = $this->course_frequency_id;
-            $course->course_level_id = $this->course_level_id;
-            $course->date_from = $this->date_from;
-            $course->date_to = $this->date_to;
-            $course->category_id = $this->category_id;
-            //$course->causal_id = $this->causal_id;
-            //$course->sub_causal_id = $this->sub_causal_id;
-            $course->max_members = $this->max_members;
-            $course->instructor_id = $this->instructor_id;
-            $course->year = $this->year;
-            $course->price = currencyToDouble($this->price);
-            $course->subscription_price = currencyToDouble($this->subscription_price);
-            $course->months = json_encode($this->months);
-            $course->type = $this->type;
-            $course->when = json_encode($this->when);
-            $course->prices = json_encode($this->prices);
-            $course->enabled = $this->enabled;
-            $course->save();
-
-            $lev = '';
-            if ($this->course_level_id > 0)
-                $lev = \App\Models\CourseLevel::findOrFail($this->course_level_id)->name;
-
-            $freq = '';
-            if ($this->course_frequency_id > 0)
-                $freq = \App\Models\CourseFrequency::findOrFail($this->course_frequency_id)->name;
-
-            $mFrom = getMonthName(date("n", strtotime($this->date_from)));
-            $mTo = getMonthName(date("n", strtotime($this->date_to)));
-            // Creo le causali di pagamento
-            //$causal = "PAGAMENTO CORSO [nome corso]-LIVELLO-FREQUENZA-ANNO-[tipo abbonamento]-[mese inizio]/[mese fine]
-
-            $causal = "PAGAMENTO CORSO " . $this->name . " - " . $lev . " - " . $freq . " - " . $this->year . " - " . $mFrom . "/" . $mTo;
-            $cp = \App\Models\Causal::where('name', $causal)->first();
-            if (!$cp)
-            {
-                $cp = new \App\Models\Causal();
-                $cp->name = $causal;
-                $cp->type = "IN";
-                $cp->parent_id = null;
-                $cp->money = false;
-                $cp->corrispettivo_fiscale = false;
-                $cp->no_receipt = false;
-                $cp->user_status = false;
-                $cp->no_first = false;
-                $cp->no_records = false;
-                $cp->enabled = true;
-                $cp->save();
-            }
-            $course->causal_id = $cp->id;
 
-            $causal = "PAGAMENTO ISCRIZIONE " . $this->name . " - " . $lev . " - " . $freq . " - " . $this->year . " - " . $mFrom . "/" . $mTo;
-            $ci = \App\Models\Causal::where('name', $causal)->first();
-            if (!$ci)
+            $this->msgPrices = '';
+            $this->msgWhen = '';
+
+            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';
+
+            if ($this->msgPrices == '' &&  $this->msgWhen == '')
             {
-                $ci = new \App\Models\Causal();
-                $ci->name = $causal;
-                $ci->type = "IN";
-                $ci->parent_id = null;
-                $ci->money = false;
-                $ci->corrispettivo_fiscale = false;
-                $ci->no_receipt = false;
-                $ci->user_status = false;
-                $ci->no_first = false;
-                $ci->no_records = false;
-                $ci->enabled = true;
-                $ci->save();
-            }
-            $course->sub_causal_id = $ci->id;
 
-            $course->save();
-            
-            session()->flash('success','Corso creato');
-            $this->resetFields();
-            $this->add = false;
-            $this->emit('setEdit', false);
+                $course = new \App\Models\Course();
+
+                $course->name = $this->name;
+                $course->parent_id = $this->parent_id;
+                $course->course_type_id = $this->course_type_id;
+                $course->course_duration_id = $this->course_duration_id;
+                $course->course_frequency_id = $this->course_frequency_id;
+                $course->course_level_id = $this->course_level_id;
+                $course->date_from = $this->date_from;
+                $course->date_to = $this->date_to;
+                $course->category_id = $this->category_id;
+                //$course->causal_id = $this->causal_id;
+                //$course->sub_causal_id = $this->sub_causal_id;
+                $course->max_members = $this->max_members;
+                $course->instructor_id = $this->instructor_id;
+                $course->year = $this->year;
+                $course->price = currencyToDouble($this->price);
+                $course->subscription_price = currencyToDouble($this->subscription_price);
+                $course->months = json_encode($this->months);
+                $course->type = $this->type;
+                $course->when = json_encode($this->when);
+                $course->prices = json_encode($this->prices);
+                $course->enabled = $this->enabled;
+                $course->save();
+
+                $lev = '';
+                if ($this->course_level_id > 0)
+                    $lev = \App\Models\CourseLevel::findOrFail($this->course_level_id)->name;
+
+                $freq = '';
+                if ($this->course_frequency_id > 0)
+                    $freq = \App\Models\CourseFrequency::findOrFail($this->course_frequency_id)->name;
+
+                $mFrom = getMonthName(date("n", strtotime($this->date_from)));
+                $mTo = getMonthName(date("n", strtotime($this->date_to)));
+                // Creo le causali di pagamento
+                //$causal = "PAGAMENTO CORSO [nome corso]-LIVELLO-FREQUENZA-ANNO-[tipo abbonamento]-[mese inizio]/[mese fine]
+
+                $causal = "PAGAMENTO CORSO " . $this->name . " - " . $lev . " - " . $freq . " - " . $this->year . " - " . $mFrom . "/" . $mTo;
+                $cp = \App\Models\Causal::where('name', $causal)->first();
+                if (!$cp)
+                {
+                    $cp = new \App\Models\Causal();
+                    $cp->name = $causal;
+                    $cp->type = "IN";
+                    $cp->parent_id = null;
+                    $cp->money = false;
+                    $cp->corrispettivo_fiscale = false;
+                    $cp->no_receipt = false;
+                    $cp->user_status = false;
+                    $cp->no_first = false;
+                    $cp->no_records = false;
+                    $cp->enabled = true;
+                    $cp->save();
+                }
+                $course->causal_id = $cp->id;
+
+                $causal = "PAGAMENTO ISCRIZIONE " . $this->name . " - " . $lev . " - " . $freq . " - " . $this->year . " - " . $mFrom . "/" . $mTo;
+                $ci = \App\Models\Causal::where('name', $causal)->first();
+                if (!$ci)
+                {
+                    $ci = new \App\Models\Causal();
+                    $ci->name = $causal;
+                    $ci->type = "IN";
+                    $ci->parent_id = null;
+                    $ci->money = false;
+                    $ci->corrispettivo_fiscale = false;
+                    $ci->no_receipt = false;
+                    $ci->user_status = false;
+                    $ci->no_first = false;
+                    $ci->no_records = false;
+                    $ci->enabled = true;
+                    $ci->save();
+                }
+                $course->sub_causal_id = $ci->id;
+
+                $course->save();
+                
+                session()->flash('success','Corso creato');
+                $this->resetFields();
+                $this->add = false;
+                $this->emit('setEdit', false);
+            }
         } catch (\Exception $ex) {
             session()->flash('error','Errore (' . $ex->getMessage() . ')');
         }

+ 51 - 22
app/Http/Livewire/Rate.php

@@ -33,6 +33,8 @@ class Rate extends Component
     public $price_list = [];
     public $type = '';
 
+    public $errorMsg = '';
+
     public function mount()
     {
         // Load members for the dropdown
@@ -119,28 +121,52 @@ class Rate extends Component
     public function add()
     {
 
-        
+        $this->errorMsg = '';
+        if ($this->date == '')
+        {
+            $this->errorMsg = 'La data di scadenza è obbligatoria';
+        }
+        else
+        {
 
-        $rate = new \App\Models\Rate();
-        $rate->member_id = $this->member_id;
-        $rate->member_course_id = $this->member_course_id;
-        $rate->course_subscription_id = $this->course_subscription_id;
-        $rate->price = currencyToDouble($this->price);
-        $rate->date = $this->date;
-        if ($this->type == '1')
-            $this->months[] = $this->month;
-        $rate->months = json_encode($this->months);
-        $rate->note = '';
-        $rate->status = 0;
-        $rate->save();
-
-        $this->course_subscription_id = null;
-        $this->price = 0;
-        $this->date = null;
-        $this->month = '';
-        $this->months = [];
+            if (!$this->course_subscription_id > 0)
+            {
+                $this->errorMsg = 'Devi selezionare un tipo di abbonamento';
+            }
+            else
+            {
+
+                if ($this->type > 1 && $this->type != sizeof($this->months))
+                {
+                    $this->errorMsg = 'Hai selezionato un numero di mesi errato in base all\'abbonamento selezionato' . $this->type .'.'. sizeof($this->months);
+                }
+                else
+                {
 
-        $this->emit('close-popup');
+                    $rate = new \App\Models\Rate();
+                    $rate->member_id = $this->member_id;
+                    $rate->member_course_id = $this->member_course_id;
+                    $rate->course_subscription_id = $this->course_subscription_id;
+                    $rate->price = currencyToDouble($this->price);
+                    $rate->date = $this->date;
+                    if ($this->type == '1')
+                        $this->months[] = $this->month;
+                    $rate->months = json_encode($this->months);
+                    $rate->note = '';
+                    $rate->status = 0;
+                    $rate->save();
+
+                    $this->course_subscription_id = null;
+                    $this->price = 0;
+                    $this->date = null;
+                    $this->month = '';
+                    $this->months = [];
+
+                    $this->emit('close-popup');
+                }
+            }
+
+        }
 
     }
 
@@ -200,8 +226,11 @@ class Rate extends Component
             $this->months[] = $m;
         }
         else
-        {
-
+        {            
+            if (($key = array_search($m, $this->months)) !== false) 
+            {
+                $this->months = array_slice($this->months, $key, 1);
+            }
         }
     }
 

+ 4 - 0
app/Http/Livewire/RecordIN.php

@@ -103,6 +103,8 @@ class RecordIN extends Component
 
     public $rows = array();
 
+    public $fromCourse = false;
+
     protected $rules = [
         'member_id' => 'required',
         'payment_method_id' => 'required',
@@ -382,6 +384,8 @@ class RecordIN extends Component
             }
             if (isset($_GET["months"]) && $_GET["months"] != '') {
 
+                $this->fromCourse = true;
+
                 $price = $_GET["price"] / 100 * 100;
                 $this->refreshAfter = 1;
                 $desc = "Pagamento";

+ 5 - 0
app/Models/Rate.php

@@ -27,6 +27,11 @@ class Rate extends Model
         return $this->belongsTo(Member::class);
     }
 
+    public function record()
+    {
+        return $this->belongsTo(Record::class);
+    }
+
     public function member_course()
     {
         return $this->belongsTo(MemberCourse::class, 'member_course_id');

+ 11 - 8
resources/views/livewire/course.blade.php

@@ -175,13 +175,13 @@
                             <div class="col-3 mt-2">
                                 <div class="form--item">
                                     <label for="inputName" class="form-label">Data inizio</label>
-                                    <input class="form-control" type="date" placeholder="Data inizio" wire:model="date_from">
+                                    <input class="form-control @error('name') is-invalid @enderror" type="date" placeholder="Data inizio" wire:model="date_from">
                                 </div>
                             </div>
                             <div class="col-3 mt-2">
                                 <div class="form--item">
                                     <label for="inputName" class="form-label">Data fine</label>
-                                    <input class="form-control" type="date" placeholder="Data fine" wire:model="date_to">
+                                    <input class="form-control @error('name') is-invalid @enderror" type="date" placeholder="Data fine" wire:model="date_to">
                                 </div>
                             </div>
                             @if(false)
@@ -260,15 +260,12 @@
                             <div class="col-6 mt-2">
                                 <div class="form--item">
                                     <label for="inputName" class="form-label">Anno</label>
-                                    <select class="form-control" wire:model="year">
+                                    <select class="form-control @error('year') is-invalid @enderror" wire:model="year">
                                         <option value=""></option>
                                         @for($i=2024; $i<=date("Y") + 1; $i++)
                                             <option value="{{$i . "-" . $i + 1}}">{{$i . "/" . $i + 1}}
                                         @endfor
                                     </select>
-                                    @error('year')
-                                        <div class="invalid-feedback">{{ $message }}</div>
-                                    @enderror
                                 </div>
                             </div>
 
@@ -283,7 +280,7 @@
                             </div>
                             <div class="col-6">
                                 @foreach($prices as $idP => $p)
-                                    <div class="row mt-2">
+                                    <div class="row mt-2 ">
                                         <div class="col-6">
                                             <label for="abb" class="form-label">Abbonamento</label>
                                             <select class="form-control" wire:model="prices.{{$idP}}.course_subscription_id">
@@ -297,7 +294,7 @@
                                             <label for="price" class="form-label">Prezzo</label>
                                             <input class="form-control " type="text" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00" wire:model="prices.{{$idP}}.price">
                                         </div>
-                                        <div class="col-1">
+                                        <div class="col-2">
                                             @if($idP == 0)
                                                 <br><button class="btn--ui primary add--daye" wire:click.prevent="addPrice()"><i class="fa-solid fa-plus"></i></button>
                                             @endif
@@ -305,6 +302,9 @@
                                                 <br><button class="btn--ui primary add--daye" wire:click.prevent="delPrice({{$idP}})"><i class="fa-solid fa-minus"></i></button>
                                             @endif
                                         </div>
+                                        <div class="col-12">
+                                            <span style="color:red">{{$msgPrices}}</span>
+                                        </div>
                                     </div>
                                 @endforeach
                             </div>
@@ -353,6 +353,9 @@
                                             <button class="btn--ui primary add--day position-absolute" wire:click.prevent="addRow()"><i class="fa-solid fa-plus"></i></button>
                                         </div>
                                     </div>
+                                    <div class="col-12">
+                                        <span style="color:red">{{$msgWhen}}</span>
+                                    </div>
 
                                 @endforeach
                             

+ 5 - 5
resources/views/livewire/rate.blade.php

@@ -93,7 +93,7 @@
                     <th scope="col"><input type="checkbox" name="chkAll" class="chkAll"></th>
                     <th scope="col">Data scadenza</th>
                     <th scope="col">Rata</th>
-                    <th scope="col">Competenza</th>
+                    <th scope="col">Mesi</th>
                     <th scope="col">Prezzo</th>
                     <th scope="col" style="text-align:center">Stato pagamento</th>
                     <th scope="col">...</th>
@@ -155,6 +155,7 @@
                     <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                 </div>
                 <div class="modal-body">
+                    <span style="color:red">{{$errorMsg}}</span>
                     <div class="row">
                         <div class="col-md-6">
                             <label for="course_subscription_id" class="form-label">Abbonamento</label>
@@ -352,11 +353,10 @@
         $(document).ready(function() {
             loadDataTable();
 
-            $('.chkMonth').change(function() {
-                let val = ($(this).val());
+            $(document).on("click", ".chkMonth", function(event){
+                let val = ($(this).val());      
                 @this.addDeleteMonth(val);
-                
-            });
+            }); 
 
             $('.monthsSelect').select2({
                 

+ 3 - 1
resources/views/livewire/records_in.blade.php

@@ -687,7 +687,9 @@
                                     <tr>
                                         <td>
                                             {{$this->getCausal($row["causal_id"])}}<br>
-                                            {{$row["note"]}}
+                                            @if(!$fromCourse)
+                                                {{$row["note"]}}
+                                            @endif
                                         </td>
                                         @php
                                         $vat_value = 0;