forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaymentMethods.php
331 lines (294 loc) · 13.1 KB
/
PaymentMethods.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
<?php
include('includes/session.php');
$Title = _('Payment Methods');
/* Manual links before header.php */
/* RChacon: This is a topic to create.*/
$ViewTopic = 'ARTransactions';// Filename in ManualContents.php's TOC.
$BookMark = 'PaymentMethods';// Anchor's id in the manual's html document.
include('includes/header.php');
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/transactions.png" title="' . _('Payments') .
'" alt="" />' . ' ' . $Title . '</p>';
if ( isset($_GET['SelectedPaymentID']) )
$SelectedPaymentID = $_GET['SelectedPaymentID'];
elseif (isset($_POST['SelectedPaymentID']))
$SelectedPaymentID = $_POST['SelectedPaymentID'];
if (isset($Errors)) {
unset($Errors);
}
$Errors = array();
if (isset($_POST['submit'])) {
//initialise no input errors assumed initially before we test
$InputError = 0;
/* actions to take once the user has clicked the submit button
ie the page has called itself with some user input */
$i=1;
//first off validate inputs sensible
if (ContainsIllegalCharacters($_POST['MethodName'])) {
$InputError = 1;
prnMsg( _('The payment method cannot contain illegal characters') . ' ' . '" \' - & or a space','error');
$Errors[$i] = 'MethodName';
$i++;
}
if ( trim($_POST['MethodName']) == "") {
$InputError = 1;
prnMsg( _('The payment method may not be empty.'),'error');
$Errors[$i] = 'MethodName';
$i++;
}
if (!is_numeric(filter_number_format($_POST['DiscountPercent']))) {
$InputError = 1;
prnMsg( _('The discount percentage must be a number less than 1'),'error');
$Errors[$i] = 'DiscountPercent';
$i++;
} else if (filter_number_format($_POST['DiscountPercent'])>1) {
$InputError = 1;
prnMsg( _('The discount percentage must be a number less than 1'),'error');
$Errors[$i] = 'DiscountPercent';
$i++;
} else if (filter_number_format($_POST['DiscountPercent'])<0) {
$InputError = 1;
prnMsg( _('The discount percentage must be either zero or less than 1'),'error');
$Errors[$i] = 'DiscountPercent';
$i++;
}
if (isset($_POST['SelectedPaymentID']) AND $InputError !=1) {
/*SelectedPaymentID could also exist if submit had not been clicked this code would not run in this case cos submit is false of course see the delete code below*/
// Check the name does not clash
$SQL = "SELECT count(*) FROM paymentmethods
WHERE paymentid <> '" . $SelectedPaymentID ."'
AND paymentname ".LIKE." '" . $_POST['MethodName'] . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ( $MyRow[0] > 0 ) {
$InputError = 1;
prnMsg( _('The payment method can not be renamed because another with the same name already exists.'),'error');
} else {
// Get the old name and check that the record still exists need to be very careful here
$SQL = "SELECT paymentname FROM paymentmethods
WHERE paymentid = '" . $SelectedPaymentID . "'";
$Result = DB_query($SQL);
if ( DB_num_rows($Result) != 0 ) {
$MyRow = DB_fetch_row($Result);
$OldName = $MyRow[0];
$SQL = "UPDATE paymentmethods
SET paymentname='" . $_POST['MethodName'] . "',
paymenttype = '" . $_POST['ForPayment'] . "',
receipttype = '" . $_POST['ForReceipt'] . "',
usepreprintedstationery = '" . $_POST['UsePrePrintedStationery']. "',
opencashdrawer = '" . $_POST['OpenCashDrawer'] . "',
percentdiscount = '" . filter_number_format($_POST['DiscountPercent']) . "'
WHERE paymentname " . LIKE . " '".$OldName."'";
} else {
$InputError = 1;
prnMsg( _('The payment method no longer exists.'),'error');
}
}
$Msg = _('Record Updated');
$ErrMsg = _('Could not update payment method');
} elseif ($InputError !=1) {
/*SelectedPaymentID is null cos no item selected on first time round so must be adding a record*/
$SQL = "SELECT count(*) FROM paymentmethods
WHERE paymentname LIKE'".$_POST['MethodName'] ."'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ( $MyRow[0] > 0 ) {
$InputError = 1;
prnMsg( _('The payment method can not be created because another with the same name already exists.'),'error');
} else {
$SQL = "INSERT INTO paymentmethods (paymentname,
paymenttype,
receipttype,
usepreprintedstationery,
opencashdrawer,
percentdiscount)
VALUES ('" . $_POST['MethodName'] ."',
'" . $_POST['ForPayment'] ."',
'" . $_POST['ForReceipt'] ."',
'" . $_POST['UsePrePrintedStationery'] ."',
'" . $_POST['OpenCashDrawer'] . "',
'" . filter_number_format($_POST['DiscountPercent']) . "')";
}
$Msg = _('New payment method added');
$ErrMsg = _('Could not insert the new payment method');
}
if ($InputError!=1){
$Result = DB_query($SQL, $ErrMsg);
prnMsg($Msg,'success');
echo '<br />';
}
unset ($SelectedPaymentID);
unset ($_POST['SelectedPaymentID']);
unset ($_POST['MethodName']);
unset ($_POST['ForPayment']);
unset ($_POST['ForReceipt']);
unset ($_POST['OpenCashDrawer']);
unset ($_POST['UsePrePrintedStationery']);
} elseif (isset($_GET['delete'])) {
//the link to delete a selected record was clicked instead of the submit button
// PREVENT DELETES IF DEPENDENT RECORDS IN 'stockmaster'
// Get the original name of the payment method the ID is just a secure way to find the payment method
$SQL = "SELECT paymentname FROM paymentmethods
WHERE paymentid = '" . $SelectedPaymentID . "'";
$Result = DB_query($SQL);
if ( DB_num_rows($Result) == 0 ) {
// This is probably the safest way there is
prnMsg( _('Cannot delete this payment method because it no longer exist'),'warn');
} else {
$MyRow = DB_fetch_row($Result);
$OldMeasureName = $MyRow[0];
$SQL= "SELECT COUNT(*) FROM banktrans
WHERE banktranstype LIKE '" . $OldMeasureName . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if ($MyRow[0]>0) {
prnMsg( _('Cannot delete this payment method because bank transactions have been created using this payment method'),'warn');
echo '<br />' . _('There are') . ' ' . $MyRow[0] . ' ' . _('bank transactions that refer to this payment method') . '</font>';
} else {
$SQL="DELETE FROM paymentmethods WHERE paymentname " . LIKE . " '" . $OldMeasureName . "'";
$Result = DB_query($SQL);
prnMsg( $OldMeasureName . ' ' . _('payment method has been deleted') . '!','success');
echo '<br />';
} //end if not used
} //end if payment method exist
unset ($SelectedPaymentID);
unset ($_GET['SelectedPaymentID']);
unset($_GET['delete']);
unset ($_POST['SelectedPaymentID']);
unset ($_POST['MethodID']);
unset ($_POST['MethodName']);
unset ($_POST['ForPayment']);
unset ($_POST['ForReceipt']);
unset ($_POST['OpenCashDrawer']);
}
if (!isset($SelectedPaymentID)) {
/* A payment method could be posted when one has been edited and is being updated
or GOT when selected for modification
SelectedPaymentID will exist because it was sent with the page in a GET .
If its the first time the page has been displayed with no parameters
then none of the above are true and the list of payment methods will be displayed with
links to delete or edit each. These will call the same page again and allow update/input
or deletion of the records*/
$SQL = "SELECT paymentid,
paymentname,
paymenttype,
receipttype,
usepreprintedstationery,
opencashdrawer,
percentdiscount
FROM paymentmethods
ORDER BY paymentid";
$ErrMsg = _('Could not get payment methods because');
$Result = DB_query($SQL,$ErrMsg);
echo '<table class="selection">
<thead>
<tr>
<th class="SortedColumn">' . _('Payment Method') . '</th>
<th class="SortedColumn">' . _('Use For Payments') . '</th>
<th class="SortedColumn">' . _('Use For Receipts') . '</th>
<th class="SortedColumn">' . _('Use Pre-printed Stationery') . '</th>
<th class="SortedColumn">' . _('Open POS Cash Drawer for Sale') . '</th>
<th class="SortedColumn">' . _('Payment discount') . ' %</th>
<th colspan="2"> </th>
</tr>
</thead>
<tbody>';
while ($MyRow = DB_fetch_array($Result)) {
echo '<tr class="striped_row">
<td>' . $MyRow['paymentname'] . '</td>
<td class="centre">' . ($MyRow['paymenttype'] ? _('Yes') : _('No')) . '</td>
<td class="centre">' . ($MyRow['receipttype'] ? _('Yes') : _('No')) . '</td>
<td class="centre">' . ($MyRow['usepreprintedstationery'] ? _('Yes') : _('No')) . '</td>
<td class="centre">' . ($MyRow['opencashdrawer'] ? _('Yes') : _('No')) . '</td>
<td class="centre">' . locale_number_format($MyRow['percentdiscount']*100,2) . '</td>
<td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?SelectedPaymentID=' . $MyRow['paymentid'] . '">' . _('Edit') . '</a></td>
<td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?SelectedPaymentID=' . $MyRow['paymentid'] . '&delete=1" onclick="return confirm(\'' . _('Are you sure you wish to delete this payment method?') . '\');">' . _('Delete') . '</a></td>
</tr>';
} //END WHILE LIST LOOP
echo '</tbody></table><br />';
} //end of ifs and buts!
if (isset($SelectedPaymentID)) {
echo '<div class="centre"><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">' . _('Review Payment Methods') . '</a></div>';
}
if (! isset($_GET['delete'])) {
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
if (isset($SelectedPaymentID)) {
//editing an existing section
$SQL = "SELECT paymentid,
paymentname,
paymenttype,
receipttype,
usepreprintedstationery,
opencashdrawer,
percentdiscount
FROM paymentmethods
WHERE paymentid='" . $SelectedPaymentID . "'";
$Result = DB_query($SQL);
if ( DB_num_rows($Result) == 0 ) {
prnMsg( _('Could not retrieve the requested payment method, please try again.'),'warn');
unset($SelectedPaymentID);
} else {
$MyRow = DB_fetch_array($Result);
$_POST['MethodID'] = $MyRow['paymentid'];
$_POST['MethodName'] = $MyRow['paymentname'];
$_POST['ForPayment'] = $MyRow['paymenttype'];
$_POST['ForReceipt'] = $MyRow['receipttype'];
$_POST['UsePrePrintedStationery'] = $MyRow['usepreprintedstationery'];
$_POST['OpenCashDrawer'] = $MyRow['opencashdrawer'];
$_POST['DiscountPercent'] = $MyRow['percentdiscount'];
echo '<input type="hidden" name="SelectedPaymentID" value="' . $_POST['MethodID'] . '" />';
echo '<fieldset>
<legend>', _('Edit Payment Method'), '</legend>';
}
} else {
$_POST['MethodName']='';
$_POST['ForPayment'] = 1; // Default is use for payment
$_POST['ForReceipt'] = 1; // Default is use for receipts
$_POST['UsePrePrintedStationery'] = 0; // Default is use for receipts
$_POST['OpenCashDrawer'] = 0; //Default is not to open cash drawer
$_POST['DiscountPercent']=0;
echo '<fieldset>
<legend>', _('Create Payment Method'), '</legend>';
}
echo '<field>
<label for="MethodName">' . _('Payment Method') . ':</label>
<input type="text" '. (in_array('MethodName',$Errors) ? 'class="inputerror"' : '' ) .' name="MethodName" autofocus="autofocus" required="required" size="30" maxlength="30" value="' . $_POST['MethodName'] . '" />
</field>';
echo '<field>
<label for="ForPayment">' . _('Use For Payments') . ':' . '</label>
<select required="required" name="ForPayment">
<option' . ($_POST['ForPayment'] ? ' selected="selected"' : '') .' value="1">' . _('Yes') . '</option>
<option' . ($_POST['ForPayment'] ? '' : ' selected="selected"') .' value="0">' . _('No') . '</option>
</select>
</field>';
echo '<field>
<label for="ForReceipt">' . _('Use For Receipts') . ':</label>
<select required="required" name="ForReceipt">
<option' . ($_POST['ForReceipt'] ? ' selected="selected"' : '') .' value="1">' . _('Yes') . '</option>
<option' . ($_POST['ForReceipt'] ? '' : ' selected="selected"') .' value="0">' . _('No') . '</option>
</select>
</field>';
echo '<field>
<label for="UsePrePrintedStationery">' . _('Use Pre-printed Stationery') . ':' . '</label>
<select name="UsePrePrintedStationery">
<option' . ($_POST['UsePrePrintedStationery'] ? ' selected="selected"': '' ) .' value="1">' . _('Yes') . '</option>
<option' . ($_POST['UsePrePrintedStationery']==1 ? '' : ' selected="selected"' ) .' value="0">' . _('No') . '</option>
</select>
</field>';
echo '<field>
<label for="OpenCashDrawer">' . _('Open POS Cash Drawer for Sale') . ':' . '</label>
<select name="OpenCashDrawer">
<option' . ($_POST['OpenCashDrawer'] ? ' selected="selected"' : '') .' value="1">' . _('Yes') . '</option>
<option' . ($_POST['OpenCashDrawer'] ? '' : ' selected="selected"') .' value="0">' . _('No') . '</option>
</select>
</field>';
echo '<field>
<label for="DiscountPercent">' . _('Payment Discount Percent on Receipts') . ':' . '</label>
<input type="text" class="number" min="0" max="1" name="DiscountPercent" value="' . locale_number_format($_POST['DiscountPercent'],2) . '" />
</field>';
echo '</fieldset>';
echo '<div class="centre"><input type="submit" name="submit" value="' . _('Enter Information') . '" /></div>';
echo '</form>';
} //end if record deleted no point displaying form to add record
include('includes/footer.php');
?>