 

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <center>
			<h1><b>Purchase Order</b> </h1>
	  </center>
	    
                     
    </section>
    
    <section class="content">
    <div style="text-align:right;">
    <a href="<?php echo base_url() ?>purchaseorderListing" class="btn btn-info" value="Back"/>Back</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">
					<!--<center>
                        <h3 class="box-title">Purchase Order</h3>
					</center>
                    </div><!-- /.box-header -->
                    <!-- form start -->
					  <?php
                      $attributes = array('class' => 'form-label-left addPO ','name'  => 'addPO','id'  => 'addPO');
                        
                        echo form_open($this->config->base_url().'/purchaseorder/addPO/',$attributes); ?>
                   
                        <div class="box-body">
                            <div class="row">
                                <div class="col-md-6">                                
                                   <div class="form-group">
                                        <label for="PO_Type">Purchase Order Type</label>&nbsp;&nbsp;<font color="Red">*</font> 
										</div>
										<div class="form-control">
										 <?php
									    $options = array("0"=>'Select Purchase Order Type');
										//print_r(  $options);
										
										if(!empty($POType))
										{
									    foreach ($POType as $PO):
                                          
									      $options[$PO->ConfigValue] =  $PO->ConfigValue;

										endforeach;
										}										
							
								echo form_dropdown('PO_Type', $options,set_value('PO_Type'),'id="PO_Type"' ,'class="form-control"','required="true"');
            
								?>
                                        
                                    </div> 




									
                                </div>
                                <div class="col-md-6">
								 <div class="form-group">
									<label for="Departure_Date"> Purchase Order Date</label> 
									</div>
									<div class="form-group">
									<?php
                                         $data = array('name' => 'PO_Date',  'value' => set_value('PO_Date'),'id'=>'PO_Date',  'class' =>  'form-control datePicker','required'=>'true');
                                        echo form_input($data);
                                        ?>   
                                </div>
								 </div>
                            </div>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="SupplierID">Supplier Name</label> &nbsp;&nbsp;<font color="Red">*</font> 
										<div class="form-control">
										 <?php
									    $options = array("0"=>'Select Supplier');
										//print_r(  $options);
										
										if(!empty($POType))
										{
									    foreach ($SupplierName as $SID):
                                          
									   
										  $options[$SID->SupplierID] =  $SID->SupplierID.' '.' - '.' '.$SID->SupplierName;

										endforeach;
										}										
							
								echo form_dropdown('SupplierID', $options,set_value('SupplierID'),'id="SupplierID"' ,'class = "form-control required"','required="true"');
            
								?>
										 
                                    </div>
                                </div>
								 </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="SupplierAddress">Supplier's Address</label>
										</div>
										<div class="form-group">
									<?php
                                         $data = array('name' => 'SupplierAddress','value' => set_value('SupplierAddress'),'id'=>'SupplierAddress',  'class' => 'form-control' ,'readonly' => 'true');
                                        echo form_input($data);
                                        ?>   
                                </div>											
													
                                    </div>
                                </div>
								
                            </div>							
                           <div class="row">
                                <div class="col-md-6">
                                   <div class="form-group">
                                        <label for="role">Requested By</label> &nbsp;&nbsp;<font color="Red">*</font> 
										</div>
										<div class="form-control">
										  <?php
									    $options = array("0"=>'Select Requested By');
										//print_r(  $options);
										
										if(!empty($users))
										{
									    foreach ($users as $UID):
                                          
									   
										  $options[$UID->userId] =  $UID->userId.' '.'-'.' '.$UID->name;

										endforeach;
										}										
							
								echo form_dropdown('role', $options,set_value('role'),'id="role"','class = "form-control "','required="true"');
            
								?>
                                       
                                    </div>
                                </div>
								
								<div class="col-md-6 ">
                                   <div class="form-group">
                                        <label for="re_email" >Requester Email</label> 
										</div>
										 <div class="form-group">
