add payment option
This commit is contained in:
@@ -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');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user