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]>
119 lines
2.8 KiB
PHP
119 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Sales\Domain\Entities;
|
|
|
|
use App\Modules\Sales\Domain\Exceptions\CashDayClosed;
|
|
use App\Modules\Sales\Domain\Exceptions\CashDayNotClosed;
|
|
use App\Modules\Sales\Domain\ValueObjects\CashDayBalance;
|
|
use DateTimeImmutable;
|
|
|
|
/**
|
|
* A day of quick sales at the counter (kassapäivä). Closing it forms the
|
|
* day's balance and stops further sales on it; management may reopen it,
|
|
* which empties the balance until it is closed again.
|
|
*/
|
|
final class CashDay
|
|
{
|
|
private function __construct(
|
|
private ?int $id,
|
|
private DateTimeImmutable $day,
|
|
private ?CashDayBalance $balance,
|
|
private ?int $closedBy,
|
|
private ?DateTimeImmutable $closedAt,
|
|
private ?int $reopenedBy,
|
|
private ?DateTimeImmutable $reopenedAt,
|
|
) {}
|
|
|
|
public static function open(DateTimeImmutable $day): self
|
|
{
|
|
return new self(null, $day, null, null, null, null, null);
|
|
}
|
|
|
|
public static function reconstitute(int $id, DateTimeImmutable $day, ?CashDayBalance $balance, ?int $closedBy, ?DateTimeImmutable $closedAt, ?int $reopenedBy, ?DateTimeImmutable $reopenedAt): self
|
|
{
|
|
return new self($id, $day, $balance, $closedBy, $closedAt, $reopenedBy, $reopenedAt);
|
|
}
|
|
|
|
/**
|
|
* @param list<QuickSale> $sales The day's sales, credits included.
|
|
*
|
|
* @throws CashDayClosed
|
|
*/
|
|
public function close(array $sales, int $closedBy, DateTimeImmutable $now): void
|
|
{
|
|
$this->ensureOpen();
|
|
|
|
$this->balance = CashDayBalance::of($sales);
|
|
$this->closedBy = $closedBy;
|
|
$this->closedAt = $now;
|
|
}
|
|
|
|
/**
|
|
* @throws CashDayNotClosed
|
|
*/
|
|
public function reopen(int $reopenedBy, DateTimeImmutable $now): void
|
|
{
|
|
if (! $this->isClosed()) {
|
|
throw new CashDayNotClosed;
|
|
}
|
|
|
|
$this->balance = null;
|
|
$this->closedBy = null;
|
|
$this->closedAt = null;
|
|
$this->reopenedBy = $reopenedBy;
|
|
$this->reopenedAt = $now;
|
|
}
|
|
|
|
/**
|
|
* @throws CashDayClosed
|
|
*/
|
|
public function ensureOpen(): void
|
|
{
|
|
if ($this->isClosed()) {
|
|
throw new CashDayClosed;
|
|
}
|
|
}
|
|
|
|
public function isClosed(): bool
|
|
{
|
|
return $this->closedAt !== null;
|
|
}
|
|
|
|
public function id(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function day(): DateTimeImmutable
|
|
{
|
|
return $this->day;
|
|
}
|
|
|
|
public function balance(): ?CashDayBalance
|
|
{
|
|
return $this->balance;
|
|
}
|
|
|
|
public function closedBy(): ?int
|
|
{
|
|
return $this->closedBy;
|
|
}
|
|
|
|
public function closedAt(): ?DateTimeImmutable
|
|
{
|
|
return $this->closedAt;
|
|
}
|
|
|
|
public function reopenedBy(): ?int
|
|
{
|
|
return $this->reopenedBy;
|
|
}
|
|
|
|
public function reopenedAt(): ?DateTimeImmutable
|
|
{
|
|
return $this->reopenedAt;
|
|
}
|
|
}
|