Advertisement
erptarragona

receipt.php

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