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

class LapK extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
		check_not_login();
		$this->load->model(['lapkeu_m', 'Supl_m']);
	}
	public function index()
	{
		$data['inovoicharian'] = $this->lapkeu_m->invoivelap();
		$data['inpengharian'] = $this->lapkeu_m->invopengcab();
		$data['inoicecabjh'] = $this->lapkeu_m->invoice_nocabjh();
		$data['inpengcaba'] = $this->lapkeu_m->invoice_pengcaba();
		$data['totpesbrgkasir'] = $this->Supl_m->gettotalpesbrgcabkasiraja();
		$data['totservice'] = $this->lapkeu_m->tot_service();


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

	public function addpencab()
	{
		$post = $this->input->post(null, TRUE);
		$this->lapkeu_m->addpencab($post);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Data Biaya Pengeluaran berhasil Ditambahkan');
		}
		redirect($_SERVER['HTTP_REFERER']);
	}

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

	public function addlapJurnalHariancab()
	{
		$this->form_validation->set_rules('inov_jurhcab', 'inov_jurhcab', 'trim|is_unique[tb_jurhcab.inov_jurhcab]');

		$this->form_validation->set_message('is_unique', '');


		if ($this->form_validation->run() == false) {
			$data['inovoicharian'] = $this->lapkeu_m->invoivelap();
			$data['inpengharian'] = $this->lapkeu_m->invopengcab();
			$data['inoicecabjh'] = $this->lapkeu_m->invoice_nocabjh();
			$data['inpengcaba'] = $this->lapkeu_m->invoice_pengcaba();
			$data['totpesbrgkasir'] = $this->Supl_m->gettotalpesbrgcabkasiraja();
			$data['totservice'] = $this->lapkeu_m->tot_service();

			$this->template->load('template', 'lapK', $data);
		} else {

			$post = $this->input->post(null, TRUE);
			$this->lapkeu_m->addlapJurnalHariancab($post);
			if ($this->db->affected_rows() > 0) {
				$this->session->set_flashdata('success', 'Laporan Jurnal Harian berhasil Ditambahkan');
			}
			redirect('lapK');
		}
	}
}
