- Work types get an hourly rate (VAT 0), set on the work type form or in the hourly rate grid of the new Hinnasto page (/catalog/prices), which saves a cell when focus leaves it. - Fixed-price products with a unit from a list, consumer product flag and automatic hours, which need a work type. Products are moved and deactivated, never deleted. - The mileage rate is stored in a new settings table through the shared Settings contract. - Shared Money value object keeps amounts in cents, parses "85,50" and formats "85,50 €". - Prices are read only through PriceListQueries, not CatalogQueries, so personal money permissions can be added in one place next. - Only admins and management can open the pages for now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Modules\Catalog\Domain\Enums\ProductUnit;
|
|
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ProductModel;
|
|
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<ProductModel>
|
|
*/
|
|
class ProductFactory extends Factory
|
|
{
|
|
protected $model = ProductModel::class;
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'name' => fake()->unique()->words(2, true),
|
|
'unit' => ProductUnit::Piece->value,
|
|
'price_cents' => fake()->numberBetween(100, 10000),
|
|
'is_consumer_product' => false,
|
|
'auto_hours' => 0,
|
|
'work_type_id' => null,
|
|
'is_active' => true,
|
|
'sort_order' => fake()->unique()->numberBetween(100, 100000),
|
|
];
|
|
}
|
|
|
|
public function consumer(): static
|
|
{
|
|
return $this->state(fn (): array => ['is_consumer_product' => true]);
|
|
}
|
|
|
|
public function inactive(): static
|
|
{
|
|
return $this->state(fn (): array => ['is_active' => false]);
|
|
}
|
|
|
|
public function withAutoHours(float $hours = 0.25): static
|
|
{
|
|
return $this->state(fn (): array => [
|
|
'auto_hours' => $hours,
|
|
'work_type_id' => WorkTypeModel::factory(),
|
|
]);
|
|
}
|
|
}
|