Add the task calendar, holidays, workflow templates and customer removal
Task calendar (/jobs/calendar) replaces per-unit task Kanban columns (K34): a two-week Gantt of tasks per person. Bars move, resize and change person by dragging or through a keyboard dialog. Each task's estimate is booked evenly over working days into task_bookings, and what exceeds the daily maximum (jobs.daily_capacity_hours, 8 h) moves to the next working day. Tasks get planned_from/planned_to on the form. Holidays (/settings/holidays): Finnish public holidays calculated per year, which the admin can take out of use, plus company days off. Also includes the earlier uncommitted work: workflow templates with adding tasks from a template, and removing customers no module refers to. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->travelTo(new DateTimeImmutable('2026-12-21 09:00'));
|
||||
|
||||
$this->employee = User::factory()->create(['name' => 'Eero Työntekijä']);
|
||||
$this->other = User::factory()->create(['name' => 'Aino Ahkera']);
|
||||
$this->actingAs($this->employee);
|
||||
$marketing = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole();
|
||||
$this->job = CustomerJobModel::factory()->create(['name' => 'Kampanja', 'status' => 'order', 'responsible_user_id' => $this->employee->id]);
|
||||
DB::table('customer_job_service_unit')->where('customer_job_id', $this->job->id)->update(['service_unit_id' => $marketing->id]);
|
||||
$this->graphic = WorkTypeModel::query()->where('name', 'graafinen työ')->sole();
|
||||
});
|
||||
|
||||
function calendarTaskModel(array $attributes, array $assignees): TaskModel
|
||||
{
|
||||
return TaskModel::factory()->assignedTo($assignees)->create($attributes);
|
||||
}
|
||||
|
||||
it('shows the two weeks from today with holidays, rows and bars', function () {
|
||||
calendarTaskModel(['customer_job_id' => test()->job->id, 'work_type_id' => test()->graphic->id, 'title' => 'Mainoskuvat', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-23'], [test()->other->id]);
|
||||
calendarTaskModel(['customer_job_id' => test()->job->id, 'work_type_id' => test()->graphic->id, 'title' => 'Ilman aikataulua'], [test()->employee->id]);
|
||||
|
||||
$this->get(route('jobs.calendar'))
|
||||
->assertOk()
|
||||
->assertSee('Tehtäväkalenteri')
|
||||
->assertSee('21.12.2026–3.1.2027')
|
||||
->assertSee('Jouluaatto')
|
||||
->assertSee('Uudenvuodenpäivä')
|
||||
->assertSeeInOrder(['Eero Työntekijä', 'Aino Ahkera', 'Ei tekijää'])
|
||||
->assertSee('Mainoskuvat')
|
||||
->assertSee('Aikatauluttamattomat tehtävät')
|
||||
->assertSee('Ilman aikataulua');
|
||||
});
|
||||
|
||||
it('moves a task to another person by dropping it and books their days', function () {
|
||||
$task = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Mainoskuvat', 'estimated_hours' => 12], [$this->employee->id]);
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('reschedule', $task->id, $this->job->id, $this->employee->id, $this->other->id, '2026-12-28', null)
|
||||
->assertSee('Tehtävä Mainoskuvat: Aino Ahkera 28.12.2026–29.12.2026.');
|
||||
|
||||
expect($task->refresh()->planned_from?->format('Y-m-d'))->toBe('2026-12-28')
|
||||
->and($task->planned_to?->format('Y-m-d'))->toBe('2026-12-29')
|
||||
->and(DB::table('task_assignees')->where('task_id', $task->id)->pluck('user_id')->all())->toBe([$this->other->id])
|
||||
->and(DB::table('task_bookings')->where('task_id', $task->id)->orderBy('day')->pluck('minutes', 'day')->all())->toBe(['2026-12-28' => 360, '2026-12-29' => 360]);
|
||||
});
|
||||
|
||||
it('continues a task on the next working day when the day is full', function () {
|
||||
calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Kuvaus', 'estimated_hours' => 6], [$this->employee->id]);
|
||||
$first = TaskModel::query()->sole();
|
||||
Livewire::test('jobs::calendar')->call('reschedule', $first->id, $this->job->id, $this->employee->id, $this->employee->id, '2026-12-23', '2026-12-23');
|
||||
$task = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Taitto', 'estimated_hours' => 4], [$this->employee->id]);
|
||||
|
||||
// 24.–27.12. are holidays and a weekend, so the rest goes to Monday.
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('reschedule', $task->id, $this->job->id, $this->employee->id, $this->employee->id, '2026-12-23', '2026-12-23')
|
||||
->assertSee('Päivät olivat täynnä, joten tehtävä jatkuu 28.12.2026 asti.')
|
||||
->assertSee('8 / 8 h');
|
||||
|
||||
expect($task->refresh()->planned_to?->format('Y-m-d'))->toBe('2026-12-28');
|
||||
});
|
||||
|
||||
it('changes the schedule and status in the dialog and takes a task out of the calendar', function () {
|
||||
$task = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Mainoskuvat', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-22'], [$this->employee->id]);
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('openDialog', $task->id, $this->employee->id)
|
||||
->assertSet('plannedFrom', '2026-12-22')
|
||||
->set('plannedFrom', '2026-12-29')
|
||||
->set('plannedTo', '2026-12-28')
|
||||
->call('saveDialog')
|
||||
->assertHasErrors('plannedTo')
|
||||
->set('plannedTo', '2026-12-30')
|
||||
->set('status', 'in_progress')
|
||||
->call('saveDialog')
|
||||
->assertHasNoErrors()
|
||||
->assertSee('Tehtävän Mainoskuvat tila on nyt Työn alla.')
|
||||
->call('openDialog', $task->id, $this->employee->id)
|
||||
->call('clearSchedule')
|
||||
->assertSee('Tehtävän Mainoskuvat aikataulu poistettu.');
|
||||
|
||||
expect($task->refresh()->status->value)->toBe('in_progress')
|
||||
->and($task->planned_from)->toBeNull();
|
||||
});
|
||||
|
||||
it('shows a subcontractor only their own row and lets them change only the status', function () {
|
||||
$subcontractor = User::factory()->subcontractor()->create(['name' => 'Ville Alihankkija']);
|
||||
DB::table('customer_job_members')->insert(['customer_job_id' => $this->job->id, 'user_id' => $subcontractor->id]);
|
||||
$own = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Oma tehtävä', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-22'], [$subcontractor->id]);
|
||||
calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Toisen tehtävä', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-22'], [$this->employee->id]);
|
||||
$this->actingAs($subcontractor);
|
||||
|
||||
$this->get(route('jobs.calendar'))
|
||||
->assertOk()
|
||||
->assertSee('Oma tehtävä')
|
||||
->assertDontSee('Toisen tehtävä')
|
||||
->assertDontSee('Eero Työntekijä')
|
||||
->assertDontSee('Ei tekijää');
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('reschedule', $own->id, $this->job->id, $subcontractor->id, $subcontractor->id, '2026-12-28', null)
|
||||
->assertForbidden();
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('openDialog', $own->id, $subcontractor->id)
|
||||
->set('status', 'done')
|
||||
->call('saveDialog')
|
||||
->assertSee('Tehtävän Oma tehtävä tila on nyt Valmis.');
|
||||
|
||||
expect($own->refresh()->status->value)->toBe('done')
|
||||
->and($own->planned_from?->format('Y-m-d'))->toBe('2026-12-22');
|
||||
});
|
||||
|
||||
it('adds a schedule on the task form', function () {
|
||||
Livewire::test('jobs::task-form', ['job' => $this->job->id])
|
||||
->set('form.title', 'Mainoskuvat')
|
||||
->set('form.work_type_id', (string) $this->graphic->id)
|
||||
->set('form.estimated_hours', '4')
|
||||
->set('form.planned_from', '2026-12-28')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$task = TaskModel::query()->sole();
|
||||
|
||||
expect($task->planned_to?->format('Y-m-d'))->toBe('2026-12-28')
|
||||
->and(DB::table('task_bookings')->where('task_id', $task->id)->sum('minutes'))->toBe(240);
|
||||
});
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
use App\Modules\Catalog\Application\UseCases\AddWorkflowTemplate;
|
||||
use App\Modules\Catalog\Application\UseCases\SetWorkflowTemplateActive;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Features\SupportLockedProperties\CannotUpdateLockedPropertyException;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->employee = User::factory()->create(['name' => 'Eero Työntekijä']);
|
||||
$this->actingAs($this->employee);
|
||||
$this->marketing = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole();
|
||||
$this->job = CustomerJobModel::factory()->create(['name' => 'Kampanja', 'status' => 'order', 'responsible_user_id' => $this->employee->id]);
|
||||
DB::table('customer_job_service_unit')->where('customer_job_id', $this->job->id)->update(['service_unit_id' => $this->marketing->id]);
|
||||
$this->graphic = WorkTypeModel::query()->where('name', 'graafinen työ')->sole();
|
||||
$this->planning = WorkTypeModel::query()->where('name', 'suunnittelu')->sole();
|
||||
$printing = WorkTypeModel::query()->where('name', 'painotyö')->sole();
|
||||
|
||||
$add = fn (string $name, int $workTypeId, array $steps): int => app(AddWorkflowTemplate::class)->execute(new WorkflowTemplateData(
|
||||
$name,
|
||||
$workTypeId,
|
||||
array_map(fn (array $step): WorkflowStepData => new WorkflowStepData(...$step), $steps),
|
||||
));
|
||||
|
||||
$this->campaign = $add('Somekampanja', $this->graphic->id, [['Suunnittelu', 'Kohderyhmä ja viestit', $this->planning->id], ['Kuvat'], ['Julkaisu']]);
|
||||
$this->print = $add('Esite', $printing->id, [['Painatus']]);
|
||||
});
|
||||
|
||||
it('adds the steps of a template as tasks of the job', function () {
|
||||
$this->get(route('jobs.show', $this->job->id))->assertSee(route('jobs.tasks.from-template', $this->job->id));
|
||||
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->assertSee('Somekampanja (graafinen työ)')
|
||||
->assertSee('Vaiheet: Suunnittelu (suunnittelu) → Kuvat → Julkaisu')
|
||||
->assertDontSee('Esite')
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->call('add')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('jobs.show', $this->job->id).'#tasks');
|
||||
|
||||
$tasks = TaskModel::query()->orderBy('id')->get();
|
||||
|
||||
expect($tasks->map(fn ($task) => [$task->title, $task->work_type_id, $task->status->value, $task->description])->all())->toBe([
|
||||
['Suunnittelu', $this->planning->id, 'waiting', 'Kohderyhmä ja viestit'],
|
||||
['Kuvat', $this->graphic->id, 'waiting', null],
|
||||
['Julkaisu', $this->graphic->id, 'waiting', null],
|
||||
])
|
||||
->and(DB::table('task_assignees')->pluck('user_id')->unique()->values()->all())->toBe([$this->employee->id]);
|
||||
|
||||
$this->get(route('jobs.show', $this->job->id))->assertSee('Lisättiin 3 tehtävää pohjasta Somekampanja (graafinen työ).');
|
||||
});
|
||||
|
||||
it('needs a template that is still available', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->call('add')
|
||||
->assertHasErrors(['templateId'])
|
||||
->assertSee('Valitse pohja.');
|
||||
|
||||
$component = Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])->set('templateId', (string) $this->campaign);
|
||||
app(SetWorkflowTemplateActive::class)->execute($this->campaign, false);
|
||||
|
||||
$component->call('add')
|
||||
->assertHasErrors(['templateId'])
|
||||
->assertSee('Pohja ei ole enää käytettävissä tälle työlle. Valitse toinen.');
|
||||
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->set('templateId', (string) $this->print)
|
||||
->call('add')
|
||||
->assertHasErrors(['templateId']);
|
||||
|
||||
expect(TaskModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('is not for subcontractors, jobs before a quote request or archived jobs', function () {
|
||||
$this->job->update(['status' => 'tentative']);
|
||||
$this->get(route('jobs.tasks.from-template', $this->job->id))->assertNotFound();
|
||||
|
||||
$this->job->update(['status' => 'archived']);
|
||||
$this->get(route('jobs.tasks.from-template', $this->job->id))->assertNotFound();
|
||||
|
||||
$this->job->update(['status' => 'order']);
|
||||
$subcontractor = User::factory()->subcontractor()->create();
|
||||
DB::table('customer_job_members')->insert(['customer_job_id' => $this->job->id, 'user_id' => $subcontractor->id]);
|
||||
|
||||
$this->actingAs($subcontractor)->get(route('jobs.tasks.from-template', $this->job->id))->assertForbidden();
|
||||
});
|
||||
|
||||
it('locks the job id', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])->set('jobId', 999);
|
||||
})->throws(CannotUpdateLockedPropertyException::class);
|
||||
|
||||
it('shows a table of the chosen template tasks and saves their due dates and estimates', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->assertDontSee('Pohjan Somekampanja tehtävät')
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->assertSet('rows', array_fill(0, 3, ['due_on' => '', 'estimated_hours' => '']))
|
||||
->assertSee('Pohjan Somekampanja tehtävät')
|
||||
->assertSee('Määräpäivä: Kuvat')
|
||||
->assertSee('Arvioitu aika (h): Julkaisu')
|
||||
->set('rows.0.due_on', '2026-06-01')
|
||||
->set('rows.0.estimated_hours', '1,5')
|
||||
->set('rows.2.estimated_hours', '2')
|
||||
->call('add')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$tasks = TaskModel::query()->orderBy('id')->get();
|
||||
|
||||
expect($tasks->map(fn ($task) => [$task->title, $task->due_on?->format('Y-m-d'), $task->estimated_hours === null ? null : (float) $task->estimated_hours])->all())->toBe([
|
||||
['Suunnittelu', '2026-06-01', 1.5],
|
||||
['Kuvat', null, null],
|
||||
['Julkaisu', null, 2.0],
|
||||
]);
|
||||
});
|
||||
|
||||
it('shows errors in the table cells and adds nothing', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->set('rows.1.due_on', '1.6.2026')
|
||||
->set('rows.2.estimated_hours', 'paljon')
|
||||
->call('add')
|
||||
->assertHasErrors(['rows.1.due_on', 'rows.2.estimated_hours'])
|
||||
->assertSee('aria-invalid="true"', escape: false);
|
||||
|
||||
expect(TaskModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('empties the rows when another template is chosen', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->set('rows.0.estimated_hours', '3')
|
||||
->set('templateId', '')
|
||||
->assertSet('rows', [])
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->assertSet('rows.0.estimated_hours', '');
|
||||
});
|
||||
Reference in New Issue
Block a user