dolibarr  13.0.2
fournisseurs.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
8  * Copyright (C) 2014 Ion Agorria <ion@agorria.com>
9  * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
10  * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
11  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
12  * Copyright (C) 2019 Tim Otte <otte@meuser.it>
13  * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <https://www.gnu.org/licenses/>.
27  */
28 
35 require '../main.inc.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.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 if (!empty($conf->barcode->enabled)) dol_include_once('/core/class/html.formbarcode.class.php');
44 // Load translation files required by the page
45 $langs->loadLangs(array('products', 'suppliers', 'bills', 'margins', 'stocks'));
46 
47 $id = GETPOST('id', 'int');
48 $ref = GETPOST('ref', 'alpha');
49 $rowid = GETPOST('rowid', 'int');
50 $action = GETPOST('action', 'aZ09');
51 $cancel = GETPOST('cancel', 'alpha');
52 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'pricesuppliercard';
53 
54 $socid = GETPOST('socid', 'int');
55 $cost_price = GETPOST('cost_price', 'alpha');
56 $backtopage = GETPOST('backtopage', 'alpha');
57 $error = 0;
58 
59 $extrafields = new ExtraFields($db);
60 
61 // If socid provided by ajax company selector
62 if (!empty($_REQUEST['search_fourn_id']))
63 {
64  $_GET['id_fourn'] = $_GET['search_fourn_id'];
65  $_POST['id_fourn'] = $_POST['search_fourn_id'];
66  $_REQUEST['id_fourn'] = $_REQUEST['search_fourn_id'];
67 }
68 
69 // Security check
70 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
71 $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
72 if ($user->socid) $socid = $user->socid;
73 $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
74 
75 if (empty($user->rights->fournisseur->lire)) accessforbidden();
76 
77 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
78 $sortfield = GETPOST("sortfield", 'alpha');
79 $sortorder = GETPOST("sortorder", 'alpha');
80 $page = (GETPOST("page", 'int') ?GETPOST("page", 'int') : 0);
81 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
82 $offset = $limit * $page;
83 $pageprev = $page - 1;
84 $pagenext = $page + 1;
85 if (!$sortfield) $sortfield = "s.nom";
86 if (!$sortorder) $sortorder = "ASC";
87 
88 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
89 $hookmanager->initHooks(array('pricesuppliercard', 'globalcard'));
90 
91 $object = new ProductFournisseur($db);
92 if ($id > 0 || $ref)
93 {
94  $object->fetch($id, $ref);
95 }
96 
97 $sortfield = GETPOST("sortfield", 'alpha');
98 $sortorder = GETPOST("sortorder", 'alpha');
99 
100 if (!$sortfield) $sortfield = "s.nom";
101 if (!$sortorder) $sortorder = "ASC";
102 
103 
104 /*
105  * Actions
106  */
107 
108 if ($cancel) $action = '';
109 
110 $usercanread = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->lire) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->lire));
111 $usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer));
112 
113 $parameters = array('socid'=>$socid, 'id_prod'=>$id);
114 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
115 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
116 
117 if (empty($reshook))
118 {
119  if ($action == 'setcost_price')
120  {
121  if ($id)
122  {
123  $result = $object->fetch($id);
124  $object->cost_price = price2num($cost_price);
125  $result = $object->update($object->id, $user);
126  if ($result > 0)
127  {
128  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
129  $action = '';
130  } else {
131  $error++;
132  setEventMessages($object->error, $object->errors, 'errors');
133  }
134  }
135  }
136 
137  if ($action == 'confirm_remove_pf')
138  {
139  if ($rowid) // id of product supplier price to remove
140  {
141  $action = '';
142  $result = $object->remove_product_fournisseur_price($rowid);
143  if ($result > 0) {
144  $db->query("DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields WHERE fk_object = $rowid");
145  setEventMessages($langs->trans("PriceRemoved"), null, 'mesgs');
146  } else {
147  $error++;
148  setEventMessages($object->error, $object->errors, 'errors');
149  }
150  }
151  }
152 
153  if ($action == 'save_price')
154  {
155  $id_fourn = GETPOST("id_fourn");
156  if (empty($id_fourn)) $id_fourn = GETPOST("search_id_fourn");
157  $ref_fourn = GETPOST("ref_fourn");
158  if (empty($ref_fourn)) $ref_fourn = GETPOST("search_ref_fourn");
159  $ref_fourn_old = GETPOST("ref_fourn_old");
160  if (empty($ref_fourn_old)) $ref_fourn_old = $ref_fourn;
161  $quantity = price2num(GETPOST("qty", 'nohtml'), 'MS');
162  $remise_percent = price2num(GETPOST('remise_percent', 'alpha'));
163 
164  $npr = preg_match('/\*/', $_POST['tva_tx']) ? 1 : 0;
165  $tva_tx = str_replace('*', '', GETPOST('tva_tx', 'alpha'));
166  if (!preg_match('/\((.*)\)/', $tva_tx)) {
167  $tva_tx = price2num($tva_tx);
168  }
169 
170  $price_expression = GETPOST('eid', 'int') ? GETPOST('eid', 'int') : ''; // Discard expression if not in expression mode
171  $delivery_time_days = GETPOST('delivery_time_days', 'int') ? GETPOST('delivery_time_days', 'int') : '';
172  $supplier_reputation = GETPOST('supplier_reputation');
173  $supplier_description = GETPOST('supplier_description', 'restricthtml');
174  $barcode = GETPOST('barcode', 'alpha');
175  $fk_barcode_type = GETPOST('fk_barcode_type', 'int');
176  $packaging = price2num(GETPOST("packaging", 'alphanohtml'), 'MS');
177 
178  if ($tva_tx == '')
179  {
180  $error++;
181  $langs->load("errors");
182  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("VATRateForSupplierProduct")), null, 'errors');
183  }
184  if (!is_numeric($tva_tx))
185  {
186  $error++;
187  $langs->load("errors");
188  setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("VATRateForSupplierProduct")), null, 'errors');
189  }
190  if (empty($quantity))
191  {
192  $error++;
193  $langs->load("errors");
194  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Qty")), null, 'errors');
195  }
196  if (empty($ref_fourn))
197  {
198  $error++;
199  $langs->load("errors");
200  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefSupplier")), null, 'errors');
201  }
202  if ($id_fourn <= 0)
203  {
204  $error++;
205  $langs->load("errors");
206  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Supplier")), null, 'errors');
207  }
208  if (price2num($_POST["price"]) < 0 || $_POST["price"] == '')
209  {
210  if ($price_expression === '') // Return error of missing price only if price_expression not set
211  {
212  $error++;
213  $langs->load("errors");
214  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Price")), null, 'errors');
215  } else {
216  $_POST["price"] = 0;
217  }
218  }
219  if (!empty($conf->multicurrency->enabled)) {
220  if (empty($_POST["multicurrency_code"])) {
221  $error++;
222  $langs->load("errors");
223  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Currency")), null, 'errors');
224  }
225  if (price2num($_POST["multicurrency_tx"]) <= 0 || $_POST["multicurrency_tx"] == '') {
226  $error++;
227  $langs->load("errors");
228  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("CurrencyRate")), null, 'errors');
229  }
230  if (price2num($_POST["multicurrency_price"]) < 0 || $_POST["multicurrency_price"] == '') {
231  $error++;
232  $langs->load("errors");
233  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PriceCurrency")), null, 'errors');
234  }
235  }
236 
237  if (!$error)
238  {
239  $db->begin();
240 
241  if (!$error)
242  {
243  $ret = $object->add_fournisseur($user, $id_fourn, $ref_fourn_old, $quantity); // This insert record with no value for price. Values are update later with update_buyprice
244  if ($ret == -3)
245  {
246  $error++;
247 
248  $object->fetch($object->product_id_already_linked);
249  $productLink = $object->getNomUrl(1, 'supplier');
250 
251  setEventMessages($langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct", $productLink), null, 'errors');
252  } elseif ($ret < 0)
253  {
254  $error++;
255  setEventMessages($object->error, $object->errors, 'errors');
256  }
257  }
258 
259  if (!$error)
260  {
261  $supplier = new Fournisseur($db);
262  $result = $supplier->fetch($id_fourn);
263  if (GETPOSTISSET('ref_fourn_price_id')) {
264  $object->fetch_product_fournisseur_price(GETPOST('ref_fourn_price_id', 'int'));
265  }
266 
267  $extralabels = $extrafields->fetch_name_optionals_label("product_fournisseur_price");
268  $extrafield_values = $extrafields->getOptionalsFromPost("product_fournisseur_price");
269  if (!empty($extrafield_values)) {
270  $resql = $db->query("SELECT fk_object FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields WHERE fk_object = ".$object->product_fourn_price_id);
271  // Insert a new extrafields row, if none exists
272  if ($db->num_rows($resql) != 1) {
273  $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields (fk_object, ";
274  foreach ($extrafield_values as $key => $value) {
275  $sql .= str_replace('options_', '', $key).', ';
276  }
277  $sql = substr($sql, 0, strlen($sql) - 2).") VALUES (".$object->product_fourn_price_id.", ";
278  foreach ($extrafield_values as $key => $value) {
279  $sql .= '"'.$value.'", ';
280  }
281  $sql = substr($sql, 0, strlen($sql) - 2).')';
282  } else {
283  // update the existing one
284  $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields SET ";
285  foreach ($extrafield_values as $key => $value) {
286  $sql .= str_replace('options_', '', $key).' = "'.$value.'", ';
287  }
288  $sql = substr($sql, 0, strlen($sql) - 2).' WHERE fk_object = '.$object->product_fourn_price_id;
289  }
290 
291  // Execute the sql command from above
292  $db->query($sql);
293  }
294 
295  $newprice = price2num(GETPOST("price", "alpha"));
296 
297  if (empty($packaging)) $packaging = 1;
298  if ($packaging < $quantity) $packaging = $quantity;
299  $object->packaging = $packaging;
300 
301  if (!empty($conf->multicurrency->enabled))
302  {
303  $multicurrency_tx = price2num(GETPOST("multicurrency_tx", 'alpha'));
304  $multicurrency_price = price2num(GETPOST("multicurrency_price", 'alpha'));
305  $multicurrency_code = GETPOST("multicurrency_code", 'alpha');
306 
307  $ret = $object->update_buyprice($quantity, $newprice, $user, GETPOST("price_base_type"), $supplier, GETPOST("oselDispo"), $ref_fourn, $tva_tx, GETPOST("charges"), $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', $multicurrency_price, GETPOST("multicurrency_price_base_type"), $multicurrency_tx, $multicurrency_code, $supplier_description, $barcode, $fk_barcode_type);
308  } else {
309  $ret = $object->update_buyprice($quantity, $newprice, $user, GETPOST("price_base_type"), $supplier, GETPOST("oselDispo"), $ref_fourn, $tva_tx, GETPOST("charges"), $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', 0, 'HT', 1, '', $supplier_description, $barcode, $fk_barcode_type);
310  }
311  if ($ret < 0)
312  {
313  $error++;
314  setEventMessages($object->error, $object->errors, 'errors');
315  } else {
316  if (!empty($conf->dynamicprices->enabled) && $price_expression !== '')
317  {
318  //Check the expression validity by parsing it
319  $priceparser = new PriceParser($db);
320  $object->fk_supplier_price_expression = $price_expression;
321  $price_result = $priceparser->parseProductSupplier($object);
322  if ($price_result < 0) { //Expression is not valid
323  $error++;
324  setEventMessages($priceparser->translatedError(), null, 'errors');
325  }
326  }
327  if (!$error && !empty($conf->dynamicprices->enabled))
328  {
329  //Set the price expression for this supplier price
330  $ret = $object->setSupplierPriceExpression($price_expression);
331  if ($ret < 0)
332  {
333  $error++;
334  setEventMessages($object->error, $object->errors, 'errors');
335  }
336  }
337  }
338  }
339 
340  if (!$error)
341  {
342  $db->commit();
343  $action = '';
344  } else {
345  $db->rollback();
346  }
347  } else {
348  $action = 'add_price';
349  }
350  }
351 }
352 
353 
354 /*
355  * view
356  */
357 
358 $title = $langs->trans('ProductServiceCard');
359 $helpurl = '';
360 $shortlabel = dol_trunc($object->label, 16);
361 if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT))
362 {
363  $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('BuyingPrices');
364  $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
365 }
366 if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE))
367 {
368  $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('BuyingPrices');
369  $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
370 }
371 
372 llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'classforhorizontalscrolloftabs');
373 
374 $form = new Form($db);
375 
376 if ($id > 0 || $ref)
377 {
378  if ($result)
379  {
380  if ($action == 'ask_remove_pf') {
381  $form = new Form($db);
382  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&rowid='.$rowid, $langs->trans('DeleteProductBuyPrice'), $langs->trans('ConfirmDeleteProductBuyPrice'), 'confirm_remove_pf', '', 0, 1);
383  echo $formconfirm;
384  }
385 
386  if ($action <> 'edit' && $action <> 're-edit')
387  {
388  $head = product_prepare_head($object);
389  $titre = $langs->trans("CardProduct".$object->type);
390  $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
391 
392  print dol_get_fiche_head($head, 'suppliers', $titre, -1, $picto);
393 
394  $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
395  $object->next_prev_filter = " fk_product_type = ".$object->type;
396 
397  $shownav = 1;
398  if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0;
399 
400  dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
401 
402  print '<div class="fichecenter">';
403 
404  print '<div class="underbanner clearboth"></div>';
405  print '<table class="border tableforfield centpercent">';
406 
407  // Cost price. Can be used for margin module for option "calculate margin on explicit cost price
408  print '<tr><td>';
409  $textdesc = $langs->trans("CostPriceDescription");
410  $textdesc .= "<br>".$langs->trans("CostPriceUsage");
411  $text = $form->textwithpicto($langs->trans("CostPrice"), $textdesc, 1, 'help', '');
412  print $form->editfieldkey($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6');
413  print '</td><td colspan="2">';
414  print $form->editfieldval($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6');
415  print '</td></tr>';
416 
417  // PMP
418  print '<tr><td class="titlefieldcreate">'.$form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")).'</td>';
419  print '<td>';
420  if ($object->pmp > 0) print price($object->pmp).' '.$langs->trans("HT");
421  print '</td>';
422  print '</tr>';
423 
424  // Best buying Price
425  print '<tr><td class="titlefieldcreate">'.$langs->trans("BuyingPriceMin").'</td>';
426  print '<td colspan="2">';
427  $product_fourn = new ProductFournisseur($db);
428  if ($product_fourn->find_min_price_product_fournisseur($object->id) > 0)
429  {
430  if ($product_fourn->product_fourn_price_id > 0) print $product_fourn->display_price_product_fournisseur();
431  else print $langs->trans("NotDefined");
432  }
433  print '</td></tr>';
434 
435  print '</table>';
436 
437  print '</div>';
438  print '<div style="clear:both"></div>';
439 
441 
442 
443  // Form to add or update a price
444  if (($action == 'add_price' || $action == 'update_price') && $usercancreate)
445  {
446  $langs->load("suppliers");
447 
448  if ($rowid)
449  {
450  $object->fetch_product_fournisseur_price($rowid, 1); //Ignore the math expression when getting the price
451  print load_fiche_titre($langs->trans("ChangeSupplierPrice"));
452  } else {
453  print load_fiche_titre($langs->trans("AddSupplierPrice"));
454  }
455 
456  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST">';
457  print '<input type="hidden" name="token" value="'.newToken().'">';
458  print '<input type="hidden" name="action" value="save_price">';
459 
461 
462  print '<table class="border centpercent">';
463 
464  // Supplier
465  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Supplier").'</td><td>';
466  if ($rowid)
467  {
468  $supplier = new Fournisseur($db);
469  $supplier->fetch($socid);
470  print $supplier->getNomUrl(1);
471  print '<input type="hidden" name="id_fourn" value="'.$socid.'">';
472  print '<input type="hidden" name="ref_fourn_price_id" value="'.$rowid.'">';
473  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
474  print '<input type="hidden" name="socid" value="'.$socid.'">';
475  } else {
476  $events = array();
477  $events[] = array('method' => 'getVatRates', 'url' => dol_buildpath('/core/ajax/vatrates.php', 1), 'htmlname' => 'tva_tx', 'params' => array());
478  print $form->select_company(GETPOST("id_fourn", 'alpha'), 'id_fourn', 'fournisseur=1', 'SelectThirdParty', 0, 0, $events);
479 
480  $parameters = array('filtre'=>"fournisseur=1", 'html_name'=>'id_fourn', 'selected'=>GETPOST("id_fourn"), 'showempty'=>1, 'prod_id'=>$object->id);
481  $reshook = $hookmanager->executeHooks('formCreateThirdpartyOptions', $parameters, $object, $action);
482  if (empty($reshook))
483  {
484  if (empty($form->result))
485  {
486  print ' - <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&type=f&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id.'&action='.$action).'">'.$langs->trans("CreateDolibarrThirdPartySupplier").'</a>';
487  }
488  }
489  }
490  print '</td></tr>';
491 
492  // Ref supplier
493  print '<tr><td class="fieldrequired">'.$langs->trans("SupplierRef").'</td><td>';
494  if ($rowid)
495  {
496  print '<input type="hidden" name="ref_fourn_old" value="'.$object->ref_supplier.'">';
497  print '<input class="flat width150" maxlength="30" name="ref_fourn" value="'.$object->ref_supplier.'">';
498  } else {
499  print '<input class="flat width150" maxlength="30" name="ref_fourn" value="'.(GETPOST("ref_fourn") ? GETPOST("ref_fourn") : '').'">';
500  }
501  print '</td>';
502  print '</tr>';
503 
504  // Availability
505  if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY))
506  {
507  $langs->load("propal");
508  print '<tr><td>'.$langs->trans("Availability").'</td><td>';
509  $form->selectAvailabilityDelay($object->fk_availability, "oselDispo", 1);
510  print '</td></tr>'."\n";
511  }
512 
513  // Qty min
514  print '<tr>';
515  print '<td class="fieldrequired">'.$langs->trans("QtyMin").'</td>';
516  print '<td>';
517  $quantity = GETPOSTISSET('qty') ? price2num(GETPOST('qty', 'nohtml'), 'MS') : "1";
518  if ($rowid)
519  {
520  print '<input type="hidden" name="qty" value="'.$object->fourn_qty.'">';
521  print $object->fourn_qty;
522  } else {
523  print '<input class="flat" name="qty" size="5" value="'.$quantity.'">';
524  }
525  // Units
526  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
527  $unit = $object->getLabelOfUnit();
528  if ($unit !== '') {
529  print '&nbsp;&nbsp;'.$langs->trans($unit);
530  }
531  }
532  print '</td></tr>';
533 
534  if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
535  // Packaging
536  print '<tr>';
537 
538  print '<td class="fieldrequired">'.$form->textwithpicto($langs->trans("PackagingForThisProduct"), $langs->trans("PackagingForThisProductDesc")).'</td>';
539  print '<td>';
540  $packaging = GETPOSTISSET('packaging') ? price2num(GETPOST('packaging', 'nohtml'), 'MS') : ((empty($rowid)) ? "1" : price2num($object->packaging, 'MS'));
541  print '<input class="flat" name="packaging" size="5" value="'.$packaging.'">';
542 
543  // Units
544  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
545  $unit = $object->getLabelOfUnit();
546  if ($unit !== '') {
547  print '&nbsp;&nbsp;'.$langs->trans($unit);
548  }
549  }
550  }
551  // Vat rate
552  $default_vat = '';
553 
554  // We don't have supplier, so we try to guess.
555  // For this we build a fictive supplier with same properties than user but using vat)
556  $mysoc2 = clone $mysoc;
557  $mysoc2->name = 'Fictive seller with same country';
558  $mysoc2->tva_assuj = 1;
559  $default_vat = get_default_tva($mysoc2, $mysoc, $object->id, 0);
560  $default_npr = get_default_npr($mysoc2, $mysoc, $object->id, 0);
561  if (empty($default_vat)) $default_npr = $default_vat;
562 
563  print '<tr><td class="fieldrequired">'.$langs->trans("VATRateForSupplierProduct").'</td>';
564  print '<td>';
565  //print $form->load_tva('tva_tx',$object->tva_tx,$supplier,$mysoc); // Do not use list here as it may be any vat rates for any country
566  if (!empty($rowid)) // If we have a supplier, it is an update, we must show the vat of current supplier price
567  {
568  $tmpproductsupplier = new ProductFournisseur($db);
569  $tmpproductsupplier->fetch_product_fournisseur_price($rowid, 1);
570  $default_vat = $tmpproductsupplier->fourn_tva_tx;
571  $default_npr = $tmpproductsupplier->fourn_tva_npr;
572  } else {
573  if (empty($default_vat))
574  {
575  $default_vat = $object->tva_tx;
576  }
577  }
578  $vattosuggest = (GETPOST("tva_tx") ?vatrate(GETPOST("tva_tx")) : ($default_vat != '' ?vatrate($default_vat) : ''));
579  $vattosuggest = preg_replace('/\s*\(.*\)$/', '', $vattosuggest);
580  print '<input type="text" class="flat" size="5" name="tva_tx" value="'.$vattosuggest.'">';
581  print '</td></tr>';
582 
583  if (!empty($conf->dynamicprices->enabled)) //Only show price mode and expression selector if module is enabled
584  {
585  // Price mode selector
586  print '<tr><td class="fieldrequired">'.$langs->trans("PriceMode").'</td><td>';
587  $price_expression = new PriceExpression($db);
588  $price_expression_list = array(0 => $langs->trans("PriceNumeric")); //Put the numeric mode as first option
589  foreach ($price_expression->list_price_expression() as $entry) {
590  $price_expression_list[$entry->id] = $entry->title;
591  }
592  $price_expression_preselection = GETPOST('eid') ? GETPOST('eid') : ($object->fk_supplier_price_expression ? $object->fk_supplier_price_expression : '0');
593  print $form->selectarray('eid', $price_expression_list, $price_expression_preselection);
594  print '&nbsp; <div id="expression_editor" class="button">'.$langs->trans("PriceExpressionEditor").'</div>';
595  print '</td></tr>';
596  // This code hides the numeric price input if is not selected, loads the editor page if editor button is pressed
597  print '<script type="text/javascript">
598  jQuery(document).ready(run);
599  function run() {
600  jQuery("#expression_editor").click(on_click);
601  jQuery("#eid").change(on_change);
602  on_change();
603  }
604  function on_click() {
605  window.location = "'.DOL_URL_ROOT.'/product/dynamic_price/editor.php?id='.$id.'&tab=fournisseurs&eid=" + $("#eid").val();
606  }
607  function on_change() {
608  if ($("#eid").val() == 0) {
609  jQuery("#price_numeric").show();
610  } else {
611  jQuery("#price_numeric").hide();
612  }
613  }
614  </script>';
615  }
616 
617  if (!empty($conf->multicurrency->enabled)) {
618  // Currency
619  print '<tr><td class="fieldrequired">'.$langs->trans("Currency").'</td>';
620  print '<td>';
621  $currencycodetouse = GETPOST('multicurrency_code') ?GETPOST('multicurrency_code') : (isset($object->fourn_multicurrency_code) ? $object->fourn_multicurrency_code : '');
622  if (empty($currencycodetouse) && $object->fourn_multicurrency_tx == 1) $currencycodetouse = $conf->currency;
623  print $form->selectMultiCurrency($currencycodetouse, "multicurrency_code", 1);
624  print ' &nbsp; '.$langs->trans("CurrencyRate").' ';
625  print '<input class="flat" name="multicurrency_tx" size="4" value="'.vatrate(GETPOST('multicurrency_tx') ? GETPOST('multicurrency_tx') : (isset($object->fourn_multicurrency_tx) ? $object->fourn_multicurrency_tx : '')).'">';
626  print '</td>';
627  print '</tr>';
628 
629  // Currency price qty min
630  print '<tr><td class="fieldrequired">'.$langs->trans("PriceQtyMinCurrency").'</td>';
631  $pricesupplierincurrencytouse = (GETPOST('multicurrency_price') ?GETPOST('multicurrency_price') : (isset($object->fourn_multicurrency_price) ? $object->fourn_multicurrency_price : ''));
632  print '<td><input class="flat" name="multicurrency_price" size="8" value="'.price($pricesupplierincurrencytouse).'">';
633  print '&nbsp;';
634  print $form->selectPriceBaseType((GETPOST('multicurrency_price_base_type') ?GETPOST('multicurrency_price_base_type') : 'HT'), "multicurrency_price_base_type"); // We keep 'HT' here, multicurrency_price_base_type is not yet supported for supplier prices
635  print '</td></tr>';
636 
637  // Price qty min
638  print '<tr><td class="fieldrequired">'.$langs->trans("PriceQtyMin").'</td>';
639  print '<td><input class="flat" name="disabled_price" size="8" value="">';
640  print '<input type="hidden" name="price" value="">';
641  print '<input type="hidden" name="price_base_type" value="">';
642  print '&nbsp;';
643  print $form->selectPriceBaseType('', "disabled_price_base_type");
644  print '</td></tr>';
645 
646  $currencies = array();
647  $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'multicurrency WHERE entity = '.$conf->entity;
648  $resql = $db->query($sql);
649  if ($resql) {
650  $currency = new MultiCurrency($db);
651  while ($obj = $db->fetch_object($resql)) {
652  $currency->fetch($obj->rowid);
653  $currencies[$currency->code] = $currency->rate->rate;
654  }
655  }
656  $currencies = json_encode($currencies);
657 
658  print <<<END
659  <script type="text/javascript">
660  function update_price_from_multicurrency() {
661  var multicurrency_price = $('input[name="multicurrency_price"]').val();
662  var multicurrency_tx = $('input[name="multicurrency_tx"]').val();
663  $('input[name="price"]').val(multicurrency_price / multicurrency_tx);
664  $('input[name="disabled_price"]').val(multicurrency_price / multicurrency_tx);
665  }
666  jQuery(document).ready(function () {
667  $('input[name="disabled_price"]').prop('disabled', true);
668  $('select[name="disabled_price_base_type"]').prop('disabled', true);
669  update_price_from_multicurrency();
670 
671  $('input[name="multicurrency_price"]').keyup(function () {
672  update_price_from_multicurrency();
673  }).change(function () {
674  update_price_from_multicurrency();
675  }).on('paste', function () {
676  update_price_from_multicurrency();
677  });
678 
679  $('input[name="multicurrency_tx"]').keyup(function () {
680  update_price_from_multicurrency();
681  }).change(function () {
682  update_price_from_multicurrency();
683  }).on('paste', function () {
684  update_price_from_multicurrency();
685  });
686 
687  $('select[name="multicurrency_price_base_type"]').change(function () {
688  $('input[name="price_base_type"]').val($(this).val());
689  $('select[name="disabled_price_base_type"]').val($(this).val());
690  });
691 
692  var currencies_array = $currencies;
693  $('select[name="multicurrency_code"]').change(function () {
694  $('input[name="multicurrency_tx"]').val(currencies_array[$(this).val()]);
695  });
696  });
697  </script>
698 END;
699  } else {
700  // Price qty min
701  print '<tr><td class="fieldrequired">'.$langs->trans("PriceQtyMin").'</td>';
702  print '<td><input class="flat" name="price" size="8" value="'.(GETPOST('price') ? price(GETPOST('price')) : (isset($object->fourn_price) ? price($object->fourn_price) : '')).'">';
703  print '&nbsp;';
704  print $form->selectPriceBaseType((GETPOST('price_base_type') ? GETPOST('price_base_type') : 'HT'), "price_base_type"); // We keep 'HT' here, price_base_type is not yet supported for supplier prices
705  print '</td></tr>';
706  }
707 
708 
709  // Discount qty min
710  print '<tr><td>'.$langs->trans("DiscountQtyMin").'</td>';
711  print '<td><input class="flat" name="remise_percent" size="4" value="'.(GETPOST('remise_percent') ?vatrate(GETPOST('remise_percent')) : (isset($object->fourn_remise_percent) ?vatrate($object->fourn_remise_percent) : '')).'"> %';
712  print '</td>';
713  print '</tr>';
714 
715  // Delivery delay in days
716  print '<tr>';
717  print '<td>'.$langs->trans('NbDaysToDelivery').'</td>';
718  print '<td><input class="flat" name="delivery_time_days" size="4" value="'.($rowid ? $object->delivery_time_days : '').'">&nbsp;'.$langs->trans('days').'</td>';
719  print '</tr>';
720 
721  // Reputation
722  print '<tr><td>'.$langs->trans("ReferenceReputation").'</td><td>';
723  echo $form->selectarray('supplier_reputation', $object->reputations, $supplier_reputation ? $supplier_reputation : $object->supplier_reputation);
724  print '</td></tr>';
725 
726  // Barcode
727  if (!empty($conf->barcode->enabled))
728  {
729  // Option to define a transport cost on supplier price
730  print '<tr>';
731  print '<td>'.$langs->trans('BarcodeValue').'</td>';
732  print '<td>'.img_picto('', 'barcode', 'class="pictofixedwidth"').'<input class="flat" name="barcode" value="'.($rowid ? $object->supplier_barcode : '').'"></td>';
733  print '</tr>';
734  $formbarcode = new FormBarCode($db);
735 
736  // Barcode type
737  print '<tr>';
738  print '<td>'.$langs->trans('BarcodeType').'</td>';
739  print '<td>';
740  print $formbarcode->selectBarcodeType(($rowid ? $object->supplier_fk_barcode_type : $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE), 'fk_barcode_type', 1);
741  print '</td>';
742  print '</tr>';
743  }
744 
745  // Option to define a transport cost on supplier price
746  if ($conf->global->PRODUCT_CHARGES)
747  {
748  if (!empty($conf->margin->enabled))
749  {
750  print '<tr>';
751  print '<td>'.$langs->trans("Charges").'</td>';
752  print '<td><input class="flat" name="charges" size="8" value="'.(GETPOST('charges') ?price(GETPOST('charges')) : (isset($object->fourn_charges) ?price($object->fourn_charges) : '')).'">';
753  print '</td>';
754  print '</tr>';
755  }
756  }
757 
758  // Product description of the supplier
759  if (!empty($conf->global->PRODUIT_FOURN_TEXTS))
760  {
761  //WYSIWYG Editor
762  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
763 
764  print '<tr>';
765  print '<td>'.$langs->trans('ProductSupplierDescription').'</td>';
766  print '<td>';
767 
768  $doleditor = new DolEditor('supplier_description', $object->desc_supplier, '', 160, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_4, '90%');
769  $doleditor->Create();
770 
771  print '</td>';
772  print '</tr>';
773  }
774 
775  // Extrafields
776  $extrafields->fetch_name_optionals_label("product_fournisseur_price");
777  $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
778  $extrafield_values = $extrafields->getOptionalsFromPost("product_fournisseur_price");
779  if (!empty($extralabels)) {
780  if (empty($rowid)) {
781  foreach ($extralabels as $key => $value) {
782  if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) {
783  if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]);
784 
785  print '<tr><td'.($extrafields->attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '').'>';
786  if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key]));
787  else print $langs->trans($value);
788  print '</td><td>'.$extrafields->showInputField($key, GETPOSTISSET('options_'.$key) ? $extrafield_values['options_'.$key] : '', '', '', '', '', 0, 'product_fournisseur_price').'</td></tr>';
789  }
790  }
791  } else {
792  $sql = "SELECT";
793  $sql .= " fk_object";
794  foreach ($extralabels as $key => $value) {
795  $sql .= ", ".$key;
796  }
797  $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields";
798  $sql .= " WHERE fk_object = ".$rowid;
799  $resql = $db->query($sql);
800  if ($resql) {
801  $obj = $db->fetch_object($resql);
802  foreach ($extralabels as $key => $value) {
803  if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) {
804  if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]);
805 
806  print '<tr><td'.($extrafields->attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '').'>';
807  if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key]));
808  else print $langs->trans($value);
809  print '</td><td>'.$extrafields->showInputField($key, GETPOSTISSET('options_'.$key) ? $extrafield_values['options_'.$key] : $obj->{$key}, '', '', '', '', 0, 'product_fournisseur_price');
810 
811  print '</td></tr>';
812  }
813  }
814  $db->free($resql);
815  }
816  }
817  }
818 
819  if (is_object($hookmanager))
820  {
821  $parameters = array('id_fourn'=>$id_fourn, 'prod_id'=>$object->id);
822  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
823  print $hookmanager->resPrint;
824  }
825 
826  print '</table>';
827 
829 
830  print '<div class="center">';
831  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
832  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
833  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
834  print '</div>';
835 
836  print '</form>';
837  }
838 
839  // Actions buttons
840 
841  print "\n<div class=\"tabsAction\">\n";
842 
843  if ($action != 'add_price' && $action != 'update_price')
844  {
845  $parameters = array();
846  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
847  if (empty($reshook))
848  {
849  if ($usercancreate)
850  {
851  print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$object->id.'&amp;action=add_price">';
852  print $langs->trans("AddSupplierPrice").'</a>';
853  }
854  }
855  }
856 
857  print "\n</div>\n";
858  print '<br>';
859 
860  if ($user->rights->fournisseur->lire) // Duplicate ? this check is already in the head of this file
861  {
862  $param = '';
863  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
864  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
865  $param .= '&ref='.urlencode($object->ref);
866 
867  $product_fourn = new ProductFournisseur($db);
868  $product_fourn_list = $product_fourn->list_product_fournisseur_price($object->id, $sortfield, $sortorder, $limit, $offset);
869  $product_fourn_list_all = $product_fourn->list_product_fournisseur_price($object->id, $sortfield, $sortorder, 0, 0);
870  $nbtotalofrecords = count($product_fourn_list_all);
871  $num = count($product_fourn_list);
872  if (($num + ($offset * $limit)) < $nbtotalofrecords) $num++;
873 
874  print_barre_liste($langs->trans('SupplierPrices'), $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit, 1);
875 
876  // Definition of fields for lists
877  // Some fields are missing because they are not included in the database query
878  $arrayfields = array(
879  'pfp.datec'=>array('label'=>$langs->trans("AppliedPricesFrom"), 'checked'=>1, 'position'=>1),
880  's.nom'=>array('label'=>$langs->trans("Suppliers"), 'checked'=>1, 'position'=>2),
881  'pfp.fk_availability'=>array('label'=>$langs->trans("Availability"), 'enabled' => !empty($conf->global->FOURN_PRODUCT_AVAILABILITY), 'checked'=>0, 'position'=>4),
882  'pfp.quantity'=>array('label'=>$langs->trans("QtyMin"), 'checked'=>1, 'position'=>5),
883  'pfp.unitprice'=>array('label'=>$langs->trans("UnitPriceHT"), 'checked'=>1, 'position'=>9),
884  'pfp.multicurrency_unitprice'=>array('label'=>$langs->trans("UnitPriceHTCurrency"), 'enabled' => $conf->multicurrency->enabled, 'checked'=>0, 'position'=>10),
885  'pfp.delivery_time_days'=>array('label'=>$langs->trans("NbDaysToDelivery"), 'checked'=>1, 'position'=>13),
886  'pfp.supplier_reputation'=>array('label'=>$langs->trans("ReputationForThisProduct"), 'checked'=>1, 'position'=>14),
887  'pfp.barcode'=>array('label'=>$langs->trans("BarcodeValue"), 'enabled' => $conf->barcode->enabled, 'checked'=>0, 'position'=>15),
888  'pfp.fk_barcode_type'=>array('label'=>$langs->trans("BarcodeType"), 'enabled' => $conf->barcode->enabled, 'checked'=>0, 'position'=>16),
889  'pfp.packaging'=>array('label'=>$langs->trans("PackagingForThisProduct"), 'enabled' => !empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING), 'checked'=>0, 'position'=>17),
890  'pfp.tms'=>array('label'=>$langs->trans("DateModification"), 'enabled' => $conf->barcode->enabled, 'checked'=>1, 'position'=>18),
891  );
892 
893  // fetch optionals attributes and labels
894  $extrafields->fetch_name_optionals_label("product_fournisseur_price");
895  $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
896 
897  if (!empty($extralabels)) {
898  foreach ($extralabels as $key => $value) {
899  // Show field if not hidden
900  if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {
901  $extratitle = $langs->trans($value);
902  $arrayfields['ef.'.$key] = array('label'=>$extratitle, 'checked'=>0, 'position'=>(end($arrayfields)['position'] + 1), 'langfile'=>$extrafields->attributes["product_fournisseur_price"]['langfile'][$key], 'help'=>$extrafields->attributes["product_fournisseur_price"]['help'][$key]);
903  }
904  }
905  }
906 
907  // Selection of new fields
908  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
909 
910  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
911  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
912 
913  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post" name="formulaire">';
914  print '<input type="hidden" name="token" value="'.newToken().'">';
915  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
916  print '<input type="hidden" name="action" value="list">';
917  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
918  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
919 
920  // Suppliers list title
921  print '<div class="div-table-responsive">';
922  print '<table class="liste centpercent">';
923 
924  $param = "&id=".$object->id;
925 
926  print '<tr class="liste_titre">';
927  if (!empty($arrayfields['pfp.datec']['checked'])) print_liste_field_titre("AppliedPricesFrom", $_SERVER["PHP_SELF"], "pfp.datec", "", $param, "", $sortfield, $sortorder, '', '', 1);
928  if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre("Suppliers", $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder, '', '', 1);
929  print_liste_field_titre("SupplierRef", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder, '', '', 1);
930  if (!empty($arrayfields['pfp.fk_availability']['checked'])) print_liste_field_titre("Availability", $_SERVER["PHP_SELF"], "pfp.fk_availability", "", $param, "", $sortfield, $sortorder);
931  if (!empty($arrayfields['pfp.quantity']['checked'])) print_liste_field_titre("QtyMin", $_SERVER["PHP_SELF"], "pfp.quantity", "", $param, '', $sortfield, $sortorder, 'right ');
932  print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
933  print_liste_field_titre("PriceQtyMinHT", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
934  if (!empty($conf->multicurrency->enabled)) print_liste_field_titre("PriceQtyMinHTCurrency", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
935  if (!empty($arrayfields['pfp.unitprice']['checked'])) print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "pfp.unitprice", "", $param, '', $sortfield, $sortorder, 'right ');
936  if (!empty($arrayfields['pfp.multicurrency_unitprice']['checked'])) print_liste_field_titre("UnitPriceHTCurrency", $_SERVER["PHP_SELF"], "pfp.multicurrency_unitprice", "", $param, '', $sortfield, $sortorder, 'right ');
937  if (!empty($conf->multicurrency->enabled)) print_liste_field_titre("Currency", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
938  print_liste_field_titre("DiscountQtyMin", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
939  if (!empty($arrayfields['pfp.delivery_time_days']['checked'])) print_liste_field_titre("NbDaysToDelivery", $_SERVER["PHP_SELF"], "pfp.delivery_time_days", "", $param, '', $sortfield, $sortorder, 'right ');
940  if (!empty($arrayfields['pfp.supplier_reputation']['checked'])) print_liste_field_titre("ReputationForThisProduct", $_SERVER["PHP_SELF"], "pfp.supplier_reputation", "", $param, '', $sortfield, $sortorder, 'center ');
941  if (!empty($arrayfields['pfp.barcode']['checked'])) print_liste_field_titre("BarcodeValue", $_SERVER["PHP_SELF"], "pfp.barcode", "", $param, '', $sortfield, $sortorder, 'center ');
942  if (!empty($arrayfields['pfp.fk_barcode_type']['checked'])) print_liste_field_titre("BarcodeType", $_SERVER["PHP_SELF"], "pfp.fk_barcode_type", "", $param, '', $sortfield, $sortorder, 'center ');
943  if (!empty($arrayfields['pfp.packaging']['checked'])) print_liste_field_titre("PackagingForThisProduct", $_SERVER["PHP_SELF"], "pfp.packaging", "", $param, 'align="center"', $sortfield, $sortorder);
944  if (!empty($arrayfields['pfp.tms']['checked'])) print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "pfp.tms", "", $param, '', $sortfield, $sortorder, 'right ', '', 1);
945 
946  // fetch optionals attributes and labels
947  $extrafields->fetch_name_optionals_label("product_fournisseur_price");
948  $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
949 
950  if (!empty($extralabels)) {
951  foreach ($extralabels as $key => $value) {
952  // Show field if not hidden
953  if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {
954  if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]);
955  if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key]));
956  else $extratitle = $langs->trans($value);
957  if (!empty($arrayfields['ef.'.$key]['checked'])) print_liste_field_titre($extratitle, $_SERVER["PHP_SELF"], 'ef.'.$key, '', $param, '', $sortfield, $sortorder, 'right ');
958  }
959  }
960  }
961 
962  if (is_object($hookmanager))
963  {
964  $parameters = array('id_fourn'=>$id_fourn, 'prod_id'=>$object->id);
965  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action);
966  }
967  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
968  print "</tr>\n";
969 
970  if (is_array($product_fourn_list))
971  {
972  foreach ($product_fourn_list as $productfourn)
973  {
974  print '<tr class="oddeven">';
975 
976  // Date from
977  if (!empty($arrayfields['pfp.datec']['checked'])) {
978  print '<td>'.dol_print_date(($productfourn->fourn_date_creation ? $productfourn->fourn_date_creation : $productfourn->date_creation), 'dayhour').'</td>';
979  }
980 
981  // Supplier
982  if (!empty($arrayfields['s.nom']['checked'])) {
983  print '<td class="tdoverflowmax200">'.$productfourn->getSocNomUrl(1, 'supplier').'</td>';
984  }
985 
986  // Supplier ref
987  if ($usercancreate) { // change required right here
988  print '<td class="left">'.$productfourn->getNomUrl().'</td>';
989  } else {
990  print '<td class="left">'.$productfourn->fourn_ref.'</td>';
991  }
992 
993  // Availability
994  if (!empty($arrayfields['pfp.fk_availability']['checked']))
995  {
996  $form->load_cache_availability();
997  $availability = $form->cache_availability[$productfourn->fk_availability]['label'];
998  print '<td class="left">'.$availability.'</td>';
999  }
1000 
1001  // Quantity
1002  if (!empty($arrayfields['pfp.quantity']['checked'])) {
1003  print '<td class="right">';
1004  print $productfourn->fourn_qty;
1005  // Units
1006  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1007  $unit = $object->getLabelOfUnit();
1008  if ($unit !== '') {
1009  print '&nbsp;&nbsp;'.$langs->trans($unit);
1010  }
1011  }
1012  print '</td>';
1013  }
1014 
1015  // VAT rate
1016  print '<td class="right">';
1017  print vatrate($productfourn->fourn_tva_tx, true);
1018  print '</td>';
1019 
1020  // Price for the quantity
1021  print '<td class="right">';
1022  print $productfourn->fourn_price ?price($productfourn->fourn_price) : "";
1023  print '</td>';
1024 
1025  if (!empty($conf->multicurrency->enabled)) {
1026  // Price for the quantity in currency
1027  print '<td class="right">';
1028  print $productfourn->fourn_multicurrency_price ? price($productfourn->fourn_multicurrency_price) : "";
1029  print '</td>';
1030  }
1031 
1032  // Unit price
1033  if (!empty($arrayfields['pfp.unitprice']['checked'])) {
1034  print '<td class="right">';
1035  print price($productfourn->fourn_unitprice);
1036  //print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):"&nbsp;");
1037  print '</td>';
1038  }
1039 
1040  // Unit price in currency
1041  if (!empty($arrayfields['pfp.multicurrency_unitprice']['checked'])) {
1042  print '<td class="right">';
1043  print price($productfourn->fourn_multicurrency_unitprice);
1044  print '</td>'; }
1045 
1046  // Currency
1047  if (!empty($conf->multicurrency->enabled)) {
1048  print '<td class="right">';
1049  print $productfourn->fourn_multicurrency_code ? currency_name($productfourn->fourn_multicurrency_code) : '';
1050  print '</td>';
1051  }
1052 
1053  // Discount
1054  print '<td class="right">';
1055  print price2num($productfourn->fourn_remise_percent).'%';
1056  print '</td>';
1057 
1058  // Delivery delay
1059  if (!empty($arrayfields['pfp.delivery_time_days']['checked'])) {
1060  print '<td class="right">';
1061  print $productfourn->delivery_time_days;
1062  print '</td>';
1063  }
1064 
1065  // Reputation
1066  if (!empty($arrayfields['pfp.supplier_reputation']['checked'])) {
1067  print '<td class="center">';
1068  if (!empty($productfourn->supplier_reputation) && !empty($object->reputations[$productfourn->supplier_reputation])) {
1069  print $object->reputations[$productfourn->supplier_reputation];
1070  }
1071  print'</td>';
1072  }
1073 
1074  // Barcode
1075  if (!empty($arrayfields['pfp.barcode']['checked'])) {
1076  print '<td align="right">';
1077  print $productfourn->supplier_barcode;
1078  print '</td>';
1079  }
1080 
1081  // Barcode type
1082  if (!empty($arrayfields['pfp.fk_barcode_type']['checked'])) {
1083  print '<td class="center">';
1084  $productfourn->barcode_type = !empty($productfourn->supplier_fk_barcode_type) ? $productfourn->supplier_fk_barcode_type : 0;
1085  $productfourn->fetch_barcode();
1086  print $productfourn->barcode_type_label ? $productfourn->barcode_type_label : ($productfourn->supplier_barcode ? '<div class="warning">'.$langs->trans("SetDefaultBarcodeType").'<div>' : '');
1087  print '</td>';
1088  }
1089 
1090  // Packaging
1091  if (!empty($arrayfields['pfp.packaging']['checked'])) {
1092  print '<td align="center">';
1093  print price2num($productfourn->packaging);
1094  print '</td>';
1095  }
1096 
1097  // Date
1098  if (!empty($arrayfields['pfp.tms']['checked'])) {
1099  print '<td align="right">';
1100  print dol_print_date(($productfourn->fourn_date_modification ? $productfourn->fourn_date_modification : $productfourn->date_modification), "dayhour");
1101  print '</td>';
1102  }
1103 
1104  // Extrafields
1105  if (!empty($extralabels)) {
1106  $sql = "SELECT";
1107  $sql .= " fk_object";
1108  foreach ($extralabels as $key => $value) {
1109  $sql .= ", ".$key;
1110  }
1111  $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields";
1112  $sql .= " WHERE fk_object = ".$productfourn->product_fourn_price_id;
1113  $resql = $db->query($sql);
1114  if ($resql) {
1115  if ($db->num_rows($resql) != 1) {
1116  foreach ($extralabels as $key => $value) {
1117  if (!empty($arrayfields['ef.'.$key]['checked']) && !empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {
1118  print "<td></td>";
1119  }
1120  }
1121  } else {
1122  $obj = $db->fetch_object($resql);
1123  foreach ($extralabels as $key => $value) {
1124  if (!empty($arrayfields['ef.'.$key]['checked']) && !empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {
1125  print '<td align="right">'.$extrafields->showOutputField($key, $obj->{$key})."</td>";
1126  }
1127  }
1128  }
1129  $db->free($resql);
1130  }
1131  }
1132 
1133  if (is_object($hookmanager))
1134  {
1135  $parameters = array('id_pfp'=>$productfourn->product_fourn_price_id, 'id_fourn'=>$id_fourn, 'prod_id'=>$object->id);
1136  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action);
1137  }
1138 
1139  // Modify-Remove
1140  print '<td class="center nowraponall">';
1141 
1142  if ($usercancreate)
1143  {
1144  print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$productfourn->fourn_id.'&amp;action=update_price&amp;rowid='.$productfourn->product_fourn_price_id.'">'.img_edit()."</a>";
1145  print ' &nbsp; ';
1146  print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$productfourn->fourn_id.'&amp;action=ask_remove_pf&amp;rowid='.$productfourn->product_fourn_price_id.'">'.img_picto($langs->trans("Remove"), 'delete').'</a>';
1147  }
1148 
1149  print '</td>';
1150 
1151  print '</tr>';
1152  }
1153  } else {
1154  dol_print_error($db);
1155  }
1156 
1157  print '</table>';
1158  print '</div>';
1159  print '</form>';
1160  }
1161  }
1162  }
1163 } else {
1164  print $langs->trans("ErrorUnknown");
1165 }
1166 
1167 // End of page
1168 llxFooter();
1169 $db->close();
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
Class to parse product price expressions.
const TYPE_SERVICE
Service.
const TYPE_PRODUCT
Regular product.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to manage suppliers.
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...
currency_name($code_iso, $withcode= '', $outputlangs=null)
Return label of currency or code+label.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class for accesing price expression table.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage barcode HTML.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) Si ...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
Class Currency.
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
Class to manage predefined suppliers products.
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:35