Advertisement
erptarragona

receipt.php

Nov 22nd, 2024
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.88 KB | None | 0 0
  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. /**
  24.  *  \file       htdocs/takepos/receipt.php
  25.  *  \ingroup    takepos
  26.  *  \brief      Page to show a receipt.
  27.  */
  28.  
  29. // Includes
  30. if (!isset($action)) {
  31.     //if (! defined('NOREQUIREUSER'))   define('NOREQUIREUSER', '1');   // Not disabled cause need to load personalized language
  32.     //if (! defined('NOREQUIREDB'))     define('NOREQUIREDB', '1');     // Not disabled cause need to load personalized language
  33.     //if (! defined('NOREQUIRESOC'))        define('NOREQUIRESOC', '1');
  34.     //if (! defined('NOREQUIRETRAN'))       define('NOREQUIRETRAN', '1');
  35.     if (!defined('NOTOKENRENEWAL')) {
  36.         define('NOTOKENRENEWAL', '1');
  37.     }
  38.     if (!defined('NOREQUIREMENU')) {
  39.         define('NOREQUIREMENU', '1');
  40.     }
  41.     if (!defined('NOREQUIREHTML')) {
  42.         define('NOREQUIREHTML', '1');
  43.     }
  44.     if (!defined('NOREQUIREAJAX')) {
  45.         define('NOREQUIREAJAX', '1');
  46.     }
  47.  
  48.     require '../main.inc.php'; // If this file is called from send.php avoid load again
  49. }
  50. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  51.  
  52. $langs->loadLangs(array("main", "bills", "cashdesk", "companies"));
  53.  
  54. $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant
  55.  
  56. $facid = GETPOST('facid', 'int');
  57.  
  58. $action = GETPOST('action', 'aZ09');
  59. $gift = GETPOST('gift', 'int');
  60.  
  61. if (!$user->hasRight('takepos', 'run')) {
  62.     accessforbidden();
  63. }
  64.  
  65.  
  66. /*
  67.  * View
  68.  */
  69.  
  70. top_httphead('text/html', 1);
  71.  
  72. if ($place > 0) {
  73.     $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$db->escape($_SESSION["takeposterminal"]."-".$place).")'";
  74.     $resql = $db->query($sql);
  75.     $obj = $db->fetch_object($resql);
  76.     if ($obj) {
  77.         $facid = $obj->rowid;
  78.     }
  79. }
  80. $object = new Facture($db);
  81. $object->fetch($facid);
  82.  
  83. // Call to external receipt modules if exist
  84. $parameters = array();
  85. $hookmanager->initHooks(array('takeposfrontend'));
  86. $reshook = $hookmanager->executeHooks('TakeposReceipt', $parameters, $object);
  87. if (!empty($hookmanager->resPrint)) {
  88.     print $hookmanager->resPrint;
  89.     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
  90. }
  91.  
  92. // 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.
  93. ?>
  94. <body>
  95. <style>
  96. .right {
  97.     text-align: right;
  98. }
  99. .center {
  100.     text-align: center;
  101. }
  102. .left {
  103.     text-align: left;
  104. }
  105. body, p, table {
  106.     line-height: 1; /* Ajusta este valor según la compacidad que desees */
  107. }
  108. </style>
  109. <center>
  110. <font size="4">
  111. <?php echo '<b>'.$mysoc->name.'</b>'; ?>
  112. </font>
  113. </center>
  114. <br>
  115. <p class="left">
  116. <?php
  117. $constFreeText = 'TAKEPOS_HEADER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
  118. if (getDolGlobalString('TAKEPOS_HEADER') || getDolGlobalString($constFreeText)) {
  119.     $newfreetext = '';
  120.     $substitutionarray = getCommonSubstitutionArray($langs);
  121.     if (getDolGlobalString('TAKEPOS_HEADER')) {
  122.         $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_HEADER'), $substitutionarray);
  123.     }
  124.     if (getDolGlobalString($constFreeText)) {
  125.         $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
  126.     }
  127.     print nl2br($newfreetext);
  128. }
  129. ?>
  130. </p>
  131. <p class="right">
  132. <?php
  133. print $langs->trans('Date')." ".dol_print_date($object->date, 'day').'<br>';
  134. if (!empty($conf->global->TAKEPOS_RECEIPT_NAME)) {
  135.     print $conf->global->TAKEPOS_RECEIPT_NAME." ";
  136. }
  137. if ($object->statut == Facture::STATUS_DRAFT) {
  138.     print str_replace(")", "", str_replace("-", " ".$langs->trans('Place')." ", str_replace("(PROV-POS", $langs->trans("Terminal")." ", $object->ref)));
  139. } else {
  140.     print $object->ref;
  141. }
  142. if (!empty($conf->global->TAKEPOS_SHOW_CUSTOMER)) {
  143.     if ($object->socid != getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"])) {
  144.         $soc = new Societe($db);
  145.         if ($object->socid > 0) {
  146.             $soc->fetch($object->socid);
  147.         } else {
  148.             $soc->fetch(getDolGlobalInt('CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]));
  149.         }
  150.         print "<br>".$langs->trans("Customer").': '.$soc->name;
  151.     }
  152. }
  153. if (!empty($conf->global->TAKEPOS_SHOW_DATE_OF_PRINING)) {
  154.     print "<br>".$langs->trans("DateOfPrinting").': '.dol_print_date(dol_now(), 'dayhour', 'tzuserrel').'<br>';
  155. }
  156. ?>
  157. </p>
  158. <br>
  159.  
  160. <table width="100%" style="border-top-style: double;">
  161.     <thead>
  162.     <tr>
  163.         <th class="center"><?php print $langs->trans("Label"); ?></th>
  164.         <th class="right"><?php print $langs->trans("Discount"); ?></th> <!-- descuento xus -->
  165.         <th class="right"><?php print $langs->trans("Qty"); ?></th>
  166.         <th class="right"><?php if ($gift != 1) {
  167.             print $langs->trans("Price");
  168.                           } ?></th>
  169.         <?php  if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) { ?>
  170.         <th class="right"><?php if ($gift != 1) {
  171.             print $langs->trans("TotalHT");
  172.                           } ?></th>
  173.         <?php } ?>
  174.         <th class="right"><?php if ($gift != 1) {
  175.             print $langs->trans("TotalTTC");
  176.                           } ?></th>
  177.     </tr>
  178.     </thead>
  179.     <tbody>
  180.     <?php
  181.     if ($action == 'without_details') {
  182.         $qty = GETPOST('qty', 'int') > 0 ? GETPOST('qty', 'int') : 1;
  183.         print '<tr>';
  184.         print '<td>' . GETPOST('label', 'alphanohtml') . '</td>';
  185.         print '<td class="right">' . $qty . '</td>';
  186.         print '<td class="right">' . price(price2num($object->total_ttc / $qty, 'MU'), 1) . '</td>';
  187.         if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) {
  188.             print '<td class="right">' . price($object->total_ht, 1) . '</td>';
  189.         }
  190.         print '<td class="right">' . price($object->total_ttc, 1) . '</td>';
  191.         print '</tr>';
  192.     } else {
  193.         foreach ($object->lines as $line) {
  194.             ?>
  195.         <tr>
  196.             <td>
  197.             <?php if (!empty($line->product_label)) {
  198.                 echo $line->product_label;
  199.             } else {
  200.                 echo $line->description;
  201.             } ?>
  202.             </td>
  203.             <td class="right"><?php echo $line->remise_percent . '%'; ?></td> <!-- descuento xus -->
  204.             <td class="right"><?php echo $line->qty; ?></td>
  205.             <td class="right"><?php if ($gift != 1) {
  206.                 echo price(price2num($line->total_ttc / $line->qty, 'MT'), 1);
  207.                               } ?></td>
  208.             <?php
  209.             if (!empty($conf->global->TAKEPOS_SHOW_HT_RECEIPT)) { ?>
  210.                         <td class="right"><?php if ($gift != 1) {
  211.                             echo price($line->total_ht, 1);
  212.                                           } ?></td>
  213.                 <?php
  214.             }
  215.             ?>
  216.             <td class="right"><?php if ($gift != 1) {
  217.                 echo price($line->total_ttc, 1);
  218.                               } ?></td>
  219.         </tr>
  220.             <?php
  221.         }
  222.     }
  223.     ?>
  224.     </tbody>
  225. </table>
  226. <br>
  227. <table class="right">
  228. <tr>
  229.     <th class="right"><?php if ($gift != 1) {
  230.         echo $langs->trans("TotalHT");
  231.                       } ?></th>
  232.     <td class="right"><?php if ($gift != 1) {
  233.         echo price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  234.                       } ?></td>
  235. </tr>
  236. <?php if ($conf->global->TAKEPOS_TICKET_VAT_GROUPPED) {
  237.     $vat_groups = array();
  238.     foreach ($object->lines as $line) {
  239.         if (!array_key_exists($line->tva_tx, $vat_groups)) {
  240.             $vat_groups[$line->tva_tx] = 0;
  241.         }
  242.         $vat_groups[$line->tva_tx] += $line->total_tva;
  243.     }
  244.     // Loop on each VAT group
  245.     foreach ($vat_groups as $key => $val) {
  246.         ?>
  247.     <tr>
  248.         <th align="right"><?php if ($gift != 1) {
  249.             echo $langs->trans("VAT").' '.vatrate($key, 1);
  250.                           } ?></th>
  251.         <td align="right"><?php if ($gift != 1) {
  252.             echo price($val, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  253.                           } ?></td>
  254.     </tr>
  255.         <?php
  256.     }
  257. } else { ?>
  258. <tr>
  259.     <th class="right"><?php if ($gift != 1) {
  260.         echo $langs->trans("TotalVAT").'</th><td class="right">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  261.                       } ?></td>
  262. </tr>
  263. <?php }
  264.  
  265. // Now show local taxes if company uses them
  266.  
  267. if (price2num($object->total_localtax1, 'MU') || $mysoc->useLocalTax(1)) { ?>
  268. <tr>
  269.     <th class="right"><?php if ($gift != 1) {
  270.         echo ''.$langs->trans("TotalLT1").'</th><td class="right">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  271.                       } ?></td>
  272. </tr>
  273. <?php } ?>
  274. <?php if (price2num($object->total_localtax2, 'MU') || $mysoc->useLocalTax(2)) { ?>
  275. <tr>
  276.     <th class="right"><?php if ($gift != 1) {
  277.         echo ''.$langs->trans("TotalLT2").'</th><td class="right">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  278.                       } ?></td>
  279. </tr>
  280. <?php } ?>
  281. <tr>
  282.     <th class="right"><?php if ($gift != 1) {
  283.         echo ''.$langs->trans("TotalTTC").'</th><td class="right">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n";
  284.                       } ?></td>
  285. </tr>
  286. <?php
  287. if (isModEnabled('multicurrency') && !empty($_SESSION["takeposcustomercurrency"]) && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
  288.     //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
  289.     include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
  290.     $multicurrency = new MultiCurrency($db);
  291.     $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
  292.     echo '<tr><th class="right">';
  293.     if ($gift != 1) {
  294.         echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].'</th><td class="right">'.price($object->total_ttc * $multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n";
  295.     }
  296.     echo '</td></tr>';
  297. }
  298.  
  299. if (getDolGlobalString('TAKEPOS_PRINT_PAYMENT_METHOD')) {
  300.     if (empty($facid)) {
  301.         // Case of specimen
  302.         echo '<tr>';
  303.         echo '<td class="right">';
  304.         echo $langs->transnoentitiesnoconv("PaymentTypeShortLIQ");
  305.         echo '</td>';
  306.         echo '<td class="right">';
  307.         $amount_payment = 0;
  308.         echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
  309.         echo '</td>';
  310.         echo '</tr>';
  311.     } else {
  312.         $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,";
  313.         $sql .= " cp.code";
  314.         $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
  315.         $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
  316.         $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $facid);
  317.         $sql .= " ORDER BY p.datep";
  318.  
  319.         $resql = $db->query($sql);
  320.         if ($resql) {
  321.             $num = $db->num_rows($resql);
  322.  
  323.             $i = 0;
  324.             while ($i < $num) {
  325.                 $row = $db->fetch_object($resql);
  326.  
  327.                 echo '<tr>';
  328.                 echo '<td class="right">';
  329.                 echo $langs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
  330.                 echo '</td>';
  331.                 echo '<td class="right">';
  332.                 $amount_payment = (isModEnabled('multicurrency') && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
  333.                 if ($row->code == "LIQ") {
  334.                     $amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if is cash payment
  335.                 }
  336.                 echo price($amount_payment, 1, '', 1, - 1, - 1, $conf->currency);
  337.                 echo '</td>';
  338.                 echo '</tr>';
  339.                 if ($row->code == "LIQ" && $row->pos_change > 0) { // Print change only in cash payments
  340.                     echo '<tr>';
  341.                     echo '<td class="right">';
  342.                     echo $langs->trans("Change");
  343.                     echo '</td>';
  344.                     echo '<td class="right">';
  345.                     echo price($row->pos_change, 1, '', 1, - 1, - 1, $conf->currency);
  346.                     echo '</td>';
  347.                     echo '</tr>';
  348.                 }
  349.                 $i++;
  350.             }
  351.         }
  352.     }
  353. }
  354. ?>
  355. </table>
  356. <div style="border-top-style: double;">
  357. <br>
  358. <br>
  359. <br>
  360. <?php
  361. $constFreeText = 'TAKEPOS_FOOTER'.(empty($_SESSION['takeposterminal']) ? '0' : $_SESSION['takeposterminal']);
  362. if (getDolGlobalString('TAKEPOS_FOOTER') || getDolGlobalString($constFreeText)) {
  363.     $newfreetext = '';
  364.     $substitutionarray = getCommonSubstitutionArray($langs);
  365.     if (getDolGlobalString($constFreeText)) {
  366.         $newfreetext .= make_substitutions(getDolGlobalString($constFreeText), $substitutionarray);
  367.     }
  368.     if (getDolGlobalString('TAKEPOS_FOOTER')) {
  369.         $newfreetext .= make_substitutions(getDolGlobalString('TAKEPOS_FOOTER'), $substitutionarray);
  370.     }
  371.     print $newfreetext;
  372. }
  373. ?>
  374.  
  375. <script type="text/javascript">
  376.     <?php
  377.     if ($facid) print 'window.print();'; //Avoid print when is specimen
  378.     ?>
  379. </script>
  380.  
  381. </body>
  382. </html>
  383.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement