receipt.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. /**
  23. * \file htdocs/takepos/receipt.php
  24. * \ingroup takepos
  25. * \brief Page to show a receipt.
  26. */
  27. if (!isset($action)) {
  28. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
  29. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
  30. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
  31. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
  32. if (!defined('NOTOKENRENEWAL')) {
  33. define('NOTOKENRENEWAL', '1');
  34. }
  35. if (!defined('NOREQUIREMENU')) {
  36. define('NOREQUIREMENU', '1');
  37. }
  38. if (!defined('NOREQUIREHTML')) {
  39. define('NOREQUIREHTML', '1');
  40. }
  41. if (!defined('NOREQUIREAJAX')) {
  42. define('NOREQUIREAJAX', '1');
  43. }
  44. require '../main.inc.php'; // If this file is called from send.php avoid load again
  45. }
  46. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  47. $langs->loadLangs(array("main", "cashdesk", "companies"));
  48. $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant
  49. $facid = GETPOST('facid', 'int');
  50. $gift = GETPOST('gift', 'int');
  51. if (empty($user->rights->takepos->run)) {
  52. accessforbidden();
  53. }
  54. /*
  55. * View
  56. */
  57. top_httphead('text/html');
  58. if ($place > 0) {
  59. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
  60. $resql = $db->query($sql);
  61. $obj = $db->fetch_object($resql);
  62. if ($obj) {
  63. $facid = $obj->rowid;
  64. }
  65. }
  66. $object = new Facture($db);
  67. $object->fetch($facid);
  68. // Call to external receipt modules if exist
  69. $hookmanager->initHooks(array('takeposfrontend'), $facid);
  70. $reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
  71. if (!empty($hookmanager->resPrint)) {
  72. print $hookmanager->resPrint;
  73. exit;
  74. }
  75. // 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.
  76. ?>
  77. <html>
  78. <body>
  79. <style>
  80. .right {
  81. text-align: right;
  82. }
  83. .center {
  84. text-align: center;
  85. }
  86. .left {
  87. text-align: left;
  88. }
  89. </style>
  90. <center>
  91. <font size="4">
  92. <?php echo '<b>'.$mysoc->name.'</b>'; ?>
  93. </font>
  94. </center>
  95. <br>
  96. <p class="left">
  97. <?php
  98. $constFreeText = 'TAKEPOS_HEADER'.$_SESSION['takeposterminal'];
  99. if (!empty($conf->global->TAKEPOS_HEADER) || !empty($conf->global->{$constFreeText})) {
  100. $newfreetext = '';
  101. $substitutionarray = getCommonSubstitutionArray($langs);
  102. if (!empty($conf->global->TAKEPOS_HEADER)) {
  103. $newfreetext .= make_substitutions($conf->global->TAKEPOS_HEADER, $substitutionarray);
  104. }
  105. if (!empty($conf->global->{$constFreeText})) {
  106. $newfreetext .= make_substitutions($conf->global->{$constFreeText}, $substitutionarray);
  107. }
  108. print nl2br($newfreetext);
  109. }
  110. ?>
  111. </p>
  112. <p class="right">
  113. <?php
  114. print $langs->trans('Date')." ".dol_print_date($object->date, 'day').'<br>';
  115. if (!empty($conf->global->TAKEPOS_RECEIPT_NAME)) {
  116. print $conf->global->TAKEPOS_RECEIPT_NAME." ";
  117. }
  118. if ($object->statut == Facture::STATUS_DRAFT) {
  119. print str_replace(")", "", str_replace("-", " ".$langs->trans('Place')." ", str_replace("(PROV-POS", $langs->trans("Terminal")." ", $object->ref)));
  120. } else {
  121. print $object->ref;
  122. }
  123. if ($conf->global->TAKEPOS_SHOW_CUSTOMER) {
  124. if ($object->socid != $conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]}) {
  125. $soc = new Societe($db);
  126. if ($object->socid > 0) {
  127. $soc->fetch($object->socid);
  128. } else {
  129. $soc->fetch($conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]});
  130. }
  131. print "<br>".$langs->trans("Customer").': '.$soc->name;
  132. }
  133. }
  134. ?>
  135. </p>
  136. <br>
  137. <table width="100%" style="border-top-style: double;">
  138. <thead>
  139. <tr>
  140. <th class="center"><?php print $langs->trans("Label"); ?></th>
  141. <th class="right"><?php print $langs->trans("Qty"); ?></th>
  142. <th class="right"><?php if ($gift != 1) {
  143. print $langs->trans("Price");
  144. } ?></th>
  145. <?php if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) { ?>
  146. <th class="right"><?php if ($gift != 1) {
  147. print $langs->trans("TotalHT");
  148. } ?></th>
  149. <?php } ?>
  150. <th class="right"><?php if ($gift != 1) {
  151. print $langs->trans("TotalTTC");
  152. } ?></th>
  153. </tr>
  154. </thead>
  155. <tbody>
  156. <?php
  157. foreach ($object->lines as $line) {
  158. ?>
  159. <tr>
  160. <td>
  161. <?php if (!empty($line->product_label)) {
  162. echo $line->product_label;
  163. } else {
  164. echo $line->description;
  165. } ?>
  166. </td>
  167. <td class="right"><?php echo $line->qty; ?></td>
  168. <td class="right"><?php if ($gift != 1) {
  169. echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1);
  170. } ?></td>
  171. <?php
  172. if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) { ?>
  173. <td class="right"><?php if ($gift != 1) {
  174. echo price($line->total_ht, 1);
  175. } ?></td>
  176. <?php
  177. }
  178. ?>
  179. <td class="right"><?php if ($gift != 1) {
  180. echo price($line->total_ttc, 1);
  181. } ?></td>
  182. </tr>
  183. <?php
  184. }
  185. ?>
  186. </tbody>
  187. </table>
  188. <br>
  189. <table class="right">
  190. <tr>
  191. <th class="right"><?php if ($gift != 1) {
  192. echo $langs->trans("TotalHT");
  193. } ?></th>
  194. <td class="right"><?php if ($gift != 1) {
  195. echo price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  196. } ?></td>
  197. </tr>
  198. <?php if ($conf->global->TAKEPOS_TICKET_VAT_GROUPPED) {
  199. $vat_groups = array();
  200. foreach ($object->lines as $line) {
  201. if (!array_key_exists($line->tva_tx, $vat_groups)) {
  202. $vat_groups[$line->tva_tx] = 0;
  203. }
  204. $vat_groups[$line->tva_tx] += $line->total_tva;
  205. }
  206. foreach ($vat_groups as $key => $val) {
  207. ?>
  208. <tr>
  209. <th align="right"><?php if ($gift != 1) {
  210. echo $langs->trans("VAT").' '.vatrate($key, 1);
  211. } ?></th>
  212. <td align="right"><?php if ($gift != 1) {
  213. echo price($val, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  214. } ?></td>
  215. </tr>
  216. <?php
  217. }
  218. } else { ?>
  219. <tr>
  220. <th class="right"><?php if ($gift != 1) {
  221. echo $langs->trans("TotalVAT").'</th><td class="right">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  222. } ?></td>
  223. </tr>
  224. <?php } ?>
  225. <tr>
  226. <th class="right"><?php if ($gift != 1) {
  227. echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  228. } ?></td>
  229. </tr>
  230. <?php
  231. if (!empty($conf->multicurrency->enabled) && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
  232. //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
  233. include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
  234. $multicurrency = new MultiCurrency($db);
  235. $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
  236. echo '<tr><th class="right">';
  237. if ($gift != 1) {
  238. echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].'</th><td class="right">'.price($object->total_ttc * $multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n";
  239. }
  240. echo '</td></tr>';
  241. }
  242. if ($conf->global->TAKEPOS_PRINT_PAYMENT_METHOD) {
  243. $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,";
  244. $sql .= " cp.code";
  245. $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
  246. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
  247. $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $facid);
  248. $sql .= " ORDER BY p.datep";
  249. $resql = $db->query($sql);
  250. if ($resql) {
  251. $num = $db->num_rows($resql);
  252. $i = 0;
  253. while ($i < $num) {
  254. $row = $db->fetch_object($resql);
  255. echo '<tr>';
  256. echo '<td class="right">';
  257. echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
  258. echo '</td>';
  259. echo '<td class="right">';
  260. $amount_payment = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
  261. if ($row->code == "LIQ") {
  262. $amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if is cash payment
  263. }
  264. echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
  265. echo '</td>';
  266. echo '</tr>';
  267. if ($row->code == "LIQ" && $row->pos_change > 0) { // Print change only in cash payments
  268. echo '<tr>';
  269. echo '<td class="right">';
  270. echo $langs->trans("Change");
  271. echo '</td>';
  272. echo '<td class="right">';
  273. echo price($row->pos_change, 1, '', 1, - 1, - 1, $conf->currency);
  274. echo '</td>';
  275. echo '</tr>';
  276. }
  277. $i++;
  278. }
  279. }
  280. }
  281. ?>
  282. </table>
  283. <div style="border-top-style: double;">
  284. <br>
  285. <br>
  286. <br>
  287. <?php
  288. $constFreeText = 'TAKEPOS_FOOTER'.$_SESSION['takeposterminal'];
  289. if (!empty($conf->global->TAKEPOS_FOOTER) || !empty($conf->global->{$constFreeText})) {
  290. $newfreetext = '';
  291. $substitutionarray = getCommonSubstitutionArray($langs);
  292. if (!empty($conf->global->{$constFreeText})) {
  293. $newfreetext .= make_substitutions($conf->global->{$constFreeText}, $substitutionarray);
  294. }
  295. if (!empty($conf->global->TAKEPOS_FOOTER)) {
  296. $newfreetext .= make_substitutions($conf->global->TAKEPOS_FOOTER, $substitutionarray);
  297. }
  298. print $newfreetext;
  299. }
  300. ?>
  301. <script type="text/javascript">
  302. window.print();
  303. </script>
  304. </body>
  305. </html>