Give the machine console its own session with PIN sign-in, make counters cumulative

The console under console/ has its own session cookie and console guard
(UseConsoleSession), so signing out or changing user there leaves the
normal interface alone. Links open it in a new window through a one-time
handoff key; a signed-out console asks for a PIN code or password on its
own login page. Users set their 4-6 digit PIN on the profile's PIN page,
and the console's change user dialog takes it on a keypad; five wrong
PINs lock PIN sign-in for 15 minutes.

Machine counters are cumulative: users record how much a job used and it
is added to the latest reading. A maintenance record restarts the whole
counter interval from the reading at the record.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-29 09:58:11 +02:00
co-authored by Claude Sonnet 5.5
parent 87e38260dc
commit 32c33e2a64
55 changed files with 1660 additions and 194 deletions
@@ -5,6 +5,7 @@ use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
use App\Modules\Inventory\Infrastructure\Persistence\Eloquent\StockItemModel;
use App\Modules\Inventory\Infrastructure\Persistence\Eloquent\StockMovementModel;
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineCounterModel;
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineCounterReadingModel;
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineModel;
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MaintenanceItemModel;
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MaintenanceRecordModel;
@@ -54,7 +55,41 @@ it('adds maintenance items with a counter interval, time intervals or both, and
$this->get(route('machines.maintenance.create', $this->machine->id))->assertForbidden();
});
it('shows a maintenance request when due and starts the interval again with a maintenance record that uses the stock item', function () {
it('adds the usage of a job to the cumulative counter and refuses an empty or zero usage', function () {
$this->actingAs($this->employee);
Livewire::test('machines::maintenance', ['machineId' => $this->machine->id])
->set('usage.'.$this->prints->id, '350')
->call('saveUsage', $this->prints->id)
->assertHasNoErrors()
->set('usage.'.$this->prints->id, '1 000')
->call('saveUsage', $this->prints->id)
->assertSet('message', "Laskuriin Tulosteet lisätty 1\u{00A0}000 kpl, laskuri nyt 1\u{00A0}350 kpl.")
->set('usage.'.$this->prints->id, '0')
->call('saveUsage', $this->prints->id)
->assertHasErrors('usage.'.$this->prints->id)
->set('usage.'.$this->prints->id, '')
->call('saveUsage', $this->prints->id)
->assertHasErrors('usage.'.$this->prints->id);
expect(MachineCounterReadingModel::query()->orderBy('id')->pluck('reading_milli')->all())->toBe([350_000, 1_350_000]);
});
it('hides the maintenance sections of a machine without counters and maintenance items from users', function () {
$this->prints->delete();
$this->actingAs($this->employee);
Livewire::test('machines::maintenance', ['machineId' => $this->machine->id])
->assertDontSee(__('machines.maintenance.items'))
->assertDontSee(__('machines.maintenance.history'));
$this->actingAs($this->manager);
Livewire::test('machines::maintenance', ['machineId' => $this->machine->id])
->assertSee(__('machines.maintenance.add'))
->assertDontSee(__('machines.maintenance.history'));
});
it('shows a maintenance request when due and resets the interval with a maintenance record that uses the stock item', function () {
$item = MaintenanceItemModel::query()->create([
'machine_id' => $this->machine->id, 'name' => 'Rummun vaihto', 'machine_counter_id' => $this->prints->id, 'interval_milli' => 20_000_000,
'counter_baseline_milli' => 0, 'period' => 'week', 'period_count' => 1, 'starts_on' => now()->toDateString(), 'warning_percent' => 90,
@@ -64,8 +99,8 @@ it('shows a maintenance request when due and starts the interval again with a ma
Livewire::test('machines::maintenance', ['machineId' => $this->machine->id])
->assertSee('Kunnossa')
->set('readings.'.$this->prints->id, '19 000')
->call('saveReading', $this->prints->id)
->set('usage.'.$this->prints->id, '19 000')
->call('saveUsage', $this->prints->id)
->assertSee('Huolto lähestyy')
->assertSee("jäljellä 1\u{00A0}000 kpl", false);
@@ -74,18 +109,17 @@ it('shows a maintenance request when due and starts the interval again with a ma
Livewire::test('machines::maintenance', ['machineId' => $this->machine->id])
->assertSee('Huolto myöhässä')
->call('startRecord', $item->id)
->assertSet('recordReading', '19000')
->set('recordReading', '19500')
->set('recordNote', 'Rumpu vaihdettu')
->call('record')
->assertSet('message', 'Huolto Rummun vaihto kirjattu.')
->assertSee('Kunnossa')
->assertSee("jäljellä 20\u{00A0}000 kpl", false)
->assertSee('Rumpu vaihdettu');
$record = MaintenanceRecordModel::query()->sole();
$use = StockMovementModel::query()->sole();
expect($record->counter_reading_milli)->toBe(19_500_000)
expect($record->counter_reading_milli)->toBe(19_000_000)
->and($use->only(['stock_item_id', 'machine_id', 'maintenance_record_id', 'quantity_milli']))
->toBe(['stock_item_id' => $this->drum->id, 'machine_id' => $this->machine->id, 'maintenance_record_id' => $record->id, 'quantity_milli' => -1_000]);