forked from altairisfr/takepos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpay.php
446 lines (403 loc) · 17.8 KB
/
pay.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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<?php
/* Copyright (C) 2018 Andreu Bisquerra <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/takepos/pay.php
* \ingroup takepos
* \brief Page with the content of the popup to enter payments
*/
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
if (!defined('NOCSRFCHECK')) {
define('NOCSRFCHECK', '1');
}
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1');
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
//if (!defined('NOREQUIREAJAX')) {
// define('NOREQUIREAJAX', '1');
//}
require '../main.inc.php'; // Load $user and permissions
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$langs->loadLangs(array("main", "bills", "cashdesk", "banks"));
$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : '0'); // $place is id of table for Bar or Restaurant
$invoiceid = GETPOST('invoiceid', 'int');
if (empty($user->rights->takepos->run)) {
accessforbidden();
}
$hookmanager->initHooks(array('takeposinvoice'));
/*
* View
*/
$invoice = new Facture($db);
if ($invoiceid > 0) {
$invoice->fetch($invoiceid);
} else {
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
$resql = $db->query($sql);
$obj = $db->fetch_object($resql);
if ($obj) {
$invoiceid = $obj->rowid;
}
if (!$invoiceid) {
$invoiceid = 0; // Invoice does not exist yet
} else {
$invoice->fetch($invoiceid);
}
}
$arrayofcss = array('/takepos/css/pos.css.php');
$arrayofjs = array();
$head = '';
$title = '';
$disablejs = 0;
$disablehead = 0;
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
// Define list of possible payments
$arrayOfValidPaymentModes = array();
$arrayOfValidBankAccount = array();
$sql = "SELECT code, libelle as label FROM ".MAIN_DB_PREFIX."c_paiement";
$sql .= " WHERE entity IN (".getEntity('c_paiement').")";
$sql .= " AND active = 1";
$sql .= " ORDER BY libelle";
$resql = $db->query($sql);
if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$paycode = $obj->code;
if ($paycode == 'LIQ') {
$paycode = 'CASH';
}
if ($paycode == 'CB') {
$paycode = 'CB';
}
if ($paycode == 'CHQ') {
$paycode = 'CHEQUE';
}
$accountname = "CASHDESK_ID_BANKACCOUNT_".$paycode.$_SESSION["takeposterminal"];
if (!empty($conf->global->$accountname) && $conf->global->$accountname > 0) {
$arrayOfValidBankAccount[$conf->global->$accountname] = $conf->global->$accountname;
$arrayOfValidPaymentModes[] = $obj;
}
}
}
?>
<link rel="stylesheet" href="css/pos.css.php">
<?php
if ($conf->global->TAKEPOS_COLOR_THEME == 1) {
print '<link rel="stylesheet" href="css/colorful.css">';
}
?>
</head>
<body>
<script>
<?php
$remaintopay = 0;
if ($invoice->id > 0) {
$remaintopay = $invoice->getRemainToPay();
}
$alreadypayed = (is_object($invoice) ? ($invoice->total_ttc - $remaintopay) : 0);
if ($conf->global->TAKEPOS_NUMPAD == 0) {
print "var received='';";
} else {
print "var received=0;";
}
?>
var alreadypayed = <?php echo $alreadypayed ?>;
function addreceived(price)
{
<?php
if (empty($conf->global->TAKEPOS_NUMPAD)) {
print 'received+=String(price);'."\n";
} else {
print 'received+=parseFloat(price);'."\n";
}
?>
$('.change1').html(pricejs(parseFloat(received), 'MT'));
$('.change1').val(parseFloat(received));
alreadypaydplusreceived=price2numjs(alreadypayed + parseFloat(received));
//console.log("already+received = "+alreadypaydplusreceived);
//console.log("total_ttc = "+<?php echo $invoice->total_ttc; ?>);
if (alreadypaydplusreceived > <?php echo $invoice->total_ttc; ?>)
{
var change=parseFloat(alreadypayed + parseFloat(received) - <?php echo $invoice->total_ttc; ?>);
$('.change2').html(pricejs(change, 'MT'));
$('.change2').val(change);
$('.change1').removeClass('colorred');
$('.change1').addClass('colorgreen');
$('.change2').removeClass('colorwhite');
$('.change2').addClass('colorred');
}
else
{
$('.change2').html(pricejs(0, 'MT'));
$('.change2').val(0);
if (alreadypaydplusreceived == <?php echo $invoice->total_ttc; ?>)
{
$('.change1').removeClass('colorred');
$('.change1').addClass('colorgreen');
$('.change2').removeClass('colorred');
$('.change2').addClass('colorwhite');
}
else
{
$('.change1').removeClass('colorgreen');
$('.change1').addClass('colorred');
$('.change2').removeClass('colorred');
$('.change2').addClass('colorwhite');
}
}
}
function reset()
{
received=0;
$('.change1').html(pricejs(received, 'MT'));
$('.change1').val(price2numjs(received));
$('.change2').html(pricejs(received, 'MT'));
$('.change2').val(price2numjs(received));
$('.change1').removeClass('colorgreen');
$('.change1').addClass('colorred');
$('.change2').removeClass('colorred');
$('.change2').addClass('colorwhite');
}
function Validate(payment)
{
var invoiceid = <?php echo ($invoiceid > 0 ? $invoiceid : 0); ?>;
var accountid = $("#selectaccountid").val();
var amountpayed = $("#change1").val();
var excess = $("#change2").val();
if (amountpayed > <?php echo $invoice->total_ttc; ?>) {
amountpayed = <?php echo $invoice->total_ttc; ?>;
}
console.log("We click on the payment mode to pay amount = "+amountpayed);
parent.$("#poslines").load("invoice.php?place=<?php echo $place; ?>&action=valid&pay="+payment+"&amount="+amountpayed+"&excess="+excess+"&invoiceid="+invoiceid+"&accountid="+accountid, function() {
if (amountpayed > <?php echo $remaintopay; ?> || amountpayed == <?php echo $remaintopay; ?> || amountpayed==0 ) {
console.log("Close popup");
parent.$.colorbox.close();
}
else {
console.log("Amount is not comple, so we do NOT close popup and reload it.");
location.reload();
}
});
}
function ValidateSumup() {
console.log("Launch ValidateSumup");
<?php $_SESSION['SMP_CURRENT_PAYMENT'] = "NEW" ?>
var invoiceid = <?php echo($invoiceid > 0 ? $invoiceid : 0); ?>;
var amountpayed = $("#change1").val();
if (amountpayed > <?php echo $invoice->total_ttc; ?>) {
amountpayed = <?php echo $invoice->total_ttc; ?>;
}
// Starting sumup app
window.open('sumupmerchant://pay/1.0?affiliate-key=<?php echo $conf->global->TAKEPOS_SUMUP_AFFILIATE ?>&app-id=<?php echo $conf->global->TAKEPOS_SUMUP_APPID ?>&total=' + amountpayed + '¤cy=EUR&title=' + invoiceid + '&callback=<?php echo DOL_MAIN_URL_ROOT ?>/takepos/smpcb.php');
var loop = window.setInterval(function () {
$.ajax({
method: 'POST',
data: { token: '<?php echo currentToken(); ?>' },
url: '<?php echo DOL_URL_ROOT ?>/takepos/smpcb.php?status' }).done(function (data) {
console.log(data);
if (data === "SUCCESS") {
parent.$("#poslines").load("invoice.php?place=<?php echo $place; ?>&action=valid&pay=CB&amount=" + amountpayed + "&invoiceid=" + invoiceid, function () {
//parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
parent.$.colorbox.close();
//parent.setFocusOnSearchField(); // This does not have effect
});
clearInterval(loop);
} else if (data === "FAILED") {
parent.$.colorbox.close();
clearInterval(loop);
}
});
}, 2500);
}
</script>
<div style="position:relative; padding-top: 20px; left:5%; height:150px; width:90%;">
<div class="paymentbordline paymentbordlinetotal center">
<span class="takepospay colorwhite"><?php echo $langs->trans('TotalTTC'); ?>: <span id="totaldisplay" class="colorwhite"><?php echo price($invoice->total_ttc, 1, '', 1, -1, -1, $invoice->multicurrency_code); ?></span></span>
</div>
<?php if ($remaintopay != $invoice->total_ttc) { ?>
<div class="paymentbordline paymentbordlineremain center">
<span class="takepospay colorwhite"><?php echo $langs->trans('RemainToPay'); ?>: <span id="remaintopaydisplay" class="colorwhite"><?php echo price($remaintopay, 1, '', 1, -1, -1, $invoice->multicurrency_code); ?></span></span>
</div>
<?php } ?>
<div class="paymentbordline paymentbordlinereceived center">
<span class="takepospay colorwhite"><?php echo $langs->trans("Received"); ?>: <span class="change1 colorred"><?php echo price(0, 1, '', 1, -1, -1, $invoice->multicurrency_code); ?></span><input type="hidden" id="change1" class="change1" value="0"></span>
</div>
<div class="paymentbordline paymentbordlinechange center">
<span class="takepospay colorwhite"><?php echo $langs->trans("Change"); ?>: <span class="change2 colorwhite"><?php echo price(0, 1, '', 1, -1, -1, $invoice->multicurrency_code); ?></span><input type="hidden" id="change2" class="change2" value="0"></span>
</div>
<?php
if (!empty($conf->global->TAKEPOS_CAN_FORCE_BANK_ACCOUNT_DURING_PAYMENT)) {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
print '<div class="paymentbordline paddingtop paddingbottom center">';
$filter = '';
$form = new Form($db);
print '<span class="takepospay colorwhite">'.$langs->trans("BankAccount").': </span>';
$form->select_comptes(0, 'accountid', 0, $filter, 1, '');
print ajax_combobox('selectaccountid');
print '</div>';
}
?>
</div>
<div style="position:absolute; left:5%; height:52%; width:90%;">
<?php
$action_buttons = array(
array(
"function" =>"reset()",
"span" => "style='font-size: 150%;'",
"text" => "C",
"class" => "poscolorblue"
),
array(
"function" => "parent.$.colorbox.close();",
"span" => "id='printtext' style='font-weight: bold; font-size: 18pt;'",
"text" => "X",
"class" => "poscolordelete"
),
);
$numpad = $conf->global->TAKEPOS_NUMPAD;
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '7' : '10').');">'.($numpad == 0 ? '7' : '10').'</button>';
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '8' : '20').');">'.($numpad == 0 ? '8' : '20').'</button>';
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '9' : '50').');">'.($numpad == 0 ? '9' : '50').'</button>';
?>
<?php if (count($arrayOfValidPaymentModes) > 0) {
$paycode = $arrayOfValidPaymentModes[0]->code;
$payIcon = '';
if ($paycode == 'LIQ') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'coins';
}
} elseif ($paycode == 'CB') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'credit-card';
}
} elseif ($paycode == 'CHQ') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'money-check';
}
}
print '<button type="button" class="calcbutton2" onclick="Validate(\''.dol_escape_js($paycode).'\');">'.(!empty($payIcon) ? '<span class="fa fa-2x fa-'.$payIcon.' iconwithlabel"></span><span class="hideonsmartphone"><br>'. $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[0]->code) : $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[0]->code)).'</span></button>';
} else {
print '<button type="button" class="calcbutton2">'.$langs->trans("NoPaimementModesDefined").'</button>';
}
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '4' : '1').');">'.($numpad == 0 ? '4' : '1').'</button>';
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '5' : '2').');">'.($numpad == 0 ? '5' : '2').'</button>';
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '6' : '5').');">'.($numpad == 0 ? '6' : '5').'</button>';
?>
<?php if (count($arrayOfValidPaymentModes) > 1) {
$paycode = $arrayOfValidPaymentModes[1]->code;
$payIcon = '';
if ($paycode == 'LIQ') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'coins';
}
} elseif ($paycode == 'CB') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'credit-card';
}
} elseif ($paycode == 'CHQ') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'money-check';
}
}
print '<button type="button" class="calcbutton2" onclick="Validate(\''.dol_escape_js($paycode).'\');">'.(!empty($payIcon) ? '<span class="fa fa-2x fa-'.$payIcon.' iconwithlabel"></span><br> '. $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[1]->code) : $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[1]->code)).'</button>';
} else {
$button = array_pop($action_buttons);
print '<button type="button" class="calcbutton2" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
}
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '1' : '0.10').');">'.($numpad == 0 ? '1' : '0.10').'</button>';
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '2' : '0.20').');">'.($numpad == 0 ? '2' : '0.20').'</button>';
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '3' : '0.50').');">'.($numpad == 0 ? '3' : '0.50').'</button>';
?>
<?php if (count($arrayOfValidPaymentModes) > 2) {
$paycode = $arrayOfValidPaymentModes[2]->code;
$payIcon = '';
if ($paycode == 'LIQ') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'coins';
}
} elseif ($paycode == 'CB') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'credit-card';
}
} elseif ($paycode == 'CHQ') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'money-check';
}
}
print '<button type="button" class="calcbutton2" onclick="Validate(\''.dol_escape_js($paycode).'\');">'.(!empty($payIcon) ? '<span class="fa fa-2x fa-'.$payIcon.' iconwithlabel"></span><br>'. $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[2]->code) : $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[2]->code)).'</button>';
} else {
$button = array_pop($action_buttons);
print '<button type="button" class="calcbutton2" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
}
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '0' : '0.01').');">'.($numpad == 0 ? '0' : '0.01').'</button>';
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '\'000\'' : '0.02').');">'.($numpad == 0 ? '000' : '0.02').'</button>';
print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '\'.\'' : '0.05').');">'.($numpad == 0 ? '.' : '0.05').'</button>';
$i = 3;
while ($i < count($arrayOfValidPaymentModes)) {
$paycode = $arrayOfValidPaymentModes[$i]->code;
$payIcon = '';
if ($paycode == 'LIQ') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'coins';
}
} elseif ($paycode == 'CB') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'credit-card';
}
} elseif ($paycode == 'CHQ') {
if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
$payIcon = 'money-check';
}
}
print '<button type="button" class="calcbutton2" onclick="Validate(\''.dol_escape_js($paycode).'\');">'.(!empty($payIcon) ? '<span class="fa fa-2x fa-'.$payIcon.' iconwithlabel"></span><br>'. $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[$i]->code) : $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[$i]->code)).'</button>';
$i = $i + 1;
}
$keyforsumupbank = "CASHDESK_ID_BANKACCOUNT_SUMUP".$_SESSION["takeposterminal"];
if ($conf->global->TAKEPOS_ENABLE_SUMUP) {
if (!empty($conf->global->$keyforsumupbank)) {
print '<button type="button" class="calcbutton2" onclick="ValidateSumup();">Sumup</button>';
} else {
$langs->loadLangs(array("errors", "admin"));
print '<button type="button" class="calcbutton2 disabled" title="'.$langs->trans("SetupNotComplete").'">Sumup</button>';
}
}
$class = ($i == 3) ? "calcbutton3" : "calcbutton2";
foreach ($action_buttons as $button) {
$newclass = $class.($button["class"] ? " ".$button["class"] : "");
print '<button type="button" class="'.$newclass.'" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
}
if ($conf->global->TAKEPOS_DELAYED_PAYMENT) {
print '<button type="button" class="calcbutton2" onclick="Validate(\'delayed\');">'.$langs->trans("Reported").'</button>';
}
?>
<?php
// Add code from hooks
$parameters=array();
$hookmanager->executeHooks('completePayment', $parameters, $invoice);
print $hookmanager->resPrint;
?>
</div>
</body>
</html>