  <?php
    
		$PONO = '';
		$CompanyAddress = '';
        $CompanyName = '';
	    $SuplierName = '';
		$SuplierAddress = '';
		$DeliveryAddress = '';
		$Podt = '';
		$DeliveryDate ='';
		
		$ServiceDescription = '';
	if(!empty($CompanyDetails))
		{
    foreach ($CompanyDetails as $CO)
    {
		$CompanyName = $CO->CompanyName;
		$CompanyAddress = $CO->Address;
		
	}
}	
		if(!empty($POItem))
		{
    foreach ($POItem as $PO)
    {
		 $PONO = $PO->PONO;
		 $SuplierName = $PO->SupplierName;
		$SuplierAddress = $PO->Address;
		$DeliveryAddress = $PO->DeliveryAddress;
		
		$dt = new DateTime($PO->PODate, new DateTimeZone('Asia/Kolkata'));				
		$Podt =  $dt->format('d-m-Y');
		$dtDe = new DateTime($PO->DeliveryDate, new DateTimeZone('Asia/Kolkata'));				
		$DeliveryDate =  $dtDe->format('d-m-Y');
		$ServiceDescription =$PO->ServiceDescription;
		
	}
}
		
         ?>
<div><center>
<h2>PURCHASE ORDER</h2> 
</center>
</div>
<div align="right"> PO NO:<?php echo $PONO?> </div> 
 <div align="right"> <?php echo $Podt?> </div>
<p> 
<b style="color:#3c8dbc"><?php echo $CompanyName; ?></b><br/>   <?php echo $CompanyAddress; ?></p>
<table><tr><td>
<p><a style="color:#3c8dbc">Vendor Address : </a>  <br/> <?php echo $SuplierName?> <br/><?php  echo $SuplierAddress ?></p></td><td>
<p><a style="color:#3c8dbc">Delivery To :</a><br/>  <?php  echo $DeliveryAddress?><p></td>
</tr></table>
<p>
<div align="right"> Delivery Date :<?php echo $DeliveryDate?></div></p>


<table style="border-collapse: collapse;"  cellpadding="0" cellspacing="0" border="1" width="105%">
<tr style="background:#000;color:#fff;">
<th>#</th>
<th>Item Description</th>
<th>Qty</th>
<th>Rate</th>
<th>Amount</th>
<th>Discount</th>
<th>Excise Duty</th>
<th>Vat</th>
<th>CST</th>
<th>GST</th>
<th>Other Taxes</th>
<th>Insurance</th>
<th>Freight</th>
<th>Total Amount</th>
<th></th>
</tr>

							 <?php
                    if(!empty($POItem))
                    {
						$SubTotalAmount = 0;
						 $index = 0;
						 $TotalAmount = 0;
						 $OrderValue = 0;
						 $AfterExciseDuty = 0;
						 $AfterVAT = 0;
						 $AfterCST = 0;
						 $AfterGST = 0;
						 $AfterOtherTaxes = 0;
						 $Insurance = 0;
						 $AfterFreightValue = 0;
						 $AfterDiscount = 0;
                        foreach($POItem as $record)
                        {
							$index = $index + 1;
							
                    ?>
<tr>
<td><?php echo $index ; ?></td>
<td><?php echo $record->MaterialName ; ?></td>
<td align="right"><?php echo $record->Quantity ; ?></td>
<td align="right"><?php echo $record->Rate ; ?></td>
<td align="right"><?php echo $record->BasicValue ; ?></td>
<td align="right"><?php echo $record->AfterDiscount; ?></td>
<td align="right"><?php echo $record->AfterExciseDuty ; ?></td>
<td align="right"><?php echo $record->AfterVAT ; ?></td>
<td align="right"><?php echo $record->AfterCST ; ?></td>
<td align="right"><?php echo $record->AfterGST ; ?></td>
<td align="right"><?php echo $record->AfterOtherTaxes ; ?></td>
<td align="right"><?php echo $record->Insurance ; ?></td>
<td align="right"><?php echo $record->AfterFreightValue ; ?></td>
<td align="right"><?php $TotalAmount = (($record->BasicValue+$record->AfterExciseDuty 
							+ $record->AfterVAT+$record->AfterCST+$record->AfterGST + $record->AfterOtherTaxes + $record->Insurance+ $record->AfterFreightValue)- $record->AfterDiscount);
echo number_format($TotalAmount,2) ; ?></td>
</tr>

<?php
                        $SubTotalAmount  = $SubTotalAmount + $record->BasicValue;
						$AfterExciseDuty =$AfterExciseDuty + $record->AfterExciseDuty;
						$AfterVAT =$AfterVAT + $record->AfterVAT;
						$AfterCST = $AfterCST + $record->AfterCST; 
						$AfterGST =$AfterGST + $record->AfterGST;
						$AfterOtherTaxes =$AfterOtherTaxes + $record->AfterOtherTaxes;
						$Insurance =$Insurance + $record->Insurance;
						$AfterFreightValue =$AfterFreightValue + $record->AfterFreightValue;
						 $AfterDiscount =  $AfterDiscount + $record->AfterDiscount ;
						}
						$OrderValue =  (( $SubTotalAmount + $AfterVAT + $AfterCST+$AfterGST+$AfterOtherTaxes +$Insurance +$AfterFreightValue+$AfterExciseDuty) - $AfterDiscount ) ;
                    }
					
                    ?>
</table>
<div align="right">

<table style="border-collapse: collapse;"  cellpadding="0" cellspacing="0" border="0" width="105%">
<tr>
<td align="right">Sub Total Amount :</td>
<td align="right"><?php echo number_format($SubTotalAmount,2);?></td>
<br/>
</tr>
<tr>
<td align="right">Discount  :</td>
<td align="right"><?php echo  number_format($AfterDiscount,2);?></td>

</tr>
<tr>
<td align="right">Excise Duty  :</td>
<td align="right"><?php echo  number_format($AfterExciseDuty,2);?></td>

</tr>
<tr>
<td align="right">Vat :</td>
<td align="right"><?php echo  number_format($AfterVAT,2);?></td>

</tr>
<tr>
<td align="right">CST :</td>
<td align="right"><?php echo   number_format($AfterCST,2);?></td>

</tr>
<tr>
<td align="right">GST :</td>
<td align="right"><?php  echo  number_format($AfterGST,2);?></td>

</tr>
<tr>
<td align="right">Other Taxes:</td>
<td align="right"><?php echo number_format($AfterOtherTaxes,2);?></td>

</tr>
<tr>
<td align="right">Insurance :</td>
<td align="right"><?php echo number_format($Insurance,2);?></td>

</tr>
<tr>
<td align="right">Freight  :</td>
<td align="right"><?php echo number_format($AfterFreightValue,2);?></td>

</tr>
<tr>
<td align="right"><p><b>Total Order Amount :</b></p></td>
<td align="right"><b><?php echo  number_format($OrderValue,2);?></b></td>

</tr>
</table>
<br>
<br>
<p>
<div align="Left"> <b>Service Description:</b><br/><br/><?php echo $ServiceDescription;?></div></p>
<?php 
if(!empty($releasedetails)){
	foreach($releasedetails as $detail){

?>
<table width="200%">
<tr>
<td><b>ReleasedBy:</b></td>
<td><b>ReleasedOn:</b></td>
</tr>
<tr>
<td><?php echo $detail->FirstName;?></td>
<td><?php echo $detail->ReleasedOn;?></td>
</tr>
</table>
<?php 
	}
}
?>
</div>