dolibarr  13.0.2
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')) define('NOCSRFCHECK', '1');
29 if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
30 if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
31 if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
32 if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
33 
34 require '../main.inc.php'; // Load $user and permissions
35 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
36 
37 $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
38 
39 $invoiceid = GETPOST('invoiceid', 'int');
40 
41 if (empty($user->rights->takepos->run)) {
43 }
44 
45 
46 /*
47  * View
48  */
49 
50 $invoice = new Facture($db);
51 if ($invoiceid > 0)
52 {
53  $invoice->fetch($invoiceid);
54 } else {
55  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
56  $resql = $db->query($sql);
57  $obj = $db->fetch_object($resql);
58  if ($obj)
59  {
60  $invoiceid = $obj->rowid;
61  }
62  if (!$invoiceid)
63  {
64  $invoiceid = 0; // Invoice does not exist yet
65  } else {
66  $invoice->fetch($invoiceid);
67  }
68 }
69 
70 $arrayofcss = array('/takepos/css/pos.css.php');
71 $arrayofjs = array();
72 
73 top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
74 
75 $langs->loadLangs(array('main', 'bills', 'cashdesk'));
76 
77 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
78  $htmlReductionPercent = '<span class="fa fa-2x fa-percent"></span>';
79  $htmlReductionAmount = '<span class="fa fa-2x fa-money"></span><br>'.$langs->trans('Amount');
80 } else {
81  $htmlReductionPercent = $langs->trans('ReductionShort').'<br>%';
82  $htmlReductionAmount = $langs->trans('ReductionShort').'<br>'.$langs->trans('Amount');
83 }
84 ?>
85 <link rel="stylesheet" href="css/pos.css.php">
86 </head>
87 <body>
88 
89 <script>
90  var reductionType ='';
91  var reductionTotal = '';
92  var editAction = '';
93  var editNumber = '';
94  var htmlBtnOK = '<span style="font-size: 14pt;">OK</span>';
95  var htmlReductionPercent = '<?php echo dol_escape_js($htmlReductionPercent); ?>';
96  var htmlReductionAmount = '<?php echo dol_escape_js($htmlReductionAmount); ?>';
97 
101  function Reset()
102  {
103  reductionType = '';
104  reductionTotal = '';
105  editAction = '';
106  editNumber = '';
107  jQuery('#reduction_total').val(reductionTotal);
108  jQuery("#reduction_type_percent").html(htmlReductionPercent);
109  jQuery('#reduction_type_amount').html(htmlReductionAmount);
110  }
111 
117  function Edit(number)
118  {
119  console.log('Edit ' + number);
120 
121  if (number === 'p') {
122  if (editAction === 'p' && reductionType === 'percent'){
123  ValidateReduction();
124  } else {
125  editAction = 'p';
126  }
127  reductionType = 'percent';
128  } else if (number === 'a') {
129  if (editAction === 'a' && reductionType === 'amount'){
130  ValidateReduction();
131  } else {
132  editAction = 'a';
133  }
134  reductionType = 'amount';
135  }
136 
137  if (editAction === 'p'){
138  jQuery('#reduction_type_percent').html(htmlBtnOK);
139  jQuery('#reduction_type_amount').html(htmlReductionAmount);
140  } else if (editAction === 'a'){
141  jQuery('#reduction_type_amount').html(htmlBtnOK);
142  jQuery("#reduction_type_percent").html(htmlReductionPercent);
143  } else {
144  jQuery('#reduction_type_percent').html(htmlReductionPercent);
145  jQuery('#reduction_type_amount').html(htmlReductionAmount);
146  }
147  }
148 
154  function AddReduction(reductionNumber)
155  {
156  console.log('AddReduction ' + reductionNumber);
157 
158  reductionTotal += String(reductionNumber);
159  jQuery('#reduction_total').val(reductionTotal);
160  }
161 
165  function ValidateReduction()
166  {
167  console.log('ValidateReduction');
168 
169  if (reductionTotal.length <= 0) {
170  console.error('Error no reduction');
171  return;
172  }
173 
174  var reductionNumber = parseFloat(reductionTotal);
175  if (isNaN(reductionNumber)) {
176  console.error('Error not a valid number :', reductionNumber);
177  return;
178  }
179 
180  if (reductionType === 'percent') {
181  var invoiceid = <?php echo ($invoiceid > 0 ? $invoiceid : 0); ?>;
182  parent.$("#poslines").load("invoice.php?action=update_reduction_global&place=<?php echo $place; ?>&number="+reductionNumber+"&invoiceid="+invoiceid, function() {
183  Reset();
184  parent.$.colorbox.close();
185  });
186  } else if (reductionType === 'amount') {
187  var desc = "<?php echo dol_escape_js($langs->transnoentities('Reduction')); ?>";
188  parent.$("#poslines").load("invoice.php?action=freezone&place=<?php echo $place; ?>&number=-"+reductionNumber+"&desc="+desc, function() {
189  Reset();
190  parent.$.colorbox.close();
191  });
192  } else {
193  console.error('Error bad reduction type :', reductionType);
194  }
195  }
196 </script>
197 
198 <div style="position:absolute; top:2%; left:5%; width:91%;">
199 <center>
200 <?php
201  print '<input type="text" class="takepospay" id="reduction_total" name="reduction_total" style="width: 50%;" placeholder="'.$langs->trans('Reduction').'">';
202 ?>
203 </center>
204 </div>
205 
206 <div style="position:absolute; top:33%; left:5%; height:52%; width:92%;">
207 <?php
208 
209 print '<button type="button" class="calcbutton" onclick="AddReduction(7);">7</button>';
210 print '<button type="button" class="calcbutton" onclick="AddReduction(8);">8</button>';
211 print '<button type="button" class="calcbutton" onclick="AddReduction(9);">9</button>';
212 print '<button type="button" class="calcbutton2" id="reduction_type_percent" onclick="Edit(\'p\');">'.$htmlReductionPercent.'</button>';
213 print '<button type="button" class="calcbutton" onclick="AddReduction(4);">4</button>';
214 print '<button type="button" class="calcbutton" onclick="AddReduction(5);">5</button>';
215 print '<button type="button" class="calcbutton" onclick="AddReduction(6);">6</button>';
216 print '<button type="button" class="calcbutton2" id="reduction_type_amount" onclick="Edit(\'a\');">'.$htmlReductionAmount.'</button>';
217 print '<button type="button" class="calcbutton" onclick="AddReduction(1);">1</button>';
218 print '<button type="button" class="calcbutton" onclick="AddReduction(2);">2</button>';
219 print '<button type="button" class="calcbutton" onclick="AddReduction(3);">3</button>';
220 print '<button type="button" class="calcbutton3 poscolorblue" onclick="Reset();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">C</span></button>';
221 print '<button type="button" class="calcbutton" onclick="AddReduction(0);">0</button>';
222 print '<button type="button" class="calcbutton" onclick="AddReduction(\'.\');">.</button>';
223 print '<button type="button" class="calcbutton">&nbsp;</button>';
224 print '<button type="button" class="calcbutton3 poscolordelete" onclick="parent.$.colorbox.close();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">X</span></button>';
225 
226 ?>
227 </div>
228 
229 </body>
230 </html>
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= '', $disablejmobile=0, $disablenofollow=0)
Ouput html header of a page.
Definition: main.inc.php:1280
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 ...
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
Class to manage invoices.