mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Task duration / start time helpers
This commit is contained in:
parent
dbcfce8bb9
commit
73802c3647
@ -15,6 +15,7 @@ use App\Models\Filterable;
|
|||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
class Task extends BaseModel
|
class Task extends BaseModel
|
||||||
{
|
{
|
||||||
@ -81,4 +82,69 @@ class Task extends BaseModel
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Project::class);
|
return $this->belongsTo(Project::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static function calcstart_time()
|
||||||
|
{
|
||||||
|
$parts = json_decode($this->time_log) ?: [];
|
||||||
|
|
||||||
|
if (count($parts)) {
|
||||||
|
return Carbon::createFromTimeStamp($parts[0][0]);
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLaststart_time()
|
||||||
|
{
|
||||||
|
$parts = json_decode($this->time_log) ?: [];
|
||||||
|
|
||||||
|
if (count($parts)) {
|
||||||
|
$index = count($parts) - 1;
|
||||||
|
|
||||||
|
return $parts[$index][0];
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function calcDuration($start_time_cutoff = 0, $end_time_cutoff = 0)
|
||||||
|
{
|
||||||
|
$duration = 0;
|
||||||
|
$parts = json_decode($this->time_log) ?: [];
|
||||||
|
|
||||||
|
foreach ($parts as $part) {
|
||||||
|
$start_time = $part[0];
|
||||||
|
if (count($part) == 1 || ! $part[1]) {
|
||||||
|
$end_time = time();
|
||||||
|
} else {
|
||||||
|
$end_time = $part[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($start_time_cutoff) {
|
||||||
|
$start_time = max($start_time, $start_time_cutoff);
|
||||||
|
}
|
||||||
|
if ($end_time_cutoff) {
|
||||||
|
$end_time = min($end_time, $end_time_cutoff);
|
||||||
|
}
|
||||||
|
|
||||||
|
$duration += max($end_time - $start_time, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return round($duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,11 @@ class TaskRepository extends BaseRepository
|
|||||||
{
|
{
|
||||||
|
|
||||||
$task->fill($data);
|
$task->fill($data);
|
||||||
|
|
||||||
|
if(!$task->start_time)
|
||||||
|
$task->start_time = $task->calcStartTime();
|
||||||
|
|
||||||
|
$task->duration = $task->calcDuration();
|
||||||
$task->save();
|
$task->save();
|
||||||
|
|
||||||
if (array_key_exists('documents', $data)) {
|
if (array_key_exists('documents', $data)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user