mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 22:39:34 +00:00
auto calculating tracked_time and estimated_time both for master and sub task
This commit is contained in:
1 parent
ef2ab75ce4
commit
ae900e24c0
7 files changed
+104
-34
No files matched your search
@@ -64,4 +64,23 @@ class MasterTask extends Model
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function recalculateEstimatedTime()
|
||||
{
|
||||
$this->estimated_time = $this->subtasks->sum('estimated_time');
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function recalculateTrackedTime()
|
||||
{
|
||||
$trackedTime = 0.0;
|
||||
|
||||
foreach ( $this->subtasks as $subtask ) {
|
||||
$trackedTime += $subtask->timesheets->sum('time');
|
||||
}
|
||||
|
||||
$this->tracked_time = $trackedTime;
|
||||
$this->save();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -46,8 +46,11 @@ class SubTask extends Model
|
||||
$item['user_id'] = $item['employee_id'];
|
||||
unset($item['employee_id']);
|
||||
$item['sub_task_id'] = $this->id;
|
||||
$item['created_at'] = Carbon::now();
|
||||
$item['updated_at'] = Carbon::now();
|
||||
|
||||
if (!$this->id) {
|
||||
$item['created_at'] = Carbon::now();
|
||||
$item['updated_at'] = Carbon::now();
|
||||
}
|
||||
return $item;
|
||||
}, $timesheets);
|
||||
|
||||
@@ -55,6 +58,9 @@ class SubTask extends Model
|
||||
$this->timesheets()->whereNotIn('id', collect($timesheets)->pluck('id')->filter())->delete();
|
||||
|
||||
$this->timesheets()->upsert($timesheets, ['id']);
|
||||
|
||||
// kedze updatujem cez upsert, tak sa neaktualizuje updated_at. preto ho musim updatnut manualne
|
||||
$this->touch();
|
||||
}
|
||||
|
||||
public function syncTimeblocks(Array $timeblocks)
|
||||
|
||||
@@ -12,6 +12,8 @@ class Timesheet extends Model
|
||||
public $timestamps = true;
|
||||
public $guarded = ['id'];
|
||||
|
||||
protected $touches = ['subtask'];
|
||||
|
||||
public function subtask()
|
||||
{
|
||||
return $this->belongsTo(SubTask::class, 'sub_task_id');
|
||||
|
||||
Reference in new issue
Block a user