Add an editable menu name and reserve billing material numbers on creation
- Company details get an optional "Valikon nimi", shown at the left of the main menu; it falls back to the application name when empty. - A billing material gets its running number (billing_exports.number) only when it is created, so discarded drafts leave no gaps. Drafts have no number; existing created materials are numbered by the migration, and the CSV file name uses the number. - TaskAssigneeMigrationTest rolls back from its own migration onward instead of assuming it is the last one. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
||||
|
||||
## Project
|
||||
|
||||
An ERP / work-management system (*toiminnanohjausjärjestelmä*) for a small (5–10 person) Finnish media/marketing company. Stack: Laravel 13, Livewire 4 (single-file components), TallStackUI 4 (Blade components, no prefix: `<x-input>`, `<x-button>`), Tailwind 4, Vite 8, Pest, Larastan. Domain code lives in modules under `app/Modules` (so far `Shared`, `Users`, `Customers`, `Catalog` (service units, services and work types, managed on the Pohjatiedot page; workflow templates of work types with ordered steps, read through `WorkflowTemplateQueries`, from which Jobs' `AddTasksFromWorkflowTemplate` makes a job's tasks, each with its own assignee and, by default, scheduled to end on its due date with the estimate booked backwards from it (`TaskPlanner::planBackwards`, not before today); hourly rates, products and the mileage rate on the Hinnasto page, read through `PriceListQueries`, never `CatalogQueries`) `Jobs` (customer jobs: numbering, members, tags, links, history, tasks with one assignee (`tasks.assignee_user_id`) and members (`task_members`, who see the task among their own but get no bookings), task checklists, and the task calendar `jobs::calendar`: a Gantt of tasks on their assignee's row where `ScheduleTask` moves a task's planned period and assignee and `TaskPlanner`/`TaskScheduler` book its estimate into `task_bookings` for the assignee only, split over working days with the rest moved to the next working day past the daily maximum `jobs.daily_capacity_hours`) `TimeTracking` (hours on tasks: weekly sheet and task booking page) `Expenses` (expenses on jobs with cost, markup and billed amount; reads jobs and prices through its own `ExpenseJobs`/`ExpensePricing` ports) `Billing` (the monthly billing material: a draft of invoices made of done jobs and monthly fee jobs (one line per unbilled month up to the draft's month, each such job an invoice of its own), management's billable hours, and on creation invoice lines with price snapshots, downloadable as a semicolon CSV with amounts in whole cents and the VAT rate in tenths of a percent (`billing.csv`, with consumers' identity codes for those who may see them); reads and marks hours, expenses and jobs through its `BillingJobs`/`BillingHours`/`BillingExpenses`/`BillingPrices` ports, which call those modules' queries and the use cases `MarkJobHoursBilled`, `MarkJobExpensesBilled` and `ChangeJobStatus`) and `Sales` (quick sales of consumer products at the counter, credits and cash days; its `QuickSaleHours` port books product durations through Jobs' `ProvideQuickSaleTask` (the yearly "Pikamyynnit" job) and TimeTracking's `AddTaskHours`)); `/` is still a temporary Livewire demo page behind login (`resources/views/pages/⚡home.blade.php`, layout `resources/views/layouts/app.blade.php`, which has the main menu and logout for signed-in users).
|
||||
An ERP / work-management system (*toiminnanohjausjärjestelmä*) for a small (5–10 person) Finnish media/marketing company. Stack: Laravel 13, Livewire 4 (single-file components), TallStackUI 4 (Blade components, no prefix: `<x-input>`, `<x-button>`), Tailwind 4, Vite 8, Pest, Larastan. Domain code lives in modules under `app/Modules` (so far `Shared`, `Users`, `Customers`, `Catalog` (service units, services and work types, managed on the Pohjatiedot page; workflow templates of work types with ordered steps, read through `WorkflowTemplateQueries`, from which Jobs' `AddTasksFromWorkflowTemplate` makes a job's tasks, each with its own assignee and, by default, scheduled to end on its due date with the estimate booked backwards from it (`TaskPlanner::planBackwards`, not before today); hourly rates, products and the mileage rate on the Hinnasto page, read through `PriceListQueries`, never `CatalogQueries`) `Jobs` (customer jobs: numbering, members, tags, links, history, tasks with one assignee (`tasks.assignee_user_id`) and members (`task_members`, who see the task among their own but get no bookings), task checklists, and the task calendar `jobs::calendar`: a Gantt of tasks on their assignee's row where `ScheduleTask` moves a task's planned period and assignee and `TaskPlanner`/`TaskScheduler` book its estimate into `task_bookings` for the assignee only, split over working days with the rest moved to the next working day past the daily maximum `jobs.daily_capacity_hours`) `TimeTracking` (hours on tasks: weekly sheet and task booking page) `Expenses` (expenses on jobs with cost, markup and billed amount; reads jobs and prices through its own `ExpenseJobs`/`ExpensePricing` ports) `Billing` (the monthly billing material (its running number `billing_exports.number` is reserved only when it is created, so discarded drafts leave no gaps, and a draft has none): a draft of invoices made of done jobs and monthly fee jobs (one line per unbilled month up to the draft's month, each such job an invoice of its own), management's billable hours, and on creation invoice lines with price snapshots, downloadable as a semicolon CSV with amounts in whole cents and the VAT rate in tenths of a percent (`billing.csv`, with consumers' identity codes for those who may see them); reads and marks hours, expenses and jobs through its `BillingJobs`/`BillingHours`/`BillingExpenses`/`BillingPrices` ports, which call those modules' queries and the use cases `MarkJobHoursBilled`, `MarkJobExpensesBilled` and `ChangeJobStatus`) and `Sales` (quick sales of consumer products at the counter, credits and cash days; its `QuickSaleHours` port books product durations through Jobs' `ProvideQuickSaleTask` (the yearly "Pikamyynnit" job) and TimeTracking's `AddTaskHours`)); `/` is still a temporary Livewire demo page behind login (`resources/views/pages/⚡home.blade.php`, layout `resources/views/layouts/app.blade.php`, which has the main menu and logout for signed-in users).
|
||||
|
||||
- **The specification is `docs/maarittely.md`** (Finnish). It defines roles and the permission table, money visibility, customers, customer jobs (*asiakastyö*) with fields and enum keys, Kanban, tasks, time entries, expenses, the service unit → service → work type hierarchy and pricing, Fennoa billing export, the data model, the phases with phase 1 in detail, and open questions. Read it before designing any domain feature. `määrittely.txt` is the original description with the customer's answers to questions 1–53, referenced as *(K12)* in the spec.
|
||||
- **Language rule:** code (identifiers, tables, columns, enum keys) is in English; the specification and the UI are in Finnish. Keep UI strings in translation files from the start.
|
||||
@@ -26,7 +26,7 @@ Read `docs/architecture.md` (Finnish) before adding or changing domain code. `ap
|
||||
- **Login** is the `Users` module: `Auth::attemptWhen` with `CheckLoginAllowed` (active, intern's last day not passed), and the `EnsureAccountIsUsable` web middleware ends sessions of users who are no longer allowed in. Nobody handles passwords: new users and "forgot password" get the same emailed set-password link, and when an admin creates a user or asks for a new link, the link is also shown to the admin to copy. Admin links use the `admin_links` broker (own table, valid 72 h); forgot-password links use the default broker (60 min); the reset page accepts both, and using or issuing a link ends the user's earlier links. `AuthenticateSession` ends a user's other sessions when the password changes. Passwords need 12+ characters with mixed case, a number and a symbol (`Password::defaults` in `UsersServiceProvider`). Login allows 5 failed attempts a minute per email + IP and 20 per IP; the forgot-password page 5 requests a minute per IP.
|
||||
- **Main menu**: the layout renders the groups of `App\View\MainMenu` (Työt, Oma kirjaus, Asiakkaat ja myynti, Hallinto, Ylläpito) as disclosure popovers (`resources/views/components/nav-group.blade.php`). A new page is added to `MainMenu::definition()` with the Gate ability of its route; groups with no allowed links disappear.
|
||||
- **Holidays** are Shared: `Shared\Application\UseCases\HolidayCalendar` gives the Finnish public holidays (`FinnishHolidays`, calculated) minus those the admin took out of use plus company days off (`holiday_overrides`), edited on `shared::holidays` (`/settings/holidays`, gate `settings.manage`).
|
||||
- **Company details** (name, business ID, address, phone, email) are kept by `Shared\Application\UseCases\CompanyDetailsStore` in the settings (`shared.company_*`) and edited by the admin on `shared::company` (`/settings/company`, gate `settings.manage`). `BusinessId` (Y-tunnus with check digit) is a Shared value object.
|
||||
- **Company details** (name, business ID, address, phone, email) are kept by `Shared\Application\UseCases\CompanyDetailsStore` in the settings (`shared.company_*`) and edited by the admin on `shared::company` (`/settings/company`, gate `settings.manage`). `BusinessId` (Y-tunnus with check digit) is a Shared value object. The name at the left of the main menu is the optional "Valikon nimi" (`shared.company_menu_name`), read with `CompanyDetailsStore::menuName()` (falls back to `config('app.name')`).
|
||||
- **PDFs** use `barryvdh/laravel-dompdf` with a plain Blade view (no Tailwind; DejaVu Sans), streamed inline: see the quick sale receipt `Sales\Presentation\Http\Controllers\ShowReceipt` and `Sales/Presentation/Views/receipt.blade.php` (view namespace `sales-views`).
|
||||
- **Security headers** (`X-Frame-Options`, `frame-ancestors`, `nosniff`, `Referrer-Policy`, HSTS over HTTPS) come from the global `Shared\Presentation\Http\Middleware\SetSecurityHeaders`, pushed in `SharedServiceProvider`. No full CSP: Alpine/Livewire need `unsafe-eval`.
|
||||
- Money is `Shared\Domain\ValueObjects\Money` (whole cents, `parse()` accepts "85,50", `format()` gives "85,50 €", `addVat()`/`removeVat()` with a `VatPercentage` round half up); store it in `*_cents` integer columns. Prices are without VAT except consumer product prices, which are stored with VAT. Show other than consumer prices only behind `money.prices` and keep amounts out of public Livewire properties. App-wide settings go through `Shared\Application\Contracts\Settings` (`settings` table) with keys prefixed by the owning module.
|
||||
|
||||
@@ -14,6 +14,7 @@ final readonly class ExportSummary
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public ?int $number,
|
||||
public ExportStatus $status,
|
||||
public DateTimeImmutable $createdAt,
|
||||
public string $createdByName,
|
||||
|
||||
@@ -21,6 +21,7 @@ final readonly class ExportView
|
||||
*/
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public ?int $number,
|
||||
public ExportStatus $status,
|
||||
public string $period,
|
||||
public DateTimeImmutable $createdAt,
|
||||
|
||||
@@ -70,6 +70,7 @@ final class ExportViews
|
||||
|
||||
return new ExportView(
|
||||
(int) $export->id(),
|
||||
$export->number(),
|
||||
$export->status(),
|
||||
$export->period(),
|
||||
$export->createdAt(),
|
||||
|
||||
@@ -23,7 +23,8 @@ use App\Modules\Users\Application\Contracts\Clock;
|
||||
* Creates the billing material from its draft (spec 12), all or nothing:
|
||||
* checks every job again, marks the approved hours and billable expenses
|
||||
* billed, forms the invoice lines from what was marked with the current
|
||||
* prices, and moves the jobs to "Lasku luotu". Monthly fee jobs keep
|
||||
* prices, gives the material the next running number (reserved only now, so
|
||||
* discarded drafts leave no gaps), and moves the jobs to "Lasku luotu". Monthly fee jobs keep
|
||||
* running, so their status stays.
|
||||
*/
|
||||
final class FinalizeBillingExport
|
||||
@@ -81,7 +82,7 @@ final class FinalizeBillingExport
|
||||
}
|
||||
}
|
||||
|
||||
$export->finalize($linesByJob, $actorUserId, $this->clock->now());
|
||||
$export->finalize($linesByJob, $this->exports->nextNumber(), $actorUserId, $this->clock->now());
|
||||
$this->exports->save($export);
|
||||
|
||||
return count($export->invoices());
|
||||
|
||||
@@ -26,6 +26,11 @@ interface BillingExportRepository
|
||||
|
||||
public function delete(BillingExport $export): void;
|
||||
|
||||
/**
|
||||
* The next free number of a created material (1, 2, ...), without gaps.
|
||||
*/
|
||||
public function nextNumber(): int;
|
||||
|
||||
/**
|
||||
* The jobs among the given ones whose fixed price is already on a created material.
|
||||
*
|
||||
|
||||
@@ -30,6 +30,7 @@ final class BillingExport
|
||||
*/
|
||||
private function __construct(
|
||||
private ?int $id,
|
||||
private ?int $number,
|
||||
private ExportStatus $status,
|
||||
private string $period,
|
||||
private int $createdBy,
|
||||
@@ -44,15 +45,15 @@ final class BillingExport
|
||||
*/
|
||||
public static function startDraft(int $createdBy, DateTimeImmutable $now): self
|
||||
{
|
||||
return new self(null, ExportStatus::Draft, $now->format('Y-m'), $createdBy, $now, null, null, []);
|
||||
return new self(null, null, ExportStatus::Draft, $now->format('Y-m'), $createdBy, $now, null, null, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<BillingInvoice> $invoices
|
||||
*/
|
||||
public static function reconstitute(int $id, ExportStatus $status, string $period, int $createdBy, DateTimeImmutable $createdAt, ?int $finalizedBy, ?DateTimeImmutable $finalizedAt, array $invoices): self
|
||||
public static function reconstitute(int $id, ?int $number, ExportStatus $status, string $period, int $createdBy, DateTimeImmutable $createdAt, ?int $finalizedBy, ?DateTimeImmutable $finalizedAt, array $invoices): self
|
||||
{
|
||||
return new self($id, $status, $period, $createdBy, $createdAt, $finalizedBy, $finalizedAt, $invoices);
|
||||
return new self($id, $number, $status, $period, $createdBy, $createdAt, $finalizedBy, $finalizedAt, $invoices);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,14 +171,14 @@ final class BillingExport
|
||||
}
|
||||
|
||||
/**
|
||||
* Forms the invoice lines and locks the material.
|
||||
* Forms the invoice lines, gives the material its number and locks it.
|
||||
*
|
||||
* @param array<int, list<InvoiceLine>> $linesByJob Keyed by job id.
|
||||
*
|
||||
* @throws ExportNotDraft
|
||||
* @throws ExportEmpty
|
||||
*/
|
||||
public function finalize(array $linesByJob, int $finalizedBy, DateTimeImmutable $now): void
|
||||
public function finalize(array $linesByJob, int $number, int $finalizedBy, DateTimeImmutable $now): void
|
||||
{
|
||||
$this->ensureDraft();
|
||||
|
||||
@@ -193,6 +194,7 @@ final class BillingExport
|
||||
$invoice->setLines($lines);
|
||||
}
|
||||
|
||||
$this->number = $number;
|
||||
$this->status = ExportStatus::Created;
|
||||
$this->finalizedBy = $finalizedBy;
|
||||
$this->finalizedAt = $now;
|
||||
@@ -240,6 +242,14 @@ final class BillingExport
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The running number, reserved when the material is created; a draft has none.
|
||||
*/
|
||||
public function number(): ?int
|
||||
{
|
||||
return $this->number;
|
||||
}
|
||||
|
||||
public function status(): ExportStatus
|
||||
{
|
||||
return $this->status;
|
||||
|
||||
@@ -13,6 +13,7 @@ use Illuminate\Support\Carbon;
|
||||
* Persistence model, used only inside the Billing Infrastructure layer.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int|null $number
|
||||
* @property ExportStatus $status
|
||||
* @property string|null $period Y-m
|
||||
* @property int $created_by
|
||||
@@ -21,7 +22,7 @@ use Illuminate\Support\Carbon;
|
||||
* @property Carbon $created_at
|
||||
*/
|
||||
#[Table('billing_exports')]
|
||||
#[Fillable(['status', 'period', 'created_by', 'finalized_by', 'finalized_at'])]
|
||||
#[Fillable(['number', 'status', 'period', 'created_by', 'finalized_by', 'finalized_at'])]
|
||||
class BillingExportModel extends Model
|
||||
{
|
||||
/**
|
||||
@@ -39,6 +40,7 @@ class BillingExportModel extends Model
|
||||
{
|
||||
return [
|
||||
'status' => ExportStatus::class,
|
||||
'number' => 'integer',
|
||||
'created_by' => 'integer',
|
||||
'finalized_by' => 'integer',
|
||||
'finalized_at' => 'datetime',
|
||||
|
||||
+7
@@ -45,6 +45,7 @@ class EloquentBillingExportRepository implements BillingExportRepository
|
||||
$model = $export->id() === null ? new BillingExportModel : BillingExportModel::query()->findOrFail($export->id());
|
||||
|
||||
$model->fill([
|
||||
'number' => $export->number(),
|
||||
'status' => $export->status(),
|
||||
'period' => $export->period(),
|
||||
'created_by' => $export->createdBy(),
|
||||
@@ -116,6 +117,11 @@ class EloquentBillingExportRepository implements BillingExportRepository
|
||||
BillingExportModel::query()->whereKey($export->id())->delete();
|
||||
}
|
||||
|
||||
public function nextNumber(): int
|
||||
{
|
||||
return (int) BillingExportModel::query()->max('number') + 1;
|
||||
}
|
||||
|
||||
public function fixedPriceBilledJobIds(array $jobIds): array
|
||||
{
|
||||
if ($jobIds === []) {
|
||||
@@ -175,6 +181,7 @@ class EloquentBillingExportRepository implements BillingExportRepository
|
||||
|
||||
return BillingExport::reconstitute(
|
||||
$model->id,
|
||||
$model->number,
|
||||
$model->status,
|
||||
$model->period ?? $model->created_at->format('Y-m'),
|
||||
$model->created_by,
|
||||
|
||||
@@ -43,6 +43,7 @@ class EloquentBillingQueries implements BillingQueries
|
||||
|
||||
return $models->map(fn (BillingExportModel $model): ExportSummary => new ExportSummary(
|
||||
$model->id,
|
||||
$model->number,
|
||||
$model->status,
|
||||
DateTimeImmutable::createFromInterface($model->created_at),
|
||||
$names[$model->created_by] ?? '',
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Modules\Billing\Presentation\Http\Controllers;
|
||||
|
||||
use App\Modules\Billing\Application\DTOs\ExportRow;
|
||||
use App\Modules\Billing\Application\Services\ExportRows;
|
||||
use App\Modules\Billing\Application\Services\ExportViews;
|
||||
use App\Modules\Billing\Domain\Enums\LineKind;
|
||||
use App\Modules\Billing\Domain\Exceptions\BillingExportNotFound;
|
||||
use App\Modules\Billing\Domain\Exceptions\ExportNotCreated;
|
||||
@@ -19,7 +20,7 @@ use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
*/
|
||||
class DownloadBillingCsv
|
||||
{
|
||||
public function __invoke(int $export, ExportRows $exportRows): StreamedResponse
|
||||
public function __invoke(int $export, ExportRows $exportRows, ExportViews $exportViews): StreamedResponse
|
||||
{
|
||||
Gate::authorize('billing.manage');
|
||||
|
||||
@@ -29,6 +30,8 @@ class DownloadBillingCsv
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$number = $exportViews->of($export)->number ?? abort(404);
|
||||
|
||||
return response()->streamDownload(function () use ($rows): void {
|
||||
$out = fopen('php://output', 'w');
|
||||
|
||||
@@ -44,7 +47,7 @@ class DownloadBillingCsv
|
||||
}
|
||||
|
||||
fclose($out);
|
||||
}, __('billing.csv.file', ['number' => $export]), [
|
||||
}, __('billing.csv.file', ['number' => $number]), [
|
||||
'Content-Type' => 'text/csv; charset=UTF-8',
|
||||
'Cache-Control' => 'no-store, private',
|
||||
]);
|
||||
|
||||
@@ -210,9 +210,19 @@ new class extends Component
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* A draft has no number yet: it is reserved when the material is created.
|
||||
*/
|
||||
public function heading(): string
|
||||
{
|
||||
$number = $this->export->number;
|
||||
|
||||
return $number === null ? __('billing.export.draft_title') : __('billing.export.title', ['number' => $number]);
|
||||
}
|
||||
|
||||
public function render(): mixed
|
||||
{
|
||||
return $this->view()->title(__('billing.export.title', ['number' => $this->exportId]));
|
||||
return $this->view()->title($this->heading());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -308,7 +318,7 @@ new class extends Component
|
||||
|
||||
<div class="space-y-2">
|
||||
<p><x-link :href="route('billing.index')" navigate>{{ __('billing.export.back') }}</x-link></p>
|
||||
<h1 class="text-2xl font-semibold">{{ __('billing.export.title', ['number' => $export->id]) }}</h1>
|
||||
<h1 class="text-2xl font-semibold">{{ $this->heading() }}</h1>
|
||||
<p class="flex items-center gap-2 text-sm">
|
||||
@if ($export->isDraft())
|
||||
<x-icon name="pencil-square" class="size-5 shrink-0" aria-hidden="true" />
|
||||
|
||||
@@ -106,7 +106,7 @@ new class extends Component
|
||||
@else
|
||||
<x-table :headers="$this->headers()" :rows="$this->exports">
|
||||
@interact('column_number', $export)
|
||||
<x-link :href="route('billing.export', $export->id)" navigate>{{ __('billing.index.export_label', ['number' => $export->id]) }}</x-link>
|
||||
<x-link :href="route('billing.export', $export->id)" navigate>{{ $export->number === null ? __('billing.index.draft_label') : __('billing.index.export_label', ['number' => $export->number]) }}</x-link>
|
||||
@endinteract
|
||||
|
||||
@interact('column_status', $export)
|
||||
@@ -142,7 +142,7 @@ new class extends Component
|
||||
|
||||
@interact('column_file', $export)
|
||||
@if ($export->status->value === 'created')
|
||||
<x-link :href="route('billing.csv', $export->id)" icon="arrow-down-tray" :aria-label="__('billing.csv.download_named', ['number' => $export->id])">{{ __('billing.csv.download_short') }}</x-link>
|
||||
<x-link :href="route('billing.csv', $export->id)" icon="arrow-down-tray" :aria-label="__('billing.csv.download_named', ['number' => $export->number])">{{ __('billing.csv.download_short') }}</x-link>
|
||||
@endif
|
||||
@endinteract
|
||||
</x-table>
|
||||
|
||||
@@ -16,6 +16,7 @@ final readonly class CompanyDetails
|
||||
public ?string $address = null,
|
||||
public ?string $phone = null,
|
||||
public ?string $email = null,
|
||||
public ?string $menuName = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@ final class CompanyDetailsStore
|
||||
'address' => 'shared.company_address',
|
||||
'phone' => 'shared.company_phone',
|
||||
'email' => 'shared.company_email',
|
||||
'menu_name' => 'shared.company_menu_name',
|
||||
];
|
||||
|
||||
public function __construct(private Settings $settings) {}
|
||||
@@ -47,6 +48,7 @@ final class CompanyDetailsStore
|
||||
$this->settings->get(self::KEYS['address']),
|
||||
$this->settings->get(self::KEYS['phone']),
|
||||
$this->settings->get(self::KEYS['email']),
|
||||
$this->settings->get(self::KEYS['menu_name']),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -72,6 +74,15 @@ final class CompanyDetailsStore
|
||||
$this->settings->put(self::KEYS['address'], self::text($details->address));
|
||||
$this->settings->put(self::KEYS['phone'], self::text($details->phone));
|
||||
$this->settings->put(self::KEYS['email'], $email);
|
||||
$this->settings->put(self::KEYS['menu_name'], self::text($details->menuName));
|
||||
}
|
||||
|
||||
/**
|
||||
* The name shown at the left of the main menu: the saved one, or the application name.
|
||||
*/
|
||||
public function menuName(): string
|
||||
{
|
||||
return $this->settings->get(self::KEYS['menu_name']) ?? (string) config('app.name');
|
||||
}
|
||||
|
||||
private static function text(?string $value): ?string
|
||||
|
||||
@@ -16,6 +16,8 @@ new class extends Component
|
||||
{
|
||||
public string $name = '';
|
||||
|
||||
public string $menu_name = '';
|
||||
|
||||
public string $business_id = '';
|
||||
|
||||
public string $address = '';
|
||||
@@ -35,6 +37,7 @@ new class extends Component
|
||||
|
||||
if ($details !== null) {
|
||||
$this->name = $details->name;
|
||||
$this->menu_name = $details->menuName ?? '';
|
||||
$this->business_id = $details->businessId;
|
||||
$this->address = $details->address ?? '';
|
||||
$this->phone = $details->phone ?? '';
|
||||
@@ -49,6 +52,7 @@ new class extends Component
|
||||
|
||||
$this->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'menu_name' => ['nullable', 'string', 'max:100'],
|
||||
'business_id' => ['required', 'string', 'max:20'],
|
||||
'address' => ['nullable', 'string', 'max:500'],
|
||||
'phone' => ['nullable', 'string', 'max:50'],
|
||||
@@ -56,6 +60,7 @@ new class extends Component
|
||||
], [
|
||||
'name.required' => __('company.errors.name'),
|
||||
'name.max' => __('company.errors.name'),
|
||||
'menu_name.max' => __('company.errors.menu_name'),
|
||||
'business_id.required' => __('company.errors.business_id'),
|
||||
'business_id.max' => __('company.errors.business_id'),
|
||||
'address.max' => __('company.errors.address'),
|
||||
@@ -64,7 +69,7 @@ new class extends Component
|
||||
]);
|
||||
|
||||
try {
|
||||
$store->save(new CompanyDetails($this->name, $this->business_id, $this->address, $this->phone, $this->email));
|
||||
$store->save(new CompanyDetails($this->name, $this->business_id, $this->address, $this->phone, $this->email, $this->menu_name));
|
||||
} catch (CompanyNameRequired) {
|
||||
$this->addError('name', __('company.errors.name'));
|
||||
|
||||
@@ -100,6 +105,7 @@ new class extends Component
|
||||
|
||||
<form wire:submit="save" class="space-y-6" novalidate>
|
||||
<x-input wire:model="name" :label="__('company.fields.name')" autocomplete="organization" required />
|
||||
<x-input wire:model="menu_name" :label="__('company.fields.menu_name')" :hint="__('company.fields.menu_name_hint')" autocomplete="off" />
|
||||
<x-input wire:model="business_id" :label="__('company.fields.business_id')" :hint="__('company.fields.business_id_hint')" autocomplete="off" required />
|
||||
<x-textarea wire:model="address" :label="__('company.fields.address')" :hint="__('company.fields.address_hint')" rows="3" autocomplete="street-address" />
|
||||
<x-input wire:model="phone" type="tel" :label="__('company.fields.phone')" autocomplete="tel" />
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
/**
|
||||
* The number of a billing material is reserved when it is created, not when
|
||||
* the draft is started, so discarded drafts leave no gaps. Created
|
||||
* materials get 1, 2, ... in the order they were started; drafts have none.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('billing_exports', function (Blueprint $table) {
|
||||
$table->unsignedInteger('number')->nullable()->unique()->after('id');
|
||||
});
|
||||
|
||||
$number = 0;
|
||||
|
||||
foreach (DB::table('billing_exports')->where('status', '!=', 'draft')->orderBy('id')->pluck('id') as $id) {
|
||||
DB::table('billing_exports')->where('id', $id)->update(['number' => ++$number]);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('billing_exports', function (Blueprint $table) {
|
||||
$table->dropUnique(['number']);
|
||||
$table->dropColumn('number');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -77,10 +77,12 @@ return [
|
||||
'file' => 'Tiedosto',
|
||||
],
|
||||
'export_label' => 'Aineisto :number',
|
||||
'draft_label' => 'Luonnos',
|
||||
],
|
||||
|
||||
'export' => [
|
||||
'title' => 'Laskuaineisto :number',
|
||||
'draft_title' => 'Laskuaineiston luonnos',
|
||||
'back' => 'Kaikki laskuaineistot',
|
||||
'draft_info' => 'Luonnos, aloittanut :name :at. Muutokset tallentuvat heti.',
|
||||
'created_info' => 'Muodostettu :at, muodostaja :name.',
|
||||
|
||||
+4
-1
@@ -2,9 +2,11 @@
|
||||
|
||||
return [
|
||||
'title' => 'Yritystiedot',
|
||||
'intro' => 'Yrityksen tiedot tulostuvat kuitteihin. Arvonlisäverotunnus muodostetaan Y-tunnuksesta.',
|
||||
'intro' => 'Yrityksen tiedot tulostuvat kuitteihin, ja valikon nimi näkyy päävalikon vasemmassa reunassa. Arvonlisäverotunnus muodostetaan Y-tunnuksesta.',
|
||||
'fields' => [
|
||||
'name' => 'Yrityksen nimi',
|
||||
'menu_name' => 'Valikon nimi',
|
||||
'menu_name_hint' => 'Näkyy päävalikon vasemmassa reunassa. Jos kenttä on tyhjä, käytetään nimeä Toiminnanohjaus.',
|
||||
'business_id' => 'Y-tunnus',
|
||||
'business_id_hint' => 'Esimerkiksi 1234567-8.',
|
||||
'address' => 'Osoite',
|
||||
@@ -17,6 +19,7 @@ return [
|
||||
'errors' => [
|
||||
'name' => 'Anna yrityksen nimi (enintään 255 merkkiä).',
|
||||
'business_id' => 'Anna kelvollinen Y-tunnus, esim. 1234567-8.',
|
||||
'menu_name' => 'Valikon nimi saa olla enintään 100 merkkiä.',
|
||||
'address' => 'Osoite saa olla enintään 500 merkkiä.',
|
||||
'phone' => 'Puhelinnumero saa olla enintään 50 merkkiä.',
|
||||
'email' => 'Anna kelvollinen sähköpostiosoite.',
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<header class="border-b border-zinc-200 dark:border-zinc-700">
|
||||
<div class="mx-auto flex max-w-5xl flex-wrap items-center gap-x-6 gap-y-2 px-4 py-3 sm:px-6">
|
||||
<a href="{{ route('home') }}" wire:navigate class="rounded font-semibold text-zinc-700 hover:text-zinc-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:text-zinc-200 dark:hover:text-white">
|
||||
{{ config('app.name') }}
|
||||
{{ app(\App\Modules\Shared\Application\UseCases\CompanyDetailsStore::class)->menuName() }}
|
||||
</a>
|
||||
|
||||
<nav aria-label="{{ __('layout.main_menu') }}" class="flex flex-1 flex-wrap items-center gap-1">
|
||||
|
||||
@@ -93,7 +93,7 @@ it('downloads a created billing material as a CSV file for Excel', function () {
|
||||
$response = $this->get(route('billing.csv', $exportId))
|
||||
->assertOk()
|
||||
->assertHeader('Content-Type', 'text/csv; charset=UTF-8')
|
||||
->assertDownload("laskuaineisto-{$exportId}.csv");
|
||||
->assertDownload('laskuaineisto-1.csv');
|
||||
|
||||
expect($response->headers->get('Cache-Control'))->toContain('no-store');
|
||||
|
||||
|
||||
@@ -295,3 +295,31 @@ it('does not bill a monthly fee job without a monthly fee', function () {
|
||||
->call('add', $job->id)
|
||||
->assertSet('errorMessage', fn (string $message) => str_contains($message, 'kuukausihinta'));
|
||||
});
|
||||
|
||||
it('numbers created materials without gaps: a draft has no number and a discarded one uses none', function () {
|
||||
$first = doneJob(['name' => 'Esite'], [$this->layout->id => 1]);
|
||||
$second = doneJob(['name' => 'Juliste'], [$this->layout->id => 1]);
|
||||
|
||||
$discarded = openDraft();
|
||||
Livewire::test('billing::export', ['export' => $discarded])
|
||||
->assertSee('Laskuaineiston luonnos')
|
||||
->call('add', $first->id)
|
||||
->call('discard');
|
||||
|
||||
$exportId = openDraft();
|
||||
expect(BillingExportModel::query()->findOrFail($exportId)->number)->toBeNull();
|
||||
|
||||
Livewire::test('billing::export', ['export' => $exportId])
|
||||
->call('add', $first->id)
|
||||
->call('finalize')
|
||||
->assertSee('Laskuaineisto 1');
|
||||
|
||||
$next = openDraft();
|
||||
Livewire::test('billing::export', ['export' => $next])
|
||||
->call('add', $second->id)
|
||||
->call('finalize')
|
||||
->assertSee('Laskuaineisto 2');
|
||||
|
||||
expect(BillingExportModel::query()->orderBy('id')->pluck('number')->all())->toBe([1, 2])
|
||||
->and($next)->toBeGreaterThan($exportId);
|
||||
});
|
||||
|
||||
@@ -12,7 +12,13 @@ it('makes the earlier assignee with most booked time the assignee and the others
|
||||
$booked = TaskModel::factory()->create();
|
||||
$unbooked = TaskModel::factory()->create();
|
||||
|
||||
$this->artisan('migrate:rollback', ['--step' => 1])->assertSuccessful();
|
||||
// Roll back this migration and every one after it, so later migrations don't matter.
|
||||
$steps = count(array_filter(
|
||||
array_map('basename', glob(database_path('migrations/*.php'))),
|
||||
fn (string $file): bool => $file >= '2026_11_24_163029_split_task_assignee_and_members.php',
|
||||
));
|
||||
|
||||
$this->artisan('migrate:rollback', ['--step' => $steps])->assertSuccessful();
|
||||
|
||||
DB::table('task_assignees')->insert([
|
||||
['task_id' => $booked->id, 'user_id' => $eero->id],
|
||||
|
||||
@@ -51,3 +51,38 @@ it('keeps everyone but the admin out', function () {
|
||||
|
||||
$this->get(route('settings.company'))->assertForbidden();
|
||||
});
|
||||
|
||||
it('saves the menu name and shows it at the left of the main menu', function () {
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
|
||||
Livewire::test('shared::company')
|
||||
->set('name', 'Mediatalo Oy')
|
||||
->set('menu_name', ' Mediatalo Työt ')
|
||||
->set('business_id', '0737546-2')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect(app(CompanyDetailsStore::class)->menuName())->toBe('Mediatalo Työt');
|
||||
|
||||
Livewire::test('shared::company')->assertSet('menu_name', 'Mediatalo Työt');
|
||||
|
||||
$this->get(route('customers.index'))->assertSee('Mediatalo Työt');
|
||||
});
|
||||
|
||||
it('falls back to the application name when the menu name is empty, even before other details are saved', function () {
|
||||
$store = app(CompanyDetailsStore::class);
|
||||
|
||||
expect($store->get())->toBeNull()
|
||||
->and($store->menuName())->toBe(config('app.name'));
|
||||
});
|
||||
|
||||
it('rejects a menu name over 100 characters', function () {
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
|
||||
Livewire::test('shared::company')
|
||||
->set('name', 'Mediatalo Oy')
|
||||
->set('business_id', '0737546-2')
|
||||
->set('menu_name', str_repeat('a', 101))
|
||||
->call('save')
|
||||
->assertHasErrors(['menu_name' => [__('company.errors.menu_name')]]);
|
||||
});
|
||||
|
||||
@@ -118,16 +118,19 @@ it('rejects billable hours that are not quarters of an hour', function (string $
|
||||
it('locks the material once it is created', function () {
|
||||
$export = draft();
|
||||
$export->addJob(new DraftJob(1, 10, null, null));
|
||||
$export->finalize([1 => [InvoiceLine::fixedPrice(1, 'Työ', 1000, 2550)]], 2, new DateTimeImmutable('2026-11-24 12:00'));
|
||||
expect($export->number())->toBeNull();
|
||||
|
||||
$export->finalize([1 => [InvoiceLine::fixedPrice(1, 'Työ', 1000, 2550)]], 7, 2, new DateTimeImmutable('2026-11-24 12:00'));
|
||||
|
||||
expect($export->status())->toBe(ExportStatus::Created)
|
||||
->and($export->number())->toBe(7)
|
||||
->and($export->invoices()[0]->totals()->netCents)->toBe(1000);
|
||||
|
||||
$export->addJob(new DraftJob(2, 10, null, null));
|
||||
})->throws(ExportNotDraft::class);
|
||||
|
||||
it('does not create an empty material', function () {
|
||||
draft()->finalize([], 1, new DateTimeImmutable);
|
||||
draft()->finalize([], 1, 1, new DateTimeImmutable);
|
||||
})->throws(ExportEmpty::class);
|
||||
|
||||
it('prices hours by the quarter and rounds half up', function () {
|
||||
|
||||
Reference in New Issue
Block a user