<?php
                                         $data = array('name' => 're_email', 'value' => set_value('re_email'),'id'=>'re_email', 'class' => 'form-control email', 'onchange'=>'validateEmail()');
                                        echo form_input($data);
                                        ?>   
										
										
                                    </div>
                                </div>
							
							 </div>
                         <div class="row">
						<div class="col-md-6 ">
                                   <div class="form-group">
                                        <label for="re_phone">Requesters Phone</label> &nbsp;&nbsp;<font color="Red">*</font> 
										</div>
										 <div class="form-group">
										 <?php
                                         $data = array('name' => 're_phone','value' => set_value('re_phone'),  'class' => 'form-control required re_phone','onkeypress'=>'return event.charCode >= 48 && event.charCode <= 57', 'maxlength' => '12', 'id'=>'re_phone','required'=>'true');
                                        echo form_input($data);
                                        ?>  	
										
																		
                                       
                                    </div>
                                </div>
						<div class="col-md-6">
						   <div class="form-group">
									<label for="Departure_Date"> Requested Date</label> <font color="Red">*</font>
									</div>
									<div class="form-group">
									<?php
                                         $data = array('name' => 're_Date', 'value' => set_value('re_Date'),'id'=>'re_Date', 'class' => 'form-control datePicker chechDate re_Date','required'=>'true');
                                        echo form_input($data);
                                        ?>    </div> 
                                </div>
                                   
						</div>
						 <div class="row">
						<div class="col-md-6">                                
                                    <div class="form-group">
                                        <label for="bud_manager">Budget Manager</label> &nbsp;&nbsp;<font color="Red">*</font> 
										</div>
										<div class="form-control">
										 <?php
									    $options = array("0"=>'Select Budget Manager');
										//print_r(  $options);
										
										if(!empty($EmpList))
										{
									    foreach ($EmpList as $EID):
                                          
									      $options[$EID->EmpID] = $EID->EmpID .' - '.$EID->FirstName.' '.','.' '.$EID->LastName;

										endforeach;
										}		
											
											echo form_dropdown('BudgetManager', $options,set_value('BudgetManager'),'id="BudgetManager"','class = "form-control "','required="true"','onchange="SelectedDepartment()"');									
							
								
            
								?>
                                         
                                    </div>                                    
                                </div>
								
						<div class="col-md-6">                                
                                     <div class="form-group">
                                        <label for="bud_manager_de">Budget Manager Department</label> 
										</div>
										<div class="form-group">
										<?php
                                         $data = array('name' => 'BudgetManagerDepartment',  'value' => set_value('BudgetManagerDepartment'),'id'=>'BudgetManagerDepartment','class' => 'form-control ', 'readonly'=>'true');
                                        echo form_input($data);
                                        ?>  																	 
                                        
                                    </div>                                    
								</div>
								
								</div>
								 <div class="row">
						<div class="col-md-6">                                
                                    <div class="form-group">
                                        <label for="Pur_category">Purchasing Category</label></div>
										<div class="form-control">
										 <?php
									    $options = array("0"=>'Select Purchase Order Type');
										//print_r(  $options);
										
										if(!empty($PurchasingCategory))
										{
									    foreach ($PurchasingCategory as $PC):
                                          
									      $options[$PC->ConfigValue] =  $PC->ConfigValue;

										endforeach;
										}										
							
								echo form_dropdown('Pur_category',$options,set_value('Pur_category'),'id="Pur_category"', 'class = "form-control "');
            
								?>
                                        
                                    </div>
                                    
                                </div>
								 <div class="col-md-6">
                                   <div class="form-group">
                                        <label for="SpecialOrder">Special Requirement of order</label>
										</div>
										<div class="form-group">
										<?php
                                         $data = array('name' => 'SpecialOrder','value' => set_value('SpecialOrder'),'id'=>'SpecialOrder',  'class' => 'form-control ', 'required'=>'true','maxlength'=>'500');
                                        echo form_input($data);
                                        ?>  
										
										                                        
                                    </div>
                                </div>
								</div>								
								<div >                                
                                    <div class="form-group">
                                        <label for="Justification">Justification for the Purchase</label>
										</div>
										<div class="form-group">
										<?php
                                         $data = array('name' => 'Justification', 'value' => set_value('Justification'),'id'=>'Justification', 'class' => 'form-control ', 'required'=>'false','maxlength'=>'4000');
                                        echo form_input($data);
                                        ?>  
											
                                    </div>                                    
								</div>
								
								</div>
						</div>
						
						<div>	
					
					<div class="col-md-12" ><b><u>Purchase Order Line Item : </u><b> </div>	
					<div class="col-xs-10 col-md-12">
                <div >
				          
					 <div class="col-md-2 col-md-offset-10" style="padding-bottom:1%">
						 <a data-toggle="modal" href="#myModal1" class="btn btn-primary"><i class="fa fa-plus"></i>Add PO Line Item</a>
						 </div>
							<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
							<div class="modal-dialog">
							<div class="modal-content">
							<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
							<h4 class="modal-title" align="Center"><b>Add Purchase Order Line Item</b></h4>
							</div>
							<div class="modal-body">
						<!--<form role="form" action="<?php echo base_url() ?>purchaseorder/addNewPOLineItem" method="post" id="AddPOLineItem" role="form"> -->
                        <div class="box-body">
                            <div class="row">
                                <div >                                
                                                                 
                                    <div class="form-group">
                                        <label for="ProductDescription" text-align="right">Product Description</label><font color="Red">*</font>
										</div>
										<div class="form-group">
										<?php
									    $options = array("1"=>'Select Product Description');
										//print_r(  $options);
										
										if(!empty($RawMaterials))
										{
									    foreach ($RawMaterials as $RID):
                                           $options[$RID->MaterialCode] =  $RID->MaterialCode.' '.'-'.' '.$RID->MaterialName;
									     

										endforeach;
										}										
							echo form_dropdown('ProductDescription',$options,set_value('ProductDescription'),'id="ProductDescription"', 'class = "form-control "');
									
            
								?>
                                        
                                    </div>  
                                </div>                               
                                
                            </div>
                            <div class="row">
                                <div >
                                   <div class="form-group">
                                        <label for="UOM">UOM</label> <font color="Red">*</font> </div>
										<div class="form-group">
										<?php
									    $options = array("1"=>'Select UOM');
										//print_r(  $options);
										
										if(!empty($UOM))
										{
									    foreach ($UOM as $UID):
                                           $options[$UID->ConfigValue] =  $UID->ConfigValue;
									     

										endforeach;
										}										
							echo form_dropdown('UOM',$options,set_value('UOM'),'id="UOM"', 'class = "form-control "');
								
            
								?>
                                       
                                    </div>
                                </div>
                              </div>                 
						
						 <div class="row">
                                <div >
