dolibarr 21.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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
27//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
28//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
29//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
30if (!defined('NOTOKENRENEWAL')) {
31 define('NOTOKENRENEWAL', '1');
32}
33if (!defined('NOREQUIREMENU')) {
34 define('NOREQUIREMENU', '1');
35}
36if (!defined('NOREQUIREHTML')) {
37 define('NOREQUIREHTML', '1');
38}
39if (!defined('NOREQUIREAJAX')) {
40 define('NOREQUIREAJAX', '1');
41}
42
43// Load Dolibarr environment
44require '../main.inc.php'; // Load $user and permissions
45require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
55$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
56
57$invoiceid = GETPOSTINT('invoiceid');
58
59if (!$user->hasRight('takepos', 'run')) {
61}
62
63
64/*
65 * View
66 */
67
68$invoice = new Facture($db);
69if ($invoiceid > 0) {
70 $invoice->fetch($invoiceid);
71} else {
72 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture";
73 $sql .= " WHERE ref = '(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
74 $sql .= " AND entity IN (".getEntity('invoice').")";
75
76 $resql = $db->query($sql);
77 $obj = $db->fetch_object($resql);
78 if ($obj) {
79 $invoiceid = $obj->rowid;
80 }
81 if (!$invoiceid) {
82 $invoiceid = 0; // Invoice does not exist yet
83 } else {
84 $invoice->fetch($invoiceid);
85 }
86}
87
88$head = '';
89$arrayofcss = array('/takepos/css/pos.css.php');
90$arrayofjs = array();
91
92top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
93
94$langs->loadLangs(array('main', 'bills', 'cashdesk'));
95
96if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
97 $htmlReductionPercent = '<span class="fa fa-2x fa-percent"></span>';
98 $htmlReductionAmount = '<span class="fa fa-2x fa-money"></span><br>'.$langs->trans('Amount');
99} else {
100 $htmlReductionPercent = $langs->trans('ReductionShort').'<br>%';
101 $htmlReductionAmount = $langs->trans('ReductionShort').'<br>'.$langs->trans('Amount');
102}
103?>
104<link rel="stylesheet" href="css/pos.css.php">
105</head>
106
107<body>
108
109<script>
110 var reductionType ='';
111 var reductionTotal = '';
112 var editAction = '';
113 var editNumber = '';
114 var htmlBtnOK = '<span style="font-size: 14pt;">OK</span>';
115 var htmlReductionPercent = '<?php echo dol_escape_js($htmlReductionPercent); ?>';
116 var htmlReductionAmount = '<?php echo dol_escape_js($htmlReductionAmount); ?>';
117
121 function Reset()
122 {
123 reductionType = '';
124 reductionTotal = '';
125 editAction = '';
126 editNumber = '';
127 jQuery('#reduction_total').val(reductionTotal);
128 jQuery("#reduction_type_percent").html(htmlReductionPercent);
129 jQuery('#reduction_type_amount').html(htmlReductionAmount);
130 }
131
137 function Edit(number)
138 {
139 console.log('Edit ' + number);
140
141 if (number === 'p') {
142 if (editAction === 'p' && reductionType === 'percent'){
143 ValidateReduction();
144 } else {
145 editAction = 'p';
146 }
147 reductionType = 'percent';
148 } else if (number === 'a') {
149 if (editAction === 'a' && reductionType === 'amount'){
150 ValidateReduction();
151 } else {
152 editAction = 'a';
153 }
154 reductionType = 'amount';
155 }
156
157 if (editAction === 'p'){
158 jQuery('#reduction_type_percent').html(htmlBtnOK);
159 jQuery('#reduction_type_amount').html(htmlReductionAmount);
160 } else if (editAction === 'a'){
161 jQuery('#reduction_type_amount').html(htmlBtnOK);
162 jQuery("#reduction_type_percent").html(htmlReductionPercent);
163 } else {
164 jQuery('#reduction_type_percent').html(htmlReductionPercent);
165 jQuery('#reduction_type_amount').html(htmlReductionAmount);
166 }
167
168 $("#reduction_total").focus();
169 }
170
176 function AddReduction(reductionNumber)
177 {
178 console.log('AddReduction ' + reductionNumber);
179
180 reductionTotal += String(reductionNumber);
181 jQuery('#reduction_total').val(reductionTotal);
182 }
183
187 function ValidateReduction()
188 {
189 console.log('ValidateReduction');
190 reductionTotal = jQuery('#reduction_total').val();
191
192 reductionTotal = $("#reduction_total").val();
193
194 if (reductionTotal.length <= 0) {
195 console.error('Error no reduction');
196 return;
197 }
198
199 var reductionNumber = parseFloat(reductionTotal);
200 if (isNaN(reductionNumber)) {
201 console.error('Error not a valid number :', reductionNumber);
202 return false;
203 }
204
205 if (reductionType === 'percent') {
206 var invoiceid = <?php echo($invoiceid > 0 ? $invoiceid : 0); ?>;
207 parent.$("#poslines").load("invoice.php?action=update_reduction_global&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&number="+reductionNumber+"&invoiceid="+invoiceid, function() {
208 Reset();
209 parent.$.colorbox.close();
210 });
211 } else if (reductionType === 'amount') {
212 var desc = "<?php echo dol_escape_js($langs->transnoentities('Reduction')); ?>";
213 parent.$("#poslines").load("invoice.php?action=freezone&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&number=-"+reductionNumber+"&desc="+desc, function() {
214 Reset();
215 parent.$.colorbox.close();
216 });
217 } else {
218 console.error('Error bad reduction type :', reductionType);
219 return false
220 }
221
222 return true;
223 }
224
225 // manual input validation
226 function formvalid(type) {
227 reductionType = type;
228 if (reductionType != "") {
229 return ValidateReduction();
230 }
231 return false;
232 }
233
234 // console.log("Set initial focus");
235 // $("#reduction_total").focus();
236</script>
237
238<div style="position:absolute; top:2%; left:5%; width:91%;">
239<center>
240<?php
241print '<input type="text" class="takepospay width125" id="reduction_total" name="reduction_total" placeholder="'.$langs->trans('Reduction').'" autofocus>';
242if (getDolGlobalString('TAKEPOS_ADD_BUTTON_TO_ENTER_DISCOUNT_WITH_KEYBOARD')) {
243 print '<input type="button" class="butAction" value="'.$langs->trans('AmountTTC').'" onclick="return formvalid(\'amount\');">';
244 print '<input type="button" class="butAction" value="'.$langs->trans('Percentage').'" onclick="return formvalid(\'percent\');">';
245}
246?>
247</center>
248</div>
249
250<div style="position:absolute; top:33%; left:5%; height:52%; width:92%;">
251<?php
252
253print '<button type="button" class="calcbutton" onclick="AddReduction(\'7\');">7</button>';
254print '<button type="button" class="calcbutton" onclick="AddReduction(\'8\');">8</button>';
255print '<button type="button" class="calcbutton" onclick="AddReduction(\'9\');">9</button>';
256print '<button type="button" class="calcbutton2" id="reduction_type_percent" onclick="Edit(\'p\');">'.$htmlReductionPercent.'</button>';
257print '<button type="button" class="calcbutton" onclick="AddReduction(\'4\');">4</button>';
258print '<button type="button" class="calcbutton" onclick="AddReduction(\'5\');">5</button>';
259print '<button type="button" class="calcbutton" onclick="AddReduction(\'6\');">6</button>';
260print '<button type="button" class="calcbutton2" id="reduction_type_amount" onclick="Edit(\'a\');">'.$htmlReductionAmount.'</button>';
261print '<button type="button" class="calcbutton" onclick="AddReduction(\'1\');">1</button>';
262print '<button type="button" class="calcbutton" onclick="AddReduction(\'2\');">2</button>';
263print '<button type="button" class="calcbutton" onclick="AddReduction(\'3\');">3</button>';
264print '<button type="button" class="calcbutton3 poscolorblue" onclick="Reset();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">C</span></button>';
265print '<button type="button" class="calcbutton" onclick="AddReduction(\'0\');">0</button>';
266print '<button type="button" class="calcbutton" onclick="AddReduction(\'.\');">.</button>';
267print '<button type="button" class="calcbutton">&nbsp;</button>';
268print '<button type="button" class="calcbutton3 poscolordelete" onclick="parent.$.colorbox.close();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">X</span></button>';
269
270?>
271</div>
272
273</body>
274</html>
Class to manage invoices.
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 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.