<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // Add tipe_dokumen to m_store_raw_materials
        if (Schema::hasTable('m_store_raw_materials')) {
            Schema::table('m_store_raw_materials', function (Blueprint $table) {
                if (!Schema::hasColumn('m_store_raw_materials', 'tipe_dokumen')) {
                    $table->string('tipe_dokumen', 10)->default('DO')->after('raw_material_id')
                        ->comment('DO/PO/PR - Document type for this item at this store');
                }
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (Schema::hasTable('m_store_raw_materials')) {
            Schema::table('m_store_raw_materials', function (Blueprint $table) {
                if (Schema::hasColumn('m_store_raw_materials', 'tipe_dokumen')) {
                    $table->dropColumn('tipe_dokumen');
                }
            });
        }
    }
};
