<script>
	
	function isCorrectFile(a,b){
	var	path = document.getElementById('fileUpload').value;
		path = path.split('.');
		fileType = '.'+path[path.length-1];
		fileName = path[path.length-2].split("\\");
		fileName = fileName[fileName.length-1];
	if(fileType!='.xls'){
		document.getElementById('button_div').innerHTML = '<a href="http://martinbendik.studenthosting.sk/lead_employee/getInventories/4" class="button" style="margin-right:45px">Späť</a>Vyberte prosím <b>Excel</b> súbor s príponou <b>.xls</b> !';	
	}else if(fileName!=(a+'_'+b)){
		document.getElementById('button_div').innerHTML = '<a href="http://martinbendik.studenthosting.sk/lead_employee/getInventories/4" class="button" style="margin-right:45px">Späť</a>Vyberte prosím správny názov súboru.';			
	}else{
		document.getElementById('button_div').innerHTML = '<a href="http://martinbendik.studenthosting.sk/lead_employee/getInventories/4" class="button">Späť</a><input type="submit" value="Nahrať" class="button"><input type="text" name="fileName" value="'+fileName+'.xls" hidden>';	
	} 	
}
function checkInventoryStart(){ 
	if((document.getElementsByName("reportDatumZaciatok0")[0].value.length==10)&&(document.getElementsByName("reportHodinyZaciatok0")[0].value!=99)&&(document.getElementsByName("reportMinutyZaciatok0")[0].value!=99)){
		document.getElementById("statusInvStart").innerHTML="1";
		document.getElementById("checkerInvStart").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
		document.getElementById("messageInvStart").innerHTML="";		
	}else{
		document.getElementById("statusInvStart").innerHTML="0";
		document.getElementById("checkerInvStart").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
		document.getElementById("messageInvStart").innerHTML="Zle vyplnené!";
	}	
}

function checkInventoryEnd(){ 
	if((document.getElementsByName("reportDatumKoniec0")[0].value.length==10)&&(document.getElementsByName("reportHodinyKoniec0")[0].value!=99)&&(document.getElementsByName("reportMinutyKoniec0")[0].value!=99)){
		document.getElementById("statusInvEnd").innerHTML="1";
		document.getElementById("checkerInvEnd").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
		document.getElementById("messageInvEnd").innerHTML="";		
	}else{
		document.getElementById("statusInvEnd").innerHTML="0";
		document.getElementById("checkerInvEnd").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
		document.getElementById("messageInvEnd").innerHTML="Zle vyplnené!";
	}	
}

