Files
a.montask/app/Models/User.php
T

127 lines
3.3 KiB
PHP
Raw Normal View History

2025-07-10 18:23:56 +00:00
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
2025-10-11 13:38:30 +00:00
use Carbon\Carbon;
2025-07-10 18:23:56 +00:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2026-04-23 14:00:39 +03:30
use Illuminate\Database\Eloquent\SoftDeletes;
2025-07-10 18:23:56 +00:00
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
2025-10-11 13:38:30 +00:00
use Illuminate\Support\Facades\DB;
use Morilog\Jalali\Jalalian;
2025-07-10 18:23:56 +00:00
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
2026-04-23 14:00:39 +03:30
use HasFactory, Notifiable, softDeletes;
2025-07-10 18:23:56 +00:00
2025-10-11 13:38:30 +00:00
2025-07-10 18:23:56 +00:00
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'email',
2025-10-11 13:38:30 +00:00
'chatid',
'name',
'number',
2026-07-22 14:10:05 +03:30
'birthday',
2025-07-10 18:23:56 +00:00
'password',
2025-10-11 13:38:30 +00:00
'user_name',
'is_admin',
'plain_id',
2026-04-08 07:22:13 +00:00
'break',
'req_counts',
'active_task'
2025-10-11 13:38:30 +00:00
2025-07-10 18:23:56 +00:00
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
2025-10-11 13:38:30 +00:00
protected $hidden = [];
2025-07-10 18:23:56 +00:00
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
2026-07-22 14:10:05 +03:30
return [
'birthday' => 'date',
];
2025-07-10 18:23:56 +00:00
}
2025-10-11 13:38:30 +00:00
2026-04-21 16:46:39 +00:00
public function task()
2025-10-11 13:38:30 +00:00
{
2026-04-21 16:46:39 +00:00
return $this->hasMany(Tasks::class, 'user_id');
2025-10-11 13:38:30 +00:00
}
2026-04-21 16:46:39 +00:00
// public function tasks()
// {
//// return $this->belongsToMany(Tasks::class, 'pivot_tasks', 'user_id', 'task_id');
// return $this->belongsToMany(
// Tasks::class, // مدل مقصد
// 'pivot_tasks', // جدول واسط
// 'user_id', // ستون جدول واسط که به جدول users اشاره می‌کنه
// 'task_id', // ستون جدول واسط که به جدول tasks اشاره می‌کنه
// 'plain_id', // ستون جدول users که ستون جدول واسط بهش اشاره می‌کنه (local key)
// 'task_id' // ستون جدول tasks که ستون جدول واسط بهش اشاره می‌کنه (related key)
// )->withPivot(['id', 'started_at','ended_at','duration',]);
// }
2025-10-11 13:38:30 +00:00
public function attendances()
{
return $this->hasMany(Attendance::class, 'user_identity', 'user_name')
2026-07-22 14:10:05 +03:30
->select('id', 'user_identity', 'entered_at', 'exited_at', 'duration', 'requested', 'distance', 'distance_exit', 'late_minutes', 'daily_fine_minutes', 'daily_fine_amount')
2025-10-11 13:38:30 +00:00
->orderBy('entered_at', 'desc');
}
public function attendanceBreaks()
{
return $this->hasManyThrough(AttendanceBreak::class,Attendance::class,'user_identity','attendance_id',
'user_name', // local key در users
'id' // local key در attendances
2026-04-18 06:17:01 +00:00
)->orderBy('id', 'desc');
2026-04-08 07:22:13 +00:00
2025-10-11 13:38:30 +00:00
}
2026-04-21 16:46:39 +00:00
// public function thismonth($data)
// {
//
// }
2025-10-11 13:38:30 +00:00
public function everymonth($data)
{
$result = [];
foreach ($data->attendances as $att) {
if ($att->entered_at) {
$date = \Morilog\Jalali\Jalalian::fromCarbon(\Carbon\Carbon::parse($att->entered_at));
$month = $date->format('%B');
if (!isset($result[$month])) {
$result[$month] = [];
}
$result[$month][] = $att;
}
}
return $result;
}
2025-07-10 18:23:56 +00:00
}