dolibarr 25.0.0-alpha
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2026 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.'/compta/facture/class/facture.class.php';
56$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
57
58$invoiceid = GETPOSTINT('invoiceid');
59
60if (!$user->hasRight('takepos', 'run')) {
62}
63
64
65/*
66 * View
67 */
68
69$invoice = new Facture($db);
70if ($invoiceid > 0) {
71 $invoice->fetch($invoiceid);
72} else {
73 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture";
74 $sql .= " WHERE ref = '(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
75 $sql .= " AND entity IN (".getEntity('invoice').")";
76
77 $resql = $db->query($sql);
78 $obj = $db->fetch_object($resql);
79 if ($obj) {
80 $invoiceid = $obj->rowid;
81 }
82 if (!$invoiceid) {
83 $invoiceid = 0; // Invoice does not exist yet
84 } else {
85 $invoice->fetch($invoiceid);
86 }
87}
88
89$head = '';
90$arrayofcss = array('/takepos/css/pos.css.php');
91$arrayofjs = array();
92
93top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
94
95$langs->loadLangs(array('main', 'bills', 'cashdesk'));
96
97if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
98 $htmlReductionPercent = '<span class="fa fa-2x fa-percent"></span>';
99 $htmlReductionAmount = '<span class="fa fa-2x fa-money"></span><br>'.$langs->trans('Amount');
100} else {
101 $htmlReductionPercent = $langs->trans('ReductionShort').'<br>%';
102 $htmlReductionAmount = $langs->trans('ReductionShort').'<br>'.$langs->trans('Amount');
103}
104?>
105<link rel="stylesheet" href="css/pos.css.php">
106</head>
107
108<body>
109
110<script>
111 var reductionType ='';
112 var reductionTotal = '';
113 var editAction = '';
114 var editNumber = '';
115 var htmlBtnOK = '<span style="font-size: 14pt;">OK</span>';
116 var htmlReductionPercent = <?php echo "'".dol_escape_js($htmlReductionPercent)."'" ; ?>;
117 var htmlReductionAmount = <?php echo "'".dol_escape_js($htmlReductionAmount)."'" ; ?>;
118
122 function Reset()
123 {
124 reductionType = '';
125 reductionTotal = '';
126 editAction = '';
127 editNumber = '';
128 jQuery('#reduction_total').val(reductionTotal);
129 jQuery("#reduction_type_percent").html(htmlReductionPercent);
130 jQuery('#reduction_type_amount').html(htmlReductionAmount);
131 }
132
138 function Edit(number)
139 {
140 console.log('Edit ' + number);
141
142 if (number === 'p') {
143 if (editAction === 'p' && reductionType === 'percent'){
144 ValidateReduction();
145 } else {
146 editAction = 'p';
147 }
148 reductionType = 'percent';
149 } else if (number === 'a') {
150 if (editAction === 'a' && reductionType === 'amount'){
151 ValidateReduction();
152 } else {
153 editAction = 'a';
154 }
155 reductionType = 'amount';
156 }
157
158 if (editAction === 'p'){
159 jQuery('#reduction_type_percent').html(htmlBtnOK);
160 jQuery('#reduction_type_amount').html(htmlReductionAmount);
161 } else if (editAction === 'a'){
162 jQuery('#reduction_type_amount').html(htmlBtnOK);
163 jQuery("#reduction_type_percent").html(htmlReductionPercent);
164 } else {
165 jQuery('#reduction_type_percent').html(htmlReductionPercent);
166 jQuery('#reduction_type_amount').html(htmlReductionAmount);
167 }
168
169 $("#reduction_total").focus();
170 }
171
177 function AddReduction(reductionNumber)
178 {
179 console.log('AddReduction ' + reductionNumber);
180
181 reductionTotal += String(reductionNumber);
182 jQuery('#reduction_total').val(reductionTotal);
183 }
184
188 function ValidateReduction()
189 {
190 console.log('ValidateReduction');
191 reductionTotal = jQuery('#reduction_total').val();
192
193 reductionTotal = $("#reduction_total").val();
194
195 if (reductionTotal.length <= 0) {
196 console.error('Error no reduction');
197 return;
198 }
199
200 var reductionNumber = parseFloat(reductionTotal);
201 if (isNaN(reductionNumber)) {
202 console.error('Error not a valid number :', reductionNumber);
203 return false;
204 }
205
206 if (reductionType === 'percent') {
207 var invoiceid = <?php echo($invoiceid > 0 ? $invoiceid : 0); ?>;
208 parent.$("#poslines").load("invoice.php?action=update_reduction_global&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&number="+reductionNumber+"&invoiceid="+invoiceid, function() {
209 Reset();
210 parent.$.colorbox.close();
211 });
212 } else if (reductionType === 'amount') {
213 var desc = <?php echo "'".dol_escape_js($langs->transnoentities('Reduction'))."'" ; ?>;
214 parent.$("#poslines").load("invoice.php?action=freezone&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&number=-"+reductionNumber+"&desc="+desc, function() {
215 Reset();
216 parent.$.colorbox.close();
217 });
218 } else {
219 console.error('Error bad reduction type :', reductionType);
220 return false
221 }
222
223 return true;
224 }
225
226 // manual input validation
227 function formvalid(type) {
228 reductionType = type;
229 if (reductionType != "") {
230 return ValidateReduction();
231 }
232 return false;
233 }
234
235 // console.log("Set initial focus");
236 // $("#reduction_total").focus();
237</script>
238
239<div style="position:absolute; top:2%; left:5%; width:91%;">
240<center>
241<?php
242print '<input type="text" class="takepospay width125" id="reduction_total" name="reduction_total" placeholder="'.$langs->trans('Reduction').'" autofocus>';
243if (getDolGlobalString('TAKEPOS_ADD_BUTTON_TO_ENTER_DISCOUNT_WITH_KEYBOARD')) {
244 print '<input type="button" class="butAction" value="'.$langs->trans('AmountTTC').'" onclick="return formvalid(\'amount\');">';
245 print '<input type="button" class="butAction" value="'.$langs->trans('Percentage').'" onclick="return formvalid(\'percent\');">';
246}
247?>
248</center>
249</div>
250
251<div style="position:absolute; top:33%; left:5%; height:52%; width:92%;">
252<?php
253
254print '<button type="button" class="calcbutton" onclick="AddReduction(\'7\');">7</button>';
255print '<button type="button" class="calcbutton" onclick="AddReduction(\'8\');">8</button>';
256print '<button type="button" class="calcbutton" onclick="AddReduction(\'9\');">9</button>';
257print '<button type="button" class="calcbutton2" id="reduction_type_percent" onclick="Edit(\'p\');">'.$htmlReductionPercent.'</button>';
258print '<button type="button" class="calcbutton" onclick="AddReduction(\'4\');">4</button>';
259print '<button type="button" class="calcbutton" onclick="AddReduction(\'5\');">5</button>';
260print '<button type="button" class="calcbutton" onclick="AddReduction(\'6\');">6</button>';
261print '<button type="button" class="calcbutton2" id="reduction_type_amount" onclick="Edit(\'a\');">'.$htmlReductionAmount.'</button>';
262print '<button type="button" class="calcbutton" onclick="AddReduction(\'1\');">1</button>';
263print '<button type="button" class="calcbutton" onclick="AddReduction(\'2\');">2</button>';
264print '<button type="button" class="calcbutton" onclick="AddReduction(\'3\');">3</button>';
265print '<button type="button" class="calcbutton3 poscolorblue" onclick="Reset();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">C</span></button>';
266print '<button type="button" class="calcbutton" onclick="AddReduction(\'0\');">0</button>';
267print '<button type="button" class="calcbutton" onclick="AddReduction(\'.\');">.</button>';
268print '<button type="button" class="calcbutton">&nbsp;</button>';
269print '<button type="button" class="calcbutton3 poscolordelete" onclick="parent.$.colorbox.close();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">X</span></button>';
270
271?>
272</div>
273
274</body>
275</html>
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:280
Class to manage invoices.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalString($key, $default='')
Return a 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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.