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:
@@ -35,6 +35,11 @@ class FakeCustomerQueries implements CustomerQueries
|
||||
return array_intersect_key($this->customers, array_flip($ids));
|
||||
}
|
||||
|
||||
public function internalCustomerId(): ?int
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function personalIdentityCodeOf(int $customerId): ?string
|
||||
{
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Sales\Application\Contracts\QuickSaleHours;
|
||||
use DateTimeImmutable;
|
||||
|
||||
class FakeQuickSaleHours implements QuickSaleHours
|
||||
{
|
||||
/** @var list<array{int, string, int, int, int}> seller, day, work type, quarters, sale */
|
||||
public array $booked = [];
|
||||
|
||||
public bool $fails = false;
|
||||
|
||||
public function book(int $sellerId, DateTimeImmutable $day, int $workTypeId, int $quarters, int $saleId): bool
|
||||
{
|
||||
if ($this->fails) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->booked[] = [$sellerId, $day->format('Y-m-d'), $workTypeId, $quarters, $saleId];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Sales\Application\Contracts\QuickSaleProducts;
|
||||
use App\Modules\Sales\Application\DTOs\SellableProduct;
|
||||
|
||||
class FakeQuickSaleProducts implements QuickSaleProducts
|
||||
{
|
||||
/** @var list<SellableProduct> */
|
||||
public array $products = [];
|
||||
|
||||
public function add(int $id, string $name, int $grossCents, int $vatBasisPoints = 2550, int $durationQuarters = 0, ?int $workTypeId = null): void
|
||||
{
|
||||
$this->products[] = new SellableProduct($id, $name, 'piece', $grossCents, $vatBasisPoints, $durationQuarters, $workTypeId);
|
||||
}
|
||||
|
||||
public function sellable(): array
|
||||
{
|
||||
return $this->products;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Sales\Domain\Contracts\CashDayRepository;
|
||||
use App\Modules\Sales\Domain\Entities\CashDay;
|
||||
use DateTimeImmutable;
|
||||
|
||||
class InMemoryCashDayRepository implements CashDayRepository
|
||||
{
|
||||
/** @var array<string, CashDay> */
|
||||
public array $days = [];
|
||||
|
||||
public function forDay(DateTimeImmutable $day): CashDay
|
||||
{
|
||||
return isset($this->days[$day->format('Y-m-d')]) ? clone $this->days[$day->format('Y-m-d')] : CashDay::open($day);
|
||||
}
|
||||
|
||||
public function save(CashDay $cashDay): CashDay
|
||||
{
|
||||
$this->days[$cashDay->day()->format('Y-m-d')] = clone $cashDay;
|
||||
|
||||
return $cashDay;
|
||||
}
|
||||
|
||||
public function lockForDay(DateTimeImmutable $day): CashDay
|
||||
{
|
||||
return $this->forDay($day);
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,19 @@ class InMemoryCustomerJobRepository implements CustomerJobRepository, JobNumberS
|
||||
return clone $this->jobs[$id];
|
||||
}
|
||||
|
||||
/** @var array<int, int> year => job id */
|
||||
public array $quickSaleJobs = [];
|
||||
|
||||
public function findQuickSaleJob(int $year): ?CustomerJob
|
||||
{
|
||||
return isset($this->quickSaleJobs[$year]) ? $this->findById($this->quickSaleJobs[$year]) : null;
|
||||
}
|
||||
|
||||
public function markAsQuickSaleJob(int $jobId, int $year): void
|
||||
{
|
||||
$this->quickSaleJobs[$year] = $jobId;
|
||||
}
|
||||
|
||||
public function recordChanges(int $jobId, int $userId, array $changes): void
|
||||
{
|
||||
foreach ($changes as $change) {
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Customers\Domain\Contracts\CustomerRepository;
|
||||
use App\Modules\Customers\Domain\Entities\Customer;
|
||||
use App\Modules\Customers\Domain\ValueObjects\BusinessId;
|
||||
use App\Modules\Customers\Domain\ValueObjects\PersonalIdentityCode;
|
||||
use App\Modules\Shared\Domain\ValueObjects\BusinessId;
|
||||
|
||||
class InMemoryCustomerRepository implements CustomerRepository
|
||||
{
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Sales\Domain\Contracts\QuickSaleRepository;
|
||||
use App\Modules\Sales\Domain\Entities\QuickSale;
|
||||
use DateTimeImmutable;
|
||||
|
||||
class InMemoryQuickSaleRepository implements QuickSaleRepository
|
||||
{
|
||||
/** @var array<int, QuickSale> */
|
||||
public array $sales = [];
|
||||
|
||||
private int $nextId = 1;
|
||||
|
||||
public function findById(int $id): ?QuickSale
|
||||
{
|
||||
return $this->sales[$id] ?? null;
|
||||
}
|
||||
|
||||
public function add(QuickSale $sale): QuickSale
|
||||
{
|
||||
$id = $this->nextId++;
|
||||
|
||||
return $this->sales[$id] = QuickSale::reconstitute(
|
||||
$id,
|
||||
$sale->sellerId(),
|
||||
$sale->customerId(),
|
||||
$sale->paymentMethod(),
|
||||
$sale->soldAt(),
|
||||
$sale->soldOn(),
|
||||
$sale->lines(),
|
||||
$sale->creditsSaleId(),
|
||||
);
|
||||
}
|
||||
|
||||
public function isCredited(int $saleId): bool
|
||||
{
|
||||
foreach ($this->sales as $sale) {
|
||||
if ($sale->creditsSaleId() === $saleId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function forDay(DateTimeImmutable $day): array
|
||||
{
|
||||
return array_values(array_filter($this->sales, fn (QuickSale $sale): bool => $sale->soldOn()->format('Y-m-d') === $day->format('Y-m-d')));
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,17 @@ class InMemoryTaskRepository implements TaskRepository
|
||||
return $task !== null && $task->jobId() === $jobId ? clone $task : null;
|
||||
}
|
||||
|
||||
public function findByWorkType(int $jobId, int $workTypeId): ?Task
|
||||
{
|
||||
foreach ($this->tasks as $task) {
|
||||
if ($task->jobId() === $jobId && $task->workTypeId() === $workTypeId) {
|
||||
return clone $task;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function save(Task $task): Task
|
||||
{
|
||||
$id = $task->id() ?? $this->nextId++;
|
||||
|
||||
Reference in New Issue
Block a user