<?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('parties',function(Blueprint $t){$t->id();$t->ulid('public_id')->unique();$t->foreignId('company_id')->constrained()->cascadeOnDelete();$t->foreignId('assigned_branch_id')->nullable()->constrained('branches')->nullOnDelete();$t->foreignId('assigned_user_id')->nullable()->constrained('users')->nullOnDelete();$t->string('legal_name');$t->string('trade_name')->nullable();$t->string('entity_type')->default('company');$t->string('trn',20)->nullable()->index();$t->string('trade_license_number')->nullable();$t->date('license_expiry_date')->nullable();$t->string('identification_number')->nullable();$t->string('contact_person')->nullable();$t->string('phone')->nullable()->index();$t->string('email')->nullable()->index();$t->text('billing_address')->nullable();$t->text('operational_address')->nullable();$t->string('emirate')->nullable();$t->char('country_code',2)->default('AE');$t->decimal('credit_limit',20,4)->default(0);$t->unsignedInteger('credit_period_days')->default(0);$t->char('default_currency',3)->default('AED');$t->foreignId('default_tax_code_id')->nullable()->constrained('tax_codes')->restrictOnDelete();$t->foreignId('default_income_account_id')->nullable()->constrained('accounts')->restrictOnDelete();$t->foreignId('default_expense_account_id')->nullable()->constrained('accounts')->restrictOnDelete();$t->foreignId('default_receivable_account_id')->nullable()->constrained('accounts')->restrictOnDelete();$t->foreignId('default_payable_account_id')->nullable()->constrained('accounts')->restrictOnDelete();$t->string('einvoice_address')->nullable();$t->string('einvoice_scheme')->nullable();$t->text('notes')->nullable();$t->boolean('is_active')->default(true);$t->timestamps();$t->index(['company_id','legal_name']);});Schema::create('party_roles',function(Blueprint $t){$t->id();$t->foreignId('party_id')->constrained()->cascadeOnDelete();$t->string('role',40);$t->timestamps();$t->unique(['party_id','role']);});}public function down():void{Schema::dropIfExists('party_roles');Schema::dropIfExists('parties');}};
