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

class M_purchase extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function tb_pr()
    {
        $id = $this->session->id_user;
        return $this->db->query("SELECT distinct
        A.kd_lpbj,date_format(B.tgl_lpbj,'%d %b %Y') as tgl,B.tgl_lpbj,B.unit,C.FullName as req
        FROM tb_pr A
        Left join lpbj_h B on B.kd_lpbj = A.kd_lpbj
        Left join employee C on C.emp_id = B.cr_id
        where A.sts_purchase is null and B.unit in(select fc from tb_emp_unit where emp_id = '$id');")->result_array();
    }

    public function tb_pr_dtl($kd)
    {
        $id = $this->session->id_user;
        return $this->db->query("SELECT 
        A.doc_id,
        A.kd_lpbj,
        A.kd_brg,
        B.brg,
        A.qty_req_pr,
        A.uom,
        C.strNmDept as dept,
        A.stok,
        A.keterangan,
        date_format(A.tgl,'%d %b %Y') as tgl,
        A.keterangan_purchase
        FROM tb_pr A
        left join tb_brg B on B.kd_brg = A.kd_brg
        left join tpc_dept C on C.ID = A.dept
        left join lpbj_h D on D.kd_lpbj = A.kd_lpbj
        where A.sts = 2 And A.kd_lpbj = '$kd' And A.sts_purchase is null
        and D.unit in(select fc from tb_emp_unit where emp_id = '$id');")->result_array();
    }
}
