dolibarr  13.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 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  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 if (!isset($action)) {
29  //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
30  //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
31  //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
32  //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
33  if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
34  if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
35  if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
36  if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
37 
38  require '../main.inc.php'; // If this file is called from send.php avoid load again
39 }
40 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
41 
42 $langs->loadLangs(array("main", "cashdesk", "companies"));
43 
44 $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
45 
46 $facid = GETPOST('facid', 'int');
47 
48 $gift = GETPOST('gift', 'int');
49 
50 if (empty($user->rights->takepos->run)) {
52 }
53 
54 
55 /*
56  * View
57  */
58 
59 top_httphead('text/html');
60 
61 if ($place > 0)
62 {
63  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
64  $resql = $db->query($sql);
65  $obj = $db->fetch_object($resql);
66  if ($obj)
67  {
68  $facid = $obj->rowid;
69  }
70 }
71 $object = new Facture($db);
72 $object->fetch($facid);
73 
74 // Call to external receipt modules if exist
75 $hookmanager->initHooks(array('takeposfrontend'), $facid);
76 $reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
77 if (!empty($hookmanager->resPrint)) {
78  print $hookmanager->resPrint;
79  exit;
80 }
81 
82 // 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.
83 ?>
84 <html>
85 <body>
86 <style>
87 .right {
88  text-align: right;
89 }
90 .center {
91  text-align: center;
92 }
93 .left {
94  text-align: left;
95 }
96 </style>
97 <center>
98 <font size="4">
99 <?php echo '<b>'.$mysoc->name.'</b>'; ?>
100 </font>
101 </center>
102 <br>
103 <p class="left">
104 <?php
105 $constFreeText = 'TAKEPOS_HEADER'.$_SESSION['takeposterminal'];
106 if (!empty($conf->global->TAKEPOS_HEADER) || !empty($conf->global->{$constFreeText}))
107 {
108  $newfreetext = '';
109  $substitutionarray = getCommonSubstitutionArray($langs);
110  if (!empty($conf->global->TAKEPOS_HEADER)) $newfreetext .= make_substitutions($conf->global->TAKEPOS_HEADER, $substitutionarray);
111  if (!empty($conf->global->{$constFreeText})) $newfreetext .= make_substitutions($conf->global->{$constFreeText}, $substitutionarray);
112  print $newfreetext;
113 }
114 ?>
115 </p>
116 <p class="right">
117 <?php
118 print $langs->trans('Date')." ".dol_print_date($object->date, 'day').'<br>';
119 if (!empty($conf->global->TAKEPOS_RECEIPT_NAME)) print $conf->global->TAKEPOS_RECEIPT_NAME." ";
120 if ($object->statut == Facture::STATUS_DRAFT) print str_replace(")", "", str_replace("-", " ".$langs->trans('Place')." ", str_replace("(PROV-POS", $langs->trans("Terminal")." ", $object->ref)));
121 else print $object->ref;
122 if ($conf->global->TAKEPOS_SHOW_CUSTOMER)
123 {
124  if ($object->socid != $conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]})
125  {
126  $soc = new Societe($db);
127  if ($object->socid > 0) $soc->fetch($object->socid);
128  else $soc->fetch($conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]});
129  print "<br>".$langs->trans("Customer").': '.$soc->name;
130  }
131 }
132 ?>
133 </p>
134 <br>
135 
136 <table width="100%" style="border-top-style: double;">
137  <thead>
138  <tr>
139  <th class="center"><?php print $langs->trans("Label"); ?></th>
140  <th class="right"><?php print $langs->trans("Qty"); ?></th>
141  <th class="right"><?php if ($gift != 1) print $langs->trans("Price"); ?></th>
142  <th class="right"><?php if ($gift != 1) print $langs->trans("TotalTTC"); ?></th>
143  </tr>
144  </thead>
145  <tbody>
146  <?php
147  foreach ($object->lines as $line)
148  {
149  ?>
150  <tr>
151  <td>
152  <?php if (!empty($line->product_label)) echo $line->product_label;
153  else echo $line->description; ?>
154  </td>
155  <td class="right"><?php echo $line->qty; ?></td>
156  <td class="right"><?php if ($gift != 1) echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1); ?></td>
157  <td class="right"><?php if ($gift != 1) echo price($line->total_ttc, 1); ?></td>
158  </tr>
159  <?php
160  }
161  ?>
162  </tbody>
163 </table>
164 <br>
165 <table class="right">
166 <tr>
167  <th class="right"><?php if ($gift != 1) echo $langs->trans("TotalHT"); ?></th>
168  <td class="right"><?php if ($gift != 1) echo price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency)."\n"; ?></td>
169 </tr>
170 <?php if ($conf->global->TAKEPOS_TICKET_VAT_GROUPPED) {
171  $vat_groups = array();
172  foreach ($object->lines as $line)
173  {
174  if (!array_key_exists($line->tva_tx, $vat_groups)) {
175  $vat_groups[$line->tva_tx] = 0;
176  }
177  $vat_groups[$line->tva_tx] += $line->total_tva;
178  }
179  foreach ($vat_groups as $key => $val) {
180  ?>
181  <tr>
182  <th align="right"><?php if ($gift != 1) echo $langs->trans("VAT").' '.vatrate($key, 1); ?></th>
183  <td align="right"><?php if ($gift != 1) echo price($val, 1, '', 1, - 1, - 1, $conf->currency)."\n"; ?></td>
184  </tr>
185  <?php
186  }
187 } else { ?>
188 <tr>
189  <th class="right"><?php if ($gift != 1) echo $langs->trans("TotalVAT").'</th><td class="right">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency)."\n"; ?></td>
190 </tr>
191 <?php } ?>
192 <tr>
193  <th class="right"><?php if ($gift != 1) echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n"; ?></td>
194 </tr>
195 <?php
196 if (!empty($conf->multicurrency->enabled) && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
197  //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
198  include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
199  $multicurrency = new MultiCurrency($db);
200  $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
201  echo '<tr><th class="right">';
202  if ($gift != 1) echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].'</th><td class="right">'.price($object->total_ttc * $multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n";
203  echo '</td></tr>';
204 }
205 
206 if ($conf->global->TAKEPOS_PRINT_PAYMENT_METHOD) {
207  $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,";
208  $sql .= " cp.code";
209  $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
210  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
211  $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$facid;
212  $sql .= " ORDER BY p.datep";
213  $resql = $db->query($sql);
214  if ($resql)
215  {
216  $num = $db->num_rows($resql);
217  $i = 0;
218  while ($i < $num) {
219  $row = $db->fetch_object($resql);
220  echo '<tr>';
221  echo '<td class="right">';
222  echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
223  echo '</td>';
224  echo '<td class="right">';
225  $amount_payment = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
226  if ($row->code == "LIQ") $amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if is cash payment
227  echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
228  echo '</td>';
229  echo '</tr>';
230  if ($row->code == "LIQ" && $row->pos_change > 0) // Print change only in cash payments
231  {
232  echo '<tr>';
233  echo '<td class="right">';
234  echo $langs->trans("Change");
235  echo '</td>';
236  echo '<td class="right">';
237  echo price($row->pos_change, 1, '', 1, - 1, - 1, $conf->currency);
238  echo '</td>';
239  echo '</tr>';
240  }
241  $i++;
242  }
243  }
244 }
245 ?>
246 </table>
247 <div style="border-top-style: double;">
248 <br>
249 <br>
250 <br>
251 <?php
252 $constFreeText = 'TAKEPOS_FOOTER'.$_SESSION['takeposterminal'];
253 if (!empty($conf->global->TAKEPOS_FOOTER) || !empty($conf->global->{$constFreeText}))
254 {
255  $newfreetext = '';
256  $substitutionarray = getCommonSubstitutionArray($langs);
257  if (!empty($conf->global->{$constFreeText})) $newfreetext .= make_substitutions($conf->global->{$constFreeText}, $substitutionarray);
258  if (!empty($conf->global->TAKEPOS_FOOTER)) $newfreetext .= make_substitutions($conf->global->TAKEPOS_FOOTER, $substitutionarray);
259  print $newfreetext;
260 }
261 ?>
262 
263 <script type="text/javascript">
264  window.print();
265 </script>
266 </body>
267 </html>
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype= 'text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1214
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...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Class to manage third parties objects (customers, suppliers, prospects...)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
const STATUS_DRAFT
Draft status.
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 ...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
Class Currency.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=&gt;newva...
Class to manage invoices.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105