<?php
	defined('BASEPATH') OR exit('No direct script access allowed');
	
	class Kas_bank extends CI_Controller 
	{
		public function __construct()
		{
			parent::__construct();
			cek_session_login();
			
			$this->load->model('Kas_model','kas');
			$this->iduser = $this->session->idu;
			$this->level = $this->session->level;
		}
		
		public function index()
		{
			cek_menu_akses();
			$data['title'] = 'Kas Tunai & Bank';
			$data['user'] = $this->model_app->view_where('tb_users', array('id_user' => $this->iduser))->row_array();
			 
			$this->load->model('Masterdata_model','masterdata');
			
			// semua data kas
			$data['dt_kas'] = $this->kas->getAllData();
			
			// data_akun ditampilkan aset lancar
			$this->db->where_in('kelompok_akun.id_kelompok_akun', 1);
			$data['dt_akun'] = $this->masterdata->getAccountData();
			$this->template->load('main/themes','kas/view_index',$data);
			 
		}
		
		// menambah data akun kas
		public function insert()
		{
			$this->kas->insert();
			$this->session->set_flashdata('message_kas','<div class="alert alert-success" role="alert">Akun Kas berhasil ditambahkan! 
			<button type="button" class="close" data-dismiss="alert" aria-label="Close">
			<span aria-hidden="true">&times;</span>
		  	</button></div>');
			redirect('kas_bank');
		}
		
		// mengupdate data akun kas
		public function update()
		{
			$id = $this->input->post('id_sak', true);
			$this->kas->update($id);
			$this->session->set_flashdata('message_kas','<div class="alert alert-primary" role="alert">Akun Kas berhasil diupdate! 
			<button type="button" class="close" data-dismiss="alert" aria-label="Close">
			<span aria-hidden="true">&times;</span>
		  	</button></div>');
			redirect('kas_bank');
		}
		
		// menghapus data akun kas
		public function delete()
		{
	 
			$id = $this->input->post('id_sak', true);
			$this->kas->delete($id);
			$this->session->set_flashdata('message_kas','<div class="alert alert-danger" role="alert">Akun Kas berhasil dihapus! 
			<button type="button" class="close" data-dismiss="alert" aria-label="Close">
			<span aria-hidden="true">&times;</span>
		  	</button></div>');
			redirect('kas_bank');
		}
	}	