<?php

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

class CreateVentasTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('ventas', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('store_id')->unique();
            $table->string('status')->default('COMPLETADO');
            $table->unsignedBigInteger('user_id');
            $table->string('tipo_venta');
            $table->unsignedInteger('cliente_id')->nullable();
            $table->double('subtotal', 15, 2);
            $table->double('descuento', 15, 2)->default(0);
            $table->double('impuestos', 15, 2)->default(0);
            $table->double('total', 15, 2);
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('store_id')->references('id')->on('tiendas')->onDelete('cascade');
            $table->foreign('cliente_id')->references('id')->on('fs_clientes')->nullOnDelete();

        });
    }

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