|
@@ -0,0 +1,108 @@
|
|
|
|
|
+<?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::table('student_contracts', function (Blueprint $table) {
|
|
|
|
|
+ // Make legacy columns nullable only if they exist
|
|
|
|
|
+ $columns = [
|
|
|
|
|
+ 'protocol' => fn () => $table->string('protocol')->nullable()->change(),
|
|
|
|
|
+ 'contract_id' => fn () => $table->foreignId('contract_id')->nullable()->change(),
|
|
|
|
|
+ 'classes_packages_franchisee_id' => fn () => $table->foreignId('classes_packages_franchisee_id')->nullable()->change(),
|
|
|
|
|
+ 'started_date' => fn () => $table->date('started_date')->nullable()->change(),
|
|
|
|
|
+ 'end_date' => fn () => $table->date('end_date')->nullable()->change(),
|
|
|
|
|
+ 'start_time' => fn () => $table->time('start_time')->nullable()->change(),
|
|
|
|
|
+ 'end_time' => fn () => $table->time('end_time')->nullable()->change(),
|
|
|
|
|
+ 'payment_method_id' => fn () => $table->foreignId('payment_method_id')->nullable()->change(),
|
|
|
|
|
+ 'modality_id' => fn () => $table->foreignId('modality_id')->nullable()->change(),
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($columns as $column => $alter) {
|
|
|
|
|
+ if (Schema::hasColumn('student_contracts', $column)) {
|
|
|
|
|
+ $alter();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // New columns — only add if not already present
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'class_package_unit_id')) {
|
|
|
|
|
+ $table->foreignId('class_package_unit_id')
|
|
|
|
|
+ ->nullable()
|
|
|
|
|
+ ->constrained('class_package_units')
|
|
|
|
|
+ ->nullOnDelete();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'signature_date')) {
|
|
|
|
|
+ $table->date('signature_date')->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'class_quantity')) {
|
|
|
|
|
+ $table->integer('class_quantity')->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'weekday')) {
|
|
|
|
|
+ $table->tinyInteger('weekday')->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'second_weekday')) {
|
|
|
|
|
+ $table->tinyInteger('second_weekday')->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'second_start_time')) {
|
|
|
|
|
+ $table->time('second_start_time')->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'second_end_time')) {
|
|
|
|
|
+ $table->time('second_end_time')->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'due_date')) {
|
|
|
|
|
+ $table->date('due_date')->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'recurring_day')) {
|
|
|
|
|
+ $table->tinyInteger('recurring_day')->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'down_payment')) {
|
|
|
|
|
+ $table->decimal('down_payment', 10, 2)->default(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'installments')) {
|
|
|
|
|
+ $table->tinyInteger('installments')->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'early_payment_discount')) {
|
|
|
|
|
+ $table->decimal('early_payment_discount', 5, 2)->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'material_value')) {
|
|
|
|
|
+ $table->decimal('material_value', 10, 2)->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'material_installments')) {
|
|
|
|
|
+ $table->tinyInteger('material_installments')->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'interest_rate')) {
|
|
|
|
|
+ $table->decimal('interest_rate', 5, 2)->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Schema::hasColumn('student_contracts', 'payment_method')) {
|
|
|
|
|
+ $table->string('payment_method')->nullable();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function down(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ Schema::table('student_contracts', function (Blueprint $table) {
|
|
|
|
|
+ if (Schema::hasColumn('student_contracts', 'class_package_unit_id')) {
|
|
|
|
|
+ $table->dropForeign(['class_package_unit_id']);
|
|
|
|
|
+ $table->dropColumn('class_package_unit_id');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $newColumns = [
|
|
|
|
|
+ 'signature_date', 'class_quantity', 'weekday', 'second_weekday',
|
|
|
|
|
+ 'second_start_time', 'second_end_time', 'due_date', 'recurring_day',
|
|
|
|
|
+ 'down_payment', 'installments', 'early_payment_discount',
|
|
|
|
|
+ 'material_value', 'material_installments', 'interest_rate', 'payment_method',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($newColumns as $column) {
|
|
|
|
|
+ if (Schema::hasColumn('student_contracts', $column)) {
|
|
|
|
|
+ $table->dropColumn($column);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+};
|