dolibarr 20.0.2
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// Include main (when fie in included into send.php, $action is set and main was already loaded)
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 = GETPOSTINT('facid');
57
58$action = GETPOST('action', 'aZ09');
59$gift = GETPOSTINT('gift');
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<div style="font-size: 1.5em">
108<?php echo '<b>'.$mysoc->name.'</b>'; ?>
109</div>
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 (getDolGlobalString('TAKEPOS_RECEIPT_NAME')) {
132 print getDolGlobalString('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 (getDolGlobalString('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 (getDolGlobalString('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 (getDolGlobalString('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 = GETPOSTINT('qty') > 0 ? GETPOSTINT('qty') : 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 (getDolGlobalString('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 (getDolGlobalString('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 <td class="right"><?php if ($gift != 1) {
211 echo price($line->total_ttc, 1);
212 } ?></td>
213 </tr>
214 <?php
215 }
216 }
217 ?>
218 </tbody>
219</table>
220<br>
221<table class="right">
222<tr>
223 <th class="right"><?php if ($gift != 1) {
224 echo $langs->trans("TotalHT");
225 } ?></th>
226 <td class="right"><?php if ($gift != 1) {
227 echo price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency)."\n";
228 } ?></td>
229</tr>
230<?php if (getDolGlobalString('TAKEPOS_TICKET_VAT_GROUPPED')) {
231 $vat_groups = array();
232 foreach ($object->lines as $line) {
233 if (!array_key_exists($line->tva_tx, $vat_groups)) {
234 $vat_groups[$line->tva_tx] = 0;
235 }
236 $vat_groups[$line->tva_tx] += $line->total_tva;
237 }
238 // Loop on each VAT group
239 foreach ($vat_groups as $key => $val) {
240 ?>
241 <tr>
242 <th align="right"><?php if ($gift != 1) {
243 echo $langs->trans("VAT").' '.vatrate($key, 1);
244 } ?></th>
245 <td align="right"><?php if ($gift != 1) {
246 echo price($val, 1, '', 1, - 1, - 1, $conf->currency)."\n";
247 } ?></td>
248 </tr>
249 <?php
250 }
251} else { ?>
252<tr>
253 <th class="right"><?php if ($gift != 1) {
254 echo $langs->trans("TotalVAT").'</th><td class="right">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency)."\n";
255 } ?></td>
256</tr>
257<?php }
258
259// Now show local taxes if company uses them
260
261if (price2num($object->total_localtax1, 'MU') || $mysoc->useLocalTax(1)) { ?>
262<tr>
263 <th class="right"><?php if ($gift != 1) {
264 echo ''.$langs->trans("TotalLT1").'</th><td class="right">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency)."\n";
265 } ?></td>
266</tr>
267<?php } ?>
268<?php if (price2num($object->total_localtax2, 'MU') || $mysoc->useLocalTax(2)) { ?>
269<tr>
270 <th class="right"><?php if ($gift != 1) {
271 echo ''.$langs->trans("TotalLT2").'</th><td class="right">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency)."\n";
272 } ?></td>
273</tr>
274<?php } ?>
275<tr>
276 <th class="right"><?php if ($gift != 1) {
277 echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n";
278 } ?></td>
279</tr>
280<?php
281if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"]) && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
282 //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
283 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
284 $multicurrency = new MultiCurrency($db);
285 $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
286 echo '<tr><th class="right">';
287 if ($gift != 1) {
288 echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].'</th><td class="right">'.price($object->total_ttc * $multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n";
289 }
290 echo '</td></tr>';
291}
292
293if (getDolGlobalString('TAKEPOS_PRINT_PAYMENT_METHOD')) {
294 if (empty($facid)) {
295 // Case of specimen
296 echo '<tr>';
297 echo '<td class="right">';
298 echo $langs->transnoentitiesnoconv("PaymentTypeShortLIQ");
299 echo '</td>';
300 echo '<td class="right">';
301 $amount_payment = 0;
302 echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
303 echo '</td>';
304 echo '</tr>';
305 } else {
306 $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num,";
307 $sql .= " f.multicurrency_code,";
308 $sql .= " pf.amount as amount, pf.multicurrency_amount,";
309 $sql .= " cp.code";
310 $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement as p";
311 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
312 $sql .= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $facid);
313 $sql .= " ORDER BY p.datep";
314
315 $resql = $db->query($sql);
316 if ($resql) {
317 $num = $db->num_rows($resql);
318
319 $i = 0;
320 while ($i < $num) {
321 $row = $db->fetch_object($resql);
322
323 echo '<tr>';
324 echo '<td class="right">';
325 echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
326 echo '</td>';
327 echo '<td class="right">';
328 $amount_payment = (isModEnabled('multicurrency') && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
329 //print "xx ".$row->multicurrency_amount." - ".$row->amount." - ".$amount_payment." - ".$object->multicurrency_tx;
330 if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
331 $amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if it's cash payment
332 $currency = $conf->currency;
333 } else {
334 // We do not show change if payment into a different currency because not yet supported
335 $currency = $row->multicurrency_code;
336 }
337 echo price($amount_payment, 1, '', 1, - 1, - 1, $currency);
338 echo '</td>';
339 echo '</tr>';
340 if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
341 echo '<tr>';
342 echo '<td class="right">';
343 echo $langs->trans("Change"); // ChangeBack ?
344 echo '</td>';
345 echo '<td class="right">';
346 echo price($row->pos_change, 1, '', 1, - 1, - 1, $currency);
347 echo '</td>';
348 echo '</tr>';
349 }
350 $i++;
351 }
352 }
353 }
354}
355?>
356</table>
357<div style="border-top-style: double;">
358<br>
359<br>
360<br>
361<?php
362$constFreeText = 'TAKEPOS_FOOTER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
363if (getDolGlobalString('TAKEPOS_FOOTER') || getDolGlobalString($constFreeText)) {
364 $newfreetext = '';
365 $substitutionarray = getCommonSubstitutionArray($langs);
366 if (getDolGlobalString($constFreeText)) {
367 $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
368 }
369 if (getDolGlobalString('TAKEPOS_FOOTER')) {
370 $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_FOOTER'), $substitutionarray);
371 }
372 print $newfreetext;
373}
374?>
375
376<script type="text/javascript">
377 <?php
378 if ($facid) {
379 print 'window.print();';
380 } //Avoid print when is specimen
381 ?>
382</script>
383
384</body>
385</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 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.