receipt.php 11 KB

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