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:
@@ -25,6 +25,12 @@ interface CustomerQueries
|
||||
*/
|
||||
public function namesByIds(array $ids): array;
|
||||
|
||||
/**
|
||||
* The company's own internal customer, whose jobs hold internal work
|
||||
* and the yearly quick sale job.
|
||||
*/
|
||||
public function internalCustomerId(): ?int;
|
||||
|
||||
/**
|
||||
* The full personal identity code. Sensitive: call only after checking
|
||||
* the customers.view-personal-identity-code ability, and never log it.
|
||||
|
||||
@@ -10,11 +10,11 @@ use App\Modules\Customers\Domain\Entities\Customer;
|
||||
use App\Modules\Customers\Domain\Events\CustomerRegistered;
|
||||
use App\Modules\Customers\Domain\Exceptions\BusinessIdAlreadyInUse;
|
||||
use App\Modules\Customers\Domain\Exceptions\PersonalIdentityCodeAlreadyInUse;
|
||||
use App\Modules\Customers\Domain\ValueObjects\BusinessId;
|
||||
use App\Modules\Customers\Domain\ValueObjects\CustomerName;
|
||||
use App\Modules\Customers\Domain\ValueObjects\PersonalIdentityCode;
|
||||
use App\Modules\Shared\Application\Contracts\EventDispatcher;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
use App\Modules\Shared\Domain\ValueObjects\BusinessId;
|
||||
|
||||
final class RegisterCustomer
|
||||
{
|
||||
|
||||
@@ -9,10 +9,10 @@ use App\Modules\Customers\Domain\Contracts\CustomerRepository;
|
||||
use App\Modules\Customers\Domain\Exceptions\BusinessIdAlreadyInUse;
|
||||
use App\Modules\Customers\Domain\Exceptions\CustomerNotFound;
|
||||
use App\Modules\Customers\Domain\Exceptions\PersonalIdentityCodeAlreadyInUse;
|
||||
use App\Modules\Customers\Domain\ValueObjects\BusinessId;
|
||||
use App\Modules\Customers\Domain\ValueObjects\CustomerName;
|
||||
use App\Modules\Customers\Domain\ValueObjects\PersonalIdentityCode;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
use App\Modules\Shared\Domain\ValueObjects\BusinessId;
|
||||
|
||||
/**
|
||||
* Changes a customer's details. Who may remove a personal identity code is
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Modules\Customers\Domain\Contracts;
|
||||
|
||||
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;
|
||||
|
||||
interface CustomerRepository
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ use App\Modules\Customers\Domain\Enums\CustomerType;
|
||||
use App\Modules\Customers\Domain\Exceptions\CompanyCannotHavePersonalIdentityCode;
|
||||
use App\Modules\Customers\Domain\Exceptions\ConsumerCannotHaveBusinessId;
|
||||
use App\Modules\Customers\Domain\Exceptions\InternalCustomerMustBeCompany;
|
||||
use App\Modules\Customers\Domain\ValueObjects\BusinessId;
|
||||
use App\Modules\Customers\Domain\ValueObjects\CustomerName;
|
||||
use App\Modules\Customers\Domain\ValueObjects\PersonalIdentityCode;
|
||||
use App\Modules\Shared\Domain\ValueObjects\BusinessId;
|
||||
|
||||
/**
|
||||
* A customer of the company: a business or a private consumer.
|
||||
|
||||
@@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Customers\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Customers\Domain\ValueObjects\BusinessId;
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
use App\Modules\Shared\Domain\ValueObjects\BusinessId;
|
||||
|
||||
final class BusinessIdAlreadyInUse extends DomainException
|
||||
{
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Customers\Domain\Exceptions;
|
||||
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
final class InvalidBusinessId extends DomainException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('The business ID is not a valid Finnish business ID.');
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Customers\Domain\ValueObjects;
|
||||
|
||||
use App\Modules\Customers\Domain\Exceptions\InvalidBusinessId;
|
||||
|
||||
/**
|
||||
* Finnish business ID (Y-tunnus), e.g. 0737546-2.
|
||||
*
|
||||
* Seven digits, a hyphen and a check digit. Old six-digit IDs are
|
||||
* accepted and padded with a leading zero.
|
||||
*/
|
||||
final readonly class BusinessId
|
||||
{
|
||||
private const array WEIGHTS = [7, 9, 10, 5, 8, 4, 2];
|
||||
|
||||
public string $value;
|
||||
|
||||
public function __construct(string $value)
|
||||
{
|
||||
$value = trim($value);
|
||||
|
||||
if (preg_match('/^(\d{6,7})-(\d)$/', $value, $matches) !== 1) {
|
||||
throw new InvalidBusinessId;
|
||||
}
|
||||
|
||||
$digits = str_pad($matches[1], 7, '0', STR_PAD_LEFT);
|
||||
|
||||
if (self::checkDigitFor($digits) !== (int) $matches[2]) {
|
||||
throw new InvalidBusinessId;
|
||||
}
|
||||
|
||||
$this->value = "{$digits}-{$matches[2]}";
|
||||
}
|
||||
|
||||
public function equals(self $other): bool
|
||||
{
|
||||
return $this->value === $other->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null when no valid check digit exists (remainder 1).
|
||||
*/
|
||||
private static function checkDigitFor(string $digits): ?int
|
||||
{
|
||||
$sum = 0;
|
||||
|
||||
foreach (str_split($digits) as $index => $digit) {
|
||||
$sum += (int) $digit * self::WEIGHTS[$index];
|
||||
}
|
||||
|
||||
$remainder = $sum % 11;
|
||||
|
||||
return match ($remainder) {
|
||||
0 => 0,
|
||||
1 => null,
|
||||
default => 11 - $remainder,
|
||||
};
|
||||
}
|
||||
}
|
||||
+7
@@ -27,6 +27,13 @@ class EloquentCustomerQueries implements CustomerQueries
|
||||
return $ids === [] ? [] : CustomerModel::query()->whereIn('id', $ids)->pluck('name', 'id')->all();
|
||||
}
|
||||
|
||||
public function internalCustomerId(): ?int
|
||||
{
|
||||
$id = CustomerModel::query()->where('is_internal', true)->orderBy('id')->value('id');
|
||||
|
||||
return $id === null ? null : (int) $id;
|
||||
}
|
||||
|
||||
public function personalIdentityCodeOf(int $customerId): ?string
|
||||
{
|
||||
return CustomerModel::query()->find($customerId)?->personal_identity_code;
|
||||
|
||||
+1
-1
@@ -4,11 +4,11 @@ namespace App\Modules\Customers\Infrastructure\Persistence\Repositories;
|
||||
|
||||
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\CustomerName;
|
||||
use App\Modules\Customers\Domain\ValueObjects\PersonalIdentityCode;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\PersonalIdentityCodeHasher;
|
||||
use App\Modules\Shared\Domain\ValueObjects\BusinessId;
|
||||
|
||||
class EloquentCustomerRepository implements CustomerRepository
|
||||
{
|
||||
|
||||
@@ -9,11 +9,11 @@ use App\Modules\Customers\Domain\Exceptions\BusinessIdAlreadyInUse;
|
||||
use App\Modules\Customers\Domain\Exceptions\CompanyCannotHavePersonalIdentityCode;
|
||||
use App\Modules\Customers\Domain\Exceptions\ConsumerCannotHaveBusinessId;
|
||||
use App\Modules\Customers\Domain\Exceptions\InternalCustomerMustBeCompany;
|
||||
use App\Modules\Customers\Domain\Exceptions\InvalidBusinessId;
|
||||
use App\Modules\Customers\Domain\Exceptions\InvalidCustomerName;
|
||||
use App\Modules\Customers\Domain\Exceptions\InvalidPersonalIdentityCode;
|
||||
use App\Modules\Customers\Domain\Exceptions\PersonalIdentityCodeAlreadyInUse;
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
use App\Modules\Shared\Domain\Exceptions\InvalidBusinessId;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Form;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user