<?php

$PONO = '';
$POType = '';
$PODate= '';
$SupplierName = '';
$Address = '';
$SpecialOrder = '';
$Username = '';
$RequesterEmail = '';
$RequesterPh = '';
$RequestedDate = '';
$BudgetManager = '';
$BudgetManagerDepartment  = '';
$PurchasingCategory  = '';
$PurchasingJustification  = '';
$OrderValue  = '';
$DiscountType  = '';
$DiscountValue  = '';
$PackagingType  = '';
$PackagingValue  = '';
$ExciseDuty  = '';
$Vat  = '';
$Freight  = '';
$SupplierName  = '';
$Address  = '';
$BasicValue = '';
$AfterDiscount = '';
$AfterPackaging = '';
$AferExciseduty = '';
$txtAfterVat = '';							

if(!empty($PODetail))
{
    foreach ($PODetail as $PO)
    {
        $PONO = $PO->PONO;
        $POType = $PO->POType;
        $PODate = $PO->PODate;
        $SupplierName = $PO->SupplierName;
        $SpecialOrder  = $PO->SpecialOrder;
        $Username  = $PO->usrName;
        $RequesterEmail =$PO->RequesterEmail;
        $RequesterPh = $PO->RequesterPh;
		$RequestedDate = $PO->RequestedDate;
		$BudgetManager= $PO->BudgetManager;
		$BudgetManagerDepartment = $PO->BudgetManagerDepartment;
		$PurchasingCategory = $PO->PurchasingCategory;
		$PurchasingJustification = $PO->PurchasingJustification;
		$OrderValue = $PO->OrderValue;
		$DiscountType= $PO->DiscountType;
		$DiscountValue= $PO->DiscountValue;
		$PackagingType = $PO->PackagingType;
		$PackagingValue= $PO->PackagingValue;
		$ExciseDuty= $PO->ExciseDuty;
		$Vat  = $PO->Vat;
		$Freight  = $PO->Freight;		
		$Address = $PO->Address;
		$BasicValue = $PO->basicvalue;
		$AfterDiscount = $PO->AfterDiscount;
		$AfterPackaging = $PO->AfterPackaging;
		$AferExciseduty = $PO->AfterExciseduty;
		$txtAfterVat = $PO->AfterVat;
    }
}


