<?php
	$jso = json_decode($siparis["n11"], true);
	unset($gtoplam); unset($gcost); unset($siptop1); unset($indirim); unset($kdvbir); unset($kdvsekiz); unset($kdvonsekiz); unset($kargof); unset($vadef);
	$gcost=0;$gcost=(sprice($sepet["pb5"])*$sepet["s2"]);	//Maliyet/Alış Fiyatı

// İndirim Hesaplama
	$iprice = string_to_float($sepet["pb1"]); // İndirimsiz
	$bprice = !empty($iskonto) ? ($iprice / (($iskonto + 100) / 100)) : $iprice;

// KDV Hesaplama
	$bqty = $sepet["s2"];
	$stutar += $bprice * $bqty;
	$itutar += $bprice * $bqty;
	$kdv = $stutar * ($sepet["s4"] / 100);
	$ikdv = $itutar * ($sepet["s4"] / 100); // İndirimsiz

// Kargo ve KDV'si
	$kargof = ($siparis["pb4"] > 0) ? ($siparis["pb4"] / 1.20) : 0;
	$kargo_kdv = $siparis["pb4"] - $kargof;
	if ($siparis["pb4"] > 0) {
		$kdv += $kargo_kdv; // Kargo KDV hesaplama %18
	}

// Vade Farkı ve KDV'si
	$vadef = ($siparis["pb5"] > 0) ? ($siparis["pb5"] / 1.20) : 0;
	$vadef_tax = $siparis["pb5"] - ($siparis["pb5"] / 1.20);
	if ($siparis["pb5"] > 0) {
		$kdv += $vadef_tax; // Vade farkı KDV hesaplama %20
	}

// Toplam Tutar Hesaplama
	if ($siparis["t5"] == "havale") {
		$atutar = $stutar + $kdv + $kargof; //ara toplam
		$hindirim = $atutar - ($atutar / $siparis["pb3"]);
		$gtoplam = (!empty($siparis["pb3"]) && $siparis["pb3"] > 0) ? ($atutar / $siparis["pb3"]) : $atutar; //genel toplam
	} else {
		$gtoplam = $stutar + $kdv + $vadef + $kargof; //genel toplam
	}

// N11 İndirimleri
	if($jso["Order_Discount_Code_Price"]>0){
		$kindirim = $jso["Order_Discount_Code_Price"];
		$gtoplam 	= sprice($gtoplam-$kindirim);
	}

// Kiralama
	if (!empty($jso["Order_Rental_Days"])) {
		$dcodepoint = !empty($jso["Order_Rental_Discount"]) ? (100 - $jso["Order_Rental_Discount"]) / 100 : 1;
		$gtoplam *= $jso["Order_Rental_Days"] * $dcodepoint;
	}
?>