<?php

use yii\db\Migration;
use yii\db\Schema;
use common\logic\Document\Document\Document;

/**
 * Class m220916_062206_add_column_document_tax_calculation_method
 */
class m220916_062206_add_column_document_tax_calculation_method extends Migration
{
    public static $tableDocumentArray = ['invoice', 'delivery_note', 'quotation'];

    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $schemaTaxCalculationMethod = Schema::TYPE_STRING.' DEFAULT \''.Document::TAX_CALCULATION_METHOD_DEFAULT.'\'';

        // producer
        $this->addColumn('producer', 'option_tax_calculation_method', $schemaTaxCalculationMethod);

        // documents
        $columnTaxCalculationMethod = 'tax_calculation_method';
        foreach(self::$tableDocumentArray as $tableName) {
            $this->addColumn($tableName, $columnTaxCalculationMethod, $schemaTaxCalculationMethod);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropColumn('producer', 'option_tax_calculation_method');

        foreach(self::$tableDocumentArray as $tableName) {
            $this->dropColumn($tableName, 'tax_calculation_method');
        }
    }
}
