<?php
	if ($this->session->userdata('permisson')==1) {		
		$CI =& get_instance();
		$CI->load->library('libraryprofile');
		$CI->libraryprofile->showMenuBarManager($this->session->userdata('meno'),$this->session->userdata('priezvisko'));
		echo '<div id="default_container">';
			echo '<div class="button-group" style="margin-left:50px;margin-top:10px;">';
switch($mode){
	case 1: 
				echo '<a href="'.base_url('manager/redirectDetailCustomer/1/'.$id_cus).'" class="button active">Všeobecné informácie</a>';							
				echo '<a href="'.base_url('manager/redirectDetailCustomer/2/'.$id_cus).'" class="button">Inventúry zákazníka</a>';												
			echo '</div>';
			
			echo "<div class='div_curve' style='height:344px'>";	
				
				echo '<div class="divForMap" style="height:250px">';
					echo $map['html'];
				echo '</div>'; 
				
						echo '<table class="detailTable"';
							echo '<tr>';
								echo '<td style="width:150px">';
									echo '<b>Identifikačné číslo:</b>';
								echo '</td>';
								echo '<td>';
									if (strlen($Customer->ID_Zakaznik)==1) {
								echo "0000";
								echo $Customer->ID_Zakaznik;
							} elseif (strlen($Customer->ID_Zakaznik)==2) {
								echo "000";
								echo $Customer->ID_Zakaznik;
							} elseif (strlen($Customer->ID_Zakaznik)==3) {
								echo "00";
								echo $Customer->ID_Zakaznik;
							} elseif (strlen($Customer->ID_Zakaznik)==4) {
								echo "0";
								echo $Customer->ID_Zakaznik;
							} else {
								echo $Customer->ID_Zakaznik;
							}
								echo '</td>';	
							echo '</tr>';							
							echo '<tr>';
								echo '<td>';
									echo '<b>Názov spoločnosti:</b>';
								echo '</td>';
								echo '<td>';
									echo $Customer->Nazov_spolocnosti;
								echo '</td>';									
							echo '</tr>';
							echo '<tr>';
								echo '<td>';
									echo '<b>Typ spolocnosti:</b>';
								echo '</td>';
								echo '<td>';
									echo $Customer->Nazov_typ_obchodu;
								echo '</td>';																	
							echo '</tr>';
							echo '<tr>';
								echo '<td>';
								echo '&nbsp';
								echo '</td>';
							echo '</tr>';
							echo '<tr>';
								echo '<td>';
									echo '<b>Kontaktná adresa:</b>';
								echo '</td>';
								echo '<td>';
									echo $Customer->Ulica." ".$Customer->Cislo;
								echo '</td>';									
							echo '</tr>';	
							echo '<tr>';
								echo '<td>';
									echo '&nbsp';
								echo '</td>';
								echo '<td>';
									echo $Customer->PSC.", ".$Customer->Mesto;
								echo '</td>';	
							echo '</tr>';
							echo '<tr>';
								echo '<td>';
								echo '&nbsp';
								echo '</td>';
							echo '</tr>';

		
							echo '<tr>';
								echo '<td>';
									echo '<b>Počet inventúr:</b>';
								echo '</td>';
								echo '<td>';
									echo $countInventories;
								echo '</td>';									
							echo '</tr>';
							echo '<tr>';
								echo '<td>';
									echo '<b>Posledná inventúra:</b>';
								echo '</td>'; 
								echo '<td>';
								if($lastInventory==Array()){
									echo "Ešete nebola vykonaná žiadna inventúra.";
								}else{
									echo date('d.m.Y', strtotime($lastInventory->Datum_zaciatku));	
								}									
								echo '</td>';									
							echo '</tr>';
						echo '</table>';						
			echo '</div>';
			echo '<div class="button-group" style="margin-left:50px;margin-top:10px">';
									echo '<a href="'. base_url() . 'manager/getAllCustomers" class="button">Späť</a>';
							echo '</div>';
			break;
					case 2: 
							echo '<a href="'.base_url('manager/redirectDetailCustomer/1/'.$id_cus).'" class="button">Všeobecné informácie</a>';							
							echo '<a href="'.base_url('manager/redirectDetailCustomer/2/'.$id_cus).'" class="button active">Inventúry zákazníka</a>';												
						echo '</div>';
		echo "<div class='vehicle_div' style='align:center; margin-top:15px; margin-bottom:5px'>";
		echo "</div>";
						
						if(count($inventories)==0){
							echo "<h3>Pre tohoto zákazníka ešte nebola vykonaná žiadna inventúra.";	
						}else{ 
							echo "<table>";
							echo "<thead style='text-align:left'>";
								echo "<th>";
								echo "</td>";
								echo "<th>";
									echo "ID inventúry";
								echo "</th>";
								echo "<th>";
									echo "Zákazník";
								echo "</th>";
								echo "<th>";
									echo "Mesto";
								echo "</th>";
								echo "<th>";
									echo "Dátum a čas začiatku";
								echo "</th>";
								echo "<th>";
									echo "Vedúci inventúry";
								echo "</th>";
							echo "</thead>";
			echo "<tbody class='zoznamTable'>";	
			echo "<tr class='nothing'>";
				echo "<td colspan='8' class='nothing'>";
				echo "<div class='vehicle_div' style='align:center; margin-top:5px; margin-bottom:5px'></div>";
				echo "</td>";
			echo "</tr>";				
										
							foreach ($inventories as $inventory) {				
								echo "<tr>";
									echo "<td width='150px'>";
									echo "</td>";				
									echo "<td width='100px'>";
										if (strlen($inventory->ID_INV)==1) {
												echo "0000";
												echo $inventory->ID_INV;
											} elseif (strlen($inventory->ID_INV)==2) {
												echo "000";
												echo $inventory->ID_INV;
											} elseif (strlen($inventory->ID_INV)==3) {
												echo "00";
												echo $inventory->ID_INV;
											} elseif (strlen($inventory->ID_INV)==4) {
												echo "0";
												echo $inventory->ID_INV;
											} else {
												echo $inventory->ID_INV;
											}
									echo "</td>";
									echo "<td width='150px'>";
										echo $inventory->Nazov_spolocnosti;
									echo "</td>";
									echo "<td  width='160px'>";
										echo $inventory->Mesto;
									echo "</td>";					
									echo "<td  width='180px'>";
										echo date ("d.m.Y G:i",strtotime($inventory->Datum_zaciatku));
									echo "</td>";
									echo "<td  width='160px'>";
										if(($inventory->Meno==NULL) OR ($inventory->Priezvisko==NULL)){
											echo "neurčené";
										} else {
											echo $inventory->Meno . ' ' .$inventory->Priezvisko;	
										}
										
									echo "</td>";
									echo "<td>";
									echo '<div class="button-group" style="margin-left:15px">';
											echo '<a href="'. base_url('manager/redirectInventoryDetail/4/1/'.$inventory->ID_INV).'" class="button" style="margin-right:138px">Detail</a>';									 
									echo '</div>';
									echo "</td>";					
								echo "</tr>";
								}												
							echo "</table>";
							echo "<div class='vehicle_div' style='align:center; margin-top:15px; margin-bottom:5px'>";
							echo "</div>";
							echo '<div class="button-group" style="margin-left:50px;margin-top:10px">';
									echo '<a href="'. base_url() . 'manager/getAllCustomers" class="button">Späť</a>';
							echo '</div>';	
						}		
			
			
				echo "</div>";		
					break;
			}	
						
			
		echo '</div>';
			
	} else {
		redirect(base_url('main/restricted'));
	}	
?>
	


