dolibarr  20.0.0-beta
reduction.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3  * Copyright (C) 2023 Christophe Battarel <christophe.battarel@altairis.fr>
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.'/compta/facture/class/facture.class.php';
45 
46 $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
47 
48 $invoiceid = GETPOSTINT('invoiceid');
49 
50 if (!$user->hasRight('takepos', 'run')) {
52 }
53 
54 
55 /*
56  * View
57  */
58 
59 $invoice = new Facture($db);
60 if ($invoiceid > 0) {
61  $invoice->fetch($invoiceid);
62 } else {
63  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
64  $resql = $db->query($sql);
65  $obj = $db->fetch_object($resql);
66  if ($obj) {
67  $invoiceid = $obj->rowid;
68  }
69  if (!$invoiceid) {
70  $invoiceid = 0; // Invoice does not exist yet
71  } else {
72  $invoice->fetch($invoiceid);
73  }
74 }
75 
76 $head = '';
77 $arrayofcss = array('/takepos/css/pos.css.php');
78 $arrayofjs = array();
79 
80 top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
81 
82 $langs->loadLangs(array('main', 'bills', 'cashdesk'));
83 
84 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
85  $htmlReductionPercent = '<span class="fa fa-2x fa-percent"></span>';
86  $htmlReductionAmount = '<span class="fa fa-2x fa-money"></span><br>'.$langs->trans('Amount');
87 } else {
88  $htmlReductionPercent = $langs->trans('ReductionShort').'<br>%';
89  $htmlReductionAmount = $langs->trans('ReductionShort').'<br>'.$langs->trans('Amount');
90 }
91 ?>
92 <link rel="stylesheet" href="css/pos.css.php">
93 </head>
94 
95 <body>
96 
97 <script>
98  var reductionType ='';
99  var reductionTotal = '';
100  var editAction = '';
101  var editNumber = '';
102  var htmlBtnOK = '<span style="font-size: 14pt;">OK</span>';
103  var htmlReductionPercent = '<?php echo dol_escape_js($htmlReductionPercent); ?>';
104  var htmlReductionAmount = '<?php echo dol_escape_js($htmlReductionAmount); ?>';
105 
109  function Reset()
110  {
111  reductionType = '';
112  reductionTotal = '';
113  editAction = '';
114  editNumber = '';
115  jQuery('#reduction_total').val(reductionTotal);
116  jQuery("#reduction_type_percent").html(htmlReductionPercent);
117  jQuery('#reduction_type_amount').html(htmlReductionAmount);
118  }
119 
125  function Edit(number)
126  {
127  console.log('Edit ' + number);
128 
129  if (number === 'p') {
130  if (editAction === 'p' && reductionType === 'percent'){
131  ValidateReduction();
132  } else {
133  editAction = 'p';
134  }
135  reductionType = 'percent';
136  } else if (number === 'a') {
137  if (editAction === 'a' && reductionType === 'amount'){
138  ValidateReduction();
139  } else {
140  editAction = 'a';
141  }
142  reductionType = 'amount';
143  }
144 
145  if (editAction === 'p'){
146  jQuery('#reduction_type_percent').html(htmlBtnOK);
147  jQuery('#reduction_type_amount').html(htmlReductionAmount);
148  } else if (editAction === 'a'){
149  jQuery('#reduction_type_amount').html(htmlBtnOK);
150  jQuery("#reduction_type_percent").html(htmlReductionPercent);
151  } else {
152  jQuery('#reduction_type_percent').html(htmlReductionPercent);
153  jQuery('#reduction_type_amount').html(htmlReductionAmount);
154  }
155 
156  $("#reduction_total").focus();
157  }
158 
164  function AddReduction(reductionNumber)
165  {
166  console.log('AddReduction ' + reductionNumber);
167 
168  reductionTotal += String(reductionNumber);
169  jQuery('#reduction_total').val(reductionTotal);
170  }
171 
175  function ValidateReduction()
176  {
177  console.log('ValidateReduction');
178  reductionTotal = jQuery('#reduction_total').val();
179 
180  reductionTotal = $("#reduction_total").val();
181 
182  if (reductionTotal.length <= 0) {
183  console.error('Error no reduction');
184  return;
185  }
186 
187  var reductionNumber = parseFloat(reductionTotal);
188  if (isNaN(reductionNumber)) {
189  console.error('Error not a valid number :', reductionNumber);
190  return false;
191  }
192 
193  if (reductionType === 'percent') {
194  var invoiceid = <?php echo($invoiceid > 0 ? $invoiceid : 0); ?>;
195  parent.$("#poslines").load("invoice.php?action=update_reduction_global&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&number="+reductionNumber+"&invoiceid="+invoiceid, function() {
196  Reset();
197  parent.$.colorbox.close();
198  });
199  } else if (reductionType === 'amount') {
200  var desc = "<?php echo dol_escape_js($langs->transnoentities('Reduction')); ?>";
201  parent.$("#poslines").load("invoice.php?action=freezone&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&number=-"+reductionNumber+"&desc="+desc, function() {
202  Reset();
203  parent.$.colorbox.close();
204  });
205  } else {
206  console.error('Error bad reduction type :', reductionType);
207  return false
208  }
209 
210  return true;
211  }
212 
213  // manual input validation
214  function formvalid(type) {
215  reductionType = type;
216  if (reductionType != "") {
217  return ValidateReduction();
218  }
219  return false;
220  }
221 
222  // console.log("Set initial focus");
223  // $("#reduction_total").focus();
224 </script>
225 
226 <div style="position:absolute; top:2%; left:5%; width:91%;">
227 <center>
228 <?php
229 print '<input type="text" class="takepospay width125" id="reduction_total" name="reduction_total" placeholder="'.$langs->trans('Reduction').'" autofocus>';
230 if (getDolGlobalString('TAKEPOS_ADD_BUTTON_TO_ENTER_DISCOUNT_WITH_KEYBOARD')) {
231  print '<input type="button" class="butAction" value="'.$langs->trans('AmountTTC').'" onclick="return formvalid(\'amount\');">';
232  print '<input type="button" class="butAction" value="'.$langs->trans('Percentage').'" onclick="return formvalid(\'percent\');">';
233 }
234 ?>
235 </center>
236 </div>
237 
238 <div style="position:absolute; top:33%; left:5%; height:52%; width:92%;">
239 <?php
240 
241 print '<button type="button" class="calcbutton" onclick="AddReduction(\'7\');">7</button>';
242 print '<button type="button" class="calcbutton" onclick="AddReduction(\'8\');">8</button>';
243 print '<button type="button" class="calcbutton" onclick="AddReduction(\'9\');">9</button>';
244 print '<button type="button" class="calcbutton2" id="reduction_type_percent" onclick="Edit(\'p\');">'.$htmlReductionPercent.'</button>';
245 print '<button type="button" class="calcbutton" onclick="AddReduction(\'4\');">4</button>';
246 print '<button type="button" class="calcbutton" onclick="AddReduction(\'5\');">5</button>';
247 print '<button type="button" class="calcbutton" onclick="AddReduction(\'6\');">6</button>';
248 print '<button type="button" class="calcbutton2" id="reduction_type_amount" onclick="Edit(\'a\');">'.$htmlReductionAmount.'</button>';
249 print '<button type="button" class="calcbutton" onclick="AddReduction(\'1\');">1</button>';
250 print '<button type="button" class="calcbutton" onclick="AddReduction(\'2\');">2</button>';
251 print '<button type="button" class="calcbutton" onclick="AddReduction(\'3\');">3</button>';
252 print '<button type="button" class="calcbutton3 poscolorblue" onclick="Reset();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">C</span></button>';
253 print '<button type="button" class="calcbutton" onclick="AddReduction(\'0\');">0</button>';
254 print '<button type="button" class="calcbutton" onclick="AddReduction(\'.\');">.</button>';
255 print '<button type="button" class="calcbutton">&nbsp;</button>';
256 print '<button type="button" class="calcbutton3 poscolordelete" onclick="parent.$.colorbox.close();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">X</span></button>';
257 
258 ?>
259 </div>
260 
261 </body>
262 </html>
Class to manage invoices.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
Definition: main.inc.php:1786
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
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.