Procházet zdrojové kódy

presenze utenti - modifiche

ferrari před 2 měsíci
rodič
revize
4f482ad1c3

+ 17 - 8
app/Http/Livewire/Member.php

@@ -831,12 +831,21 @@ class Member extends Component
             {
                 $status = '';
                 $annullata = false;
+                $motivation = null;
                 if (in_array($calendar->id, $presences))
                 {
                     $status = "<span style=\"color:#0c6197\">Presenza</span>";
                     $this->presenze += 1;
                     $this->valori[$monthMap[date('n', strtotime($calendar->from))]] += 1;
                     $chartData[PRESENZE]["data"][$monthMap[date('n', strtotime($calendar->from))]] += 1;
+
+                    $presence = \App\Models\Presence::where('member_id', $this->dataId)->where('status', '<>', 99)->where('calendar_id', $calendar->id)->first();
+                    if ($presence->motivation && $presence->motivation->show_in_member_presences) {
+                        $motivation = $presence->motivation->name;
+                        if (!isset($this->recuperi[$motivation])) $this->recuperi[$motivation] = 0;
+
+                        $this->recuperi[$motivation] += 1;
+                    }
                 }
                 else
                 {
@@ -868,7 +877,7 @@ class Member extends Component
                     $chartData[ANNULLATE]["data"][$monthMap[date('n', strtotime($calendar->from))]] += 1;
                 }
                 
-                $this->member_presences[] = array('calendar_id' => $calendar->id, 'from' => $calendar->from, 'to' => $calendar->to, 'status' => $status, 'motivation' => null);//\App\Models\Presence::where('member_id', $this->dataId)->get();
+                $this->member_presences[] = array('calendar_id' => $calendar->id, 'from' => $calendar->from, 'to' => $calendar->to, 'status' => $status, 'motivation' => $motivation);//\App\Models\Presence::where('member_id', $this->dataId)->get();
             }
 
             //$courses = array(1);