<div class="form-group">
                                          <label for="Quantity">Quantity</label> <font color="Red">*</font>
										</div>
										<div class="form-group">
										<?php
                                         $data = array('name' => 'Quantity', 'value' => set_value('Quantity'),'id'=>'Quantity', 'class' => 'form-control required digits', 'onchange'=>'change()','required'=>'true','onkeypress'=>'return isNumberKey(event)');
                                        echo form_input($data);
                                        ?>  
											
                                       
                                    </div>
                                </div>
                              </div>   
							 
							<div class="row">
                                <div >
								 <div class="form-group">
                                           <label for="UnitPrice">Unit Price</label> <font color="Red">*</font>
										</div>
										<div class="form-group">
										<?php
                                         $data = array('name' => 'UnitPrice', 'value' => set_value('UnitPrice'),'id'=>'UnitPrice', 'class' => 'form-control required digits', 'onchange'=>'change()','required'=>'true','onkeypress'=>'return isNumberKey(event)');
                                        echo form_input($data);
                                        ?>  
											
                                       
                                    </div>
                                       
                                </div>
                              </div>    
    					 <div class="row">
                                <div >
								<div >
								 <div class="form-group">
                                           <label for="ProductPrice">Product Price</label> 
										</div>
										<div class="form-group">
										<?php
                                         $data = array('name' => 'ProductPrice', 'value' => set_value('ProductPrice'),'id'=>'ProductPrice', 'class' => 'form-control required digits','disabled'=>'true');
                                        echo form_input($data);
                                        ?>  
											
                                       
                                    </div>
                                       
                                </div>
                              </div> 
    
                        
                   <!-- </form>-->
								</div>
        <div class="modal-footer">
       
		   <a class="btn btn-primary font tempClick"  ID="tempClick"  style="margin-top: -24px;"><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">Add</span></a>
         
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
                </div>
				</div>
				<div class="x_content ajaxList">
                                            <!-- accepted payments column -->
                                           
                                            <!-- /.col -->
                                            <div class="col-xs-12">
                                                
                                                <div class="table-responsive">
                                                    <table id="POList" class="table table-striped responsive-utilities jambo_table" style="display:none;">
                                                        <thead>
                                                            <tr>
                                                             <th>SNo</th>                                                                
                                                                <th>ProductDescription</th>
                                                                <th>UOM</th>
                                                                 <th>Quantity</th>
																  <th>UnitPrice</th>
                                                                  <th>ProductPrice</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody id="tempAppend">    
                                                            
                                                        </tbody>  
                                                                                                                 
                                                    </table>
                                                </div>
                                            </div>
                                            <!-- /.col -->
                                            
                                          
                                        </div>
            </div>
                </div>
            </div>
					
					
					        <div class="col-md-12" style="border:1px solid #000">
							<br/>
								<div class="row">
								<div class="col-md-6 ">
                                         <label for="Basic_Value">Basic Value : </label> <font color="Red">*</font> 
										</div>
										 <div class="col-md-3 ">&nbsp;</div>
										  
										 	<div class="col-md-3 ">											
										
										<?php
                                         $data = array('name' => 'BasicValue', 'value' => set_value('BasicValue'), 'id'=>'BasicValue', 'class' => 'form-control required digits','readonly'=>'true');
                                        echo form_input($data);
                                        ?>  										
                                       
                                    </div>
								</div>	
								<br/>
								<div class="row">
								<div class="col-md-6 ">
                                         <label for="Discount_Value">Discount : </label> &nbsp;&nbsp;<font color="Red">*</font> 
										</div>
										 
								
						<div class="col-md-3 ">
						<?php
									    $options = array("1"=>'Select Discount Type',"Percentage"=>'Percentage',"Lump some"=>'Lump some',"Nil"=>'Nil');
										//print_r(  $options);
										
																			
							echo form_dropdown('DiscountType',$options,set_value('DiscountType'),'id="DiscountType"', 'class = "form-control "');
								
            
								?>
                                    
                                </div>
								<div class="col-md-3 ">
                                        <?php
                                         $data = array('name' => 'txtDiscount','value' => set_value('txtDiscount'), 'id'=>'txtDiscount', 'class' => 'form-control required digits','onkeypress'=>'return isNumberKey(event)','onchange'=>'calculateDiscount()');
                                        echo form_input($data);
                                        ?>                                 
                                       
                                
                                </div>
								</div>
								<br/>
								<div class="row">
								<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">  
