dolibarr 22.0.5
receipt.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
3 * Copyright (C) 2011-2023 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
5 * Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
6 * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
7 * Copyright (C) 2021 Nicolas ZABOURI <info@inovea-conseil.com>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 202 Ferran Marcet <fmarcet@2byte.es>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Include main (when fie in included into send.php, $action is set and main was already loaded)
33if (!isset($action)) {
34 //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
35 //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
36 //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
37 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
38 if (!defined('NOTOKENRENEWAL')) {
39 define('NOTOKENRENEWAL', '1');
40 }
41 if (!defined('NOREQUIREMENU')) {
42 define('NOREQUIREMENU', '1');
43 }
44 if (!defined('NOREQUIREHTML')) {
45 define('NOREQUIREHTML', '1');
46 }
47 if (!defined('NOREQUIREAJAX')) {
48 define('NOREQUIREAJAX', '1');
49 }
50
51 require '../main.inc.php'; // If this file is called from send.php avoid load again
52}
53include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
62$langs->loadLangs(array("main", "bills", "cashdesk", "companies"));
63
64$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant
65
66$facid = GETPOSTINT('facid');
67
68$action = GETPOST('action', 'aZ09');
69$gift = GETPOSTINT('gift');
70
71if (!$user->hasRight('takepos', 'run')) {
73}
74
75/*
76 * Actions
77 */
78
79// None
80
81
82/*
83 * View
84 */
85
86top_htmlhead('', '', 1);
87
88if (!$facid && (string) $place != '' && !empty($_SESSION["takeposterminal"])) {
89 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture";
90 $sql .= " WHERE ref = '(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
91 $sql .= " AND entity IN (".getEntity('invoice').")";
92
93 $resql = $db->query($sql);
94 $obj = $db->fetch_object($resql);
95 if ($obj) {
96 $facid = $obj->rowid;
97 }
98}
99$object = new Facture($db);
100$object->fetch($facid);
101
102
103// Record entry in blocked logs
104// DOL_DOCUMENT_ROOT.'/blockedlog/ajax/block-add.php?id='.$object->id.'&element='.$object->element.'&action=DOC_PREVIEW&token='.newToken();
105print "
106<script>
107jQuery(document).ready(function () {
108 console.log('Call /blockedlog/ajax/block-add on output of receipt.php');
109 $.post('".DOL_URL_ROOT."/blockedlog/ajax/block-add.php'
110 , {
111 id: ".((int) $object->id)."
112 , element: '".dol_escape_js($object->element)."'
113 , action: 'DOC_PREVIEW'
114 , token: '".currentToken()."'
115 }
116 );
117});
118</script>";
119
120
121// Call to external receipt modules if exist
122$parameters = array();
123$hookmanager->initHooks(array('takeposfrontend'));
124$reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
125if (!empty($hookmanager->resPrint)) {
126 print $hookmanager->resPrint;
127 return; // Receipt page can be called by the takepos/send.php page that use ob_start/end so we must use return and not exit to stop page
128}
129
130// IMPORTANT: This file is sended to 'Takepos Printing' application. Keep basic file. No external files as css, js... If you need images use absolute path.
131?>
132<body>
133<style>
134.right {
135 text-align: right;
136}
137.center {
138 text-align: center;
139}
140.left {
141 text-align: left;
142}
143.centpercent {
144 width: 100%;
145}
146@media only screen and (min-width: 1024px)
147{
148 body {
149 margin-left: 50px;
150 margin-right: 50px;
151 }
152}
153</style>
154<center>
155<div style="font-size: 1.5em">
156<?php echo '<b>'.$mysoc->name.'</b>'; ?>
157</div>
158</center>
159<br>
160<p class="left">
161<?php
162$constFreeText = 'TAKEPOS_HEADER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
163if (getDolGlobalString('TAKEPOS_HEADER') || getDolGlobalString($constFreeText)) {
164 $newfreetext = '';
165 $substitutionarray = getCommonSubstitutionArray($langs);
166 complete_substitutions_array($substitutionarray, $langs, $object);
167 if (getDolGlobalString('TAKEPOS_HEADER')) {
168 $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_HEADER'), $substitutionarray);
169 }
170 if (getDolGlobalString($constFreeText)) {
171 $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
172 }
173 print nl2br($newfreetext);
174}
175?>
176</p>
177<p class="right">
178<?php
179print $langs->trans('Date')." ".dol_print_date($object->date, 'day').'<br>';
180if (getDolGlobalString('TAKEPOS_RECEIPT_NAME')) {
181 print getDolGlobalString('TAKEPOS_RECEIPT_NAME') . " ";
182}
183if ($object->status == Facture::STATUS_DRAFT) {
184 print str_replace(")", "", str_replace("-", " ".$langs->trans('Place')." ", str_replace("(PROV-POS", $langs->trans("Terminal")." ", $object->ref)));
185} else {
186 print $object->ref;
187}
188if (getDolGlobalString('TAKEPOS_SHOW_CUSTOMER')) {
189 if ($object->socid != getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"])) {
190 $soc = new Societe($db);
191 if ($object->socid > 0) {
192 $soc->fetch($object->socid);
193 } else {
194 $soc->fetch(getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]));
195 }
196 print "<br>".$langs->trans("Customer").': '.$soc->name;
197 }
198}
199if (getDolGlobalString('TAKEPOS_SHOW_DATE_OF_PRINING')) {
200 print "<br>".$langs->trans("DateOfPrinting").': '.dol_print_date(dol_now(), 'dayhour', 'tzuserrel').'<br>';
201}
202?>
203</p>
204<br>
205
206<table class="centpercent" style="border-top-style: double;">
207 <thead>
208 <tr>
209 <th class="center"><?php print $langs->trans("Label"); ?></th>
210 <th class="right"><?php print $langs->trans("Qty"); ?></th>
211 <th class="right"><?php if ($gift != 1) {
212 print $langs->trans("Price");
213 } ?></th>
214 <?php if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
215 <th class="right"><?php if ($gift != 1) {
216 print $langs->trans("TotalHT");
217 } ?></th>
218 <?php } ?>
219 <th class="right"><?php if ($gift != 1) {
220 print $langs->trans("TotalTTC");
221 } ?></th>
222 </tr>
223 </thead>
224 <tbody>
225 <?php
226 if ($action == 'without_details') {
227 $qty = GETPOSTINT('qty') > 0 ? GETPOSTINT('qty') : 1;
228 print '<tr>';
229 print '<td>' . GETPOST('label', 'alphanohtml') . '</td>';
230 print '<td class="right">' . $qty . '</td>';
231 print '<td class="right">' . price(price2num($object->total_ttc / $qty, 'MU'), 1) . '</td>';
232 if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) {
233 print '<td class="right">' . price($object->total_ht, 1) . '</td>';
234 }
235 print '<td class="right">' . price($object->total_ttc, 1) . '</td>';
236 print '</tr>';
237 } else {
238 foreach ($object->lines as $line) {
239 ?>
240 <tr>
241 <td>
242 <?php if (!empty($line->product_label)) {
243 echo $line->product_label;
244 } else {
245 echo $line->desc;
246 } ?>
247 </td>
248 <td class="right"><?php echo $line->qty; ?></td>
249 <td class="right"><?php if ($gift != 1) {
250 echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1);
251 } ?></td>
252 <?php
253 if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
254 <td class="right"><?php if ($gift != 1) {
255 echo price($line->total_ht, 1);
256 } ?></td>
257 <?php
258 } ?>
259 <td class="right"><?php if ($gift != 1) {
260 echo price($line->total_ttc, 1);
261 } ?></td>
262 </tr>
263 <?php
264 }
265 }
266 ?>
267 </tbody>
268</table>
269<br>
270<table class="right centpercent">
271<tr>
272 <th class="right"><?php if ($gift != 1) {
273 echo $langs->trans("TotalHT");
274 } ?></th>
275 <td class="right"><?php if ($gift != 1) {
276 echo price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency)."\n";
277 } ?></td>
278</tr>
279<?php if (getDolGlobalString('TAKEPOS_TICKET_VAT_GROUPPED')) {
280 $vat_groups = array();
281 foreach ($object->lines as $line) {
282 if (!array_key_exists($line->tva_tx, $vat_groups)) {
283 $vat_groups[$line->tva_tx] = 0;
284 }
285 $vat_groups[$line->tva_tx] += $line->total_tva;
286 }
287 // Loop on each VAT group
288 foreach ($vat_groups as $key => $val) {
289 ?>
290 <tr>
291 <th align="right"><?php if ($gift != 1) {
292 echo $langs->trans("VAT").' '.vatrate($key, true);
293 } ?></th>
294 <td align="right"><?php if ($gift != 1) {
295 echo price($val, 1, '', 1, - 1, - 1, $conf->currency)."\n";
296 } ?></td>
297 </tr>
298 <?php
299 }
300} else { ?>
301<tr>
302 <th class="right"><?php if ($gift != 1) {
303 echo $langs->trans("TotalVAT").'</th><td class="right">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency)."\n";
304 } ?></th>
305</tr>
306<?php }
307
308// Now show local taxes if company uses them
309
310if (price2num($object->total_localtax1, 'MU') || $mysoc->useLocalTax(1)) { ?>
311<tr>
312 <th class="right"><?php if ($gift != 1) {
313 echo ''.$langs->trans("TotalLT1").'</th><td class="right">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency)."\n";
314 } ?></th>
315</tr>
316<?php } ?>
317<?php if (price2num($object->total_localtax2, 'MU') || $mysoc->useLocalTax(2)) { ?>
318<tr>
319 <th class="right"><?php if ($gift != 1) {
320 echo ''.$langs->trans("TotalLT2").'</th><td class="right">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency)."\n";
321 } ?></th>
322</tr>
323<?php } ?>
324<tr>
325 <th class="right"><?php if ($gift != 1) {
326 echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n";
327 } ?></th>
328</tr>
329<?php
330if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"]) && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
331 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
332 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
333 $multicurrency = new MultiCurrency($db);
334 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
335 echo '<tr><th class="right">';
336 if ($gift != 1) {
337 echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].'</th><td class="right">'.price($object->total_ttc * $multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n";
338 }
339 echo '</td></tr>';
340}
341
342if (getDolGlobalString('TAKEPOS_PRINT_PAYMENT_METHOD')) {
343 if (empty($facid)) {
344 // Case of specimen
345 echo '<tr>';
346 echo '<td class="right">';
347 echo $langs->transnoentitiesnoconv("PaymentTypeShortLIQ");
348 echo '</td>';
349 echo '<td class="right">';
350 $amount_payment = 0;
351 echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
352 echo '</td>';
353 echo '</tr>';
354 } else {
355 $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num,";
356 $sql .= " f.multicurrency_code,";
357 $sql .= " pf.amount as amount, pf.multicurrency_amount,";
358 $sql .= " cp.code";
359 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement as p";
360 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
361 $sql .= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $facid);
362 $sql .= " ORDER BY p.datep";
363
364 $resql = $db->query($sql);
365 if ($resql) {
366 $num = $db->num_rows($resql);
367
368 $i = 0;
369 while ($i < $num) {
370 $row = $db->fetch_object($resql);
371
372 echo '<tr>';
373 echo '<td class="right">';
374 echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
375 echo '</td>';
376 echo '<td class="right">';
377 $amount_payment = (isModEnabled('multicurrency') && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
378 //print "xx ".$row->multicurrency_amount." - ".$row->amount." - ".$amount_payment." - ".$object->multicurrency_tx;
379 if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
380 $amount_payment += $row->pos_change; // Show amount with excess received if it's cash payment
381 $currency = $conf->currency;
382 } else {
383 // We do not show change if payment into a different currency because not yet supported
384 $currency = $row->multicurrency_code;
385 }
386 echo price($amount_payment, 1, '', 1, - 1, - 1, $currency);
387 echo '</td>';
388 echo '</tr>';
389 if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
390 echo '<tr>';
391 echo '<td class="right">';
392 echo $langs->trans("Change"); // ChangeBack ?
393 echo '</td>';
394 echo '<td class="right">';
395 echo price($row->pos_change, 1, '', 1, - 1, - 1, $currency);
396 echo '</td>';
397 echo '</tr>';
398 }
399 $i++;
400 }
401 }
402 }
403}
404?>
405</table>
406<div style="border-top-style: double;">
407<br>
408<br>
409<br>
410<?php
411$constFreeText = 'TAKEPOS_FOOTER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
412if (getDolGlobalString('TAKEPOS_FOOTER') || getDolGlobalString($constFreeText)) {
413 $newfreetext = '';
414 $substitutionarray = getCommonSubstitutionArray($langs);
415 complete_substitutions_array($substitutionarray, $langs, $object);
416 if (getDolGlobalString($constFreeText)) {
417 $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
418 }
419 if (getDolGlobalString('TAKEPOS_FOOTER')) {
420 $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_FOOTER'), $substitutionarray);
421 }
422 print $newfreetext;
423}
424?>
425
426<script type="text/javascript">
427 <?php
428 if ($facid) {
429 print 'window.print();';
430 } //Avoid print when is specimen
431 ?>
432</script>
433
434</body>
435</html>
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
Class to manage invoices.
const STATUS_DRAFT
Draft status.
Class Currency.
Class to manage third parties objects (customers, suppliers, prospects...)
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
currentToken()
Return the value of token currently saved into session with name 'token'.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
treeview li table
No Email.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:158
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.