<?php

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

class AlterStockTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		if (Schema::hasTable('stock')) {
			Schema::table('stock', function($table){
				if (Schema::hasColumn('stock', 'manufacturer_code')) {
					$table->dropColumn('manufacturer_code');
				}
				if (Schema::hasColumn('stock', 'sku')) {
					$table->dropColumn('sku');
				}
				if (Schema::hasColumn('stock', 'margin')) {
					$table->dropColumn('margin');
				}
				if (Schema::hasColumn('stock', 'business_margin')) {
					$table->dropColumn('business_margin');
				}
				if (Schema::hasColumn('stock', 'cost')) {
					$table->dropColumn('cost');
				}
				if (Schema::hasColumn('stock', 'business_cost')) {
					$table->dropColumn('business_cost');
				}
				if (!Schema::hasColumn('stock', 'model_number')) {
					$table->string('model_number',64)->nullable();
				}
				if (!Schema::hasColumn('stock', 'price_excluding_vat')) {
					$table->double('price_excluding_vat')->default(0);
				}
				if (!Schema::hasColumn('stock', 'quantity_to_order')) {
					$table->integer('quantity_to_order')->default(0);
				}
				if (!Schema::hasColumn('stock', 'ordered_quantity')) {
					$table->integer('ordered_quantity')->default(0);
				}
			});
		}
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('stock', function($table){
			$table->dropColumn('model_number');
			$table->dropColumn('price_excluding_vat');
			$table->dropColumn('ordered_quantity');
			$table->dropColumn('quantity_to_order');
			$table->string('manufacturer_code',64);
			$table->string('sku', 32);
			$table->double('margin');
			$table->double('business_margin');
			$table->double('cost');

		});
	}

}
