dolibarr 21.0.0-beta
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 Frédéric France <frederic.france@free.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Include main (when fie in included into send.php, $action is set and main was already loaded)
32if (!isset($action)) {
33 //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
34 //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
35 //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
36 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
37 if (!defined('NOTOKENRENEWAL')) {
38 define('NOTOKENRENEWAL', '1');
39 }
40 if (!defined('NOREQUIREMENU')) {
41 define('NOREQUIREMENU', '1');
42 }
43 if (!defined('NOREQUIREHTML')) {
44 define('NOREQUIREHTML', '1');
45 }
46 if (!defined('NOREQUIREAJAX')) {
47 define('NOREQUIREAJAX', '1');
48 }
49
50 require '../main.inc.php'; // If this file is called from send.php avoid load again
51}
52include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
61$langs->loadLangs(array("main", "bills", "cashdesk", "companies"));
62
63$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant
64
65$facid = GETPOSTINT('facid');
66
67$action = GETPOST('action', 'aZ09');
68$gift = GETPOSTINT('gift');
69
70if (!$user->hasRight('takepos', 'run')) {
72}
73
74
75/*
76 * View
77 */
78
79top_htmlhead('', '', 1);
80
81if ((string) $place != '') {
82 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture";
83 $sql .= " WHERE ref = '(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
84 $sql .= " AND entity IN (".getEntity('invoice').")";
85
86 $resql = $db->query($sql);
87 $obj = $db->fetch_object($resql);
88 if ($obj) {
89 $facid = $obj->rowid;
90 }
91}
92$object = new Facture($db);
93$object->fetch($facid);
94
95
96// Record entry in blocked logs
97// DOL_DOCUMENT_ROOT.'/blockedlog/ajax/block-add.php?id='.$object->id.'&element='.$object->element.'&action=DOC_PREVIEW&token='.newToken();
98print "
99<script>
100jQuery(document).ready(function () {
101 console.log('Call /blockedlog/ajax/block-add on output of receipt.php');
102 $.post('".DOL_URL_ROOT."/blockedlog/ajax/block-add.php'
103 , {
104 id: ".((int) $object->id)."
105 , element: '".dol_escape_js($object->element)."'
106 , action: 'DOC_PREVIEW'
107 , token: '".currentToken()."'
108 }
109 );
110});
111</script>";
112
113
114// Call to external receipt modules if exist
115$parameters = array();
116$hookmanager->initHooks(array('takeposfrontend'));
117$reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
118if (!empty($hookmanager->resPrint)) {
119 print $hookmanager->resPrint;
120 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
121}
122
123// 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.
124?>
125<body>
126<style>
127.right {
128 text-align: right;
129}
130.center {
131 text-align: center;
132}
133.left {
134 text-align: left;
135}
136.centpercent {
137 width: 100%;
138}
139@media only screen and (min-width: 1024px)
140{
141 body {
142 margin-left: 50px;
143 margin-right: 50px;
144 }
145}
146</style>
147<center>
148<div style="font-size: 1.5em">
149<?php echo '<b>'.$mysoc->name.'</b>'; ?>
150</div>
151</center>
152<br>
153<p class="left">
154<?php
155$constFreeText = 'TAKEPOS_HEADER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
156if (getDolGlobalString('TAKEPOS_HEADER') || getDolGlobalString($constFreeText)) {
157 $newfreetext = '';
158 $substitutionarray = getCommonSubstitutionArray($langs);
159 if (getDolGlobalString('TAKEPOS_HEADER')) {
160 $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_HEADER'), $substitutionarray);
161 }
162 if (getDolGlobalString($constFreeText)) {
163 $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
164 }
165 print nl2br($newfreetext);
166}
167?>
168</p>
169<p class="right">
170<?php
171print $langs->trans('Date')." ".dol_print_date($object->date, 'day').'<br>';
172if (getDolGlobalString('TAKEPOS_RECEIPT_NAME')) {
173 print getDolGlobalString('TAKEPOS_RECEIPT_NAME') . " ";
174}
175if ($object->status == Facture::STATUS_DRAFT) {
176 print str_replace(")", "", str_replace("-", " ".$langs->trans('Place')." ", str_replace("(PROV-POS", $langs->trans("Terminal")." ", $object->ref)));
177} else {
178 print $object->ref;
179}
180if (getDolGlobalString('TAKEPOS_SHOW_CUSTOMER')) {
181 if ($object->socid != getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"])) {
182 $soc = new Societe($db);
183 if ($object->socid > 0) {
184 $soc->fetch($object->socid);
185 } else {
186 $soc->fetch(getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]));
187 }
188 print "<br>".$langs->trans("Customer").': '.$soc->name;
189 }
190}
191if (getDolGlobalString('TAKEPOS_SHOW_DATE_OF_PRINING')) {
192 print "<br>".$langs->trans("DateOfPrinting").': '.dol_print_date(dol_now(), 'dayhour', 'tzuserrel').'<br>';
193}
194?>
195</p>
196<br>
197
198<table class="centpercent" style="border-top-style: double;">
199 <thead>
200 <tr>
201 <th class="center"><?php print $langs->trans("Label"); ?></th>
202 <th class="right"><?php print $langs->trans("Qty"); ?></th>
203 <th class="right"><?php if ($gift != 1) {
204 print $langs->trans("Price");
205 } ?></th>
206 <?php if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
207 <th class="right"><?php if ($gift != 1) {
208 print $langs->trans("TotalHT");
209 } ?></th>
210 <?php } ?>
211 <th class="right"><?php if ($gift != 1) {
212 print $langs->trans("TotalTTC");
213 } ?></th>
214 </tr>
215 </thead>
216 <tbody>
217 <?php
218 if ($action == 'without_details') {
219 $qty = GETPOSTINT('qty') > 0 ? GETPOSTINT('qty') : 1;
220 print '<tr>';
221 print '<td>' . GETPOST('label', 'alphanohtml') . '</td>';
222 print '<td class="right">' . $qty . '</td>';
223 print '<td class="right">' . price(price2num($object->total_ttc / $qty, 'MU'), 1) . '</td>';
224 if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) {
225 print '<td class="right">' . price($object->total_ht, 1) . '</td>';
226 }
227 print '<td class="right">' . price($object->total_ttc, 1) . '</td>';
228 print '</tr>';
229 } else {
230 foreach ($object->lines as $line) {
231 ?>
232 <tr>
233 <td>
234 <?php if (!empty($line->product_label)) {
235 echo $line->product_label;
236 } else {
237 echo $line->desc;
238 } ?>
239 </td>
240 <td class="right"><?php echo $line->qty; ?></td>
241 <td class="right"><?php if ($gift != 1) {
242 echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1);
243 } ?></td>
244 <?php
245 if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
246 <td class="right"><?php if ($gift != 1) {
247 echo price($line->total_ht, 1);
248 } ?></td>
249 <?php
250 } ?>
251 <td class="right"><?php if ($gift != 1) {
252 echo price($line->total_ttc, 1);
253 } ?></td>
254 </tr>
255 <?php
256 }
257 }
258 ?>
259 </tbody>
260</table>
261<br>
262<table class="right centpercent">
263<tr>
264 <th class="right"><?php if ($gift != 1) {
265 echo $langs->trans("TotalHT");
266 } ?></th>
267 <td class="right"><?php if ($gift != 1) {
268 echo price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency)."\n";
269 } ?></td>
270</tr>
271<?php if (getDolGlobalString('TAKEPOS_TICKET_VAT_GROUPPED')) {
272 $vat_groups = array();
273 foreach ($object->lines as $line) {
274 if (!array_key_exists($line->tva_tx, $vat_groups)) {
275 $vat_groups[$line->tva_tx] = 0;
276 }
277 $vat_groups[$line->tva_tx] += $line->total_tva;
278 }
279 // Loop on each VAT group
280 foreach ($vat_groups as $key => $val) {
281 ?>
282 <tr>
283 <th align="right"><?php if ($gift != 1) {
284 echo $langs->trans("VAT").' '.vatrate($key, 1);
285 } ?></th>
286 <td align="right"><?php if ($gift != 1) {
287 echo price($val, 1, '', 1, - 1, - 1, $conf->currency)."\n";
288 } ?></td>
289 </tr>
290 <?php
291 }
292} else { ?>
293<tr>
294 <th class="right"><?php if ($gift != 1) {
295 echo $langs->trans("TotalVAT").'</th><td class="right">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency)."\n";
296 } ?></th>
297</tr>
298<?php }
299
300// Now show local taxes if company uses them
301
302if (price2num($object->total_localtax1, 'MU') || $mysoc->useLocalTax(1)) { ?>
303<tr>
304 <th class="right"><?php if ($gift != 1) {
305 echo ''.$langs->trans("TotalLT1").'</th><td class="right">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency)."\n";
306 } ?></th>
307</tr>
308<?php } ?>
309<?php if (price2num($object->total_localtax2, 'MU') || $mysoc->useLocalTax(2)) { ?>
310<tr>
311 <th class="right"><?php if ($gift != 1) {
312 echo ''.$langs->trans("TotalLT2").'</th><td class="right">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency)."\n";
313 } ?></th>
314</tr>
315<?php } ?>
316<tr>
317 <th class="right"><?php if ($gift != 1) {
318 echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n";
319 } ?></th>
320</tr>
321<?php
322if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"]) && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
323 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
324 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
325 $multicurrency = new MultiCurrency($db);
326 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
327 echo '<tr><th class="right">';
328 if ($gift != 1) {
329 echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].'</th><td class="right">'.price($object->total_ttc * $multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n";
330 }
331 echo '</td></tr>';
332}
333
334if (getDolGlobalString('TAKEPOS_PRINT_PAYMENT_METHOD')) {
335 if (empty($facid)) {
336 // Case of specimen
337 echo '<tr>';
338 echo '<td class="right">';
339 echo $langs->transnoentitiesnoconv("PaymentTypeShortLIQ");
340 echo '</td>';
341 echo '<td class="right">';
342 $amount_payment = 0;
343 echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
344 echo '</td>';
345 echo '</tr>';
346 } else {
347 $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num,";
348 $sql .= " f.multicurrency_code,";
349 $sql .= " pf.amount as amount, pf.multicurrency_amount,";
350 $sql .= " cp.code";
351 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement as p";
352 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
353 $sql .= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $facid);
354 $sql .= " ORDER BY p.datep";
355
356 $resql = $db->query($sql);
357 if ($resql) {
358 $num = $db->num_rows($resql);
359
360 $i = 0;
361 while ($i < $num) {
362 $row = $db->fetch_object($resql);
363
364 echo '<tr>';
365 echo '<td class="right">';
366 echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
367 echo '</td>';
368 echo '<td class="right">';
369 $amount_payment = (isModEnabled('multicurrency') && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
370 //print "xx ".$row->multicurrency_amount." - ".$row->amount." - ".$amount_payment." - ".$object->multicurrency_tx;
371 if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
372 $amount_payment += $row->pos_change; // Show amount with excess received if it's cash payment
373 $currency = $conf->currency;
374 } else {
375 // We do not show change if payment into a different currency because not yet supported
376 $currency = $row->multicurrency_code;
377 }
378 echo price($amount_payment, 1, '', 1, - 1, - 1, $currency);
379 echo '</td>';
380 echo '</tr>';
381 if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
382 echo '<tr>';
383 echo '<td class="right">';
384 echo $langs->trans("Change"); // ChangeBack ?
385 echo '</td>';
386 echo '<td class="right">';
387 echo price($row->pos_change, 1, '', 1, - 1, - 1, $currency);
388 echo '</td>';
389 echo '</tr>';
390 }
391 $i++;
392 }
393 }
394 }
395}
396?>
397</table>
398<div style="border-top-style: double;">
399<br>
400<br>
401<br>
402<?php
403$constFreeText = 'TAKEPOS_FOOTER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
404if (getDolGlobalString('TAKEPOS_FOOTER') || getDolGlobalString($constFreeText)) {
405 $newfreetext = '';
406 $substitutionarray = getCommonSubstitutionArray($langs);
407 if (getDolGlobalString($constFreeText)) {
408 $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
409 }
410 if (getDolGlobalString('TAKEPOS_FOOTER')) {
411 $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_FOOTER'), $substitutionarray);
412 }
413 print $newfreetext;
414}
415?>
416
417<script type="text/javascript">
418 <?php
419 if ($facid) {
420 print 'window.print();';
421 } //Avoid print when is specimen
422 ?>
423</script>
424
425</body>
426</html>
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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).
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.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
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:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.