Luca Parisio 9 mesi fa
parent
commit
da418bd8bb
2 ha cambiato i file con 83 aggiunte e 3 eliminazioni
  1. 14 0
      app/Http/Livewire/Rate.php
  2. 69 3
      resources/views/livewire/rate.blade.php

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

@@ -153,6 +153,20 @@ class Rate extends Component
         }
     }
 
+    public function deleteMultiple($ids)
+    {
+        try{
+            foreach($ids as $id)
+            {
+                \App\Models\Rate::find($id)->delete();
+            }
+            //$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))

+ 69 - 3
resources/views/livewire/rate.blade.php

@@ -77,12 +77,20 @@
     <section id="resume-table">
         <div class="compare--chart_wrapper d-none"></div>
 
-        <h3>{{$detail}}</h3><br>
+        <div class="row">
+            <div class="col-6">
+                <h3 class="mt-4">{{$detail}}</h3><br>
+            </div>
+            <div class="col-6 right" style="margin-top:20px;text-align:right">
+                <button id="btRemove" style="display:none;" class="btn--ui" >ELIMINA SELEZIONATI</button>
+            </div>
+        </div>
+        
 
         <table class="table tablesaw tableHead tablesaw-stack table--lista_ricevute" id="tablesaw-350" width="100%">
             <thead>
                 <tr>
-                    <th scope="col"></th>
+                    <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>
@@ -94,7 +102,11 @@
             <tbody id="checkall-target">
                 @foreach($records as $record)
                     <tr>
-                        <td></td>
+                        <td>
+                            @if($record->status == 0)
+                                <input type="checkbox" name="chk{{$record->id}}" value="{{$record->id}}" class="chkIds">
+                            @endif
+                        </td>
                         <td>{{date("d/m/Y", strtotime($record->date))}}</td>
                         <td>{{$record->course_subscription ? $record->course_subscription->name : 'Iscrizione'}}</td>
                         <td>
@@ -434,12 +446,66 @@
             $('#tablesaw-350 thead tr th').addClass('col');
             $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
 
+            var checked = false;
+
             $(document).ready(function() {
                 $(document).on("click",".addData",function() {
                     $(".title--section_addButton").trigger("click")
                 });
+
+                $('.chkAll').change(function() {
+
+                    var check = this.checked;
+                    var ok = false;
+                    $('.chkIds').each(function () {
+                        $(this).prop( "checked", check );
+                        ok = true;
+                    });
+                    if (check && ok)
+                        $("#btRemove").show();
+                    else
+                        $("#btRemove").hide();
+
+                });
+
+                $('.chkIds').change(function() {
+                    
+                    checked = false;
+                    $('.chkIds').each(function () {
+                        
+                        if (this.checked)
+                            checked = true;
+                    });
+                    
+                    if (checked)
+                        $("#btRemove").show();
+                    else
+                    {
+                        $("#btRemove").hide();
+                        $(".chkAll").prop( "checked", false );
+                    }
+
+                });
+
+                $('#btRemove').click(function(){
+                    var ids = [];
+                    $('.chkIds').each(function () {
+                        if (this.checked)
+                            ids.push($(this).val());
+                    });
+                    if (confirm('Sei sicuro?'))
+                    {
+                        @this.deleteMultiple(ids);
+                        setTimeout(() => {
+                            location.reload();    
+                        }, 200);                
+                    }
+                });
+
             } );
 
+            
+
         }
 
     </script>