<?php

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

class CreateCompanyOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('company_orders', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger("company_id");
            $table->unsignedBigInteger("invoice_id")->nullable();
            $table->unsignedBigInteger("payment_id")->nullable();
            $table->unsignedBigInteger("subscription_id");
            $table->float("subtotal");
            $table->float("vat");
            $table->float("total");
            $table->timestamps();

            $table->foreign("company_id")->on("companies")->references("id")->onDelete("restrict");
            $table->foreign("invoice_id")->on("invoices")->references("id")->onDelete("restrict");
            $table->foreign("payment_id")->on("payments")->references("id")->onDelete("restrict");
            $table->foreign("subscription_id")->on("subscriptions")->references("id")->onDelete("restrict");
        });
    }

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