<?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
	$act  = $_REQUEST['act'];
	
	if($act == 1)
	{
		$kode  = $_REQUEST['kode'];
		$inventory  = $_REQUEST['inventory'];
		list($d, $e, $f)=split ("[-]", $_REQUEST['inputDate']);
		$datepicker=$f."-".$e."-".$d;
		$customer  = $_REQUEST['customer'];
			
		$insert = mysql_query("insert into sales (invoice,invoice_date,id_customer, inventory, user_update) values ('$kode','$datepicker','$customer','$inventory','$USERNAME')");

						if($insert)
						{
							$max = mysql_fetch_array(mysql_query("select max(id_sales) as maxsales from sales "));
							$maxsales = $max['maxsales'];
							if($inventory == "Services")
							{
						?>
								<script language="javascript">
									 alert("Add Sales Success");
									document.location="add_salesdetails.php?act=3&id=<?php echo $maxsales; ?>";
								</script>
						<?php
							}
							else
							{
								?>
								<script language="javascript">
									 alert("Add Sales Success");
									document.location="add_salesdetails.php?act=4&id=<?php echo $maxsales; ?>&inventory=<?php echo $inventory; ?>";
								</script>
						<?php
							}
						}
						else
						{
							?>
								<script language="javascript">
									alert("Add Sales Failed");
									document.location="add_sales.php?act=3";
								</script>
							<?php
						}
	}
	elseif($act == 2)
	{
		$inventory = $_REQUEST['inventory'];
		if($inventory == "Diamond")
		{
				$inve = "D";
		}
		elseif($inventory == "LogamMulia")
		{
				$inve = "LM";
		}
		elseif($inventory == "Gold")
		{
				$inve = "G";
		}
		elseif($inventory == "ReadyItem")
		{
				$inve = "RI";
		}
		elseif($inventory == "Cincin")
		{
				$inve = "C";
		}
		elseif($inventory == "Mastura")
		{
				$inve = "M";
		}
		elseif($inventory == "Liontin")
		{
				$inve = "L";
		}
		elseif($inventory == "Kerabu")
		{
				$inve = "K";
		}
		elseif($inventory == "GKGR")
		{
				$inve = "GKGR";
		}
		elseif($inventory == "Rangka")
		{
				$inve = "R";
		}
		$bulan  = date('m');
		$kode = mysql_fetch_array(mysql_query("select max(id_sales) as maxid from  sales where inventory ='$inventory'"));
		$maxid = $kode['maxid'];
		$branch = mysql_fetch_array(mysql_query("select * from tbl_admin a
		inner join tbl_branch b on a.id_branch = b.id_branch where user_id='$USERNAME'"));
		$brachcode = $branch['kode_branch'];
		if($maxid == "")
		{
			$kode1 = $brachcode.$inve."/".$bulan."/1";
		
		}
		else
		{
			$total = $maxid+1;
			$kode1 = $brachcode.$inve."/".$bulan."/".$total;
		}
	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-shopping-cart"></i>Add 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="add_sales.php?act=1&inventory=<?php echo $inventory; ?>" 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="Diamond" <?php if($inventory == "Diamond") { ?> selected="selected" <?php } ?>>Diamond</option>
                              <!--<option value="Gold" <?php if($inventory == "Gold") { ?> selected="selected" <?php } ?>>Gold</option>-->
                              <option value="LogamMulia/Gold" <?php if($inventory == "LogamMulia/Gold") { ?> selected="selected" <?php } ?>>LogamMulia / Gold</option>
                               <option value="ReadyItem" <?php if($inventory == "ReadyItem") { ?> selected="selected" <?php } ?>>ReadyItem</option>
                              <option value="Services" <?php if($inventory == "Services") { ?> selected="selected" <?php } ?>>Services</option>
                                <option value="Cincin" <?php if($inventory == "Cincin") { ?> selected="selected" <?php } ?>>Cincin</option>
                           <option value="Mastura" <?php if($inventory == "Mastura") { ?> selected="selected" <?php } ?>>Mastura</option>
                           <option value="Liontin" <?php if($inventory == "Liontin") { ?> selected="selected" <?php } ?>>Liontin</option>
                            <option value="Kerabu" <?php if($inventory == "Kerabu") { ?> selected="selected" <?php } ?>>Kerabu</option>
                           <option value="GKGR" <?php if($inventory == "GKGR") { ?> selected="selected" <?php } ?>>Gelang Kaku Gelang Rantai</option>
                           <option value="Rangka" <?php if($inventory == "Rangka") { ?> selected="selected" <?php } ?>>Rangka</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 $kode1; ?>"  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 date('d-m-Y'); ?>">
                          </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 status_customer=1 order by nama_customer";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                        <option 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="submit" class="btn btn-default">Submit</button>
                            <button type="reset" class="btn btn-default">Reset</button>
                          </div>
                        </div>
                      </form>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                   

<?php include "include/foot.php"; ?>
<script src='assets/js/for_pages/dashboard.js'></script>
</body>
<?php
	}
	elseif($act == 3)
	{
	?>
    <body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-shopping-cart"></i>Add 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="add_sales.php?act=2" 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="inventory" id="inventory" class="form-control">
                              <option value="Diamond" <?php if($inventory == "Diamond") { ?> selected="selected" <?php } ?>>Diamond</option>
                              <option value="Gold" <?php if($inventory == "Gold") { ?> selected="selected" <?php } ?>>Gold</option>
                              <option value="LogamMulia" <?php if($inventory == "LogamMulia") { ?> selected="selected" <?php } ?>>LogamMulia</option>
                               <option value="ReadyItem" <?php if($inventory == "ReadyItem") { ?> selected="selected" <?php } ?>>ReadyItem</option>
                              <option value="Services" <?php if($inventory == "Services") { ?> selected="selected" <?php } ?>>Services</option>
                                <option value="Cincin" <?php if($inventory == "Cincin") { ?> selected="selected" <?php } ?>>Cincin</option>
                           <option value="Mastura" <?php if($inventory == "Mastura") { ?> selected="selected" <?php } ?>>Mastura</option>
                           <option value="Liontin" <?php if($inventory == "Liontin") { ?> selected="selected" <?php } ?>>Liontin</option>
                            <option value="Kerabu" <?php if($inventory == "Kerabu") { ?> selected="selected" <?php } ?>>Kerabu</option>
                           <option value="GKGR" <?php if($inventory == "GKGR") { ?> selected="selected" <?php } ?>>Gelang Kaku Gelang Rantai</option>
                           <option value="Rangka" <?php if($inventory == "Rangka") { ?> selected="selected" <?php } ?>>Rangka</option>
                            </select>
                          </div>
                        </div>
                   
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="submit" class="btn btn-default">Submit</button>
                            <button type="reset" class="btn btn-default">Reset</button>
                          </div>
                        </div>
                      </form>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                   

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