Luca Parisio il y a 1 an
Parent
commit
480173a0b9

+ 65 - 0
app/Console/Commands/SetMemberDatas.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class SetMemberDatas extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'update:data';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Update member data';
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+
+        $members = \App\Models\Member::all();
+
+        foreach($members as $member)
+        {
+
+            $status = $member->getStatus();
+            $status = $status["status"];
+
+            $has_certificate = $member->hasCertificate();
+            $certificate = 0;
+            $certificate_date = null;
+            if($has_certificate["date"] != '')
+            {
+                if($has_certificate["date"] < date("Y-m-d"))
+                    $certificate = 0;
+
+                if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
+                    $certificate = 1;
+
+                if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
+                    $certificate = 2;
+
+                $certificate_date = $has_certificate["date"] != '' ? $has_certificate["date"] : null;
+            }
+
+            $member->current_status = $status;
+            $member->certificate = $certificate;
+            $member->certificate_date = $certificate_date;
+            $member->save();
+
+        }
+
+        return Command::SUCCESS;
+    }
+}

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

@@ -865,6 +865,7 @@ class Member extends Component
                 'enabled' => $this->enabled
             ]);
             session()->flash('success, Tesserato creato');
+            updateMemberData($member->id);
             $this->resetFields();
             if ($close)
             {
@@ -1089,6 +1090,7 @@ class Member extends Component
                 'email' => strtolower($this->email),
                 'enabled' => $this->enabled
             ]);
+            updateMemberData($this->dataId);
             session()->flash('success','Tesserato aggiornato');
             if ($close)
             {
@@ -1210,6 +1212,7 @@ class Member extends Component
                 'discipline2_id' => $this->card_discipline2_id,
                 'discipline3_id' => $this->card_discipline3_id,
             ]);
+            updateMemberData($this->dataId);
             session()->flash('success, Tesserato creato');
             $this->resetCardFields();
             $this->addCard = false;
@@ -1287,6 +1290,7 @@ class Member extends Component
                 'discipline2_id' => $this->card_discipline2_id,
                 'discipline3_id' => $this->card_discipline3_id,
             ]);
+            updateMemberData($this->dataId);
             session()->flash('success','Tesserato aggiornato');
             $this->resetCardFields();
             $this->updateCard = false;
@@ -1537,6 +1541,7 @@ class Member extends Component
                     'expire_date' => $this->certificate_expire_date,
                     'status' => $this->certificate_status
                 ]);
