<?php

include("include/db.conn.php");
require_once("include/conf.class.php");

//GET REQUEST IDs
$curreny_code=$_REQUEST['currencyid'];
$total=$_REQUEST['total'];

//FETCH TAX AND SHIPPING
$fetch_tax=$cartCore->fetch_cart_tax_by_country_code_global_id($_REQUEST['country_id'],$_REQUEST['global_id']);
$fetch_shipping=$cartCore->fetch_cart_shipping_by_country_code_global_id($_REQUEST['country_id'],$_REQUEST['global_id']);


//SHIPPING CALCULATION

//SHIPPING FOR DEFINE COUNTRY
if(!empty($fetch_shipping['SHIPPING_COUNTRY']))
{
	if($fetch_shipping['PRECENTAGE']==true)
	{
		$shipping=round(($fetch_shipping['AMOUNT']/100)*$total,2);
		$total_with_shipping=$shipping+$total;
	}
	else
	{
		$shipping=$fetch_shipping['AMOUNT'];
		$total_with_shipping=$fetch_shipping['AMOUNT'] + $total;
	}
}

//SHIPPING FOR NON DEFINE COUNTRY
else
{
	$fetch_shipping=$cartCore->fetch_cart_shipping_by_country_code_global_id('ANY',$_REQUEST['global_id']);
	
	if($fetch_shipping['PRECENTAGE']==true)
	{
		$shipping=round(($fetch_shipping['AMOUNT']/100)*$total,2);
		$total_with_shipping=$shipping+$total;
	}
	else
	{
		$shipping=$fetch_shipping['AMOUNT'];
		$total_with_shipping=$fetch_shipping['AMOUNT'] + $total;
	}
}
//END OF SHIPPING CALCULATION



//TAX CALCULATION

//TAX FOR DEFINE COUNTRY
if(!empty($fetch_tax['TAX_COUNTRY']))
{
	if($fetch_tax['PRECENTAGE']==true)
	{
		$tax=round(($fetch_tax['AMOUNT']/100)*$total_with_shipping,2);
		$total_with_shipping_tax=$tax+$total_with_shipping;
	}
	else
	{
		$tax=$fetch_tax['AMOUNT'];
		$total_with_shipping_tax=$fetch_tax['AMOUNT'] + $total_with_shipping;
	}
}

//TAX FOR NON DEFINE COUNTRY
else
{
	$get=$cartCore->fetch_cart_tax_by_country_code_global_id('ANY',$_REQUEST['global_id']);
	
	if($get['PRECENTAGE']==true)
	{
		$tax=round(($get['AMOUNT']/100)*$total_with_shipping,2);
		$total_with_shipping_tax=$tax+$total_with_shipping;
	}
	else
	{
		$tax=$get['AMOUNT'];
		$total_with_shipping_tax=$get['AMOUNT'] + $total_with_shipping;
	}
}
//END OF TAX CALCULATION


echo json_encode(array("tax"=>$curreny_code.' '.$tax,"shipping"=>$curreny_code.' '.$shipping,"total_shipping_tax"=>$curreny_code.' '.$total_with_shipping_tax));
?>




