<?php
//$fiyat_1	==>	kdvli pb1
//$fiyat_2	==>	kdvli pb2
//$fiyat_3	==>	kdvli kursuz
//$fiyat1	==>	kdvsiz pb1
//$fiyat2	==>	kdvsiz pb2
//$fiyat3	==>	kdvsiz kursuz
if($id2<>""){$id=$id2;}else{$id=$id;}
if($ppb==""){$ppb=$rsu["t2"];}
if($tax==""){ $tax=$rsu["s4"]; }
if($_REQUEST["Rb_ID"]<>""){$Rb_ID=$_REQUEST["Rb_ID"];}elseif($sayfa3<>""){$Rb_ID=$sayfa3;}
if($_SESSION["User_Discount"]<>""){ $discount=$_SESSION["User_Discount"]; }elseif($discount==""){ $discount=0; }
if($_SESSION["User_Commission"]<>""){ $commission=$_SESSION["User_Commission"]; }else{ $commission=0; }

$varyasyonlar = json_decode($rsu["n19"], true);
if (is_array($varyasyonlar) && count($varyasyonlar) > 0) {
    $varyasyon = "var";
} else {
    $varyasyon = "yok";
}


if(($sayfa4<>"" or $Rb_ID<>"")){
	////////////////Varyasyon\\\\\\\\\\\\\\\
	$rsv = null;

	if($Rb_ID<>""){
		$seciliVaryant = $Rb_ID;
	}else{
		$seciliVaryant = $sayfa4;
	}

	if(is_array($varyasyonlar) && $seciliVaryant<>""){
		foreach($varyasyonlar as $v){
			if($v["id"] == $seciliVaryant){
				$rsv = $v;
				break;
			}
		}
	}

	$rb_id = $rsv["id"] ?? 0;
	if(!empty($rsv["t2"])){
		$rb = "{".$rsv["t1"]."} {".$rsv["t2"]."}";
	}else{
		$rb = "{".$rsv["t1"]."}";
	}
	$rbd = $rsv["stok"] ?? 0;
	////////////////Varyasyon\\\\\\\\\\\\\\\


	$pb1 = string_to_float($rsv["pb1"]);
    $pb2 = string_to_float($rsv["pb2"]);
	$s5=$rsv["s5"];
}else{
////////////////Ana Ürün\\\\\\\\\\\\\\\
	$pb1 = string_to_float($rsu["pb1"]);
    $pb2 = string_to_float($rsu["pb2"]);
	$s5=$rsu["s5"];
}
$stok = ($f7 == 1) ? $s5 : 9999;

if(trim($kpb)=="TRY"){			//Site Kuru TRY ise
	if($ppb=="TRY"){				//Ürün Kuru TRY ise
		$fiyat1=$pb1; $fiyat2=$pb2; $fiyat3=$pb1; $spb="TRY";
	}elseif($ppb=="USD"){			//Ürün Kuru USD ise
		$fiyat1=($pb1*$usd); $fiyat2=($pb2*$usd); $fiyat3=$pb1; $spb="TRY";
	}elseif($ppb=="EUR"){			//Ürün Kuru EUR ise
		$fiyat1=($pb1*$eur); $fiyat2=($pb2*$eur); $fiyat3=$pb1; $spb="TRY";
	}elseif($ppb=="GBP"){			//Ürün Kuru GBP ise
		$fiyat1=($pb1*$gbp); $fiyat2=($pb2*$gbp); $fiyat3=$pb1; $spb="TRY";
	}
}elseif(trim($kpb)=="USD"){				//Site Kuru USD ise
	if($ppb=="TRY"){
		$fiyat1=($pb1/$usd); $fiyat2=($pb2/$usd); $fiyat3=$pb1; $spb="USD";
	}elseif($ppb=="USD"){
		$fiyat1=$pb1; $fiyat2=$pb2; $fiyat3=$pb1; $spb="USD";
	}elseif($ppb=="EUR"){
		$fiyat1=($pb1*$eur/$usd); $fiyat2=($pb2*$eur/$usd); $fiyat3=$pb1; $spb="USD";
	}elseif($ppb=="GBP"){
		$fiyat1=($pb1*$gbp/$usd); $fiyat2=($pb2*$gbp/$usd); $fiyat3=$pb1; $spb="USD";
	}
}elseif(trim($kpb)=="EUR"){
	if($ppb=="TRY"){
		$fiyat1=($pb1/$eur); $fiyat2=($pb2/$eur); $fiyat3=$pb1; $spb="EUR";
	}elseif($ppb=="USD"){
		$fiyat1=($pb1*$usd/$eur); $fiyat2=($pb2*$usd/$eur); $fiyat3=$pb1; $spb="EUR";
	}elseif($ppb=="EUR"){
		$fiyat1=$pb1; $fiyat2=$pb2; $fiyat3=$pb1; $spb="EUR";
	}elseif($ppb=="GBP"){
		$fiyat1=($pb1*$gbp/$eur); $fiyat2=($pb2*$gbp/$eur); $fiyat3=$pb1; $spb="EUR";
	}
}elseif(trim($kpb)=="GBP"){
	if($ppb=="TRY"){
		$fiyat1=($pb1/$gbp); $fiyat2=($pb2/$gbp); $fiyat3=$pb1; $spb="GBP";
	}elseif($ppb=="USD"){
		$fiyat1=($pb1*$usd/$gbp); $fiyat2=($pb2*$usd/$gbp); $fiyat3=$pb1; $spb="GBP";
	}elseif($ppb=="EUR"){
		$fiyat1=($pb1*$eur/$gbp); $fiyat2=($pb2*$eur/$gbp); $fiyat3=$pb1; $spb="GBP";
	}elseif($ppb=="GBP"){
		$fiyat1=$pb1; $fiyat2=$pb2; $fiyat3=$pb1; $spb="GBP";
	}
}
$fkdv=(1+($tax/100));

