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

class Approve extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        //if (isset($this->session->id_user) == false) {
        //    redirect(base_url('Auth'));
        //}
        //$this->load->model('M_Lpbj');
    }

/*
    public function online_approve()
    {
        $key_lpbj = $this->input->get('key');
        $data = $this->db->get_where("tb_apprv", ["token" => $key_lpbj]);
        $dataaprv = $this->db->get_where("tb_apprv", ["token" => $key_lpbj])->row_array();
        if ($data->num_rows() > 0) {
            if ($dataaprv['apprv_sts'] == 1) {
                $key = $this->input->get("key");
                $lpbj = $this->db->get_where("tb_apprv", ['token' => $key])->row_array();
                $cr_lpbj = $this->db->get_where("lpbj_h", ['kd_lpbj' => $lpbj['kd_lpbj']])->row_array();
                $lokasi = $this->session->strKdLokasi;
                $this->db->select('ID, strNmDept');
                $dept = $this->db->get_where('tpc_dept', ["stsAktif" => 1, "strKdLokasi" => $lokasi])->result_array();
                $this->db->select('strDeskripsi, strKdItem');
                $databrg = $this->db->get('item')->result_array();

                $datauser = $this->M_Lpbj->get_user($cr_lpbj['cr_id']);

                $datadetail = $this->M_Lpbj->lpbj_list_aprv($key);

                $this->load->view(
                    'online_approve',
                    [
                        "nmrlpbj" => $lpbj,
                        "brg" => $databrg,
                        "dept" => $dept,
                        "datauser" => $datauser,
                        "key" => $key,
                        "data" => $datadetail
                    ]
                );
            } else {
                echo "LPBJ ini sudah diapprove";
            }
        } else {
            $this->load->view('error_404');
        }
    }

*/

    public function online_void_lot()
    {
        $token = $this->input->get('key');
        $cari = $this->db->get_where('tb_void_lot', ["token" => $token,"sts" => 1]);
        if ($cari->num_rows() > 0) {
            $data = array(
                'sts' => 2,
                'aprv_date' => date('Y-m-d H:i:s')
            );
            $this->db->where('token', $token);
            $this->db->update('tb_void_lot', $data);
            $this->load->view('void_konfirmasi');
        }

        if ($cari->num_rows() == 0) {
            $this->load->view('error_404');
        }
    }
}
