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

class SsProses 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();
		$data['get_pel'] = $this->SsProses_m->getpel();
		$this->template->load('template', 'ssProses', $data);
	}

	// input data detail kerusakan
	public function addpelangan()
	{
		$post = $this->input->post(null, TRUE);
		$this->SsProses_m->addsell($post);
		$this->SsProses_m->addpel($post);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'invoice Data Perbaikan Berhasil Ditambahkan');
		}
		redirect('ssProses');
	}

	public function addsell()
	{
		$post = $this->input->post(null, TRUE);
		$this->SsProses_m->addsell($post);
		$this->SsProses_m->upkunjungan($post);

		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'invoice Data Perbaikan Berhasil Ditambahkan');
		}
		redirect('ssProses');
	}

	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['mekanik'] = $this->SsProses_m->get_mekanik();


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

	public function ssKasir($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();

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

	public function editanalisa()
	{
		$post = $this->input->post(null, TRUE);
		$this->SsProses_m->editanalisa($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 addpart()
	{
		$post = $this->input->post(null, TRUE);
		$this->SsProses_m->addpart($post);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Data Sparepart Berhasil Ditambahkan');
		}
		redirect($_SERVER['HTTP_REFERER']);
	}

	public function editpart()
	{
		$post = $this->input->post(null, TRUE);
		$this->SsProses_m->editpart($post);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Pemsangan 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']);
	}
}
