<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_add_show_logo_on_invoice extends CI_Migration {

    public function up()
    {
        // Add show_logo_on_invoice column to db_store table (for regular sales invoices)
        $fields = array(
            'show_logo_on_invoice' => array(
                'type' => 'INT',
                'constraint' => 1,
                'default' => 1,
                'null' => TRUE,
                'comment' => '1=Show logo on sales invoice, 0=Hide logo'
            ),
            'show_logo_on_reports' => array(
                'type' => 'INT',
                'constraint' => 1,
                'default' => 1,
                'null' => TRUE,
                'comment' => '1=Show logo on reports, 0=Hide logo'
            )
        );
        
        if (!$this->db->field_exists('show_logo_on_invoice', 'db_store')) {
            $this->dbforge->add_column('db_store', array('show_logo_on_invoice' => $fields['show_logo_on_invoice']));
        }
        
        if (!$this->db->field_exists('show_logo_on_reports', 'db_store')) {
            $this->dbforge->add_column('db_store', array('show_logo_on_reports' => $fields['show_logo_on_reports']));
        }
    }

    public function down()
    {
        // Remove the columns if they exist
        if ($this->db->field_exists('show_logo_on_invoice', 'db_store')) {
            $this->dbforge->drop_column('db_store', 'show_logo_on_invoice');
        }
        
        if ($this->db->field_exists('show_logo_on_reports', 'db_store')) {
            $this->dbforge->drop_column('db_store', 'show_logo_on_reports');
        }
    }
}

