-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcancelTransaction.php
52 lines (35 loc) · 1.79 KB
/
cancelTransaction.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require_once "includes/database.php";
if (isset($_POST["transactionid"])){
try{
$conn->beginTransaction();
$preparedStatement = $conn->prepare("update transactions set is_cancelled=1 where transactionid = ?");
$preparedStatement->execute(array($_POST["transactionid"]));
if ($preparedStatement->rowCount()==0) return;
if($_POST["option"]=="order"){
// set all products purchased to 30% of their price (70% refund)
$setPriceStatement = $conn->prepare("update orderdetails set unit_price = 0.3* unit_price where orderid = ? ");
$setPriceStatement->execute(array($_POST["transactionid"]));
$getProductsStatement = $conn->prepare("SELECT productid, quantity FROM orderdetails where orderid = ?");
// increment stock
$incrementStockStatement = $conn-> prepare("update product set quantity = quantity + ? where productid= ?");
$getProductsStatement->execute(array($_POST["transactionid"]));
while ($row = $getProductsStatement->fetch()){
$productid = $row["productid"];
$quantity = $row["quantity"];
$incrementStockStatement->execute(array($quantity, $productid));
}
}else if($_POST["option"]=="appointment"){
// set all paid services to 30% of their price (70% refund)
$setPriceStatement = $conn->prepare("update appointmentdetails set price = 0.3* price where transactionid = ? ");
$setPriceStatement->execute(array($_POST["transactionid"]));
}
$conn->commit();
echo "success";
}catch(\PDOException $e){
$conn->rollBack();
echo "failure";
// show the error message
die($e->getMessage());
}
}