/*
if($commission<>0){
	$fiyat_1=$fiyat_1 * $commission;
	$fiyat_2=$fiyat_2 * $commission;
	$fiyat_3=$fiyat_3 * $commission;
	$fiyat1=$fiyat1 * $commission;
	$fiyat2=$fiyat2 * $commission;
	$fiyat3=$fiyat3 * $commission;
}
*/

if($module["profit_rate"]>0){	
	$profit_rate1=((100+$module["profit_rate"])/100);
	$profit_rate2=((100+($module["profit_rate"]+($module["profit_rate"]/2)))/100);
	$fiyat_1=$rsu["pb3"] * $profit_rate1;
	$fiyat_2=$rsu["pb3"] * $profit_rate2;
	$fiyat_3=$rsu["pb3"] * $profit_rate1;
	$fiyat1=$rsu["pb3"] * $profit_rate1;
	$fiyat2=$rsu["pb3"] * $profit_rate2;
	$fiyat3=$rsu["pb3"] * $profit_rate1;
}

if($module["s11"]==0){
	$fiyat_1=$fiyat1 * $fkdv;
	$fiyat_2=$fiyat2 * $fkdv;
	$fiyat_3=$fiyat3 * $fkdv;
	$tax_calc = $fiyat_1 - $fiyat1;
	$kdv="+ Kdv";
}else{
	$fiyat_1 = $fiyat1;
	$fiyat_2 = $fiyat2;
	$fiyat_3 = $fiyat3;
	$fiyat1 = $fiyat1 / $fkdv;
	$fiyat2 = $fiyat2 / $fkdv;
	$fiyat3 = $fiyat3 / $fkdv;
	$tax_calc = $fiyat_1 - $fiyat1;
	$kdv="Kdv Dahil";
}

if($discount<>0){
	$ifiyat_1=$fiyat_1;
	$ifiyat1=$fiyat1;
	$fiyat_1=$fiyat_1 * $discount;
	$fiyat_2=$fiyat_2 * $discount;
	$fiyat_3=$fiyat_3 * $discount;
	$fiyat1=$fiyat1 * $discount;
	$fiyat2=$fiyat2 * $discount;
	$fiyat3=$fiyat3 * $discount;
}

if($module["round"]<>""){
	$fiyat_1=yuvarla($fiyat_1,$module["round"]);
	$fiyat_2=yuvarla($fiyat_2,$module["round"]);
	$fiyat_3=yuvarla($fiyat_3,$module["round"]);
	$fiyat1=yuvarla($fiyat1,$module["round"]);
	$fiyat2=yuvarla($fiyat2,$module["round"]);
	$fiyat3=yuvarla($fiyat3,$module["round"]);
}

if($module["eksi_stok"]==1){ $stok=9999; }

?>