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

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

    public function tb_lotfg($mulai, $hingga)
    {
        return $this->db->query("SELECT A.id,A.shift,A.tgl,date_format(A.tgl,'%d %b %Y') as tanggal,A.kd_mesin,C.mesin,A.nomor,A.sku,B.barang,
        date_format(E.tgl_transfer,'%d %b %Y') as tgl_transfer,ifnull(D.cari_gudang,0) as cari_gudang,E.doc_tf
        FROM tb_lot A 
        Left join tb_fg B on B.sku = A.sku
        Left join tb_mesin C on C.kd_mesin = A.kd_mesin
        Left join(select id_produksi,count(id_produksi) as cari_gudang from tb_fg_gudang group by id_produksi)D on D.id_produksi = A.id 
        Left Join(select distinct id_produksi,tgl_transfer,doc_tf  from tb_fg_gudang)E on E.id_produksi = A.id
        where A.tgl between '$mulai' and '$hingga'
        order by A.tgl,A.shift;")->result_array();
    }

    public function cetaklot($id)
    {
        return $this->db->query("call nomer_lot($id);")->result_array();
    }
}
