<?php

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

class AddPurchaseAndSalesColumnsToPrProducts extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasColumn('pr_products', 'last_purchased_qty')) {
        Schema::table('pr_products', function (Blueprint $table) {
            $table->decimal('last_purchased_qty', 22, 4)->default(0)->after('last_purchase_price');
            $table->decimal('last_purchased_adjusted_qty', 22, 4)->default(0)->after('last_purchased_qty');
            $table->decimal('year_ago_sold_qty', 22, 4)->default(0)->after('last_purchased_adjusted_qty');
        });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('pr_products', function (Blueprint $table) {
            $table->dropColumn(['last_purchased_qty', 'last_purchased_adjusted_qty', 'year_ago_sold_qty']);
        });
    }
}
