dolibarr  16.0.5
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');
28 if (!defined('NOCSRFCHECK')) {
29  define('NOCSRFCHECK', '1');
30 }
31 if (!defined('NOTOKENRENEWAL')) {
32  define('NOTOKENRENEWAL', '1');
33 }
34 if (!defined('NOREQUIREMENU')) {
35  define('NOREQUIREMENU', '1');
36 }
37 if (!defined('NOREQUIREHTML')) {
38  define('NOREQUIREHTML', '1');
39 }
40 if (!defined('NOREQUIREAJAX')) {
41  define('NOREQUIREAJAX', '1');
42 }
43 
44 require '../main.inc.php'; // Load $user and permissions
45 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
46 
47 $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
48 
49 $invoiceid = GETPOST('invoiceid', 'int');
50 
51 if (empty($user->rights->takepos->run)) {
53 }
54 
55 
56 /*
57  * View
58  */
59 
60 $invoice = new Facture($db);
61 if ($invoiceid > 0) {
62  $invoice->fetch($invoiceid);
63 } else {
64  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
65  $resql = $db->query($sql);
66  $obj = $db->fetch_object($resql);
67  if ($obj) {
68  $invoiceid = $obj->rowid;
69  }
70  if (!$invoiceid) {
71  $invoiceid = 0; // Invoice does not exist yet
72  } else {
73  $invoice->fetch($invoiceid);
74  }
75 }
76 
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) || !empty($conf->global->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 <body>
95 
96 <script>
97  var reductionType ='';
98  var reductionTotal = '';
99  var editAction = '';
100  var editNumber = '';
101  var htmlBtnOK = '<span style="font-size: 14pt;">OK</span>';
102  var htmlReductionPercent = '<?php echo dol_escape_js($htmlReductionPercent); ?>';
103  var htmlReductionAmount = '<?php echo dol_escape_js($htmlReductionAmount); ?>';
104 
108  function Reset()
109  {
110  reductionType = '';
111  reductionTotal = '';
112  editAction = '';
113  editNumber = '';
114  jQuery('#reduction_total').val(reductionTotal);
115  jQuery("#reduction_type_percent").html(htmlReductionPercent);
116  jQuery('#reduction_type_amount').html(htmlReductionAmount);
117  }
118 
124  function Edit(number)
125  {
126  console.log('Edit ' + number);
127 
128  if (number === 'p') {
129  if (editAction === 'p' && reductionType === 'percent'){
130  ValidateReduction();
131  } else {
132  editAction = 'p';
133  }
134  reductionType = 'percent';
135  } else if (number === 'a') {
136  if (editAction === 'a' && reductionType === 'amount'){
137  ValidateReduction();
138  } else {
139  editAction = 'a';
140  }
141  reductionType = 'amount';
142  }
143 
144  if (editAction === 'p'){
145  jQuery('#reduction_type_percent').html(htmlBtnOK);
146  jQuery('#reduction_type_amount').html(htmlReductionAmount);
147  } else if (editAction === 'a'){
148  jQuery('#reduction_type_amount').html(htmlBtnOK);
149  jQuery("#reduction_type_percent").html(htmlReductionPercent);
150  } else {
151  jQuery('#reduction_type_percent').html(htmlReductionPercent);
152  jQuery('#reduction_type_amount').html(htmlReductionAmount);
153  }
154  }
155 
161  function AddReduction(reductionNumber)
162  {
163  console.log('AddReduction ' + reductionNumber);
164 
165  reductionTotal += String(reductionNumber);
166  jQuery('#reduction_total').val(reductionTotal);
167  }
168 
172  function ValidateReduction()
173  {
174  console.log('ValidateReduction');
175 
176  if (reductionTotal.length <= 0) {
177  console.error('Error no reduction');
178  return;
179  }
180 
181  var reductionNumber = parseFloat(reductionTotal);
182  if (isNaN(reductionNumber)) {
183  console.error('Error not a valid number :', reductionNumber);
184  return;
185  }
186 
187  if (reductionType === 'percent') {
188  var invoiceid = <?php echo ($invoiceid > 0 ? $invoiceid : 0); ?>;
189  parent.$("#poslines").load("invoice.php?action=update_reduction_global&place=<?php echo $place; ?>&number="+reductionNumber+"&invoiceid="+invoiceid, function() {
190  Reset();
191  parent.$.colorbox.close();
192  });
193  } else if (reductionType === 'amount') {
194  var desc = "<?php echo dol_escape_js($langs->transnoentities('Reduction')); ?>";
195  parent.$("#poslines").load("invoice.php?action=freezone&place=<?php echo $place; ?>&number=-"+reductionNumber+"&desc="+desc, function() {
196  Reset();
197  parent.$.colorbox.close();
198  });
199  } else {
200  console.error('Error bad reduction type :', reductionType);
201  }
202  }
203 </script>
204 
205 <div style="position:absolute; top:2%; left:5%; width:91%;">
206 <center>
207 <?php
208  print '<input type="text" class="takepospay" id="reduction_total" name="reduction_total" style="width: 50%;" placeholder="'.$langs->trans('Reduction').'">';
209 ?>
210 </center>
211 </div>
212 
213 <div style="position:absolute; top:33%; left:5%; height:52%; width:92%;">
214 <?php
215 
216 print '<button type="button" class="calcbutton" onclick="AddReduction(7);">7</button>';
217 print '<button type="button" class="calcbutton" onclick="AddReduction(8);">8</button>';
218 print '<button type="button" class="calcbutton" onclick="AddReduction(9);">9</button>';
219 print '<button type="button" class="calcbutton2" id="reduction_type_percent" onclick="Edit(\'p\');">'.$htmlReductionPercent.'</button>';
220 print '<button type="button" class="calcbutton" onclick="AddReduction(4);">4</button>';
221 print '<button type="button" class="calcbutton" onclick="AddReduction(5);">5</button>';
222 print '<button type="button" class="calcbutton" onclick="AddReduction(6);">6</button>';
223 print '<button type="button" class="calcbutton2" id="reduction_type_amount" onclick="Edit(\'a\');">'.$htmlReductionAmount.'</button>';
224 print '<button type="button" class="calcbutton" onclick="AddReduction(1);">1</button>';
225 print '<button type="button" class="calcbutton" onclick="AddReduction(2);">2</button>';
226 print '<button type="button" class="calcbutton" onclick="AddReduction(3);">3</button>';
227 print '<button type="button" class="calcbutton3 poscolorblue" onclick="Reset();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">C</span></button>';
228 print '<button type="button" class="calcbutton" onclick="AddReduction(0);">0</button>';
229 print '<button type="button" class="calcbutton" onclick="AddReduction(\'.\');">.</button>';
230 print '<button type="button" class="calcbutton">&nbsp;</button>';
231 print '<button type="button" class="calcbutton3 poscolordelete" onclick="parent.$.colorbox.close();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">X</span></button>';
232 
233 ?>
234 </div>
235 
236 </body>
237 </html>
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
top_htmlhead
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:1482
Facture
Class to manage invoices.
Definition: facture.class.php:60
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933