Add money permissions, a read-only price list and VAT rates
- Admins give employees and interns personal money permissions (prices, expenses, quotes, billing) on the user form. Other modules check them through the money.* abilities; admins and management see all amounts, subcontractors none. - Employees and interns get a read-only price list: consumer products with VAT always, hourly rates, other products and the mileage rate only with the price permission. Subcontractors cannot open it. - VAT rates are maintained on the price list page, with one default rate that always stays in use. Products get a VAT rate; changing a rate's percentage applies to every product using it. - Consumer product prices are entered and stored with VAT, so cash prices stay round; the price without VAT is calculated. The product form shows the other price as you type. - Shared VatPercentage value object and Money::addVat()/removeVat(), rounding half up to the cent in integer arithmetic. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* VAT rates in hundredths of a percent (2550 = 25,5 %). One rate is the
|
||||
* default, used for hours, expenses and mileage. Rows are never
|
||||
* deleted, only deactivated.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('vat_rates', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 100);
|
||||
$table->unsignedInteger('basis_points');
|
||||
$table->boolean('is_default')->default(false);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->unsignedInteger('sort_order');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('sort_order');
|
||||
});
|
||||
|
||||
$now = now();
|
||||
|
||||
DB::table('vat_rates')->insert(array_map(
|
||||
fn (array $rate, int $index): array => $rate + ['is_active' => true, 'sort_order' => $index + 1, 'created_at' => $now, 'updated_at' => $now],
|
||||
[
|
||||
['name' => 'Yleinen', 'basis_points' => 2550, 'is_default' => true],
|
||||
['name' => 'Alennettu 13,5 %', 'basis_points' => 1350, 'is_default' => false],
|
||||
['name' => 'Alennettu 10 %', 'basis_points' => 1000, 'is_default' => false],
|
||||
['name' => 'Veroton', 'basis_points' => 0, 'is_default' => false],
|
||||
],
|
||||
[0, 1, 2, 3],
|
||||
));
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('vat_rates');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Every product has a VAT rate; existing products get the default one.
|
||||
* The column stays nullable in the database, the domain requires it.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->foreignId('vat_rate_id')->nullable()->after('price_cents')->constrained()->restrictOnDelete();
|
||||
});
|
||||
|
||||
$defaultId = DB::table('vat_rates')->where('is_default', true)->value('id');
|
||||
|
||||
DB::table('products')->update(['vat_rate_id' => $defaultId]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('vat_rate_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Personal permissions of employees and interns to see money amounts.
|
||||
* Admins and management see all amounts by role.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('user_money_permissions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->unique()->constrained()->cascadeOnDelete();
|
||||
$table->boolean('can_see_prices')->default(false);
|
||||
$table->boolean('can_see_expenses')->default(false);
|
||||
$table->boolean('can_see_quotes')->default(false);
|
||||
$table->boolean('can_see_billing')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('user_money_permissions');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user