Luca Parisio 5 месяцев назад
Родитель
Сommit
c78abdc762

+ 10 - 5
app/Http/Livewire/Presence.php

@@ -173,6 +173,7 @@ class Presence extends Component
 
         $presence = false;
         $my_presence = false;
+        $motivation = '';
         $status = 0;
 
         $has_presence = \App\Models\Presence::where('calendar_id', $this->calendar->id)->where('member_id', $member->id)->first();
@@ -180,6 +181,10 @@ class Presence extends Component
         {
             $presence = true;
             $my_presence = $has_presence->user_id == \Auth::user()->id;
+            if ($has_presence->motivation_id > 0)
+            {
+                $motivation = \App\Models\Motivation::findOrFail($has_presence->motivation_id)->name;
+            }
             $status = $has_presence->status;
         }
 
@@ -189,7 +194,7 @@ class Presence extends Component
             $my_presence = true;
         }
 
-        return array('id' => $member->id, 'first_name' => $member->first_name, 'last_name' => $member->last_name, 'certificate' => $y, 'presence' => $presence, 'my_presence' => $my_presence, 'status' => $status);
+        return array('id' => $member->id, 'first_name' => $member->first_name, 'last_name' => $member->last_name, 'certificate' => $y, 'presence' => $presence, 'my_presence' => $my_presence, 'status' => $status, 'motivation' => $motivation);
 
     }
 
@@ -329,8 +334,8 @@ class Presence extends Component
                 ]);
                 foreach($this->member_ids as $m)
                 {
-                    if ($this->manual)
-                    {
+                    //if ($this->manual)
+                    //{
                         //\App\Models\Presence::where('calendar_id', $this->calendar->id)->where('user_id', \Auth::user()->id)->where('status', '<>', 99)->delete();
                         //foreach($ids as $id)
                         //{
@@ -342,12 +347,12 @@ class Presence extends Component
                             $p->status = 0;
                             $p->save();
                         //}
-                    }
+                    /*}
                     else
                     {
                         if (!in_array($m, $this->newMembers))
                             $this->newMembers[] = $m;
-                    }
+                    }*/
                 }
             }
 

+ 5 - 0
app/Models/Presence.php

@@ -26,4 +26,9 @@ class Presence extends Model
     {
         return $this->belongsTo(\App\Models\Calendar::class);
     }
+
+    public function motivation()
+    {
+        return $this->belongsTo(\App\Models\Motivation::class);
+    }
 }

+ 5 - 0
resources/views/livewire/presence.blade.php

@@ -78,6 +78,7 @@
                         <th scope="col">Cognome</th>
                         <th scope="col">Nome</th>
                         <th scope="col">Certificato</th>
+                        <th scope="col">Motivazione</th>
                         <th scope="col">Presenza</th>
                     </tr>
                 </thead>
@@ -103,6 +104,10 @@
                                     @endif
                                     {{$date}}
                                 </span>
+                            </td>
+                            <td>
+                                {{$record["motivation"]}}
+                            </td>
                             <td>
                                 @if ($record["status"] != 99)
                                     @if ($record["presence"])