dolibarr  16.0.5
price.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
7  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
8  * Copyright (C) 2014-2018 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2014-2019 Philippe Grand <philippe.grand@atoo-net.com>
10  * Copyright (C) 2014 Ion agorria <ion@agorria.com>
11  * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
12  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
13  * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
14  * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
15  * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program. If not, see <https://www.gnu.org/licenses/>.
29  */
30 
37 require '../main.inc.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_expression.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
43 
44 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
45  require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
46 
47  $prodcustprice = new Productcustomerprice($db);
48 }
49 
50 // Load translation files required by the page
51 $langs->loadLangs(array('products', 'bills', 'companies', 'other'));
52 
53 $error = 0;
54 $errors = array();
55 
56 $id = GETPOST('id', 'int');
57 $ref = GETPOST('ref', 'alpha');
58 $action = GETPOST('action', 'aZ09');
59 $cancel = GETPOST('cancel', 'alpha');
60 $eid = GETPOST('eid', 'int');
61 
62 $search_soc = GETPOST('search_soc');
63 
64 // Security check
65 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
66 $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
67 if ($user->socid) {
68  $socid = $user->socid;
69 }
70 
71 if ($id > 0 || !empty($ref)) {
72  $object = new Product($db);
73  $object->fetch($id, $ref);
74 }
75 
76 // Clean param
77 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) {
78  $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5;
79 }
80 
81 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
82 $hookmanager->initHooks(array('productpricecard', 'globalcard'));
83 
84 if ($object->id > 0) {
85  if ($object->type == $object::TYPE_PRODUCT) {
86  restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
87  }
88  if ($object->type == $object::TYPE_SERVICE) {
89  restrictedArea($user, 'service', $object->id, 'product&product', '', '');
90  }
91 } else {
92  restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
93 }
94 
95 
96 /*
97  * Actions
98  */
99 
100 if ($cancel) {
101  $action = '';
102 }
103 
104 $parameters = array('id'=>$id, 'ref'=>$ref);
105 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
106 if ($reshook < 0) {
107  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
108 }
109 
110 if (empty($reshook)) {
111  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
112  $search_soc = '';
113  }
114 
115  if ($action == 'setlabelsellingprice' && $user->admin) {
116  require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
117  $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.GETPOST('pricelevel');
118  dolibarr_set_const($db, $keyforlabel, GETPOST('labelsellingprice', 'alpha'), 'chaine', 0, '', $conf->entity);
119  $action = '';
120  }
121 
122  if (($action == 'update_vat') && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) {
123  $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
124 
125  // We must define tva_tx, npr and local taxes
126  $tva_tx = $tva_tx_txt;
127  $reg = array();
128  $vatratecode = '';
129  if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
130  $vatratecode = $reg[1];
131  $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate.
132  }
133 
134  $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot
135  $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
136  $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0';
137  // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
138  if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
139  // We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in create product.
140  $vatratecode = $reg[1];
141  // Get record from code
142  $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
143  $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
144  $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
145  $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
146  $sql .= " AND t.code = '".$db->escape($vatratecode)."'";
147  $resql = $db->query($sql);
148  if ($resql) {
149  $obj = $db->fetch_object($resql);
150  if ($obj) {
151  $npr = $obj->recuperableonly;
152  $localtax1 = $obj->localtax1;
153  $localtax2 = $obj->localtax2;
154  $localtax1_type = $obj->localtax1_type;
155  $localtax2_type = $obj->localtax2_type;
156  }
157  }
158  } else {
159  // Get record with empty code
160  $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
161  $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
162  $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
163  $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
164  $sql .= " AND t.code = ''";
165  $resql = $db->query($sql);
166  if ($resql) {
167  $obj = $db->fetch_object($resql);
168  if ($obj) {
169  $npr = $obj->recuperableonly;
170  $localtax1 = $obj->localtax1;
171  $localtax2 = $obj->localtax2;
172  $localtax1_type = $obj->localtax1_type;
173  $localtax2_type = $obj->localtax2_type;
174  }
175  }
176  }
177 
178  $object->default_vat_code = $vatratecode;
179  $object->tva_tx = $tva_tx;
180  $object->tva_npr = $npr;
181  $object->localtax1_tx = $localtax1;
182  $object->localtax2_tx = $localtax2;
183  $object->localtax1_type = $localtax1_type;
184  $object->localtax2_type = $localtax2_type;
185 
186  $db->begin();
187 
188  $resql = $object->update($object->id, $user);
189  if ($resql <= 0) {
190  $error++;
191  setEventMessages($object->error, $object->errors, 'errors');
192  }
193 
194  if (!$error) {
195  if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
196  for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
197  // Force the update of the price of the product using the new VAT
198  if ($object->multiprices_base_type[$i] == 'HT') {
199  $oldprice = $object->multiprices[$i];
200  $oldminprice = $object->multiprices_min[$i];
201  } else {
202  $oldprice = $object->multiprices_ttc[$i];
203  $oldminprice = $object->multiprices_min_ttc[$i];
204  }
205  $oldpricebasetype = $object->multiprices_base_type[$i];
206  $oldnpr = $object->multiprices_recuperableonly[$i];
207 
208  //$localtaxarray=array('0'=>$localtax1_type,'1'=>$localtax1,'2'=>$localtax2_type,'3'=>$localtax2);
209  $localtaxarray = array(); // We do not store localtaxes into product, we will use instead the "vat code" to retrieve them.
210  $level = $i;
211  $ret = $object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode);
212 
213  if ($ret < 0) {
214  $error++;
215  setEventMessages($object->error, $object->errors, 'errors');
216  }
217  }
218  } else {
219  // Force the update of the price of the product using the new VAT
220  if ($object->price_base_type == 'HT') {
221  $oldprice = $object->price;
222  $oldminprice = $object->price_min;
223  } else {
224  $oldprice = $object->price_ttc;
225  $oldminprice = $object->price_min_ttc;
226  }
227  $oldpricebasetype = $object->price_base_type;
228  $oldnpr = $object->tva_npr;
229 
230  //$localtaxarray=array('0'=>$localtax1_type,'1'=>$localtax1,'2'=>$localtax2_type,'3'=>$localtax2);
231  $localtaxarray = array(); // We do not store localtaxes into product, we will use instead the "vat code" to retrieve them.
232  $level = 0;
233  $ret = $object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode);
234 
235  if ($ret < 0) {
236  $error++;
237  setEventMessages($object->error, $object->errors, 'errors');
238  }
239  }
240  }
241 
242  if (!$error) {
243  $db->commit();
244  } else {
245  $db->rollback();
246  }
247 
248  $action = '';
249  }
250 
251  if (($action == 'update_price') && !$cancel && $object->getRights()->creer) {
252  $error = 0;
253  $pricestoupdate = array();
254 
255  $psq = GETPOST('psqflag');
256  $psq = empty($newpsq) ? 0 : $newpsq;
257  $maxpricesupplier = $object->min_recommended_price();
258 
259  if (!empty($conf->dynamicprices->enabled)) {
260  $object->fk_price_expression = empty($eid) ? 0 : $eid; //0 discards expression
261 
262  if ($object->fk_price_expression != 0) {
263  //Check the expression validity by parsing it
264  $priceparser = new PriceParser($db);
265 
266  if ($priceparser->parseProduct($object) < 0) {
267  $error++;
268  setEventMessages($priceparser->translatedError(), null, 'errors');
269  }
270  }
271  }
272 
273  // Multiprices
274  if (!$error && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
275  $newprice = GETPOST('price', 'array');
276  $newprice_min = GETPOST('price_min', 'array');
277  $newpricebase = GETPOST('multiprices_base_type', 'array');
278  $newvattx = GETPOST('tva_tx', 'array');
279  $newvatnpr = GETPOST('tva_npr', 'array');
280  $newlocaltax1_tx = GETPOST('localtax1_tx', 'array');
281  $newlocaltax1_type = GETPOST('localtax1_type', 'array');
282  $newlocaltax2_tx = GETPOST('localtax2_tx', 'array');
283  $newlocaltax2_type = GETPOST('localtax2_type', 'array');
284 
285  //Shall we generate prices using price rules?
286  $object->price_autogen = GETPOST('usePriceRules') == 'on';
287 
288  for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
289  if (!isset($newprice[$i])) {
290  continue;
291  }
292 
293  $tva_tx_txt = $newvattx[$i];
294 
295  $tva_tx = $tva_tx_txt;
296  $vatratecode = '';
297  $reg = array();
298  if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
299  $vat_src_code = $reg[1];
300  $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate.
301  }
302  $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot
303 
304  $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
305  $localtax1 = $newlocaltax1_tx[$i];
306  $localtax1_type = $newlocaltax1_type[$i];
307  $localtax2 = $newlocaltax2_tx[$i];
308  $localtax2_type = $newlocaltax2_type[$i];
309  if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
310  // We look into database using code
311  $vatratecode = $reg[1];
312  // Get record from code
313  $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
314  $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
315  $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
316  $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
317  $sql .= " AND t.code ='".$db->escape($vatratecode)."'";
318  $resql = $db->query($sql);
319  if ($resql) {
320  $obj = $db->fetch_object($resql);
321  if ($obj) {
322  $npr = $obj->recuperableonly;
323  $localtax1 = $obj->localtax1;
324  $localtax2 = $obj->localtax2;
325  $localtax1_type = $obj->localtax1_type;
326  $localtax2_type = $obj->localtax2_type;
327  }
328 
329  // If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
330  if (in_array($mysoc->country_code, array('ES'))) {
331  $localtax1 = get_localtax($tva_tx, 1);
332  $localtax2 = get_localtax($tva_tx, 2);
333  }
334  }
335  } else {
336  // Get record with empty code
337  $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
338  $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
339  $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
340  $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
341  $sql .= " AND t.code = ''";
342  $resql = $db->query($sql);
343  if ($resql) {
344  $obj = $db->fetch_object($resql);
345  if ($obj) {
346  $npr = $obj->recuperableonly;
347  $localtax1 = $obj->localtax1;
348  $localtax2 = $obj->localtax2;
349  $localtax1_type = $obj->localtax1_type;
350  $localtax2_type = $obj->localtax2_type;
351  }
352  }
353  }
354 
355  $pricestoupdate[$i] = array(
356  'price' => price2num($newprice[$i], '', 2),
357  'price_min' => price2num($newprice_min[$i], '', 2),
358  'price_base_type' => $newpricebase[$i],
359  'default_vat_code' => $vatratecode,
360  'vat_tx' => $tva_tx, // default_vat_code should be used in priority in a future
361  'npr' => $npr, // default_vat_code should be used in priority in a future
362  'localtaxes_array' => array('0'=>$localtax1_type, '1'=>$localtax1, '2'=>$localtax2_type, '3'=>$localtax2) // default_vat_code should be used in priority in a future
363  );
364 
365  //If autogeneration is enabled, then we only set the first level
366  if ($object->price_autogen) {
367  break;
368  }
369  }
370  } elseif (!$error) {
371  $newprice = price2num(GETPOST('price', 'alpha'), '', 2);
372  $newprice_min = price2num(GETPOST('price_min', 'alpha'), '', 2);
373  $newpricebase = GETPOST('price_base_type', 'alpha');
374  $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
375 
376  $tva_tx = $tva_tx_txt;
377  $vatratecode = '';
378  $reg = array();
379  if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
380  $vat_src_code = $reg[1];
381  $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate.
382  }
383  $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot
384 
385  $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
386  $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0';
387  // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
388  if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
389  // We look into database using code
390  $vatratecode = $reg[1];
391  // Get record from code
392  $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
393  $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
394  $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
395  $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
396  $sql .= " AND t.code ='".$db->escape($vatratecode)."'";
397  $resql = $db->query($sql);
398  if ($resql) {
399  $obj = $db->fetch_object($resql);
400  if ($obj) {
401  $npr = $obj->recuperableonly;
402  $localtax1 = $obj->localtax1;
403  $localtax2 = $obj->localtax2;
404  $localtax1_type = $obj->localtax1_type;
405  $localtax2_type = $obj->localtax2_type;
406  }
407 
408  // If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
409  if (in_array($mysoc->country_code, array('ES'))) {
410  $localtax1 = get_localtax($tva_tx, 1);
411  $localtax2 = get_localtax($tva_tx, 2);
412  }
413  }
414  } else {
415  // Get record with empty code
416  $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
417  $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
418  $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
419  $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
420  $sql .= " AND t.code = ''";
421  $resql = $db->query($sql);
422  if ($resql) {
423  $obj = $db->fetch_object($resql);
424  if ($obj) {
425  $npr = $obj->recuperableonly;
426  $localtax1 = $obj->localtax1;
427  $localtax2 = $obj->localtax2;
428  $localtax1_type = $obj->localtax1_type;
429  $localtax2_type = $obj->localtax2_type;
430  }
431  }
432  }
433 
434  $pricestoupdate[0] = array(
435  'price' => $newprice,
436  'price_min' => $newprice_min,
437  'price_base_type' => $newpricebase,
438  'default_vat_code' => $vatratecode,
439  'vat_tx' => $tva_tx, // default_vat_code should be used in priority in a future
440  'npr' => $npr, // default_vat_code should be used in priority in a future
441  'localtaxes_array' => array('0'=>$localtax1_type, '1'=>$localtax1, '2'=>$localtax2_type, '3'=>$localtax2) // default_vat_code should be used in priority in a future
442  );
443  }
444 
445  if (!$error) {
446  $db->begin();
447 
448  foreach ($pricestoupdate as $key => $val) {
449  $newprice = $val['price'];
450 
451  if ($val['price'] < $val['price_min'] && !empty($object->fk_price_expression)) {
452  $newprice = $val['price_min']; //Set price same as min, the user will not see the
453  }
454 
455  $newprice = price2num($newprice, 'MU');
456  $newprice_min = price2num($val['price_min'], 'MU');
457  $newvattx = price2num($val['vat_tx']);
458 
459  if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE) && $newprice_min < $maxpricesupplier) {
460  setEventMessages($langs->trans("MinimumPriceLimit", price($maxpricesupplier, 0, '', 1, - 1, - 1, 'auto')), null, 'errors');
461  $error++;
462  break;
463  }
464 
465  if ($object->multiprices[$key] != $newprice || $object->multiprices_min[$key] != $newprice_min || $object->multiprices_base_type[$key] != $val['price_base_type'] || $object->multiprices_tva_tx[$key] != $newvattx) {
466  $res = $object->updatePrice($newprice, $val['price_base_type'], $user, $val['vat_tx'], $newprice_min, $key, $val['npr'], $psq, 0, $val['localtaxes_array'], $val['default_vat_code']);
467  } else {
468  $res = 0;
469  }
470 
471  if ($res < 0) {
472  $error++;
473  setEventMessages($object->error, $object->errors, 'errors');
474  break;
475  }
476  }
477  }
478 
479  if (!$error && $object->update($object->id, $user) < 0) {
480  $error++;
481  setEventMessages($object->error, $object->errors, 'errors');
482  }
483 
484  if (empty($error)) {
485  $action = '';
486  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
487  $db->commit();
488  } else {
489  $action = 'edit_price';
490  $db->rollback();
491  }
492  }
493 
494 
495  if ($action == 'delete' && $user->rights->produit->supprimer) {
496  $result = $object->log_price_delete($user, GETPOST('lineid', 'int'));
497  if ($result < 0) {
498  setEventMessages($object->error, $object->errors, 'errors');
499  }
500  }
501 
502  // Set Price by quantity
503  if ($action == 'activate_price_by_qty') {
504  // Activating product price by quantity add a new price line with price_by_qty set to 1
505  $level = GETPOST('level', 'int');
506  $ret = $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1);
507 
508  if ($ret < 0) {
509  setEventMessages($object->error, $object->errors, 'errors');
510  }
511  }
512  // Unset Price by quantity
513  if ($action == 'disable_price_by_qty') {
514  // Disabling product price by quantity add a new price line with price_by_qty set to 0
515  $level = GETPOST('level', 'int');
516  $ret = $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 0);
517 
518  if ($ret < 0) {
519  setEventMessages($object->error, $object->errors, 'errors');
520  }
521  }
522 
523  if ($action == 'edit_price_by_qty') { // Edition d'un prix par quantité
524  $rowid = GETPOST('rowid', 'int');
525  }
526 
527  // Add or update price by quantity
528  if ($action == 'update_price_by_qty') {
529  // Récupération des variables
530  $rowid = GETPOST('rowid', 'int');
531  $priceid = GETPOST('priceid', 'int');
532  $newprice = price2num(GETPOST("price"), 'MU', 2);
533  // $newminprice=price2num(GETPOST("price_min"),'MU'); // TODO : Add min price management
534  $quantity = price2num(GETPOST('quantity'), 'MS', 2);
535  $remise_percent = price2num(GETPOST('remise_percent'), '', 2);
536  $remise = 0; // TODO : allow discount by amount when available on documents
537 
538  if (empty($quantity)) {
539  $error++;
540  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Qty")), null, 'errors');
541  }
542  if (empty($newprice)) {
543  $error++;
544  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Price")), null, 'errors');
545  }
546  if (!$error) {
547  // Calcul du prix HT et du prix unitaire
548  if ($object->price_base_type == 'TTC') {
549  $price = price2num($newprice) / (1 + ($object->tva_tx / 100));
550  }
551 
552  $price = price2num($newprice, 'MU');
553  $unitPrice = price2num($price / $quantity, 'MU');
554 
555  // Ajout / mise à jour
556  if ($rowid > 0) {
557  $sql = "UPDATE ".MAIN_DB_PREFIX."product_price_by_qty SET";
558  $sql .= " price=".((float) $price)."',";
559  $sql .= " unitprice=".((float) $unitPrice).",";
560  $sql .= " quantity=".((float) $quantity).",";
561  $sql .= " remise_percent=".((float) $remise_percent).",";
562  $sql .= " remise=".((float) $remise);
563  $sql .= " WHERE rowid = ".((int) $rowid);
564 
565  $result = $db->query($sql);
566  if (!$result) {
567  dol_print_error($db);
568  }
569  } else {
570  $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values (";
571  $sql .= ((int) $priceid).','.((float) $price).','.((float) $unitPrice).','.((float) $quantity).','.((float) $remise_percent).','.((float) $remise).')';
572 
573  $result = $db->query($sql);
574  if (!$result) {
575  if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
576  setEventMessages($langs->trans("DuplicateRecord"), null, 'errors');
577  } else {
578  dol_print_error($db);
579  }
580  }
581  }
582  }
583  }
584 
585  if ($action == 'delete_price_by_qty') {
586  $rowid = GETPOST('rowid', 'int');
587  if (!empty($rowid)) {
588  $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty";
589  $sql .= " WHERE rowid = ".((int) $rowid);
590 
591  $result = $db->query($sql);
592  } else {
593  setEventMessages(('delete_price_by_qty'.$langs->transnoentities('MissingIds')), null, 'errors');
594  }
595  }
596 
597  if ($action == 'delete_all_price_by_qty') {
598  $priceid = GETPOST('priceid', 'int');
599  if (!empty($rowid)) {
600  $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty";
601  $sql .= " WHERE fk_product_price = ".((int) $priceid);
602 
603  $result = $db->query($sql);
604  } else {
605  setEventMessages(('delete_price_by_qty'.$langs->transnoentities('MissingIds')), null, 'errors');
606  }
607  }
608 
614  if ($action == 'add_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) {
615  $maxpricesupplier = $object->min_recommended_price();
616 
617  $update_child_soc = GETPOST('updatechildprice', 'int');
618 
619  // add price by customer
620  $prodcustprice->fk_soc = GETPOST('socid', 'int');
621  $prodcustprice->ref_customer = GETPOST('ref_customer', 'alpha');
622  $prodcustprice->fk_product = $object->id;
623  $prodcustprice->price = price2num(GETPOST("price"), 'MU');
624  $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU');
625  $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha');
626 
627  $tva_tx_txt = GETPOST("tva_tx", 'alpha');
628 
629  $tva_tx = $tva_tx_txt;
630  $vatratecode = '';
631  if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
632  $vat_src_code = $reg[1];
633  $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate.
634  }
635  $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot
636 
637  $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
638  $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0';
639  // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
640  if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
641  // We look into database using code
642  $vatratecode = $reg[1];
643  // Get record from code
644  $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
645  $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
646  $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
647  $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
648  $sql .= " AND t.code ='".$db->escape($vatratecode)."'";
649  $resql = $db->query($sql);
650  if ($resql) {
651  $obj = $db->fetch_object($resql);
652  if ($obj) {
653  $npr = $obj->recuperableonly;
654  $localtax1 = $obj->localtax1;
655  $localtax2 = $obj->localtax2;
656  $localtax1_type = $obj->localtax1_type;
657  $localtax2_type = $obj->localtax2_type;
658  }
659 
660  // If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
661  if (in_array($mysoc->country_code, array('ES'))) {
662  $localtax1 = get_localtax($tva_tx, 1);
663  $localtax2 = get_localtax($tva_tx, 2);
664  }
665  }
666  } else {
667  // Get record with empty code
668  $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
669  $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
670  $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
671  $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
672  $sql .= " AND t.code = ''";
673  $resql = $db->query($sql);
674  if ($resql) {
675  $obj = $db->fetch_object($resql);
676  if ($obj) {
677  $npr = $obj->recuperableonly;
678  $localtax1 = $obj->localtax1;
679  $localtax2 = $obj->localtax2;
680  $localtax1_type = $obj->localtax1_type;
681  $localtax2_type = $obj->localtax2_type;
682  }
683  }
684  }
685 
686  $prodcustprice->default_vat_code = $vatratecode;
687  $prodcustprice->tva_tx = $tva_tx;
688  $prodcustprice->recuperableonly = $npr;
689  $prodcustprice->localtax1_tx = $localtax1;
690  $prodcustprice->localtax2_tx = $localtax2;
691  $prodcustprice->localtax1_type = $localtax1_type;
692  $prodcustprice->localtax2_type = $localtax2_type;
693 
694  if (!($prodcustprice->fk_soc > 0)) {
695  $langs->load("errors");
696  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty")), null, 'errors');
697  $error++;
698  $action = 'add_customer_price';
699  }
700  if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE) && $prodcustprice->price_min < $maxpricesupplier) {
701  $langs->load("errors");
702  setEventMessages($langs->trans("MinimumPriceLimit", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')), null, 'errors');
703  $error++;
704  $action = 'add_customer_price';
705  }
706 
707  if (!$error) {
708  $result = $prodcustprice->create($user, 0, $update_child_soc);
709 
710  if ($result < 0) {
711  setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
712  } else {
713  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
714  }
715 
716  $action = '';
717  }
718  }
719 
720  if ($action == 'delete_customer_price' && ($user->rights->produit->supprimer || $user->rights->service->supprimer)) {
721  // Delete price by customer
722  $prodcustprice->id = GETPOST('lineid', 'int');
723  $result = $prodcustprice->delete($user);
724 
725  if ($result < 0) {
726  setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
727  } else {
728  setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
729  }
730  $action = '';
731  }
732 
733  if ($action == 'update_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) {
734  $maxpricesupplier = $object->min_recommended_price();
735 
736  $update_child_soc = GETPOST('updatechildprice', 'int');
737 
738  $prodcustprice->fetch(GETPOST('lineid', 'int'));
739 
740  // update price by customer
741  $prodcustprice->ref_customer = GETPOST('ref_customer', 'alpha');
742  $prodcustprice->price = price2num(GETPOST("price"), 'MU');
743  $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU');
744  $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha');
745 
746  $tva_tx_txt = GETPOST("tva_tx");
747 
748  $tva_tx = $tva_tx_txt;
749  $vatratecode = '';
750  if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
751  $vat_src_code = $reg[1];
752  $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate.
753  }
754  $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot
755 
756  $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
757  $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0';
758  // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
759  if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
760  // We look into database using code
761  $vatratecode = $reg[1];
762  // Get record from code
763  $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
764  $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
765  $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
766  $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
767  $sql .= " AND t.code ='".$db->escape($vatratecode)."'";
768  $resql = $db->query($sql);
769  if ($resql) {
770  $obj = $db->fetch_object($resql);
771  if ($obj) {
772  $npr = $obj->recuperableonly;
773  $localtax1 = $obj->localtax1;
774  $localtax2 = $obj->localtax2;
775  $localtax1_type = $obj->localtax1_type;
776  $localtax2_type = $obj->localtax2_type;
777  }
778 
779  // If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
780  if (in_array($mysoc->country_code, array('ES'))) {
781  $localtax1 = get_localtax($tva_tx, 1);
782  $localtax2 = get_localtax($tva_tx, 2);
783  }
784  }
785  } else {
786  // Get record with empty code
787  $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
788  $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
789  $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
790  $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
791  $sql .= " AND t.code = ''";
792  $resql = $db->query($sql);
793  if ($resql) {
794  $obj = $db->fetch_object($resql);
795  if ($obj) {
796  $npr = $obj->recuperableonly;
797  $localtax1 = $obj->localtax1;
798  $localtax2 = $obj->localtax2;
799  $localtax1_type = $obj->localtax1_type;
800  $localtax2_type = $obj->localtax2_type;
801  }
802  }
803  }
804 
805  $prodcustprice->default_vat_code = $vatratecode;
806  $prodcustprice->tva_tx = $tva_tx;
807  $prodcustprice->recuperableonly = $npr;
808  $prodcustprice->localtax1_tx = $localtax1;
809  $prodcustprice->localtax2_tx = $localtax2;
810  $prodcustprice->localtax1_type = $localtax1_type;
811  $prodcustprice->localtax2_type = $localtax2_type;
812 
813  if ($prodcustprice->price_min < $maxpricesupplier && !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
814  setEventMessages($langs->trans("MinimumPriceLimit", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')), null, 'errors');
815  $error++;
816  $action = 'update_customer_price';
817  }
818 
819  if (!$error) {
820  $result = $prodcustprice->update($user, 0, $update_child_soc);
821 
822  if ($result < 0) {
823  setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
824  } else {
825  setEventMessages($langs->trans("Save"), null, 'mesgs');
826  }
827 
828  $action = '';
829  }
830  }
831 }
832 
833 
834 /*
835  * View
836  */
837 
838 $form = new Form($db);
839 
840 if (!empty($id) || !empty($ref)) {
841  // fetch updated prices
842  $object->fetch($id, $ref);
843 }
844 
845 $title = $langs->trans('ProductServiceCard');
846 $helpurl = '';
847 $shortlabel = dol_trunc($object->label, 16);
848 if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
849  $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('SellingPrices');
850  $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
851 }
852 if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
853  $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('SellingPrices');
854  $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
855 }
856 
857 llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'classforhorizontalscrolloftabs');
858 
859 $head = product_prepare_head($object);
860 $titre = $langs->trans("CardProduct".$object->type);
861 $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
862 
863 print dol_get_fiche_head($head, 'price', $titre, -1, $picto);
864 
865 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
866 $object->next_prev_filter = " fk_product_type = ".$object->type;
867 
868 $shownav = 1;
869 if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
870  $shownav = 0;
871 }
872 
873 dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
874 
875 
876 print '<div class="fichecenter">';
877 
878 print '<div class="underbanner clearboth"></div>';
879 print '<table class="border tableforfield" width="100%">';
880 
881 // Price per customer segment/level
882 if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
883  // Price and min price are variable (depends on level of company).
884  if (!empty($socid)) {
885  $soc = new Societe($db);
886  $soc->id = $socid;
887  $soc->fetch($socid);
888 
889  // Type
890  if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) {
891  $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
892  print '<tr><td class="">';
893  print (empty($conf->global->PRODUCT_DENY_CHANGE_PRODUCT_TYPE)) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, 0, $typeformat) : $langs->trans('Type');
894  print '</td><td>';
895  print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, 0, $typeformat);
896  print '</td></tr>';
897  }
898 
899  // Selling price
900  print '<tr><td class="titlefieldcreate">';
901  print $langs->trans("SellingPrice");
902  print '</td>';
903  print '<td colspan="2">';
904  if ($object->multiprices_base_type[$soc->price_level] == 'TTC') {
905  print '<span class="amount">'.price($object->multiprices_ttc[$soc->price_level]).'</span>';
906  } else {
907  print '<span class="amount">'.price($object->multiprices[$soc->price_level]).'</span>';
908  }
909  if ($object->multiprices_base_type[$soc->price_level]) {
910  print ' '.$langs->trans($object->multiprices_base_type[$soc->price_level]);
911  } else {
912  print ' '.$langs->trans($object->price_base_type);
913  }
914  print '</td></tr>';
915 
916  // Price min
917  print '<tr><td>'.$langs->trans("MinPrice").'</td><td colspan="2">';
918  if ($object->multiprices_base_type[$soc->price_level] == 'TTC') {
919  print price($object->multiprices_min_ttc[$soc->price_level]).' '.$langs->trans($object->multiprices_base_type[$soc->price_level]);
920  } else {
921  print price($object->multiprices_min[$soc->price_level]).' '.$langs->trans(empty($object->multiprices_base_type[$soc->price_level]) ? 'HT' : $object->multiprices_base_type[$soc->price_level]);
922  }
923  print '</td></tr>';
924 
925  if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { // using this option is a bug. kept for backward compatibility
926  // TVA
927  print '<tr><td>'.$langs->trans("DefaultTaxRate").'</td><td colspan="2">';
928 
929  $positiverates = '';
930  if (price2num($object->multiprices_tva_tx[$soc->price_level])) {
931  $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_tva_tx[$soc->price_level]);
932  }
933  if (price2num($object->multiprices_localtax1_type[$soc->price_level])) {
934  $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_localtax1_tx[$soc->price_level]);
935  }
936  if (price2num($object->multiprices_localtax2_type[$soc->price_level])) {
937  $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_localtax2_tx[$soc->price_level]);
938  }
939  if (empty($positiverates)) {
940  $positiverates = '0';
941  }
942  echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr);
943  //print vatrate($object->multiprices_tva_tx[$soc->price_level], true);
944  print '</td></tr>';
945  } else {
946  // TVA
947  print '<tr><td>'.$langs->trans("DefaultTaxRate").'</td><td>';
948 
949  $positiverates = '';
950  if (price2num($object->tva_tx)) {
951  $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx);
952  }
953  if (price2num($object->localtax1_type)) {
954  $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx);
955  }
956  if (price2num($object->localtax2_type)) {
957  $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx);
958  }
959  if (empty($positiverates)) {
960  $positiverates = '0';
961  }
962  echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr);
963  /*
964  if ($object->default_vat_code)
965  {
966  print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')';
967  }
968  else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true);*/
969  print '</td></tr>';
970  }
971  } else {
972  if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { // using this option is a bug. kept for backward compatibility
973  // Type
974  if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) {
975  $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
976  print '<tr><td class="">';
977  print (empty($conf->global->PRODUCT_DENY_CHANGE_PRODUCT_TYPE)) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, 0, $typeformat) : $langs->trans('Type');
978  print '</td><td>';
979  print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, 0, $typeformat);
980  print '</td></tr>';
981  }
982 
983  // We show only vat for level 1
984  print '<tr><td class="titlefieldcreate">'.$langs->trans("DefaultTaxRate").'</td>';
985  print '<td colspan="2">'.vatrate($object->multiprices_tva_tx[1], true).'</td>';
986  print '</tr>';
987  } else {
988  // Type
989  if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) {
990  $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
991  print '<tr><td class="">';
992  print (empty($conf->global->PRODUCT_DENY_CHANGE_PRODUCT_TYPE)) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, 0, $typeformat) : $langs->trans('Type');
993  print '</td><td>';
994  print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, 0, $typeformat);
995  print '</td></tr>';
996  }
997 
998  // TVA
999  print '<!-- Default VAT Rate -->';
1000  print '<tr><td class="titlefieldcreate">'.$langs->trans("DefaultTaxRate").'</td><td>';
1001 
1002  $positiverates = '';
1003  if (price2num($object->tva_tx)) {
1004  $positiverates .= ($positiverates ? '<span class="opacitymedium">/</span>' : '').price2num($object->tva_tx);
1005  }
1006  if (price2num($object->localtax1_type)) {
1007  $positiverates .= ($positiverates ? '<span class="opacitymedium">/</span>' : '').price2num($object->localtax1_tx);
1008  }
1009  if (price2num($object->localtax2_type)) {
1010  $positiverates .= ($positiverates ? '<span class="opacitymedium">/</span>' : '').price2num($object->localtax2_tx);
1011  }
1012  if (empty($positiverates)) {
1013  $positiverates = '0';
1014  }
1015  print vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), true, $object->tva_npr, 1);
1016  /*
1017  if ($object->default_vat_code)
1018  {
1019  print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')';
1020  }
1021  else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true);*/
1022  print '</td></tr>';
1023  }
1024  print '</table>';
1025 
1026  print '<br>';
1027 
1028  print '<table class="noborder tableforfield" width="100%">';
1029  print '<tr class="liste_titre"><td>';
1030  print $langs->trans("PriceLevel");
1031  if ($user->admin) {
1032  print ' <a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editlabelsellingprice&token='.newToken().'&pricelevel='.$i.'&id='.$object->id.'">'.img_edit($langs->trans('EditSellingPriceLabel'), 0).'</a>';
1033  }
1034  print '</td>';
1035  print '<td style="text-align: right">'.$langs->trans("SellingPrice").'</td>';
1036  print '<td style="text-align: right">'.$langs->trans("MinPrice").'</td>';
1037  print '</tr>';
1038 
1039  for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
1040  print '<tr class="oddeven">';
1041 
1042  // Label of price
1043  print '<td>';
1044  $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$i;
1045  if (preg_match('/editlabelsellingprice/', $action)) {
1046  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
1047  print '<input type="hidden" name="token" value="'.newToken().'">';
1048  print '<input type="hidden" name="action" value="setlabelsellingprice">';
1049  print '<input type="hidden" name="pricelevel" value="'.$i.'">';
1050  print $langs->trans("SellingPrice").' '.$i.' - ';
1051  print '<input class="maxwidthonsmartphone" type="text" name="labelsellingprice" value="'.$conf->global->$keyforlabel.'">';
1052  print '&nbsp;<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Modify").'">';
1053  print '</form>';
1054  } else {
1055  print $langs->trans("SellingPrice").' '.$i;
1056  if (!empty($conf->global->$keyforlabel)) {
1057  print ' - '.$langs->trans($conf->global->$keyforlabel);
1058  }
1059  }
1060  print '</td>';
1061 
1062  if ($object->multiprices_base_type [$i] == 'TTC') {
1063  print '<td class="right"><span class="amount">'.price($object->multiprices_ttc[$i]);
1064  } else {
1065  print '<td class="right"><span class="amount">'.price($object->multiprices[$i]);
1066  }
1067 
1068  if ($object->multiprices_base_type[$i]) {
1069  print ' '.$langs->trans($object->multiprices_base_type [$i]).'</span></td>';
1070  } else {
1071  print ' '.$langs->trans($object->price_base_type).'</span></td>';
1072  }
1073 
1074  // Prix min
1075  print '<td style="text-align: right">';
1076  if (empty($object->multiprices_base_type[$i])) {
1077  $object->multiprices_base_type[$i] = "HT";
1078  }
1079  if ($object->multiprices_base_type[$i] == 'TTC') {
1080  print price($object->multiprices_min_ttc[$i]).' '.$langs->trans($object->multiprices_base_type[$i]);
1081  } else {
1082  print price($object->multiprices_min[$i]).' '.$langs->trans($object->multiprices_base_type[$i]);
1083  }
1084  print '</td></tr>';
1085 
1086  // Price by quantity
1087  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { // TODO Fix the form included into a tr instead of a td
1088  print '<tr><td>'.$langs->trans("PriceByQuantity").' '.$i;
1089  if (!empty($conf->global->$keyforlabel)) {
1090  print ' - '.$langs->trans($conf->global->$keyforlabel);
1091  }
1092  print '</td><td colspan="2">';
1093 
1094  if ($object->prices_by_qty[$i] == 1) {
1095  print '<table width="50%" class="border" summary="List of quantities">';
1096 
1097  print '<tr class="liste_titre">';
1098  print '<td>'.$langs->trans("PriceByQuantityRange").' '.$i.'</td>';
1099  print '<td class="right">'.$langs->trans("HT").'</td>';
1100  print '<td class="right">'.$langs->trans("UnitPrice").'</td>';
1101  print '<td class="right">'.$langs->trans("Discount").'</td>';
1102  print '<td>&nbsp;</td>';
1103  print '</tr>';
1104  foreach ($object->prices_by_qty_list[$i] as $ii => $prices) {
1105  if ($action == 'edit_price_by_qty' && $rowid == $prices['rowid'] && ($user->rights->produit->creer || $user->rights->service->creer)) {
1106  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
1107  print '<input type="hidden" name="token" value="'.newToken().'">';
1108  print '<input type="hidden" name="action" value="update_price_by_qty">';
1109  print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].'">';
1110  print '<input type="hidden" value="'.$prices['rowid'].'" name="rowid">';
1111  print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
1112  print '<td><input size="5" type="text" value="'.$prices['quantity'].'" name="quantity"></td>';
1113  print '<td class="right" colspan="2"><input size="10" type="text" value="'.price2num($prices['price'], 'MU').'" name="price">&nbsp;'.$object->price_base_type.'</td>';
1114  print '<td class="right nowraponall"><input size="5" type="text" value="'.$prices['remise_percent'].'" name="remise_percent"> %</td>';
1115  print '<td class="center"><input type="submit" value="'.$langs->trans("Modify").'" class="button"></td>';
1116  print '</tr>';
1117  print '</form>';
1118  } else {
1119  print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
1120  print '<td>'.$prices['quantity'].'</td>';
1121  print '<td class="right">'.price($prices['price']).'</td>';
1122  print '<td class="right">'.price($prices['unitprice']).'</td>';
1123  print '<td class="right">'.price($prices['remise_percent']).' %</td>';
1124  print '<td class="center">';
1125  if (($user->rights->produit->creer || $user->rights->service->creer)) {
1126  print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit_price_by_qty&token='.newToken().'&rowid='.$prices["rowid"].'">';
1127  print img_edit().'</a>';
1128  print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete_price_by_qty&token='.newToken().'&rowid='.$prices["rowid"].'">';
1129  print img_delete().'</a>';
1130  } else {
1131  print '&nbsp;';
1132  }
1133  print '</td>';
1134  print '</tr>';
1135  }
1136  }
1137  if ($action != 'edit_price_by_qty' && ($user->rights->produit->creer || $user->rights->service->creer)) {
1138  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
1139  print '<input type="hidden" name="token" value="'.newToken().'">';
1140  print '<input type="hidden" name="action" value="update_price_by_qty">';
1141  print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].'">'; // id in product_price
1142  print '<input type="hidden" value="0" name="rowid">'; // id in product_price
1143  print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
1144  print '<td><input size="5" type="text" value="1" name="quantity"></td>';
1145  print '<td class="right" class="nowrap"><input size="10" type="text" value="0" name="price">&nbsp;'.$object->price_base_type.'</td>';
1146  print '<td class="right">&nbsp;</td>';
1147  print '<td class="right" class="nowraponall"><input size="5" type="text" value="0" name="remise_percent"> %</td>';
1148  print '<td class="center"><input type="submit" value="'.$langs->trans("Add").'" class="button"></td>';
1149  print '</tr>';
1150  print '</form>';
1151  }
1152 
1153  print '</table>';
1154  print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable_price_by_qty&level='.$i.'&token='.newToken().'">('.$langs->trans("DisablePriceByQty").')</a>';
1155  } else {
1156  print $langs->trans("No");
1157  print '&nbsp; <a class="marginleftonly marginrightonly" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=activate_price_by_qty&level='.$i.'&token='.newToken().'">('.$langs->trans("Activate").')</a>';
1158  }
1159  print '</td></tr>';
1160  }
1161  }
1162  }
1163 } else {
1164  // TVA
1165  print '<tr><td class="titlefield">'.$langs->trans("DefaultTaxRate").'</td><td>';
1166 
1167  $positiverates = '';
1168  if (price2num($object->tva_tx)) {
1169  $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx);
1170  }
1171  if (price2num($object->localtax1_type)) {
1172  $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx);
1173  }
1174  if (price2num($object->localtax2_type)) {
1175  $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx);
1176  }
1177  if (empty($positiverates)) {
1178  $positiverates = '0';
1179  }
1180  echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr, 0, 1);
1181  /*
1182  if ($object->default_vat_code)
1183  {
1184  print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')';
1185  }
1186  else print vatrate($object->tva_tx, true, $object->tva_npr, true);*/
1187  print '</td></tr>';
1188 
1189  // Price
1190  print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>';
1191  if ($object->price_base_type == 'TTC') {
1192  print price($object->price_ttc).' '.$langs->trans($object->price_base_type);
1193  } else {
1194  print price($object->price).' '.$langs->trans($object->price_base_type);
1195  }
1196  print '</td></tr>';
1197 
1198  // Price minimum
1199  print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
1200  if ($object->price_base_type == 'TTC') {
1201  print price($object->price_min_ttc).' '.$langs->trans($object->price_base_type);
1202  } else {
1203  print price($object->price_min).' '.$langs->trans($object->price_base_type);
1204  }
1205  print '</td></tr>';
1206 
1207  // Price by quantity
1208  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { // TODO Fix the form inside tr instead of td
1209  print '<tr><td>'.$langs->trans("PriceByQuantity");
1210  if ($object->prices_by_qty[0] == 0) {
1211  print '&nbsp; <a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=activate_price_by_qty&level=1&token='.newToken().'">('.$langs->trans("Activate").')';
1212  } else {
1213  print '&nbsp; <a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable_price_by_qty&level=1&token='.newToken().'">('.$langs->trans("DisablePriceByQty").')';
1214  }
1215  print '</td><td>';
1216 
1217  if ($object->prices_by_qty[0] == 1) {
1218  print '<table width="50%" class="border" summary="List of quantities">';
1219  print '<tr class="liste_titre">';
1220  //print '<td>' . $langs->trans("PriceByQuantityRange") . '</td>';
1221  print '<td>'.$langs->trans("Quantity").'</td>';
1222  print '<td class="right">'.$langs->trans("Price").'</td>';
1223  print '<td class="right"></td>';
1224  print '<td class="right">'.$langs->trans("UnitPrice").'</td>';
1225  print '<td class="right">'.$langs->trans("Discount").'</td>';
1226  print '<td>&nbsp;</td>';
1227  print '</tr>';
1228  if ($action != 'edit_price_by_qty') {
1229  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">'; // FIXME a form into a table is not allowed
1230  print '<input type="hidden" name="token" value="'.newToken().'">';
1231  print '<input type="hidden" name="action" value="update_price_by_qty">';
1232  print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].'">'; // id in product_price
1233  print '<input type="hidden" value="0" name="rowid">'; // id in product_price_by_qty
1234 
1235  print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
1236  print '<td><input size="5" type="text" value="1" name="quantity"></td>';
1237  print '<td class="right"><input class="width50 right" type="text" value="0" name="price"></td>';
1238  print '<td>';
1239  //print $object->price_base_type;
1240  print '</td>';
1241  print '<td class="right">&nbsp;</td>';
1242  print '<td class="right nowraponall"><input type="text" class="width50 right" value="0" name="remise_percent"> %</td>';
1243  print '<td class="center"><input type="submit" value="'.$langs->trans("Add").'" class="button"></td>';
1244  print '</tr>';
1245 
1246  print '</form>';
1247  }
1248  foreach ($object->prices_by_qty_list[0] as $ii => $prices) {
1249  if ($action == 'edit_price_by_qty' && $rowid == $prices['rowid'] && ($user->rights->produit->creer || $user->rights->service->creer)) {
1250  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
1251  print '<input type="hidden" name="token" value="'.newToken().'">';
1252  print '<input type="hidden" name="action" value="update_price_by_qty">';
1253  print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].'">'; // id in product_price
1254  print '<input type="hidden" value="'.$prices['rowid'].'" name="rowid">'; // id in product_price_by_qty
1255  print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
1256  print '<td><input size="5" type="text" value="'.$prices['quantity'].'" name="quantity"></td>';
1257  print '<td class="right"><input class="width50 right" type="text" value="'.price2num($prices['price'], 'MU').'" name="price"></td>';
1258  print '<td class="right">';
1259  //print $object->price_base_type;
1260  print $prices['price_base_type'];
1261  print '</td>';
1262  print '<td class="right">&nbsp;</td>';
1263  print '<td class="right nowraponall"><input class="width50 right" type="text" value="'.$prices['remise_percent'].'" name="remise_percent"> %</td>';
1264  print '<td class="center"><input type="submit" value="'.$langs->trans("Modify").'" class="button"></td>';
1265  print '</tr>';
1266  print '</form>';
1267  } else {
1268  print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
1269  print '<td>'.$prices['quantity'].'</td>';
1270  print '<td class="right">'.price($prices['price']).'</td>';
1271  print '<td class="right">';
1272  //print $object->price_base_type;
1273  print $prices['price_base_type'];
1274  print '</td>';
1275  print '<td class="right">'.price($prices['unitprice']).'</td>';
1276  print '<td class="right">'.price($prices['remise_percent']).' %</td>';
1277  print '<td class="center">';
1278  if (($user->rights->produit->creer || $user->rights->service->creer)) {
1279  print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit_price_by_qty&token='.newToken().'&rowid='.$prices["rowid"].'">';
1280  print img_edit().'</a>';
1281  print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete_price_by_qty&token='.newToken().'&rowid='.$prices["rowid"].'">';
1282  print img_delete().'</a>';
1283  } else {
1284  print '&nbsp;';
1285  }
1286  print '</td>';
1287  print '</tr>';
1288  }
1289  }
1290  print '</table>';
1291  } else {
1292  print $langs->trans("No");
1293  }
1294  print '</td></tr>';
1295  }
1296 }
1297 
1298 print "</table>\n";
1299 
1300 print '</div>';
1301 print '<div style="clear:both"></div>';
1302 
1303 
1304 print dol_get_fiche_end();
1305 
1306 
1307 
1308 /*
1309  * Action bar
1310  */
1311 
1312 
1313 if (!$action || $action == 'delete' || $action == 'showlog_customer_price' || $action == 'showlog_default_price' || $action == 'add_customer_price'
1314  || $action == 'activate_price_by_qty' || $action == 'disable_price_by_qty') {
1315  print "\n".'<div class="tabsAction">'."\n";
1316 
1317 
1318  $parameters = array();
1319  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1320  if (empty($reshook)) {
1321  if ($object->isVariant()) {
1322  if ($user->rights->produit->creer || $user->rights->service->creer) {
1323  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag($langs->trans("NoEditVariants")) . '">' . $langs->trans("UpdateDefaultPrice") . '</a></div>';
1324  }
1325  } else {
1326  if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1327  if ($user->rights->produit->creer || $user->rights->service->creer) {
1328  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_price&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("UpdateDefaultPrice") . '</a></div>';
1329  } else {
1330  print '<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">' . $langs->trans("UpdateDefaultPrice") . '</span></div>';
1331  }
1332  }
1333 
1334  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1335  if ($user->rights->produit->creer || $user->rights->service->creer) {
1336  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=add_customer_price&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("AddCustomerPrice") . '</a></div>';
1337  } else {
1338  print '<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">' . $langs->trans("AddCustomerPrice") . '</span></div>';
1339  }
1340  }
1341 
1342  if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1343  if ($user->rights->produit->creer || $user->rights->service->creer) {
1344  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_vat&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("UpdateVAT") . '</a></div>';
1345  } else {
1346  print '<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">' . $langs->trans("UpdateVAT") . '</span></div>';
1347  }
1348 
1349  if ($user->rights->produit->creer || $user->rights->service->creer) {
1350  print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_price&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("UpdateLevelPrices") . '</a></div>';
1351  } else {
1352  print '<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">' . $langs->trans("UpdateLevelPrices") . '</span></div>';
1353  }
1354  }
1355  }
1356  }
1357 
1358  print "\n</div>\n";
1359 }
1360 
1361 
1362 
1363 /*
1364  * Edit price area
1365  */
1366 
1367 if ($action == 'edit_vat' && ($user->rights->produit->creer || $user->rights->service->creer)) {
1368  print load_fiche_titre($langs->trans("UpdateVAT"), '');
1369 
1370  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
1371  print '<input type="hidden" name="token" value="'.newToken().'">';
1372  print '<input type="hidden" name="action" value="update_vat">';
1373  print '<input type="hidden" name="id" value="'.$object->id.'">';
1374 
1375  print dol_get_fiche_head('');
1376 
1377  print '<table class="border centpercent">';
1378 
1379  // VAT
1380  print '<tr><td>'.$langs->trans("DefaultTaxRate").'</td><td>';
1381  print $form->load_tva("tva_tx", $object->default_vat_code ? $object->tva_tx.' ('.$object->default_vat_code.')' : $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, $object->type, false, 1);
1382  print '</td></tr>';
1383 
1384  print '</table>';
1385 
1386  print dol_get_fiche_end();
1387 
1388  print $form->buttonsSaveCancel();
1389 
1390  print '<br></form><br>';
1391 }
1392 
1393 if ($action == 'edit_price' && $object->getRights()->creer) {
1394  print '<br>';
1395  print load_fiche_titre($langs->trans("NewPrice"), '');
1396 
1397  if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1398  print '<!-- Edit price -->'."\n";
1399  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
1400  print '<input type="hidden" name="token" value="'.newToken().'">';
1401  print '<input type="hidden" name="action" value="update_price">';
1402  print '<input type="hidden" name="id" value="'.$object->id.'">';
1403 
1404  print dol_get_fiche_head('');
1405 
1406  print '<div class="div-table-responsive-no-min">';
1407  print '<table class="border centpercent">';
1408 
1409  // VAT
1410  print '<tr><td class="titlefield">'.$langs->trans("DefaultTaxRate").'</td><td>';
1411  print $form->load_tva("tva_tx", $object->default_vat_code ? $object->tva_tx.' ('.$object->default_vat_code.')' : $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, $object->type, false, 1);
1412  print '</td></tr>';
1413 
1414  // Price base
1415  print '<tr><td>';
1416  print $langs->trans('PriceBase');
1417  print '</td>';
1418  print '<td>';
1419  print $form->selectPriceBaseType($object->price_base_type, "price_base_type");
1420  print '</td>';
1421  print '</tr>';
1422 
1423  // Only show price mode and expression selector if module is enabled
1424  if (!empty($conf->dynamicprices->enabled)) {
1425  // Price mode selector
1426  print '<!-- Show price mode of dynamicprices editor -->'."\n";
1427  print '<tr><td>'.$langs->trans("PriceMode").'</td><td>';
1428  print img_picto('', 'dynamicprice', 'class="pictofixedwidth"');
1429  $price_expression = new PriceExpression($db);
1430  $price_expression_list = array(0 => $langs->trans("Numeric").' <span class="opacitymedium">('.$langs->trans("NoDynamicPrice").')</span>'); //Put the numeric mode as first option
1431  foreach ($price_expression->list_price_expression() as $entry) {
1432  $price_expression_list[$entry->id] = $entry->title;
1433  }
1434  $price_expression_preselection = GETPOST('eid') ? GETPOST('eid') : ($object->fk_price_expression ? $object->fk_price_expression : '0');
1435  print $form->selectarray('eid', $price_expression_list, $price_expression_preselection);
1436  print '&nbsp; <a id="expression_editor" class="classlink">'.$langs->trans("PriceExpressionEditor").'</a>';
1437  print '</td></tr>';
1438 
1439  // This code hides the numeric price input if is not selected, loads the editor page if editor button is pressed
1440  ?>
1441 
1442  <script type="text/javascript">
1443  jQuery(document).ready(function() {
1444  jQuery("#expression_editor").click(function() {
1445  window.location = "<?php echo DOL_URL_ROOT ?>/product/dynamic_price/editor.php?id=<?php echo $id ?>&tab=price&eid=" + $("#eid").val();
1446  });
1447  jQuery("#eid").change(on_change);
1448  on_change();
1449  });
1450  function on_change() {
1451  if ($("#eid").val() == 0) {
1452  jQuery("#price_numeric").show();
1453  } else {
1454  jQuery("#price_numeric").hide();
1455  }
1456  }
1457  </script>
1458  <?php
1459  }
1460 
1461  // Price
1462  $product = new Product($db);
1463  $product->fetch($id, $ref, '', 1); //Ignore the math expression when getting the price
1464  print '<tr id="price_numeric"><td>';
1465  $text = $langs->trans('SellingPrice');
1466  print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
1467  print '</td><td>';
1468  if ($object->price_base_type == 'TTC') {
1469  print '<input name="price" size="10" value="'.price($product->price_ttc).'">';
1470  } else {
1471  print '<input name="price" size="10" value="'.price($product->price).'">';
1472  }
1473  print '</td></tr>';
1474 
1475  // Price minimum
1476  print '<tr><td>';
1477  $text = $langs->trans('MinPrice');
1478  print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
1479  print '</td><td>';
1480  if ($object->price_base_type == 'TTC') {
1481  print '<input name="price_min" size="10" value="'.price($object->price_min_ttc).'">';
1482  } else {
1483  print '<input name="price_min" size="10" value="'.price($object->price_min).'">';
1484  }
1485  if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
1486  print ' &nbsp; '.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().'</td>';
1487  }
1488  print '</td>';
1489  print '</tr>';
1490 
1491  $parameters = array();
1492  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1493 
1494  print '</table>';
1495  print '</div>';
1496 
1497  print dol_get_fiche_end();
1498 
1499  print $form->buttonsSaveCancel();
1500 
1501  print '</form>';
1502  } else {
1503  print '<!-- Edit price per level -->'."\n";
1504  ?>
1505  <script>
1506 
1507  var showHidePriceRules = function () {
1508  var otherPrices = $('div.fiche form table tbody tr:not(:first)');
1509  var minPrice1 = $('div.fiche form input[name="price_min[1]"]');
1510 
1511  if (jQuery('input#usePriceRules').prop('checked')) {
1512  otherPrices.hide();
1513  minPrice1.hide();
1514  } else {
1515  otherPrices.show();
1516  minPrice1.show();
1517  }
1518  };
1519 
1520  jQuery(document).ready(function () {
1521  showHidePriceRules();
1522 
1523  jQuery('input#usePriceRules').click(showHidePriceRules);
1524  });
1525  </script>
1526  <?php
1527 
1528  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
1529  print '<input type="hidden" name="token" value="'.newToken().'">';
1530  print '<input type="hidden" name="action" value="update_price">';
1531  print '<input type="hidden" name="id" value="'.$object->id.'">';
1532 
1533  //print dol_get_fiche_head('', '', '', -1);
1534 
1535  if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($conf->global->PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL)) {
1536  print $langs->trans('UseMultipriceRules').' <input type="checkbox" id="usePriceRules" name="usePriceRules" '.($object->price_autogen ? 'checked' : '').'><br><br>';
1537  }
1538 
1539  print '<div class="div-table-responsive-no-min">';
1540  print '<table class="noborder">';
1541  print '<thead><tr class="liste_titre">';
1542 
1543  print '<td>'.$langs->trans("PriceLevel").'</td>';
1544 
1545  if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
1546  print '<td style="text-align: center">'.$langs->trans("DefaultTaxRate").'</td>';
1547  } else {
1548  print '<td></td>';
1549  }
1550 
1551  print '<td class="center">'.$langs->trans("SellingPrice").'</td>';
1552 
1553  print '<td class="center">'.$langs->trans("MinPrice").'</td>';
1554 
1555  if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
1556  print '<td></td>';
1557  }
1558  print '</tr></thead>';
1559 
1560  print '<tbody>';
1561 
1562  for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
1563  print '<tr class="oddeven">';
1564  print '<td>';
1565  $text = $langs->trans('SellingPrice').' '.$i;
1566  print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
1567  print '</td>';
1568 
1569  // VAT
1570  if (empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
1571  print '<td>';
1572  print '<input type="hidden" name="tva_tx['.$i.']" value="'.($object->default_vat_code ? $object->tva_tx.' ('.$object->default_vat_code.')' : $object->tva_tx).'">';
1573  print '<input type="hidden" name="tva_npr['.$i.']" value="'.$object->tva_npr.'">';
1574  print '<input type="hidden" name="localtax1_tx['.$i.']" value="'.$object->localtax1_tx.'">';
1575  print '<input type="hidden" name="localtax1_type['.$i.']" value="'.$object->localtax1_type.'">';
1576  print '<input type="hidden" name="localtax2_tx['.$i.']" value="'.$object->localtax2_tx.'">';
1577  print '<input type="hidden" name="localtax2_type['.$i.']" value="'.$object->localtax2_type.'">';
1578  print '</td>';
1579  } else {
1580  // This option is kept for backward compatibility but has no sense
1581  print '<td style="text-align: center">';
1582  print $form->load_tva("tva_tx[".$i.']', $object->multiprices_tva_tx[$i], $mysoc, '', $object->id, false, $object->type, false, 1);
1583  print '</td>';
1584  }
1585 
1586  // Selling price
1587  print '<td style="text-align: center">';
1588  if ($object->multiprices_base_type [$i] == 'TTC') {
1589  print '<input name="price['.$i.']" size="10" value="'.price($object->multiprices_ttc [$i]).'">';
1590  } else {
1591  print '<input name="price['.$i.']" size="10" value="'.price($object->multiprices [$i]).'">';
1592  }
1593  print '&nbsp;'.$form->selectPriceBaseType($object->multiprices_base_type [$i], "multiprices_base_type[".$i."]");
1594  print '</td>';
1595 
1596  // Min price
1597  print '<td style="text-align: center">';
1598  if ($object->multiprices_base_type [$i] == 'TTC') {
1599  print '<input name="price_min['.$i.']" size="10" value="'.price($object->multiprices_min_ttc [$i]).'">';
1600  } else {
1601  print '<input name="price_min['.$i.']" size="10" value="'.price($object->multiprices_min [$i]).'">';
1602  }
1603  if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
1604  print '<td class="left">'.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().'</td>';
1605  }
1606  print '</td>';
1607 
1608  print '</tr>';
1609  }
1610 
1611  print '</tbody>';
1612 
1613  print '</table>';
1614  print '</div>';
1615 
1616  //print dol_get_fiche_end();
1617 
1618  print $form->buttonsSaveCancel();
1619 
1620  print '</form>';
1621  }
1622 }
1623 
1624 
1625 // List of price changes - log historic (ordered by descending date)
1626 
1627 if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_default_price') && !in_array($action, array('edit_price', 'edit_vat'))) {
1628  $sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.default_vat_code, p.recuperableonly, p.localtax1_tx, p.localtax1_type, p.localtax2_tx, p.localtax2_type,";
1629  $sql .= " p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty,";
1630  $sql .= " p.date_price as dp, p.fk_price_expression, u.rowid as user_id, u.login";
1631  $sql .= " FROM ".MAIN_DB_PREFIX."product_price as p,";
1632  $sql .= " ".MAIN_DB_PREFIX."user as u";
1633  $sql .= " WHERE fk_product = ".((int) $object->id);
1634  $sql .= " AND p.entity IN (".getEntity('productprice').")";
1635  $sql .= " AND p.fk_user_author = u.rowid";
1636  if (!empty($socid) && !empty($conf->global->PRODUIT_MULTIPRICES)) {
1637  $sql .= " AND p.price_level = ".((int) $soc->price_level);
1638  }
1639  $sql .= " ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC";
1640  // $sql .= $db->plimit();
1641  //print $sql;
1642 
1643  $result = $db->query($sql);
1644  if ($result) {
1645  print '<div class="divlogofpreviouscustomerprice">';
1646 
1647  $num = $db->num_rows($result);
1648 
1649  if (!$num) {
1650  $db->free($result);
1651 
1652  // Il doit au moins y avoir la ligne de prix initial.
1653  // On l'ajoute donc pour remettre a niveau (pb vieilles versions)
1654  // We emulate the change of the price from interface with the same value than the one into table llx_product
1655  if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
1656  $ret = $object->updatePrice(($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_ttc[1] : $object->multiprices[1]), $object->multiprices_base_type[1], $user, (empty($object->multiprices_tva_tx[1]) ? 0 : $object->multiprices_tva_tx[1]), ($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_min_ttc[1] : $object->multiprices_min[1]), 1);
1657  } else {
1658  $ret = $object->updatePrice(($object->price_base_type == 'TTC' ? $object->price_ttc : $object->price), $object->price_base_type, $user, $object->tva_tx, ($object->price_base_type == 'TTC' ? $object->price_min_ttc : $object->price_min));
1659  }
1660 
1661  if ($ret < 0) {
1662  dol_print_error($db, $object->error, $object->errors);
1663  } else {
1664  $result = $db->query($sql);
1665  $num = $db->num_rows($result);
1666  }
1667  }
1668 
1669  if ($num > 0) {
1670  // Default prices or
1671  // Log of previous customer prices
1672  $backbutton = '<a class="justalink" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">'.$langs->trans("Back").'</a>';
1673 
1674  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1675  print_barre_liste($langs->trans("DefaultPriceLog"), 0, $_SERVER["PHP_SELF"], '', '', '', $backbutton, 0, $num, 'title_accountancy.png');
1676  } else {
1677  print_barre_liste($langs->trans("PriceByCustomerLog"), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, $num, 'title_accountancy.png');
1678  }
1679 
1680  print '<!-- List of log prices -->'."\n";
1681  print '<div class="div-table-responsive">'."\n";
1682  print '<table class="liste centpercent">'."\n";
1683 
1684  print '<tr class="liste_titre">';
1685  print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
1686 
1687  if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1688  print '<td class="center">'.$langs->trans("PriceLevel").'</td>';
1689  }
1690  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1691  print '<td class="center">'.$langs->trans("Type").'</td>';
1692  }
1693 
1694  print '<td class="center">'.$langs->trans("PriceBase").'</td>';
1695  if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1696  print '<td class="right">'.$langs->trans("DefaultTaxRate").'</td>';
1697  }
1698  print '<td class="right">'.$langs->trans("HT").'</td>';
1699  print '<td class="right">'.$langs->trans("TTC").'</td>';
1700  if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
1701  print '<td class="right">'.$langs->trans("INCT").'</td>';
1702  }
1703  if (!empty($conf->dynamicprices->enabled)) {
1704  print '<td class="right">'.$langs->trans("PriceExpressionSelected").'</td>';
1705  }
1706  print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
1707  print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
1708  print '<td class="right">'.$langs->trans("ChangedBy").'</td>';
1709  if ($user->rights->produit->supprimer) {
1710  print '<td class="right">&nbsp;</td>';
1711  }
1712  print '</tr>';
1713 
1714  $notfirstlineforlevel = array();
1715 
1716  $i = 0;
1717  while ($i < $num) {
1718  $objp = $db->fetch_object($result);
1719 
1720  print '<tr class="oddeven">';
1721  // Date
1722  print "<td>".dol_print_date($db->jdate($objp->dp), "dayhour", 'tzuserrel')."</td>";
1723 
1724  // Price level
1725  if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1726  print '<td class="center">'.$objp->price_level."</td>";
1727  }
1728  // Price by quantity
1729  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1730  $type = ($objp->price_by_qty == 1) ? 'PriceByQuantity' : 'Standard';
1731  print '<td class="center">'.$langs->trans($type)."</td>";
1732  }
1733 
1734  print '<td class="center">';
1735  if (empty($objp->price_by_qty)) {
1736  print $langs->trans($objp->price_base_type);
1737  }
1738  print "</td>";
1739 
1740  if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1741  print '<td class="right">';
1742 
1743  if (empty($objp->price_by_qty)) {
1744  $positiverates = '';
1745  if (price2num($objp->tva_tx)) {
1746  $positiverates .= ($positiverates ? '/' : '').price2num($objp->tva_tx);
1747  }
1748  if (price2num($objp->localtax1_type)) {
1749  $positiverates .= ($positiverates ? '/' : '').price2num($objp->localtax1_tx);
1750  }
1751  if (price2num($objp->localtax2_type)) {
1752  $positiverates .= ($positiverates ? '/' : '').price2num($objp->localtax2_tx);
1753  }
1754  if (empty($positiverates)) {
1755  $positiverates = '0';
1756  }
1757  echo vatrate($positiverates.($objp->default_vat_code ? ' ('.$objp->default_vat_code.')' : ''), '%', !empty($objp->tva_npr) ? $objp->tva_npr : 0);
1758  /*
1759  if ($objp->default_vat_code)
1760  {
1761  print vatrate($objp->tva_tx, true) . ' ('.$objp->default_vat_code.')';
1762  }
1763  else print vatrate($objp->tva_tx, true, $objp->recuperableonly);*/
1764  }
1765 
1766  print "</td>";
1767  }
1768 
1769  // Line for default price
1770  if ($objp->price_base_type == 'HT') {
1771  $pu = $objp->price;
1772  } else {
1773  $pu = $objp->price_ttc;
1774  }
1775 
1776  // Local tax was not saved into table llx_product on old version. So we will use value linked to VAT code.
1777  $localtaxarray = getLocalTaxesFromRate($objp->tva_tx.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), 0, $mysoc, $mysoc);
1778  // Define part of HT, VAT, TTC
1779  $resultarray = calcul_price_total(1, $pu, 0, $objp->tva_tx, 1, 1, 0, $objp->price_base_type, $objp->recuperableonly, $object->type, $mysoc, $localtaxarray);
1780  // Calcul du total ht sans remise
1781  $total_ht = $resultarray[0];
1782  $total_vat = $resultarray[1];
1783  $total_localtax1 = $resultarray[9];
1784  $total_localtax2 = $resultarray[10];
1785  $total_ttc = $resultarray[2];
1786 
1787  // Price
1788  if (!empty($objp->fk_price_expression) && !empty($conf->dynamicprices->enabled)) {
1789  $price_expression = new PriceExpression($db);
1790  $res = $price_expression->fetch($objp->fk_price_expression);
1791  $title = $price_expression->title;
1792  print '<td class="right"></td>';
1793  print '<td class="right"></td>';
1794  if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
1795  print '<td class="right"></td>';
1796  }
1797  print '<td class="right">'.$title."</td>";
1798  } else {
1799  // Price HT
1800  print '<td class="right">';
1801  if (empty($objp->price_by_qty)) {
1802  print '<span class="amount">'.price($objp->price).'</span>';
1803  }
1804  print "</td>";
1805  // Price TTC
1806  print '<td class="right">';
1807  if (empty($objp->price_by_qty)) {
1808  $price_ttc = $objp->price_ttc;
1809  print '<span class="amount">'.price($price_ttc).'<span>';
1810  }
1811  print "</td>";
1812  if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
1813  print '<td class="right">';
1814  print $resultarray[2];
1815  print '</td>';
1816  }
1817  if (!empty($conf->dynamicprices->enabled)) { //Only if module is enabled
1818  print '<td class="right"></td>';
1819  }
1820  }
1821 
1822  // Price min
1823  print '<td class="right">';
1824  if (empty($objp->price_by_qty)) {
1825  print price($objp->price_min);
1826  }
1827  print '</td>';
1828 
1829  // Price min inc tax
1830  print '<td class="right">';
1831  if (empty($objp->price_by_qty)) {
1832  $price_min_ttc = $objp->price_min_ttc;
1833  print price($price_min_ttc);
1834  }
1835  print '</td>';
1836 
1837  // User
1838  print '<td class="right">';
1839  if ($objp->user_id > 0) {
1840  $userstatic = new User($db);
1841  $userstatic->fetch($objp->user_id);
1842  print $userstatic->getNomUrl(1, '', 0, 0, 24, 0, 'login');
1843  }
1844  print '</td>';
1845 
1846  // Action
1847  if ($user->rights->produit->supprimer) {
1848  $candelete = 0;
1849  if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1850  if (empty($notfirstlineforlevel[$objp->price_level])) {
1851  $notfirstlineforlevel[$objp->price_level] = 1;
1852  } else {
1853  $candelete = 1;
1854  }
1855  } elseif ($i > 0) {
1856  $candelete = 1;
1857  }
1858 
1859  print '<td class="right">';
1860  if ($candelete || ($db->jdate($objp->dp) >= dol_now())) { // Test on date is to be able to delete a corrupted record with a date in future
1861  print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id.'&lineid='.$objp->rowid.'">';
1862  print img_delete();
1863  print '</a>';
1864  } else {
1865  print '&nbsp;'; // Can not delete last price (it's current price)
1866  }
1867  print '</td>';
1868  }
1869 
1870  print "</tr>\n";
1871  $i++;
1872  }
1873 
1874  $db->free($result);
1875  print "</table>";
1876  print '</div>';
1877  print "<br>";
1878  }
1879 
1880  print '</div>';
1881  } else {
1882  dol_print_error($db);
1883  }
1884 }
1885 
1886 
1887 // Add area to show/add/edit a price for a dedicated customer
1888 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1889  $prodcustprice = new Productcustomerprice($db);
1890 
1891  $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
1892  $sortfield = GETPOST('sortfield', 'aZ09comma');
1893  $sortorder = GETPOST('sortorder', 'aZ09comma');
1894  $page = (GETPOST("page", 'int') ?GETPOST("page", 'int') : 0);
1895  if (empty($page) || $page == -1) {
1896  $page = 0;
1897  } // If $page is not defined, or '' or -1
1898  $offset = $limit * $page;
1899  $pageprev = $page - 1;
1900  $pagenext = $page + 1;
1901  if (!$sortorder) {
1902  $sortorder = "ASC";
1903  }
1904  if (!$sortfield) {
1905  $sortfield = "soc.nom";
1906  }
1907 
1908  // Build filter to diplay only concerned lines
1909  $filter = array('t.fk_product' => $object->id);
1910 
1911  if (!empty($search_soc)) {
1912  $filter['soc.nom'] = $search_soc;
1913  }
1914 
1915  if ($action == 'add_customer_price') {
1916  // Form to add a new customer price
1917  $maxpricesupplier = $object->min_recommended_price();
1918 
1919  print '<!-- add_customer_price -->';
1920  print load_fiche_titre($langs->trans('AddCustomerPrice'));
1921 
1922  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
1923  print '<input type="hidden" name="token" value="'.newToken().'">';
1924  print '<input type="hidden" name="action" value="add_customer_price_confirm">';
1925  print '<input type="hidden" name="id" value="'.$object->id.'">';
1926 
1927  print '<div class="tabBar tabBarWithBottom">';
1928 
1929  print '<table class="border centpercent">';
1930  print '<tr>';
1931  print '<td class="fieldrequired">'.$langs->trans('ThirdParty').'</td>';
1932  print '<td>';
1933  print img_picto('', 'company').$form->select_company('', 'socid', 's.client IN (1,2,3)', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth300');
1934  print '</td>';
1935  print '</tr>';
1936 
1937  // Ref. Customer
1938  print '<tr><td>' . $langs->trans('RefCustomer') . '</td>';
1939  print '<td><input name="ref_customer" size="12"></td></tr>';
1940 
1941  // VAT
1942  print '<tr><td class="fieldrequired">'.$langs->trans("DefaultTaxRate").'</td><td>';
1943  print $form->load_tva("tva_tx", $object->default_vat_code ? $object->tva_tx.' ('.$object->default_vat_code.')' : $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, $object->type, false, 1);
1944  print '</td></tr>';
1945 
1946  // Price base
1947  print '<tr><td class="fieldrequired">';
1948  print $langs->trans('PriceBase');
1949  print '</td>';
1950  print '<td>';
1951  print $form->selectPriceBaseType($object->price_base_type, "price_base_type");
1952  print '</td>';
1953  print '</tr>';
1954 
1955  // Price
1956  print '<tr><td class="fieldrequired">';
1957  $text = $langs->trans('SellingPrice');
1958  print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
1959  print '</td><td>';
1960  if ($object->price_base_type == 'TTC') {
1961  print '<input name="price" size="10" value="'.price($object->price_ttc).'">';
1962  } else {
1963  print '<input name="price" size="10" value="'.price($object->price).'">';
1964  }
1965  print '</td></tr>';
1966 
1967  // Price minimum
1968  print '<tr><td>';
1969  $text = $langs->trans('MinPrice');
1970  print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
1971  if ($object->price_base_type == 'TTC') {
1972  print '<td><input name="price_min" size="10" value="'.price($object->price_min_ttc).'">';
1973  } else {
1974  print '<td><input name="price_min" size="10" value="'.price($object->price_min).'">';
1975  }
1976  if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
1977  print '<td class="left">'.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().'</td>';
1978  }
1979  print '</td></tr>';
1980 
1981  print '</table>';
1982 
1983  print '</div>';
1984 
1985 
1986  print '<div class="center">';
1987 
1988  // Update all child soc
1989  print '<div class="marginbottomonly">';
1990  print '<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
1991  print '<label for="updatechildprice">'.$langs->trans('ForceUpdateChildPriceSoc').'</label>';
1992  print '</div>';
1993 
1994  print $form->buttonsSaveCancel();
1995 
1996  print '</form>';
1997  } elseif ($action == 'edit_customer_price') {
1998  // Edit mode
1999  $maxpricesupplier = $object->min_recommended_price();
2000 
2001  print '<!-- edit_customer_price -->';
2002  print load_fiche_titre($langs->trans('PriceByCustomer'));
2003 
2004  $result = $prodcustprice->fetch(GETPOST('lineid', 'int'));
2005  if ($result < 0) {
2006  setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
2007  }
2008 
2009  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
2010  print '<input type="hidden" name="token" value="'.newToken().'">';
2011  print '<input type="hidden" name="action" value="update_customer_price_confirm">';
2012  print '<input type="hidden" name="lineid" value="'.$prodcustprice->id.'">';
2013 
2014  print '<table class="liste centpercent">';
2015  print '<tr>';
2016  print '<td class="titlefield fieldrequired">'.$langs->trans('ThirdParty').'</td>';
2017  $staticsoc = new Societe($db);
2018  $staticsoc->fetch($prodcustprice->fk_soc);
2019  print "<td>".$staticsoc->getNomUrl(1)."</td>";
2020  print '</tr>';
2021 
2022  // Ref. Customer
2023  print '<tr><td>' . $langs->trans('RefCustomer') . '</td>';
2024  print '<td><input name="ref_customer" size="12" value="' . dol_escape_htmltag($prodcustprice->ref_customer) . '"></td></tr>';
2025 
2026  // VAT
2027  print '<tr><td class="fieldrequired">'.$langs->trans("DefaultTaxRate").'</td><td>';
2028  print $form->load_tva("tva_tx", $prodcustprice->default_vat_code ? $prodcustprice->tva_tx.' ('.$prodcustprice->default_vat_code.')' : $prodcustprice->tva_tx, $mysoc, '', $object->id, $prodcustprice->recuperableonly, $object->type, false, 1);
2029  print '</td></tr>';
2030 
2031  // Price base
2032  print '<tr><td class="fieldrequired">';
2033  print $langs->trans('PriceBase');
2034  print '</td>';
2035  print '<td>';
2036  print $form->selectPriceBaseType($prodcustprice->price_base_type, "price_base_type");
2037  print '</td>';
2038  print '</tr>';
2039 
2040  // Price
2041  print '<tr><td class="fieldrequired">';
2042  $text = $langs->trans('SellingPrice');
2043  print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
2044  print '</td><td>';
2045  if ($prodcustprice->price_base_type == 'TTC') {
2046  print '<input name="price" size="10" value="'.price($prodcustprice->price_ttc).'">';
2047  } else {
2048  print '<input name="price" size="10" value="'.price($prodcustprice->price).'">';
2049  }
2050  print '</td></tr>';
2051 
2052  // Price minimum
2053  print '<tr><td>';
2054  $text = $langs->trans('MinPrice');
2055  print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
2056  print '</td><td>';
2057  if ($prodcustprice->price_base_type == 'TTC') {
2058  print '<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).'">';
2059  } else {
2060  print '<input name="price_min" size="10" value="'.price($prodcustprice->price_min).'">';
2061  }
2062  print '</td>';
2063  if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
2064  print '<td class="left">'.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().'</td>';
2065  }
2066  print '</tr>';
2067 
2068  print '</table>';
2069 
2070 
2071  print '<div class="center">';
2072  print '<div class="marginbottomonly">';
2073  print '<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
2074  print '<label for="updatechildprice">'.$langs->trans('ForceUpdateChildPriceSoc').'</label>';
2075  print "</div>";
2076 
2077  print $form->buttonsSaveCancel();
2078 
2079  print '<br></form>';
2080  } elseif ($action == 'showlog_customer_price') {
2081  // List of all log of prices by customers
2082  print '<!-- list of all log of prices per customer -->'."\n";
2083 
2084  $filter = array('t.fk_product' => $object->id, 't.fk_soc' => GETPOST('socid', 'int'));
2085 
2086  // Count total nb of records
2087  $nbtotalofrecords = '';
2088  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
2089  $nbtotalofrecords = $prodcustprice->fetch_all_log($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
2090  }
2091 
2092  $result = $prodcustprice->fetch_all_log($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
2093  if ($result < 0) {
2094  setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
2095  }
2096 
2097  $option = '&socid='.GETPOST('socid', 'int').'&id='.$object->id;
2098 
2099  $staticsoc = new Societe($db);
2100  $staticsoc->fetch(GETPOST('socid', 'int'));
2101 
2102  $title = $langs->trans('PriceByCustomerLog');
2103  $title .= ' - '.$staticsoc->getNomUrl(1);
2104 
2105  $backbutton = '<a class="justalink" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">'.$langs->trans("Back").'</a>';
2106 
2107  print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $option, $sortfield, $sortorder, $backbutton, count($prodcustprice->lines), $nbtotalofrecords, 'title_accountancy.png');
2108 
2109  if (count($prodcustprice->lines) > 0) {
2110  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
2111  print '<input type="hidden" name="token" value="'.newToken().'">';
2112  print '<input type="hidden" name="id" value="'.$object->id.'">';
2113 
2114  print '<div class="div-table-responsive-no-min">';
2115  print '<table class="liste centpercent">';
2116 
2117  print '<tr class="liste_titre">';
2118  print '<td>'.$langs->trans("ThirdParty").'</td>';
2119  print '<td>'.$langs->trans('RefCustomer').'</td>';
2120  print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
2121  print '<td class="center">'.$langs->trans("PriceBase").'</td>';
2122  print '<td class="right">'.$langs->trans("DefaultTaxRate").'</td>';
2123  print '<td class="right">'.$langs->trans("HT").'</td>';
2124  print '<td class="right">'.$langs->trans("TTC").'</td>';
2125  if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
2126  print '<td class="right">'.$langs->trans("INCT").'</td>';
2127  }
2128  print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
2129  print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
2130  print '<td class="right">'.$langs->trans("ChangedBy").'</td>';
2131  print '<td>&nbsp;</td>';
2132  print '</tr>';
2133 
2134  foreach ($prodcustprice->lines as $line) {
2135  // Date
2136  $staticsoc = new Societe($db);
2137  $staticsoc->fetch($line->fk_soc);
2138 
2139  $tva_tx = $line->default_vat_code ? $line->tva_tx.' ('.$line->default_vat_code.')' : $line->tva_tx;
2140 
2141  // Line for default price
2142  if ($line->price_base_type == 'HT') {
2143  $pu = $line->price;
2144  } else {
2145  $pu = $line->price_ttc;
2146  }
2147 
2148  // Local tax is not saved into table of product. We use value linked to VAT code.
2149  $localtaxarray = getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), 0, $staticsoc, $mysoc);
2150  // Define part of HT, VAT, TTC
2151  $resultarray = calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly, $object->type, $mysoc, $localtaxarray);
2152  // Calcul du total ht sans remise
2153  $total_ht = $resultarray[0];
2154  $total_vat = $resultarray[1];
2155  $total_localtax1 = $resultarray[9];
2156  $total_localtax2 = $resultarray[10];
2157  $total_ttc = $resultarray[2];
2158 
2159  print '<tr class="oddeven">';
2160 
2161  print "<td>".$staticsoc->getNomUrl(1)."</td>";
2162  print '<td>'.$line->ref_customer.'</td>';
2163  print "<td>".dol_print_date($line->datec, "dayhour", 'tzuserrel')."</td>";
2164  print '<td class="center">'.$langs->trans($line->price_base_type)."</td>";
2165  print '<td class="right">';
2166 
2167  $positiverates = '';
2168  if (price2num($line->tva_tx)) {
2169  $positiverates .= ($positiverates ? '/' : '').price2num($line->tva_tx);
2170  }
2171  if (price2num($line->localtax1_type)) {
2172  $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax1_tx);
2173  }
2174  if (price2num($line->localtax2_type)) {
2175  $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax2_tx);
2176  }
2177  if (empty($positiverates)) {
2178  $positiverates = '0';
2179  }
2180 
2181  echo vatrate($positiverates.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), '%', ($line->tva_npr ? $line->tva_npr : $line->recuperableonly));
2182 
2183  //. vatrate($tva_tx, true, $line->recuperableonly) .
2184  print "</td>";
2185  print '<td class="right"><span class="amount">'.price($line->price)."</span></td>";
2186 
2187  print '<td class="right"><span class="amount">'.price($line->price_ttc)."</span></td>";
2188  if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
2189  print '<td class="right">'.price($resultarray[2]).'</td>';
2190  }
2191 
2192  print '<td class="right">'.price($line->price_min).'</td>';
2193  print '<td class="right">'.price($line->price_min_ttc).'</td>';
2194 
2195  // User
2196  $userstatic = new User($db);
2197  $userstatic->fetch($line->fk_user);
2198  print '<td class="right">';
2199  print $userstatic->getNomUrl(1, '', 0, 0, 24, 0, 'login');
2200  //print $userstatic->getLoginUrl(1);
2201  print '</td>';
2202  print '</tr>';
2203  }
2204  print "</table>";
2205  print '</div>';
2206  } else {
2207  print $langs->trans('None');
2208  }
2209  } elseif ($action != 'showlog_default_price' && $action != 'edit_price') {
2210  // List of all prices by customers
2211  print '<!-- list of all prices per customer -->'."\n";
2212 
2213  // Count total nb of records
2214  $nbtotalofrecords = '';
2215  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
2216  $nbtotalofrecords = $prodcustprice->fetch_all($sortorder, $sortfield, 0, 0, $filter);
2217  }
2218 
2219  $result = $prodcustprice->fetch_all($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
2220  if ($result < 0) {
2221  setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
2222  }
2223 
2224  $option = '&search_soc='.$search_soc.'&id='.$object->id;
2225 
2226  print_barre_liste($langs->trans('PriceByCustomer'), $page, $_SERVER ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, 'title_accountancy.png');
2227 
2228  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
2229  print '<input type="hidden" name="token" value="'.newToken().'">';
2230  print '<input type="hidden" name="id" value="'.$object->id.'">';
2231 
2232  print '<!-- List of prices per customer -->'."\n";
2233  print '<div class="div-table-responsive-no-min">'."\n";
2234  print '<table class="liste centpercent">'."\n";
2235 
2236  if (count($prodcustprice->lines) > 0 || $search_soc) {
2237  $colspan = 9;
2238  if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
2239  $colspan++;
2240  }
2241 
2242  print '<tr class="liste_titre">';
2243  print '<td class="liste_titre"><input type="text" class="flat maxwidth125" name="search_soc" value="'.$search_soc.'"></td>';
2244  print '<td class="liste_titre" colspan="'.$colspan.'">&nbsp;</td>';
2245  // Print the search button
2246  print '<td class="liste_titre maxwidthsearch">';
2247  $searchpicto = $form->showFilterAndCheckAddButtons(0);
2248  print $searchpicto;
2249  print '</td>';
2250  print '</tr>';
2251  }
2252 
2253  print '<tr class="liste_titre">';
2254  print '<td>'.$langs->trans("ThirdParty").'</td>';
2255  print '<td>'.$langs->trans('RefCustomer').'</td>';
2256  print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
2257  print '<td class="center">'.$langs->trans("PriceBase").'</td>';
2258  print '<td class="right">'.$langs->trans("DefaultTaxRate").'</td>';
2259  print '<td class="right">'.$langs->trans("HT").'</td>';
2260  print '<td class="right">'.$langs->trans("TTC").'</td>';
2261  if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
2262  print '<td class="right">'.$langs->trans("INCT").'</td>';
2263  }
2264  print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
2265  print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
2266  print '<td class="right">'.$langs->trans("ChangedBy").'</td>';
2267  print '<td></td>';
2268  print '</tr>';
2269 
2270  // Line for default price
2271  if ($object->price_base_type == 'HT') {
2272  $pu = $object->price;
2273  } else {
2274  $pu = $object->price_ttc;
2275  }
2276 
2277  // Local tax was not saved into table llx_product on old version. So we will use value linked to VAT code.
2278  $localtaxarray = getLocalTaxesFromRate($object->tva_tx.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), 0, $mysoc, $mysoc);
2279  // Define part of HT, VAT, TTC
2280  $resultarray = calcul_price_total(1, $pu, 0, $object->tva_tx, 1, 1, 0, $object->price_base_type, $object->recuperableonly, $object->type, $mysoc, $localtaxarray);
2281  // Calcul du total ht sans remise
2282  $total_ht = $resultarray[0];
2283  $total_vat = $resultarray[1];
2284  $total_localtax1 = $resultarray[9];
2285  $total_localtax2 = $resultarray[10];
2286  $total_ttc = $resultarray[2];
2287 
2288  print '<tr class="oddeven">';
2289  print '<td colspan="3">' . $langs->trans('Default') . '</td>';
2290 
2291  print '<td class="center">'.$langs->trans($object->price_base_type)."</td>";
2292 
2293  // VAT Rate
2294  print '<td class="right">';
2295 
2296  $positiverates = '';
2297  if (price2num($object->tva_tx)) {
2298  $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx);
2299  }
2300  if (price2num($object->localtax1_type)) {
2301  $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx);
2302  }
2303  if (price2num($object->localtax2_type)) {
2304  $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx);
2305  }
2306  if (empty($positiverates)) {
2307  $positiverates = '0';
2308  }
2309  echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr);
2310 
2311  //print vatrate($object->tva_tx, true, $object->tva_npr);
2312  //print $object->default_vat_code?' ('.$object->default_vat_code.')':'';
2313  print "</td>";
2314 
2315  print '<td class="right"><span class="amount">'.price($object->price)."</span></td>";
2316 
2317  print '<td class="right"><span class="amount">'.price($object->price_ttc)."</span></td>";
2318  if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
2319  //print '<td class="right">' . price($object->price_ttc) . "</td>";
2320  print '<td class="right"><span class="amount">'.price($resultarray[2]).'</span></td>';
2321  }
2322 
2323  print '<td class="right">'.price($object->price_min).'</td>';
2324  print '<td class="right">'.price($object->price_min_ttc).'</td>';
2325  print '<td class="right">';
2326  print '</td>';
2327  if ($user->rights->produit->supprimer || $user->rights->service->supprimer) {
2328  print '<td class="nowraponall">';
2329  print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=showlog_default_price&token='.newToken().'&id='.$object->id.'">';
2330  print img_info($langs->trans('PriceByCustomerLog'));
2331  print '</a>';
2332  print ' ';
2333  print '<a class="marginleftonly marginrightonly editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit_price&token='.newToken().'&id='.$object->id.'">';
2334  print img_edit('default', 0, 'style="vertical-align: middle;"');
2335  print '</a>';
2336  print '</td>';
2337  }
2338  print "</tr>\n";
2339 
2340  if (count($prodcustprice->lines) > 0) {
2341  foreach ($prodcustprice->lines as $line) {
2342  // Date
2343  $staticsoc = new Societe($db);
2344  $staticsoc->fetch($line->fk_soc);
2345 
2346  $tva_tx = $line->default_vat_code ? $line->tva_tx.' ('.$line->default_vat_code.')' : $line->tva_tx;
2347 
2348  // Line for default price
2349  if ($line->price_base_type == 'HT') {
2350  $pu = $line->price;
2351  } else {
2352  $pu = $line->price_ttc;
2353  }
2354 
2355  // Local tax is not saved into table of product. We use value linked to VAT code.
2356  $localtaxarray = getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), 0, $staticsoc, $mysoc);
2357  // Define part of HT, VAT, TTC
2358  $resultarray = calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly, $object->type, $mysoc, $localtaxarray);
2359  // Calcul du total ht sans remise
2360  $total_ht = $resultarray[0];
2361  $total_vat = $resultarray[1];
2362  $total_localtax1 = $resultarray[9];
2363  $total_localtax2 = $resultarray[10];
2364  $total_ttc = $resultarray[2];
2365 
2366  print '<tr class="oddeven">';
2367 
2368  print "<td>".$staticsoc->getNomUrl(1)."</td>";
2369  print '<td>'.dol_escape_htmltag($line->ref_customer).'</td>';
2370  print "<td>".dol_print_date($line->datec, "dayhour", 'tzuserrel')."</td>";
2371  print '<td class="center">'.$langs->trans($line->price_base_type)."</td>";
2372  // VAT Rate
2373  print '<td class="right">';
2374 
2375  $positiverates = '';
2376  if (price2num($line->tva_tx)) {
2377  $positiverates .= ($positiverates ? '/' : '').price2num($line->tva_tx);
2378  }
2379  if (price2num($line->localtax1_type)) {
2380  $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax1_tx);
2381  }
2382  if (price2num($line->localtax2_type)) {
2383  $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax2_tx);
2384  }
2385  if (empty($positiverates)) {
2386  $positiverates = '0';
2387  }
2388 
2389  echo vatrate($positiverates.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), '%', ($line->tva_npr ? $line->tva_npr : $line->recuperableonly));
2390 
2391  print "</td>";
2392 
2393  print '<td class="right"><span class="amount">'.price($line->price)."</span></td>";
2394 
2395  print '<td class="right"><span class="amount">'.price($line->price_ttc)."</span></td>";
2396  if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
2397  //print '<td class="right">' . price($line->price_ttc) . "</td>";
2398  print '<td class="right"><span class="amount">'.price($resultarray[2]).'</span></td>';
2399  }
2400 
2401  print '<td class="right">'.price($line->price_min).'</td>';
2402  print '<td class="right">'.price($line->price_min_ttc).'</td>';
2403 
2404  // User
2405  $userstatic = new User($db);
2406  $userstatic->fetch($line->fk_user);
2407  print '<td class="right">';
2408  print $userstatic->getNomUrl(1, '', 0, 0, 24, 0, 'login');
2409  print '</td>';
2410 
2411  // Todo Edit or delete button
2412  // Action
2413  if ($user->rights->produit->supprimer || $user->rights->service->supprimer) {
2414  print '<td class="right nowraponall">';
2415  print '<a href="'.$_SERVER["PHP_SELF"].'?action=showlog_customer_price&token='.newToken().'&id='.$object->id.'&socid='.$line->fk_soc.'">';
2416  print img_info($langs->trans('PriceByCustomerLog'));
2417  print '</a>';
2418  print ' ';
2419  print '<a class="marginleftonly editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit_customer_price&token='.newToken().'&id='.$object->id.'&lineid='.$line->id.'">';
2420  print img_edit('default', 0, 'style="vertical-align: middle;"');
2421  print '</a>';
2422  print ' ';
2423  print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?action=delete_customer_price&token='.newToken().'&id='.$object->id.'&lineid='.$line->id.'">';
2424  print img_delete('default', 'style="vertical-align: middle;"');
2425  print '</a>';
2426  print '</td>';
2427  }
2428 
2429  print "</tr>\n";
2430  }
2431  }
2432 
2433  print "</table>";
2434  print '</div>';
2435 
2436  print "</form>";
2437  }
2438 }
2439 
2440 // End of page
2441 llxFooter();
2442 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
getLocalTaxesFromRate
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
Definition: functions.lib.php:6097
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
dol_trunc
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
Definition: functions.lib.php:3805
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
PriceExpression
Class for accesing price expression table.
Definition: price_expression.class.php:30
Productcustomerprice
File of class to manage predefined price products or services by customer.
Definition: productcustomerprice.class.php:29
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
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
img_info
img_info($titlealt='default')
Show info logo.
Definition: functions.lib.php:4502
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
product_prepare_head
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:35
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4389
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
calcul_price_total
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
Definition: price.lib.php:86
PriceParser
Class to parse product price expressions.
Definition: price_parser.class.php:33
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
get_localtax
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
Definition: functions.lib.php:5837
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$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
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5541
Product\TYPE_SERVICE
const TYPE_SERVICE
Service.
Definition: product.class.php:504
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
Product\TYPE_PRODUCT
const TYPE_PRODUCT
Regular product.
Definition: product.class.php:500
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
vatrate
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
Definition: functions.lib.php:5492
float
div float
Buy price without taxes.
Definition: style.css.php:809