-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDailyBankTransactions.php
251 lines (228 loc) · 11.3 KB
/
DailyBankTransactions.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
<?php
/* Allows you to view all bank transactions for a selected date range, and the inquiry can be filtered by matched or unmatched transactions, or all transactions can be chosen. */
include('includes/session.php');
$Title = _('Daily Bank Transactions');// Screen identification.
$ViewTopic = 'GeneralLedger';// Filename's id in ManualContents.php's TOC.
$BookMark = 'DailyBankTransactions';// Anchor's id in the manual's html document.
include('includes/header.php');
if (!isset($_POST['Show'])) {
$SQL = "SELECT bankaccountname,
bankaccounts.accountcode,
bankaccounts.currcode
FROM bankaccounts,
chartmaster,
bankaccountusers
WHERE bankaccounts.accountcode=chartmaster.accountcode
AND bankaccounts.accountcode=bankaccountusers.accountcode
AND bankaccountusers.userid = '" . $_SESSION['UserID'] ."'";
$ErrMsg = _('The bank accounts could not be retrieved because');
$DbgMsg = _('The SQL used to retrieve the bank accounts was');
$AccountsResults = DB_query($SQL,$ErrMsg,$DbgMsg);
echo '<div class="block-header"><a href="" class="header-title-link"><h1> ' .// Icon title.
_('Bank Transactions Inquiry') . '</h1></a></div>';// Page title.
echo '<div class="row gutter30">
<div class="col-xs-12">';
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<div class="row">
<div class="col-xs-4">
<div class="form-group"> <label class="col-md-8 control-label">' . _('Bank Account') . '</label>
<select name="BankAccount" class="form-control">';
if (DB_num_rows($AccountsResults)==0){
echo '</select></div>
</div>';
echo prnMsg( _('Bank Accounts have not yet been defined. You must first') . ' <a href="' . $RootPath . '/BankAccounts.php">' . _('define the bank accounts') . '</a> ' . _('and general ledger accounts to be affected'),'warn');
include('includes/footer.php');
exit;
} else {
while ($myrow=DB_fetch_array($AccountsResults)){
/*list the bank account names */
if (!isset($_POST['BankAccount']) AND $myrow['currcode']==$_SESSION['CompanyRecord']['currencydefault']){
$_POST['BankAccount']=$myrow['accountcode'];
}
if ($_POST['BankAccount']==$myrow['accountcode']){
echo '<option selected="selected" value="' . $myrow['accountcode'] . '">' . $myrow['bankaccountname'] . ' - ' . $myrow['currcode'] . '</option>';
} else {
echo '<option value="' . $myrow['accountcode'] . '">' . $myrow['bankaccountname'] . ' - ' . $myrow['currcode'] . '</option>';
}
}
echo '</select></div></div>';
}
echo '<div class="col-xs-4">
<div class="form-group has-error"> <label class="col-md-8 control-label">' . _('Date From') . '</label>
<input type="text" name="FromTransDate" class="form-control input-datepicker-close" data-date-format="dd/mm/yyyy" id="example-datepicker" required="required" maxlength="10" size="11" onchange="isDate(this, this.value, '."'".$_SESSION['DefaultDateFormat']."'".')" value="' .
date($_SESSION['DefaultDateFormat']) . '" /></div>
</div>
<div class="col-xs-4">
<div class="form-group has-error"> <label class="col-md-8 control-label">' . _('Date To') . '</label>
<input type="text" name="ToTransDate" class="form-control input-datepicker-close" data-date-format="dd/mm/yyyy" id="example-datepicker" required="required" maxlength="10" size="11" onchange="isDate(this, this.value, '."'".$_SESSION['DefaultDateFormat']."'".')" value="' . date($_SESSION['DefaultDateFormat']) . '" /></div>
</div></div>
<div class="row">
<div class="col-xs-4">
<div class="form-group"> <label class="col-md-8 control-label">' . _('Show Transactions') . '</label>
<select name="ShowType" class="form-control">
<option value="All">' . _('All') . '</option>
<option value="Unmatched">' . _('Unmatched') . '</option>
<option value="Matched">' . _('Matched') . '</option>
</select></div>
</div>
<div class="col-xs-4">
<div class="form-group"> <br />
<input type="submit" class="btn btn-info" name="Show" value="' . _('Show'). '" />
</div>
</div>
</div>
</form></div></div>';
} else {
$SQL = "SELECT bankaccountname,
bankaccounts.currcode,
currencies.decimalplaces
FROM bankaccounts
INNER JOIN currencies
ON bankaccounts.currcode = currencies.currabrev
WHERE bankaccounts.accountcode='" . $_POST['BankAccount'] . "'";
$BankResult = DB_query($SQL,_('Could not retrieve the bank account details'));
$sql="SELECT (SELECT sum(banktrans.amount) FROM banktrans
WHERE transdate < '" . FormatDateForSQL($_POST['FromTransDate']) . "'
AND bankact='" . $_POST['BankAccount'] ."') AS prebalance,
banktrans.currcode,
banktrans.amount,
banktrans.amountcleared,
banktrans.functionalexrate,
banktrans.exrate,
banktrans.banktranstype,
banktrans.transdate,
banktrans.transno,
banktrans.ref,
bankaccounts.bankaccountname,
systypes.typename,
systypes.typeid
FROM banktrans
INNER JOIN bankaccounts
ON banktrans.bankact=bankaccounts.accountcode
INNER JOIN systypes
ON banktrans.type=systypes.typeid
WHERE bankact='".$_POST['BankAccount']."'
AND transdate>='" . FormatDateForSQL($_POST['FromTransDate']) . "'
AND transdate<='" . FormatDateForSQL($_POST['ToTransDate']) . "'
ORDER BY banktrans.transdate ASC, banktrans.banktransid ASC";
$result = DB_query($sql);
$BankDetailRow = DB_fetch_array($BankResult);
if (DB_num_rows($result)==0) {
echo '<div class="block-header"><a href="" class="header-title-link"><h1>' .// Icon title.
_('Bank Transactions Inquiry') . '</h1></a></div>';// Page title.
echo prnMsg(_('There are no transactions for this account in the date range selected'), 'error');
$sql = "SELECT sum(banktrans.amount) FROM banktrans WHERE bankact='" . $_POST['BankAccount'] . "'";
$ErrMsg = _('Failed to retrive balance data');
$balresult = DB_query($sql,$ErrMsg);
if (DB_num_rows($balresult)>0) {
$Balance = DB_fetch_row($balresult);
$Balance = $Balance[0];
if (ABS($Balance)>0.001){
echo '<div class="block-header"><a href="" class="header-title-link"><h1>' . _('The Bank Account Balance Is in') . ' ' . $BankDetailRow['currcode'] . ' ' . locale_number_format($Balance,$BankDetailRow['decimalplaces']) . '</h1></a></div>';
}
}
} else {
echo '<div id="Report">';// Division to identify the report block.
echo '<div class="block-header"><a href="" class="header-title-link"><h1> ' .// Icon title.
_('Account Transactions For').'<br />'.$BankDetailRow['bankaccountname'].'<br /><small>'.
_('Between').' '.$_POST['FromTransDate'] . ' ' . _('and') . ' ' . $_POST['ToTransDate'] . '</h1></a></div>';// Page title.*/
echo '<div class="row gutter30">
<div class="col-xs-12">
<div class="table-responsive">
<table id="general-table" class="table table-bordered">
<thead>
<tr>
<th>' . ('Date') . '</th>
<th>' . _('Transaction type') . '</th>
<th>' . _('Transaction Number') . '</th>
<th>' . _('Transaction Mode') . '</th>
<th>' . _('Reference') . '</th>
<th>' . _('Amount in orginal currency') . '</th>
<th>' . _('Balance in') . ' ' . $BankDetailRow['currcode'] . '</th>
<th>' . _('Running Total').' '.$BankDetailRow['currcode'] . '</th>
<th>' . _('Amount in').' '.$_SESSION['CompanyRecord']['currencydefault'] . '</th>
<th>' . _('Running Total').' '.$_SESSION['CompanyRecord']['currencydefault'] . '</th>
<th>' . _('Cleared?') . '</th>
<th>' . _('GL Narrative') . '</th>
</tr>
</thead><tbody>';
$AccountCurrTotal=0;
$LocalCurrTotal =0;
$Balance = 0;
$j = 0;
while ($myrow = DB_fetch_array($result)){
if ($j == 0) {
if (ABS($myrow['prebalance'])>0.0001) {
$Balance += $myrow['prebalance'];
echo '<tr class="striped_row">
<td colspan="6" style="font-weight:bold">' . _('Previous Balance') . '</td>
<td class="number">' . locale_number_format($myrow['prebalance'],$BankDetailRow['decimalplaces']) . '</td>
<td colspan="5"></td>
</tr>';
$j++;
}
}
//check the GL narrative
if ($myrow['type'] == 2) {
$myrow['typeid'] = 1;
$myrow['transno'] = substr($myrow['ref'],1,strpos($myrow['ref'],' ')-1);
}
$sql = "SELECT narrative FROM gltrans WHERE type='" . $myrow['typeid'] . "' AND typeno='" . $myrow['transno'] . "'";
$ErrMsg = _('Failed to retrieve gl narrative');
$glresult = DB_query($sql,$ErrMsg);
if (DB_num_rows($glresult)>0) {
$GLNarrative = DB_fetch_array($glresult);
$GLNarrative = $GLNarrative[0];
} else {
$GLNarrative = 'NA';
}
$Balance += $myrow['amount']/$myrow['exrate'];
$AccountCurrTotal += $myrow['amount']/$myrow['exrate'];
$LocalCurrTotal += $myrow['amount']/$myrow['functionalexrate']/$myrow['exrate'];
if ($myrow['amount']==$myrow['amountcleared']) {
$Matched=_('Yes');
} else {
$Matched=_('No');
}
echo '<tr class="striped_row">
<td class="centre">' . ConvertSQLDate($myrow['transdate']) . '</td>
<td>' . _($myrow['typename']) . '</td>
<td class="number"><a href="' . $RootPath . '/GLTransInquiry.php?TypeID=' . $myrow['typeid'] . '&TransNo=' . $myrow['transno'] . '" class="btn btn-info">' . $myrow['transno'] . '</a></td>
<td>' . $myrow['banktranstype'] . '</td>
<td>' . $myrow['ref'] . '</td>
<td class="number">' . locale_number_format($myrow['amount'],$BankDetailRow['decimalplaces']) . ' ' . $myrow['currcode'] . '</td>
<td class="number">' . locale_number_format($Balance,$BankDetailRow['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($AccountCurrTotal,$BankDetailRow['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($myrow['amount']/$myrow['functionalexrate']/$myrow['exrate'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($LocalCurrTotal,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . $Matched . '</td>
<td>' . $GLNarrative . '</td>
</tr>';
}
echo '<tr class="striped_row">
<td colspan="6" style="font-weight:bold;">' . _('Account Balance') . '</td>
<td class="number" style="font-weight:bold;">' .locale_number_format($Balance,$BankDetailRow['decimalplaces']) . '</td>
<td colspan="5"></td>
</tr>
</tbody></table>';
echo '</div></div></div></div>';// div id="Report".
} //end if no bank trans in the range to show
echo '<div class="row gutter30">
<div class="col-xs-12">';
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">
<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
<div class="row">
<div class="col-xs-4">
<div class="form-group">', // Form buttons:
'<button onclick="javascript:window.print()" class="btn btn-info" type="button">', _('Print'), '</button></div></div>', // "Print" button.
'<div class="col-xs-4">
<div class="form-group"><button name="SelectADifferentPeriod" class="btn btn-info" type="submit" value="'. _('Select A Different Period') .'">' .
_('Select Another Date') . '</button></div></div>'.// "Select A Different Period" button.
'<div class="col-xs-4">
<div class="form-group"><button onclick="window.location=\'menu_data.php?Application=GL\'" class="btn btn-default" type="button"> ', _('Return'), '</button></div></div>', // "Return" button.
'</div>
</form></div></div>';
}
include('includes/footer.php');
?>