-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.php
33 lines (26 loc) · 894 Bytes
/
transaction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
include 'includes/session.php';
$id = $_POST['id'];
$conn = $pdo->open();
$output = array('list'=>'');
$stmt = $conn->prepare("SELECT * FROM details LEFT JOIN products ON products.id=details.product_id LEFT JOIN sales ON sales.id=details.sales_id WHERE details.sales_id=:id");
$stmt->execute(['id'=>$id]);
$total = 0;
foreach($stmt as $row){
$output['transaction'] = $row['pay_id'];
$output['date'] = date('M d, Y', strtotime($row['sales_date']));
$subtotal = $row['price']*$row['quantity'];
$total += $subtotal;
$output['list'] .= "
<tr class='prepend_items'>
<td>".$row['name']."</td>
<td>$ ".number_format($row['price'], 2)."</td>
<td>".$row['quantity']."</td>
<td>$ ".number_format($subtotal, 2)."</td>
</tr>
";
}
$output['total'] = '<b>$ '.number_format($total, 2).'<b>';
$pdo->close();
echo json_encode($output);
?>