2 /* $Revision: 1.13 $ */
6 include("includes/session.inc");
8 if (($_GET["Type"]=='Receipts') OR ($_POST["Type"]=='Receipts')){
10 $TypeName =_('Receipts');
11 $title = _('Bank Account Deposits Matching');
12 } elseif (($_GET["Type"]=='Payments') OR ($_POST["Type"]=='Payments')) {
14 $TypeName =_('Payments');
15 $title = _('Bank Account Payments Matching');
17 prnMsg(_('This page must be called with a bank transaction type') . '. ' . _('It should not be called directly'),'error');
18 include ('includes/footer.inc');
22 include('includes/header.inc');
24 if (isset($_POST['Update']) AND $_POST['RowCounter']>1){
25 for ($Counter=1;$Counter <= $_POST['RowCounter']; $Counter++
){
26 if ($_POST["Clear_" . $Counter]==True){
27 /*Update the banktrans recoord to match it off */
28 $sql = "UPDATE banktrans SET amountcleared=(amount/exrate)
29 WHERE banktransid=" . $_POST["BankTrans_" . $Counter];
30 $ErrMsg = _('Could not match off this payment beacause');
31 $result = DB_query($sql,$db,$ErrMsg);
33 } elseif (is_numeric((float) $_POST["AmtClear_" . $Counter]) AND (($_POST["AmtClear_" . $Counter]<0 AND $Type=='Payments') OR ($Type=='Receipts' AND ($_POST["AmtClear_" . $Counter]>0)))){
34 /*if the amount entered was numeric and negative for a payment or positive for a receipt */
35 $sql = "UPDATE banktrans SET amountcleared=" . $_POST["AmtClear_" . $Counter] . "
36 WHERE banktransid=" . $_POST["BankTrans_" . $Counter];
38 $ErrMsg = _('Could not update the amount matched off this bank transaction because');
39 $result = DB_query($sql,$db,$ErrMsg);
41 } elseif ($_POST["Unclear_" . $Counter]==True){
42 $sql = "UPDATE banktrans SET amountcleared = 0
43 WHERE banktransid=" . $_POST["BankTrans_" . $Counter];
44 $ErrMsg = _('Could not unclear this bank transaction because');
45 $result = DB_query($sql,$db,$ErrMsg);
48 /*Show the updated position with the same criteria as previously entered*/
49 $_POST["ShowTransactions"] = True;
53 echo "<FORM ACTION='". $_SERVER['PHP_SELF'] . "?" . SID
. "' METHOD=POST>";
55 echo "<INPUT TYPE=HIDDEN Name=Type Value=$Type>";
58 echo '<TD ALIGN=RIGHT>' . _('Bank Account') . ':</TD><TD COLSPAN=3><SELECT name="BankAccount">';
60 $sql = "SELECT accountcode, bankaccountname FROM bankaccounts";
61 $resultBankActs = DB_query($sql,$db);
62 while ($myrow=DB_fetch_array($resultBankActs)){
63 if ($myrow["accountcode"] == $_POST['BankAccount']){
64 echo "<OPTION SELECTED Value='" . $myrow['accountcode'] . "'>" . $myrow['bankaccountname'];
66 echo "<OPTION Value='" . $myrow['accountcode'] . "'>" . $myrow['bankaccountname'];
70 echo '</SELECT></TD></TR>';
72 if (!isset($_POST['BeforeDate']) OR !Is_Date($_POST['BeforeDate'])){
73 $_POST['BeforeDate'] = Date($_SESSION['DefaultDateFormat']);
75 if (!isset($_POST['AfterDate']) OR !Is_Date($_POST['AfterDate'])){
76 $_POST['AfterDate'] = Date($_SESSION['DefaultDateFormat'], Mktime(0,0,0,Date("m")-3,Date("d"),Date("y")));
79 echo '<TR><TD>' . _('Show') . ' ' . $TypeName . ' ' . _('before') . ':</TD>
80 <TD><INPUT TYPE=TEXT NAME="BeforeDate" SIZE=12 MAXLENGTH=12 Value="' . $_POST['BeforeDate'] . '"></TD>';
81 echo '<TD>' . _('but after') . ':</TD>
82 <TD><INPUT TYPE=TEXT NAME="AfterDate" SIZE=12 MAXLENGTH=12 Value="' . $_POST['AfterDate'] . '"></TD></TR>';
83 echo '<TR><TD COLSPAN=3>' . _('Choose outstanding') . ' ' . $TypeName . ' ' . _('only or all') . ' ' . $TypeName . ' ' . _('in the date range') . ':</TD>
84 <TD><SELECT NAME="Ostg_or_All">';
86 if ($_POST["Ostg_or_All"]=='All'){
87 echo '<OPTION SELECTED Value="All">' . _('Show all') . ' ' . $TypeName . ' ' . _('in the date range');
88 echo '<OPTION Value="Ostdg">' . _('Show unmatched') . ' ' . $TypeName . ' ' . _('only');
90 echo '<OPTION Value="All">' . _('Show all') . ' ' . $TypeName . ' ' . _('in the date range');
91 echo '<OPTION SELECTED Value="Ostdg">' . _('Show unmatched') . ' ' . $TypeName . ' ' . _('only');
93 echo '</SELECT></TD></TR>';
95 echo '<TR><TD COLSPAN=3>' . _('Choose to display only the first 20 matching') . ' ' . $TypeName . ' ' . _('or all') . ' ' . $TypeName . ' ' . _('meeting the criteria') . ':</TD><TD><SELECT NAME="First20_or_All">';
96 if ($_POST["First20_or_All"]=='All'){
97 echo '<OPTION SELECTED Value="All">' . _('Show all') . ' ' . $TypeName . ' ' . _('in the date range');
98 echo '<OPTION Value="First20">' . _('Show only the first 20') . ' ' . $TypeName;
100 echo '<OPTION Value="All">' . _('Show all') . ' ' . $TypeName . ' ' . _('in the date range');
101 echo '<OPTION SELECTED Value="First20">' . _('Show only the first 20') . ' ' . $TypeName;
103 echo '</SELECT></TD></TR>';
106 echo '</TABLE><CENTER><INPUT TYPE=SUBMIT NAME="ShowTransactions" VALUE="' . _('Show selected') . ' ' . $TypeName . '">';
107 echo "<P><A HREF='$rootpath/BankReconciliation.php?" . SID
. "'>" . _('Show reconciliation') . '</A>';
111 if (!Is_Date($_POST['BeforeDate'])){
113 prnMsg(_('The date entered for the field to show') . ' ' . $TypeName . ' ' . _('before') . ', ' . _('is not entered in a recognised date format') . '. ' . _('Entry is expected in the format') . ' ' . $_SESSION['DefaultDateFormat'],'error');
115 if (!Is_Date($_POST['AfterDate'])){
117 prnMsg( _('The date entered for the field to show') . ' ' . $Type . ' ' . _('after') . ', ' . _('is not entered in a recognised date format') . '. ' . _('Entry is expected in the format') . ' ' . $_SESSION['DefaultDateFormat'],'error');
120 if ($InputError !=1 AND isset($_POST["BankAccount"]) AND $_POST["BankAccount"]!="" AND isset($_POST["ShowTransactions"])){
122 $SQLBeforeDate = FormatDateForSQL($_POST['BeforeDate']);
123 $SQLAfterDate = FormatDateForSQL($_POST['AfterDate']);
125 if ($_POST["Ostg_or_All"]=='All'){
126 if ($Type=='Payments'){
127 $sql = "SELECT banktransid,
131 amount/exrate as amt,
135 AND transdate >= '". $SQLAfterDate . "'
136 AND transdate <= '" . $SQLBeforeDate . "'
137 AND bankact=" .$_POST["BankAccount"] . "
138 ORDER BY banktransid";
140 } else { /* Type must == Receipts */
141 $sql = "SELECT banktransid,
145 amount/exrate as amt,
149 AND transdate >= '". $SQLAfterDate . "'
150 AND transdate <= '" . $SQLBeforeDate . "'
151 AND bankact=" .$_POST['BankAccount'] . "
152 ORDER BY banktransid";
154 } else { /*it must be only the outstanding bank trans required */
155 if ($Type=='Payments'){
156 $sql = "SELECT banktransid,
160 amount/exrate as amt,
164 AND transdate >= '". $SQLAfterDate . "'
165 AND transdate <= '" . $SQLBeforeDate . "'
166 AND bankact=" .$_POST["BankAccount"] . "
167 AND ABS(amountcleared - (amount / exrate)) > 0.009
168 ORDER BY banktransid";
169 } else { /* Type must == Receipts */
170 $sql = "SELECT banktransid,
174 amount/exrate as amt,
178 AND transdate >= '". $SQLAfterDate . "'
179 AND transdate <= '" . $SQLBeforeDate . "'
180 AND bankact=" .$_POST["BankAccount"] . "
181 AND ABS(amountcleared - (amount / exrate)) > 0.009
182 ORDER BY banktransid";
185 if ($_POST["First20_or_All"]!='All'){
186 $sql = $sql . " LIMIT 20";
189 $ErrMsg = _('The payments with the selected criteria could not be retrieved because');
190 $PaymentsResult = DB_query($sql, $db, $ErrMsg);
192 $TableHeader = '<TR><TD class="tableheader">'. _('Ref'). '</TD>
193 <TD class="tableheader">' . $TypeName . '</TD>
194 <TD class="tableheader">' . _('Date') . '</TD>
195 <TD class="tableheader">' . _('Amount') . '</TD>
196 <TD class="tableheader">' . _('Outstanding') . '</TD>
197 <TD COLSPAN=3 ALIGN=CENTER class="tableheader">' . _('Clear') . ' / ' . _('Unclear') . '</TD>
199 echo '<TABLE CELLPADDING=2 BORDER=2>' . $TableHeader;
202 $j = 1; //page length counter
203 $k=0; //row colour counter
204 $i = 1; //no of rows counter
206 while ($myrow=DB_fetch_array($PaymentsResult)) {
208 $DisplayTranDate = ConvertSQLDate($myrow['transdate']);
209 $Outstanding = $myrow['amt']- $myrow['amountcleared'];
210 if (ABS($Outstanding)<0.009){ /*the payment is cleared dont show the check box*/
212 printf("<tr bgcolor='#CCCEEE'>
216 <td ALIGN=RIGHT>%s</td>
217 <td ALIGN=RIGHT>%s</td>
218 <td COLSPAN=2 ALIGN=CENTER>%s</td>
219 <td ALIGN=CENTER><INPUT TYPE='checkbox' NAME='Unclear_%s'><INPUT TYPE=HIDDEN NAME='BankTrans_%s' VALUE=%s></TD>
222 $myrow['banktranstype'],
224 number_format($myrow['amt'],2),
225 number_format($Outstanding,2),
229 $myrow['banktransid']);
233 echo "<tr bgcolor='#CCCCCC'>";
236 echo "<tr bgcolor='#EEEEEE'>";
243 <td ALIGN=RIGHT>%s</td>
244 <td ALIGN=RIGHT>%s</td>
245 <td ALIGN=CENTER><INPUT TYPE='checkbox' NAME='Clear_%s'><INPUT TYPE=HIDDEN NAME='BankTrans_%s' VALUE=%s></td>
246 <td COLSPAN=2><INPUT TYPE='text' MAXLENGTH=15 SIZE=15 NAME='AmtClear_%s'></td>
249 $myrow['banktranstype'],
251 number_format($myrow['amt'],2),
252 number_format($Outstanding,2),
255 $myrow['banktransid'],
265 //end of page full new headings if
270 echo '</TABLE><INPUT TYPE=HIDDEN NAME="RowCounter" VALUE=' . $i . '><INPUT TYPE=SUBMIT NAME="Update" VALUE="' . _('Update Matching') . '"></CENTER>';
275 include('includes/footer.inc');