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

$username=$_SESSION['username'];
	$akses=mysql_query("select id_level from tab_user where username='$username'");
	$akses1=mysql_fetch_array($akses);
	
	$akses2=mysql_query("select id_level_brand from tab_user where username='$username'");
				$akses3=mysql_fetch_array($akses2);
				$level=$akses3[id_level_brand];
				
				$akses4=mysql_query("select id_level_brand_pa from tab_user where username='$username'");
				$akses5=mysql_fetch_array($akses4);
				$level2=$akses5[id_level_brand_pa];
	if($akses1['id_level'] =='0' and $level=='2')
	{
	$sql=mysql_query("select * from bs_stok where(tipe != 'BIKE' and tipe != 'FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand where id_level_brand='$level')) and  (tipe ='BIKE' and tipe ='FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand_pa where id_level_brand_pa='$level2')) and tipe IN (SELECT m.nama_tipe FROM tab_user u INNER JOIN level g ON u.id_level=g.id_level INNER JOIN grup_menu gm ON gm.id_level=g.id_level INNER JOIN tipe_new m ON gm.id_tipe=m.id WHERE u.username='$username') and status !='0'  and dealer < 4000000 and kode_diskon !='0' and tipe!='BIKE' order by date desc LIMIT 6");		
	}
	else
	{
	$sql=mysql_query("select * from bs_stok where(tipe != 'BIKE' and tipe != 'FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand where id_level_brand='$level')) and  (tipe ='BIKE' and tipe ='FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand_pa where id_level_brand_pa='$level2')) and tipe IN (SELECT m.nama_tipe
FROM tab_user u
INNER JOIN level g ON u.id_level=g.id_level
INNER JOIN grup_menu gm ON gm.id_level=g.id_level 
INNER JOIN tipe_new m ON gm.id_tipe=m.id
WHERE
	u.username='$username') and status !='0'  and kode_diskon !='0' and tipe!='BIKE' order by date desc LIMIT 6");
	}
while($row=mysql_fetch_array($sql))
{
$id_diskon=$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);
						$harga_retail=number_format($row[retail]);

		$region=$_SESSION['region'];
        $kode=$row['kode_ax'];
        $size=$row['size_ax'];
        $color=$row['colour_ax'];
        $config=$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=ROUND($diskon[diskon]);
    
        }
        else
        {
		$diskon1= (($row[dealer] * $diskon[diskon])/100);
		$diskon3= $row[dealer] - $diskon1;
		$diskon2=number_format($diskon3);
		$harga_dealer=number_format($row[dealer]);
		$dis=ROUND($diskon[diskon]);
        }
		?>
	<!--<div class="col-md-3 gallery-grid wow flipInY animated" data-wow-delay=".5s">
						<div class="mask1">
					<span><?php echo "$dis"; ?>%</span>
					<a href="#"><img src="http://bsis.bikershop.biz/inside/data/resize/<?php echo "$row[photo]"; ?>" class="img-responsive" alt=""/></a>
					</div>
					<div class="gallery-text simpleCart_shelfItem">
						<h5><?php echo "$row[nama]"; ?> <?php echo "$row[config_ax]"; ?> <?php echo "$row[size_ax]"; ?> <?php echo "$row[colour_ax]"; ?> </h5>
						<div class="ofr">
								<p class="pric1"><del>Rp. <?php echo "$harga_dealer"; ?></del><br />
							<span class="item_price">Rp. <?php echo "$diskon2"; ?></span></p>
							</div>
						<ul>
							<li><a class="item_add" id="add" name="add" href="#" onclick="cart('<?php echo $row[id] ?>')"><span class="glyphicon glyphicon glyphicon-shopping-cart" aria-hidden="true"></span></a></li>
						</ul>
					</div>
				</div>-->
				<div class="product-grids simpleCart_shelfItem wow fadeInUp animated" data-wow-delay=".5s">
			<div class="new-top">
			<div class="mask1"><span><?php echo "$dis"; ?>%</span>
				<a href="#"  data-toggle="modal" data-target="#myModal" id="image" name="image" onclick="image('<?php echo $row[id] ?>')"><img src="http://bsis.bikershop.biz/inside/data/resize/<?php echo "$row[photo]"; ?>" class="img-responsive" alt=""/></a>
				</div>
				<!--<div class="new-text">
					<ul>
						<li><a class="item_add" data-toggle="modal" data-target="#myModal" id="image" name="image" href="#" onclick="image('<?php echo $row[id] ?>')">Lihat Gambar</a></li>
						<li><input type="number" class="item_quantity" name="qty" id="qty_<?php echo $row[id] ?>" min="1" value="1"></li>
						<li><a class="item_add" id="add" name="add" href="#" onclick="cart('<?php echo $row[id] ?>')">Beli</a></li>
					</ul>
				</div>-->
			</div>
			<div class="new-bottom">
			    			    <div class="b">
				<h5><?php echo "$row[nama]"; ?> <?php echo "$row[config_ax]"; ?> <?php echo "$row[size_ax]"; ?> <?php echo "$row[colour_ax]"; ?> </h5>
				</div>
						<!--<div class="rating">
							<span></span>
						</div>-->						
										<div class="ofr">
						<?php
							if($row['kode_diskon'] == '0')
							{
								?>
								<p><span class="item_price1">HET: Rp.<?php echo "$harga_retail"; ?></span><br><span class="item_price">NET: Rp.<?php echo "$harga_dealer"; ?></span></p>
								<?php
							}
							else
							{
								?>
								<p class="pric1"><span class="item_price1">HET: Rp.<?php echo "$harga_retail"; ?></span><br>NET:<del> Rp.<?php echo "$harga_dealer"; ?></del>
								<span class="item_price">Rp.<?php echo "$diskon2"; ?></span></p>
								<?php
							}
							?>
							
						</div>		
							<div class="clearfix"></div>
						<div class="bawah">
						<div class="left-in"><?php
						if($_SESSION['user_akses'] == 'dealer')
						{
							?>
							<span><span class="notify-badge"><?php echo $row[stok_ext] ?></span></span>
							<?php
						}
						else
						{
							?>
								<span><a href="#kode_<?php echo $row[id] ?>" data-toggle="collapse"><span class="notify-badge"><?php echo $row[stok] ?></span></a></span>
							<?php
						 $kode=$row['kode_ax'];
						    $size=$row['size_ax'];
						    $color=$row['colour_ax'];
						    $config=$row['config_ax'];
							$select=mysql_query("select * from stok where kode_ax='$kode' and size_ax='$size' and colour_ax='$color' and config_ax='$config' and stok > 0 ");
						?>
  <div id="kode_<?php echo $row[id] ?>" class="collapse">
    <?php
							
							while($a=mysql_fetch_array($select))
							{
							?>
							<span style="font-size:10px;"><?php echo $a['warehouse'] ?>:<?php echo $a['stok'] ?></span>,

							<?php
							} 
							?>
  </div>
  <?php 
						}
						?><input type="number" class="item_quantity1" name="qty" id="qty_<?php echo $row[id] ?>" min="1" value="1"></div>
						<div class="right-add"><a id="add" name="add" href="#" onclick="cart('<?php echo $row[id] ?>')"> Beli</a></div>
						</div>
					</div>
				
				</div>
<?php
}
?>

