<!DOCTYPE html>

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

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

  <body class="hold-transition skin-blue sidebar-mini layout-boxed">
    <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 Delivery
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Warehouse</a></li>
            <li class="active">Tambah Delivery</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">Tambah Data</h3>
						</div><!-- /.box-header -->
						<!-- form start -->
						<?php echo"
						<form id='multiple_select_form' name=form method=POST action = 'insert.php' >"; ?>
						  <div class="box-body">
						  
							<div class="form-group">
							  <label>Packing By</label>
								<?php									
									echo"<input type='text' class='form-control' name = 'pack' placeholder='Packing By' required>";
								?>
							</div>

							
							<div class="form-group">
							  <label>Select Sales untuk delivery</label>
								<select name="framework[]" id="framework" class="form-control selectpicker" data-live-search="true" multiple required>
									<?php
										$cek = mysql_query("Select * from jualcs where bayar2 = 'Y' and status <> 'D' and billno not in (SELECT jualcs FROM deliverydetail left join delivery  on delivery.pk = deliverydetail.delivery where delivery.status <> 'D') order by billno desc");
										while ($r=mysql_fetch_array($cek)){
											$cust = mysql_result(mysql_query("select nama from customer where id = $r[cust]"),0);
											echo "<option value='$r[billno]'>$r[billno] - $cust - </option>";
										}		
									?>
								</select>
								<br /><br />
								<input type="hidden" name="hidden_framework" id="hidden_framework" />
							</div>
							
							


							<input type="submit" name="submit" class="btn btn-info" value="Submit" />
							
						  </div><!-- /.box-body -->
						<?php echo"  
						</form>";?>
					  </div><!-- /.box -->

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

      <!-- 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 -->

    <!-- 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>
$(document).ready(function(){
 $('.selectpicker').selectpicker();

 $('#framework').change(function(){
  $('#hidden_framework').val($('#framework').val());
 });

 $('#multiple_select_form').on('submit', function(event){
  event.preventDefault();
  if($('#framework').val() != '')
  {
   var form_data = $(this).serialize();
   $.ajax({
    url:"insert.php",
    method:"POST",
    data:form_data,
    success:function(data)
    {
     //console.log(data);
     $('#hidden_framework').val('');
     $('.selectpicker').selectpicker('val', '');
     alert(data);
    }
   })
  }
  else
  {
   alert("Please select framework");
   return false;
  }
 });
});
</script>
  </body>
</html>
<?php 
	}
?>