-
Notifications
You must be signed in to change notification settings - Fork 12
/
acc_sav_depos.php
executable file
·136 lines (119 loc) · 5.05 KB
/
acc_sav_depos.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE HTML>
<?PHP
require 'functions.php';
checkLogin();
$db_link = connect();
getCustID($db_link);
//Generate timestamp
$timestamp = time();
// Update savings balance for current customer and store into variable
updateSavingsBalance ($db_link, $_SESSION['cust_id']);
$sav_balance = getSavingsBalance($db_link, $_SESSION['cust_id']);
// DEPOSIT-Button
if (isset($_POST['deposit'])){
// Sanitize user input
$sav_date = strtotime(sanitize($db_link, $_POST['sav_date']));
$sav_amount = sanitize($db_link, $_POST['sav_amount']);
$sav_receipt = sanitize($db_link, $_POST['sav_receipt']);
$sav_payer = sanitize($db_link, $_POST['sav_payer']);
if($_POST['sav_fixed'] != "") $sav_fixed = strtotime(sanitize($db_link, $_POST['sav_fixed']));
else $sav_fixed = NULL;
$savtype_id = sanitize($db_link, $_POST['savtype_id']);
// Insert savings transaction into SAVINGS
$sql_insert = "INSERT INTO savings (savtype_id, cust_id, sav_date, sav_amount, sav_receipt, sav_payer, sav_fixed, sav_created, user_id) VALUES ('$savtype_id', '$_SESSION[cust_id]', '$sav_date', '$sav_amount', '$sav_receipt', '$sav_payer', '$sav_fixed', '$timestamp', '$_SESSION[log_id]')";
$query_insert = mysqli_query($db_link, $sql_insert);
checkSQL($db_link, $query_insert);
// Update savings account balance
updateSavingsBalance($db_link, $_SESSION['cust_id']);
// Include Expense, if transaction was Savings Interest
if ($savtype_id == 3){
$sql_expense = "INSERT INTO expenses (cust_id, exptype_id, exp_amount, exp_date, exp_voucher, exp_created, user_id) VALUES ('$_SESSION[cust_id]', '19', '$sav_amount', '$sav_date', '$sav_receipt', '$timestamp', '$_SESSION[log_id]')";
$query_expense = mysqli_query($db_link, $sql_expense);
checkSQL($db_link, $query_expense);
}
//Refer to acc_sav_depos.php
header('Location: acc_sav_depos.php?cust='.$_SESSION['cust_id']);
}
//Get current customer's details
$result_cust = getCustomer($db_link, $_SESSION['cust_id']);
?>
<html>
<?PHP includeHead('Savings Deposit',0) ?>
<script>
function validate(form){
fail = validateDate(form.sav_date.value)
fail += validateReceipt(form.sav_receipt.value)
fail += validateAmount(form.sav_amount.value)
if (fail == "") return true
else { alert(fail); return false }
}
</script>
<script src="functions_validate.js"></script>
<script src="function_randCheck.js"></script>
</head>
<body>
<!-- MENU -->
<?PHP includeMenu(2); ?>
<div id="menu_main">
<a href="customer.php?cust=<?PHP echo $_SESSION['cust_id'] ?>">Back</a>
<a href="cust_search.php">Search</a>
<a href="acc_sav_depos.php?cust=<?PHP echo $_SESSION['cust_id'] ?>" id="item_selected">Deposit</a>
<a href="acc_sav_withd.php?cust=<?PHP echo $_SESSION['cust_id'] ?>">Withdrawal</a>
<a href="acc_share_buy.php?cust=<?PHP echo $_SESSION['cust_id'] ?>">Share Buy</a>
<a href="acc_share_sale.php?cust=<?PHP echo $_SESSION['cust_id'] ?>">Share Sale</a>
<a href="loan_new.php?cust=<?PHP echo $_SESSION['cust_id'] ?>">New Loan</a>
<a href="cust_new.php">New Customer</a>
<a href="cust_act.php">Active Cust.</a>
<a href="cust_inact.php">Inactive Cust.</a>
</div>
<!-- LEFT SIDE: Input for new Deposit -->
<div class="content_left" style="width:35%;">
<p class="heading_narrow">Deposit for <?PHP echo $result_cust['cust_name'].' ('.$result_cust['cust_no'].')'; ?></p>
<form action="acc_sav_depos.php" method="post" onsubmit="return validate(this);">
<table id="tb_fields">
<tr>
<td>Date:</td>
<td><input type="text" id="datepicker" name="sav_date" value="<?PHP echo date("d.m.Y",$timestamp); ?>" placeholder="DD.MM.YYYY" tabindex="1" required="required" /></td>
</tr>
<?PHP
if ($_SESSION['set_sfx'] == 1)
echo '
<tr>
<td>Transaction Type:</td>
<td>
<select name="savtype_id">
<option value="1">Deposit</option>
<option value="3">Savings Interest</option>
</select>
</td>
</tr>
<tr>
<td>Fix Deposit until:</td>
<td><input type="text" id="datepicker2" name="sav_fixed" placeholder="DD.MM.YYYY" tabindex="2" /></td>
</tr>';
else echo '<input type="hidden" name="savtype_id" value="1" />';
?>
<tr>
<td>Amount:</td>
<td><input type="number" name="sav_amount" placeholder="<?PHP echo $_SESSION['set_cur']; ?>" class="defaultnumber" min=1 tabindex="3" required="required" /></td>
</tr>
<tr>
<td>Receipt No:</td>
<td><input type="number" name="sav_receipt" placeholder="for Deposit Transaction" class="defaultnumber" tabindex="4" required="required" /></td>
</tr>
<tr>
<td>Depositor:</td>
<td><input type="text" name="sav_payer" placeholder="if not account holder" tabindex="5" /></td>
</tr>
<tr>
<td colspan="2" class="center"><input type="submit" name="deposit" value="Deposit" tabindex="6" /></td>
</tr>
</table>
</form>
</div>
<!-- RIGHT SIDE: Statement for Savings Account -->
<div class="content_right" style="width:65%;">
<?PHP include 'acc_sav_list.php'; ?>
</div>
</body>
</html>