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

class Lapkeucabrl extends CI_Controller
{

	function __construct()
	{
		parent::__construct();
		check_not_login(); // kode akses login diambil dari helper
		check_admin();
		$this->load->model('lapkeu_m');

		$this->load->library('form_validation');
	}

	public function index()
	{
		$data['totpenga'] = $this->lapkeu_m->gettotalpencabofficerl(); // ok
		$data['totgaji'] = $this->lapkeu_m->getpengrlcabtotalgaji(); // ok
		$data['totpengrl'] = $this->lapkeu_m->getpengrlcabtotal(); // ok
		$data['invoice_rlcab'] = $this->lapkeu_m->invoice_rlcab(); // ok
		//$data['rlcab'] = $this->lapkeu_m->getrlcab(); // ok
		$data['perlcabgaji'] = $this->lapkeu_m->getpengrlcabgaji(); // refisi
		$data['perlcab'] = $this->lapkeu_m->getpengrlcab(); // ok
		$data['pengrlcab'] = $this->lapkeu_m->invoice_pengrlcab(); // ok

		$this->template->load('template', 'lapkeucabrl', $data);
	}

	public function addpengrlcab()
	{
		$this->form_validation->set_rules('peng_rlcab', 'peng_rlcab', 'trim');

		$this->form_validation->set_message('required', '" masih kossong "');
		$this->form_validation->set_message('is_unique', '" sudah terdaftar "');


		if ($this->form_validation->run() == false) {
			$this->template->load('template', 'lapkeucabrl/addpengrlcab');
		} else {
			$post = $this->input->post(null, TRUE);
			$this->lapkeu_m->addpengrlcab($post);
			if ($this->db->affected_rows() > 0) {
				$this->session->set_flashdata('success', 'Pengeluaran Rugi Laba Bulanan berhasil Ditambahkan');
			}
			redirect($_SERVER['HTTP_REFERER']);
		}
	}

	public function addpengnercab()
	{
		$post = $this->input->post(null, TRUE);
		$this->lapkeu_m->addpengnercab($post);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Lanjut ke laoran Neraca ');
		}
		redirect('lapkeucabner');
	}

	public function delpenrlcab($id)
	{
		$this->lapkeu_m->delpenrlcab($id);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Data Item Pengeluaran berhasil Dihapus');
		}
		redirect($_SERVER['HTTP_REFERER']);
	}
}