function checkLane(x){
	if((parseInt(document.getElementsByName("reportDatumZaciatok"+x)[0].value.length)==10)&&(document.getElementsByName("reportHodinyZaciatok"+x)[0].value!=99)&&(document.getElementsByName("reportMinutyZaciatok"+x)[0].value!=99)){	
		if((parseInt(document.getElementsByName("reportDatumKoniec"+x)[0].value.length)==10)&&(document.getElementsByName("reportHodinyKoniec"+x)[0].value!=99)&&(document.getElementsByName("reportMinutyKoniec"+x)[0].value!=99)){
			if((document.getElementsByName("reportHodinyPauza"+x)[0].value!=99)&&(document.getElementsByName("reportMinutyPauza"+x)[0].value!=99)){
				
				var particularStart = new Date(parseInt(document.getElementsByName("reportDatumZaciatok"+x)[0].value.substring(6,10)),parseInt(document.getElementsByName("reportDatumZaciatok"+x)[0].value.substring(3,5))-1,parseInt(document.getElementsByName("reportDatumZaciatok"+x)[0].value.substring(0,2)),parseInt(document.getElementsByName("reportHodinyZaciatok"+x)[0].value),parseInt(document.getElementsByName("reportMinutyZaciatok"+x)[0].value));
				
				var particularEnd = new Date(parseInt(document.getElementsByName("reportDatumKoniec"+x)[0].value.substring(6,10)),parseInt(document.getElementsByName("reportDatumKoniec"+x)[0].value.substring(3,5))-1,parseInt(document.getElementsByName("reportDatumKoniec"+x)[0].value.substring(0,2)),parseInt(document.getElementsByName("reportHodinyKoniec"+x)[0].value),parseInt(document.getElementsByName("reportMinutyKoniec"+x)[0].value));
				
				var PauseTime = ((parseInt(document.getElementsByName('reportHodinyPauza'+x)[0].value)*3600000)+(parseInt(document.getElementsByName('reportMinutyPauza'+x)[0].value)*60000));
				
				var inventoryStart = new Date(parseInt(document.getElementsByName("reportDatumZaciatok0")[0].value.substring(6,10)),parseInt(document.getElementsByName("reportDatumZaciatok0")[0].value.substring(3,5))-1,parseInt(document.getElementsByName("reportDatumZaciatok0")[0].value.substring(0,2)),parseInt(document.getElementsByName("reportHodinyZaciatok0")[0].value),parseInt(document.getElementsByName("reportMinutyZaciatok0")[0].value));			
				
				var inventoryEnd = new Date(parseInt(document.getElementsByName("reportDatumKoniec0")[0].value.substring(6,10)),parseInt(document.getElementsByName("reportDatumKoniec0")[0].value.substring(3,5))-1,parseInt(document.getElementsByName("reportDatumKoniec0")[0].value.substring(0,2)),parseInt(document.getElementsByName("reportHodinyKoniec0")[0].value),parseInt(document.getElementsByName("reportMinutyKoniec0")[0].value));
				
				
					if((inventoryStart.getTime())>(particularStart.getTime())){
						document.getElementById("status"+x).innerHTML="0";
						document.getElementById("checker"+x).innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
						document.getElementById("message"+x).innerHTML="Prišiel pred inventúrou?";		
					}else{
						if((inventoryEnd.getTime())<(particularEnd.getTime())){
							document.getElementById("status"+x).innerHTML="0";
							document.getElementById("checker"+x).innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
							document.getElementById("message"+x).innerHTML="Odišiel po inventúre?";	
						}else{
							if(((particularEnd.getTime())-(particularStart.getTime())<0)){
								document.getElementById("status"+x).innerHTML="0";
								document.getElementById("checker"+x).innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
								document.getElementById("message"+x).innerHTML="Odišiel pred tým ako prišiel?";		
							}else{
								if((particularEnd.getTime())-(particularStart.getTime())<10800000){
									if((particularEnd.getTime())-(particularStart.getTime())==0){
										document.getElementById("status"+x).innerHTML="1";
										document.getElementById("checker"+x).innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/Exclamation.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
										document.getElementById("message"+x).innerHTML="Storno";
										document.getElementsByName("reportHodinyPauza"+x)[0].value="00";
										document.getElementsByName("reportMinutyPauza"+x)[0].value="00";	
									}else{
										document.getElementById("status"+x).innerHTML="0";
										document.getElementById("checker"+x).innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
										document.getElementById("message"+x).innerHTML="Garancia 3 hodín!";	
									}										
								}else{
									if((particularEnd.getTime())-(particularStart.getTime())<PauseTime){
										document.getElementById("status"+x).innerHTML="0";
										document.getElementById("checker"+x).innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
										document.getElementById("message"+x).innerHTML="Viac odpočíval ako pracoval?";	
									}else{							
										document.getElementById("status"+x).innerHTML="1";
										document.getElementById("checker"+x).innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/yes.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
										document.getElementById("message"+x).innerHTML="";						
									}
								}	
							}									
						}				
					}
							
										
			}else{
				document.getElementById("status"+x).innerHTML="0";
				document.getElementById("checker"+x).innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'	>";
				document.getElementById("message"+x).innerHTML="Zle pauza!";	
			}				
		}else{
			document.getElementById("status"+x).innerHTML="0";
			document.getElementById("checker"+x).innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'	>";
			document.getElementById("message"+x).innerHTML="Zle koniec!";				
		}		
	}else{
		document.getElementById("status"+x).innerHTML="0";
		document.getElementById("checker"+x).innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'	>";
		document.getElementById("message"+x).innerHTML="Zle nástup!";
	}	
}

function checkComparedTimes(){
	if((document.getElementById("statusInvStart").innerHTML=="1")&&(document.getElementById("statusInvStart").innerHTML=="1")){
		var inventoryStart = new Date(parseInt(document.getElementsByName("reportDatumZaciatok0")[0].value.substring(6,10)),parseInt(document.getElementsByName("reportDatumZaciatok0")[0].value.substring(3,5))-1,parseInt(document.getElementsByName("reportDatumZaciatok0")[0].value.substring(0,2)),parseInt(document.getElementsByName("reportHodinyZaciatok0")[0].value),parseInt(document.getElementsByName("reportMinutyZaciatok0")[0].value));			
				
		var inventoryEnd = new Date(parseInt(document.getElementsByName("reportDatumKoniec0")[0].value.substring(6,10)),parseInt(document.getElementsByName("reportDatumKoniec0")[0].value.substring(3,5))-1,parseInt(document.getElementsByName("reportDatumKoniec0")[0].value.substring(0,2)),parseInt(document.getElementsByName("reportHodinyKoniec0")[0].value),parseInt(document.getElementsByName("reportMinutyKoniec0")[0].value));
	
		if ((inventoryEnd.getTime()-inventoryStart.getTime())<0){
			document.getElementById("statusInvStart").innerHTML="0";
			document.getElementById("checkerInvStart").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
			document.getElementById("messageInvStart").innerHTML="Príchod skôr";
			document.getElementById("statusInvEnd").innerHTML="0";
			document.getElementById("checkerInvEnd").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
			document.getElementById("messageInvEnd").innerHTML="ako odchod!";		
		}else if ((inventoryEnd.getTime()-inventoryStart.getTime())<10800000){
			document.getElementById("statusInvStart").innerHTML="0";
			document.getElementById("checkerInvStart").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
			document.getElementById("messageInvStart").innerHTML="Garancia 3 hodín!";
			document.getElementById("statusInvEnd").innerHTML="0";
			document.getElementById("checkerInvEnd").innerHTML="<img src='http://martinbendik.studenthosting.sk/pictures/no.png' height='17' width='17' align='middle' style='padding-top:0px; margin-bottom:3px'>";
			document.getElementById("messageInvEnd").innerHTML="Garancia 3 hodín!";	
		}					
	}
}

