Files
Toiminnanohjaus/database/migrations/2026_11_24_060013_create_expenses_table.php
petriandClaude Opus 5.5 54d98d9d2f Add expenses on customer jobs
- New Expenses module: purchases (materials, other) with a description
  and cost, and mileage priced with the price list's mileage rate.
- Who paid and whether the expense is billed are separate: an employee's
  own payments are reimbursed elsewhere. A billed expense has a markup
  and a billed amount, cost plus markup unless given.
- A job's expenses page lists, adds, edits and removes them; amounts of
  others' expenses need the expenses permission, own ones always show.
  Done jobs lock their expenses.
- The Kulut menu shows the user's own expenses by month. Management
  records subcontractors' expenses, which they see but cannot change.
- The price list gets a default markup for new purchases.
- Number fields that update a calculation now use wire:model.live.blur:
  in Livewire 4 plain .blur no longer sends the value to the server,
  which also fixes the product form's VAT calculation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 08:11:27 +02:00

43 lines
1.5 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Expenses on customer jobs. Amounts are in cents without VAT; the
* billed amount is null when the expense is not billed to the customer.
*/
public function up(): void
{
Schema::create('expenses', function (Blueprint $table) {
$table->id();
$table->foreignId('customer_job_id')->constrained()->restrictOnDelete();
$table->foreignId('user_id')->constrained()->restrictOnDelete();
$table->foreignId('recorded_by')->constrained('users')->restrictOnDelete();
$table->string('category', 20);
$table->string('paid_by', 20);
$table->date('spent_on');
$table->string('description', 255)->nullable();
$table->unsignedInteger('cost_cents');
$table->decimal('kilometers', 7, 1)->nullable();
$table->string('destination', 255)->nullable();
$table->string('purpose', 255)->nullable();
$table->boolean('is_billable')->default(true);
$table->unsignedInteger('markup_basis_points')->nullable();
$table->unsignedInteger('billed_amount_cents')->nullable();
$table->timestamps();
$table->index(['customer_job_id', 'spent_on']);
$table->index(['user_id', 'spent_on']);
});
}
public function down(): void
{
Schema::dropIfExists('expenses');
}
};