<?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('penjualan', function (Blueprint $table) {
            $table->id('penjualan_id');
            $table->date('tanggal_penjualan');

            // kolom diskon
            $table->integer('diskon')->default(0);

            // total dan pembayaran
            $table->decimal('total_harga', 10, 2)->default(0);
            $table->enum('status', ['pending', 'paid', 'cancelled'])->default('pending');
            $table->decimal('uang_dibayar', 10, 2)->nullable();
            $table->decimal('kembalian', 10, 2)->nullable();

            $table->foreignId('pelanggan_id')->nullable()
                ->constrained('pelanggan', 'pelanggan_id')
                ->cascadeOnUpdate()
                ->nullOnDelete();

            $table->foreignId('user_id')->nullable()
                ->constrained('tbl_users', 'user_id')
                ->cascadeOnUpdate()
                ->nullOnDelete();

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('penjualan');
    }
};
