mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-15 19:52:15 +01:00
Added client to time entries
This commit is contained in:
committed by
Constantin Graf
parent
2862033321
commit
ec239f20f2
@@ -15,6 +15,7 @@ use App\Http\Resources\V1\TimeEntry\TimeEntryCollection;
|
||||
use App\Http\Resources\V1\TimeEntry\TimeEntryResource;
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Project;
|
||||
use App\Models\TimeEntry;
|
||||
use App\Service\TimeEntryAggregationService;
|
||||
use App\Service\TimeEntryFilter;
|
||||
@@ -214,8 +215,11 @@ class TimeEntryController extends Controller
|
||||
throw new TimeEntryStillRunningApiException();
|
||||
}
|
||||
|
||||
$client = $request->get('project_id') !== null ? Project::findOrFail($request->get('project_id'))->client : null;
|
||||
|
||||
$timeEntry = new TimeEntry();
|
||||
$timeEntry->fill($request->validated());
|
||||
$timeEntry->client()->associate($client);
|
||||
$timeEntry->user_id = $member->user_id;
|
||||
$timeEntry->description = $request->get('description') ?? '';
|
||||
$timeEntry->organization()->associate($organization);
|
||||
@@ -246,6 +250,11 @@ class TimeEntryController extends Controller
|
||||
throw new TimeEntryCanNotBeRestartedApiException();
|
||||
}
|
||||
|
||||
if ($request->has('project_id')) {
|
||||
$client = $request->get('project_id') !== null ? Project::findOrFail($request->get('project_id'))->client : null;
|
||||
$timeEntry->client()->associate($client);
|
||||
}
|
||||
|
||||
$timeEntry->fill($request->validated());
|
||||
$timeEntry->description = $request->get('description', $timeEntry->description) ?? '';
|
||||
$timeEntry->save();
|
||||
@@ -274,6 +283,13 @@ class TimeEntryController extends Controller
|
||||
throw new AuthorizationException();
|
||||
}
|
||||
|
||||
$client = null;
|
||||
$overwriteClient = false;
|
||||
if ($request->has('changes.project_id')) {
|
||||
$client = $request->input('changes.project_id') !== null ? Project::findOrFail($request->input('changes.project_id'))?->client : null;
|
||||
$overwriteClient = true;
|
||||
}
|
||||
|
||||
$success = new Collection();
|
||||
$error = new Collection();
|
||||
|
||||
@@ -291,8 +307,10 @@ class TimeEntryController extends Controller
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
$timeEntry->fill($changes);
|
||||
if ($overwriteClient) {
|
||||
$timeEntry->client()->associate($client);
|
||||
}
|
||||
$timeEntry->save();
|
||||
$success->push($id);
|
||||
}
|
||||
|
||||
@@ -64,12 +64,10 @@ class TimeEntryUpdateRequest extends FormRequest
|
||||
],
|
||||
// Start of time entry (ISO 8601 format, UTC timezone)
|
||||
'start' => [
|
||||
'required',
|
||||
'date_format:Y-m-d\TH:i:s\Z',
|
||||
],
|
||||
// End of time entry (ISO 8601 format, UTC timezone)
|
||||
'end' => [
|
||||
'present',
|
||||
'nullable',
|
||||
'date_format:Y-m-d\TH:i:s\Z',
|
||||
'after:start',
|
||||
|
||||
@@ -31,6 +31,8 @@ use Korridor\LaravelComputedAttributes\ComputedAttributes;
|
||||
* @property-read Organization $organization
|
||||
* @property string|null $project_id
|
||||
* @property-read Project|null $project
|
||||
* @property string|null $client_id
|
||||
* @property-read Client|null $client
|
||||
* @property string|null $task_id
|
||||
* @property-read Task|null $task
|
||||
*
|
||||
@@ -124,4 +126,14 @@ class TimeEntry extends Model
|
||||
{
|
||||
return $this->belongsTo(Task::class, 'task_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* This relation can be reconstructed via the task relation. It is only here for performance reasons.
|
||||
*
|
||||
* @return BelongsTo<Client, TimeEntry>
|
||||
*/
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class, 'client_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ class ClockifyTimeEntriesImporter extends DefaultImporter
|
||||
$timeEntry->member_id = $memberId;
|
||||
$timeEntry->task_id = $taskId;
|
||||
$timeEntry->project_id = $projectId;
|
||||
$timeEntry->client_id = $clientId;
|
||||
$timeEntry->organization_id = $this->organization->id;
|
||||
if (strlen($record['Description']) > 500) {
|
||||
throw new ImportException('Time entry description is too long');
|
||||
|
||||
@@ -93,6 +93,7 @@ class TogglTimeEntriesImporter extends DefaultImporter
|
||||
$timeEntry->member_id = $memberId;
|
||||
$timeEntry->task_id = $taskId;
|
||||
$timeEntry->project_id = $projectId;
|
||||
$timeEntry->client_id = $clientId;
|
||||
$timeEntry->organization_id = $this->organization->id;
|
||||
$timeEntry->description = $record['Description'];
|
||||
if (! in_array($record['Billable'], ['Yes', 'No'], true)) {
|
||||
|
||||
Reference in New Issue
Block a user