<?php
session_name("AUTHENUSER");
session_start();
$USERNAME = $_SESSION['SES_USERNAME'];
if(!session_name("AUTHENUSER"))
	{
?>
						<script language="javascript">
						 alert("Waktu Login telah habis.Silahkan Login Kembali");
						document.location="index.php";
						</script>
<?php
	}
if(!$USERNAME)
	{
?>
						<script language="javascript">
						 alert("Harap Login Dahulu.");
						document.location="index.php";
						</script>
<?php
	}
	?>
	<?php 
	include "common/config.php";
	include "include/head.php";
	?>
<?php
		$id_sales  = $_REQUEST['id_sales'];
		$id  = $_REQUEST['id_sales'];
		$fetch = mysql_fetch_array(mysql_query("select * from  sales where id_sales='$id_sales'"));
		$inventory = $fetch['inventory'];
		$id_customer = $fetch['id_customer'];
		list($y, $m, $d)=split ("[-]",$fetch['invoice_date']);
		$invoice_date=$d."-".$m."-".$y;
		$invoice = $fetch['invoice'];
		list($y, $m, $d)=split ("[-]",$fetch['payment_date']);
		$payment_date=$d."-".$m."-".$y;
		$notes = $fetch['notes'];
		$nominal = $fetch['nominal'];
		$nominalreturn = $fetch['nominalreturn'];
		$id_term = $fetch['id_term'];
		$cicilan = $fetch['cicilan'];
		
	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-shopping-cart"></i>View Sales</h1>
