add payment option

This commit is contained in:
2025-10-02 18:35:02 +02:00
parent 0e0912c81b
commit 971a9e89d1
27 changed files with 1327 additions and 34 deletions
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('payments')) {
Schema::create('payments', function (Blueprint $table): void {
$table->id();
$table->foreignId('account_id')->constrained()->cascadeOnDelete();
$table->bigInteger('amount_cents');
$table->string('currency', 3)->default('EUR');
$table->string('reference')->nullable();
$table->timestamp('paid_at')->nullable();
$table->jsonb('meta')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->softDeletes();
$table->index(['account_id', 'paid_at']);
$table->index('reference');
});
}
}
public function down(): void
{
Schema::dropIfExists('payments');
}
};
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('bookings')) {
Schema::create('bookings', function (Blueprint $table): void {
$table->id();
$table->foreignId('account_id')->constrained()->cascadeOnDelete();
$table->foreignId('payment_id')->nullable()->constrained('payments')->nullOnDelete();
$table->bigInteger('amount_cents');
$table->enum('type', ['debit', 'credit']);
$table->string('description')->nullable();
$table->timestamp('booked_at')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index(['account_id', 'booked_at']);
});
}
}
public function down(): void
{
Schema::dropIfExists('bookings');
}
};
@@ -0,0 +1,61 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
// Drop in reverse dependency order
if (Schema::hasTable('bookings')) {
Schema::drop('bookings');
}
if (Schema::hasTable('payments')) {
Schema::drop('payments');
}
// Recreate payments
Schema::create('payments', function (Blueprint $table): void {
$table->id();
$table->foreignId('account_id')->constrained()->cascadeOnDelete();
$table->bigInteger('amount_cents');
$table->string('currency', 3)->default('EUR');
$table->string('reference')->nullable();
$table->timestamp('paid_at')->nullable();
$table->jsonb('meta')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->softDeletes();
$table->index(['account_id', 'paid_at']);
$table->index('reference');
});
// Recreate bookings
Schema::create('bookings', function (Blueprint $table): void {
$table->id();
$table->foreignId('account_id')->constrained()->cascadeOnDelete();
$table->foreignId('payment_id')->nullable()->constrained('payments')->nullOnDelete();
$table->bigInteger('amount_cents');
$table->enum('type', ['debit', 'credit']);
$table->string('description')->nullable();
$table->timestamp('booked_at')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index(['account_id', 'booked_at']);
});
}
public function down(): void
{
if (Schema::hasTable('bookings')) {
Schema::drop('bookings');
}
if (Schema::hasTable('payments')) {
Schema::drop('payments');
}
}
};
@@ -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
{
public function up(): void
{
Schema::create('payment_settings', function (Blueprint $table): void {
$table->id();
$table->string('default_currency', 3)->default('EUR');
$table->boolean('create_activity_on_payment')->default(false);
$table->foreignId('default_decision_id')->nullable()->constrained('decisions')->nullOnDelete();
$table->foreignId('default_action_id')->nullable()->constrained('actions')->nullOnDelete();
$table->string('activity_note_template', 255)->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('payment_settings');
}
};
@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
if (Schema::hasTable('payments') && ! Schema::hasColumn('payments', 'activity_id')) {
Schema::table('payments', function (Blueprint $table): void {
$table->foreignId('activity_id')->nullable()->constrained('activities')->nullOnDelete()->after('created_by');
$table->index('activity_id');
});
}
}
public function down(): void
{
if (Schema::hasTable('payments') && Schema::hasColumn('payments', 'activity_id')) {
Schema::table('payments', function (Blueprint $table): void {
$table->dropConstrainedForeignId('activity_id');
});
}
}
};
+8 -33
View File
@@ -4,7 +4,6 @@
use App\Models\AccountType;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class AccountTypeSeeder extends Seeder
{
@@ -12,40 +11,16 @@ public function run(): void
{
$now = now();
// If table is empty, insert with explicit IDs so id=1 exists (matches default logic elsewhere)
if (AccountType::count() === 0) {
$rows = [
['id' => 1, 'name' => 'Default', 'description' => 'Default account type', 'created_at' => $now, 'updated_at' => $now],
['id' => 2, 'name' => 'Primary', 'description' => 'Primary account', 'created_at' => $now, 'updated_at' => $now],
['id' => 3, 'name' => 'Secondary', 'description' => 'Secondary account', 'created_at' => $now, 'updated_at' => $now],
['id' => 4, 'name' => 'Savings', 'description' => 'Savings account', 'created_at' => $now, 'updated_at' => $now],
['id' => 5, 'name' => 'Checking', 'description' => 'Checking account', 'created_at' => $now, 'updated_at' => $now],
['id' => 6, 'name' => 'Credit', 'description' => 'Credit account', 'created_at' => $now, 'updated_at' => $now],
['id' => 7, 'name' => 'Loan', 'description' => 'Loan account', 'created_at' => $now, 'updated_at' => $now],
['id' => 8, 'name' => 'Other', 'description' => 'Other account type', 'created_at' => $now, 'updated_at' => $now],
];
DB::table('account_types')->insert($rows);
return;
}
// If table already has data, ensure the basics exist (idempotent, no explicit IDs)
$names = [
'Default' => 'Default account type',
'Primary' => 'Primary account',
'Secondary' => 'Secondary account',
'Savings' => 'Savings account',
'Checking' => 'Checking account',
'Credit' => 'Credit account',
'Loan' => 'Loan account',
'Other' => 'Other account type',
$rows = [
['name' => 'Receivables', 'description' => 'Standard receivable account'],
['name' => 'Payables', 'description' => 'Standard payable account'],
['name' => 'Loan', 'description' => 'Loan and credit account'],
['name' => 'Savings', 'description' => 'Savings account type'],
['name' => 'Current', 'description' => 'Current/operational account'],
];
foreach ($names as $name => $desc) {
AccountType::updateOrCreate(
['name' => $name],
['description' => $desc]
);
foreach ($rows as $row) {
AccountType::updateOrCreate(['name' => $row['name']], ['description' => $row['description']]);
}
}
}
+2
View File
@@ -29,6 +29,8 @@ public function run(): void
);
$this->call([
AccountTypeSeeder::class,
PaymentSettingSeeder::class,
PersonSeeder::class,
SegmentSeeder::class,
ActionSeeder::class,
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace Database\Seeders;
use App\Models\PaymentSetting;
use Illuminate\Database\Seeder;
class PaymentSettingSeeder extends Seeder
{
public function run(): void
{
// Create default record if not exists
PaymentSetting::query()->firstOrCreate([], [
'default_currency' => 'EUR',
'create_activity_on_payment' => false,
'default_decision_id' => null,
'default_action_id' => null,
'activity_note_template' => 'Prejeto plačilo: {amount} {currency}',
]);
}
}