freezone.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
  3. * Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/takepos/freezone.php
  20. * \ingroup takepos
  21. * \brief Popup to enter a free line
  22. */
  23. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  24. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  25. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  26. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  27. if (!defined('NOTOKENRENEWAL')) {
  28. define('NOTOKENRENEWAL', '1');
  29. }
  30. if (!defined('NOREQUIREMENU')) {
  31. define('NOREQUIREMENU', '1');
  32. }
  33. if (!defined('NOREQUIREHTML')) {
  34. define('NOREQUIREHTML', '1');
  35. }
  36. if (!defined('NOREQUIREAJAX')) {
  37. define('NOREQUIREAJAX', '1');
  38. }
  39. // Load Dolibarr environment
  40. require '../main.inc.php'; // Load $user and permissions
  41. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  42. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  44. global $mysoc;
  45. $langs->loadLangs(array("bills", "cashdesk"));
  46. $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : '0'); // $place is id of table for Bar or Restaurant
  47. $idline = GETPOST('idline', 'int');
  48. $action = GETPOST('action', 'aZ09');
  49. if (empty($user->rights->takepos->run)) {
  50. accessforbidden();
  51. }
  52. // get invoice
  53. $invoice = new Facture($db);
  54. if ($place > 0) {
  55. $invoice->fetch($place);
  56. } else {
  57. $invoice->fetch('', '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$place.')');
  58. }
  59. // get default vat rate
  60. $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION['takeposterminal'];
  61. $soc = new Societe($db);
  62. if ($invoice->socid > 0) {
  63. $soc->fetch($invoice->socid);
  64. } else {
  65. $soc->fetch($conf->global->$constforcompanyid);
  66. }
  67. $vatRateDefault = get_default_tva($mysoc, $soc);
  68. /*
  69. * View
  70. */
  71. $arrayofcss = array('/takepos/css/pos.css.php');
  72. $arrayofjs = array();
  73. top_htmlhead('', '', 0, 0, $arrayofjs, $arrayofcss);
  74. ?>
  75. <body>
  76. <script>
  77. var vatRate = '<?php echo dol_escape_js($vatRateDefault); ?>';
  78. /**
  79. * Apply new VAT rate
  80. *
  81. * @param {string} id VAT id
  82. * @param {string} rate VAT rate
  83. */
  84. function ApplyVATRate(id, rate) {
  85. console.log("Save selected VAT Rate into vatRate variable with value "+rate);
  86. vatRate = rate;
  87. jQuery('button.vat_rate').removeClass('selected');
  88. jQuery('#vat_rate_'+id).addClass('selected');
  89. }
  90. /**
  91. * Save (validate)
  92. */
  93. function Save() {
  94. console.log("We click so we call page invoice.php with place=<?php echo $place; ?> tva_tx="+vatRate);
  95. parent.$("#poslines").load("invoice.php?action=freezone&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&number="+$('#number').val()+"&tva_tx="+vatRate, {desc:$('#desc').val()});
  96. parent.$.colorbox.close();
  97. }
  98. $( document ).ready(function() {
  99. $('#desc').focus()
  100. });
  101. </script>
  102. <br>
  103. <center>
  104. <form>
  105. <input type="text" id="desc" name="desc" class="takepospay" style="width:40%;" placeholder="<?php echo $langs->trans('Description'); ?>">
  106. <?php
  107. if ($action == "freezone") {
  108. echo '<input type="text" id="number" name="number" class="takepospay" style="width:15%;" placeholder="'.$langs->trans('Price').'">';
  109. }
  110. if ($action == "addnote") {
  111. echo '<input type="hidden" id="number" name="number" value="'.$idline.'">';
  112. }
  113. ?>
  114. <input type="hidden" name="place" class="takepospay" value="<?php echo $place; ?>">
  115. <input type="submit" class="button takepospay clearboth" value="OK" onclick="Save(); return false;">
  116. </form>
  117. <?php
  118. if ($action == 'freezone' && !getDolGlobalString("TAKEPOS_USE_DEFAULT_VATRATE_FOR_FREEZONE")) {
  119. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  120. $form = new Form($db);
  121. $num = $form->load_cache_vatrates("'".$mysoc->country_code."'");
  122. if ($num > 0) {
  123. print '<br><br>';
  124. print $langs->trans('VAT').' : ';
  125. foreach ($form->cache_vatrates as $rate) {
  126. print '<button type="button" class="button item_value vat_rate'.($rate['txtva'] == $vatRateDefault ? ' selected' : '').'" id="vat_rate_'.$rate['rowid'].'" onclick="ApplyVATRate(\''.$rate['rowid'].'\', \''.$rate['txtva'].'\');">'.$rate['txtva'].' %</button>';
  127. }
  128. }
  129. }
  130. ?>
  131. </center>
  132. </body>
  133. </html>