Add the price list: hourly rates, products and mileage rate
- 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]>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Hourly rate of a work type in cents, VAT 0; null when not priced.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('work_types', function (Blueprint $table) {
|
||||
$table->unsignedInteger('hourly_rate_cents')->nullable()->after('name');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('work_types', function (Blueprint $table) {
|
||||
$table->dropColumn('hourly_rate_cents');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Fixed-price products (passikuvat, tulosteet). Prices in cents, VAT 0.
|
||||
* Products are never deleted, only deactivated.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('products', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 100);
|
||||
$table->string('unit', 20);
|
||||
$table->unsignedInteger('price_cents');
|
||||
$table->boolean('is_consumer_product')->default(false);
|
||||
$table->decimal('auto_hours', 6, 2)->default(0);
|
||||
$table->foreignId('work_type_id')->nullable()->constrained()->restrictOnDelete();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->unsignedInteger('sort_order');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('sort_order');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('products');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Application-wide settings, e.g. the mileage rate.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('settings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('key', 100)->unique();
|
||||
$table->text('value')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('settings');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user