Browse Source

Fix corsi

Luca Parisio 7 months ago
parent
commit
c185ffe9de

+ 2 - 0
app/Http/Livewire/Member.php

@@ -206,6 +206,7 @@ class Member extends Component
         $this->email = '';
         $this->enabled = true;
         $this->under18 = false;
+        $this->hasCertificate = false;
         $this->money = 0;
         $this->image = null;
 
@@ -1068,6 +1069,7 @@ class Member extends Component
                 $this->dataId = $member->id;
 
                 $this->active = $member->getStatus();
+                $this->hasCertificate = $member->hasCertificate()["status"];
 
                 $this->money = $member->getMoney();
 

+ 17 - 0
app/Http/Livewire/Rate.php

@@ -219,6 +219,23 @@ class Rate extends Component
         }
     }
 
+    public function suspendMultiple($ids)
+    {
+        try{
+            foreach($ids as $id)
+            {
+                $r = \App\Models\Rate::find($id);
+                $r->status = $r->status == 2 ? 0 : 2;
+                $r->save();
+            }
+
+            //$this->emit('load-data-table');
+            session()->flash('success',"Rata eliminata");
+        }catch(\Exception $e){
+            session()->flash('error','Errore (' . $ex->getMessage() . ')');
+        }
+    }
+
     public function addDeleteMonth($m)
     {
         if (!in_array($m, $this->months))

+ 1 - 1
resources/views/livewire/member.blade.php

@@ -1272,7 +1272,7 @@
                                             </table>
 
                                             @if($dataId > 0)
-                                                @if ($active["status"] == 1 || $active["status"] == 2)
+                                                @if ($active["status"] == 1 || $hasCertificate)
                                                     <button class="btn--ui primary"wire:click.prevent="addCourse()" style="max-width:200px">Aggiungi</button>
                                                 @endif
                                             @endif

+ 32 - 4
resources/views/livewire/rate.blade.php

@@ -78,10 +78,13 @@
         <div class="compare--chart_wrapper d-none"></div>
 
         <div class="row">
-            <div class="col-10">
+            <div class="col-6">
                 <h3 class="mt-4">{{$detail}}</h3><br>
             </div>
-            <div class="col-2 right" style="margin-top:20px;text-align:right">
+            <div class="col-3 right" style="margin-top:20px;text-align:right">
+                <button id="btSuspend" style="display:none;" class="btn--ui" >SOSPENDI/ATTIVA SELEZIONATI</button>
+            </div>
+            <div class="col-3 right" style="margin-top:20px;text-align:right">
                 <button id="btRemove" style="display:none;" class="btn--ui" >ELIMINA SELEZIONATI</button>
             </div>
         </div>
@@ -92,7 +95,7 @@
                 <tr>
                     <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">Pagamento</th>
                     <th scope="col">Mesi</th>
                     <th scope="col">Prezzo</th>
                     <th scope="col" style="text-align:center">Stato pagamento</th>
@@ -103,7 +106,7 @@
                 @foreach($records as $record)
                     <tr>
                         <td>
-                            @if($record->status == 0)
+                            @if($record->status == 0 || $record->status == 2)
                                 <input type="checkbox" name="chk{{$record->id}}" value="{{$record->id}}" class="chkIds">
                             @endif
                         </td>
@@ -459,9 +462,15 @@
                         ok = true;
                     });
                     if (check && ok)
+                    {
                         $("#btRemove").show();
+                        $("#btSuspend").show();
+                    }
                     else
+                    {
                         $("#btRemove").hide();
+                        $("#btSuspend").hide();
+                    }
 
                 });
 
@@ -475,10 +484,14 @@
                     });
                     
                     if (checked)
+                    {
                         $("#btRemove").show();
+                        $("#btSuspend").show();
+                    }
                     else
                     {
                         $("#btRemove").hide();
+                        $("#btSuspend").hide();
                         $(".chkAll").prop( "checked", false );
                     }
 
@@ -499,6 +512,21 @@
                     }
                 });
 
+                $('#btSuspend').click(function(){
+                    var ids = [];
+                    $('.chkIds').each(function () {
+                        if (this.checked)
+                            ids.push($(this).val());
+                    });
+                    if (confirm('Sei sicuro?'))
+                    {
+                        @this.suspendMultiple(ids);
+                        setTimeout(() => {
+                            location.reload();    
+                        }, 200);                
+                    }
+                });
+
             } );