@@ -887,18 +896,18 @@ class Member extends Component
         $presences_recuperi = \App\Models\Presence::whereIn('calendar_id', $calendar_recuperi)->where('member_id', $this->dataId)->get();
         foreach($presences_recuperi as $p)
         {
-            // $this->member_presences[] = array('calendar_id' => $p->calendar->id, 'from' => $p->calendar->from, 'to' => $p->calendar->to, 'status' => '<span style="color:#7136f6">Recupero</span>', 'motivation' => $p->motivation->name);//\App\Models\Presence::where('member_id', $this->dataId)->get();
-            $this->member_presences[] = array('calendar_id' => $p->calendar->id, 'from' => $p->calendar->from, 'to' => $p->calendar->to, 'status' => '<span style=\"color:#0c6197\">Presenza</span>', 'motivation' => $p->motivation->name);//\App\Models\Presence::where('member_id', $this->dataId)->get();
+            if ($p->motivation && $p->motivation->show_in_member_presences) {
+                // $this->member_presences[] = array('calendar_id' => $p->calendar->id, 'from' => $p->calendar->from, 'to' => $p->calendar->to, 'status' => '<span style="color:#7136f6">Recupero</span>', 'motivation' => $p->motivation->name);//\App\Models\Presence::where('member_id', $this->dataId)->get();
+                $this->member_presences[] = array('calendar_id' => $p->calendar->id, 'from' => $p->calendar->from, 'to' => $p->calendar->to, 'status' => '<span style=\"color:#0c6197\">Presenza</span>', 'motivation' => $p->motivation->name);//\App\Models\Presence::where('member_id', $this->dataId)->get();
 
-            if ($p->motivation) {
                 if (!isset($this->recuperi[$p->motivation->name])) $this->recuperi[$p->motivation->name] = 0;
 
                 $this->recuperi[$p->motivation->name] += 1;
+                $this->presenze += 1;
+                
+                // $chartData[RECUPERO]["data"][$monthMap[date('n', strtotime($p->calendar->from))]] += 1;
+                $chartData[PRESENZE]["data"][$monthMap[date('n', strtotime($p->calendar->from))]] += 1;
             }
-            $this->presenze += 1;
-
-            $chartData[PRESENZE]["data"][$monthMap[date('n', strtotime($p->calendar->from))]] += 1;
-            // $chartData[RECUPERO]["data"][$monthMap[date('n', strtotime($p->calendar->from))]] += 1;
         }
 
         $sortVariable='from';

+ 10 - 7
app/Http/Livewire/Motivation.php

@@ -6,7 +6,7 @@ use Livewire\Component;
 
 class Motivation extends Component
 {
-    public $records, $name, $type, $enabled, $dataId, $update = false, $add = false;
+    public $records, $name, $type, $enabled, $show_in_member_presences, $dataId, $update = false, $add = false;
 
     protected $rules = [
         'name' => 'required'
@@ -47,7 +47,7 @@ class Motivation extends Component
 
     public function render()
     {
-        $this->records = \App\Models\Motivation::select('id', 'name', 'type', 'enabled')->get();
+        $this->records = \App\Models\Motivation::select('id', 'name', 'type', 'show_in_member_presences', 'enabled')->get();
         return view('livewire.motivation');
     }
 
@@ -65,7 +65,8 @@ class Motivation extends Component
             \App\Models\Motivation::create([
                 'name' => $this->name,
                 'type' => $this->type,
-                'enabled' => $this->enabled
+                'enabled' => $this->enabled,
+                'show_in_member_presences' => $this->show_in_member_presences,
             ]);
             session()->flash('success','Campo creata');
             $this->resetFields();
@@ -79,11 +80,12 @@ class Motivation extends Component
         try {
             $motivation = \App\Models\Motivation::findOrFail($id);
             if( !$motivation) {
-                session()->flash('error','Campo non trovata');
+                session()->flash('error','Motivazione non trovata');
             } else {
                 $this->name = $motivation->name;
                 $this->type = $motivation->type;
                 $this->enabled = $motivation->enabled;
+                $this->show_in_member_presences = $motivation->show_in_member_presences;
                 $this->dataId = $motivation->id;
                 $this->update = true;
                 $this->add = false;
@@ -100,9 +102,10 @@ class Motivation extends Component
             \App\Models\Motivation::whereId($this->dataId)->update([
                 'name' => $this->name,
                 'type' => $this->type,
-                'enabled' => $this->enabled
+                'enabled' => $this->enabled,
+                'show_in_member_presences' => $this->show_in_member_presences,
             ]);
-            session()->flash('success','Campo aggiornata');
+            session()->flash('success','Motivazione aggiornata');
             $this->resetFields();
             $this->update = false;
         } catch (\Exception $ex) {
@@ -121,7 +124,7 @@ class Motivation extends Component
     {
         try{
             \App\Models\Motivation::find($id)->delete();
-            session()->flash('success',"Campo eliminata");
+            session()->flash('success',"Motivazione eliminata");
             return redirect(request()->header('Referer'));
         }catch(\Exception $e){
             session()->flash('error','Errore (' . $ex->getMessage() . ')');

+ 2 - 1
app/Models/Motivation.php

@@ -12,6 +12,7 @@ class Motivation extends Model
     protected $fillable = [
         'name',
         'enabled',
-        'type'
+        'type',
+        'show_in_member_presences'
     ];
 }

+ 32 - 0
database/migrations/2025_11_28_162913_add_show_in_member_presences_to_motivations.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('motivations', function (Blueprint $table) {
+            $table->integer('show_in_member_presences')->default(1);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('motivations', function (Blueprint $table) {
+            $table->dropColumn('show_in_member_presences');
+        });
+    }
+};

+ 7 - 2
resources/views/livewire/motivation.blade.php

@@ -52,10 +52,9 @@
 
     @else
 
+        <a class="btn--ui lightGrey" href="/motivations"><i class="fa-solid fa-arrow-left"></i></a><br><br>
         <div class="container">
 
-            <a class="btn--ui lightGrey" href="/banks"><i class="fa-solid fa-arrow-left"></i></a><br><br>
-
             @if (session()->has('error'))
                 <div class="alert alert-danger" role="alert">
                     {{ session()->get('error') }}
@@ -93,6 +92,12 @@
                                     <input class="form-check-input form-control" style="width:22px; height:22px;" type="checkbox" id="enabled" wire:model="enabled">
                                 </div>
                             </div>
+                            <div class="col">
+                                <div class="form--item">
+                                    <label for="show_in_member_presences" class="form-label">Visualizza in Presenze Utente</label>
+                                    <input class="form-check-input form-control" style="width:22px; height:22px;" type="checkbox" id="show_in_member_presences" wire:model="show_in_member_presences">
+                                </div>
+                            </div>
                         </div>
 
                         <!-- // inline input field -->