freezone.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. $invoiceid = GETPOST('invoiceid', 'int');
  48. $idline = GETPOST('idline', 'int');
  49. $action = GETPOST('action', 'aZ09');
  50. if (!$user->hasRight('takepos', 'run')) {
  51. accessforbidden();
  52. }
  53. // get invoice
  54. $invoice = new Facture($db);
  55. if ($invoiceid > 0) {
  56. $invoice->fetch($invoiceid);
  57. } else {
  58. $invoice->fetch('', '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$place.')');
  59. }
  60. // get default vat rate
  61. $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION['takeposterminal'];
  62. $soc = new Societe($db);
  63. if ($invoice->socid > 0) {
  64. $soc->fetch($invoice->socid);
  65. } else {
  66. $soc->fetch(getDolGlobalInt($constforcompanyid));
  67. }
  68. $vatRateDefault = get_default_tva($mysoc, $soc);
  69. /*
  70. * View
  71. */
  72. $arrayofcss = array('/takepos/css/pos.css.php');
  73. $arrayofjs = array();
  74. top_htmlhead('', '', 0, 0, $arrayofjs, $arrayofcss);
  75. ?>
  76. <body>
  77. <script>
  78. var vatRate = '<?php echo dol_escape_js($vatRateDefault); ?>';
  79. /**
  80. * Apply new VAT rate
  81. *
  82. * @param {string} id VAT id
  83. * @param {string} rate VAT rate
  84. */
  85. function ApplyVATRate(id, rate) {
  86. console.log("Save selected VAT Rate into vatRate variable with value "+rate);
  87. vatRate = rate;
  88. jQuery('button.vat_rate').removeClass('selected');
  89. jQuery('#vat_rate_'+id).addClass('selected');
  90. }
  91. /**
  92. * Save (validate)
  93. */
  94. function Save() {
  95. console.log("We click so we call page invoice.php with invoiceid=<?php echo $invoiceid; ?>, place=<?php echo $place; ?>, amount="+$("#number").val()+", tva_tx="+vatRate);
  96. parent.$("#poslines").load("invoice.php?action=freezone&token=<?php echo newToken(); ?>&invoiceid=<?php echo $invoiceid; ?>&place=<?php echo $place; ?>&number="+$("#number").val()+"&tva_tx="+vatRate, {desc:$("#desc").val()});
  97. parent.$.colorbox.close();
  98. }
  99. $( document ).ready(function() {
  100. $('#desc').focus()
  101. });
  102. </script>
  103. <br>
  104. <center>
  105. <form>
  106. <input type="text" id="desc" name="desc" class="takepospay" style="width:40%;" placeholder="<?php echo $langs->trans('Description'); ?>">
  107. <?php
  108. if ($action == "freezone") {
  109. echo '<input type="text" id="number" name="number" class="takepospay" style="width:15%;" placeholder="'.$langs->trans(getDolGlobalString("TAKEPOS_CHANGE_PRICE_HT") ? 'AmountHT' : 'AmountTTC').'">';
  110. }
  111. if ($action == "addnote") {
  112. echo '<input type="hidden" id="number" name="number" value="'.$idline.'">';
  113. }
  114. ?>
  115. <input type="hidden" name="place" class="takepospay" value="<?php echo $place; ?>">
  116. <input type="submit" class="button takepospay clearboth" value="OK" onclick="Save(); return false;">
  117. </form>
  118. <?php
  119. if ($action == 'freezone' && !getDolGlobalString("TAKEPOS_USE_DEFAULT_VATRATE_FOR_FREEZONE")) {
  120. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  121. $form = new Form($db);
  122. $num = $form->load_cache_vatrates("'".$mysoc->country_code."'");
  123. if ($num > 0) {
  124. print '<br><br>';
  125. print $langs->trans('VAT').' : ';
  126. foreach ($form->cache_vatrates as $rate) {
  127. 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>';
  128. }
  129. }
  130. }
  131. ?>
  132. </center>
  133. </body>
  134. </html>