<?php
                                         $data = array('name' => 'AfterDiscount','value' => set_value('AfterDiscount'), 'id'=>'AfterDiscount', 'class' => 'form-control required digits','readonly'=>'true');
                                        echo form_input($data);
                                        ?> 									
                                       
                                    </div>
                                </div>
								</div>
								<br/>
								<div class="row">
								
								<div class="col-md-6 ">
									<label for="Packaging">Packaging : </label> &nbsp;&nbsp;<font color="Red">*</font> 
								</div>
								<div class="col-md-3 ">
                                    
<?php
									    $options = array("1"=>'Select Packaging Type',"Percentage"=>'Percentage',"Lump some"=>'Lump some',"Nil"=>'Nil');
										//print_r(  $options);
										
																			
							echo form_dropdown('PackagingType',$options,set_value('PackagingType'),'id="PackagingType"', 'class = "form-control "','onchange="SelectPackagingType()"');
								
            
								?>									
                                         
                                    
                                </div>
								<div class="col-md-3 ">
                                   
<?php
                                         $data = array('name' => 'txtPackaging','value' => set_value('txtPackaging'), 'id'=>'txtPackaging', 'class' => 'form-control required digits','onkeypress'=>'return isNumberKey(event)','onchange'=>'calculatePackaging()');
                                        echo form_input($data);
                                        ?>     									
                                       
                                    </div>
                              
								</div>
