<?php
session_start();
include('config/koneksi2.php');

foreach($_SESSION as $name => $value){
		if($value > 0){
			if(substr($name, 0, 5) == 'cart_'){
				$id = substr($name, 5, (strlen($name)-5));
				$get = mysql_query("SELECT * FROM bs_stok WHERE id='$id'");
				while($get_row = mysql_fetch_assoc($get)){
				$id_diskon=$get_row[kode_diskon];
				$sql_diskon="select * from diskon where kode_diskon='$id_diskon'";
				$hasil_diskon=mysql_query($sql_diskon);
				$diskon=mysql_fetch_array($hasil_diskon);
				
				$region=$_SESSION['region'];
                $kode=$get_row['kode_ax'];
                $size=$get_row['size_ax'];
                $color=$get_row['colour_ax'];
                $config=$get_row['config_ax'];
                
                $hargato=mysql_query("select harga from harga where kode='$kode' and size='$size' and color='$color' and config='$config' and region='$region'");
                $har=mysql_fetch_array($hargato);
                if($region !="")
                {
                $diskon1= (($har[harga] * $diskon[diskon])/100);
				$diskon3= $har[harga] - $diskon1;
				$diskon2=number_format($diskon3);
				$harga_dealer=number_format($har[harga]);
				$dis=$diskon[diskon];
				$dealer=$har[harga];
                }
                else
                {
				$diskon1= (($get_row[dealer] * $diskon[diskon])/100);
				$diskon3= $get_row[dealer] - $diskon1;
				$diskon2=number_format($diskon3);
				$harga_dealer=number_format($get_row[dealer]);
				$dis=$diskon[diskon];
				$dealer=$get_row[dealer];

                }
						
				$prom=mysql_query("select * from inthismonth where id_produk='$id' and qty > 0 and id_produk NOT IN (select id_produk from userp where user='$username')");
				$cek=mysql_num_rows($prom);
				if($cek > 0)
				{
					$d=mysql_fetch_array($prom);
					$dis1= (($dealer * $d[disc])/100);
				$dis3= $dealer - $dis1;
				
				$sub =  ($dis3 * 1) + ($dealer * ($value - 1));
					
				}
				else
				{
					if($id_diskon =='0')
					{
					$sub = $dealer * $value;
					}
					else
					{
					$sub = $diskon3 * $value;
					}
				}
				
				}
			}
			$total += $sub;
			$total_value += $value;
			$total_all = $total_value - $_SESSION['port'];
		}
	} 

	echo "<div class=\"header-right\">
						<a href=\"checkout.html\"><span class=\"glyphicon glyphicon-shopping-cart\" aria-hidden=\"true\"></span></a>
						<h4><a href=\"checkout.html\">
								<span class=\"simpleCart_total\"> Rp. ".number_format($total)." </span> (<span id=\"simpleCart_quantity\" class=\"simpleCart_quantity\"> ".$total_all." </span>) 
						</a></h4>
						<!--<div class=\"cart-box\">
							<p><a href=\"javascript:;\" class=\"simpleCart_empty\" onclick=\"hapus()\">Empty cart</a></p>
							<div class=\"clearfix\"> </div>
						</div>-->
					</div>";
	
	?>