 <?php

include('/home/armeatsh/etc/pw.php');

$location = 'Aurora';

if(isset($_POST['cash']))
{
    $payment = 'cash';
}

if(isset($_POST['credit']))
{
    $payment = 'credit';
}

if(isset($_POST['gcash']))
{
    $payment = 'gcash';
}
?>
<table cellpadding='5px' border='0px' width='90%' bgcolor='#fffff'>
			<tr>
			<td colspan='5' align='center' ><font face='Times New Roman' size='3px' color='#000000'><b>A & R Meatshop</b></font></td>
			</tr>
			
			<tr>
			<td colspan='5' align='center'><font face='Times New Roman' size='4px' color='#000000'>Transaction Details</font></td>
			</tr>
			<tr>
				<td><font face='Times New Roman' size='2px' color='#000000'>Customer:</font>
				<?php $customerdate = $query->query("SELECT customer from sales where entrust = 0 and branch = '$location' order by id desc"); 
					$transact = mysqli_fetch_array($customerdate);
					echo "$transact[customer]"; 
				?>
							</td>
				
			</tr>
			<?php $datetime=date('Y-m-d H:i:s'); ?>
			<tr><td><font face='Times New Roman' size='2px' color='#000000'>Date : <?php echo $datetime; ?> </font></td>
			<?php
					$ask_customers = $query->query("SELECT Max(entrust) as entrust from sales");
						while($customer = mysqli_fetch_array($ask_customers))
						{
						 $transaction=$customer['entrust'];
						}
						$count=	$transaction+1;
						echo"<td colspan='4' align='right'><font face='Times New Roman' size='2px' >Entrust Number : $count</font></td>";
					
					
			?>
			</tr>
			
			<tr>
				
				<td align='center' bgcolor='#B0C4DE'><font face='Times New Roman' size='3px' color='#000000'>Product</font></td>
				<td align='right' bgcolor='#B0C4DE'><font face='Times New Roman' size='3px' color='#000000'>Unit</font></td>
				<td align='right' bgcolor='#B0C4DE'><font face='Times New Roman' size='3px' color='#000000'>Quantity</font></td>
				<td align='right' bgcolor='#B0C4DE'><font face='Times New Roman' size='3px' color='#000000'>Unit Price</font></td>
				<td align='right' bgcolor='#B0C4DE'><font face='Times New Roman' size='3px' color='#000000'>Amount</font></td>
				
			</tr>
			<?php
			$total=0;

				$request=$query->query("SELECT * from sales  where entrust = 0 and branch = '$location' order by id asc");
				while($transaction = mysqli_fetch_array($request))
				{
				
				echo"
							<tr bgcolor='#F5F5F5'>
							
							";
							
						
						
				echo"<td><font face='Times New Roman' size='3px' >$transaction[product]</font></td>";
				echo"<td align='right'><font face='Times New Roman' size='3px' >$transaction[unit]</font></td>";
				echo"<td align='right'><font face='Times New Roman' size='3px' >$transaction[qty]</font></td>
							<td align='right'><font face='Times New Roman' size='3px' >".number_format($transaction['price'],2)."</font></td>";
						    $x=$transaction['qty']*$transaction['price'];
						$total=$total+$x;
				echo"<td align='right'><font face='Times New Roman' size='3px' >".number_format($x,2)."</font></td></tr>";
				}
				echo"<td colspan='4' align='right'><font face='Times New Roman' size='2px' color='#000000'>TOTAL AMOUNT</font></td><td align='right'><font face='Times New Roman' size='3px' color='#000000'>".number_format($total,2)."</font></td></tr>";
	

			?>
			</table>
			</td>
			</tr>
			</table>
			
			
			
			<?php
						$ask_customers = $query->query("SELECT max(entrust) as entrust1 from sales");
					
						while($customer1 = mysqli_fetch_array($ask_customers))
						{
						 $transaction=$customer1['entrust1'];
								
						}
						$count=	$transaction+1;
						
			$update_product = $query->query("UPDATE sales set entrust ='$count', date = '$datetime', payment = '$payment'  where entrust = '0' and branch = '$location' ")or die(mysqli_error());
			
			
			?>