<br/>
								<div class="row">								
								<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"> 
									<?php
                                         $data = array('name' => 'AfterPackaging','value' => set_value('AfterPackaging'), 'id'=>'AfterPackaging', 'class' => 'form-control required digits','readonly'=>'true');
                                        echo form_input($data);
                                        ?> 									
                                       
                                    </div>
                                </div>
								</div>
								<br/>
								<div class="row">
								<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"> 
										<?php
                                         $data = array('name' => 'Exciseduty','value' => set_value('Exciseduty'), 'id'=>'Exciseduty', 'class' => 'form-control required digits','onkeypress'=>'return isNumberKey(event)','onchange'=>'calculateExeciseDuty()');
                                        echo form_input($data);
                                        ?> 									
                                       
                                    </div>
                                </div>
								</div>
								<br/>
								<div class="row">
								<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"> 
<?php
                                         $data = array('name' => 'AferExciseduty', 'value' => set_value('AferExciseduty'),'id'=>'AferExciseduty', 'class' => 'form-control required digits','readonly'=>'true');
                                        echo form_input($data);
                                        ?> 									
                                        
                                    </div>
                                </div>
								</div>
								<br/>
								<div class="row">
								<div class="col-md-6 ">
									<label for="Vat">Vat	 : </label> <font color="Red">*</font> 
								</div>
								<div class="col-md-3 ">&nbsp;</div>
								<div class="col-md-3 ">
                                    <div class="form-group">  
<?php
                                         $data = array('name' => 'txtVat','value' => set_value('txtVat'), 'id'=>'txtVat', 'class' => 'form-control required digits','onkeypress'=>'return isNumberKey(event)','onchange'=>'calculateVat()');
                                        echo form_input($data);
                                        ?> 										
                                       
                                    </div>
                                </div>
								</div>
								<br/>
								<div class="row">
								<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">  
<?php
                                         $data = array('name' => 'txtAfterVat', 'value' => set_value('txtAfterVat'),'id'=>'txtAfterVat', 'class' => 'form-control required digits','readonly'=>'true');
                                        echo form_input($data);
                                        ?> 												
                                       
                                    </div>
                                </div>
								 </div>
								 <br/>
								<div class="row">
								<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">
<?php
                                         $data = array('name' => 'txtFreight', 'value' => set_value('txtFreight'),'id'=>'txtFreight', 'class' => 'form-control required digits','onkeypress'=>'return isNumberKey(event)','onchange'=>'calculateFreight()');
                                        echo form_input($data);
                                        ?> 											
                                        
                                    </div>
                                </div>
								</div>
								<br/>
								<div class="row">
								<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">   
<?php
                                         $data = array('name' => 'txtOrderValue','value' => set_value('txtOrderValue'), 'id'=>'txtOrderValue', 'class' => 'form-control required digits','readonly'=>'true');
                                        echo form_input($data);
                                        ?> 															
                                       
                                    </div>
                                </div>
								</div>
								  </div>
						</div><!-- /.box-body -->
						 
                        <div class="box-footer" align="right">
						 
						  <input type="hidden" name="txtRowCount" id="txtRowCount" />
						  <input type="submit"  class="btn btn-info"  id="btnSubmit" onclick=" Validate()" value = "Submit"/>						                           
                            <input type="reset" id="reset"  class="btn btn-info" value="Reset" />
                        </div>
					 
                
            </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>
