receipt.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <?php
  2. /* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
  3. * Copyright (C) 2011-2023 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. // Include main (when fie in included into send.php, $action is set and main was already loaded)
  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')) {
  34. define('NOTOKENRENEWAL', '1');
  35. }
  36. if (!defined('NOREQUIREMENU')) {
  37. define('NOREQUIREMENU', '1');
  38. }
  39. if (!defined('NOREQUIREHTML')) {
  40. define('NOREQUIREHTML', '1');
  41. }
  42. if (!defined('NOREQUIREAJAX')) {
  43. define('NOREQUIREAJAX', '1');
  44. }
  45. require '../main.inc.php'; // If this file is called from send.php avoid load again
  46. }
  47. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  48. $langs->loadLangs(array("main", "bills", "cashdesk", "companies"));
  49. $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant
  50. $facid = GETPOST('facid', 'int');
  51. $action = GETPOST('action', 'aZ09');
  52. $gift = GETPOST('gift', 'int');
  53. if (!$user->hasRight('takepos', 'run')) {
  54. accessforbidden();
  55. }
  56. /*
  57. * View
  58. */
  59. top_httphead('text/html', 1);
  60. if ($place > 0) {
  61. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
  62. $resql = $db->query($sql);
  63. $obj = $db->fetch_object($resql);
  64. if ($obj) {
  65. $facid = $obj->rowid;
  66. }
  67. }
  68. $object = new Facture($db);
  69. $object->fetch($facid);
  70. // Call to external receipt modules if exist
  71. $parameters = array();
  72. $hookmanager->initHooks(array('takeposfrontend'));
  73. $reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
  74. if (!empty($hookmanager->resPrint)) {
  75. print $hookmanager->resPrint;
  76. return; // Receipt page can be called by the takepos/send.php page that use ob_start/end so we must use return and not exit to stop page
  77. }
  78. // 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.
  79. ?>
  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'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
  101. if (getDolGlobalString('TAKEPOS_HEADER') || getDolGlobalString($constFreeText)) {
  102. $newfreetext = '';
  103. $substitutionarray = getCommonSubstitutionArray($langs);
  104. if (getDolGlobalString('TAKEPOS_HEADER')) {
  105. $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_HEADER'), $substitutionarray);
  106. }
  107. if (getDolGlobalString($constFreeText)) {
  108. $newfreetext .= make_substitutions(getDolGlobalString($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 (getDolGlobalString('TAKEPOS_RECEIPT_NAME')) {
  118. print getDolGlobalString('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 (getDolGlobalString('TAKEPOS_SHOW_CUSTOMER')) {
  126. if ($object->socid != getDolGlobalInt('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(getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]));
  132. }
  133. print "<br>".$langs->trans("Customer").': '.$soc->name;
  134. }
  135. }
  136. if (getDolGlobalString('TAKEPOS_SHOW_DATE_OF_PRINING')) {
  137. print "<br>".$langs->trans("DateOfPrinting").': '.dol_print_date(dol_now(), 'dayhour', 'tzuserrel').'<br>';
  138. }
  139. ?>
  140. </p>
  141. <br>
  142. <table width="100%" style="border-top-style: double;">
  143. <thead>
  144. <tr>
  145. <th class="center"><?php print $langs->trans("Label"); ?></th>
  146. <th class="right"><?php print $langs->trans("Qty"); ?></th>
  147. <th class="right"><?php if ($gift != 1) {
  148. print $langs->trans("Price");
  149. } ?></th>
  150. <?php if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
  151. <th class="right"><?php if ($gift != 1) {
  152. print $langs->trans("TotalHT");
  153. } ?></th>
  154. <?php } ?>
  155. <th class="right"><?php if ($gift != 1) {
  156. print $langs->trans("TotalTTC");
  157. } ?></th>
  158. </tr>
  159. </thead>
  160. <tbody>
  161. <?php
  162. if ($action == 'without_details') {
  163. $qty = GETPOST('qty', 'int') > 0 ? GETPOST('qty', 'int') : 1;
  164. print '<tr>';
  165. print '<td>' . GETPOST('label', 'alphanohtml') . '</td>';
  166. print '<td class="right">' . $qty . '</td>';
  167. print '<td class="right">' . price(price2num($object->total_ttc / $qty, 'MU'), 1) . '</td>';
  168. if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) {
  169. print '<td class="right">' . price($object->total_ht, 1) . '</td>';
  170. }
  171. print '<td class="right">' . price($object->total_ttc, 1) . '</td>';
  172. print '</tr>';
  173. } else {
  174. foreach ($object->lines as $line) {
  175. ?>
  176. <tr>
  177. <td>
  178. <?php if (!empty($line->product_label)) {
  179. echo $line->product_label;
  180. } else {
  181. echo $line->description;
  182. } ?>
  183. </td>
  184. <td class="right"><?php echo $line->qty; ?></td>
  185. <td class="right"><?php if ($gift != 1) {
  186. echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1);
  187. } ?></td>
  188. <?php
  189. if (getDolGlobalString('TAKEPOS_SHOW_HT_RECEIPT')) { ?>
  190. <td class="right"><?php if ($gift != 1) {
  191. echo price($line->total_ht, 1);
  192. } ?></td>
  193. <?php
  194. } ?>
  195. <td class="right"><?php if ($gift != 1) {
  196. echo price($line->total_ttc, 1);
  197. } ?></td>
  198. </tr>
  199. <?php
  200. }
  201. }
  202. ?>
  203. </tbody>
  204. </table>
  205. <br>
  206. <table class="right">
  207. <tr>
  208. <th class="right"><?php if ($gift != 1) {
  209. echo $langs->trans("TotalHT");
  210. } ?></th>
  211. <td class="right"><?php if ($gift != 1) {
  212. echo price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  213. } ?></td>
  214. </tr>
  215. <?php if ($conf->global->TAKEPOS_TICKET_VAT_GROUPPED) {
  216. $vat_groups = array();
  217. foreach ($object->lines as $line) {
  218. if (!array_key_exists($line->tva_tx, $vat_groups)) {
  219. $vat_groups[$line->tva_tx] = 0;
  220. }
  221. $vat_groups[$line->tva_tx] += $line->total_tva;
  222. }
  223. // Loop on each VAT group
  224. foreach ($vat_groups as $key => $val) {
  225. ?>
  226. <tr>
  227. <th align="right"><?php if ($gift != 1) {
  228. echo $langs->trans("VAT").' '.vatrate($key, 1);
  229. } ?></th>
  230. <td align="right"><?php if ($gift != 1) {
  231. echo price($val, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  232. } ?></td>
  233. </tr>
  234. <?php
  235. }
  236. } else { ?>
  237. <tr>
  238. <th class="right"><?php if ($gift != 1) {
  239. echo $langs->trans("TotalVAT").'</th><td class="right">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  240. } ?></td>
  241. </tr>
  242. <?php }
  243. // Now show local taxes if company uses them
  244. if (price2num($object->total_localtax1, 'MU') || $mysoc->useLocalTax(1)) { ?>
  245. <tr>
  246. <th class="right"><?php if ($gift != 1) {
  247. echo ''.$langs->trans("TotalLT1").'</th><td class="right">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  248. } ?></td>
  249. </tr>
  250. <?php } ?>
  251. <?php if (price2num($object->total_localtax2, 'MU') || $mysoc->useLocalTax(2)) { ?>
  252. <tr>
  253. <th class="right"><?php if ($gift != 1) {
  254. echo ''.$langs->trans("TotalLT2").'</th><td class="right">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  255. } ?></td>
  256. </tr>
  257. <?php } ?>
  258. <tr>
  259. <th class="right"><?php if ($gift != 1) {
  260. echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  261. } ?></td>
  262. </tr>
  263. <?php
  264. if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"]) && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
  265. //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
  266. include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
  267. $multicurrency = new MultiCurrency($db);
  268. $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
  269. echo '<tr><th class="right">';
  270. if ($gift != 1) {
  271. echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].'</th><td class="right">'.price($object->total_ttc * $multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n";
  272. }
  273. echo '</td></tr>';
  274. }
  275. if (getDolGlobalString('TAKEPOS_PRINT_PAYMENT_METHOD')) {
  276. if (empty($facid)) {
  277. // Case of specimen
  278. echo '<tr>';
  279. echo '<td class="right">';
  280. echo $langs->transnoentitiesnoconv("PaymentTypeShortLIQ");
  281. echo '</td>';
  282. echo '<td class="right">';
  283. $amount_payment = 0;
  284. echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
  285. echo '</td>';
  286. echo '</tr>';
  287. } else {
  288. $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num,";
  289. $sql .= " f.multicurrency_code,";
  290. $sql .= " pf.amount as amount, pf.multicurrency_amount,";
  291. $sql .= " cp.code";
  292. $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement as p";
  293. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
  294. $sql .= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $facid);
  295. $sql .= " ORDER BY p.datep";
  296. $resql = $db->query($sql);
  297. if ($resql) {
  298. $num = $db->num_rows($resql);
  299. $i = 0;
  300. while ($i < $num) {
  301. $row = $db->fetch_object($resql);
  302. echo '<tr>';
  303. echo '<td class="right">';
  304. echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
  305. echo '</td>';
  306. echo '<td class="right">';
  307. $amount_payment = (isModEnabled('multicurrency') && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
  308. //print "xx ".$row->multicurrency_amount." - ".$row->amount." - ".$amount_payment." - ".$object->multicurrency_tx;
  309. if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
  310. $amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if it's cash payment
  311. $currency = $conf->currency;
  312. } else {
  313. // We do not show change if payment into a different currency because not yet supported
  314. $currency = $row->multicurrency_code;
  315. }
  316. echo price($amount_payment, 1, '', 1, - 1, - 1, $currency);
  317. echo '</td>';
  318. echo '</tr>';
  319. if ((!isModEnabled('multicurrency') || $object->multicurrency_tx == 1) && $row->code == "LIQ" && $row->pos_change > 0) {
  320. echo '<tr>';
  321. echo '<td class="right">';
  322. echo $langs->trans("Change"); // ChangeBack ?
  323. echo '</td>';
  324. echo '<td class="right">';
  325. echo price($row->pos_change, 1, '', 1, - 1, - 1, $currency);
  326. echo '</td>';
  327. echo '</tr>';
  328. }
  329. $i++;
  330. }
  331. }
  332. }
  333. }
  334. ?>
  335. </table>
  336. <div style="border-top-style: double;">
  337. <br>
  338. <br>
  339. <br>
  340. <?php
  341. $constFreeText = 'TAKEPOS_FOOTER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
  342. if (getDolGlobalString('TAKEPOS_FOOTER') || getDolGlobalString($constFreeText)) {
  343. $newfreetext = '';
  344. $substitutionarray = getCommonSubstitutionArray($langs);
  345. if (getDolGlobalString($constFreeText)) {
  346. $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
  347. }
  348. if (getDolGlobalString('TAKEPOS_FOOTER')) {
  349. $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_FOOTER'), $substitutionarray);
  350. }
  351. print $newfreetext;
  352. }
  353. ?>
  354. <script type="text/javascript">
  355. <?php
  356. if ($facid) {
  357. print 'window.print();';
  358. } //Avoid print when is specimen
  359. ?>
  360. </script>
  361. </body>
  362. </html>