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$result = $object->fetch($facid);
101// Only an invoice of the POS, in an entity of the user, can be printed from the POS
102if ($result <= 0 || $object->module_source != 'takepos' || !in_array($object->entity, explode(',', getEntity('invoice')))) {
104}
105
106
107// Record entry in blocked logs
108// DOL_DOCUMENT_ROOT.'/blockedlog/ajax/block-add.php?id='.$object->id.'&element='.$object->element.'&action=DOC_PREVIEW&token='.newToken();
109print "
110<script>
111jQuery(document).ready(function () {
112 console.log('Call /blockedlog/ajax/block-add on output of receipt.php');
113 $.post('".DOL_URL_ROOT."/blockedlog/ajax/block-add.php'
114 , {
115 id: ".((int) $object->id)."
116 , element: '".dol_escape_js($object->element)."'
117 , action: 'DOC_PREVIEW'
118 , token: '".currentToken()."'
119 }
120 );
121});
122</script>";
123
124
125// Call to external receipt modules if exist
126$parameters = array();
127$hookmanager->initHooks(array('takeposfrontend'));
128$reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
129if (!empty($hookmanager->resPrint)) {
130 print $hookmanager->resPrint;
131 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
132}
133
134// 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.
135?>
136<body>
137<style>
138.right {
139 text-align: right;
140}
141.center {
142 text-align: center;
143}
144.left {
145 text-align: left;
146}
147.centpercent {
148 width: 100%;
149}
150@media only screen and (min-width: 1024px)
151{
152 body {
153 margin-left: 50px;
154 margin-right: 50px;
155 }
156}
157</style>
158<center>
159<div style="font-size: 1.5em">
160<?php echo '<b>'.$mysoc->name.'</b>'; ?>
161</div>
162</center>
163<br>
164<p class="left">
165<?php
166$constFreeText = 'TAKEPOS_HEADER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
167if (getDolGlobalString('TAKEPOS_HEADER') || getDolGlobalString($constFreeText)) {
168 $newfreetext = '';
169 $substitutionarray = getCommonSubstitutionArray($langs);
170 complete_substitutions_array($substitutionarray, $langs, $object);
171 if (getDolGlobalString('TAKEPOS_HEADER')) {
172 $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_HEADER'), $substitutionarray);
173 }
174 if (getDolGlobalString($constFreeText)) {
175 $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
176 }
177 print nl2br($newfreetext);
178}
179?>
180</p>
181<p class="right">
182<?php
183print $langs->trans('Date')." ".dol_print_date($object->date, 'day').'<br>';
184if (getDolGlobalString('TAKEPOS_RECEIPT_NAME')) {
185 print getDolGlobalString('TAKEPOS_RECEIPT_NAME') . " ";
186}
187if ($object->status == Facture::STATUS_DRAFT) {
188 print str_replace(")", "", str_replace("-", " ".$langs->trans('Place')." ", str_replace("(PROV-POS", $langs->trans("Terminal")." ", $object->ref)));
189} else {
190 print $object->ref;
191}
192if (getDolGlobalString('TAKEPOS_SHOW_CUSTOMER')) {
193 if ($object->socid != getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"])) {
194 $soc = new Societe($db);
195 if ($object->socid > 0) {
196 $soc->fetch($object->socid);
197 } else {
198 $soc->fetch(getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]));
199 }
200 print "<br>".$langs->trans("Customer").': '.$soc->name;
201 }
202}
203if (getDolGlobalString('TAKEPOS_SHOW_DATE_OF_PRINING')) {
204 print "<br>".$langs->trans("DateOfPrinting").': '.dol_print_date(dol_now(), 'dayhour', 'tzuserrel').'<br>';
205}
206?>
207</p>
208<br>
209
210<table class="centpercent" style="border-top-style: double;">
211 <thead>
212 <tr>
213 <th class="center"><?php print $langs->trans("Label"); ?></th>
214 <th class="right"><?php print $langs->trans("Qty"); ?></th>
215 <th class="right"><?php if ($gift != 1) {
216 print $langs->trans("Price");
217 } ?></th>
218 <?php if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
219 <th class="right"><?php if ($gift != 1) {
220 print $langs->trans("TotalHT");
221 } ?></th>
222 <?php } ?>
223 <th class="right"><?php if ($gift != 1) {
224 print $langs->trans("TotalTTC");
225 } ?></th>
226 </tr>
227 </thead>
228 <tbody>
229 <?php
230 if ($action == 'without_details') {
231 $qty = GETPOSTINT('qty') > 0 ? GETPOSTINT('qty') : 1;
232 print '<tr>';
233 print '<td>' . GETPOST('label', 'alphanohtml') . '</td>';
234 print '<td class="right">' . $qty . '</td>';
235 print '<td class="right">' . price(price2num($object->total_ttc / $qty, 'MU'), 1) . '</td>';
236 if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) {
237 print '<td class="right">' . price($object->total_ht, 1) . '</td>';
238 }
239 print '<td class="right">' . price($object->total_ttc, 1) . '</td>';
240 print '</tr>';
241 } else {
242 foreach ($object->lines as $line) {
243 ?>
244 <tr>
245 <td>
246 <?php if (!empty($line->product_label)) {
247 echo $line->product_label;
248 } else {
249 echo $line->desc;
250 } ?>
251 </td>
252 <td class="right"><?php echo $line->qty; ?></td>
253 <td class="right"><?php if ($gift != 1) {
254 echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1);
255 } ?></td>
256 <?php
257 if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
258 <td class="right"><?php if ($gift != 1) {
259 echo price($line->total_ht, 1);
260 } ?></td>
261 <?php
262 } ?>
263 <td class="right"><?php if ($gift != 1) {
264 echo price($line->total_ttc, 1);
265 } ?></td>
266 </tr>
267 <?php
268 }
269 }
270 ?>
271 </tbody>
272</table>
273<br>
274<table class="right centpercent">
275<tr>
276 <th class="right"><?php if ($gift != 1) {
277 echo $langs->trans("TotalHT");
278 } ?></th>
279 <td class="right"><?php if ($gift != 1) {
280 echo price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency)."\n";
281 } ?></td>
282</tr>
283<?php if (getDolGlobalString('TAKEPOS_TICKET_VAT_GROUPPED')) {
284 $vat_groups = array();
285 foreach ($object->lines as $line) {
286 if (!array_key_exists($line->tva_tx, $vat_groups)) {
287 $vat_groups[$line->tva_tx] = 0;
288 }
289 $vat_groups[$line->tva_tx] += $line->total_tva;
290 }
291 // Loop on each VAT group
292 foreach ($vat_groups as $key => $val) {
293 ?>
294 <tr>
295 <th align="right"><?php if ($gift != 1) {
296 echo $langs->trans("VAT").' '.vatrate($key, true);
297 } ?></th>
298 <td align="right"><?php if ($gift != 1) {
299 echo price($val, 1, '', 1, - 1, - 1, $conf->currency)."\n";
300 } ?></td>
301 </tr>
302 <?php
303 }
304} else { ?>
305<tr>
306 <th class="right"><?php if ($gift != 1) {
307 echo $langs->trans("TotalVAT").'</th><td class="right">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency)."\n";
308 } ?></th>
309</tr>
310<?php }
311
312// Now show local taxes if company uses them
313
314// $mysoc->useLocalTax(N) is a country-wide flag (true as soon as the country has a
315// matching c_tva row with a localtaxN_type), so on its own it always prints the line
316// for Spanish companies even when the company is "No sujeto a RE / IRPF". Mirror the
317// pattern used by compta/facture/card.php, card-rec.php and prelevement.php and gate
318// the country check on $mysoc->localtaxN_assuj == "1".
319if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || price2num($object->total_localtax1, 'MU')) { ?>
320<tr>
321 <th class="right"><?php if ($gift != 1) {
322 echo ''.$langs->trans("TotalLT1").'</th><td class="right">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency)."\n";
323 } ?></th>
324</tr>
325<?php } ?>
326<?php if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || price2num($object->total_localtax2, 'MU')) { ?>
327<tr>
328 <th class="right"><?php if ($gift != 1) {
329 echo ''.$langs->trans("TotalLT2").'</th><td class="right">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency)."\n";
330 } ?></th>
331</tr>
332<?php } ?>
333<tr>
334 <th class="right"><?php if ($gift != 1) {
335 echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n";
336 } ?></th>
337</tr>
338<?php
339if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"]) && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
340 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
341 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
342 $multicurrency = new MultiCurrency($db);
343 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
344 echo '<tr><th class="right">';
345 if ($gift != 1) {
346 echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].'</th><td class="right">'.price($object->total_ttc * $multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n";
347 }
348 echo '</td></tr>';
349}
350
351if (getDolGlobalString('TAKEPOS_PRINT_PAYMENT_METHOD')) {
352 if (empty($facid)) {
353 // Case of specimen
354 echo '<tr>';
355 echo '<td class="right">';
356 echo $langs->transnoentitiesnoconv("PaymentTypeShortLIQ");
357 echo '</td>';
358 echo '<td class="right">';
359 $amount_payment = 0;
360 echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
361 echo '</td>';
362 echo '</tr>';
363 } else {
364 $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num,";
365 $sql .= " f.multicurrency_code,";
366 $sql .= " pf.amount as amount, pf.multicurrency_amount,";
367 $sql .= " cp.code";
368 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement as p";
369 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
370 $sql .= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $facid);
371 $sql .= " ORDER BY p.datep";
372
373 $resql = $db->query($sql);
374 if ($resql) {
375 $num = $db->num_rows($resql);
376
377 $i = 0;
378 while ($i < $num) {
379 $row = $db->fetch_object($resql);
380
381 echo '<tr>';
382 echo '<td class="right">';
383 echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
384 echo '</td>';
385 echo '<td class="right">';
386 $amount_payment = (isModEnabled('multicurrency') && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
387 //print "xx ".$row->multicurrency_amount." - ".$row->amount." - ".$amount_payment." - ".$object->multicurrency_tx;
388 if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
389 $amount_payment += $row->pos_change; // Show amount with excess received if it's cash payment
390 $currency = $conf->currency;
391 } else {
392 // We do not show change if payment into a different currency because not yet supported
393 $currency = $row->multicurrency_code;
394 }
395 echo price($amount_payment, 1, '', 1, - 1, - 1, $currency);
396 echo '</td>';
397 echo '</tr>';
398 if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
399 echo '<tr>';
400 echo '<td class="right">';
401 echo $langs->trans("Change"); // ChangeBack ?
402 echo '</td>';
403 echo '<td class="right">';
404 echo price($row->pos_change, 1, '', 1, - 1, - 1, $currency);
405 echo '</td>';
406 echo '</tr>';
407 }
408 $i++;
409 }
410 }
411 }
412}
413?>
414</table>
415<div style="border-top-style: double;">
416<br>
417<br>
418<br>
419<?php
420$constFreeText = 'TAKEPOS_FOOTER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
421if (getDolGlobalString('TAKEPOS_FOOTER') || getDolGlobalString($constFreeText)) {
422 $newfreetext = '';
423 $substitutionarray = getCommonSubstitutionArray($langs);
424 complete_substitutions_array($substitutionarray, $langs, $object);
425 if (getDolGlobalString($constFreeText)) {
426 $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
427 }
428 if (getDolGlobalString('TAKEPOS_FOOTER')) {
429 $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_FOOTER'), $substitutionarray);
430 }
431 print $newfreetext;
432}
433?>
434
435<script type="text/javascript">
436 <?php
437 if ($facid) {
438 print 'window.print();';
439 } //Avoid print when is specimen
440 ?>
441</script>
442
443</body>
444</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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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.