<!DOCTYPE html>

<?php 
	session_start();
	date_default_timezone_set("Asia/Jakarta");
	@ob_start();
	include "../../config/koneksi.php";
	include "../../config/fungsi_rupiah.php";
	include "../headadvance.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>
            Edit Orderan
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="data.php">Orderan</a></li>
            <li class="active"><?php echo"<a href='edit.php?id=$_GET[id]'>"; ?>Edit Orderam</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-6">
					  <!-- Horizontal Form -->
					  <div class="box box-info">
						<div class="box-header with-border">
						  <h3 class="box-title">View Orderan</h3>
						</div><!-- /.box-header -->
						<!-- form start -->
						<?php echo"
						<form id='demoForm' name=form method=POST action='aksisales.php?module=sales&act=edit&id=$_GET[id]' class='form-horizontal'>"; ?>
						  <div class="box-body">
							<div class="form-group">
								<?php
									$st = mysql_result(mysql_query("select status from orders where billno = $_GET[id]"),0);
									
										$batal = mysql_result(mysql_query("select batal from orders where billno = $_GET[id]"),0);
										$SONum =  mysql_result(mysql_query("select web from orders where billno = $_GET[id]"),0);
										echo"<h2><b>$SONum</b></h2>";
										if ($batal == 1){
											echo"<h2><b>BATAL</b></h2>";
										}
										$angkutan= mysql_result(mysql_query("select pengangkutan from orders where billno = $_GET[id]"),0);
										$nopol= mysql_result(mysql_query("select nopol from orders where billno = $_GET[id]"),0);
										$sta= mysql_result(mysql_query("select sts from orders where billno = $_GET[id]"),0);
										
										if(($angkutan == "" and $nopol == "") or ($angkutan == "0" and $nopol == "0")){
											if ($batal == 0){
												echo"<a href='aksisales.php?module=sales&act=batal&id=$_GET[id]' class='btn btn-sm btn-danger btn-flat pull-left'>BATAL</a>";
											}
										}
										else{
											echo"<br><b>Pengangkutan : $angkutan<br> Nopol : $nopol <br> status : $sta</b>";
										
										}
										
								?>
							</div>
							
							<div class="form-group">
							  <label>Tanggal Input</label>
								<?php
									$billdate = mysql_result(mysql_query("select billdate from temporder where billno = $_GET[id]"),0);
									$dt1 =date_format(date_create($billdate),"d-m-Y H:i");
									echo"<input type='text' class='form-control' name = 'sls' value='$dt1' disabled>";
								?>
							</div>
							
							
													
							

								<div class="form-group">
								  <label>Jenis Bahan</label>
								  
									<select name="category" id="cate"  class="form-control" disabled>
										<?php
											$cat = mysql_result(mysql_query("select category from vorderdetails where billno = $_GET[id]"),0);
											$catname = mysql_result(mysql_query("select category from categories where pk = $cat"),0);
											echo"<option value = $cat>$catname</option>";
											$cek = mysql_query("Select * from categories  order by category asc");
											while ($r=mysql_fetch_array($cek)){	
												echo"<option value = $r[pk]>$r[category]</option>";
											}	
										?>
									</select>
								</div>
								
								
								<div class="form-group">
									<label>Tipe</label>
									<select name="choices[]" id="choices" onchange="myFunction()" class="form-control" disabled>
										<?php
											$prod = mysql_result(mysql_query("select code from vorderdetails where billno = $_GET[id]"),0);
											$prodname = mysql_result(mysql_query("select product from vorderdetails where billno = $_GET[id]"),0);
											echo"<option value = $prod>$prodname</option>";
										?>
										<!-- js populates -->
									</select>
								</div>
								
								

								<div class="form-group">
								  <label>Qty</label>
								  <?php
									$qty = mysql_result(mysql_query("select qty from vorderdetails where billno = $_GET[id]"),0);
									echo"<input id='qty' type='text' value = '$qty' class='form-control'  name='qty' onkeypress='return isNumberKey(event)'/>";
								  ?>
								</div>
								
								<div class="form-group">
								  <label>Bonus</label>
								  <?php
									$bonus = mysql_result(mysql_query("select bonus from orders where billno = $_GET[id]"),0);
									echo"<input id='qty2' type='text' value = '$bonus' class='form-control'  name='bonus' onkeypress='return isNumberKey(event)'/>";
								  ?>
								</div>
								
								<div class="form-group">
								  <label>Price</label>
								  <?php
									$price2 = mysql_result(mysql_query("select price from vorderdetails where billno = $_GET[id]"),0);
									$price= format_rupiah($price2);
									echo"<input id='txtValue' class='form-control' value = '$price' type='text' name='harga' onkeypress='return isNumberKey(event)'/>";
								  ?>
								</div>
								
								<div class="form-group">
								  <label>Total Price</label>
								  <?php
									$tot= format_rupiah($qty * $price2);
									echo"<input id='txtTotal' value = '$tot' class='form-control' type='text' name='harga' disabled/>";
								  ?>
								</div>
																
								
								<div class="form-group">
								  <label>Customer</label>
								  <select class="form-control select2" name ='cust' disabled >
									<?php 
										$cust = mysql_result(mysql_query("select customerid from vorderdetails where billno = $_GET[id]"),0);
										$custname = mysql_result(mysql_query("select customername from customers where customerid = $cust"),0);
										echo"<option value = $cust>$custname </option>";
										$cek = mysql_query("Select * from customers  order by customername");
										
										while ($r=mysql_fetch_array($cek)){	
											echo"<option value = $r[customerid]>$r[customername] - $r[address]</option>";
										}
									?>

								  </select>
								</div>
								
								
								  <!-- Date dd/mm/yyyy -->
								  <div class="form-group">
									<label>Rencana Antar</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	
										$rencana = mysql_result(mysql_query("select antar from orders where billno = $_GET[id]"),0);
										echo"<input name ='antar' type='text' class='form-control' placeholder = 'dd-mm-yyyy' value = '$rencana'  data-mask>";
									?>
									</div><!-- /.input group -->
								  </div>
												
								<div class="form-group">
								  <label>Keterangan</label>
								  <textarea name='ket' class="form-control" rows="3" placeholder="Enter ..."><?php $ket = mysql_result(mysql_query("select keterangan from vorderdetails where billno = $_GET[id]"),0); echo "$ket"; ?></textarea>
								</div>
								
								<div class="form-group">
								  <label>Keterangan Untuk IDA</label>
								  <textarea name='ket2' class="form-control" rows="3" placeholder="Enter ..."><?php $ket2 = mysql_result(mysql_query("select ida from vorderdetails where billno = $_GET[id]"),0); echo "$ket2"; ?></textarea>
								</div>
		
							
							
							
							
								<?php
									if($st == "New"){
										echo"<button type='submit' class='btn btn-info'>Update Data</button>";
									}
									else{
										echo"<button type='submit' class='btn btn-info'>Update Keterangan</button>";
									}
								?>
							
						  </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 () {
        //Initialize Select2 Elements


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

        

      
      });
    </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();

       


        //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>
	
	<script type="text/javascript">
	
	function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode != 46 && charCode != 45 &&(charCode < 48 || charCode > 57)))
        return false;
    return true;
	}