+                updateMemberData($this->dataId);
             }
             /*else
             {
@@ -1599,6 +1604,7 @@ class Member extends Component
                 'expire_date' => $this->certificate_expire_date,
                 'status' => $this->certificate_status
             ]);
+            updateMemberData($this->dataId);
             session()->flash('success','Tesserato aggiornato');
             $this->resetCertificateFields();
             $this->updateCertificate = false;

+ 11 - 2
app/Http/Livewire/RecordINOUT.php

@@ -112,14 +112,22 @@ class RecordINOUT extends Component
                 $first_parent_id = \App\Models\Causal::where('id', $record->parent_id)->first()->parent_id;
             }
             if ($type == 'IN')
-                $this->rows_in[] = array('id' => $record->id, 'name' => $record->name, 'level' => $indentation, 'parent_id' => $record->parent_id, 'first_parent_id' => $first_parent_id);
+                $this->rows_in[] = array('id' => $record->id, 'name' => $record->name, 'level' => $indentation, 'parent_id' => $record->parent_id, 'parent_name' => $this->getCausalName($record->parent_id), 'first_parent_id' => $first_parent_id, 'first_parent_name' => $this->getCausalName($first_parent_id));
             if ($type == 'OUT')
-                $this->rows_out[] = array('id' => $record->id, 'name' => $record->name, 'level' => $indentation, 'parent_id' => $record->parent_id, 'first_parent_id' => $first_parent_id);
+                $this->rows_out[] = array('id' => $record->id, 'name' => $record->name, 'level' => $indentation, 'parent_id' => $record->parent_id, 'parent_name' => $this->getCausalName($record->parent_id), 'first_parent_id' => $first_parent_id, 'first_parent_name' => $this->getCausalName($first_parent_id));
             if(count($record->childs))
                 $this->getCausale($record->childs, $type, $indentation + 1);
         }
     }
 
+    public function getCausalName($id)
+    {
+        if ($id > 0)
+            return \App\Models\Causal::findOrFail($id)->name;
+        else
+            return "";
+    }
+
     public function render()
     {
         return view('livewire.records_in_out');
@@ -370,6 +378,7 @@ class RecordINOUT extends Component
         $this->records_out = [];
         $this->records_in = [];
         $this->emit('load-select');
+        $this->emit('reset-collapse');
         //$this->showData = false;
     }
 

+ 4 - 4
app/Models/Member.php

@@ -54,7 +54,6 @@ class Member extends Model
         'certificate_date',
         'to_complete'
     ];
-
     public function nation()
     {
         return $this->belongsTo(Nation::class);
@@ -196,10 +195,11 @@ class Member extends Model
     public function hasCertificate()
     {
         $ret = array('status' => false, 'date' => '');
-        $certificates = \App\Models\MemberCertificate::where('member_id', $this->id)->orderBy('expire_date')->get();
-        foreach($certificates as $certificate)
+        $certificates = \App\Models\MemberCertificate::where('member_id', $this->id)->orderBy('expire_date', 'DESC')->get();
+        foreach($certificates as $idx => $certificate)
         {
-            $ret = array('status' => $certificate->expire_date . " 23:59:59" > date("Y-m-d"), 'date' => $certificate->expire_date);
+            if ($idx == 0)
+                $ret = array('status' => $certificate->expire_date . " 23:59:59" > date("Y-m-d"), 'date' => $certificate->expire_date);
         }
         return $ret;
     }

+ 2 - 0
app/Models/MemberCard.php

@@ -22,6 +22,8 @@ class MemberCard extends Model
         'discipline3_id',
     ];
 
+
+
     public function member()
     {
         return $this->belongsTo(Member::class);

+ 28 - 0
app/helpers.php

@@ -142,3 +142,31 @@ function sendReceiptDeleteEmail($receipt)
         }
     }
 }
+
+function updateMemberData($member_id)
+{
+    $member = \App\Models\Member::findOrFail($member_id);
+    $status = $member->getStatus();
+    $status = $status["status"];
+    $has_certificate = $member->hasCertificate();
+    $certificate = 0;
+    $certificate_date = null;
+    if($has_certificate["date"] != '')
+    {
+        if($has_certificate["date"] < date("Y-m-d"))
+            $certificate = 0;
+
+        if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
+            $certificate = 1;
+
+        if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
+            $certificate = 2;
+
+        $certificate_date = $has_certificate["date"] != '' ? $has_certificate["date"] : null;
+    }
+
+    $member->current_status = $status;
+    $member->certificate = $certificate;
+    $member->certificate_date = $certificate_date;
+    $member->save();
+}

+ 5 - 5
public/css/style.css

@@ -14881,11 +14881,11 @@ ul.pagination li a[aria-label=Next] {
   filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#BE231D", endColorstr="#921b16", GradientType=1);
 }
 .badge.complete {
-    background: #f88846;
-    background: -moz-linear-gradient(45deg, #f88846 0%, #921b16 100%);
-    background: -webkit-linear-gradient(45deg, #f88846 0%, #921b16 100%);
-    background: linear-gradient(45deg, #f88846 0%, #921b16 100%);
-    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#f88846", endColorstr="#921b16", GradientType=1);
+    background: #2596be;
+    background: -moz-linear-gradient(45deg, #2596be 0%, #2596be 100%);
+    background: -webkit-linear-gradient(45deg, #2596be 0%, #2596be 100%);
+    background: linear-gradient(45deg, #2596be 0%, #2596be 100%);
+    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#2596be", endColorstr="#2596be", GradientType=1);
   }
 .tessere--tab {
   margin-top: 0.9375rem;

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

@@ -2230,7 +2230,7 @@
                     { data: "year"},
                     {
                         data: "status",
-                        "orderable": false,
+                        //"orderable": false,
                         render: function (data){
                             // Split class and text
                             const d = data.split("|");
@@ -2253,7 +2253,6 @@
                     },*/
                     {
                         data: "certificate",
-                        "orderable": false,
                         render: function (data){
                             // Split class and text
                             var ret = '';

+ 43 - 15
resources/views/livewire/records_in_out.blade.php

@@ -98,8 +98,19 @@
 
                                     @foreach($rows_in as $in)
                                         @if($filterCausalsIn == null || (sizeof($filterCausalsIn) == 0 || in_array($in["id"], $filterCausalsIn) || in_array($in["parent_id"], $filterCausalsIn) || in_array($in["first_parent_id"], $filterCausalsIn)))
-                                            <tr data-id="{{$in["id"]}}" data-parent="{{$in["parent_id"]}}">
-                                                <td>{!!str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $in["level"])!!}{{$in["name"]}}</td>
+                                            <tr data-id="{{$in["id"]}}" data-parent="{{$filterCausalsIn == null || in_array($in["parent_id"], $filterCausalsIn) ? $in["parent_id"] : ''}}">
+                                                <td>
+                                                    {!!str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $in["level"])!!}
+
+                                                    @if($filterCausalsIn != null && !in_array($in["first_parent_id"], $filterCausalsIn))
+                                                        {{$in["first_parent_name"]}}
+                                                        {{$in["parent_name"]}}
+                                                    @endif
+                                                    @if($filterCausalsIn != null && !in_array($in["parent_id"], $filterCausalsIn))
+
+                                                    @endif
+                                                    {{$in["name"]}}
+                                                </td>
                                                 @foreach($columns as $column)
                                                     <td class="cellBorder" style="text-align:right">
                                                         @if(isset($records_in[$column][$in["id"]]))