var baseurl = "<?php print base_url(); ?>";
 $(".addPO").submit(function(e) {
  
		e.preventDefault();
		
$.ajax({
			data:$('.addPO').serialize(),
			type:"POST",
			url:"<?php echo base_url() ?>purchaseorder/addNewPO", 
			success:function(data) {
			if(data)
			{
				
				alert('Purchase Order has been Successfully Generated : '+ data);
				window.location =	baseurl +'purchaseorder/ViewPurchaseOrder/?PONo='+ data;
				//purchaseorder/ViewPurchaseOrder/?PONo='.$record->PONO;
			}
			else
			{
			alert("Error");	
			}
			
			
		}
		});
	
		 });
		 

 $(function() {
    $( ".datePicker" ).datepicker({ 
	dateFormat: 'dd/mm/yy'
	
	
    	});
  });
  


  
  
  $('#SupplierID').change(function() {
   

    
		 var id = $('#SupplierID').val();
		
		 $.ajax({
			data:{id:id},
			
			type:"POST",
			url:"<?php echo base_url();?>purchaseorder/GetSupplier",
			success:function(data) {
				if(data)
			{
				
		      $('#SupplierAddress').val(data);
			}
			else
			{
			alert("Error");	
			}					
			
		}
		
		});
  
});

 $('#BudgetManager').change(function() {
    
 var id = $('#BudgetManager').val();
		
		 $.ajax({
			data:{id:id},
			
			type:"POST",
			url:"<?php echo base_url();?>purchaseorder/GetBudgetManagerDepartment",
			success:function(data) {
				if(data)
			{
				
		      $('#BudgetManagerDepartment').val(data);
			}
			else
			{
			alert("Error");	
			}					
			
		}
		
		});	
  
});

</script>
<script type="text/html" id="tempList">
<tr  id="<%=index%>">
<td align="left"><%=index%></td>
<?php
                                         $data = array('name' => '"POItem[<%=index%>][index]"',  'value' => set_value('<%=index%>'),'id'=>'"POItem[<%=index%>][index]"',  'class' => 'form-control','type'=>'hidden');
                                        echo form_input($data);
                                        ?>  

 <td align="left"><%=ProductDescription%></td>
 
  <td align="left"><%=UOM%></td>
  
  <td align="left"><%=Quantity%></td>

  <td align="left"><%=UnitPrice%></td>
 
   <td align="left"><%=ProductPrice%></td>
  
  
