2018-10-15 23:40:34 +11:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2021-01-04 08:54:54 +11:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
|
*/
|
2018-10-15 23:40:34 +11:00
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2018-11-20 15:36:56 +11:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-01-21 20:22:10 +11:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2020-10-29 13:24:12 +11:00
|
|
|
use Illuminate\Support\Carbon;
|
2018-10-15 23:40:34 +11:00
|
|
|
|
2018-11-02 21:54:46 +11:00
|
|
|
class Task extends BaseModel
|
2018-10-15 23:40:34 +11:00
|
|
|
{
|
2018-11-20 15:36:56 +11:00
|
|
|
use MakesHash;
|
2020-01-21 20:22:10 +11:00
|
|
|
use SoftDeletes;
|
2020-10-13 07:42:02 +11:00
|
|
|
use Filterable;
|
|
|
|
|
|
2019-06-26 14:04:10 +10:00
|
|
|
protected $fillable = [
|
2019-12-31 08:59:12 +11:00
|
|
|
'client_id',
|
2019-06-26 14:04:10 +10:00
|
|
|
'invoice_id',
|
2020-10-13 07:42:02 +11:00
|
|
|
'project_id',
|
2020-10-28 10:02:32 +11:00
|
|
|
'assigned_user_id',
|
2019-06-26 14:04:10 +10:00
|
|
|
'custom_value1',
|
|
|
|
|
'custom_value2',
|
2020-10-13 07:42:02 +11:00
|
|
|
'custom_value3',
|
|
|
|
|
'custom_value4',
|
2019-06-26 14:04:10 +10:00
|
|
|
'description',
|
|
|
|
|
'is_running',
|
|
|
|
|
'time_log',
|
2020-10-27 06:10:04 +11:00
|
|
|
'status_id',
|
|
|
|
|
'status_sort_order',
|
2020-10-27 13:27:38 +11:00
|
|
|
'invoice_documents',
|
2020-10-29 10:11:52 +11:00
|
|
|
'rate',
|
2020-10-29 20:40:13 +11:00
|
|
|
'number',
|
2020-12-15 08:52:14 +11:00
|
|
|
'is_date_based',
|
2019-12-31 08:59:12 +11:00
|
|
|
];
|
2018-11-20 15:36:56 +11:00
|
|
|
|
2020-07-23 13:55:11 +10:00
|
|
|
protected $touches = [];
|
2020-07-16 21:01:39 +10:00
|
|
|
|
2020-05-06 21:49:42 +10:00
|
|
|
public function getEntityType()
|
|
|
|
|
{
|
2020-09-06 19:38:10 +10:00
|
|
|
return self::class;
|
2020-05-06 21:49:42 +10:00
|
|
|
}
|
|
|
|
|
|
2020-07-16 21:01:39 +10:00
|
|
|
public function company()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-28 15:31:32 +10:00
|
|
|
public function documents()
|
|
|
|
|
{
|
|
|
|
|
return $this->morphMany(Document::class, 'documentable');
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 21:16:38 +11:00
|
|
|
public function assigned_user()
|
|
|
|
|
{
|
2019-12-31 08:59:12 +11:00
|
|
|
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
2019-11-05 21:16:38 +11:00
|
|
|
}
|
2019-11-25 20:38:55 +11:00
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function client()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Client::class);
|
|
|
|
|
}
|
2020-10-13 07:42:02 +11:00
|
|
|
|
|
|
|
|
public function invoice()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Invoice::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function project()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Project::class);
|
|
|
|
|
}
|
2020-10-29 13:24:12 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-29 14:34:29 +11:00
|
|
|
public function calcStartTime()
|
2020-10-29 13:24:12 +11:00
|
|
|
{
|
|
|
|
|
$parts = json_decode($this->time_log) ?: [];
|
|
|
|
|
|
|
|
|
|
if (count($parts)) {
|
2020-10-29 20:56:37 +11:00
|
|
|
return Carbon::createFromTimeStamp($parts[0][0])->timestamp;
|
2020-10-29 13:24:12 +11:00
|
|
|
} else {
|
2020-10-29 20:56:37 +11:00
|
|
|
return null;
|
2020-10-29 13:24:12 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-29 14:34:29 +11:00
|
|
|
public function getLastStartTime()
|
2020-10-29 13:24:12 +11:00
|
|
|
{
|
|
|
|
|
$parts = json_decode($this->time_log) ?: [];
|
|
|
|
|
|
|
|
|
|
if (count($parts)) {
|
|
|
|
|
$index = count($parts) - 1;
|
|
|
|
|
|
|
|
|
|
return $parts[$index][0];
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-29 14:34:29 +11:00
|
|
|
public function calcDuration($start_time_cutoff = 0, $end_time_cutoff = 0)
|
2020-10-29 13:24:12 +11:00
|
|
|
{
|
|
|
|
|
$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);
|
|
|
|
|
}
|
2018-10-15 23:40:34 +11:00
|
|
|
}
|