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