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

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

    public function tb_scan_out($tgl)
    {
        return $this->db->query("SELECT C.barang,COUNT(A.no_lot) AS qty_out
        FROM tb_scan_out A
        LEFT JOIN (SELECT kode_fg,sku FROM tb_fg_gudang) B ON B.kode_fg = A.no_lot 
        LEFT JOIN (SELECT sku,barang FROM tb_fg) C ON C.sku = B.sku
        WHERE DATE(A.scan_time) = '$tgl' AND A.gudang_asal = 2
        GROUP BY C.barang;")->result_array();
    }

    public function tb_scan_in($tgl)
    {
        return $this->db->query("SELECT C.barang,COUNT(A.no_lot) AS qty_out
        FROM tb_scan_mutasi A
        LEFT JOIN (SELECT kode_fg,sku FROM tb_fg_gudang) B ON B.kode_fg = A.no_lot 
        LEFT JOIN (SELECT sku,barang FROM tb_fg) C ON C.sku = B.sku
        WHERE DATE(A.scan_time) = '$tgl' AND A.gudang_asal = 2
        GROUP BY C.barang;")->result_array();
    }

    public function stok_gempol()
    {
        return $this->db->query("SELECT A.sku,B.barang,COUNT(A.kode_fg) AS stok
        FROM tb_fg_gudang A
        LEFT JOIN tb_fg B ON B.sku = A.sku
        WHERE A.tgl_kirim IS NULL AND A.id_gudang = 2
        GROUP BY A.sku,B.barang;")->result_array();
    }

    public function get_sopir()
    {
        return $this->db->query("SELECT A.emp_id,A.FullName AS sopir
        FROM employee A
        LEFT JOIN tb_emp_unit B ON B.emp_id = A.emp_id
        WHERE A.strJobPosition = 'SOPIR' 
        AND A.stsAktif = '1' AND B.unit = 'GP';")->result_array();
    }

}
