diff --git a/database/migrations/2026_01_29_170000_create_sales_commissions_table.php b/database/migrations/2026_01_29_170000_create_sales_commissions_table.php new file mode 100644 index 0000000..1fad60a --- /dev/null +++ b/database/migrations/2026_01_29_170000_create_sales_commissions_table.php @@ -0,0 +1,72 @@ +id(); + $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID'); + $table->unsignedBigInteger('management_id')->comment('영업 관리 ID (sales_tenant_managements)'); + + // 입금 정보 + $table->enum('payment_type', ['deposit', 'balance'])->comment('입금 구분 (deposit:계약금, balance:잔금)'); + $table->decimal('payment_amount', 14, 2)->comment('입금액'); + $table->date('payment_date')->comment('입금일'); + + // 수당 계산 기준 + $table->decimal('base_amount', 14, 2)->comment('수당 계산 기준액 (가입비의 50%)'); + $table->decimal('partner_rate', 5, 2)->default(20.00)->comment('영업파트너 수당률 (%)'); + $table->decimal('manager_rate', 5, 2)->default(5.00)->comment('매니저 수당률 (%)'); + $table->decimal('partner_commission', 14, 2)->comment('영업파트너 수당액'); + $table->decimal('manager_commission', 14, 2)->comment('매니저 수당액'); + + // 지급 정보 + $table->date('scheduled_payment_date')->comment('지급예정일 (익월 10일)'); + $table->enum('status', ['pending', 'approved', 'paid', 'cancelled']) + ->default('pending') + ->comment('상태 (pending:대기, approved:승인, paid:지급완료, cancelled:취소)'); + $table->date('actual_payment_date')->nullable()->comment('실제 지급일'); + + // 대상자 정보 + $table->unsignedBigInteger('partner_id')->comment('영업파트너 ID (sales_partners)'); + $table->unsignedBigInteger('manager_user_id')->nullable()->comment('매니저 사용자 ID'); + + // 부가 정보 + $table->text('notes')->nullable()->comment('메모'); + $table->string('bank_reference', 100)->nullable()->comment('이체 참조번호'); + + // 승인 정보 + $table->unsignedBigInteger('approved_by')->nullable()->comment('승인자 ID'); + $table->timestamp('approved_at')->nullable()->comment('승인일시'); + + $table->timestamps(); + $table->softDeletes(); + + // 인덱스 + $table->index('tenant_id'); + $table->index('management_id'); + $table->index('partner_id'); + $table->index('manager_user_id'); + $table->index('payment_type'); + $table->index('payment_date'); + $table->index('scheduled_payment_date'); + $table->index('status'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('sales_commissions'); + } +}; diff --git a/database/migrations/2026_01_29_170100_create_sales_commission_details_table.php b/database/migrations/2026_01_29_170100_create_sales_commission_details_table.php new file mode 100644 index 0000000..9b60ba2 --- /dev/null +++ b/database/migrations/2026_01_29_170100_create_sales_commission_details_table.php @@ -0,0 +1,47 @@ +id(); + $table->unsignedBigInteger('commission_id')->comment('수수료 정산 ID'); + $table->unsignedBigInteger('contract_product_id')->comment('계약 상품 ID (sales_contract_products)'); + + // 상품별 수당 계산 + $table->decimal('registration_fee', 14, 2)->comment('상품 가입비'); + $table->decimal('base_amount', 14, 2)->comment('수당 계산 기준액 (가입비의 50%)'); + $table->decimal('partner_rate', 5, 2)->comment('영업파트너 수당률 (%)'); + $table->decimal('manager_rate', 5, 2)->comment('매니저 수당률 (%)'); + $table->decimal('partner_commission', 14, 2)->comment('영업파트너 수당액'); + $table->decimal('manager_commission', 14, 2)->comment('매니저 수당액'); + + $table->timestamps(); + + // 인덱스 및 외래키 + $table->index('commission_id'); + $table->index('contract_product_id'); + + $table->foreign('commission_id') + ->references('id') + ->on('sales_commissions') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('sales_commission_details'); + } +}; diff --git a/database/migrations/2026_01_29_170200_add_payment_columns_to_sales_tenant_managements.php b/database/migrations/2026_01_29_170200_add_payment_columns_to_sales_tenant_managements.php new file mode 100644 index 0000000..8a53699 --- /dev/null +++ b/database/migrations/2026_01_29_170200_add_payment_columns_to_sales_tenant_managements.php @@ -0,0 +1,53 @@ +decimal('deposit_amount', 14, 2)->nullable()->after('membership_status')->comment('계약금'); + $table->date('deposit_paid_date')->nullable()->after('deposit_amount')->comment('계약금 입금일'); + $table->enum('deposit_status', ['pending', 'paid']) + ->default('pending') + ->after('deposit_paid_date') + ->comment('계약금 상태 (pending:대기, paid:입금완료)'); + + // 잔금 정보 + $table->decimal('balance_amount', 14, 2)->nullable()->after('deposit_status')->comment('잔금'); + $table->date('balance_paid_date')->nullable()->after('balance_amount')->comment('잔금 입금일'); + $table->enum('balance_status', ['pending', 'paid']) + ->default('pending') + ->after('balance_paid_date') + ->comment('잔금 상태 (pending:대기, paid:입금완료)'); + + // 총 가입비 (계약 상품 합계, 캐시용) + $table->decimal('total_registration_fee', 14, 2)->nullable()->after('balance_status')->comment('총 가입비'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('sales_tenant_managements', function (Blueprint $table) { + $table->dropColumn([ + 'deposit_amount', + 'deposit_paid_date', + 'deposit_status', + 'balance_amount', + 'balance_paid_date', + 'balance_status', + 'total_registration_fee', + ]); + }); + } +};