Set the calendar's daily capacity in the company details

The task calendar's daily maximum moves from the hidden setting
jobs.daily_capacity_hours to shared.daily_capacity_hours, edited by the
admin on the company details page. An empty field means 7.5 hours.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-25 11:00:35 +02:00
co-authored by Claude Sonnet 5.5
parent e0da863cf7
commit 7c605014c7
16 changed files with 245 additions and 23 deletions
@@ -101,7 +101,7 @@ it('gives admin and management the management panel', function () {
$load = collect($overview->workloads)->firstWhere('userId', $this->worker->id);
expect($load->thisWeek->bookedMinutes)->toBe(2700)
->and($load->thisWeek->capacityMinutes)->toBe(5 * 8 * 60)
->and($load->thisWeek->capacityMinutes)->toBe(5 * 450)
->and(collect($overview->workloads)->pluck('userId'))->toContain($manager->id);
});
@@ -68,7 +68,7 @@ it('continues a task on the next working day when the day is full', function ()
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');
->assertSee('7,5 / 7,5 h');
expect($task->refresh()->planned_to?->format('Y-m-d'))->toBe('2026-12-28');
});
@@ -9,6 +9,8 @@ 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 App\Modules\Shared\Application\Contracts\Settings;
use App\Modules\Shared\Application\UseCases\DailyCapacity;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Livewire\Features\SupportLockedProperties\CannotUpdateLockedPropertyException;
@@ -17,6 +19,7 @@ use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
app(Settings::class)->put(DailyCapacity::KEY, '8');
$this->employee = User::factory()->create(['name' => 'Eero Työntekijä']);
$this->actingAs($this->employee);
$this->marketing = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole();
@@ -1,7 +1,9 @@
<?php
use App\Models\User;
use App\Modules\Jobs\Application\Services\TaskPlanner;
use App\Modules\Shared\Application\UseCases\CompanyDetailsStore;
use App\Modules\Shared\Application\UseCases\DailyCapacity;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
@@ -76,6 +78,44 @@ it('falls back to the application name when the menu name is empty, even before
->and($store->menuName())->toBe(config('app.name'));
});
it('saves the calendar daily capacity, 7.5 hours when empty', function () {
$this->actingAs(User::factory()->admin()->create());
$capacity = app(DailyCapacity::class);
Livewire::test('shared::company')
->assertSet('daily_capacity_hours', '')
->set('name', 'Mediatalo Oy')
->set('business_id', '0737546-2')
->set('daily_capacity_hours', '6,5')
->call('save')
->assertHasNoErrors();
expect($capacity->minutes())->toBe(390)
->and(app(TaskPlanner::class)->capacityMinutes())->toBe(390);
Livewire::test('shared::company')
->assertSet('daily_capacity_hours', '6,5')
->set('daily_capacity_hours', '')
->call('save')
->assertHasNoErrors();
expect($capacity->minutes())->toBe(450);
});
it('rejects an invalid daily capacity without saving anything', function () {
$this->actingAs(User::factory()->admin()->create());
Livewire::test('shared::company')
->set('name', 'Mediatalo Oy')
->set('business_id', '0737546-2')
->set('daily_capacity_hours', '25')
->call('save')
->assertHasErrors(['daily_capacity_hours' => [__('company.errors.daily_capacity_hours')]]);
expect(app(CompanyDetailsStore::class)->get())->toBeNull()
->and(app(DailyCapacity::class)->hours())->toBeNull();
});
it('rejects a menu name over 100 characters', function () {
$this->actingAs(User::factory()->admin()->create());
@@ -23,6 +23,7 @@ use App\Modules\Jobs\Domain\Exceptions\TaskHasTimeEntries;
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
use App\Modules\Jobs\Domain\Exceptions\TasksNotAllowedYet;
use App\Modules\Jobs\Domain\ValueObjects\TaskTitle;
use App\Modules\Shared\Application\UseCases\DailyCapacity;
use App\Modules\Shared\Application\UseCases\HolidayCalendar;
use Tests\Fakes\FakeCatalogQueries;
use Tests\Fakes\FakeClock;
@@ -64,7 +65,7 @@ beforeEach(function () {
$checker = new TaskReferenceChecker($this->catalog, $this->users);
$this->bookings = new InMemoryTaskBookingRepository($this->tasks);
$this->planner = new TaskPlanner($this->bookings, new HolidayCalendar(new InMemoryHolidayOverrides), new FakeSettings);
$this->planner = new TaskPlanner($this->bookings, new HolidayCalendar(new InMemoryHolidayOverrides), new DailyCapacity(tap(new FakeSettings, fn (FakeSettings $settings) => $settings->put(DailyCapacity::KEY, '8'))));
$this->addTask = new AddTask($this->jobs, $this->tasks, $checker, $this->planner, $transactions, $this->events);
$this->updateTask = new UpdateTask($this->jobs, $this->tasks, $checker, $this->planner, $transactions, $this->events);
$this->scheduleTask = new ScheduleTask($this->jobs, $this->tasks, $checker, $this->planner, $transactions, $this->events);
@@ -13,6 +13,7 @@ use App\Modules\Jobs\Domain\Exceptions\InvalidEstimatedHours;
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
use App\Modules\Jobs\Domain\Exceptions\TasksNotAllowedYet;
use App\Modules\Jobs\Domain\Exceptions\WorkflowTemplateNotAvailable;
use App\Modules\Shared\Application\UseCases\DailyCapacity;
use App\Modules\Shared\Application\UseCases\HolidayCalendar;
use Tests\Fakes\FakeCatalogQueries;
use Tests\Fakes\FakeClock;
@@ -59,7 +60,7 @@ beforeEach(function () {
$this->templates->addTemplate(4, 'Rikki', 11, 1, [['Painatus', 21]]);
$this->bookings = new InMemoryTaskBookingRepository($this->tasks);
$planner = new TaskPlanner($this->bookings, new HolidayCalendar(new InMemoryHolidayOverrides), new FakeSettings);
$planner = new TaskPlanner($this->bookings, new HolidayCalendar(new InMemoryHolidayOverrides), new DailyCapacity(tap(new FakeSettings, fn (FakeSettings $settings) => $settings->put(DailyCapacity::KEY, '8'))));
$this->addTasks = new AddTasksFromWorkflowTemplate($this->jobs, $this->tasks, $this->templates, new TaskReferenceChecker($catalog, $users), $planner, new FakeClock(new DateTimeImmutable('2026-05-01')), $transactions, $this->events);
});
@@ -0,0 +1,35 @@
<?php
use App\Modules\Shared\Application\UseCases\DailyCapacity;
use App\Modules\Shared\Domain\Exceptions\InvalidDailyCapacity;
use Tests\Fakes\FakeSettings;
it('is 7.5 hours until set', function () {
$capacity = new DailyCapacity(new FakeSettings);
expect($capacity->minutes())->toBe(450)
->and($capacity->hours())->toBeNull();
});
it('saves hours with a comma or a point and clears them when empty', function () {
$settings = new FakeSettings;
$capacity = new DailyCapacity($settings);
$capacity->save(' 6,5 ');
expect($capacity->minutes())->toBe(390)
->and($capacity->hours())->toBe('6,5')
->and($settings->get(DailyCapacity::KEY))->toBe('6.5');
$capacity->save('8.0');
expect($capacity->minutes())->toBe(480)
->and($capacity->hours())->toBe('8');
$capacity->save('');
expect($capacity->minutes())->toBe(450)
->and($settings->get(DailyCapacity::KEY))->toBeNull();
});
it('rejects hours that are not more than 0 and at most 24', function (string $hours) {
expect(DailyCapacity::isValid($hours))->toBeFalse()
->and(fn () => (new DailyCapacity(new FakeSettings))->save($hours))->toThrow(InvalidDailyCapacity::class);
})->with(['0', '-1', '24,5', 'abc', '7,5 h']);