function checkHeader(){
	checkInventoryStart();
	checkInventoryEnd();
	checkComparedTimes();		
}

function checkEmployees(){
	
	var allEmp = parseInt(document.getElementById("countAll").innerHTML);
	var max = allEmp+1;
	var status = 0;
	for (i=1; i<max; i++){
		checkLane(i);	
	}
			
}

function myConfirmation(){
	document.getElementById('div_conf').innerHTML = '<a href="http://martinbendik.studenthosting.sk/lead_employee/getInventories/4" class="button">Späť</a><input type="submit" value="Uložiť" class="button">';
}

function checkFinallyAllStatus(){

	if((document.getElementById("statusInvStart").innerHTML=="1")&&(document.getElementById("statusInvEnd").innerHTML=="1")){
		(document.getElementById("headerStatus").innerHTML="1");	
	}else{
		(document.getElementById("headerStatus").innerHTML="0");	
	}

	if(document.getElementById("headerStatus").innerHTML=="1"){
		document.getElementById("reportEmployees").style.visibility = "visible";
	}else{
		document.getElementById("reportEmployees").style.visibility = "hidden";	
	}
	
	var allEmp = parseInt(document.getElementById("countAll").innerHTML);
	var max = allEmp+1;
	var status = 0;
	for (i=1; i<max; i++){
		if(document.getElementById('status'+i).innerHTML=="1"){
			status=status+1;	
		}
	}	
	if (status==allEmp){	
		(document.getElementById("bodyStatus").innerHTML="1");	
	}else{
		(document.getElementById("bodyStatus").innerHTML="0");
	}	
	
	if((document.getElementById("headerStatus").innerHTML=="1")&&(document.getElementById("bodyStatus").innerHTML=="1")){
		if(document.getElementById('statusConfirmation').innerHTML=="0"){
			document.getElementById('div_conf').innerHTML = '<a href="http://martinbendik.studenthosting.sk/lead_employee/getInventories/4" class="button">Späť</a><input type="checkbox" id="checkbox_conf" onchange="myConfirmation()" style="margin-left:25px;margin-top:6px">Súhlasím, že všetky údaje som skontroloval a zadal správne a že beriem zodpovednosť za prípadné vzniknuté škody!<br>';
			document.getElementById('statusConfirmation').innerHTML="1";		
		}		
	} else {
		document.getElementById('div_conf').innerHTML = '<a href="http://martinbendik.studenthosting.sk/lead_employee/getInventories/4" class="button">Späť</a>';
		document.getElementById('statusConfirmation').innerHTML="0";
	}				
}
function checkingFunction(){
	checkHeader();
	checkEmployees();	
	checkFinallyAllStatus();	
}
	
document.addEventListener("click", function(){
	checkingFunction();		
});
$(document).ready(function() {checkingFunction();});


