tsks
This commit is contained in:
@@ -4,9 +4,12 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Attendance extends Model
|
||||
{
|
||||
// protected $appends = ['full_time'];
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'user_identity',
|
||||
@@ -21,6 +24,7 @@ class Attendance extends Model
|
||||
'ip_address',
|
||||
'entered_at',
|
||||
'exited_at',
|
||||
'requested',
|
||||
];
|
||||
|
||||
public function setEntryLocationAttribute($value)
|
||||
@@ -42,5 +46,39 @@ class Attendance extends Model
|
||||
{
|
||||
return $this->hasMany(AttendanceBreak::class);
|
||||
}
|
||||
|
||||
public function duration($start,$end)
|
||||
{
|
||||
// dd($start,$end, $date);
|
||||
$fakedate = '2020/02/20';
|
||||
$start = Carbon::parse($start)->format('Y/m/d') ? Carbon::parse($start) : Carbon::parse($start . $fakedate);
|
||||
$end = Carbon::parse($end)->format('Y/m/d') ? Carbon::parse($end) : Carbon::parse($end . $fakedate);
|
||||
|
||||
|
||||
$diffInSeconds = $start->diffInSeconds($end); // فاصله به ثانیه
|
||||
$hours = floor($diffInSeconds / 3600);
|
||||
$minutes = floor(($diffInSeconds % 3600) / 60);
|
||||
$seconds = $diffInSeconds % 60;
|
||||
|
||||
$duration = sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
|
||||
return $duration;
|
||||
}
|
||||
// public function attendanceBreak()
|
||||
// {
|
||||
//
|
||||
// return $this->hasMany(AttendanceBreak::class, 'attendance_id', 'id')
|
||||
// ->select('attendance_id', 'break_start', 'break_end', 'duration')
|
||||
// ->orderBy('break_start', 'desc');
|
||||
//
|
||||
//
|
||||
// }
|
||||
public function attendanceBreaks()
|
||||
{
|
||||
return $this->hasMany(AttendanceBreak::class, 'attendance_id', 'id')
|
||||
->orderBy('break_start', 'desc');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public $timestamps = true;
|
||||
}
|
||||
|
||||
Regular → Executable
+1
@@ -11,6 +11,7 @@ class AttendanceBreak extends Model
|
||||
'attendance_id',
|
||||
'break_start',
|
||||
'break_end',
|
||||
'duration',
|
||||
];
|
||||
|
||||
// رابطه به حضور
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Tasks extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'tasks';
|
||||
|
||||
// protected $primaryKey = 'id'; // چون جدول UUID داره
|
||||
// public $incrementing = false;
|
||||
// protected $keyType = 'int';
|
||||
|
||||
protected $fillable = [
|
||||
'task_id',
|
||||
'name',
|
||||
'description',
|
||||
'workspace_slug',
|
||||
'assignees',
|
||||
'start_date',
|
||||
'target_date',
|
||||
'priority',
|
||||
'description_html',
|
||||
'completed_at',
|
||||
'project',
|
||||
'workspace',
|
||||
'state',
|
||||
'json',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
|
||||
];
|
||||
|
||||
// رابطه many-to-many با users
|
||||
public function users()
|
||||
{
|
||||
// return $this->belongsToMany(User::class, 'pivot_tasks', 'task_id', 'user_id');
|
||||
return $this->belongsToMany(
|
||||
User::class, // مدل مقصد
|
||||
'pivot_tasks', // جدول واسط
|
||||
'task_id', // ستون جدول واسط که به جدول tasks اشاره میکنه
|
||||
'user_id', // ستون جدول واسط که به جدول users اشاره میکنه
|
||||
'task_id', // ستون جدول tasks که ستون واسط بهش اشاره میکنه (local key)
|
||||
'plain_id' // ستون جدول users که ستون واسط بهش اشاره میکنه (related key)
|
||||
);
|
||||
}
|
||||
}
|
||||
Regular → Executable
+74
-9
@@ -3,24 +3,36 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'chatid',
|
||||
'name',
|
||||
'number',
|
||||
'password',
|
||||
'user_name',
|
||||
'is_admin',
|
||||
'plain_id',
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -28,10 +40,7 @@ class User extends Authenticatable
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
protected $hidden = [];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
@@ -40,9 +49,65 @@ class User extends Authenticatable
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
return [];
|
||||
}
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
public function attendances()
|
||||
{
|
||||
|
||||
return $this->hasMany(Attendance::class, 'user_identity', 'user_name')
|
||||
->select('id', 'user_identity', 'entered_at', 'exited_at', 'duration','requested')
|
||||
->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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function thismonth($data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Regular → Executable
Reference in New Issue
Block a user