function removeAllOptions(sel, removeGrp) {
    var len, groups, par;
    if (removeGrp) {
        groups = sel.getElementsByTagName('optgroup');
        len = groups.length;
        for (var i=len; i; i--) {
            sel.removeChild( groups[i-1] );
        }
    }
    
    len = sel.options.length;
    for (var i=len; i; i--) {
        par = sel.options[i-1].parentNode;
        par.removeChild( sel.options[i-1] );
    }
}

function appendDataToSelect(sel, obj) {
    var f = document.createDocumentFragment();
    var labels = [], group, opts;
    
    function addOptions(obj) {
        var f = document.createDocumentFragment();
        var o;
        
        for (var i=0, len=obj.text.length; i<len; i++) {
            o = document.createElement('option');
            o.appendChild( document.createTextNode( obj.text[i] ) );
            
            if ( obj.value ) {
                o.value = obj.value[i];
            }
            
            f.appendChild(o);
        }
        return f;
    }
    
    if ( obj.text ) {
        opts = addOptions(obj);
        f.appendChild(opts);
    } else {
        for ( var prop in obj ) {
            if ( obj.hasOwnProperty(prop) ) {
                labels.push(prop);
            }
        }
        
        for (var i=0, len=labels.length; i<len; i++) {
            group = document.createElement('optgroup');
            group.label = labels[i];
            f.appendChild(group);
            opts = addOptions(obj[ labels[i] ] );
            group.appendChild(opts);
        }
    }
    sel.appendChild(f);
}

// anonymous function assigned to onchange event of controlling select list
document.forms['demoForm'].elements['category'].onchange = function(e) {
    // name of associated select list
    var relName = 'choices[]';
	
	var relName2 = 'choices222[]';
    
    // reference to associated select list 
    var relList = this.form.elements[ relName ];
	
	var relList2 = this.form.elements[ relName2 ];
    
    // get data from object literal based on selection in controlling select list (this.value)
    var obj = Select_List_Data[ relName ][ this.value ];
	
	var obj2 = Select_List_Data2[ relName2 ][ this.value ];
    
    // remove current option elements
    removeAllOptions(relList, true);
	
	removeAllOptions(relList2, true);
    
    // call function to add optgroup/option elements
    // pass reference to associated select list and data for new options
    appendDataToSelect(relList, obj);
	appendDataToSelect(relList2, obj2);
};

