Add quick sales with cash days, credits and PDF receipts

Quick sales (pikamyynti) of active consumer products at the counter, in a
new Sales module:

- Product buttons add one to the sale's list per press; quantities can be
  lowered, raised or removed. Payment by cash or card, optional customer.
- Product durations are booked as the seller's hours on the yearly
  "Pikamyynnit" job (internal customer, not billed) through Jobs'
  ProvideQuickSaleTask and TimeTracking's AddTaskHours. The sale stands
  even when the hours cannot be booked, and the seller is told.
- Sales are never deleted: a credit records the lines negated on today's
  cash day, once per sale, by the seller or management.
- Closing a cash day stores its balance by payment method and VAT rate and
  stops sales on it; only management reopens a day.
- A printable A5 PDF receipt (barryvdh/laravel-dompdf) with the company's
  details, business ID, VAT number, lines and VAT breakdown.

Company details are kept in the settings and edited by the admin only on
the new Yritystiedot page. BusinessId moves from Customers to Shared so
both use the same check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 12:33:46 +02:00
co-authored by Claude Opus 5.5
parent c149c56388
commit 6de5d9bef1
101 changed files with 4768 additions and 29 deletions
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace App\Modules\Sales\Application\DTOs;
use App\Modules\Sales\Domain\ValueObjects\CashDayBalance;
/**
* A cash day's state. The balance is the stored one of a closed day and
* the balance that closing would form on an open day. Times are
* "Y-m-d H:i" in the company's time zone.
*/
final readonly class CashDaySummary
{
public function __construct(
public string $day,
public bool $isClosed,
public CashDayBalance $balance,
public ?string $closedByName = null,
public ?string $closedAt = null,
public ?string $reopenedByName = null,
public ?string $reopenedAt = null,
) {}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace App\Modules\Sales\Application\DTOs;
final readonly class QuickSaleLineSummary
{
public function __construct(
public string $productName,
public int $quantity,
public int $unitPriceCents,
public int $totalCents,
public int $vatBasisPoints = 0,
) {}
}
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace App\Modules\Sales\Application\DTOs;
use App\Modules\Sales\Domain\Enums\PaymentMethod;
use App\Modules\Sales\Domain\ValueObjects\VatTotal;
/**
* A quick sale as listed: amounts with VAT, negative on a credit.
* $soldAt is "Y-m-d H:i" in the company's time zone. $creditsSaleId is set
* on a credit, $creditedBySaleId on a sale that has been credited.
*/
final readonly class QuickSaleSummary
{
/**
* @param list<QuickSaleLineSummary> $lines
*/
public function __construct(
public int $id,
public string $soldAt,
public int $sellerId,
public string $sellerName,
public ?string $customerName,
public PaymentMethod $paymentMethod,
public int $totalCents,
public array $lines,
public ?int $creditsSaleId,
public ?int $creditedBySaleId,
) {}
public function isCredit(): bool
{
return $this->creditsSaleId !== null;
}
public function canBeCredited(): bool
{
return $this->creditsSaleId === null && $this->creditedBySaleId === null;
}
/**
* The sale's VAT by rate, highest rate first, as on its receipt.
*
* @return list<VatTotal>
*/
public function vatTotals(): array
{
$grossByRate = [];
foreach ($this->lines as $line) {
$grossByRate[$line->vatBasisPoints] = ($grossByRate[$line->vatBasisPoints] ?? 0) + $line->totalCents;
}
krsort($grossByRate);
return array_map(
fn (int $basisPoints, int $gross): VatTotal => VatTotal::ofGross($basisPoints, $gross),
array_keys($grossByRate),
array_values($grossByRate),
);
}
}
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace App\Modules\Sales\Application\DTOs;
/**
* Input for a quick sale: quantities by product id (zero or empty ones are
* left out by the caller), the payment method key and an optional customer.
*/
final readonly class SaleData
{
/**
* @param array<int, int> $quantities
*/
public function __construct(
public array $quantities,
public string $paymentMethod,
public ?int $customerId = null,
) {}
}
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace App\Modules\Sales\Application\DTOs;
/**
* A recorded quick sale: its id and total with VAT, and the hours booked
* on the seller or left unbooked (in quarters of an hour).
*/
final readonly class SaleResult
{
public function __construct(
public int $saleId,
public int $totalCents,
public int $bookedQuarters,
public int $unbookedQuarters,
) {}
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace App\Modules\Sales\Application\DTOs;
/**
* A consumer product as it is sold: its price with VAT and the hours its
* sale books on the seller ($durationQuarters on $workTypeId). $unit is
* the price list unit key, e.g. "piece".
*/
final readonly class SellableProduct
{
public function __construct(
public int $id,
public string $name,
public string $unit,
public int $grossCents,
public int $vatBasisPoints,
public int $durationQuarters,
public ?int $workTypeId,
) {}
}