dolibarr  18.0.6
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  *
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 
25 //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
26 //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
27 //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
28 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
29 if (!defined('NOTOKENRENEWAL')) {
30  define('NOTOKENRENEWAL', '1');
31 }
32 if (!defined('NOREQUIREMENU')) {
33  define('NOREQUIREMENU', '1');
34 }
35 if (!defined('NOREQUIREHTML')) {
36  define('NOREQUIREHTML', '1');
37 }
38 if (!defined('NOREQUIREAJAX')) {
39  define('NOREQUIREAJAX', '1');
40 }
41 
42 // Load Dolibarr environment
43 require '../main.inc.php'; // Load $user and permissions
44 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
45 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
47 
48 global $mysoc;
49 
50 $langs->loadLangs(array("bills", "cashdesk"));
51 
52 $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : '0'); // $place is id of table for Bar or Restaurant
53 
54 $idline = GETPOST('idline', 'int');
55 $action = GETPOST('action', 'aZ09');
56 
57 if (empty($user->rights->takepos->run)) {
59 }
60 
61 // get invoice
62 $invoice = new Facture($db);
63 if ($place > 0) {
64  $invoice->fetch($place);
65 } else {
66  $invoice->fetch('', '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$place.')');
67 }
68 
69 // get default vat rate
70 $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION['takeposterminal'];
71 $soc = new Societe($db);
72 if ($invoice->socid > 0) {
73  $soc->fetch($invoice->socid);
74 } else {
75  $soc->fetch($conf->global->$constforcompanyid);
76 }
77 $vatRateDefault = get_default_tva($mysoc, $soc);
78 
79 
80 /*
81  * View
82  */
83 
84 $arrayofcss = array('/takepos/css/pos.css.php');
85 $arrayofjs = array();
86 
87 top_htmlhead('', '', 0, 0, $arrayofjs, $arrayofcss);
88 ?>
89 <body>
90 
91 <script>
92  var vatRate = '<?php echo dol_escape_js($vatRateDefault); ?>';
93 
100  function ApplyVATRate(id, rate) {
101  console.log("Save selected VAT Rate into vatRate variable with value "+rate);
102  vatRate = rate;
103  jQuery('button.vat_rate').removeClass('selected');
104  jQuery('#vat_rate_'+id).addClass('selected');
105  }
106 
110  function Save() {
111  console.log("We click so we call page invoice.php with place=<?php echo $place; ?> tva_tx="+vatRate);
112  parent.$("#poslines").load("invoice.php?action=freezone&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&number="+$('#number').val()+"&tva_tx="+vatRate, {desc:$('#desc').val()});
113  parent.$.colorbox.close();
114  }
115 
116  $( document ).ready(function() {
117  $('#desc').focus()
118  });
119 </script>
120 
121 <br>
122 <center>
123 <form>
124 <input type="text" id="desc" name="desc" class="takepospay" style="width:40%;" placeholder="<?php echo $langs->trans('Description'); ?>">
125 <?php
126 if ($action == "freezone") {
127  echo '<input type="text" id="number" name="number" class="takepospay" style="width:15%;" placeholder="'.$langs->trans('Price').'">';
128 }
129 if ($action == "addnote") {
130  echo '<input type="hidden" id="number" name="number" value="'.$idline.'">';
131 }
132 ?>
133 <input type="hidden" name="place" class="takepospay" value="<?php echo $place; ?>">
134 <input type="submit" class="button takepospay clearboth" value="OK" onclick="Save(); return false;">
135 </form>
136 <?php
137 if ($action == 'freezone' && !getDolGlobalString("TAKEPOS_USE_DEFAULT_VATRATE_FOR_FREEZONE")) {
138  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
139 
140  $form = new Form($db);
141  $num = $form->load_cache_vatrates("'".$mysoc->country_code."'");
142  if ($num > 0) {
143  print '<br><br>';
144  print $langs->trans('VAT').' : ';
145  foreach ($form->cache_vatrates as $rate) {
146  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>';
147  }
148  }
149 }
150 ?>
151 </center>
152 
153 </body>
154 </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...)
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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 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='', $arrayofcss='', $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.
Definition: main.inc.php:1641
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.