dolibarr  16.0.5
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 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');
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'), $facid);
85 $reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
86 if (!empty($hookmanager->resPrint)) {
87  print $hookmanager->resPrint;
88  exit;
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 <html>
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']);
115 if (!empty($conf->global->TAKEPOS_HEADER) || !empty($conf->global->{$constFreeText})) {
116  $newfreetext = '';
117  $substitutionarray = getCommonSubstitutionArray($langs);
118  if (!empty($conf->global->TAKEPOS_HEADER)) {
119  $newfreetext .= make_substitutions($conf->global->TAKEPOS_HEADER, $substitutionarray);
120  }
121  if (!empty($conf->global->{$constFreeText})) {
122  $newfreetext .= make_substitutions($conf->global->{$constFreeText}, $substitutionarray);
123  }
124  print nl2br($newfreetext);
125 }
126 ?>
127 </p>
128 <p class="right">
129 <?php
130 print $langs->trans('Date')." ".dol_print_date($object->date, 'day').'<br>';
131 if (!empty($conf->global->TAKEPOS_RECEIPT_NAME)) {
132  print $conf->global->TAKEPOS_RECEIPT_NAME." ";
133 }
134 if ($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 }
139 if ($conf->global->TAKEPOS_SHOW_CUSTOMER) {
140  if ($object->socid != $conf->global->{'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($conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]});
146  }
147  print "<br>".$langs->trans("Customer").': '.$soc->name;
148  }
149 }
150 ?>
151 </p>
152 <br>
153 
154 <table width="100%" style="border-top-style: double;">
155  <thead>
156  <tr>
157  <th class="center"><?php print $langs->trans("Label"); ?></th>
158  <th class="right"><?php print $langs->trans("Qty"); ?></th>
159  <th class="right"><?php if ($gift != 1) {
160  print $langs->trans("Price");
161  } ?></th>
162  <?php if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) { ?>
163  <th class="right"><?php if ($gift != 1) {
164  print $langs->trans("TotalHT");
165  } ?></th>
166  <?php } ?>
167  <th class="right"><?php if ($gift != 1) {
168  print $langs->trans("TotalTTC");
169  } ?></th>
170  </tr>
171  </thead>
172  <tbody>
173  <?php
174  if ($action == 'without_details') {
175  $qty = GETPOST('qty', 'int') > 0 ? GETPOST('qty', 'int') : 1;
176  print '<tr>';
177  print '<td>' . GETPOST('label', 'alphanohtml') . '</td>';
178  print '<td class="right">' . $qty . '</td>';
179  print '<td class="right">' . price(price2num($object->total_ttc / $qty, 'MU'), 1) . '</td>';
180  if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) {
181  print '<td class="right">' . price($object->total_ht, 1) . '</td>';
182  }
183  print '<td class="right">' . price($object->total_ttc, 1) . '</td>';
184  print '</tr>';
185  } else {
186  foreach ($object->lines as $line) {
187  ?>
188  <tr>
189  <td>
190  <?php if (!empty($line->product_label)) {
191  echo $line->product_label;
192  } else {
193  echo $line->description;
194  } ?>
195  </td>
196  <td class="right"><?php echo $line->qty; ?></td>
197  <td class="right"><?php if ($gift != 1) {
198  echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1);
199  } ?></td>
200  <?php
201  if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) { ?>
202  <td class="right"><?php if ($gift != 1) {
203  echo price($line->total_ht, 1);
204  } ?></td>
205  <?php
206  }
207  ?>
208  <td class="right"><?php if ($gift != 1) {
209  echo price($line->total_ttc, 1);
210  } ?></td>
211  </tr>
212  <?php
213  }
214  }
215  ?>
216  </tbody>
217 </table>
218 <br>
219 <table class="right">
220 <tr>
221  <th class="right"><?php if ($gift != 1) {
222  echo $langs->trans("TotalHT");
223  } ?></th>
224  <td class="right"><?php if ($gift != 1) {
225  echo price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency)."\n";
226  } ?></td>
227 </tr>
228 <?php if ($conf->global->TAKEPOS_TICKET_VAT_GROUPPED) {
229  $vat_groups = array();
230  foreach ($object->lines as $line) {
231  if (!array_key_exists($line->tva_tx, $vat_groups)) {
232  $vat_groups[$line->tva_tx] = 0;
233  }
234  $vat_groups[$line->tva_tx] += $line->total_tva;
235  }
236  foreach ($vat_groups as $key => $val) {
237  ?>
238  <tr>
239  <th align="right"><?php if ($gift != 1) {
240  echo $langs->trans("VAT").' '.vatrate($key, 1);
241  } ?></th>
242  <td align="right"><?php if ($gift != 1) {
243  echo price($val, 1, '', 1, - 1, - 1, $conf->currency)."\n";
244  } ?></td>
245  </tr>
246  <?php
247  }
248 } else { ?>
249 <tr>
250  <th class="right"><?php if ($gift != 1) {
251  echo $langs->trans("TotalVAT").'</th><td class="right">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency)."\n";
252  } ?></td>
253 </tr>
254 <?php } ?>
255 <tr>
256  <th class="right"><?php if ($gift != 1) {
257  echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n";
258  } ?></td>
259 </tr>
260 <?php
261 if (isModEnabled('multicurrency') && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
262  //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
263  include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
264  $multicurrency = new MultiCurrency($db);
265  $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
266  echo '<tr><th class="right">';
267  if ($gift != 1) {
268  echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].'</th><td class="right">'.price($object->total_ttc * $multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n";
269  }
270  echo '</td></tr>';
271 }
272 
273 if ($conf->global->TAKEPOS_PRINT_PAYMENT_METHOD) {
274  $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,";
275  $sql .= " cp.code";
276  $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
277  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
278  $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $facid);
279  $sql .= " ORDER BY p.datep";
280  $resql = $db->query($sql);
281  if ($resql) {
282  $num = $db->num_rows($resql);
283  $i = 0;
284  while ($i < $num) {
285  $row = $db->fetch_object($resql);
286  echo '<tr>';
287  echo '<td class="right">';
288  echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
289  echo '</td>';
290  echo '<td class="right">';
291  $amount_payment = (isModEnabled('multicurrency') && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
292  if ($row->code == "LIQ") {
293  $amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if is cash payment
294  }
295  echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
296  echo '</td>';
297  echo '</tr>';
298  if ($row->code == "LIQ" && $row->pos_change > 0) { // Print change only in cash payments
299  echo '<tr>';
300  echo '<td class="right">';
301  echo $langs->trans("Change");
302  echo '</td>';
303  echo '<td class="right">';
304  echo price($row->pos_change, 1, '', 1, - 1, - 1, $conf->currency);
305  echo '</td>';
306  echo '</tr>';
307  }
308  $i++;
309  }
310  }
311 }
312 ?>
313 </table>
314 <div style="border-top-style: double;">
315 <br>
316 <br>
317 <br>
318 <?php
319 $constFreeText = 'TAKEPOS_FOOTER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
320 if (!empty($conf->global->TAKEPOS_FOOTER) || !empty($conf->global->{$constFreeText})) {
321  $newfreetext = '';
322  $substitutionarray = getCommonSubstitutionArray($langs);
323  if (!empty($conf->global->{$constFreeText})) {
324  $newfreetext .= make_substitutions($conf->global->{$constFreeText}, $substitutionarray);
325  }
326  if (!empty($conf->global->TAKEPOS_FOOTER)) {
327  $newfreetext .= make_substitutions($conf->global->TAKEPOS_FOOTER, $substitutionarray);
328  }
329  print $newfreetext;
330 }
331 ?>
332 
333 <script type="text/javascript">
334  window.print();
335 </script>
336 
337 </body>
338 </html>
Facture\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: facture.class.php:412
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:7839
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
top_httphead
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1407
Facture
Class to manage invoices.
Definition: facture.class.php:60
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
MultiCurrency
Class Currency.
Definition: multicurrency.class.php:39
getCommonSubstitutionArray
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Definition: functions.lib.php:7275
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
price
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.
Definition: functions.lib.php:5541
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
vatrate
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.
Definition: functions.lib.php:5492
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25