dolibarr 22.0.5
freezone.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3 * Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
28//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
29//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
30//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
31if (!defined('NOTOKENRENEWAL')) {
32 define('NOTOKENRENEWAL', '1');
33}
34if (!defined('NOREQUIREMENU')) {
35 define('NOREQUIREMENU', '1');
36}
37if (!defined('NOREQUIREHTML')) {
38 define('NOREQUIREHTML', '1');
39}
40if (!defined('NOREQUIREAJAX')) {
41 define('NOREQUIREAJAX', '1');
42}
43
44// Load Dolibarr environment
45require '../main.inc.php'; // Load $user and permissions
46require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
48require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
49
50global $mysoc;
60$langs->loadLangs(array("bills", "cashdesk"));
61
62$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : '0'); // $place is id of table for Bar or Restaurant
63
64$invoiceid = GETPOSTINT('invoiceid');
65
66$idline = GETPOSTINT('idline');
67$action = GETPOST('action', 'aZ09');
68
69if (!$user->hasRight('takepos', 'run')) {
71}
72
73// get invoice
74$invoice = new Facture($db);
75if ($invoiceid > 0) {
76 $invoice->fetch($invoiceid);
77} else {
78 $invoice->fetch(0, '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$place.')');
79}
80
81
82// get default vat rate
83$constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION['takeposterminal'];
84$soc = new Societe($db);
85if ($invoice->socid > 0) {
86 $soc->fetch($invoice->socid);
87} else {
88 $soc->fetch(getDolGlobalInt($constforcompanyid));
89}
90$vatRateDefault = get_default_tva($mysoc, $soc);
91
92
93/*
94 * View
95 */
96
97$arrayofcss = array('/takepos/css/pos.css.php');
98$arrayofjs = array();
99
100top_htmlhead('', '', 0, 0, $arrayofjs, $arrayofcss);
101?>
102<body>
103
104<script>
105 var vatRate = '<?php echo dol_escape_js($vatRateDefault); ?>';
106
113 function ApplyVATRate(id, rate) {
114 console.log("Save selected VAT Rate into vatRate variable with value "+rate);
115 vatRate = rate;
116 jQuery('button.vat_rate').removeClass('selected');
117 jQuery('#vat_rate_'+id).addClass('selected');
118 }
119
123 function Save() {
124 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);
125 parent.$("#poslines").load("<?php echo DOL_URL_ROOT; ?>/takepos/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()});
126 parent.$.colorbox.close();
127 }
128
129 $( document ).ready(function() {
130 $('#desc').focus()
131 });
132</script>
133
134<br>
135<center>
136<form>
137<input type="text" id="desc" name="desc" class="takepospay" style="width:40%;" placeholder="<?php echo $langs->trans('Description'); ?>">
138<?php
139if ($action == "freezone" && $user->hasRight('takepos', 'run')) {
140 echo '<input type="text" id="number" name="number" class="takepospay" style="width:15%;" placeholder="'.$langs->trans(getDolGlobalString("TAKEPOS_CHANGE_PRICE_HT") ? 'AmountHT' : 'AmountTTC').'">';
141}
142if ($action == "addnote" && $user->hasRight('takepos', 'run')) {
143 echo '<input type="hidden" id="number" name="number" value="'.$idline.'">';
144}
145?>
146<input type="hidden" name="place" class="takepospay" value="<?php echo $place; ?>">
147<input type="submit" class="button takepospay clearboth" value="OK" onclick="Save(); return false;">
148</form>
149<?php
150if ($action == 'freezone' && !getDolGlobalString("TAKEPOS_USE_DEFAULT_VATRATE_FOR_FREEZONE") && $user->hasRight('takepos', 'run')) {
151 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
152
153 $form = new Form($db);
154 $num = $form->load_cache_vatrates("'".$mysoc->country_code."'");
155 if ($num > 0) {
156 print '<br><br>';
157 print $langs->trans('VAT').' : ';
158 foreach ($form->cache_vatrates as $rate) {
159 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>';
160 }
161 }
162}
163?>
164</center>
165
166</body>
167</html>
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:158
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.