forked from mangoO-Microfinance/mangoO-Microfinance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer.php
384 lines (349 loc) · 14.7 KB
/
customer.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<!DOCTYPE HTML>
<?PHP
require 'functions.php';
checkLogin();
$db_link = connect();
getCustID($db_link);
unset($_SESSION['interest_sum'], $_SESSION['balance']);
//Generate timestamp
$timestamp = time();
//Calculate Balance on Savings account
$sav_balance = getSavingsBalance($db_link, $_SESSION['cust_id']);
$sav_fixed = getSavingsFixed($db_link, $_SESSION['cust_id']);
//UPDATE-Button
if (isset($_POST['update'])){
//Sanitize user input
$cust_no = sanitize($db_link, $_POST['cust_no']);
$cust_name = sanitize($db_link, $_POST['cust_name']);
$cust_dob = strtotime(sanitize($db_link, $_POST['cust_dob']));
$custsex_id = sanitize($db_link, $_POST['custsex_id']);
$cust_address = sanitize($db_link, $_POST['cust_address']);
$cust_phone = sanitize($db_link, $_POST['cust_phone']);
$cust_email = sanitize($db_link, $_POST['cust_email']);
$cust_occup = sanitize($db_link, $_POST['cust_occup']);
$custmarried_id = sanitize($db_link, $_POST['custmarried_id']);
$cust_heir = sanitize($db_link, $_POST['cust_heir']);
$cust_heirrel = sanitize($db_link, $_POST['cust_heirrel']);
if ($cust_lengthres == 0 OR $cust_lengthres == NULL) $cust_lengthres = NULL;
$custsick_id = sanitize($db_link, $_POST['custsick_id']);
$cust_active = sanitize($db_link, $_POST['cust_active']);
$timestamp = time();
//Update CUSTOMER
$sql_update = "UPDATE customer SET cust_no = '$cust_no', cust_name = '$cust_name', cust_dob = $cust_dob, custsex_id = $custsex_id, cust_address = '$cust_address', cust_phone = '$cust_phone', cust_email = '$cust_email', cust_occup = '$cust_occup', custmarried_id = $custmarried_id, cust_heir = '$cust_heir', cust_heirrel = '$cust_heirrel', custsick_id = $custsick_id, cust_active = '$cust_active', cust_lastupd = $timestamp, user_id = $_SESSION[log_id] WHERE cust_id = $_SESSION[cust_id]";
$query_update = mysqli_query($db_link, $sql_update);
checkSQL($db_link, $query_update);
header('Location: customer.php?cust='.$_SESSION['cust_id']);
}
//Get current customer's details
$result_cust = getCustomer($db_link, $_SESSION['cust_id']);
//Error-Message, if customer is not found
if ($result_cust['cust_id']==''){
echo '<script>
alert(\'Customer not found in database.\');
window.location = "cust_search.php";
</script>';
}
//Select Marital Status from custmarried for dropdown-menu
$sql_mstat = "SELECT * FROM custmarried";
$query_mstat = mysqli_query($db_link, $sql_mstat);
checkSQL($db_link, $query_mstat);
//Select Sicknesses from custsick for dropdown-menu
$sql_sick = "SELECT * FROM custsick";
$query_sick = mysqli_query($db_link, $sql_sick);
checkSQL($db_link, $query_sick);
//Select Sexes from custsex for dropdown-menu
$sql_sex = "SELECT * FROM custsex";
$query_sex = mysqli_query($db_link, $sql_sex);
checkSQL($db_link, $query_sex);
//Select Shares from SHARES
$sql_sha = "SELECT * FROM shares WHERE cust_id = '$_SESSION[cust_id]'";
$query_sha = mysqli_query($db_link, $sql_sha);
checkSQL($db_link, $query_sha);
$share_amount = 0;
$share_value = 0;
while($row_shares = mysqli_fetch_assoc($query_sha)){
$share_amount = $share_amount + $row_shares['share_amount'];
$share_value = $share_value + $row_shares['share_value'];
}
//Select the five most recent savings transactions for display
$sql_sav = "SELECT * FROM savings, savtype WHERE savings.savtype_id = savtype.savtype_id AND cust_id = '$_SESSION[cust_id]' ORDER BY sav_date DESC, sav_id DESC LIMIT 5" ;
$query_sav = mysqli_query($db_link, $sql_sav);
checkSQL($db_link, $query_sav);
?>
<html>
<?PHP includeHead('Customer',0) ?>
<script>
function validate(form){
fail = validateName(form.cust_name.value)
fail += validateDob(form.cust_dob.value)
fail += validateAddress(form.cust_address.value)
fail += validatePhone(form.cust_phone.value)
fail += validateEmail(form.cust_email.value)
if (fail == "") return true
else { alert(fail); return false }
}
function validateSubscr(form){
fail = validateDate(form.subscr_date.value)
fail += validateReceipt(form.subscr_receipt.value)
if (document.getElementById('subscr_from_sav').checked){
fail += validateOverdraft(<?PHP echo $_SESSION['fee_subscr']; ?>, <?PHP echo $sav_balance; ?>, 0, <?PHP echo $_SESSION['set_msb']; ?>, <?PHP echo $sav_fixed; ?>)}
if (fail == "") return true
else { alert(fail); return false }
}
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}
</script>
<script src="functions_validate.js"></script>
</head>
<body>
<!-- MENU -->
<?PHP includeMenu(2); ?>
<div id="menu_main">
<a href="cust_search.php">Search</a>
<?PHP
if ($result_cust['cust_active'] == 1) echo '
<a href="acc_sav_depos.php?cust='.$_SESSION['cust_id'].'">Deposit</a>
<a href="acc_sav_withd.php?cust='.$_SESSION['cust_id'].'">Withdrawal</a>
<a href="acc_share_buy.php?cust='.$_SESSION['cust_id'].'">Share Buy</a>
<a href="acc_share_sale.php?cust='.$_SESSION['cust_id'].'">Share Sale</a>';
if ($result_cust['cust_active'] == 1 AND ($timestamp-$result_cust['cust_since']) > convertMonths($_SESSION['set_minmemb'])) echo '
<a href="loan_new.php?cust='.$_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: Customer Details -->
<div class="content_left" style="width:60%;">
<!-- HEADING -->
<p class="heading" style="margin-bottom:.3em;">
<?PHP echo $result_cust['cust_name'].' ('.$result_cust['cust_no'].')'; ?>
</p>
<form action="customer.php" method="post" onSubmit="return validate(this)">
<table id ="tb_fields" style="border-spacing:0.1em 1.25em;">
<colgroup>
<col width="9%"/>
<col width="25%"/>
<col width="8%"/>
<col width="25%"/>
<col width="8%"/>
<col width="25%"/>
</colgroup>
<?PHP
echo '<tr>
<td rowspan="4" colspan="2" style="text-align:center; vertical-align:top;">
<a href="cust_new_pic.php?from=customer">';
if (isset($result_cust['cust_pic']))
echo '<img src="'.$result_cust['cust_pic'].'" title="Customer\'s picture">';
else {
if ($result_cust['custsex_id'] == 2) echo '<img src="ico/custpic_f.png" title="Upload new picture" />';
else echo '<img src="ico/custpic_m.png" title="Upload new picture" />';
}
echo ' </a>
</td>
<td>Cust No:</td>
<td><input type="text" name="cust_no" value="'.$result_cust['cust_no'].'" tabindex="1" /></td>
<td>Occupation:</td>
<td><input type="text" name="cust_occup" value="'.$result_cust['cust_occup'].'" tabindex="8"/></td>
</tr>';
echo '<tr>
<td>Name:</td>
<td><input type="text" name="cust_name" value="'.$result_cust['cust_name'].'" tabindex="2" /></td>
<td>Marital Status:</td>
<td>
<select name="custmarried_id" size="1" tabindex="9">';
while ($row_mstat = mysqli_fetch_assoc($query_mstat)){
if($row_mstat ['custmarried_id'] == $result_cust['custmarried_id']){
echo '<option selected value="'.$row_mstat['custmarried_id'].'">'.$row_mstat['custmarried_status'].'</option>';
}
else echo '<option value="'.$row_mstat['custmarried_id'].'">'.$row_mstat['custmarried_status'].'</option>';
}
echo ' </select>
</td>
</tr>
<tr>
<td>Gender:</td>
<td>
<select name="custsex_id" size="1" tabindex="3">';
while ($row_sex = mysqli_fetch_assoc($query_sex)){
if($row_sex ['custsex_id'] == $result_cust['custsex_id']){
echo '<option selected value="'.$row_sex['custsex_id'].'">'.$row_sex['custsex_name'].'</option>';
}
else echo '<option value="'.$row_sex['custsex_id'].'">'.$row_sex['custsex_name'].'</option>';
}
echo '</select>
</td>
<td>Representative:</td>
<td><input type="text" name="cust_heir" value="'.$result_cust['cust_heir'].'" tabindex="10" /></td>
</tr>
<tr>
<td>DoB:</td>
<td><input type="text" id="datepicker" name="cust_dob" value="'.date("d.m.Y",$result_cust['cust_dob']).'" placeholder="DD.MM.YYYY" tabindex="4" /></td>
<td>Relation:</td>
<td><input type="text" name="cust_heirrel" value="'.$result_cust['cust_heirrel'].'" tabindex="11" /></td>
</tr>
<tr>';
if ($_SESSION['fee_subscr'] > 0) echo '
<td>Subscrip. expires:</td>
<td><input type="text" name="cust_lastsub" value="'.date("d.m.Y",$result_cust['cust_lastsub']+31536000).'" disabled="disabled"/></td>';
else echo '<td></td><td></td>';
echo '<td>Address:</td>
<td><input type="text" name="cust_address" value="'.$result_cust['cust_address'].'" placeholder="Place of Residence" tabindex="5" /></td>
<td>Sickness:</td>
<td>
<select name="custsick_id" size="1" tabindex="12">';
while ($row_sick = mysqli_fetch_assoc($query_sick)){
if($row_sick['custsick_id'] == $result_cust['custsick_id']){
echo '<option selected value="'.$row_sick['custsick_id'].'">'.$row_sick['custsick_name'].'</option>';
}
else echo '<option value="'.$row_sick['custsick_id'].'">'.$row_sick['custsick_name'].'</option>';
}
echo '</select>
</td>
</tr>';
echo '<tr>
<td>Member since:</td>
<td><input type="text" name="cust_since" value="'.date("d.m.Y", $result_cust['cust_since']).'" disabled="disabled" /></td>
<td>Phone No:</td>
<td><input type="text" name="cust_phone" value="'.$result_cust['cust_phone'].'" tabindex="6" /></td>
<td>Active:</td>
<td><input type="checkbox" name="cust_active" value="1" tabindex="13"';
if ($result_cust['cust_active']==1) echo ' checked="checked"';
echo ' />
</td>
</tr>
<tr>
<td>Updated<br/>on / by:</td>
<td><input type="text" disabled="diabled" value="'.date("d.m.Y", $result_cust['cust_lastupd']).' / '.$result_cust['user_name'].'" /></td>
<td>E-Mail:</td>
<td><input type="text" name="cust_email" value="'.$result_cust['cust_email'].'" placeholder="[email protected]" tabindex="7" /></td>
<td></td>
<td><input type="submit" name="update" value="Save Changes" tabindex="14" /></td>
</tr>';
?>
</table>
<!--
<input type="button" name="membership" value="Subscription" onclick="setVisibility('content_hidden', 'block');" />
-->
</form>
<!-- MIDDLE PART: Renew Subscription -->
<?PHP if($_SESSION['fee_subscr'] > 0) include 'modules/mod_subscr.php'; ?>
</div>
<!-- RIGHT SIDE: Account Details -->
<div class="content_right" style="width:40%;">
<!-- TABLE 1: Savings Account -->
<table id="tb_table">
<colgroup>
<col width="20%">
<col width="30%">
<col width="30%">
<col width="20%">
</colgroup>
<tr>
<th class="title" colspan="4">
<?PHP
if ($result_cust['cust_active'] == 1) echo
'<a href="acc_sav_depos.php?cust='.$_SESSION['cust_id'].'">Savings Account</a> (Recent Transactions)';
else echo 'Savings Account (Recent Transactions)';
?>
</th>
</tr>
<tr>
<th>Date</th>
<th>Transaction Type</th>
<th>Amount</th>
<th>Receipt/Slip</th>
</tr>
<?PHP
while($row_sav = mysqli_fetch_assoc($query_sav)) {
echo '<tr>
<td>'.date("d.m.Y",$row_sav['sav_date']).'</td>
<td>'.$row_sav['savtype_type'].'</td>
<td>'.number_format($row_sav['sav_amount']).' '.$_SESSION['set_cur'].'</td>';
if ($row_sav['savtype_id'] == 2) echo '<td>S '.$row_sav['sav_slip'].'</td>';
else echo '<td>R '.$row_sav['sav_receipt'].'</td>';
echo '</tr>';
}
echo '<tr class="balance">
<td colspan="4" >Balance: '.number_format($sav_balance).' '.$_SESSION['set_cur'].'</td>
</tr>';
?>
</table>
<!-- TABLE 2: Loans Account -->
<table id="tb_table">
<colgroup>
<col width="20%">
<col width="20%">
<col width="20%">
<col width="20%">
<col width="20%">
</colgroup>
<tr>
<th class="title" colspan="6">Loans Account</th>
</tr>
<tr>
<th>Loan No.</th>
<th>Status</th>
<th>Amount</th>
<th>Balance</th>
<th>Next Rate</th>
</tr>
<?PHP
//Select all loans for current customer
$sql_loans = "SELECT * FROM loans, loanstatus WHERE loans.loanstatus_id = loanstatus.loanstatus_id AND cust_id = '$_SESSION[cust_id]'";
$query_loans = mysqli_query($db_link, $sql_loans);
checkSQL($db_link, $query_loans);
while ($row_loan = mysqli_fetch_assoc($query_loans)){
//Select last unpaid Due Date from LTRANS
$sql_ltrans = "SELECT MIN(ltrans_due) FROM ltrans, loans WHERE ltrans.loan_id = loans.loan_id AND loans.loanstatus_id = '2' AND loans.loan_id = '$row_loan[loan_id]' AND ltrans_due IS NOT NULL AND ltrans_date IS NULL";
$query_ltrans = mysqli_query($db_link, $sql_ltrans);
checkSQL($db_link, $query_ltrans);
$next_due = mysqli_fetch_assoc($query_ltrans);
// Get loan balances
$loan_balances = getLoanBalance($db_link, $row_loan['loan_id']);
echo '<tr>
<td><a href="loan.php?lid='.$row_loan['loan_id'].'">'.$row_loan['loan_no'].'</a></td>
<td>'.$row_loan['loanstatus_status'].'</td>';
if ($row_loan['loan_issued'] == 1) echo '
<td>'.number_format($loan_balances['pdue']+$loan_balances['idue']).'</td>
<td>'.number_format($loan_balances['balance']).'</td>';
else echo '<td>'.number_format($row_loan['loan_principal']).'</td>
<td>N/A</td>';
if ($row_loan['loanstatus_id'] == 2 and isset($next_due)) {
echo '<td';
if ($next_due['MIN(ltrans_due)'] < time()) echo ' class="warn"';
if ($next_due['MIN(ltrans_due)'] != null) echo '>'.date("d.m.Y",$next_due['MIN(ltrans_due)']).'</td>';
else echo '></td>';
}
else echo '<td>N/A</td>';
echo '</tr>';
}
?>
</table>
<!-- TABLE 3: Share Account -->
<table id="tb_table">
<tr>
<th class="title" colspan="2">
<?PHP
if ($result_cust['cust_active'] == 1) echo
'<a href="acc_share_buy.php?cust='.$_SESSION['cust_id'].'">Share Account</a>';
else echo 'Share Account';
?>
</th>
</tr>
<tr>
<th>Number of Shares</th>
<th>Value of Shares</th>
</tr>
<tr>
<td><?PHP echo $share_amount ?></td>
<td><?PHP echo number_format($share_value).' '.$_SESSION['set_cur'] ?></td>
</tr>
</table>
</div>
</body>
<?PHP
if ($share_amount == 0 && $result_cust['cust_active'] == 1) showMessage('This Customer owns no Shares!');
?>
</html>