<?
	header("Content-Type: text/html; charset=utf-8");
	
	$g_path = '../../my/';
	
	include $g_path."u_globals.php";
	include $g_path."html/f.php";
	include $g_path."u_spoj_na_bazu.php";
	
	include $g_path."u_headers.php";
	
	
	if($_GET['type'] == 'Annulments' || $_GET['type'] == 'Returns' || $_GET['type'] == 'Transfers'){
		
		$x = get_data('select price_buy, price_sell, tax_group_id, feedback_compensation from articles where id = "'.$_GET['value'].'" ', 0);
	
	}else{
		
		$l_has_primka = get_item('select count(*) as zbr from receivings where type = 0 ');
		
		if($l_has_primka == 0){
			// prva primka u godini
			
			//$x = get_data('select tax_group_id, feedback_compensation from articles where id = "'.$_GET['value'].'" ', 0);
			//$x['price_buy'] = '0.01';
			//$x['price_sell'] = '0.03';
			
			$x = get_data('select price_buy, price_sell, tax_group_id, feedback_compensation from articles where id = "'.$_GET['value'].'" ', 0);
				
		}else{
			// vec ima upisanih primki
			
			// ako ima primki ove godine, NC uzmi iz zadnje primke... a PC uzmi iz articles tablice
			
			$z = get_data('select receiving_items.price_buy, receiving_items.price_sell '.
				' from receivings, receiving_items '.
				' where receivings.id = receiving_items.receiving_id '.
				' and receivings.type = 0 '.
				' and receiving_items.article_id = '.$_GET['value'].' '.
				' order by receiving_items.id desc '.
				' limit 1 ', 0);
			
			if(isset($z['price_buy']) && isset($z['price_sell'])){
				// ima ih u ranijim primkama pa ga dohvati odatle
				
				$x = get_data('select price_sell, tax_group_id, feedback_compensation from articles where id = "'.$_GET['value'].'" ', 0);
				$x['price_buy'] = $z['price_buy'];
				//$x['price_sell'] = $z['price_sell'];
				
			}else{
				// nema ih u ranijim primkama pa ga dohvati iz articles
				
				$x = get_data('select price_buy, price_sell, tax_group_id, feedback_compensation from articles where id = "'.$_GET['value'].'" ', 0);
				
			}
			
		}
		
	}
	
	
	
	
	
	
	
	
	$y = get_item('select value from settings where name = "duty.free" ');
	if($y == 'yes'){
		$l_pdv = get_item('select tax_1 from tax_groups where id = "'.$x['tax_group_id'].'" ');
	}else{
		$l_pdv = 0;
	}
	
	
	
	$la_data[0] = $x['price_buy'];
	$la_data[1] = $x['price_sell'];
	$la_data[2] = '0';
	$la_data[3] = $l_pdv;
	$la_data[4] = $x['feedback_compensation'];
	
	$la_json = json_encode($la_data);
	print $la_json;
?>
