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