db->table_exists('document_sequences')) { $this->dbforge->add_field(array( 'id' => array('type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true), 'document_type' => array('type' => 'VARCHAR', 'constraint' => 50), 'period_key' => array('type' => 'VARCHAR', 'constraint' => 20), 'prefix' => array('type' => 'VARCHAR', 'constraint' => 50), 'current_value' => array('type' => 'BIGINT', 'unsigned' => true, 'default' => 0), 'updated_at' => array('type' => 'DATETIME', 'null' => true) )); $this->dbforge->add_key('id', true); $this->dbforge->create_table('document_sequences', true, array('ENGINE' => 'InnoDB')); $this->db->query('ALTER TABLE document_sequences ADD UNIQUE KEY uq_document_sequence (document_type, period_key)'); } if (!$this->db->table_exists('system_account_mappings')) { $this->dbforge->add_field(array( 'id' => array('type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true), 'mapping_key' => array('type' => 'VARCHAR', 'constraint' => 100), 'account_id' => array('type' => 'BIGINT', 'unsigned' => true), 'description' => array('type' => 'VARCHAR', 'constraint' => 255, 'null' => true), 'is_active' => array('type' => 'TINYINT', 'constraint' => 1, 'default' => 1), 'created_at' => array('type' => 'DATETIME', 'null' => true), 'updated_at' => array('type' => 'DATETIME', 'null' => true) )); $this->dbforge->add_key('id', true); $this->dbforge->add_key('account_id'); $this->dbforge->create_table('system_account_mappings', true, array('ENGINE' => 'InnoDB')); $this->db->query('ALTER TABLE system_account_mappings ADD UNIQUE KEY uq_system_account_mapping (mapping_key)'); } $mappings = array( array('inventory', 21, 'Persediaan'), array('cost_of_goods_sold', 63, 'Harga pokok penjualan'), array('accounts_receivable', 19, 'Piutang usaha'), array('deferred_revenue', 78, 'Pendapatan diterima di muka'), array('inventory_in_sales', 80, 'Persediaan dalam penjualan'), array('goods_revenue', 62, 'Pendapatan barang'), array('customer_savings', 70, 'Tabungan pelanggan'), array('depreciation_expense', 54, 'Beban penyusutan aset') ); foreach ($mappings as $mapping) { $accountExists = $this->db->where('id', $mapping[1])->count_all_results('accounts') > 0; $mappingExists = $this->db->where('mapping_key', $mapping[0])->count_all_results('system_account_mappings') > 0; if ($accountExists && !$mappingExists) { $this->db->insert('system_account_mappings', array( 'mapping_key' => $mapping[0], 'account_id' => $mapping[1], 'description' => $mapping[2], 'is_active' => 1, 'created_at' => date('Y-m-d H:i:s') )); } } } public function down() { $this->dbforge->drop_table('system_account_mappings', true); $this->dbforge->drop_table('document_sequences', true); } }