?>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <center>
			<h1><b>Purchase Order - <?php echo $PONO ?> </b> </h1>
	  </center>
	           
    </section>
    
    <section class="content">
      
	<div style="text-align: right;">
	 
      <a href="<?php echo base_url().'C_test/create_pdf/?PO='.$PONO; ?>" target="_blank"/><button type="button" class="btn btn-info">Print</button></a>
	<a href="<?php echo base_url(); ?>purchaseorderListing" >  <button class="btn btn-info">Back</button></a>
	</div>
 <br/>
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
              <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header">
					                   
                    <form role="form" id="addUser" action=""  name="addUser"  method="post" role="form">
                        <div class="box-body">
                            <div class="row">
                                <div class="col-md-6">                                
                                    <div class="form-group">
                                        <label for="PO_Type">PO Type</label>
                                         <select  readonly class="form-control" name="PO_Type" required>
											<option value="<?php echo $POType;?>"><?php echo $POType;  ?> </option>                                                           
										</select>
                                    </div>                                    
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="PO_Date">PO Date</label>
                                        <input type="input" name="PO_Date"  readonly  value="<?php echo  $PODate; ?>" class="form-control" placeholder="" />
                                    </div>
                                </div>
								
                            </div>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="SupplierID">Supplier Name</label>
										 <select class="form-control required" id="SupplierID" readonly  name="SupplierID">
                                            <option value="<?php echo $SupplierName; ?>" ><?php echo  $SupplierName;   ?>  </option>							
										 
                                         </select>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="SupplierAddress">Supplier's Address</label>
                                        <textarea name="comment" id="SupplierAddress" form="addUser" value="<?php echo $Address; ?>"  class="form-control required" readonly ></textarea>
                                    </div>
                                </div>
								
                            </div>							
                           <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="role">Requested By</label>
                                        <select class="form-control required" id="role" name="role" readonly>
                                            <option  value="<?php echo   $Username;?>" ><?php echo   $Username; ?></option>
                                            
                                        </select>
                                    </div>
                                </div>
								
								<div class="col-md-6 ">
                                    <div class="form-group">
                                        <label for="re_email">Requester Email</label>
                                        <input type="text" class="form-control required" readonly value="<?php echo   $RequesterEmail; ?>"  id="re_email" name="re_email">
                                    </div>
                                </div>
							
							 </div>
                         <div class="row">
						<div class="col-md-6 ">
                                    <div class="form-group">
                                        <label for="re_phone">Requesters Phone</label>
                                        <input type="text" class="form-control required digits" readonly id="re_phone" maxlength="12" value="<?php echo  $RequesterPh;?>"  name="re_phone">
                                    </div>
                                </div>
						<div class="col-md-6">
                                    <div class="form-group">
                                        <label for="re_Date">Requested Date</label>
                                        <input type="input" name="re_Date" readonly  value="<?php echo $RequestedDate; ?>" class="form-control" placeholder="" />
                                    </div>
                                	</div>
						</div>
						 <div class="row">
						<div class="col-md-6">                                
                                    <div class="form-group">
                                        <label for="bud_manager">Budget Manager</label>
                                         <select  class="form-control" id="BudgetManager" readonly name="bud_manager" required  onchange="SelectedDepartment()" >
											<option value="<?php echo $BudgetManager; ?>" ><?php echo  $BudgetManager; ?> </option>
                                                                    
                              
                            </select>
                                    </div>
                                    
                                </div>
								
						<div class="col-md-6">                                
                                    <div class="form-group">
                                        <label for="bud_manager_de">Budget Manager Department</label>
                                         <input type="text"  readonly id="BudgetManagerDepartment" value="<?php echo $BudgetManagerDepartment; ?>"  class="form-control required" name="BudgetManagerDepartment"  readonly>
                                    </div>                                    
								</div>
								
								</div>
								 <div class="row">
						<div class="col-md-6">                                
                                    <div class="form-group">
                                        <label for="Pur_category">Purchasing Category</label>
                                         <select readonly  class="form-control" id="Pur_category"  name="Pur_category" required>
                                               <option value="<?php echo  $PurchasingCategory; ?>" ><?php echo $PurchasingCategory; ?></option>
                             
												
                                             </select>
                                    </div>
                                    
                                </div>
								 <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="SpecialOrder">Special Requirement of order</label>
                                        <input type="text" readonly class="form-control required" value="<?php echo  $SpecialOrder;  ?>"  id="SpecialOrder" name="SpecialOrder" maxlength="500">
                                    </div>
                                </div>
								</div>								
								<div >                                
                                    <div>
                                        <label for="Justification">Justification for the Purchase</label>
										<textarea name="comment" readonly id="Justification" value="<?php echo $PurchasingJustification;  ?>"  form="addUser" class="form-control required" ></textarea>
                                         
                                    </div>                                    
								</div>
								
								</div>
						</div>
						
						<div>	
					
					<div class="col-md-12" ><b><u>Purchase Order Line Item : </u><b> </div>	
					<div class="col-xs-12 text-right">
                <div >
				 
					
                </div>
            </div>
					<div class="col-md-12" style="border:1px solid #000">
					
					<table  id="POLineItem" class="table table-hover"  cellpadding="10" >
                    <tr  style="background-color:powderblue;">
                      <th text-align="center" nowrap >Product Description</th>
                      <th text-align="center" nowrap>UOM</th>
                      <th text-align="center" nowrap >Quantity</th>
                      <th text-align="center" nowrap >Unit Price</th>
                      <th text-align="center" nowrap>Product Amount</th>
                      
                    </tr>
					 <tbody id="tempAppend"> 
							<?php	$TotalAmount = 0.00;
                            						
                            if(!empty($POLineItem))
                                            {
                                                
												foreach ($POLineItem as $us)
                                                {
												 ?>
												 <tr border="1">
												 <td align="left"><?php echo $us->materialName?></td>
												 <td align="left"><?php echo $us->UOM ?></td>												 
												 <td align="left"><?php echo $us->Quantity ?></td>
												 <td align="left"><?php echo $us->UnitPrice ?></td>
												 <td align="left"><?php echo $us->ProductPrice ?></td>
												
												  </tr>
												  <?php 
												}
											}	
									?>											
                      </tbody>  
						 				
					</table>
					        <div class="col-md-12" style="border:1px solid #000">
								
								<div class="col-md-6 ">
									<label for="Basic_Value">Basic Value : </label>
								</div>
								 <div class="col-md-3 ">&nbsp;</div>
									<div class="col-md-3 ">
											<div class="form-group">                                        
                                        <input type="text" class="form-control required digits" style="float:left; text-align:left" value= "<?php echo $BasicValue ?>"  id="BasicValue" readonly  name="BasicValue">
                                    </div>
                                </div>							
								
								<div class="col-md-6 ">
										<label for="Discount_Value">Discount : </label>
								</div>
						<div class="col-md-3 ">
                                    <div class="form-group">                                        
                                          <input type="text" class="form-control required digits" style="float:left; text-align:left" value= "<?php echo $DiscountType ?>"  id="Discountype" readonly  name="Discountype">
                                    </div>
                                </div>
								<div class="col-md-3 ">
                                    <div class="form-group">                                        
                                        <input type="number" class="form-control required digits" id="txtDiscount" value= "<?php echo $DiscountValue; ?>"   style="float:left; text-align:left"  name="txtDiscount">
                                    </div>
                                </div>
								
								<div class="col-md-6 ">
									<label for="AfterDiscount_Value">After Discount : </label>
								</div>
								 <div class="col-md-3 ">&nbsp;</div>
								<div class="col-md-3 ">
                                    <div class="form-group">                                        
                                        <input type="text" class="form-control required digits" value= "<?php echo $AfterDiscount ?>"    id="AfterDiscount" maxlength="12" readonly  name="AfterDiscount">
                                    </div>
                                </div>
								
								<div class="col-md-6 ">
									<label for="Packaging">Packaging : </label>
								</div>
								<div class="col-md-3 ">
                                    <div class="form-group">                                        
                                         <input type="text" class="form-control required digits" style="float:left; text-align:left" value= "<?php echo $PackagingType ?>"  id="Discountype" readonly  name="Discountype">
                                    </div>
                                </div>
								<div class="col-md-3 ">
                                    <div class="form-group">                                        
                                        <input type="number" class="form-control required digits" value= "<?php echo $PackagingValue; ?>"  id="txtPackaging" style="float:left; text-align:left"   name="txtPackaging">
                                    </div>
                                </div>
								
								<div class="col-md-6 ">
									<label for="AfterPackaging">After Packaging : </label>
								</div>
					            <div class="col-md-3 ">&nbsp;</div>
								<div class="col-md-3 ">
                                    <div class="form-group">                                        
                                        <input type="input" class="form-control required digits" readonly id="AfterPackaging" style="float:left; text-align:left"  value= "<?php echo $AfterPackaging; ?>" name="AfterPackaging">
                                    </div>
                                </div>
								
								<div class="col-md-6 ">
									<label for="ExciseDuty">Excise duty @ 12.5% : </label>
								</div>
								 <div class="col-md-3 ">&nbsp;</div>
									<div class="col-md-3 ">
                                    <div class="form-group">                                        
                                        <input type="number"  value= "<?php echo $ExciseDuty; ?>"  class="form-control required digits" id="Exciseduty" style="float:left; text-align:left"  name="Exciseduty">
                                    </div>
                                </div>
								
								<div class="col-md-6 ">
									<label for="AfterExciseDuty">After Excise duty : </label>
								</div>
					            <div class="col-md-3 ">&nbsp;</div>
								<div class="col-md-3 ">
                                    <div class="form-group">                                        
                                        <input type="input"  class="form-control required digits" id="AferExciseduty" readonly style="float:left; text-align:left" value= "<?php echo $AferExciseduty; ?>"   name="AferExciseduty">
                                    </div>
                                </div>
								
								<div class="col-md-6 ">
									<label for="Vat">Vat	 : </label>
								</div>
								<div class="col-md-3 ">&nbsp;</div>
								<div class="col-md-3 ">
                                    <div class="form-group">                                        
                                        <input type="number" value= "<?php echo $Vat; ?>"  class="form-control required digits" id="txtVat" style="float:left; text-align:left"  name="txtVat">
                                    </div>
                                </div>
								
								<div class="col-md-6 ">
									<label for="AfterVat">After Vat	 : </label>
								</div>
								<div class="col-md-3 ">&nbsp;</div>
								<div class="col-md-3">
                                    <div class="form-group">                                        
                                        <input type="input" class="form-control required digits" readonly id="txtAfterVat" style="float:left; text-align:left"  name="txtAfterVat" value= "<?php echo $txtAfterVat; ?>"  >
                                    </div>
                                </div>
								 
								<div class="col-md-6 ">
									<label for="Freight">Freight	 : </label>
								</div>
									<div class="col-md-3 ">&nbsp;</div>
								<div class="col-md-3 ">
                                    <div class="form-group">                                        
                                        <input type="number" value= "<?php echo $Freight; ?>"  class="form-control required digits" id="txtFreight" style="float:left; text-align:left"  name="txtFreight">
                                    </div>
                                </div>
								
								<div class="col-md-6 ">
									<label for="Total_Order_Value ">Total Order Value : </label>
									</div>
									<div class="col-md-3 ">&nbsp;</div>
									<div class="col-md-3 ">
                                    <div class="form-group">                                        
                                        <input type="number" class="form-control required digits" style="float:left; text-align:left"   id="txtOrderValue" readonly  name="txtOrderValue"  value= "<?php echo $OrderValue; ?>">
                                    </div>
                                </div>
								  </div>
						</div><!-- /.box-body -->
						
						
                        <div class="box-footer" align="right" style="padding-top:17%;">
						  <input type="hidden" name="PONO" id="PONO" />
                            <input type="submit" id="btnSubmit"   class="btn btn-primary" value="OK" />
                           </div>
                    </form>
                
            </div>
            <div class="col-md-4">
                <?php
                    $this->load->helper('form');
                    $error = $this->session->flashdata('error');
                    if($error)
                    {
                ?>
                <div class="alert alert-danger alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <?php echo $this->session->flashdata('error'); ?>                    
                </div>
                <?php } ?>
                <?php  
                    $success = $this->session->flashdata('success');
                    if($success)
                    {
                ?>
                <div class="alert alert-success alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <?php echo $this->session->flashdata('success'); ?>
                </div>
                <?php } ?>
                
                <div class="row">
                    <div class="col-md-12">
                        <?php echo validation_errors('<div class="alert alert-danger alert-dismissable">', ' <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); ?>
                    </div>
                </div>
            </div>
        </div>    
    </section>    
</div>


</div>
<script>
function SelectDiscountType(){
	var selValue = $("option:selected", $("#DiscountType")).text()
	//alert(selValue);
	if (selValue =='Nil')
	{
		//alert('Inside if');
		 document.getElementById('txtDiscount').disabled = true;
		 document.getElementById('txtDiscount').value = '0.00';
	}
	else
	{
		//alert('Inside else if');
		 document.getElementById('txtDiscount').disabled = false;
	}
}

function SelectPackagingType(){
	var selValue = $("option:selected", $("#PackagingType")).text()
	
	if (selValue =='Nil')
	{
		
		 document.getElementById('txtPackaging').disabled = true;
		 document.getElementById('txtPackaging').value = '0.00';
	}
	else
	{
		
		 document.getElementById('txtPackaging').disabled = false;
	}
}
</script>
<script src="<?php echo base_url(); ?>assets/js/addUser.js" type="text/javascript"></script>