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

class SsKasir extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
		check_not_login(); // kode akses login diambil dari helper
		//check_admin();
		$this->load->model('SsProses_m');
	}
	public function index()
	{
		$data['invoice'] = $this->SsProses_m->invoice_no();
		$data['bmproses'] = $this->SsProses_m->getbmproses();
		$this->template->load('template', 'ssKasir', $data);
	}

	// input data detail kerusakan
	public function addsell()
	{
		$post = $this->input->post(null, TRUE);
		$this->SsProses_m->addsell($post);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Data kendaraan Berhasil Ditambahkan');
		}
		redirect($_SERVER['HTTP_REFERER']);
	}

	public function editBM($id)
	{
		$data['get_id'] = $this->SsProses_m->get($id);
		$data['getrusak'] = $this->SsProses_m->get_rusak($id);
		$data['getsparepart'] = $this->SsProses_m->get_sparepart($id);
		$data['getpart'] = $this->SsProses_m->get_part();
		$data['bmproses'] = $this->SsProses_m->getbmproses();
		$data['totjasa'] = $this->SsProses_m->totjasa($id);
		$data['totmjasa'] = $this->SsProses_m->totmjasa($id);
		$data['totpart'] = $this->SsProses_m->totpart($id);
		$data['totmpart'] = $this->SsProses_m->totmpart($id);
		$data['totbyr'] = $this->SsProses_m->totbyr($id);
		$data['dpbyr'] = $this->SsProses_m->dpbyr($id);
		$data['mekanik'] = $this->SsProses_m->get_mekanik();


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


	public function editanalisaK()
	{
		$post = $this->input->post(null, TRUE);
		$this->SsProses_m->editanalisaK($post);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Perubahan Data Berhasil Di perbaharui');
		}
		redirect($_SERVER['HTTP_REFERER']);
	}

	// input data detail kerusakan
	public function addanalisa()
	{
		$post = $this->input->post(null, TRUE);
		$this->SsProses_m->addanalisa($post);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Data Kerusakan Berhasil Ditambahkan');
		}
		redirect($_SERVER['HTTP_REFERER']);
	}

	// hapus item detail kerusakan
	public function delrusk($id)
	{
		$this->SsProses_m->delrusk($id);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Data Kerusakan berhasil Dihapus');
		}
		redirect($_SERVER['HTTP_REFERER']);
	}

	public function editpartK()
	{
		$post = $this->input->post(null, TRUE);
		$this->SsProses_m->editpartK($post);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Pengambilan Sparepart Berhasil Laporkan');
		}
		redirect($_SERVER['HTTP_REFERER']);
	}

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

	public function editbyr()
	{
		$post = $this->input->post(null, TRUE);
		$this->SsProses_m->editbyr($post);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Proses Invoice sudah Di Update');
		}
		redirect('ssKasirprint');
	}
}
