<?php
if(basename($_SERVER['PHP_SELF']) == 'corder.php') 
  $fn=" class='current'";
$custo=$conde=$condi='';
include'connection.php';
$dato=$datos=$Date;
$dati=$Date;
$p=$i=0;

include'header.php';

if(isset($_POST['open']))
		{
			$code=$_POST['code'];
			
$dok=mysqli_query($conn, "SELECT *FROM `purchase` WHERE `Status` = '0' AND `Number` = '$code' ORDER BY `Number` ASC");	
    $rok=mysqli_fetch_assoc($dok);
			$code=$rok['Number'];
			$dati=$rok['Date'];
			$name=$rok['Supplier'];
			$invo=$rok['Invoice'];
	        $amo=number_format($rok['Amount'], 2);		
			$lcno=$rok['Lcno'];
			$item=$rok['Itemna'];
			$qty=number_format($rok['Quantity'], 2);           
			$unit=$rok['Unit'];
			$type=$rok['Type'];
			$purpo=$rok['Descri'];
			$conte=$rok['Container'];
			$wei=$rok['Weight'];
			$vous=$rok['Voucher'];
			$rate=number_format($rok['Rate'], 2);
			$inom=$rok['Itemno'];
		    }
		else
		    $code=$vous=0;
?>

<div class="container-fluid main-content">
        <div class="page-title hidden-xs hidden-print">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
         Finance
          </h2>
                 </div>
     
        <div class="row">
  <div class="col-lg-2 hidden-print">
   
   <ul class="list-group">  

    <li class="list-group-item">
	  <a href="salesrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Sales Report
                </p>
              </a></li> 

    <li class="list-group-item active">
	  <a href="purchase.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Purchase Orders
                </p>
              </a></li>   

    <li class="list-group-item">
	  <a href="trans.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Service Providers
                </p>
              </a></li> 

    <li class="list-group-item">
	  <a href="experepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Payout/Expenses
                </p>
              </a></li>  

    <li class="list-group-item">
	  <a href="zreport.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Daily Z-Report
                </p>
              </a></li>   

    <li class="list-group-item">
	  <a href="taxrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;VAT/TAX Report
                </p>
              </a></li>   

    <li class="list-group-item">
	  <a href="assets.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Assets Report
                </p>
              </a></li> 
                       
            </ul><br><br><br>
  </div>
  
  
  <?php
  //include'transc.php';
