<?php
session_start();
include('config/koneksi2.php');
$username=$_SESSION['username'];

				//MENAMPILKAN DETAIL KERANJANG BELANJA//
				
				echo'<h3 class="title fadeInUp animated" data-wow-delay=".5s">My Shopping Cart</h3> ';

			

				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='.mysql_real_escape_string((int)$id));
							$id_order = mysql_real_escape_string((int)$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);
							$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];
							$sub_retail = $get_row['retail'] * $value;
							$retail = $get_row['retail'];
					
							
							$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= (($get_row[dealer] * $d[disc])/100);
							$dis3= $get_row[dealer] - $dis1;
							$t= number_format($get_row['dealer'] * $value);
							$sub='<del>'.$t.'</del>';
							$sub_dealer =  ($dis3 * 1) + ($get_row['dealer'] * ($value - 1));
							$dealer = $get_row['dealer'];
							}
							else
							{
								if($id_diskon =='0')
								{
								$sub_dealer = $get_row['dealer'] * $value;
								$sub="";
							    $dealer = $get_row['dealer'];

								}
								else
								{
								$sub_dealer = $diskon3 * $value;
								$sub="";
								$dealer = $diskon3;

								}
							}
                                
                                if($get_row[bundling] == 'yes')
								{
								echo'<div class="cart-header wow fadeInUp animated" data-wow-delay=".5s">
									<a href="#" id="del" name="del" onclick="del('.$get_row['id'].')"><div class="alert-close"> </div></a>
									<div class="cart-sec simpleCart_shelfItem">
										<div class="cart-item cyc">
											<a href="#"><img src="http://bsis.bikershop.biz/inside/data/resize/'.$get_row['photo'].'" class="img-responsive" alt=""></a>
										</div>
										<div class="cart-item-info">
											<h4><a href="#">'.$get_row['nama'].' ('.$get_row['deskripsi'].')</h4>
											<ul class="qty">
											<li><p style="font-size:11px; color:green;">HET: Rp.'.number_format($retail).' , NET: Rp.'.number_format($dealer).'</p></li>
											
											 <div class="form-group row">
											  <div class="col-xs-4"><span style="font-size:11px;">Quantity :</span><input type="number" class="form-control" name="jum" id="jum_'.$get_row['id'].'" value="'.$value.'"></div> 
											  <div class="col-xs-4" style="margin-top:15px;">
											  <h3><a href="#" onclick="update('.$get_row['id'].')"><span class="label label-primary">Update</span></a></h3></div>							
											  <div class="col-xs-12"><textarea class="form-control" name="ketbun" id="ketbun" placeholder="Input Size and color here,,,,, "></textarea></div> 
											  											  </div>


											</ul>
											<div class="delivery">
												<p>Sub total HET: Rp.'.number_format($sub_retail).' , Sub total NET: Rp.'.number_format($sub_dealer).' '.$sub.'
												</p>
											</div>
										</div>
										<div class="clearfix"></div>
									</div>
								</div>';
								}
								else
								{
								echo'<div class="cart-header wow fadeInUp animated" data-wow-delay=".5s">
									<a href="#" id="del" name="del" onclick="del('.$get_row['id'].')"><div class="alert-close"> </div></a>
									<div class="cart-sec simpleCart_shelfItem">
										<div class="cart-item cyc">
											<a href="#"><img src="http://bsis.bikershop.biz/inside/data/resize/'.$get_row['photo'].'" class="img-responsive" alt=""></a>
										</div>
										<div class="cart-item-info">
											<h4><a href="#">'.$get_row['nama'].' '.$get_row['config_ax'].' '.$get_row['size_ax'].' '.$get_row['colour_ax'].'</h4>
											<ul class="qty">
											<li><p style="font-size:11px; color:green;">HET: Rp.'.number_format($retail).' , NET: Rp.'.number_format($dealer).'</p></li>
											 <div class="form-group row">
											  <div class="col-xs-4"><span style="font-size:11px;">Quantity :</span><input type="number" class="form-control" name="jum" id="jum_'.$get_row['id'].'" value="'.$value.'"></div> 
											  <div class="col-xs-4" style="margin-top:15px;">
											  <h3><a href="#" onclick="update('.$get_row['id'].')"><span class="label label-primary">Update</span></a>
				</h3></div>											  </div>

											</ul>
											<div class="delivery">
												<p>Sub total HET: Rp.'.number_format($sub_retail).' , Sub total NET: Rp.'.number_format($sub_dealer).' '.$sub.'
												</p>
											</div>
										</div>
										<div class="clearfix"></div>
									</div>
								</div>';
								}
							}
							$total_dealer += $sub_dealer;
							$total_retail += $sub_retail;
						}
					}
				}
				
				if($total_dealer > 0)
				{
				if($_SESSION['user_akses'] == 'dealer')
				{
				echo'
				<div align="right"><h3><a href="#" onclick="hapus()"><span class="label label-danger">Kosongkan Keranjang</span></a></h3></div>
				<hr size="50">
				<table class="table">
					<tbody>
						<tr>
							<td>Total Net :</td>
							<td class="type-info">Rp. '.number_format($total_dealer).'</td>
							<td></td>
						</tr>
						<tr>
								<td>Total HET :</td>
								<td class="type-info">Rp. '.number_format($total_retail).'</td>
								<td><h3><a href="#" name="order" id="order" onclick="shop('.$total_dealer.')"><span class="label label-success">Proses Order</span></a></h3></td>
						</tr>
					</tbody>
				</table>
			';
			}
			else
			{
			echo'
				<div align="right"><h3><a href="#" onclick="hapus()"><span class="label label-danger">Kosongkan Keranjang</span></a></h3></div>
				<hr size="50">
					<table class="table">
						<tbody>
							<tr>
							<td>Nama Toko :</td>
							<td colspan="2"><input type="text" class="form-control" name="pemesan" id="pemesan" onkeyup="autotoko()">
							<ul id="showtoko"></ul>
							</td>
							</tr>
							<tr>
							<td>Keterangan :</td>
							<td colspan="2"><textarea class="form-control" name="ket" id="ket"></textarea>
							</td>
							</tr>
							<tr>
								<td>Total Net :</td>
								<td class="type-info">Rp. '.number_format($total_dealer).'</td>
								<td></td>
							</tr>
							<tr>
								<td>Total HET :</td>
								<td class="type-info">Rp. '.number_format($total_retail).'</td>
								<td><h3><a href="#" name="order" id="order" onclick="shop('.$total_dealer.')"><span class="label label-success">Proses Order</span></a></h3></td>
							</tr>
						</tbody>
					</table>
			';
			}
			}
			else
			{
			echo'
				<hr size="50">
					<table class="table">
						<tbody>
							<tr>
								<td>Keranjang Belanja Kosong</td>
								<td><h1 id="h1.-bootstrap-heading"><a href="products.html"><span class="label label-primary">Kembali Belanja</span></a></td>
							</tr>
	
						</tbody>
					</table>
			';
			}

?>