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_httphead('text/html', 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// Call to external receipt modules if exist
85$parameters = array();
86$hookmanager->initHooks(array('takeposfrontend'));
87$reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
88if (!empty($hookmanager->resPrint)) {
89 print $hookmanager->resPrint;
90 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
91}
92
93// 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.
94?>
95<body>
96<style>
97.right {
98 text-align: right;
99}
100.center {
101 text-align: center;
102}
103.left {
104 text-align: left;
105}
106</style>
107<center>
108<div style="font-size: 1.5em">
109<?php echo '<b>'.$mysoc->name.'</b>'; ?>
110</div>
111</center>
112<br>
113<p class="left">
114<?php
115$constFreeText = 'TAKEPOS_HEADER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
116if (getDolGlobalString('TAKEPOS_HEADER') || getDolGlobalString($constFreeText)) {
117 $newfreetext = '';
118 $substitutionarray = getCommonSubstitutionArray($langs);
119 if (getDolGlobalString('TAKEPOS_HEADER')) {
120 $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_HEADER'), $substitutionarray);
121 }
122 if (getDolGlobalString($constFreeText)) {
123 $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
124 }
125 print nl2br($newfreetext);
126}
127?>
128</p>
129<p class="right">
130<?php
131print $langs->trans('Date')." ".dol_print_date($object->date, 'day').'<br>';
132if (getDolGlobalString('TAKEPOS_RECEIPT_NAME')) {
133 print getDolGlobalString('TAKEPOS_RECEIPT_NAME') . " ";
134}
135if ($object->statut == Facture::STATUS_DRAFT) {
136 print str_replace(")", "", str_replace("-", " ".$langs->trans('Place')." ", str_replace("(PROV-POS", $langs->trans("Terminal")." ", $object->ref)));
137} else {
138 print $object->ref;
139}
140if (getDolGlobalString('TAKEPOS_SHOW_CUSTOMER')) {
141 if ($object->socid != getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"])) {
142 $soc = new Societe($db);
143 if ($object->socid > 0) {
144 $soc->fetch($object->socid);
145 } else {
146 $soc->fetch(getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]));
147 }
148 print "<br>".$langs->trans("Customer").': '.$soc->name;
149 }
150}
151if (getDolGlobalString('TAKEPOS_SHOW_DATE_OF_PRINING')) {
152 print "<br>".$langs->trans("DateOfPrinting").': '.dol_print_date(dol_now(), 'dayhour', 'tzuserrel').'<br>';
153}
154?>
155</p>
156<br>
157
158<table width="100%" style="border-top-style: double;">
159 <thead>
160 <tr>
161 <th class="center"><?php print $langs->trans("Label"); ?></th>
162 <th class="right"><?php print $langs->trans("Qty"); ?></th>
163 <th class="right"><?php if ($gift != 1) {
164 print $langs->trans("Price");
165 } ?></th>
166 <?php if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
167 <th class="right"><?php if ($gift != 1) {
168 print $langs->trans("TotalHT");
169 } ?></th>
170 <?php } ?>
171 <th class="right"><?php if ($gift != 1) {
172 print $langs->trans("TotalTTC");
173 } ?></th>
174 </tr>
175 </thead>
176 <tbody>
177 <?php
178 if ($action == 'without_details') {
179 $qty = GETPOSTINT('qty') > 0 ? GETPOSTINT('qty') : 1;
180 print '<tr>';
181 print '<td>' . GETPOST('label', 'alphanohtml') . '</td>';
182 print '<td class="right">' . $qty . '</td>';
183 print '<td class="right">' . price(price2num($object->total_ttc / $qty, 'MU'), 1) . '</td>';
184 if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) {
185 print '<td class="right">' . price($object->total_ht, 1) . '</td>';
186 }
187 print '<td class="right">' . price($object->total_ttc, 1) . '</td>';
188 print '</tr>';
189 } else {
190 foreach ($object->lines as $line) {
191 ?>
192 <tr>
193 <td>
194 <?php if (!empty($line->product_label)) {
195 echo $line->product_label;
196 } else {
197 echo $line->description;
198 } ?>
199 </td>
200 <td class="right"><?php echo $line->qty; ?></td>
201 <td class="right"><?php if ($gift != 1) {
202 echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1);
203 } ?></td>
204 <?php
205 if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
206 <td class="right"><?php if ($gift != 1) {
207 echo price($line->total_ht, 1);
208 } ?></td>
209 <?php
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 (getDolGlobalString('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,";
308 $sql .= " f.multicurrency_code,";
309 $sql .= " pf.amount as amount, pf.multicurrency_amount,";
310 $sql .= " cp.code";
311 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement as p";
312 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
313 $sql .= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $facid);
314 $sql .= " ORDER BY p.datep";
315
316 $resql = $db->query($sql);
317 if ($resql) {
318 $num = $db->num_rows($resql);
319
320 $i = 0;
321 while ($i < $num) {
322 $row = $db->fetch_object($resql);
323
324 echo '<tr>';
325 echo '<td class="right">';
326 echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
327 echo '</td>';
328 echo '<td class="right">';
329 $amount_payment = (isModEnabled('multicurrency') && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
330 //print "xx ".$row->multicurrency_amount." - ".$row->amount." - ".$amount_payment." - ".$object->multicurrency_tx;
331 if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
332 $amount_payment += $row->pos_change; // Show amount with excess received if it's cash payment
333 $currency = $conf->currency;
334 } else {
335 // We do not show change if payment into a different currency because not yet supported
336 $currency = $row->multicurrency_code;
337 }
338 echo price($amount_payment, 1, '', 1, - 1, - 1, $currency);
339 echo '</td>';
340 echo '</tr>';
341 if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
342 echo '<tr>';
343 echo '<td class="right">';
344 echo $langs->trans("Change"); // ChangeBack ?
345 echo '</td>';
346 echo '<td class="right">';
347 echo price($row->pos_change, 1, '', 1, - 1, - 1, $currency);
348 echo '</td>';
349 echo '</tr>';
350 }
351 $i++;
352 }
353 }
354 }
355}
356?>
357</table>
358<div style="border-top-style: double;">
359<br>
360<br>
361<br>
362<?php
363$constFreeText = 'TAKEPOS_FOOTER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
364if (getDolGlobalString('TAKEPOS_FOOTER') || getDolGlobalString($constFreeText)) {
365 $newfreetext = '';
366 $substitutionarray = getCommonSubstitutionArray($langs);
367 if (getDolGlobalString($constFreeText)) {
368 $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
369 }
370 if (getDolGlobalString('TAKEPOS_FOOTER')) {
371 $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_FOOTER'), $substitutionarray);
372 }
373 print $newfreetext;
374}
375?>
376
377<script type="text/javascript">
378 <?php
379 if ($facid) {
380 print 'window.print();';
381 } //Avoid print when is specimen
382 ?>
383</script>
384
385</body>
386</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 '.
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_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.
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:137
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.