Added client to time entries

This commit is contained in:
Constantin Graf
2024-05-29 17:20:37 +02:00
committed by Constantin Graf
parent 2862033321
commit ec239f20f2
10 changed files with 372 additions and 7 deletions

View File

@@ -155,6 +155,7 @@ class TimeEntryFactory extends Factory
return $this->state(function (array $attributes) use ($project) {
return [
'project_id' => $project?->getKey(),
'client_id' => $project?->client_id,
];
});
}
@@ -164,6 +165,8 @@ class TimeEntryFactory extends Factory
return $this->state(function (array $attributes) use ($task) {
return [
'task_id' => $task?->getKey(),
'project_id' => $task?->project?->getKey(),
'client_id' => $task?->project?->client?->getKey(),
];
});
}

View File

@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('time_entries', function (Blueprint $table) {
$table->foreignUuid('client_id')
->nullable()
->constrained('clients')
->cascadeOnDelete()
->cascadeOnUpdate();
});
DB::statement('
update time_entries
set client_id = clients.id
from projects
join clients on projects.client_id = clients.id
where time_entries.project_id = projects.id
');
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('time_entries', function (Blueprint $table) {
$table->dropForeign(['client_id']);
$table->dropColumn('client_id');
});
}
};

View File

@@ -89,6 +89,12 @@ class DatabaseSeeder extends Seeder
ProjectMember::factory()->forProject($bigCompanyProject)->forMember($userAcmeAdminMember)->create();
ProjectMember::factory()->forProject($bigCompanyProject)->forMember($userWithMultipleOrganizationsAcmeMember)->create();
TimeEntry::factory()
->count(3)
->forMember($userAcmeEmployeeMember)
->forProject($bigCompanyProject)
->create();
Task::factory()->forOrganization($organizationAcme)->forProject($bigCompanyProject)->create();
$internalProject = Project::factory()->forOrganization($organizationAcme)->create([