<!DOCTYPE html>

<?php 
	session_start();
	@ob_start();
	include "../../config/koneksi.php";
	include "../../config/fungsi_rupiah.php";
	include "../headadvance.php";

	
	if ($_SESSION['nama'] == ''){
		header('Location:index.php');
	}
	else{
		$idd = $_SESSION['idm'];
?>
<html>

  <body class="hold-transition skin-blue sidebar-mini layout-boxed" onLoad="document.getElementById('produk').focus();">
    <div class="wrapper">
		<?php include "../header.php";?>
      
		<?php include "../menu.php";?>
      

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Tambah Retur Penjualan
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="data.php">Retur Penjualan</a></li>
            <li class="active"><a href="add.php">Tambah Retur Penjualan</a></li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12">
              
              <div class="box">

                <div class="box-body">
					<div class="col-md-12">
					  <!-- Horizontal Form -->
					  <div class="box box-info">
						<div class="box-header with-border">
						  <h3 class="box-title">Item Retur Penjualan</h3>
						</div><!-- /.box-header -->
					<form id='demoForm2' name="form2" method=POST action='aksisales.php?module=sales&act=add' class='form-horizontal'>
					<div class="col-xs-12">
						<div class=" col-md-4">
							<div class="form-group">
								<label>Produk</label>
									<select name="produk" id="produk"  class="form-control select2" tabindex="1">
										<?php
											$cek = mysql_query("Select * from produk where del = 'N'  order by produk asc");
											while ($r=mysql_fetch_array($cek)){	
												echo"<option value = $r[id] data-hrg= $r[unit_rp]>$r[sku] $r[produk]</option>";
											}	
										?>
									</select>
							</div>
						</div>
								
						<div class=" col-md-2">
							<div class="form-group">
								<label for="date">Qty</label>
								<div class="input-group">
								  <input type="number" class="form-control pull-right inp" id="date" name="qty" placeholder="Quantity"   tabindex="2" value="1"   onkeypress='return validateQty2(event);' required>
								</div><!-- /.input group -->
							</div><!-- /.form group -->
						</div>
						
						<div class=" col-md-2">
							<div class="form-group">
								<label for="date">Price</label>
								<div class="input-group">
								  <input type="number" class="form-control pull-right inp" id="hrg" name="price" placeholder="Price"   tabindex="3" value="1"  onkeypress='return validateQty2(event);' required>
								</div><!-- /.input group -->
							</div><!-- /.form group -->
						</div>
						
						<div class=" col-md-2">
							<div class="form-group">
								<label for="date">Disc (%)</label>
								<div class="input-group">
								  <input type="number" class="form-control pull-right inp" id="disc" name="disc" placeholder="Disc"   tabindex="4" value="0"  onkeypress='return validateQty(event);' required>
								</div><!-- /.input group -->
							</div><!-- /.form group -->
						</div>
							 
						 <div class="col-md-2">
							<div class="form-group">
								<label for="date"></label>
								<div class="input-group">
									<!--<button type="submit" id ="add" class="btn btn-lg btn-primary" name="addtocart" >+</button>-->
							 
									<input type="submit" id ="add" class="btn btn-lg btn-primary" value="+" name="addtocart"  tabindex="5">
								</div>
							</div>	
						</div>
							
					</div>
					</form>

							

							<div class="col-xs-12">
							  <div class="table-responsive">
								<table class="table no-margin">
								  <thead>
									<tr>
									  <th>Product</th>
									  <th>Qty</th>
									  <th>Harga</th>
									  <th align ="center">Disc(%)</th>
									  <th align ="right">Total</th>
									</tr>
								  </thead>
								  <tbody>
									<?php
										$user = $_SESSION['nama'];
										$cek = mysql_query("Select * from tmpjualcs where kasir = '$user' order by id desc");

										while ($r=mysql_fetch_array($cek)){	
											$id = $r['id'];
											$harga = format_rupiah($r['harga']);
											$qty = format_rupiah($r['qty']);
											$disc = format_rupiah($r['disc']);
											$grand = format_rupiah($r['qty'] * ($r['harga'] - ($r['disc'] * $r['harga'] / 100)));
											$produk = mysql_result(mysql_query("select produk from produk where id = $r[produk]"),0);
											echo "<tr>
												  <td><a href = 'aksisales.php?module=sales&act=delitem&id=$id'><i class = 'fa fa-times' style='font-size:24px;color:red'></i></a>&nbsp; $produk</td>
												  <td>$qty</td>
												  <td>$harga</td>
												  <td>$disc</td>
												  <td align = 'right'>$grand</td>
												</tr>";
										}
									?>
									
								  </tbody>
								</table>
							  </div><!-- /.table-responsive -->
							</div><!-- /.box-body -->
							<div class="box-footer">
							  <a href="" class="btn btn-sm btn-default btn-flat pull-right">
								<?php
									$subt2 = mysql_result(mysql_query("select sum(qty * (harga - (harga * disc / 100))) from tmpjualcs where kasir = '$user' "),0);
									$subt = format_rupiah($subt2);
									echo"Sub Total : $subt";
									
									echo"<input type = 'hidden'  id='tot' value = '$grandt2'></input>";
								?>
							  </a>
						  </div>
						  
						  <form id='demoForm2' name=form method=POST action='aksisales.php?module=sales&act=diskon' class='form-horizontal'>	
						  <div class="box-footer ">
							  
								<?php
									$promo = mysql_result(mysql_query("select diskon from tmpjualcs where kasir = '$user' limit 1"),0);
									echo"
									<div class='input-group a btn-sm btn-default btn-flat pull-right'>
										
											<input type='number' class='form-control' name='promo' placeholder='Disc' value='$promo'  onkeypress='return /\d/.test(String.fromCharCode(((event||window.event).which||(event||window.event).which)));' tabindex='6' required> 
											<span class='input-group-btn'>
											<button type='submit' class='btn btn-info'><span class='fa fa-pencil-square-o'> </span></button>
											</span>
										

								  </div>";
								?>
					
						  </div>
						  </form>
						  
						  
						  
						  <div class="box-footer clearfix">
							  <a href="" class="btn btn-sm btn-default btn-flat pull-right">
								<?php
									
									$disc = mysql_result(mysql_query("select diskon from tmpjualcs where kasir = '$user' "),0);
									$grandt = format_rupiah($subt2 - $disc);
									echo"Grand Total : $grandt";
									
								?>
							  </a>
							</div>		

					
					
					
					<div class="box box-info">
								<div class="box-header with-border">
								  <h3 class="box-title">Penjualan Info</h3>
								</div><!-- /.box-header -->
							<!-- form start -->
						
						  <div class="box-body">
							 <form id='demoForm3' name=form method=POST action='aksisales.php?module=sales&act=addall' class='form-horizontal'>	
								<div class="form-group">
									<label>Tanggal</label>
									<div class="input-group">
									  <div class="input-group-addon">
										<i class="fa fa-calendar"></i>
									  </div><!--
									  <input name ="antar" type="text" class="form-control" data-inputmask="'alias': 'dd/mm/yyyy'"  data-mask>
									 -->
									 <?php
										$dt1 = date("Y-m-d");
		
											echo"<input type='date' class='form-control' name = 'tgl' value='$dt1' >";
										
									?>
									</div><!-- /.input group -->
								</div>
								
								
								
								
								
							  
								<div id = "lama" class="form-group">
									<label>Customer</label>
									<div class="input-group">
									  <div class="input-group-addon">
										<i class="fa  fa-user"></i>
									  </div>

									 <select name="cust" id="cust"  class="form-control select2" required>
											<?php
												$cek = mysql_query("Select * from customer where status = 'Y' order by nama asc");
												while ($r=mysql_fetch_array($cek)){	
													echo"<option value = $r[id]>$r[nama] - $r[telp] - $r[alamat]</option>";
												}	
											?>
										</select>
									</div><!-- /.input group -->
								</div>
								
								
														 
								
								
								
							<div class="form-group">
								<label>Keterangan</label>
								<div class="input-group">
								  <div class="input-group-addon">
									<i class="fa  fa-edit"></i>
								  </div>
									<input type="text" class="form-control pull-right"  value="-" name="ket" placeholder="Keterangan" required>
								</div><!-- /.input group -->
							</div>
								
								
								
								
								<button type="submit" class="btn btn-info">Tambah Data</button>
							
						</form>
					</div>		
							
							


							
							
						  </div><!-- /.box-body -->
						<?php echo"  
						</form>";?>
					  </div><!-- /.box -->

					  
					 </div><!-- /.box -->
					
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->
		<?php include "../footer.php";?>
		

      <!-- Control Sidebar -->
<!-- Control Sidebar -->
      <aside class="control-sidebar control-sidebar-dark">

        <!-- Tab panes -->
        <div class="tab-content">
          <!-- Home tab content -->
          <div class="tab-pane" id="control-sidebar-home-tab">

          </div><!-- /.tab-pane -->

        </div>
      </aside><!-- /.control-sidebar -->
      <!-- Add the sidebar's background. This div must be placed
           immediately after the control sidebar -->
      <div class="control-sidebar-bg"></div>
    </div><!-- ./wrapper -->

    <!-- jQuery 2.1.4 -->
    <script src="../../plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="../../bootstrap/js/bootstrap.min.js"></script>
	<script src="../../plugins/select2/select2.full.min.js"></script>
    <!-- DataTables -->
    <script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="../../plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- SlimScroll -->
    <script src="../../plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="../../plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="../../dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="../../dist/js/demo.js"></script>
    <!-- page script -->
	
	
    <script src="../../plugins/input-mask/jquery.inputmask.js"></script>
    <script src="../../plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
	

	
	<script>
		function validateQty(event) {
			var key = window.event ? event.keyCode : event.which;
		if (event.keyCode == 8 || event.keyCode == 46 || event.keyCode == 13
		 || event.keyCode == 37 || event.keyCode == 39) {
			return true;
		}
		else if ( key < 48 || key > 57 ) {
			return false;
		}
		else return true;
		};
	</script>
	
	<script>
		function validateQty2(event) {
			var key = window.event ? event.keyCode : event.which;
		if (event.keyCode == 8 || event.keyCode == 46 || event.keyCode == 9
		 || event.keyCode == 37 || event.keyCode == 39) {
			return true;
		}
		else if ( key < 48 || key > 57 ) {
			return false;
		}
		else return true;
		};
	</script>

	
	
	
	<script>
		$(".form-control pull-right inp").on("keypress", function(e){
		  $(this).next().trigger("focus");
		})
	</script>
	
	<script>
		$("select[name='produk']").on("change",function(){
			if($("option:selected",$(this)).val()!="-1"){
				document.getElementById("hrg").value = $(this).children('option:selected').data('hrg');
	
			}
	});
	</script>
	

    <script>
      $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": false,
          "ordering": true,
          "info": true,
          "autoWidth": false
        });
      });
    </script>
	<script>
      $(function () {
        //Initialize Select2 Elements
        $(".select2").select2();

        //Datemask dd/mm/yyyy
        $("#datemask").inputmask("dd/mm/yyyy", {"placeholder": "dd/mm/yyyy"});
        //Datemask2 mm/dd/yyyy
        $("#datemask2").inputmask("mm/dd/yyyy", {"placeholder": "mm/dd/yyyy"});
        //Money Euro
        $("[data-mask]").inputmask();

        //Date range picker
        $('#reservation').daterangepicker();
        //Date range picker with time picker
        $('#reservationtime').daterangepicker({timePicker: true, timePickerIncrement: 30, format: 'MM/DD/YYYY h:mm A'});
        //Date range as a button
        $('#daterange-btn').daterangepicker(
            {
              ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
              },
              startDate: moment().subtract(29, 'days'),
              endDate: moment()
            },
        function (start, end) {
          $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
        }
        );

        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
          checkboxClass: 'icheckbox_minimal-blue',
          radioClass: 'iradio_minimal-blue'
        });
        //Red color scheme for iCheck
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
          checkboxClass: 'icheckbox_minimal-red',
          radioClass: 'iradio_minimal-red'
        });
        //Flat red color scheme for iCheck
        $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
          checkboxClass: 'icheckbox_flat-green',
          radioClass: 'iradio_flat-green'
        });

        //Colorpicker
        $(".my-colorpicker1").colorpicker();
        //color picker with addon
        $(".my-colorpicker2").colorpicker();

        //Timepicker
        $(".timepicker").timepicker({
          showInputs: false
        });
      });
    </script>
	
	

	
  </body>
</html>
<?php 
	}
?>