@@ -345,40 +356,57 @@
                 $('.filterCausalsIn').select2();
                 $('.filterCausalsIn').on('change', function (e) {
                     var data = $('.filterCausalsIn').select2("val");
+                    setTimeout(function() {createCollapse();}, 1000);
                     @this.set('filterCausalsIn', data);
                 });
 
                 $('.filterCausalsOut').select2();
                 $('.filterCausalsOut').on('change', function (e) {
                     var data = $('.filterCausalsOut').select2("val");
+                    setTimeout(function() {createCollapse();}, 1000);
                     @this.set('filterCausalsOut', data);
                 });
+                createCollapse();
+            });
+        }
 
-                $('.collaptableIN').aCollapTable({
-                    startCollapsed: true,
-                    addColumn: false,
-                    plusButton: '<span class="i"> + </span>',
-                    minusButton: '<span class="i"> - </span>'
-                });
-                $('.collaptableOUT').aCollapTable({
-                    startCollapsed: true,
-                    addColumn: false,
-                    plusButton: '<span class="i"> + </span>',
-                    minusButton: '<span class="i"> - </span>'
-                });
-                $("#collapseAll").trigger("click")
+        function createCollapse()
+        {
+            $(".act-more").remove();
+
+            //$("#checkall-target > tr").removeAttr("data-level");
+            //$("#checkall-target > tr").removeAttr("class");
+
+            $('.collaptableIN').aCollapTable({
+                startCollapsed: true,
+                addColumn: false,
+                plusButton: '<span class="i"> + </span>',
+                minusButton: '<span class="i"> - </span>'
             });
+            $('.collaptableOUT').aCollapTable({
+                startCollapsed: true,
+                addColumn: false,
+                plusButton: '<span class="i"> + </span>',
+                minusButton: '<span class="i"> - </span>'
+            });
+            $("#collapseAll").trigger("click");
         }
 
