<?php

class Brpt_rekapbcp_mdl extends Base_Model {

    function __construct() {

        parent::__construct();
		
		$this->usr = $this->session->userdata('username');
		$this->nm_cmpy = $this->session->userdata('nm_cmpy');
    }

	function getAll($dtdari='',$dtsampai=''){
		$result = array();	
				
		$wh = "";
		if($dtdari != '' && $dtsampai != ''):
			$wh = " AND TgDaf BETWEEN '".dmys2ymd($dtdari)."' AND '".dmys2ymd($dtsampai)."' ";
		endif;

		$q = "SELECT 
				(SELECT COUNT(*) FROM mat_inchdr_sub WHERE KdJnsDok='1' $wh) AS jml1,
				(SELECT COUNT(*) FROM mat_inchdr_sub WHERE KdJnsDok='6' $wh) AS jml2,
				(SELECT COUNT(*) FROM mat_inchdr_sub WHERE KdJnsDok='6' $wh) AS jml3,
				(SELECT COUNT(*) FROM mat_inchdr_sub WHERE KdJnsDok='5' $wh) AS jml4,
				(SELECT COUNT(*) FROM mat_inchdr_sub WHERE KdJnsDok='5' $wh) AS jml5,
				(SELECT COUNT(*) FROM mat_inchdr_sub WHERE KdJnsDok='6' $wh) AS jml6,
				(SELECT COUNT(*) FROM mat_inchdr_sub WHERE KdJnsDok='6' $wh) AS jml7,
				(SELECT COUNT(*) FROM mat_inchdr_sub WHERE KdJnsDok='2' $wh) AS jml8,
				(SELECT COUNT(*) FROM mat_inchdr_sub WHERE KdJnsDok='8' $wh) AS jml9,
				(SELECT COUNT(*) FROM mat_outhdr_sub WHERE KdJnsDok='7' $wh) AS jml10,
				(SELECT COUNT(*) FROM mat_outhdr_sub WHERE KdJnsDok='7' $wh) AS jml11,
				(SELECT COUNT(*) FROM mat_outhdr_sub WHERE KdJnsDok='6' $wh) AS jml12,
				(SELECT COUNT(*) FROM mat_outhdr_sub WHERE KdJnsDok='4' $wh) AS jml13,
				(SELECT COUNT(*) FROM mat_outhdr_sub WHERE KdJnsDok='4' $wh) AS jml14,
				(SELECT COUNT(*) FROM mat_outhdr_sub WHERE KdJnsDok='6' $wh) AS jml15,
				(SELECT COUNT(*) FROM mat_outhdr_sub WHERE KdJnsDok='6' $wh) AS jml16,
				(SELECT COUNT(*) FROM mat_outhdr_sub WHERE KdJnsDok='3' $wh) AS jml17,
				(SELECT COUNT(*) FROM mat_outhdr_sub WHERE KdJnsDok='9' $wh) AS jml18,
				(SELECT FORMAT(IFNULL(SUM(qty*price),0),2) FROM mat_outhdr_sub a RIGHT JOIN mat_outdet_sub b ON b.matout_id=a.matout_id WHERE KdJnsDok='3' $wh) AS jml24
			FROM DUAL 
		";
		$rs = $this->db->query($q)->result_array();
		$rs[0]['c_name'] = $this->nm_cmpy;

		return $rs;
	}
	
}