// object literal holds data for optgroup/option elements
var Select_List_Data = {
    
    // name of associated select list
    'choices[]': {
        
        <?php
				$cek = mysql_query("Select * from categories  order by category asc");
				while ($r=mysql_fetch_array($cek)){	
				echo"$r[pk]: {
				
				text: [";
				
				$cek2 = mysql_query("Select * from products where category = '$r[pk]' order by code asc");
				while ($rr=mysql_fetch_array($cek2)){
					echo"'$rr[product] ',";
				}
				echo"],value: [";
				$cek3 = mysql_query("Select * from products where category = '$r[pk]' order by code asc");
				while ($rrr=mysql_fetch_array($cek3)){	
					echo"'$rrr[code]',";
				}

				echo"]
				},";
				
				}
		?>

        
    }

    
};




var Select_List_Data2 = {
    
    // name of associated select list
    'choices222[]': {
        
        <?php
				$salesman = $_SESSION['nama'];
				$cek = mysql_query("Select * from categories  order by category asc");
				while ($r=mysql_fetch_array($cek)){	
				echo"$r[pk]: {
				
				text: [";
				
				$cek2 = mysql_query("Select * from customers where sales = '$salesman' and produk = '$r[pk]'  order by customername asc");
				while ($rr=mysql_fetch_array($cek2)){
					echo"'$rr[customername] ',";
				}
				echo"],value: [";
				$cek3 = mysql_query("Select * from customers where sales = '$salesman' and produk = '$r[pk]'  order by customername asc");
				while ($rrr=mysql_fetch_array($cek3)){	
					echo"'$rrr[customerid]',";
				}

				echo"]
				},";
				
				}
		?>

        
    }

    
};

// populate associated select list when page loads
window.onload = function() {
    var form = document.forms['demoForm'];
    
    // reference to controlling select list
    var sel = form.elements['category'];
    sel.selectedIndex = 0;
	
	
	var sel2 = form.elements['category'];
    sel2.selectedIndex = 0;
    
    // name of associated select list
    var relName = 'choices[]';
    // reference to associated select list
    var rel = form.elements[ relName ];
	
	
	// name of associated select list
    var relName2 = 'choices222[]';
    // reference to associated select list
    var rel = form.elements[ relName2 ];
    
    // get data for associated select list passing its name
    // and value of selected in controlling select list
    var data = Select_List_Data[ relName ][ sel.value ];
	
	var data2= Select_List_Data2[ relName2 ][ sel2.value ];
    
    // add options to associated select list
    appendDataToSelect(rel, data);
	appendDataToSelect(rel2, data2);
};



//YM2




//YM2





function convert2() {    
 var price = 1;
 var selectedPrice = document.getElementById('choices');
 var currency = selectedPrice.options[selectedPrice.selectedIndex].text;
 var currencyValue = document.getElementById('choices').value; 



        newPrice = 0;

 //Display the new price to the user
 document.getElementById("txtValue").value = newPrice;
};
		   
function myFunction() {
	var selectedPrice = document.getElementById('choices');
	var currency = selectedPrice.options[selectedPrice.selectedIndex].text;
	var currencyValue = document.getElementById('choices').value; 
	
	var mySplitResult;
	mySplitResult = currency.split("@");
	for(i = 0; i < mySplitResult.length; i++)
           {
			newPrice =  mySplitResult[i];
           }
	newPrice = newPrice.trim();
	document.getElementById("txtValue").value = 0;
};
$('#qty').on('input', function() { 
	var UpriceOld = document.getElementById('txtValue').value;
	var Uprice;
	var Qty = document.getElementById('qty').value
	Uprice = UpriceOld.replace(".", "") ; 
	Uprice = UpriceOld.replace(".", "") ; 
	Uprice = Uprice * Qty;
    document.getElementById("txtTotal").value =  formatNumber(Uprice);
});
$('#txtValue').on('input', function() { 
	var UpriceOld = document.getElementById('txtValue').value;
	var Uprice;
	var Qty = document.getElementById('qty').value
	
	Uprice = UpriceOld.replace(".", "") ; 
	Uprice = UpriceOld.replace(".", "") ; 
	Uprice = Uprice * Qty;
    document.getElementById("txtTotal").value = formatNumber(Uprice);

});
function formatNumber(number)
{
    number = number.toFixed(0) + '';
    x = number.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

$('#cate').change(function() {
  myFunction();
});
</script>


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