<?php 

class Model_pay_check extends CI_Model {	

	public function getOnlySalaryGrossPayCheck($id_emp, $year, $month){
		$sql = 'SELECT Vyplatene FROM report_zoznam WHERE ID_ZAM='.$id_emp.' AND Vyplatene>0 AND ID_REP IS NOT NULL AND Koniec LIKE "'.$year.'-'.$month.'%"';
		$query = $this->db->query($sql)->result();
		$salary=0;
		foreach($query as $q){
			$salary+=$q->Vyplatene;	
		}
		return $salary;
	}	
	
	public function getTotalPenaltyPayCheck($id_emp, $year, $month){
		$sql = 'SELECT Vyplatene FROM report_zoznam WHERE ID_ZAM='.$id_emp.' AND Vyplatene<0 AND ID_REP IS NULL AND Koniec LIKE "'.$year.'-'.$month.'%"';
		$query = $this->db->query($sql)->result();
		$salary=0;
		foreach($query as $q){
			$salary+=$q->Vyplatene;	
		}
		return $salary;
	}
	
	public function getAllMyInventoriesPerMonth($id_emp, $year, $month){
		$sql = 'SELECT inventura.ID_INV, zakaznik.Nazov_spolocnosti, zakaznik.Mesto, inventura.Datum_zaciatku, report_zoznam.Vyplatene 
				FROM report_zoznam
				LEFT JOIN inventura ON inventura.ID_Report=report_zoznam.ID_REP
				LEFT JOIN zakaznik ON zakaznik.ID_Zakaznik=inventura.ID_Zakaznika
				WHERE report_zoznam.ID_ZAM='.$id_emp.' AND ID_REP IS NOT NULL AND Vyplatene>0 AND Koniec LIKE "'.$year.'-'.$month.'%"
				ORDER BY inventura.Datum_zaciatku ASC';
		return $this->db->query($sql)->result();
	}
	
	public function getAllMyInventoriesPenaltiesPerMonth($id_emp, $year, $month){
		$sql = 'SELECT report_zoznam.Koniec, report_zoznam.Vyplatene 
				FROM report_zoznam
				WHERE report_zoznam.ID_ZAM='.$id_emp.' AND ID_REP IS NULL AND Vyplatene<0 AND Koniec LIKE "'.$year.'-'.$month.'%"';
		return $this->db->query($sql)->result();	
	}
	
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	 
}