<!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>
            View Purchase
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="data.php">Purchase</a></li>
            <li class="active"><?php echo"<a href='edit.php?id=$_GET[id]'>"; ?>View Purchase</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 Purchase</h3>
						</div><!-- /.box-header -->
						<!-- form start -->
						
						  <div class="box-body">
							
							
							<div class="form-group">
							  <label>Tanggal Input</label>
								<?php
									$billdate = mysql_result(mysql_query("select billdate from buy where billno = $_GET[id]"),0);
									$dt1 =date_format(date_create($billdate),"d-m-Y");
									echo"<input type='text' class='form-control' name = 'sls' value='$dt1' disabled>";
								?>
							</div>
							
							<div class="form-group">
							  <label>Supplier</label>
								<?php
									$cust = mysql_result(mysql_query("select nama from supplier where id = (select cust from buy where billno = $_GET[id])"),0);
									echo"<input type='text' class='form-control' name = 'cust' value='$cust' disabled>";
								?>
							</div>

						  </div><!-- /.box-body -->

						
						
						
						
						
						
						
						
					  </div><!-- /.box -->

					  
					 </div><!-- /.box -->
					 
					 <div class="col-md-6">
              <!-- Horizontal Form -->
              <div class="box box-info">
                <div class="box-header with-border">
                  <h3 class="box-title">Keterangan PO</h3>
                </div><!-- /.box-header -->
                <!-- form start -->
                <?php echo"
				<form id='demoForm' name=form method=POST action='aksisales.php?module=sales&act=editket&id=$_GET[id]' class='form-horizontal'>"; 
				?>	
                  <div class="box-body">
                    <div class="form-group">
                      <label for="inputEmail3" class="col-sm-2 control-label">Keterangan</label>
                      <div class="col-sm-10">
                        <textarea name='ket' class="form-control" rows="5" placeholder="Enter ..."><?php $ket = mysql_result(mysql_query("select ket from buy where billno = $_GET[id]"),0); echo "$ket"; ?></textarea>
                      </div>
                    </div>
                  </div><!-- /.box-body -->
				  
				 
                </form>
              </div><!-- /.box -->
             
            </div><!--/.col (right) -->
			
			
			
					
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col -->
			
			<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>Total</th>
									</tr>
								  </thead>
								  <tbody>
									<?php
										$user = $_SESSION['nama'];
										$cek = mysql_query("Select * from buydetail where billno = $_GET[id] order by id asc");

										while ($r=mysql_fetch_array($cek)){	
											$id = $r['id'];
											$harga = format_rupiah($r['harga2']);
											$qty = format_rupiah($r['qty']);
											$grand = format_rupiah($r['qty'] * $r['harga2']);
											$produk = mysql_result(mysql_query("select produk from produk where id = $r[produk]"),0);
											echo "<tr>
												  <td>&nbsp; $produk</td>
												  <td>$qty</td>
												  <td>$harga</td>
												  <td align = 'right'>$grand</td>
												</tr>";
										}
									?>
									
								  </tbody>
								</table>
							  </div><!-- /.table-responsive -->
							</div><!-- /.box-body -->
							<div class="box-footer clearfix">
							  <a href="pages/service/data.php" class="btn btn-sm btn-default btn-flat pull-right">
								<?php
									$grandt = format_rupiah(mysql_result(mysql_query("select sum(qty * harga2) from buydetail where billno = $_GET[id] "),0));
									echo"Grand Total : $grandt";
								?>
							  </a>
							</div>	
			
          </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 
	}
?>