<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('customer_advance_payment_details', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('advance_payment_master_id');
            $table->unsignedBigInteger('product_id');
            $table->unsignedBigInteger('attribute_id');
            $table->decimal('quantity', 10, 2)->default(0);
            $table->decimal('price', 15, 2)->default(0);
            $table->decimal('total', 15, 2)->default(0);
            $table->string('invoice_type')->nullable()->default('MRP');
            $table->timestamps();
            $table->foreign('advance_payment_master_id', 'cap_details_master_id_fk')->references('id')->on('customer_advance_payment_masters')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('customer_advance_payment_details', function (Blueprint $table) {
            $table->dropForeign('cap_details_master_id_fk');
        });
        Schema::dropIfExists('customer_advance_payment_details');
    }
};