?>
       
        <div class="col-lg-10">
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">

	<?php
		if($_GET['pto']==10){
		    $dati=$_GET['dati'];
			$name=$_GET['name'];
			$invo=$_GET['invo'];
	        $amo=number_format($_GET['amo'], 2);		
			$lcno=$_GET['lcno'];
			$item=$_GET['item'];
			$qty=number_format($_GET['qty'], 2);           
			$unit=$_GET['unit'];
			$type=$_GET['type'];
			$purpo=$_GET['purpo'];
			$conte=$_GET['conte'];
			$code=$_GET['code'];
			$rate=$_GET['rate'];
			$vous=$_GET['vous'];
			$inom=$_GET['inom'];
			$wei=number_format($_GET['wei']);
		print("<center><div class='alert alert-danger' style='border-radius:5px; width:60%; float:center; height:30px; padding-top:5px; text-align:center;'><i class='lnr lnr-sad'></i><button class='close' data-dismiss='alert' type='button'>&times;</button> &nbsp; Item not found, please try again [<b>$item</b>].	</div></center>");
	    }
   echo"<form action='purchase.php' method='post'><div class='form-group'>
			<div class='col-md-1'> </div><div class='col-md-3' align='right'> 
    <label class='control-label' style='padding-top:10px;'>Due Date</label>
        </div>
            <div class='col-md-4'>
        <div class='input-group date' data-provide='datepicker'>	
      <input class='form-control form-center' name='dati' type='text' value='$dati' onkeypress='return isNumberKey(event)' required>
	  <span class='input-group-addon'><i class='lnr lnr-calendar-full'></i></span></div>
            </div></div>
		<div class='row'> </div>
		
		<div class='form-group'><div class='col-md-1'> </div>
			<div class='col-md-3' align='right'> 
    <label class='control-label' style='padding-top:10px;'>Supplier`s Name</label>
        </div>
            <div class='col-md-4'>
<input name='name' class='form-control' type='text' OnKeyup='return cUpper(this);' value='$name' id='searcha' autocomplete='off'>
            </div></div>
		<div class='row'> </div>
		
		<div class='form-group'><div class='col-md-1'> </div>
			<div class='col-md-3' align='right'> 
    <label class='control-label' style='padding-top:10px;'>Invoice Number</label>
        </div>
            <div class='col-md-4'>
<input name='invo' class='form-control text-center' OnKeyup='return cUpper(this);' type='text' value='$invo' id='searchu'>
            </div></div>
		<div class='row'> </div>
		
		<div class='form-group'><div class='col-md-1'> </div>	 
			  <div class='col-md-3' align='right'>
			  <label class='control-label' style='padding-top:10px;'>DMC&nbsp;No/Container </label></div>	

	 <div class='col-md-2'>
          <input name='lcno' class='form-control text-center' type='text' value='$lcno'>
            </div><div class='col-sm-2' style='padding-left:0px; margin-left:0px;'>
	    
	    <select class='form-control' name='conte' title='Container' data-toggle='tooltip' data-placement='top' style='margin-left:0px;' required>
	    <option value='' selected='selected'></option>";
		    
		    if($conte=='40FT'){
		        $f='selected';
		        $t=$l='';
		    }
		    if($conte=='20FT'){
		        $f=$l='';
		        $t='selected';
		    }
		    if($conte=='FLAT'){
		        $f=$t='';
		        $l='selected';
		    }
			echo"<option value='20FT' $t> 20FT </option><option value='40FT' $f> 40FT </option><option value='FLAT' $l> FLAT </option>";
			
		   echo"</select></div>
		</div>
	
		<div class='row'> </div>
		
			<div class='form-group'><div class='col-md-1'> </div>
			<div class='col-md-3' align='right'> 
    <label class='control-label' style='padding-top:10px;'>Item Name</label>
        </div>
            <div class='col-md-4'>
<input name='item' class='form-control' id='searchi' type='text' value='$item'>
            </div></div>
		<div class='row'> </div>
		
		<div class='form-group'><div class='col-md-1'> </div>
			  <div class='col-md-3' align='right'>
			  <label class='control-label' style='padding-top:10px;'>Quantity/Unit </label></div>	

	 <div class='col-md-2'>
          <input name='qty' class='form-control text-center' type='text' onkeyup='format(this);' value='$qty' onkeypress='return isNumberKey(event)' required>
            </div><div class='col-sm-2' style='padding-left:0px; margin-left:0px;'>
	    
	    <select class='form-control' name='unit' title='Count Unit' data-toggle='tooltip' data-placement='top' style='margin-left:0px; padding-left:2px; padding-right:2px;' required>
	    <option value='' selected='selected'>UNIT</option>";
		    
		    if($unit=='SQM'){
		        $sq='selected';
		        $pc=$st=$sh=$ct='';
		    }
		    if($unit=='PCS'){
		        $sq=$st=$sh=$ct='';
		        $pc='selected';
		    }
		    if($unit=='SET'){
		        $sq=$pc=$sh=$ct='';
		        $st='selected';
		    }
		    if($unit=='CTN'){
		        $sq=$pc=$st=$sh='';
		        $ct='selected';
		    }
		    if($unit=='SHEET'){
		        $sq=$pc=$st=$ct='';
		        $sh='selected';
		    }
		    
			echo"<option value='SQM' $sq> SQM </option>
			<option value='PCS' $pc> PCS </option>
			<option value='SET' $st> SET </option>
			<option value='CTN' $ct> CTN </option>
			<option value='SHEET' $sh> SHEET </option>";
			
		   echo"</select></div>
		</div>
		
		<div class='row'> </div>
		
			<div class='form-group'><div class='col-md-1'> </div>
			<div class='col-md-3' align='right'> 
    <label class='control-label' style='padding-top:10px;'>Total Weight</label>
        </div>
            <div class='col-md-3'>
           <div class='input-group'>
<span class='input-group-addon' style='width:15%; text-align:center; padding-left:0px; padding-right:0px;'> KG </span>	
      <input class='form-control form-center' name='wei' value='$wei' class='form-control text-center' onkeyup='format(this);' onkeypress='return isNumberKey(event)' type='text' required></div>
</div></div><div class='col-md-1 text-center text-warning'><b>RATE</b></div>
	
		<div class='row'> </div>
		
			<div class='form-group'><div class='col-md-1'> </div>
			<div class='col-md-3' align='right'> 
    <label class='control-label' style='padding-top:10px;'>Total Amount</label>
        </div>
            <div class='col-md-3'><div class='input-group'>
<span class='input-group-addon' style='width:15%; text-align:center; padding-left:0px; padding-right:0px;'> $ </span>	
      <input class='form-control form-center' name='amo' class='form-control text-center' onkeyup='format(this);' onkeypress='return isNumberKey(event)' type='text' value='$amo' required></div>
    </div><div class='col-md-1' style='padding-left:0px;'><input class='form-control form-center' name='rat' value='$rate' class='form-control text-center' onkeyup='format(this);' onkeypress='return isNumberKey(event)' type='text' style='padding-left:4px; padding-right:4px;' required></div></div>
              
		<div class='row'> </div>
		
			<div class='form-group'><div class='col-md-1'> </div>
			<div class='col-md-3' align='right'> 
    <label class='control-label' style='padding-top:10px;'>Purchase Type</label>
        </div>
            <div class='col-md-4'>
	    
	    <select class='form-control' name='type' title='Purchase Type' data-toggle='tooltip' data-placement='top' style='margin-left:0px;' required><option value='' selected='selected'></option>";
		    
		    if($type=='LOCAL'){
		        $c='selected';
		        $e=$o='';
		    }
		    if($type=='EAC'){
		        $e='selected';
		        $c=$o='';
		    }
		    if($type=='OVERSEASE'){
		        $o='selected';
		        $e=$c='';
		    }
			echo"<option value='LOCAL' $c> LOCAL PURCHASE </option><option value='EAC' $e> EAC PURCHASE </option><option value='OVERSEASE' $o> OVERSEASE </option>";
			
		   echo"</select></div></div>
		<div class='row'> </div>
			 	
		 <div class='form-group'><div class='col-md-1'> </div>	 
			  <div class='col-md-3' align='right'>
			  <label class='control-label' style='padding-top:10px;'>Purpose/Comment</label></div>	

	 <div class='col-md-4'>
          <textarea name='purpo' class='form-control' type='text'>$purpo</textarea>
            </div>
		</div><div class='row'> </div>
		
	</div><hr><input type='hidden' name='p' value='$p'><input type='hidden' name='vous' value='$vous'><input type='hidden' name='inom' value='$inom'> ";
	
	if($code=='0')
	    echo"<center><button type='button' class='btn btn-xs btn-danger' data-dismiss='modal' style='width:160px; height:36px;' onclick=location.href='purchase.php'><i class='lnr lnr-chevron-left-circle'></i> CANCEL </button><button type='submit' name='addo' class='btn btn-xs btn-success' style='width:160px; height:36px;'><i class='lnr lnr-checkmark-circle'></i> SAVE </button></center>";
    else
	    echo"<center><button type='button' class='btn btn-xs btn-danger' data-dismiss='modal' style='width:160px; height:36px;' onclick=location.href='purchase.php'><i class='lnr lnr-chevron-left-circle'></i> CANCEL </button><input type='hidden' name='code' value='$code'>
        <button type='submit' name='updo' class='btn btn-xs btn-success' style='width:160px; height:36px;'><i class='lnr lnr-checkmark-circle'></i> UPDATE </button></center></form>";
?>
            <br></div></div>
                  </div>
   <?php
   include'footer.php';
   ?>