</tr>
</script>
<script>
var index     = '1';
var numbers = /^[0-9]+$/;
	$('.tempClick').click(function(){
         
       		if ($("#ProductDescription option:selected").text() =='Select Product Description' )
			{
				 alert('Please Select the ProductDescription ');
		        return;
			}	
			if($("#UOM option:selected").text() == 'Select UOM' )
			{
				 alert('Please Select the UOM ');
		        return;
			}
    	if(document.getElementById('Quantity').value == '' )
	  {
		  alert('Please Enter the Quantity of the Product');
		  return;
	  }
	   if(document.getElementById('UnitPrice').value == '' )
	  {
		   alert('Please Enter the Unit Price of the Product');
		    return;
	  }
	  
		
        if ($("#ProductDescription option:selected").text() !='' && $("#UOM option:selected").text() && $('#Quantity').val() && $('#UnitPrice').val()  )
        {
		
        $('#POList').show();
         var temp = index;
         var ProductDescription = $("#ProductDescription option:selected").val();
         var UOM =  $("#UOM option:selected").text();
         var Quantity = $("#Quantity").val();
		
         var UnitPrice = $('#UnitPrice').val();
     	 var ProductPrice = parseFloat(Quantity) * parseFloat(UnitPrice);
          index = parseInt(index)+1;
	    
		 if($('#BasicValue').val() != '')
		 {
		  $('#BasicValue').val( parseFloat($('#BasicValue').val()) + ProductPrice);
		 }
		 else
		 {
			 $('#BasicValue').val(ProductPrice);
		 }
		 
	      var template = jQuery("#tempList").html();
	   
	     
          $('#tempAppend').append(_.template(template,{index:temp,ProductDescription:ProductDescription,UOM:UOM,Quantity:Quantity,UnitPrice:UnitPrice,ProductPrice:ProductPrice}));
		  
		  
		 var theForm = $(".addPO");
		 
		  
  
		
	
		 //   alert(ProductCode);
		 addHidden(theForm,"ProductDescription"+temp,ProductDescription);
		 addHidden(theForm,"UOM"+temp,UOM);
	     addHidden(theForm,"Quantity"+temp,Quantity);
		 addHidden(theForm,"UnitPrice"+temp,UnitPrice);
		 addHidden(theForm,"ProductPrice"+temp,ProductPrice);
		 
		 $('#txtRowCount').val(temp);  
		 
		//$('#ProductDescription').val('1');
		//$('#UOM').val('1');
		//$('#Quantity').val('');
		//$('#UnitPrice').val('');
		//$('#ProductPrice').val('');
		
      }
     else
      {
		  alert('Please enter all the values');
		
      } 
   
 });
 
 function addHidden(theForm, key, value) {
    // Create a hidden input element, and append it to the form:
    var input = document.createElement('input');
    input.type = 'hidden';
    input.name = key;'name-as-seen-at-the-server';
    input.value = value;
    theForm.append(input);
}
 
$('#DiscountType').change(function() {
    selValue = $("option:selected", $("#DiscountType")).text() 
  
	if (selValue =='Nil')
	{
      
		 $('#txtDiscount').attr('readonly', 'true');
		 $('#txtDiscount').val('0.00');
		 calculateDiscount();
		 
	}
	else
	{
		 $('#txtDiscount').removeAttr( 'readonly','true' );
		 $('#txtDiscount').val('');
		 calculateDiscount();
	}
  
});

$('#PackagingType').change(function() {
    selValue = $("option:selected", $("#PackagingType")).text() 
	
  
	if (selValue =='Nil')
	{
     
		 $('#txtPackaging').attr('readonly', 'true');
		 $('#txtPackaging').val('0.00');
		 calculatePackaging();
	}
	else
	{
		 $('#txtPackaging').removeAttr( 'readonly','true' );
		 $('#txtPackaging').val('');
		 calculatePackaging();
	}
  
});