</script>
<?php
	if ($this->session->userdata('permisson')==2) {
		$CI =& get_instance();
		$CI->load->library('libraryprofile');
		$CI->libraryprofile->showMenuBarLeadEmployee($this->session->userdata('meno'),$this->session->userdata('priezvisko'),$this->session->userdata('id_zamestnanca'));
		$options2 = array('99' => '','00'  => '00','01'  => '01','02'  => '02','03'  => '03','04'  => '04','05'  => '05','06'  => '06','07'  => '07','08'  => '08','09'  => '09','10'  => '10','11'  => '11','12'  => '12','13'  => '13','14'  => '14','15'  => '15','16'  => '16','17'  => '17','18'  => '18','19'  => '19','20'  => '20','21'  => '21','22'  => '22','23'  => '23');
			$options3 = array('99' => '',
                  			'00'  => '00',
                  			'05'  => '05',
                  			'10'  => '10',
                  			'15'  => '15',
							'20'  => '20',
							'25'  => '25',
							'30'  => '30',
                  			'35'  => '35',
                  			'40'  => '40',
                  			'45'  => '45',
							'50'  => '50',
							'55'  => '55',							  
                );
				
		$this->load->helper('lead_employee_helper');
		$this->load->helper('date');
		$inventoryInfo = getReportInventory($id_inv);
		
		echo '<div id="default_container">';
			echo '<div class="button-group" style="margin-left:50px;margin-top:10px" name="pokus">';
			if ($mode==1){
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////AUTOMATICKE VLOZENIE////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				echo '<a href="'.base_url('lead_employee/redirectAddReport/1/1/'.$id_inv).'" class="button active">Automatické naplnenie</a>';
				echo '<a href="'.base_url('lead_employee/redirectAddReport/1/2/'.$id_inv).'" class="button">Ručné vloženie</a>';
				echo '</div>';
				if ($error!=''){
					echo '<p id="report_error">'.$error."</p>";		
				} 				
				echo form_open_multipart(base_url('lead_employee/createNewReportAuto/'.$id_inv));
				echo '<input type="file" name="fileUpload" id="fileUpload" onChange="isCorrectFile('.$id_inv.',\''.$inventoryInfo->Mesto.'\')" class="inputfile" style="margin-left:50px; margin-top:10px">'; 				
				echo '</br>';	
				echo '<div class="button-group" id="button_div" style="margin-left:50px;margin-top:15px">';		
				echo '<a href="'.base_url('lead_employee/getInventories/4').'" class="button">Späť</a>';
				echo '</div>';
				echo form_close();
			} elseif ($mode==2 AND $auto==FALSE) {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////RUCNE VLOZENIE///////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			echo '<a href="'.base_url('lead_employee/redirectAddReport/1/1/'.$id_inv).'" class="button">Automatické naplnenie</a>';
			echo '<a href="'.base_url('lead_employee/redirectAddReport/1/2/'.$id_inv).'" class="button active">Ručné vloženie</a>';			
			echo '</div>';
			
			echo '<p style="float:right; margin-right:160px; margin-top:15px; color:red" id="reportError"></p>';
						
			$count = 1; 
			$countAll = 1;
			$inventoryDrivers =  getReportDrivers($inventoryInfo->ID_INV);
			
			$inventoryEmployees = getReportEmployees($inventoryInfo->ID_INV,$inventoryInfo->ID_Veduci);
			$countEmp = count($inventoryDrivers)+count($inventoryEmployees);
			foreach($inventoryDrivers as $inventoryDriver){
				if($inventoryDriver->ID_SOF==0){
					$countEmp=$countEmp-1;	
				}
			}	
			echo form_open(base_url('lead_employee/createNewReport'));	
//INVENTURA
			echo form_input("id_inv_hidden", $id_inv,'hidden');
				echo "<p id='countAll' hidden>".$countEmp."</p>";
				echo "<div id='headerStatus' hidden>0</div>";
				echo "<div id='bodyStatus' hidden>0</div>";
				echo "<div id='statusConfirmation' hidden>0</div>";
			echo '<div class="div_curve">';
				echo "<table style='margin-left:50px'>";
					echo "<tr>";
						echo "<td style='width:250px;'>";
							echo "<b id='kua'>Identifikačné číslo inventúry: </b>";
						echo "</td>";
						echo "<td style='padding-right:200px'>";
							if (strlen($id_inv)==1) {
								echo "0000";
								echo $id_inv;
							} elseif (strlen($id_inv)==2) {
								echo "000";
								echo $id_inv;
							} elseif (strlen($id_inv)==3) {
								echo "00";
								echo $id_inv;
							} elseif (strlen($id_inv)==4) {
								echo "0";
								echo $id_inv;
							} else {
								echo $id_inv;
							}
						echo "</td>";
						echo "<td style='width:200px'>";
							echo "<b>Vedúci inventúry: </b>";
						echo "</td>";
						echo "<td>";
							echo $inventoryInfo->Meno.' '.$inventoryInfo->Priezvisko;
						echo "</td>";
					echo "</tr>";
					echo "<tr>";
						echo "<td>";
							echo "<b>Zákazník: </b>";
						echo "</td>";						
						echo "<td>";
							echo $inventoryInfo->Nazov_spolocnosti;
						echo "</td>";
						echo "<td>";
							echo "<b>Dátum a čas príchodu: </b>";
						echo "</td>";
						echo "<td>";
							$dateStart=strtotime($inventoryInfo->Datum_zaciatku);
							$hoursDrive=intval(date('G',strtotime($inventoryInfo->Cas_cesty)));
							$minutesDrive=intval(date('i',strtotime($inventoryInfo->Cas_cesty)));
							$timeDrive=($hoursDrive*3600)+($minutesDrive*60);
							$startDate=$dateStart+$timeDrive;				
							echo '<input type="text" name="reportDatumZaciatok0"  id="calendar" alt="date" class="IP_calendar" title="d.m.Y" value="'.date('d.m.Y',$startDate).'">';										
							echo form_dropdown('reportHodinyZaciatok0', $options2, date('G',$startDate) , 'id="hodiny"' );
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyZaciatok0', $options3, date('i',$startDate) , 'id="hodiny2"' );																
					echo "</td>";
					echo "</td>";
						echo "<td id='checkerInvStart'>";
						echo "</td>";
						echo "<td id='messageInvStart'>";
						echo "</td>";
						echo "<td>";
						echo "<p id='statusInvStart' hidden></p>";
						echo "</td>";
					echo "</tr>";
					echo "<tr>";
						echo "<td>";
							echo "<b>Adresa: </b>";
						echo "</td>";						
						echo "<td>";
							echo $inventoryInfo->Ulica.' '.$inventoryInfo->Cislo.', '.$inventoryInfo->Mesto;
						echo "</td>";
						echo "<td>";
							echo "<b>Dátum a čas odchodu: </b>";
						echo "</td>";
						echo "<td>";
							$dateEnd=strtotime($inventoryInfo->Datum_konca);
							$endDate=$dateEnd-$timeDrive;
							echo '<input type="text" name="reportDatumKoniec0" id="calendar" alt="date" class="IP_calendar" title="d.m.Y" value="'.date('d.m.Y',$endDate).'">';										
							echo form_dropdown('reportHodinyKoniec0', $options2, date('G',$endDate) , 'id="hodiny"' );
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyKoniec0', $options3, date('i',$endDate) , 'id="hodiny2"' );										
					echo "</td>";
					echo "<td id='checkerInvEnd'>";
						echo "</td>";
						echo "<td id='messageInvEnd'>";
						echo "</td>";
						echo "<td>";
						echo "<p id='statusInvEnd' hidden></p>";
						echo "</td>";
					echo "</tr>";	
				echo "</table>";
			echo "</div>";
//VSETCI ZAMESTNANCI
			echo "<div class='report_div_2' id='reportEmployees'>";
			echo "<table class='report_table'>";
				echo "<tr>";
					echo "<td style='width:50px;padding-bottom:10px'>";
						echo "<b>Por. č.</b>";
					echo "</td>";
					echo "<td style='width:60px;padding-bottom:10px'>";
						echo "<b>ID zam.</b>";
					echo "</td>";
					echo "<td style='width:100px;padding-bottom:10px'>";
						echo "<b>Priezvisko</b>";
					echo "</td>";
					echo "<td style='width:100px;padding-bottom:10px'>";
						echo "<b>Meno</b>";
					echo "</td>";
					echo "<td style='width:230px;padding-bottom:10px'>";
						echo "<b>Nástup</b>";
					echo "</td>";
					echo "<td style='width:220px;padding-bottom:10px'>";
						echo "<b>Koniec</b>";
					echo "</td>";
					echo "<td style='width:130px;padding-bottom:10px'>";
						echo "<div style='margin-left:10px'>";
						echo "<b>Prestávka</b>";
						echo "</div>";
					echo "</td>";
				echo "</tr>";
//VODICI				
			foreach($inventoryDrivers as $inventoryDriver){
				if($inventoryDriver->ID_SOF!=0){
					echo form_input("id_emp_hidden".$countAll, $inventoryDriver->ID_ZAM,'hidden');
				echo "<tr>";
					echo "<td>";
						echo "S";
					echo "</td>";
					echo "<td>";
						if (strlen($inventoryDriver->ID_ZAM)==1) {
								echo "0000";
								echo $inventoryDriver->ID_ZAM;
							} elseif (strlen($inventoryDriver->ID_ZAM)==2) {
								echo "000";
								echo $inventoryDriver->ID_ZAM;
							} elseif (strlen($inventoryDriver->ID_ZAM)==3) {
								echo "00";
								echo $inventoryDriver->ID_ZAM;
							} elseif (strlen($inventoryDriver->ID_ZAM)==4) {
								echo "0";
								echo $inventoryDriver->ID_ZAM;
							} else {
								echo $inventoryDriver->ID_ZAM;
							}
					echo "</td>";
					echo "<td>";
						echo $inventoryDriver->Priezvisko;
					echo "</td>";
					echo "<td>";
						echo $inventoryDriver->Meno;
					echo "</td>";
					echo "<td>";
						echo '<input type="text" name="reportDatumZaciatok'.$countAll.'" onchange="myCheckFunction('.$countAll.')" id="calendar" alt="date" class="IP_calendar" title="d.m.Y" value="'.date('d.m.Y',$startDate).'">';										
							echo form_dropdown('reportHodinyZaciatok'.$countAll, $options2, '' , 'id="hodiny" onchange="myCheckFunction('.$countAll.')"' );
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyZaciatok'.$countAll, $options3, '' , 'id="hodiny2" onchange="myCheckFunction('.$countAll.')"' );											
					echo "</td>";
					echo "<td>";
						echo '<input type="text" name="reportDatumKoniec'.$countAll.'" onchange="myCheckFunction('.$countAll.')" id="calendar" alt="date" class="IP_calendar" title="d.m.Y" value="'.date('d.m.Y',$endDate).'">';										
							echo form_dropdown('reportHodinyKoniec'.$countAll, $options2, '' , 'id="hodiny" onchange="myCheckFunction('.$countAll.')"' );
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyKoniec'.$countAll, $options3, '' , 'id="hodiny2" onchange="myCheckFunction('.$countAll.')"' );											
					echo "</td>";
					echo "<td>";							
							echo form_dropdown('reportHodinyPauza'.$countAll, $options2, '00', 'id="hodiny" onchange="myCheckFunction('.$countAll.')" hidden' );					
							echo form_dropdown('reportMinutyPauza'.$countAll, $options3, '00' , 'id="hodiny2" onchange="myCheckFunction('.$countAll.')" hidden' );											
					echo "</td>";
					echo "<td id='checker".$countAll."'>";
					echo "</td>";
					echo "<td id='message".$countAll."'>";
					echo "</td>";
					echo "<td>";
					echo "<p id='status".$countAll."' hidden></p>";
					echo "</td>";
				echo "</tr>";
				$countAll++;	
				} 				
			}
//ZAMESTNANCI			
			foreach($inventoryEmployees as $inventoryEmployee){
				echo form_input("id_emp_hidden".$countAll, $inventoryEmployee->ID_ZAM,'hidden');
				echo "<tr>";
					echo "<td>";
						echo $count;				
					echo "</td>";
					echo "<td>";
						if (strlen($inventoryEmployee->ID_ZAM)==1) {
								echo "0000";
								echo $inventoryEmployee->ID_ZAM;
							} elseif (strlen($inventoryEmployee->ID_ZAM)==2) {
								echo "000";
								echo $inventoryEmployee->ID_ZAM;
							} elseif (strlen($inventoryEmployee->ID_ZAM)==3) {
								echo "00";
								echo $inventoryEmployee->ID_ZAM;
							} elseif (strlen($inventoryEmployee->ID_ZAM)==4) {
								echo "0";
								echo $inventoryEmployee->ID_ZAM;
							} else {
								echo $inventoryEmployee->ID_ZAM;
							}
					echo "</td>";
					echo "<td>";
						echo $inventoryEmployee->Priezvisko;
					echo "</td>";
					echo "<td>";
						echo $inventoryEmployee->Meno;
					echo "</td>";
					echo "<td>";
						echo '<input type="text" name="reportDatumZaciatok'.$countAll.'" onchange="myCheckFunction('.$countAll.')" id="calendar" alt="date" class="IP_calendar" title="d.m.Y" value="'.date('d.m.Y',$startDate).'">';										
							echo form_dropdown('reportHodinyZaciatok'.$countAll, $options2, '' , 'id="hodiny" onchange="myCheckFunction('.$countAll.')"');
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyZaciatok'.$countAll, $options3, '' , 'id="hodiny2" onchange="myCheckFunction('.$countAll.')"');											
					echo "</td>";
					echo "<td>";
						echo '<input type="text" name="reportDatumKoniec'.$countAll.'" onchange="myCheckFunction('.$countAll.')" id="calendar" alt="date" class="IP_calendar" title="d.m.Y" value="'.date('d.m.Y',$endDate).'">';										
							echo form_dropdown('reportHodinyKoniec'.$countAll, $options2, '' , 'id="hodiny" onchange="myCheckFunction('.$countAll.')"' );
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyKoniec'.$countAll, $options3, '' , 'id="hodiny2" onchange="myCheckFunction('.$countAll.')"' );											
					echo "</td>";
					echo "<td>";							
							echo form_dropdown('reportHodinyPauza'.$countAll, $options2, '', 'id="hodiny" onchange="myCheckFunction('.$countAll.')"' );
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyPauza'.$countAll, $options3, '' , 'id="hodiny2" onchange="myCheckFunction('.$countAll.')"' );											
					echo "</td>";
					echo "<td id='checker".$countAll."' style='width:20px'>";
					echo "</td>";
					echo "<td id='message".$countAll."'>";
					echo "</td>";
					echo "<td>";
					echo "<p id='status".$countAll."' hidden></p>";
					echo "</td>";
				echo "</tr>";
				$count++;		
				$countAll++;
			}
			echo "</table>";
			echo '<textarea name="notice" class="login_textarea" onclick="myNotice()" style="margin-left:50px;margin-top:15px;width:528px;height:50px" >Poznámka</textarea>';	
			echo "</div>";
			echo "<div class='div_curve' style='margin-top:20px'>";
				echo '<div class="button-group" id="div_conf" style="margin-left:50px;margin-top:5px">';		
					echo '<a href="'.base_url('lead_employee/getInventories/4').'" class="button">Späť</a>';
					echo '</p>';
				echo '</div>';
			echo "</div>";
			echo form_close();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////AUTOMATICKE VLOZENIE - NAPLNENIE/////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////									
			} else {
				echo '<a href="'.base_url('lead_employee/redirectAddReport/1/1/'.$id_inv).'" class="button active">Automatické naplnenie</a>';
				echo '<a href="'.base_url('lead_employee/redirectAddReport/1/2/'.$id_inv).'" class="button">Ručné vloženie</a>';			
				echo '</div>';
			
				echo '<p style="float:right; margin-right:160px; margin-top:15px; color:red" id="reportError"></p>';
			
				$count = 1; 
		$countAll = 1;
		$inventoryDrivers =  getReportDrivers($inventoryInfo->ID_INV);
		
		$inventoryEmployees = getReportEmployees($inventoryInfo->ID_INV,$inventoryInfo->ID_Veduci);
		$countEmp = count($inventoryDrivers)+count($inventoryEmployees);
		foreach($inventoryDrivers as $inventoryDriver){
			if($inventoryDriver->ID_SOF==0){
				$countEmp=$countEmp-1;	
			}
		}
				echo form_open(base_url('lead_employee/createNewReport'));
				echo form_input("id_inv_hidden", $id_inv,'hidden');
				echo "<p id='countAll' hidden>".$countEmp."</p>";
				echo "<div id='headerStatus' hidden>0</div>";
				echo "<div id='bodyStatus' hidden>0</div>";
				echo "<div id='statusConfirmation' hidden>0</div>";
			echo '<div class="div_curve">';
				echo "<table style='margin-left:50px'>";
					echo "<tr>";
						echo "<td style='width:250px;'>";
							echo "<b id='kua'>Identifikačné číslo inventúry: </b>";
						echo "</td>";
						echo "<td style='padding-right:200px'>";
							if (strlen($id_inv)==1) {
								echo "0000";
								echo $id_inv;
							} elseif (strlen($id_inv)==2) {
								echo "000";
								echo $id_inv;
							} elseif (strlen($id_inv)==3) {
								echo "00";
								echo $id_inv;
							} elseif (strlen($id_inv)==4) {
								echo "0";
								echo $id_inv;
							} else {
								echo $id_inv;
							}
						echo "</td>";
						echo "<td style='width:200px'>";
							echo "<b>Vedúci inventúry: </b>";
						echo "</td>";
						echo "<td>";
							echo $inventoryInfo->Meno.' '.$inventoryInfo->Priezvisko;
						echo "</td>";
					echo "</tr>";
					echo "<tr>";
						echo "<td>";
							echo "<b>Zákazník: </b>";
						echo "</td>";						
						echo "<td>";
							echo $inventoryInfo->Nazov_spolocnosti;
						echo "</td>";
						echo "<td>";
							echo "<b>Dátum a čas príchodu: </b>";
						echo "</td>";
						echo "<td>";
						echo '<input type="text" name="reportDatumZaciatok0"  id="calendar" alt="date" class="IP_calendar" title="d.m.Y" value="'.date('d.m.Y',strtotime($inventory_start)).'">';										
							echo form_dropdown('reportHodinyZaciatok0', $options2, date('G',strtotime($inventory_start)) , 'id="hodiny"' );
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyZaciatok0', $options3, date('i',strtotime($inventory_start)) , 'id="hodiny2"' );	
							echo "</td>";
							echo "<td id='checkerInvStart'>";
							echo "</td>";
							echo "<td id='messageInvStart'>";
							echo "</td>";
							echo "<td>";
							echo "<p id='statusInvStart' hidden></p>";
							echo "</td>";
					echo "</tr>";
					echo "<tr>";
						echo "<td>";
							echo "<b>Adresa: </b>";
						echo "</td>";						
						echo "<td>";
							echo $inventoryInfo->Ulica.' '.$inventoryInfo->Cislo.', '.$inventoryInfo->Mesto;
						echo "</td>";
						echo "<td>";
							echo "<b>Dátum a čas odchodu: </b>";
						echo "</td>";
						echo "<td>";
					echo '<input type="text" name="reportDatumKoniec0" id="calendar" alt="date" class="IP_calendar" title="d.m.Y" value="'.date('d.m.Y',strtotime($inventory_end)).'">';										
							echo form_dropdown('reportHodinyKoniec0', $options2, date('G',strtotime($inventory_end)) , 'id="hodiny"' );
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyKoniec0', $options3, date('i',strtotime($inventory_end)) , 'id="hodiny2"' );										
					echo "</td>";
						echo "<td id='checkerInvEnd'>";
						echo "</td>";
						echo "<td id='messageInvEnd'>";
						echo "</td>";
						echo "<td>";
						echo "<p id='statusInvEnd' hidden></p>";
						echo "</td>";
					echo "</tr>";	
				echo "</table>";
			echo "</div>";
//VSETCI ZAMESTNANCI
			echo "<div class='report_div_2' id='reportEmployees'>";
			echo "<table class='report_table'>";
				echo "<tr>";
					echo "<td style='width:50px;padding-bottom:10px'>";
						echo "<b>Por. č.</b>";
					echo "</td>";
					echo "<td style='width:60px;padding-bottom:10px'>";
						echo "<b>ID zam.</b>";
					echo "</td>";
					echo "<td style='width:100px;padding-bottom:10px'>";
						echo "<b>Priezvisko</b>";
					echo "</td>";
					echo "<td style='width:100px;padding-bottom:10px'>";
						echo "<b>Meno</b>";
					echo "</td>";
					echo "<td style='width:230px;padding-bottom:10px'>";
						echo "<b>Nástup</b>";
					echo "</td>";
					echo "<td style='width:220px;padding-bottom:10px'>";
						echo "<b>Koniec</b>";
					echo "</td>";
					echo "<td style='width:130px;padding-bottom:10px'>";
						echo "<div style='margin-left:10px'>";
						echo "<b>Prestávka</b>";
						echo "</div>";
					echo "</td>";
				echo "</tr>";
			foreach($employees as $employee){
				if($employee["EmpID"]!=0){
					echo form_input("id_emp_hidden".$countAll, $employee['EmpID'],'hidden');
				echo "<tr>";
					echo "<td>";
						echo $employee['EmpNumber'];				
					echo "</td>";
					echo "<td>";
						echo returnStringId($employee['EmpID']);					
					echo "</td>";
					echo "<td>";
						echo $employee['EmpLastName'];
					echo "</td>";
					echo "<td>";
						echo $employee['EmpFirstName'];
					echo "</td>";
					echo "<td>";
					echo '<input type="text" name="reportDatumZaciatok'.$countAll.'" onchange="myCheckFunction('.$countAll.')" id="calendar" alt="date" class="IP_calendar" title="d.m.Y" value="'.date('d.m.Y',strtotime($employee['EmpStart'])).'">';										
							echo form_dropdown('reportHodinyZaciatok'.$countAll, $options2, date('G',strtotime($employee['EmpStart'])) , 'id="hodiny" onchange="myCheckFunction('.$countAll.')"');
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyZaciatok'.$countAll, $options3, date('i',strtotime($employee['EmpStart'])) , 'id="hodiny2" onchange="myCheckFunction('.$countAll.')"');											
					echo "</td>";
					echo "<td>";
						echo '<input type="text" name="reportDatumKoniec'.$countAll.'" onchange="myCheckFunction('.$countAll.')" id="calendar" alt="date" class="IP_calendar" title="d.m.Y" value="'.date('d.m.Y',strtotime($employee['EmpEnd'])).'">';										
							echo form_dropdown('reportHodinyKoniec'.$countAll, $options2, 	date('G',strtotime($employee['EmpEnd'])) , 'id="hodiny" onchange="myCheckFunction('.$countAll.')"' );
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyKoniec'.$countAll, $options3, date('i',strtotime($employee['EmpEnd'])) , 'id="hodiny2" onchange="myCheckFunction('.$countAll.')"' );											
					echo "</td>";
					echo "<td>";
						if(isDriver($id_inv,$employee['EmpID'])==TRUE){
							echo form_dropdown('reportHodinyPauza'.$countAll, $options2, '00', 'id="hodiny" onchange="myCheckFunction('.$countAll.')" hidden' );					
							echo form_dropdown('reportMinutyPauza'.$countAll, $options3, '00' , 'id="hodiny2" onchange="myCheckFunction('.$countAll.')" hidden' );																	
						}else{
							echo form_dropdown('reportHodinyPauza'.$countAll, $options2, date('G',strtotime($employee['EmpPause'])), 'id="hodiny" onchange="myCheckFunction('.$countAll.')"' );
							echo '&nbsp' . '<b> : </b>' . '&nbsp';						
							echo form_dropdown('reportMinutyPauza'.$countAll, $options3, date('i',strtotime($employee['EmpPause'])) , 'id="hodiny2" onchange="myCheckFunction('.$countAll.')"' );																	
						}							
				    echo "</td>";
					echo "<td id='checker".$countAll."' style='width:20px'>";
					echo "</td>";
					echo "<td id='message".$countAll."'>";
					echo "</td>";
					echo "<td>";
					echo "<p id='status".$countAll."' hidden></p>";
					echo "</td>";
				echo "</tr>";
				$countAll++;	
				}
						
				}
				echo "</table>";
			echo '<textarea name="notice" class="login_textarea" onclick="myNotice()" style="margin-left:50px;margin-top:15px;width:528px;height:50px" >Poznámka</textarea>';	
			echo "</div>";
			echo "<div class='div_curve' style='margin-top:20px'>";
				echo '<div class="button-group" id="div_conf" style="margin-left:50px;margin-top:5px">';		
					echo '<a href="'.base_url('lead_employee/getInventories/4').'" class="button">Späť</a>';
					echo '</p>';
				echo '</div>';
			echo "</div>";
			echo form_close();			
			}	
						
		echo '</div>';
	} else {
		redirect(base_url('main/restricted'));
	}	
?>

	
	
	