+        Livewire.on('reset-collapse', () => {
+            createCollapse();
+        });
+
         Livewire.on('load-select', () => {
             $('.filterCausalsIn').select2();
             $('.filterCausalsIn').on('change', function (e) {
                 var data = $('.filterCausalsIn').select2("val");
+                setTimeout(function() {createCollapse();}, 1000);
                 @this.set('filterCausalsIn', data);
             });
             $('.filterCausalsOut').select2();
             $('.filterCausalsOut').on('change', function (e) {
                 var data = $('.filterCausalsOut').select2("val");
+                setTimeout(function() {createCollapse();}, 1000);
                 @this.set('filterCausalsOut', data);
             });
         });

+ 1 - 2
resources/views/livewire/records_out.blade.php

@@ -56,11 +56,10 @@
                                     <b>Periodo</b>
                                 </div>
                                 <div class="col-12">
-                                    <input id="dateFrom mb-2" type="date" class="form-control filterFrom"  >
+                                    <input id="dateFrom" type="date" class="form-control filterFrom  mb-2"  >
                                 </div>
                                 <div class="col-12">
                                     <input id="dateTo" type="date" class="form-control filterTo" >
-                                    <input id="dateTo" type="date" class="form-control filterTo" >
                                 </div>
                                 <div class="col-6 mt-2">
                                     <button class="btn--ui" onclick="setToday('{{date("Y-m-d")}}')">OGGI</button>

+ 19 - 6
routes/web.php

@@ -135,7 +135,7 @@ Route::get('/get_members', function(){
     $datas = [];
 
     // $datas = \App\Models\Member::select('members.*')->where('id', '>', 0);
-    $x = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone', 'birth_date', 'to_complete')->where('id', '>', 0);
+    $x = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone', 'birth_date', 'to_complete', 'current_status', 'certificate', 'certificate_date')->where('id', '>', 0);
 
     if (isset($_GET["search"]["value"]))
     {
@@ -239,6 +239,10 @@ Route::get('/get_members', function(){
             $column = 'birth_date';
         if ($_GET["order"][0]["column"] == 4)
             $column = 'birth_date';
+        if ($_GET["order"][0]["column"] == 5)
+            $column = 'current_status';
+        if ($_GET["order"][0]["column"] == 6)
+            $column = 'certificate';
         if ($column != '')
             $x = $x->orderBy($column, $_GET["order"][0]["dir"]);
         else
@@ -255,8 +259,10 @@ Route::get('/get_members', function(){
     foreach($x as $idx => $r)
     {
 
-        $status = $r->getStatus();
-        $status = $status["status"];
+        // $status = $r->getStatus();
+        // $status = $status["status"];
+
+        $status = $r->current_status;
 
         $class = $status > 0 ? ($status == 2 ? 'active' : 'due') : 'suspended';
         $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato';
@@ -267,8 +273,15 @@ Route::get('/get_members', function(){
             $class = "complete";
         }
 
-        $has_certificate = $r->hasCertificate();
+        // $has_certificate = $r->hasCertificate();
         $y = '';
+
+        if ($r->certificate_date != '')
+        {
+            $y = $r->certificate . "|" . $r->certificate_date;
+        }
+
+        /*
         if($has_certificate["date"] != '')
         {
             if($has_certificate["date"] < date("Y-m-d"))
@@ -281,7 +294,7 @@ Route::get('/get_members', function(){
                 $y .= '2';
             $y .= '|';
             $y .= $has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : '';
-        }
+        }*/
 
         $datas[] = array(
             //'c' => $idx + 1,
@@ -723,7 +736,7 @@ Route::get('/get_course_list', function(){
         $xx += 1;
     }
 
-    
+
     //$member_course = $member_course->where('course_id', 999999);
 
     $start = 0;