<?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('salary_revisions',function(Blueprint $t){$t->id();$t->foreignId('employee_id')->constrained()->cascadeOnDelete();$t->date('effective_from')->index();$t->decimal('base_salary',14,2);$t->json('allowances')->nullable();$t->json('deductions')->nullable();$t->text('notes')->nullable();$t->foreignId('approved_by')->nullable()->constrained('users')->nullOnDelete();$t->timestamps();$t->unique(['employee_id','effective_from']);});
Schema::create('payroll_batches',function(Blueprint $t){$t->id();$t->string('period')->unique();$t->string('status')->default('draft')->index();$t->timestamp('calculated_at')->nullable();$t->timestamp('approved_at')->nullable();$t->timestamp('paid_at')->nullable();$t->timestamp('locked_at')->nullable();$t->foreignId('approved_by')->nullable()->constrained('users')->nullOnDelete();$t->timestamps();});
Schema::create('payroll_items',function(Blueprint $t){$t->id();$t->foreignId('payroll_batch_id')->constrained()->cascadeOnDelete();$t->foreignId('employee_id')->constrained()->restrictOnDelete();$t->decimal('base_salary',14,2);$t->decimal('allowances_total',14,2)->default(0);$t->decimal('deductions_total',14,2)->default(0);$t->decimal('bonus_total',14,2)->default(0);$t->decimal('net_salary',14,2);$t->decimal('payable_days',6,2)->default(30);$t->json('snapshot');$t->timestamps();$t->unique(['payroll_batch_id','employee_id']);});
Schema::create('stipend_batches',function(Blueprint $t){$t->id();$t->string('period')->unique();$t->string('status')->default('draft');$t->foreignId('approved_by')->nullable()->constrained('users')->nullOnDelete();$t->timestamp('approved_at')->nullable();$t->timestamp('paid_at')->nullable();$t->timestamp('locked_at')->nullable();$t->timestamps();});
Schema::create('stipend_items',function(Blueprint $t){$t->id();$t->foreignId('stipend_batch_id')->constrained()->cascadeOnDelete();$t->foreignId('intern_id')->constrained()->restrictOnDelete();$t->decimal('stipend_amount',14,2);$t->decimal('deductions',14,2)->default(0);$t->decimal('additions',14,2)->default(0);$t->decimal('net_amount',14,2);$t->json('snapshot');$t->timestamps();$t->unique(['stipend_batch_id','intern_id']);});
Schema::create('expense_categories',function(Blueprint $t){$t->id();$t->string('name');$t->string('code')->unique();$t->boolean('requires_founder_approval')->default(false);$t->boolean('is_active')->default(true);$t->timestamps();});
Schema::create('expenses',function(Blueprint $t){$t->id();$t->foreignId('expense_category_id')->constrained()->restrictOnDelete();$t->string('type');$t->date('expense_date')->index();$t->decimal('amount',14,2);$t->string('payment_method')->nullable();$t->foreignId('project_id')->nullable()->constrained()->nullOnDelete();$t->foreignId('department_id')->nullable()->constrained()->nullOnDelete();$t->foreignId('claimant_user_id')->nullable()->constrained('users')->nullOnDelete();$t->string('vendor_name')->nullable();$t->text('description');$t->string('receipt_path')->nullable();$t->string('status')->default('submitted')->index();$t->foreignId('manager_approved_by')->nullable()->constrained('users')->nullOnDelete();$t->foreignId('finance_reviewed_by')->nullable()->constrained('users')->nullOnDelete();$t->foreignId('founder_approved_by')->nullable()->constrained('users')->nullOnDelete();$t->timestamp('paid_at')->nullable();$t->timestamps();});
Schema::create('assets',function(Blueprint $t){$t->id();$t->string('asset_code')->unique();$t->string('type');$t->string('make_model')->nullable();$t->string('serial_number')->nullable()->unique();$t->date('purchase_date')->nullable();$t->date('warranty_until')->nullable();$t->foreignId('assigned_user_id')->nullable()->constrained('users')->nullOnDelete();$t->timestamp('issued_at')->nullable();$t->timestamp('returned_at')->nullable();$t->string('condition')->nullable();$t->string('status')->default('available');$t->timestamps();});
Schema::create('announcements',function(Blueprint $t){$t->id();$t->string('title');$t->text('body');$t->string('audience')->default('all');$t->foreignId('published_by')->nullable()->constrained('users')->nullOnDelete();$t->timestamp('published_at')->nullable();$t->timestamp('expires_at')->nullable();$t->boolean('is_active')->default(true);$t->timestamps();});
Schema::create('audit_logs',function(Blueprint $t){$t->id();$t->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();$t->string('action')->index();$t->string('target_type')->nullable();$t->unsignedBigInteger('target_id')->nullable();$t->string('ip_address',45)->nullable();$t->text('user_agent')->nullable();$t->json('old_values')->nullable();$t->json('new_values')->nullable();$t->json('meta')->nullable();$t->timestamp('created_at')->useCurrent();$t->index(['target_type','target_id']);});
}public function down():void{Schema::dropIfExists('audit_logs');Schema::dropIfExists('announcements');Schema::dropIfExists('assets');Schema::dropIfExists('expenses');Schema::dropIfExists('expense_categories');Schema::dropIfExists('stipend_items');Schema::dropIfExists('stipend_batches');Schema::dropIfExists('payroll_items');Schema::dropIfExists('payroll_batches');Schema::dropIfExists('salary_revisions');}};
