/
home
/
u694682534
/
domains
/
blackbooks.me
/
public_html
/
amer
/
Upload File
HOME
<?php /** * Script to create checks tables directly in database * Run: php run_checks_migrations_direct.php */ // Try to find the correct path $basePath = __DIR__; if (file_exists($basePath . '/BlackBooks_lite/vendor/autoload.php')) { $basePath = $basePath . '/BlackBooks_lite'; } elseif (file_exists($basePath . '/vendor/autoload.php')) { // Already in BlackBooks_lite directory } else { die("Cannot find vendor/autoload.php. Please run this script from the project root.\n"); } require $basePath . '/vendor/autoload.php'; $app = require_once $basePath . '/bootstrap/app.php'; $kernel = $app->make(Illuminate\Contracts\Console\Kernel::class); $kernel->bootstrap(); use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\DB; echo "Creating checks tables directly...\n\n"; try { DB::beginTransaction(); // Check if banks table exists if (!Schema::hasTable('banks')) { echo "Creating banks table...\n"; Schema::create('banks', function ($table) { $table->increments('id'); $table->integer('business_id')->unsigned(); $table->foreign('business_id')->references('id')->on('business')->onDelete('cascade'); $table->string('name_ar', 255); $table->string('name_en', 255)->nullable(); $table->string('code', 50)->nullable(); $table->unsignedBigInteger('account_id')->nullable(); $table->foreign('account_id')->references('id')->on('main_accounts')->onDelete('set null'); $table->text('notes')->nullable(); $table->enum('status', ['active', 'inactive'])->default('active'); $table->integer('created_by')->unsigned()->nullable(); $table->integer('updated_by')->unsigned()->nullable(); $table->timestamps(); $table->softDeletes(); $table->index('business_id'); $table->index('status'); }); echo "✓ Banks table created successfully\n"; } else { echo "✓ Banks table already exists\n"; } // Check if cheques table exists if (!Schema::hasTable('cheques')) { echo "Creating cheques table...\n"; Schema::create('cheques', function ($table) { $table->increments('id'); $table->integer('business_id')->unsigned(); $table->foreign('business_id')->references('id')->on('business')->onDelete('cascade'); $table->integer('payment_id')->unsigned(); $table->foreign('payment_id')->references('id')->on('transaction_payments')->onDelete('cascade'); $table->string('cheque_number', 100); $table->date('due_date'); $table->integer('bank_id')->unsigned(); $table->foreign('bank_id')->references('id')->on('banks')->onDelete('restrict'); $table->string('bank_account_number', 100)->nullable(); $table->enum('check_type', ['receivable', 'payable'])->default('receivable'); $table->enum('check_status', ['pending', 'cleared', 'returned', 'cancelled'])->default('pending'); $table->date('cleared_date')->nullable(); $table->text('notes')->nullable(); $table->integer('created_by')->unsigned()->nullable(); $table->integer('updated_by')->unsigned()->nullable(); $table->timestamps(); $table->softDeletes(); $table->index('business_id'); $table->index('payment_id'); $table->index('bank_id'); $table->index('check_type'); $table->index('check_status'); $table->index('due_date'); $table->unique(['business_id', 'cheque_number', 'bank_id'], 'unique_cheque_number_per_bank'); }); echo "✓ Cheques table created successfully\n"; } else { echo "✓ Cheques table already exists\n"; } DB::commit(); echo "\n✓ All tables created successfully!\n"; } catch (\Exception $e) { DB::rollBack(); echo "✗ Error: " . $e->getMessage() . "\n"; echo "File: " . $e->getFile() . "\n"; echo "Line: " . $e->getLine() . "\n"; exit(1); }