Skip to content

Commit

Permalink
Refactor member payment calculation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
HashJProgramming committed Feb 9, 2024
1 parent d61d76c commit 2fdd53d
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions functions/add-member.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
$birthdate = $_POST['birthdate'];
$amount = $_POST['amount'];

if ($type == 'Regular'){
$total = 300;
} elseif ($type == 'Premium'){
$total = 500;
} else {
$total = 800;
}

$sql = "SELECT * FROM members WHERE fullname = :fullname OR phone = :phone";
$stmt = $db->prepare($sql);
Expand All @@ -30,6 +23,14 @@
exit;
}

if ($type == 'Regular'){
$total = 300;
} elseif ($type == 'Premium'){
$total = 500;
} else {
$total = 800;
}

$change = $amount - $total;

if ($change < 0) {
Expand All @@ -51,14 +52,6 @@

$id = $db->lastInsertId();

if ($type == 'REGULAR'){
$total = 300;
} elseif ($type == 'PREMIUM'){
$total = 500;
} else {
$total = 800;
}

$sql = "INSERT INTO payments (member, type, amount, total) VALUES (:member, :type, :amount, :total)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':member', $id);
Expand Down

0 comments on commit 2fdd53d

Please sign in to comment.