</div>
          <div class="main-content">
            <div class="row">
                <div class="widget">
                  <div class="widget-content-white glossed">
                    <div class="padded">
                      <form method="post" action="edit_sales.php?id_sales=<?php echo $id_sales; ?>&act=1" role="form" class="form-horizontal">
                        <div class="form-group">
                          <label class="col-md-4 control-label" >Inventory</label>
                          
                          <div class="col-md-8">
                            <select name="inventory1" id="inventory1" class="form-control">
                              <option value="inventory" <?php if($inventory == "inventory") { ?> selected="selected" <?php } ?>>Inventory</option>
                             <option value="services" <?php if($inventory == "services") { ?> selected="selected" <?php } ?>>Services</option>
                            </select>
                          </div>
                        </div>
                    <div class="form-group">
                          <label class="col-md-4 control-label">Invoice No.</label>
                          <div class="col-md-8">
                            <input type="text" name="kode" id="kode" class="form-control" value="<?php echo $invoice; ?>"  readonly="readonly" >
                          </div>
                        </div>
                    <div class="form-group">
                          <label class="col-md-4 control-label">Invoice Date</label>
                          <div class="col-md-8">
                            <input type="text" class="inputDate" name="inputDate" id="inputDate" value="<?php echo $invoice_date; ?>" readonly>
                          </div>
                        </div>
                        
                        
                    <div class="form-group">
                          <label class="col-md-4 control-label">Kode Customer - Nama Customer</label>
                          <div class="col-md-8">
                         <select name="customer" id="customer" class="form-control">
                              <option value="0">None</option>
							  <?php
                                              $sql3 = "select * from tbl_customer where id_customer='$id_customer' order by nama_customer";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                       <option <?php if($fetch3['id_customer']==$id_customer) { ?> selected="selected" <?php } ?> value="<?php echo $fetch3['id_customer']; ?>"><?php echo  $fetch3['kode_customer'];  ?> - <?php echo  $fetch3['nama_customer'];  ?></option>
                                                      <?php
                                              }
                                             ?>
                            </select>
                          </div>
                        </div>
                       
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="button" class="btn btn-default" onClick="document.location='report_sales.php'">Back</button>
                          </div>
                        </div>
                      </form>
                       <?php if($inventory <> "services")
		{
		?>
                          <table class="table table-striped table-bordered table-hover">
                  <thead>
                    <tr>
                      	  <th>Inventory</th>
                     <th>Kode Stock</th>
                     <th>Qty</th>
                     <th>Date</th>
                     <th>Picture</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php
						$sql = mysql_query("select *,a.inventory as inven from salesdetails a
						inner join sales b on a.id_sales = b.id_sales
						where a.status = 1 and a.id_sales  = '$id'
						order by a.tanggal");
						while($fetch = mysql_fetch_array($sql))
						{
								$id_salesdetails = $fetch['id_salesdetails'];
								$kode_stock = $fetch['kode_stock'];
								$inventory = $fetch['inventory'];
								$barcodeno = $fetch['barcode'];
								list($y, $m, $d)=split ("[-]",$fetch['tanggal']);
								$tanggal=$d."-".$m."-".$y;
								$id_sales = $fetch['id_sales'];
			
	  							if($inventory == "Diamond")
								{
										$fetch4 = mysql_fetch_array(mysql_query("select * from inventory_diamond where barcodeno ='$barcodeno'"));
										$picture = $fetch4['picture'];
										$loc = "diamond/";
										$all = $loc.$picture; 
								}
								elseif($inventory == "LogamMulia")
								{
										$fetch4 = mysql_fetch_array(mysql_query("select * from  inventory_logam where barcodeno ='$barcodeno'"));
										$picture = $fetch4['picture'];
										$loc = "gold/";
										$all = ""; 
								}
								elseif($inventory == "Gold")
								{
										$fetch4 = mysql_fetch_array(mysql_query("select * from  inventory_gold where barcodeno ='$barcodeno'"));
										$picture = $fetch4['picture'];
										$loc = "gold/";
										$all = $loc.$picture; 
								}
								elseif($inventory == "ReadyItem")
								{
										$fetch4 = mysql_fetch_array(mysql_query("select * from  inventory_readyitem where barcodeno ='$barcodeno'"));
										$picture = $fetch4['picture'];
										$loc = "readyitem/";
										$all = $loc.$picture; 
								}
								elseif($inventory == "Cincin")
								{
										$fetch4 = mysql_fetch_array(mysql_query("select * from  inventory_cincin where barcodeno ='$barcodeno'"));
										$picture = $fetch4['picture'];
										$loc = "cincin/";
										$all = $loc.$picture; 
								}
								elseif($inventory == "Mastura")
								{
										$fetch4 = mysql_fetch_array(mysql_query("select * from   inventory_mastura where barcodeno ='$barcodeno'"));
										$picture = $fetch4['picture'];
										$loc = "mastura/";
										$all = $loc.$picture; 
								}
								elseif($inventory == "Liontin")
								{
										$fetch4 = mysql_fetch_array(mysql_query("select * from   inventory_liontin where barcodeno ='$barcodeno'"));
										$picture = $fetch4['picture'];
										$loc = "liontin/";
										$all = $loc.$picture; 
								}
								elseif($inventory == "Kerabu")
								{
										$fetch4 = mysql_fetch_array(mysql_query("select * from   inventory_kerabu where barcodeno ='$barcodeno'"));
										$picture = $fetch4['picture'];
										$loc = "kerabu/";
										$all = $loc.$picture; 
								}
								elseif($inventory == "GKGR")
								{
										$fetch4 = mysql_fetch_array(mysql_query("select * from    inventory_gkgr where barcodeno ='$barcodeno'"));
										$picture = $fetch4['picture'];
										$loc = "gkgr/";
										$all = $loc.$picture; 
								}
								elseif($inventory == "Rangka")
								{
										$fetch4 = mysql_fetch_array(mysql_query("select * from   inventory_rangka where barcodeno ='$barcodeno'"));
										$picture = $fetch4['picture'];
										$loc = "rangka/";
										$all = $loc.$picture; 
								}
								
					?>
                 <tr class="gradeX">
                     <td><?php echo $fetch['inven']; ?></td>
                      <td><?php echo $fetch['kode_stock']; ?></td>
                     <td><?php echo $fetch['qty'];; ?></td>
                      <td><?php echo $tanggal; ?></td>
                      <td> <a class="image" href="<?php echo $all; ?>" >
							<img src="<?php echo $all; ?>" alt="" height="69" width="117"/></a>&nbsp;</td>
                </tr>
                <?php
						}
						?>
                  </tbody>
                </table>
                 <?php
		}
		else
		{
		?>
         <table class="table table-striped table-bordered table-hover">
                  <thead>
                    <tr>
                      	  <th>Service Description</th>
                     <th>Price</th>
                     <th>Pick Up Date</th>
                    </tr>
                  </thead>
                  <tbody>
                       <?php
						$sql = mysql_query("select * from salesservice a
						inner join sales b on a.id_sales = b.id_sales
						where a.status = 1 and a.id_sales  = '$id'
						order by a.tanggal");
						while($fetch = mysql_fetch_array($sql))
						{
								$id_servicesales = $fetch['id_servicesales'];
								list($y, $m, $d)=split ("[-]",$fetch['tanggal']);
								$tanggal=$d."-".$m."-".$y;
								$id_sales = $fetch['id_sales'];
								$currency = $fetch['currency'];
								
					?>
                 <tr class="gradeX">
                     <td><?php echo $fetch['description']; ?></td>
                     <td><?php echo $fetch['currency']; ?> <?php echo number_format($fetch['price'], 0, ',', ','); ?></td>
                      <td><?php echo $tanggal; ?></td>
                    
                </tr>
                <?php
						}
						?>
                  </tbody>
                </table>
          <?php
		}
		?>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                   

<?php include "include/foot.php"; ?>
<script src='assets/js/for_pages/dashboard.js'></script>
</body>
</html>