-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocessDeposit.php
51 lines (47 loc) · 2.25 KB
/
processDeposit.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
<?php
require('connect-db.php');
session_start();
$errors = array();
$data = array();
if(empty($_POST['amount-to-deposit'])){
$errors['deposit-amount'] = "Amount to Deposit is required";
}
if(!empty($errors)){
$data['success']= false;
$data['errors']= $errors;
}
else{
$wallet_query = "SELECT * FROM wallet WHERE User_ID='{$_SESSION['idNo']}'";
$checkLoanAvailabilityQuery ="SELECT * FROM loanStatus WHERE User_ID ='{$_SESSION['idNo']}'";
$checkLoanAvailability = $con->query($checkLoanAvailabilityQuery);
if($checkLoanAvailability->num_rows>0){
$availabilityRow = $checkLoanAvailability->fetch_array();
$availabilityStatus = $availabilityRow['loanAvailability'];
}
$select_wallet = $con->query($wallet_query);
if($select_wallet->num_rows>0){
$wallet_row=$select_wallet->fetch_array();
$_SESSION['wallet-id']= $wallet_row['WalletID'];
$_SESSION['wallet-balance']= $wallet_row['WalletBalance'];
$_SESSION['walletHistory'] = $wallet_row['WalletHistory'];
}
//If there are no errors process deposit
date_default_timezone_set("Africa/Nairobi");
$depoAmount = $_POST['amount-to-deposit'];
$total_amount= $_SESSION['wallet-balance'] + $depoAmount;
$_SESSION['walletHistory']+=$total_amount;
$depositMoneySQL = "UPDATE wallet SET WalletBalance='$total_amount', WalletHistory='{$_SESSION['walletHistory']}' WHERE User_ID='{$_SESSION['idNo']}'";
$depositWallet= $con->query($depositMoneySQL);
$data['success'] = true;
$data['message'] = "Successfully Deposited".$_POST['amount-to-deposit'] ;
$transactionType ="Cash Deposit";
$insertTransactionsSQL = "INSERT INTO transactions (User_ID,Amount,TransactionType) VALUES('{$_SESSION['idNo']}','$depoAmount','$transactionType')";
$insertTransactions = $con->query($insertTransactionsSQL);
$one = 1;
if($availabilityStatus==0){
$updateStatusSQL = "UPDATE loanStatus SET loanAvailability='$one' WHERE User_ID ='{$_SESSION['idNo']}'";
$updatStatus = $con->query($updateStatusSQL);
}
echo json_encode($data);
}
?>