Kaynağa Gözat

Merge branch 'master' into fabio_develop

FabioFratini 9 ay önce
ebeveyn
işleme
4587fb40e5

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

@@ -29,6 +29,7 @@ class Rate extends Component
     public $months = [];
     public $months = [];
     public $couse_subscriptions = [];
     public $couse_subscriptions = [];
     public $price_list = [];
     public $price_list = [];
+    public $type = '';
 
 
     public function mount()
     public function mount()
     {
     {
@@ -88,6 +89,10 @@ class Rate extends Component
         $this->price = 0;
         $this->price = 0;
         if (isset($this->price_list[$this->course_subscription_id]))
         if (isset($this->price_list[$this->course_subscription_id]))
             $this->price = $this->price_list[$this->course_subscription_id];
             $this->price = $this->price_list[$this->course_subscription_id];
+
+        $this->type = '';
+        if ($this->course_subscription_id > 0)
+            $this->type = \App\Models\CourseSubscription::findOrFail($this->course_subscription_id)->months;
     }
     }
 
 
     public function add()
     public function add()
@@ -148,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)
     public function addDeleteMonth($m)
     {
     {
         if (!in_array($m, $this->months))
         if (!in_array($m, $this->months))

+ 127 - 22
resources/views/livewire/rate.blade.php

@@ -77,12 +77,20 @@
     <section id="resume-table">
     <section id="resume-table">
         <div class="compare--chart_wrapper d-none"></div>
         <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%">
         <table class="table tablesaw tableHead tablesaw-stack table--lista_ricevute" id="tablesaw-350" width="100%">
             <thead>
             <thead>
                 <tr>
                 <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">Data scadenza</th>
                     <th scope="col">Rata</th>
                     <th scope="col">Rata</th>
                     <th scope="col">Competenza</th>
                     <th scope="col">Competenza</th>
@@ -94,7 +102,11 @@
             <tbody id="checkall-target">
             <tbody id="checkall-target">
                 @foreach($records as $record)
                 @foreach($records as $record)
                     <tr>
                     <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>{{date("d/m/Y", strtotime($record->date))}}</td>
                         <td>{{$record->course_subscription ? $record->course_subscription->name : 'Iscrizione'}}</td>
                         <td>{{$record->course_subscription ? $record->course_subscription->name : 'Iscrizione'}}</td>
                         <td>
                         <td>
@@ -135,7 +147,7 @@
 
 
     </section>
     </section>
 
 
-    <div  wire:ignore.self class="modal fade" id="rateModal" tabindex="-1" aria-labelledby="rateModalLabel" aria-hidden="true">
+    <div  wire:ignore.self class="modal" id="rateModal" tabindex="-1" aria-labelledby="rateModalLabel" aria-hidden="true">
         <div class="modal-dialog">
         <div class="modal-dialog">
             <div class="modal-content">
             <div class="modal-content">
             <div class="modal-header">
             <div class="modal-header">
@@ -155,7 +167,7 @@
                     </div>
                     </div>
                     <div class="col-md-6">
                     <div class="col-md-6">
                         <label for="price" class="form-label">Prezzo</label>
                         <label for="price" class="form-label">Prezzo</label>
-                        <input class="form-control" type="text" id="price" placeholder="Costo mensile" wire:model="price" onkeyup="onlyNumberAmount(this)">
+                        <input class="form-control" type="text" id="price" placeholder="Costo" wire:model="price" onkeyup="onlyNumberAmount(this)">
                     </div>
                     </div>
                 </div>
                 </div>
                 <div class="row mt-2">
                 <div class="row mt-2">
@@ -163,27 +175,54 @@
                         <label for="date" class="form-label">Scadenza</label>
                         <label for="date" class="form-label">Scadenza</label>
                         <input class="form-control @error('date') is-invalid @enderror" type="date" id="date" placeholder="Email" wire:model="date">
                         <input class="form-control @error('date') is-invalid @enderror" type="date" id="date" placeholder="Email" wire:model="date">
                     </div>
                     </div>
+                    @if($type == '1')
+                        <div class="col-md-6">
+                            <label for="date" class="form-label">Mesi</label>
+                            <select class="form-control" id="months"  wire:model="months">
+                                <option value="9">Settembre</option>
+                                <option value="10">Ottobre</option>
+                                <option value="11">Novembre</option>
+                                <option value="12">Dicembre</option>
+                                <option value="1">Gennaio</option>
+                                <option value="2">Febbraio</option>
+                                <option value="3">Marzo</option>
+                                <option value="4">Aprile</option>
+                                <option value="5">Maggio</option>
+                                <option value="6">Giugno</option>
+                                <option value="7">Luglio</option>
+                                <option value="8">Agosto</option>
+                            </select>
+                        </div>
+                    @endif
                 <div>
                 <div>
-                <div class="row mt-2">
-                    <div class="col-md-12">
-                        <label for="months" class="form-label">Mesi</label><br>
-                        <input type="checkbox" value="1" class="chkMonth">&nbsp;Gennaio
-                        <input type="checkbox"  value="2" class="chkMonth">&nbsp;Febbraio
-                        <input type="checkbox"  value="3" class="chkMonth">&nbsp;Marzo
-                        <input type="checkbox"  value="4" class="chkMonth">&nbsp;Aprile<br>
-                        <input type="checkbox"  value="5" class="chkMonth">&nbsp;Maggio
-                        <input type="checkbox"  value="6" class="chkMonth">&nbsp;Giugno
-                        <input type="checkbox"  value="7" class="chkMonth">&nbsp;Luglio
-                        <input type="checkbox"  value="8" class="chkMonth">&nbsp;Agosto<br>
-                        <input type="checkbox"  value="9" class="chkMonth">&nbsp;Settembre
-                        <input type="checkbox"  value="10" class="chkMonth">&nbsp;Ottobre
-                        <input type="checkbox"  value="11" class="chkMonth">&nbsp;Novembre
-                        <input type="checkbox"  value="12" class="chkMonth">&nbsp;Dicembre
+                @if($type > 1)
+                    <div class="row mt-2">
+                        <div class="col-md-12">
+                            <label for="months" class="form-label">Seleziona {{$type}} Mesi</label><br>
+                            <div class="row">
+                                <div class="col-3"><input type="checkbox"  value="9" class="chkMonth">&nbsp;Settembre</div>
+                                <div class="col-3"><input type="checkbox"  value="10" class="chkMonth">&nbsp;Ottobre</div>
+                                <div class="col-3"><input type="checkbox"  value="11" class="chkMonth">&nbsp;Novembre</div>
+                                <div class="col-3"><input type="checkbox"  value="12" class="chkMonth">&nbsp;Dicembre</div>
+                            </div>
+                            <div class="row">
+                                <div class="col-3"><input type="checkbox"  value="1" class="chkMonth">&nbsp;Gennaio</div>
+                                <div class="col-3"><input type="checkbox"  value="2" class="chkMonth">&nbsp;Febbraio</div>
+                                <div class="col-3"><input type="checkbox"  value="3" class="chkMonth">&nbsp;Marzo</div>
+                                <div class="col-3"><input type="checkbox"  value="4" class="chkMonth">&nbsp;Aprile</div>
+                            </div>
+                            <div class="row">
+                                <div class="col-3"><input type="checkbox"  value="5" class="chkMonth">&nbsp;Maggio</div>
+                                <div class="col-3"><input type="checkbox"  value="6" class="chkMonth">&nbsp;Giugno</div>
+                                <div class="col-3"><input type="checkbox"  value="7" class="chkMonth">&nbsp;Luglio</div>
+                                <div class="col-3"><input type="checkbox"  value="8" class="chkMonth">&nbsp;Agosto </div>                      
+                            </div>
+                        </div>
                     </div>
                     </div>
-                </div>
+                @endif
                 
                 
             </div>
             </div>
-            <div class="modal-footer">
+            <div class="modal-footer mt-2">
                 <button class="btn--ui lightGrey" onclick="annulla()">annulla</a>
                 <button class="btn--ui lightGrey" onclick="annulla()">annulla</a>
                 <button type="button" class="btn--ui btn-primary" wire:click.prevent="add()">Inserisci</button>
                 <button type="button" class="btn--ui btn-primary" wire:click.prevent="add()">Inserisci</button>
             </div>
             </div>
@@ -322,6 +361,18 @@
                 
                 
             });
             });
 
 
+            $('.monthsSelect').select2({
+                
+            });
+            $('.monthsSelect').on('change', function (e) {
+                var data = $('.monthsSelect').select2("val");
+                @this.set('months', data);
+                setTimeout(function() { 
+                    $('.monthsSelect').select2({                
+                    });
+                }, 100);                
+            });
+
         } );
         } );
 
 
         Livewire.on('close-popup', () => {
         Livewire.on('close-popup', () => {
@@ -395,12 +446,66 @@
             $('#tablesaw-350 thead tr th').addClass('col');
             $('#tablesaw-350 thead tr th').addClass('col');
             $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
             $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
 
 
+            var checked = false;
+
             $(document).ready(function() {
             $(document).ready(function() {
                 $(document).on("click",".addData",function() {
                 $(document).on("click",".addData",function() {
                     $(".title--section_addButton").trigger("click")
                     $(".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>
     </script>