freezone.php 4.8 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('NOCSRFCHECK')) {
  28. define('NOCSRFCHECK', '1');
  29. }
  30. if (!defined('NOTOKENRENEWAL')) {
  31. define('NOTOKENRENEWAL', '1');
  32. }
  33. if (!defined('NOREQUIREMENU')) {
  34. define('NOREQUIREMENU', '1');
  35. }
  36. if (!defined('NOREQUIREHTML')) {
  37. define('NOREQUIREHTML', '1');
  38. }
  39. if (!defined('NOREQUIREAJAX')) {
  40. define('NOREQUIREAJAX', '1');
  41. }
  42. require '../main.inc.php'; // Load $user and permissions
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  44. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  46. global $mysoc;
  47. $langs->loadLangs(array("bills", "cashdesk"));
  48. $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : '0'); // $place is id of table for Bar or Restaurant
  49. $idline = GETPOST('idline', 'int');
  50. $action = GETPOST('action', 'aZ09');
  51. if (empty($user->rights->takepos->run)) {
  52. accessforbidden();
  53. }
  54. // get invoice
  55. $invoice = new Facture($db);
  56. if ($place > 0) {
  57. $invoice->fetch($place);
  58. } else {
  59. $invoice->fetch('', '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$place.')');
  60. }
  61. // get default vat rate
  62. $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION['takeposterminal'];
  63. $soc = new Societe($db);
  64. if ($invoice->socid > 0) {
  65. $soc->fetch($invoice->socid);
  66. } else {
  67. $soc->fetch($conf->global->$constforcompanyid);
  68. }
  69. $vatRateDefault = get_default_tva($mysoc, $soc);
  70. /*
  71. * View
  72. */
  73. $arrayofcss = array('/takepos/css/pos.css.php');
  74. $arrayofjs = array();
  75. top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
  76. ?>
  77. <body>
  78. <script>
  79. var vatRate = '<?php echo dol_escape_js($vatRateDefault); ?>';
  80. /**
  81. * Apply new VAT rate
  82. *
  83. * @param {string} id VAT id
  84. * @param {string} rate VAT rate
  85. */
  86. function ApplyVATRate(id, rate) {
  87. console.log("Save selected VAT Rate into vatRate variable with value "+rate);
  88. vatRate = rate;
  89. jQuery('button.vat_rate').removeClass('selected');
  90. jQuery('#vat_rate_'+id).addClass('selected');
  91. }
  92. /**
  93. * Save (validate)
  94. */
  95. function Save() {
  96. console.log("We click so we call page invoice.php with place=<?php echo $place; ?> tva_tx="+vatRate);
  97. parent.$("#poslines").load("invoice.php?action=freezone&place=<?php echo $place; ?>&number="+$('#number').val()+"&tva_tx="+vatRate, {desc:$('#desc').val()});
  98. parent.$.colorbox.close();
  99. }
  100. $( document ).ready(function() {
  101. $('#desc').focus()
  102. });
  103. </script>
  104. <br>
  105. <center>
  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('Price').'">';
  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="button" class="button takepospay clearboth" value="OK" onclick="Save();">
  117. <?php
  118. if ($action == '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>