<?php 

class Model_settings extends CI_Model {	
	
	function __construct()
     {
          parent::__construct();
     }
	 
	public function getAllActualEmployees(){
		$sql = 'SELECT zamestnanec.ID_ZAM
				FROM zamestnanec 
				WHERE zamestnanec.Status<2 AND zamestnanec.ID_ZAM>0 AND zamestnanec.ID_TYP_Z>1
				ORDER BY zamestnanec.Priezvisko';
		return $this->db->query($sql)->result();
	}	
	
	public function getSummaryReportInventories($year,$month){
		if(strlen($month)==1){
		$month="0".$month;
		}
		$sql = 'SELECT inventura.ID_INV, inventura.ID_Report FROM inventura
				WHERE inventura.Datum_zaciatku LIKE "'.$year.'-'.$month.'%" AND inventura.ID_Report>0
				ORDER BY Datum_zaciatku ASC';
	    return $this->db->query($sql)->result();
	}
	
	public function getInventoryInfo($id_inv){
		$sql = 'SELECT * FROM inventura 
				LEFT JOIN zakaznik ON zakaznik.ID_Zakaznik=inventura.ID_Zakaznika
				LEFT JOIN typ_obchodu ON zakaznik.ID_TYP_I=typ_obchodu.ID_TYP_I
				LEFT JOIN rozloha ON inventura.ID_TYP_R=rozloha.ID_TYP_R
				WHERE inventura.ID_INV='.$id_inv;
		return $this->db->query($sql)->row();
	}
	
	public function getCountVehicles($id_inv){
		$sql = 'SELECT COUNT(rezervacia.ID_REZ) AS Pocet FROM rezervacia WHERE ID_INV='.$id_inv;
		return $this->db->query($sql)->row()->Pocet;
	}
	
	public function getDriversInter($id_inv){
		$sql = 'SELECT zamestnanec.ID_ZAM, zamestnanec.Meno, zamestnanec.Priezvisko FROM rezervacia
				LEFT JOIN zamestnanec ON rezervacia.ID_SOF=zamestnanec.ID_ZAM
				WHERE rezervacia.ID_INV='.$id_inv.' AND rezervacia.ID_SOF>0';
		return $this->db->query($sql)->result();	
	}
	
	public function getDriversExter($id_inv){
		$sql = 'SELECT zamestnanec.ID_ZAM, zamestnanec.Meno, zamestnanec.Priezvisko FROM rezervacia
				LEFT JOIN zamestnanec ON rezervacia.ID_SOF=zamestnanec.ID_ZAM
				WHERE rezervacia.ID_INV='.$id_inv.' AND rezervacia.ID_SOF=0';
		return $this->db->query($sql)->result();	
	}
	
	public function getInvrentoryLead($id_inv){
		$sql = 'SELECT zamestnanec.ID_ZAM, zamestnanec.Meno, zamestnanec.Priezvisko, zamestnanec.Email, zamestnanec.Tel_cislo_zamestnanca FROM inventura 
				LEFT JOIN zamestnanec ON zamestnanec.ID_ZAM=inventura.ID_Veduci
				WHERE inventura.ID_INV='.$id_inv;
		return $this->db->query($sql)->row();
	}
	
	public function getEmployees($id_inv){
		$sql = 'SELECT * FROM cesty
				LEFT JOIN rezervacia ON cesty.ID_REZ=rezervacia.ID_REZ
				LEFT JOIN vozidlo ON rezervacia.ID_VOZ=vozidlo.ID_VOZ
				LEFT JOIN zamestnanec ON cesty.ID_ZAM=zamestnanec.ID_ZAM
				WHERE rezervacia.ID_INV='.$id_inv.'
				ORDER BY zamestnanec.Priezvisko';
		return $this->db->query($sql)->result();
	}
	
	public function getReportTimes($id_ved,$id_rep){
		$sql = 'SELECT report_zoznam.Nastup, report_zoznam.Koniec FROM report_zoznam WHERE report_zoznam.ID_ZAM='.$id_ved.' AND report_zoznam.ID_REP='.$id_rep;
		return $this->db->query($sql)->row();
	}
	
	public function getInventorzVehicles($id_inv){
		$sql = 'SELECT * FROM rezervacia 
				LEFT JOIN vozidlo ON rezervacia.ID_VOZ=vozidlo.ID_VOZ
				WHERE rezervacia.ID_INV='.$id_inv;
		return $this->db->query($sql)->result();	
	}
	
	public function getSalaryEmployee($id_zam, $id_rep){
		$sql = 'SELECT Vyplatene FROM report_zoznam WHERE ID_REP='.$id_rep.' AND ID_ZAM='.$id_zam;
		return $this->db->query($sql)->row()->Vyplatene;
	}
}