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