dolibarr 18.0.6
reduction.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
25//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
26//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
27//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
28if (!defined('NOTOKENRENEWAL')) {
29 define('NOTOKENRENEWAL', '1');
30}
31if (!defined('NOREQUIREMENU')) {
32 define('NOREQUIREMENU', '1');
33}
34if (!defined('NOREQUIREHTML')) {
35 define('NOREQUIREHTML', '1');
36}
37if (!defined('NOREQUIREAJAX')) {
38 define('NOREQUIREAJAX', '1');
39}
40
41// Load Dolibarr environment
42require '../main.inc.php'; // Load $user and permissions
43require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
44
45$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
46
47$invoiceid = GETPOST('invoiceid', 'int');
48
49if (empty($user->rights->takepos->run)) {
51}
52
53
54/*
55 * View
56 */
57
58$invoice = new Facture($db);
59if ($invoiceid > 0) {
60 $invoice->fetch($invoiceid);
61} else {
62 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
63 $resql = $db->query($sql);
64 $obj = $db->fetch_object($resql);
65 if ($obj) {
66 $invoiceid = $obj->rowid;
67 }
68 if (!$invoiceid) {
69 $invoiceid = 0; // Invoice does not exist yet
70 } else {
71 $invoice->fetch($invoiceid);
72 }
73}
74
75$head = '';
76$arrayofcss = array('/takepos/css/pos.css.php');
77$arrayofjs = array();
78
79top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
80
81$langs->loadLangs(array('main', 'bills', 'cashdesk'));
82
83if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
84 $htmlReductionPercent = '<span class="fa fa-2x fa-percent"></span>';
85 $htmlReductionAmount = '<span class="fa fa-2x fa-money"></span><br>'.$langs->trans('Amount');
86} else {
87 $htmlReductionPercent = $langs->trans('ReductionShort').'<br>%';
88 $htmlReductionAmount = $langs->trans('ReductionShort').'<br>'.$langs->trans('Amount');
89}
90?>
91<link rel="stylesheet" href="css/pos.css.php">
92</head>
93<body>
94
95<script>
96 var reductionType ='';
97 var reductionTotal = '';
98 var editAction = '';
99 var editNumber = '';
100 var htmlBtnOK = '<span style="font-size: 14pt;">OK</span>';
101 var htmlReductionPercent = '<?php echo dol_escape_js($htmlReductionPercent); ?>';
102 var htmlReductionAmount = '<?php echo dol_escape_js($htmlReductionAmount); ?>';
103
107 function Reset()
108 {
109 reductionType = '';
110 reductionTotal = '';
111 editAction = '';
112 editNumber = '';
113 jQuery('#reduction_total').val(reductionTotal);
114 jQuery("#reduction_type_percent").html(htmlReductionPercent);
115 jQuery('#reduction_type_amount').html(htmlReductionAmount);
116 }
117
123 function Edit(number)
124 {
125 console.log('Edit ' + number);
126
127 if (number === 'p') {
128 if (editAction === 'p' && reductionType === 'percent'){
129 ValidateReduction();
130 } else {
131 editAction = 'p';
132 }
133 reductionType = 'percent';
134 } else if (number === 'a') {
135 if (editAction === 'a' && reductionType === 'amount'){
136 ValidateReduction();
137 } else {
138 editAction = 'a';
139 }
140 reductionType = 'amount';
141 }
142
143 if (editAction === 'p'){
144 jQuery('#reduction_type_percent').html(htmlBtnOK);
145 jQuery('#reduction_type_amount').html(htmlReductionAmount);
146 } else if (editAction === 'a'){
147 jQuery('#reduction_type_amount').html(htmlBtnOK);
148 jQuery("#reduction_type_percent").html(htmlReductionPercent);
149 } else {
150 jQuery('#reduction_type_percent').html(htmlReductionPercent);
151 jQuery('#reduction_type_amount').html(htmlReductionAmount);
152 }
153 }
154
160 function AddReduction(reductionNumber)
161 {
162 console.log('AddReduction ' + reductionNumber);
163
164 reductionTotal += String(reductionNumber);
165 jQuery('#reduction_total').val(reductionTotal);
166 }
167
171 function ValidateReduction()
172 {
173 console.log('ValidateReduction');
174
175 if (reductionTotal.length <= 0) {
176 console.error('Error no reduction');
177 return;
178 }
179
180 var reductionNumber = parseFloat(reductionTotal);
181 if (isNaN(reductionNumber)) {
182 console.error('Error not a valid number :', reductionNumber);
183 return;
184 }
185
186 if (reductionType === 'percent') {
187 var invoiceid = <?php echo ($invoiceid > 0 ? $invoiceid : 0); ?>;
188 parent.$("#poslines").load("invoice.php?action=update_reduction_global&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&number="+reductionNumber+"&invoiceid="+invoiceid, function() {
189 Reset();
190 parent.$.colorbox.close();
191 });
192 } else if (reductionType === 'amount') {
193 var desc = "<?php echo dol_escape_js($langs->transnoentities('Reduction')); ?>";
194 parent.$("#poslines").load("invoice.php?action=freezone&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&number=-"+reductionNumber+"&desc="+desc, function() {
195 Reset();
196 parent.$.colorbox.close();
197 });
198 } else {
199 console.error('Error bad reduction type :', reductionType);
200 }
201 }
202</script>
203
204<div style="position:absolute; top:2%; left:5%; width:91%;">
205<center>
206<?php
207 print '<input type="text" class="takepospay" id="reduction_total" name="reduction_total" style="width: 50%;" placeholder="'.$langs->trans('Reduction').'">';
208?>
209</center>
210</div>
211
212<div style="position:absolute; top:33%; left:5%; height:52%; width:92%;">
213<?php
214
215print '<button type="button" class="calcbutton" onclick="AddReduction(\'7\');">7</button>';
216print '<button type="button" class="calcbutton" onclick="AddReduction(\'8\');">8</button>';
217print '<button type="button" class="calcbutton" onclick="AddReduction(\'9\');">9</button>';
218print '<button type="button" class="calcbutton2" id="reduction_type_percent" onclick="Edit(\'p\');">'.$htmlReductionPercent.'</button>';
219print '<button type="button" class="calcbutton" onclick="AddReduction(\'4\');">4</button>';
220print '<button type="button" class="calcbutton" onclick="AddReduction(\'5\');">5</button>';
221print '<button type="button" class="calcbutton" onclick="AddReduction(\'6\');">6</button>';
222print '<button type="button" class="calcbutton2" id="reduction_type_amount" onclick="Edit(\'a\');">'.$htmlReductionAmount.'</button>';
223print '<button type="button" class="calcbutton" onclick="AddReduction(\'1\');">1</button>';
224print '<button type="button" class="calcbutton" onclick="AddReduction(\'2\');">2</button>';
225print '<button type="button" class="calcbutton" onclick="AddReduction(\'3\');">3</button>';
226print '<button type="button" class="calcbutton3 poscolorblue" onclick="Reset();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">C</span></button>';
227print '<button type="button" class="calcbutton" onclick="AddReduction(\'0\');">0</button>';
228print '<button type="button" class="calcbutton" onclick="AddReduction(\'.\');">.</button>';
229print '<button type="button" class="calcbutton">&nbsp;</button>';
230print '<button type="button" class="calcbutton3 poscolordelete" onclick="parent.$.colorbox.close();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">X</span></button>';
231
232?>
233</div>
234
235</body>
236</html>
Class to manage invoices.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput 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.