mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Added time estimates for projects and tasks, fixes ST-283
This commit is contained in:
committed by
Gregor Vostrak
parent
78ea8a673b
commit
a820d8540f
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Service\BillingContract;
|
||||
use App\Service\PermissionStore;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
|
||||
@@ -43,4 +44,9 @@ class Controller extends \App\Http\Controllers\Controller
|
||||
{
|
||||
return $this->permissionStore->has($organization, $permission);
|
||||
}
|
||||
|
||||
protected function canAccessPremiumFeatures(Organization $organization): bool
|
||||
{
|
||||
return app(BillingContract::class)->hasSubscription($organization) || app(BillingContract::class)->hasTrial($organization);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,9 @@ class ProjectController extends Controller
|
||||
$project->is_billable = (bool) $request->input('is_billable');
|
||||
$project->billable_rate = $request->getBillableRate();
|
||||
$project->client_id = $request->input('client_id');
|
||||
if ($this->canAccessPremiumFeatures($organization) && $request->has('estimated_time')) {
|
||||
$project->estimated_time = $request->getEstimatedTime();
|
||||
}
|
||||
$project->organization()->associate($organization);
|
||||
$project->save();
|
||||
|
||||
@@ -117,6 +120,9 @@ class ProjectController extends Controller
|
||||
if ($request->has('is_archived')) {
|
||||
$project->archived_at = $request->getIsArchived() ? Carbon::now() : null;
|
||||
}
|
||||
if ($this->canAccessPremiumFeatures($organization) && $request->has('estimated_time')) {
|
||||
$project->estimated_time = $request->getEstimatedTime();
|
||||
}
|
||||
$oldBillableRate = $project->billable_rate;
|
||||
$project->billable_rate = $request->getBillableRate();
|
||||
$project->client_id = $request->input('client_id');
|
||||
@@ -147,8 +153,8 @@ class ProjectController extends Controller
|
||||
throw new EntityStillInUseApiException('project', 'time_entry');
|
||||
}
|
||||
|
||||
DB::transaction(function () use (&$project) {
|
||||
$project->members->each(function (ProjectMember $member) {
|
||||
DB::transaction(function () use (&$project): void {
|
||||
$project->members->each(function (ProjectMember $member): void {
|
||||
$member->delete();
|
||||
});
|
||||
|
||||
|
||||
@@ -79,6 +79,9 @@ class TaskController extends Controller
|
||||
$task = new Task;
|
||||
$task->name = $request->input('name');
|
||||
$task->project_id = $request->input('project_id');
|
||||
if ($this->canAccessPremiumFeatures($organization) && $request->has('estimated_time')) {
|
||||
$task->estimated_time = $request->getEstimatedTime();
|
||||
}
|
||||
$task->organization()->associate($organization);
|
||||
$task->save();
|
||||
|
||||
@@ -96,6 +99,9 @@ class TaskController extends Controller
|
||||
{
|
||||
$this->checkPermission($organization, 'tasks:update', $task);
|
||||
$task->name = $request->input('name');
|
||||
if ($this->canAccessPremiumFeatures($organization) && $request->has('estimated_time')) {
|
||||
$task->estimated_time = $request->getEstimatedTime();
|
||||
}
|
||||
if ($request->has('is_done')) {
|
||||
$task->done_at = $request->getIsDone() ? Carbon::now() : null;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ class ProjectStoreRequest extends FormRequest
|
||||
'integer',
|
||||
'min:0',
|
||||
],
|
||||
// ID of the client
|
||||
'client_id' => [
|
||||
'nullable',
|
||||
new ExistsEloquent(Client::class, null, function (Builder $builder): Builder {
|
||||
@@ -59,6 +60,12 @@ class ProjectStoreRequest extends FormRequest
|
||||
return $builder->whereBelongsTo($this->organization, 'organization');
|
||||
}),
|
||||
],
|
||||
// Estimated time in seconds
|
||||
'estimated_time' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
'min:0',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -68,4 +75,11 @@ class ProjectStoreRequest extends FormRequest
|
||||
|
||||
return $input !== null && $input !== 0 ? (int) $this->input('billable_rate') : null;
|
||||
}
|
||||
|
||||
public function getEstimatedTime(): ?int
|
||||
{
|
||||
$input = $this->input('estimated_time');
|
||||
|
||||
return $input !== null && $input !== 0 ? (int) $this->input('estimated_time') : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,12 @@ class ProjectUpdateRequest extends FormRequest
|
||||
'integer',
|
||||
'min:0',
|
||||
],
|
||||
// Estimated time in seconds
|
||||
'estimated_time' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
'min:0',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -78,4 +84,11 @@ class ProjectUpdateRequest extends FormRequest
|
||||
|
||||
return $input !== null && $input !== 0 ? (int) $this->input('billable_rate') : null;
|
||||
}
|
||||
|
||||
public function getEstimatedTime(): ?int
|
||||
{
|
||||
$input = $this->input('estimated_time');
|
||||
|
||||
return $input !== null && $input !== 0 ? (int) $this->input('estimated_time') : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,19 @@ class TaskStoreRequest extends FormRequest
|
||||
return $builder->whereBelongsTo($this->organization, 'organization');
|
||||
}),
|
||||
],
|
||||
// Estimated time in seconds
|
||||
'estimated_time' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
'min:0',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getEstimatedTime(): ?int
|
||||
{
|
||||
$input = $this->input('estimated_time');
|
||||
|
||||
return $input !== null && $input !== 0 ? (int) $this->input('estimated_time') : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,12 @@ class TaskUpdateRequest extends FormRequest
|
||||
'is_done' => [
|
||||
'boolean',
|
||||
],
|
||||
// Estimated time in seconds
|
||||
'estimated_time' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
'min:0',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -47,4 +53,11 @@ class TaskUpdateRequest extends FormRequest
|
||||
|
||||
return $this->boolean('is_done');
|
||||
}
|
||||
|
||||
public function getEstimatedTime(): ?int
|
||||
{
|
||||
$input = $this->input('estimated_time');
|
||||
|
||||
return $input !== null && $input !== 0 ? (int) $this->input('estimated_time') : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ class ProjectResource extends BaseResource
|
||||
'billable_rate' => $this->resource->billable_rate,
|
||||
/** @var bool $is_billable Project time entries billable default */
|
||||
'is_billable' => $this->resource->is_billable,
|
||||
/** @var int|null $estimated_time Estimated time in seconds */
|
||||
'estimated_time' => $this->resource->estimated_time,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ class TaskResource extends BaseResource
|
||||
'is_done' => $this->resource->is_done,
|
||||
/** @var string $project_id ID of the project */
|
||||
'project_id' => $this->resource->project_id,
|
||||
/** @var int|null $estimated_time Estimated time in seconds */
|
||||
'estimated_time' => $this->resource->estimated_time,
|
||||
/** @var string $created_at When the tag was created */
|
||||
'created_at' => $this->formatDateTime($this->resource->created_at),
|
||||
/** @var string $updated_at When the tag was last updated */
|
||||
|
||||
@@ -27,6 +27,7 @@ use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
|
||||
* @property bool $is_public
|
||||
* @property bool $is_billable
|
||||
* @property-read bool $is_archived
|
||||
* @property int|null $estimated_time
|
||||
* @property Carbon|null $archived_at
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
@@ -56,6 +57,7 @@ class Project extends Model implements AuditableContract
|
||||
'name' => 'string',
|
||||
'color' => 'string',
|
||||
'archived_at' => 'datetime',
|
||||
'estimated_time' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,7 @@ use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
|
||||
* @property string $project_id
|
||||
* @property string $organization_id
|
||||
* @property Carbon|null $done_at
|
||||
* @property int|null $estimated_time
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read Project $project
|
||||
@@ -48,6 +49,7 @@ class Task extends Model implements AuditableContract
|
||||
*/
|
||||
protected $casts = [
|
||||
'name' => 'string',
|
||||
'estimated_time' => 'integer',
|
||||
'done_at' => 'datetime',
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user