receipt.php 11 KB

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