dolibarr  17.0.4
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 if (!isset($action)) {
30  //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
31  //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
32  //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
33  //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
34  if (!defined('NOTOKENRENEWAL')) {
35  define('NOTOKENRENEWAL', '1');
36  }
37  if (!defined('NOREQUIREMENU')) {
38  define('NOREQUIREMENU', '1');
39  }
40  if (!defined('NOREQUIREHTML')) {
41  define('NOREQUIREHTML', '1');
42  }
43  if (!defined('NOREQUIREAJAX')) {
44  define('NOREQUIREAJAX', '1');
45  }
46 
47  require '../main.inc.php'; // If this file is called from send.php avoid load again
48 }
49 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
50 
51 $langs->loadLangs(array("main", "bills", "cashdesk", "companies"));
52 
53 $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant
54 
55 $facid = GETPOST('facid', 'int');
56 
57 $action = GETPOST('action', 'aZ09');
58 $gift = GETPOST('gift', 'int');
59 
60 if (empty($user->rights->takepos->run)) {
62 }
63 
64 
65 /*
66  * View
67  */
68 
69 top_httphead('text/html', 1);
70 
71 if ($place > 0) {
72  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
73  $resql = $db->query($sql);
74  $obj = $db->fetch_object($resql);
75  if ($obj) {
76  $facid = $obj->rowid;
77  }
78 }
79 $object = new Facture($db);
80 $object->fetch($facid);
81 
82 // Call to external receipt modules if exist
83 $parameters = array();
84 $hookmanager->initHooks(array('takeposfrontend'));
85 $reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
86 if (!empty($hookmanager->resPrint)) {
87  print $hookmanager->resPrint;
88  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
89 }
90 
91 // 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.
92 ?>
93 <body>
94 <style>
95 .right {
96  text-align: right;
97 }
98 .center {
99  text-align: center;
100 }
101 .left {
102  text-align: left;
103 }
104 </style>
105 <center>
106 <font size="4">
107 <?php echo '<b>'.$mysoc->name.'</b>'; ?>
108 </font>
109 </center>
110 <br>
111 <p class="left">
112 <?php
113 $constFreeText = 'TAKEPOS_HEADER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
114 if (getDolGlobalString('TAKEPOS_HEADER') || getDolGlobalString($constFreeText)) {
115  $newfreetext = '';
116  $substitutionarray = getCommonSubstitutionArray($langs);
117  if (getDolGlobalString('TAKEPOS_HEADER')) {
118  $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_HEADER'), $substitutionarray);
119  }
120  if (getDolGlobalString($constFreeText)) {
121  $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
122  }
123  print nl2br($newfreetext);
124 }
125 ?>
126 </p>
127 <p class="right">
128 <?php
129 print $langs->trans('Date')." ".dol_print_date($object->date, 'day').'<br>';
130 if (!empty($conf->global->TAKEPOS_RECEIPT_NAME)) {
131  print $conf->global->TAKEPOS_RECEIPT_NAME." ";
132 }
133 if ($object->statut == Facture::STATUS_DRAFT) {
134  print str_replace(")", "", str_replace("-", " ".$langs->trans('Place')." ", str_replace("(PROV-POS", $langs->trans("Terminal")." ", $object->ref)));
135 } else {
136  print $object->ref;
137 }
138 if (!empty($conf->global->TAKEPOS_SHOW_CUSTOMER)) {
139  if ($object->socid != getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"])) {
140  $soc = new Societe($db);
141  if ($object->socid > 0) {
142  $soc->fetch($object->socid);
143  } else {
144  $soc->fetch(getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]));
145  }
146  print "<br>".$langs->trans("Customer").': '.$soc->name;
147  }
148 }
149 if (!empty($conf->global->TAKEPOS_SHOW_DATE_OF_PRINING)) {
150  print "<br>".$langs->trans("DateOfPrinting").': '.dol_print_date(dol_now(), 'dayhour', 'tzuserrel').'<br>';
151 }
152 ?>
153 </p>
154 <br>
155 
156 <table width="100%" style="border-top-style: double;">
157  <thead>
158  <tr>
159  <th class="center"><?php print $langs->trans("Label"); ?></th>
160  <th class="right"><?php print $langs->trans("Qty"); ?></th>
161  <th class="right"><?php if ($gift != 1) {
162  print $langs->trans("Price");
163  } ?></th>
164  <?php if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) { ?>
165  <th class="right"><?php if ($gift != 1) {
166  print $langs->trans("TotalHT");
167  } ?></th>
168  <?php } ?>
169  <th class="right"><?php if ($gift != 1) {
170  print $langs->trans("TotalTTC");
171  } ?></th>
172  </tr>
173  </thead>
174  <tbody>
175  <?php
176  if ($action == 'without_details') {
177  $qty = GETPOST('qty', 'int') > 0 ? GETPOST('qty', 'int') : 1;
178  print '<tr>';
179  print '<td>' . GETPOST('label', 'alphanohtml') . '</td>';
180  print '<td class="right">' . $qty . '</td>';
181  print '<td class="right">' . price(price2num($object->total_ttc / $qty, 'MU'), 1) . '</td>';
182  if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) {
183  print '<td class="right">' . price($object->total_ht, 1) . '</td>';
184  }
185  print '<td class="right">' . price($object->total_ttc, 1) . '</td>';
186  print '</tr>';
187  } else {
188  foreach ($object->lines as $line) {
189  ?>
190  <tr>
191  <td>
192  <?php if (!empty($line->product_label)) {
193  echo $line->product_label;
194  } else {
195  echo $line->description;
196  } ?>
197  </td>
198  <td class="right"><?php echo $line->qty; ?></td>
199  <td class="right"><?php if ($gift != 1) {
200  echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1);
201  } ?></td>
202  <?php
203  if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) { ?>
204  <td class="right"><?php if ($gift != 1) {
205  echo price($line->total_ht, 1);
206  } ?></td>
207  <?php
208  }
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 ($conf->global->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 
261 if ($mysoc->useLocalTax(1) || price2num($object->total_localtax1, 'MU')) { ?>
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 ($mysoc->useLocalTax(2) || price2num($object->total_localtax2, 'MU')) { ?>
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
281 if (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 
293 if (getDolGlobalString('TAKEPOS_PRINT_PAYMENT_METHOD')) {
294  $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,";
295  $sql .= " cp.code";
296  $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
297  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
298  $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $facid);
299  $sql .= " ORDER BY p.datep";
300  $resql = $db->query($sql);
301  if ($resql) {
302  $num = $db->num_rows($resql);
303  $i = 0;
304  while ($i < $num) {
305  $row = $db->fetch_object($resql);
306  echo '<tr>';
307  echo '<td class="right">';
308  echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
309  echo '</td>';
310  echo '<td class="right">';
311  $amount_payment = (isModEnabled('multicurrency') && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
312  if ($row->code == "LIQ") {
313  $amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if is cash payment
314  }
315  echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
316  echo '</td>';
317  echo '</tr>';
318  if ($row->code == "LIQ" && $row->pos_change > 0) { // Print change only in cash payments
319  echo '<tr>';
320  echo '<td class="right">';
321  echo $langs->trans("Change");
322  echo '</td>';
323  echo '<td class="right">';
324  echo price($row->pos_change, 1, '', 1, - 1, - 1, $conf->currency);
325  echo '</td>';
326  echo '</tr>';
327  }
328  $i++;
329  }
330  }
331 }
332 ?>
333 </table>
334 <div style="border-top-style: double;">
335 <br>
336 <br>
337 <br>
338 <?php
339 $constFreeText = 'TAKEPOS_FOOTER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
340 if (getDolGlobalString('TAKEPOS_FOOTER') || getDolGlobalString($constFreeText)) {
341  $newfreetext = '';
342  $substitutionarray = getCommonSubstitutionArray($langs);
343  if (getDolGlobalString($constFreeText)) {
344  $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
345  }
346  if (getDolGlobalString('TAKEPOS_FOOTER')) {
347  $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_FOOTER'), $substitutionarray);
348  }
349  print $newfreetext;
350 }
351 ?>
352 
353 <script type="text/javascript">
354  <?php
355  if ($facid) print 'window.print();'; //Avoid print when is specimen
356  ?>
357 </script>
358 
359 </body>
360 </html>
Class to manage invoices.
const STATUS_DRAFT
Draft status.
Class Currency.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
isModEnabled($module)
Is Dolibarr module enabled.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1440
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.