function change(){
	  
	  
	 if(document.getElementById('Quantity').value != '' && document.getElementById('UnitPrice').value != '')
	 {
      var txtQuantity = parseFloat( document.getElementById('Quantity').value);
	  var txtUnitPrice = parseFloat(document.getElementById('UnitPrice').value);
	  var Tot =  txtQuantity * txtUnitPrice
	  document.getElementById('ProductPrice').value = Tot;
	 }
}

 function calculateDiscount()
 {
	 var basicValue = parseFloat(document.getElementById('BasicValue').value);
	 var DiscountType =$("option:selected", $("#DiscountType")).text();
	 var DiscountText = parseFloat(document.getElementById('txtDiscount').value);
	 
	 var AfterDiscount = 0.0;
	 if(DiscountType == 'Percentage')
	 {
		 AfterDiscount = (basicValue - ((DiscountText/100) * basicValue));
		
	 }
	 else if(DiscountType == 'Nil' )
	 {
	    AfterDiscount = basicValue;
		
	 }
	 else
	 {
		 AfterDiscount = basicValue - DiscountText;		
	 }
      
	  var discount = AfterDiscount.toFixed(2);
	  
	 $('#AfterDiscount').val(discount); 
	
 }
 
 function calculatePackaging()
 {
	 var AfterDiscount =parseFloat(document.getElementById('AfterDiscount').value);
	
	 var PackagingType =$("option:selected", $("#PackagingType")).text();
	 var PackagingText = parseFloat(document.getElementById('txtPackaging').value);
	 
	 var AfterPackaging = 0.0;
	 
	 if(PackagingType == 'Percentage')
	 {
		
		 AfterPackaging = AfterDiscount + ((PackagingText/100) * AfterDiscount);
		
	 }
	 else if(PackagingType == 'Nil' )
	 {
	    AfterPackaging = AfterDiscount;
	 }
	 else
	 {
		 AfterPackaging = AfterDiscount +  PackagingText;		
	 }
     var Packaging = AfterPackaging.toFixed(2);
	$('#AfterPackaging').val(Packaging); 
	
 }
 function calculateExeciseDuty()
 {
	 var AfterPackaging =parseFloat(document.getElementById('AfterPackaging').value);
	
	
	 var ExciseDuty = parseFloat(document.getElementById('Exciseduty').value);
	 
	 var AfterExciseDuty = 0.0;
	 
	 if(ExciseDuty == '')
	 {
		
		 AfterExciseDuty = AfterPackaging;;
	 }
    
	
	 else
	 {
		 AfterExciseDuty =  AfterPackaging + ((ExciseDuty/100) * AfterPackaging);		
	 }
    CalExciseDuty = AfterExciseDuty.toFixed(2);
	$('#AferExciseduty').val(CalExciseDuty); 
	
 }
 
 function calculateVat()
 {
	 var AfterExeciseDuty =parseFloat(document.getElementById('AferExciseduty').value);
	
	
	 var Vat = parseFloat(document.getElementById('txtVat').value);
	 
	 var AfterVat = 0.0;
	 
	 if(Vat == '')
	 {
	
		 AfterVat = AfterExeciseDuty;;
	 }
    
	
	 else
	 {
		 AfterVat =  AfterExeciseDuty + ((Vat/100) * AfterExeciseDuty);		
	 }
     calAfterVat = AfterVat.toFixed(2);
	 $('#txtAfterVat').val(calAfterVat); 
	
 }
 
 function calculateFreight()
 {
	 var AfterVat =parseFloat(document.getElementById('txtAfterVat').value);
	
	
	 var Freight = parseFloat(document.getElementById('txtFreight').value);
	 
	 var AfterFreight = 0.0;
	 
	 if(Freight == '')
	 {
		
		 AfterFreight = AfterVat;
	 }   
	
	 else
	 {
		 AfterFreight =  AfterVat + Freight;		
	 }
		calAfterFreight = AfterFreight.toFixed(2);
	 $('#txtOrderValue').val(calAfterFreight); 
	
 }
 
 
       <!--
       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
	   
	  

function Validate()
{
		
	if($("option:selected", $("#PO_Type")).val() == '0')
	{
		alert('Please Select Purchase Order Type');
		return;
	}
	
	if($("option:selected", $("#SupplierID")).val() == "0")
	{
		alert('Please Select Supplier ID');
		return;
	}
	
	if($("option:selected", $("#role")).val() == "0")
	{
		alert('Please Select Requested By ');
		return;
	}
	if($("option:selected", $("#BudgetManager")).val() == "0")
	{
		alert('Please Select Budget Manager ');
		return;
	}
	if($("option:selected", $("#Pur_category")).val() == "0")
	{
		alert('Please Select Purchasing Category');
		return;
	}
	if(!validateEmail())
	{
		 alert('Please Enter Valid Email Address');
         return ;
	}
	
	
	
		
}
   function validateEmail() {
 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
          
			var email = $('#re_email').val();
			if(email != "")
			{
            if (reg.test(email) == false) 
            {
                alert('Please Enter Valid Email Address');
                return (false);
            }
			else
			{
				return true;
			}
			}
}  
    
</script>


<script>

</script>
<script src="<?php echo base_url(); ?>assets/js/addUser.js" type="text/javascript"></script>