32 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
52 public $product_fourn_price_id;
65 public $delivery_time_days;
67 public $desc_supplier;
68 public $vatrate_supplier;
78 public $fourn_remise_percent;
81 public $product_fourn_id;
82 public $product_fourn_entity;
92 public $fk_availability;
94 public $fourn_unitprice;
96 public $fourn_tva_npr;
101 public $fk_supplier_price_expression;
103 public $supplier_reputation;
104 public $reputations = array();
107 public $fourn_multicurrency_id;
108 public $fourn_multicurrency_code;
109 public $fourn_multicurrency_tx;
110 public $fourn_multicurrency_price;
111 public $fourn_multicurrency_unitprice;
122 public $supplier_barcode;
133 public $supplier_fk_barcode_type;
148 $langs->load(
"suppliers");
149 $this->reputations = array(
'-1'=>
'',
'FAVORITE'=>$langs->trans(
'Favorite'),
'NOTTHGOOD'=>$langs->trans(
'NotTheGoodQualitySupplier'),
'DONOTORDER'=>$langs->trans(
'DoNotOrderThisProductToThisSupplier'));
166 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_fournisseur_price";
167 $sql .=
" WHERE fk_product = ".$this->id.
" AND fk_soc = ".$id_fourn;
169 dol_syslog(get_class($this).
"::remove_fournisseur", LOG_DEBUG);
170 $resql2 = $this->
db->query($sql);
173 $this->error = $this->
db->lasterror();
182 $this->
db->rollback();
205 $result = $this->
call_trigger(
'SUPPLIER_PRODUCT_BUYPRICE_DELETE', $user);
206 if ($result < 0) $error++;
211 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_fournisseur_price";
212 $sql .=
" WHERE rowid = ".$rowid;
214 dol_syslog(get_class($this).
"::remove_product_fournisseur_price", LOG_DEBUG);
218 $this->error = $this->
db->lasterror();
227 $this->
db->rollback();
262 public function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability,
$ref_fourn,
$tva_tx, $charges = 0, $remise_percent = 0, $remise = 0, $newnpr = 0, $delivery_time_days = 0, $supplier_reputation =
'', $localtaxes_array = array(), $newdefaultvatcode =
'', $multicurrency_buyprice = 0, $multicurrency_price_base_type =
'HT', $multicurrency_tx = 1, $multicurrency_code =
'', $desc_fourn =
'', $barcode =
'', $fk_barcode_type =
'')
265 global $conf, $langs;
269 if (empty($qty)) $qty = 0;
270 if (empty($buyprice)) $buyprice = 0;
271 if (empty($charges)) $charges = 0;
272 if (empty($availability)) $availability = 0;
273 if (empty($remise_percent)) $remise_percent = 0;
274 if (empty($supplier_reputation) || $supplier_reputation == -1) $supplier_reputation =
'';
275 if ($delivery_time_days !=
'' && !is_numeric($delivery_time_days)) $delivery_time_days =
'';
276 if ($price_base_type ==
'TTC')
279 $buyprice = $buyprice / (1 + ($ttx / 100));
283 $multicurrency_unitBuyPrice = null;
284 $fk_multicurrency = null;
285 if (!empty($conf->multicurrency->enabled)) {
286 if (empty($multicurrency_tx)) $multicurrency_tx = 1;
287 if (empty($multicurrency_buyprice)) $multicurrency_buyprice = 0;
288 if ($multicurrency_price_base_type ==
'TTC')
291 $multicurrency_buyprice = $multicurrency_buyprice / (1 + ($ttx / 100));
293 $multicurrency_buyprice =
price2num($multicurrency_buyprice,
'MU');
294 $multicurrency_unitBuyPrice =
price2num($multicurrency_buyprice / $qty,
'MU');
296 $buyprice = $multicurrency_buyprice / $multicurrency_tx;
303 $unitBuyPrice =
price2num($buyprice / $qty,
'MU');
305 $packaging =
price2num(((empty($this->packaging) || $this->packaging < $qty) ? $qty : $this->packaging),
'MS');
312 if (count($localtaxes_array) > 0)
314 $localtaxtype1 = $localtaxes_array[
'0'];
315 $localtax1 = $localtaxes_array[
'1'];
316 $localtaxtype2 = $localtaxes_array[
'2'];
317 $localtax2 = $localtaxes_array[
'3'];
319 $localtaxtype1 =
'0';
321 $localtaxtype2 =
'0';
324 if (empty($localtax1)) $localtax1 = 0;
325 if (empty($localtax2)) $localtax2 = 0;
328 if ($buyprice !=
'' && !is_numeric($buyprice))
334 if ($this->product_fourn_price_id > 0)
338 if (is_array($logPrices) && count($logPrices) == 0)
340 $currentPfp =
new self($this->db);
341 $result = $currentPfp->fetch_product_fournisseur_price($this->product_fourn_price_id);
342 if ($result > 0 && $currentPfp->fourn_price != 0)
344 $currentPfpUser =
new User($this->
db);
345 $result = $currentPfpUser->fetch($currentPfp->user_id);
347 $currentPfp->logPrice(
349 $currentPfp->date_creation,
350 $currentPfp->fourn_price,
351 $currentPfp->fourn_qty,
352 $currentPfp->fourn_multicurrency_price,
353 $currentPfp->fourn_multicurrency_unitprice,
354 $currentPfp->fourn_multicurrency_tx,
355 $currentPfp->fourn_multicurrency_id,
356 $currentPfp->fourn_multicurrency_code
361 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_fournisseur_price";
362 $sql .=
" SET fk_user = ".$user->id.
" ,";
363 $sql .=
" ref_fourn = '".$this->db->escape(
$ref_fourn).
"',";
364 $sql .=
" desc_fourn = '".$this->db->escape($desc_fourn).
"',";
365 $sql .=
" price = ".$buyprice.
",";
366 $sql .=
" quantity = ".$qty.
",";
367 $sql .=
" remise_percent = ".$remise_percent.
",";
368 $sql .=
" remise = ".$remise.
",";
369 $sql .=
" unitprice = ".$unitBuyPrice.
",";
370 $sql .=
" fk_availability = ".$availability.
",";
371 $sql .=
" multicurrency_price = ".(isset($multicurrency_buyprice) ?
"'".$this->db->escape(
price2num($multicurrency_buyprice)).
"'" :
'null').
",";
372 $sql .=
" multicurrency_unitprice = ".(isset($multicurrency_unitBuyPrice) ?
"'".$this->db->escape(
price2num($multicurrency_unitBuyPrice)).
"'" :
'null').
",";
373 $sql .=
" multicurrency_tx = ".(isset($multicurrency_tx) ?
"'".$this->db->escape($multicurrency_tx).
"'" :
'1').
",";
374 $sql .=
" fk_multicurrency = ".(isset($fk_multicurrency) ?
"'".$this->db->escape($fk_multicurrency).
"'" :
'null').
",";
375 $sql .=
" multicurrency_code = ".(isset($multicurrency_code) ?
"'".$this->db->escape($multicurrency_code).
"'" :
'null').
",";
376 $sql .=
" entity = ".$conf->entity.
",";
377 $sql .=
" tva_tx = ".price2num(
$tva_tx).
",";
383 $sql .=
" default_vat_code=".($newdefaultvatcode ?
"'".$this->db->escape($newdefaultvatcode).
"'" :
"null").
",";
384 $sql .=
" info_bits = ".$newnpr.
",";
385 $sql .=
" charges = ".$charges.
",";
386 $sql .=
" delivery_time_days = ".($delivery_time_days !=
'' ? $delivery_time_days :
'null').
",";
387 $sql .=
" supplier_reputation = ".(empty($supplier_reputation) ?
'NULL' :
"'".$this->db->escape($supplier_reputation).
"'").
",";
388 $sql .=
" barcode = ".(empty($barcode) ?
'NULL' :
"'".$this->db->escape($barcode).
"'").
",";
389 $sql .=
" fk_barcode_type = ".(empty($fk_barcode_type) ?
'NULL' :
"'".$this->db->escape($fk_barcode_type).
"'");
390 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .=
", packaging = ".(empty($packaging) ? 1 : $packaging);
391 $sql .=
" WHERE rowid = ".$this->product_fourn_price_id;
394 dol_syslog(get_class($this).
'::update_buyprice update knowing id of line = product_fourn_price_id = '.$this->product_fourn_price_id, LOG_DEBUG);
399 $result = $this->
call_trigger(
'SUPPLIER_PRODUCT_BUYPRICE_UPDATE', $user);
400 if ($result < 0) $error++;
402 if (!$error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG))
404 $result = $this->
logPrice($user, $now, $buyprice, $qty, $multicurrency_buyprice, $multicurrency_unitBuyPrice, $multicurrency_tx, $fk_multicurrency, $multicurrency_code);
412 return $this->product_fourn_price_id;
414 $this->
db->rollback();
418 $this->error = $this->
db->error().
" sql=".$sql;
419 $this->
db->rollback();
423 dol_syslog(get_class($this).
'::update_buyprice without knowing id of line, so we delete from company, quantity and supplier_ref and insert again', LOG_DEBUG);
426 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_fournisseur_price";
427 $sql .=
" WHERE fk_soc = ".$fourn->id.
" AND ref_fourn = '".$this->
db->escape(
$ref_fourn).
"' AND quantity = ".$qty.
" AND entity = ".$conf->entity;
431 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_fournisseur_price(";
432 $sql .=
" multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,";
433 $sql .=
"datec, fk_product, fk_soc, ref_fourn, desc_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, fk_availability, default_vat_code, info_bits, entity, delivery_time_days, supplier_reputation, barcode, fk_barcode_type)";
434 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .=
", packaging";
436 $sql .= (isset($multicurrency_buyprice) ?
"'".$this->db->escape(
price2num($multicurrency_buyprice)).
"'" :
'null').
",";
437 $sql .= (isset($multicurrency_unitBuyPrice) ?
"'".$this->db->escape(
price2num($multicurrency_unitBuyPrice)).
"'" :
'null').
",";
438 $sql .= (isset($multicurrency_tx) ?
"'".$this->db->escape($multicurrency_tx).
"'" :
'1').
",";
439 $sql .= (isset($fk_multicurrency) ?
"'".$this->db->escape($fk_multicurrency).
"'" :
'null').
",";
440 $sql .= (isset($multicurrency_code) ?
"'".$this->db->escape($multicurrency_code).
"'" :
'null').
",";
441 $sql .=
" '".$this->db->idate($now).
"',";
442 $sql .=
" ".$this->id.
",";
443 $sql .=
" ".$fourn->id.
",";
444 $sql .=
" '".$this->db->escape(
$ref_fourn).
"',";
445 $sql .=
" '".$this->db->escape($desc_fourn).
"',";
446 $sql .=
" ".$user->id.
",";
447 $sql .=
" ".$buyprice.
",";
448 $sql .=
" ".$qty.
",";
449 $sql .=
" ".$remise_percent.
",";
450 $sql .=
" ".$remise.
",";
451 $sql .=
" ".$unitBuyPrice.
",";
452 $sql .=
" ".$tva_tx.
",";
453 $sql .=
" ".$charges.
",";
454 $sql .=
" ".$availability.
",";
455 $sql .=
" ".($newdefaultvatcode ?
"'".$this->db->escape($newdefaultvatcode).
"'" :
"null").
",";
456 $sql .=
" ".$newnpr.
",";
457 $sql .= $conf->entity.
",";
458 $sql .= ($delivery_time_days !=
'' ? $delivery_time_days :
'null').
",";
459 $sql .= (empty($supplier_reputation) ?
'NULL' :
"'".$this->db->escape($supplier_reputation).
"'").
",";
460 $sql .= (empty($barcode) ?
'NULL' :
"'".$this->db->escape($barcode).
"'").
",";
461 $sql .= (empty($fk_barcode_type) ?
'NULL' :
"'".$this->db->escape($fk_barcode_type).
"'");
462 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .=
", ".(empty($this->packaging) ? 1 : $this->
db->escape($this->packaging));
465 $this->product_fourn_price_id = 0;
469 $this->product_fourn_price_id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"product_fournisseur_price");
474 if (!$error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG)) {
477 $result = $this->
logPrice($user, $now, $buyprice, $qty, $multicurrency_buyprice, $multicurrency_unitBuyPrice, $multicurrency_tx, $fk_multicurrency, $multicurrency_code);
485 $result = $this->
call_trigger(
'SUPPLIER_PRODUCT_BUYPRICE_CREATE', $user);
492 return $this->product_fourn_price_id;
494 $this->
db->rollback();
498 $this->error = $this->
db->lasterror().
" sql=".$sql;
499 $this->
db->rollback();
503 $this->error = $this->
db->lasterror().
" sql=".$sql;
504 $this->
db->rollback();
523 $sql =
"SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.default_vat_code, pfp.info_bits as fourn_tva_npr, pfp.fk_availability,";
524 $sql .=
" pfp.fk_soc, pfp.ref_fourn, pfp.desc_fourn, pfp.fk_product, pfp.charges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,";
525 $sql .=
" pfp.supplier_reputation, pfp.fk_user, pfp.datec,";
526 $sql .=
" pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
527 $sql .=
" pfp.barcode, pfp.fk_barcode_type, pfp.packaging,";
528 $sql .=
" p.ref as product_ref";
529 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_fournisseur_price as pfp, ".MAIN_DB_PREFIX.
"product as p";
530 $sql .=
" WHERE pfp.rowid = ".(int) $rowid;
531 $sql .=
" AND pfp.fk_product = p.rowid";
533 dol_syslog(get_class($this).
"::fetch_product_fournisseur_price", LOG_DEBUG);
537 $obj = $this->
db->fetch_object(
$resql);
540 $this->product_fourn_price_id = $rowid;
541 $this->
id = $obj->fk_product;
543 $this->fk_product = $obj->fk_product;
544 $this->product_id = $obj->fk_product;
545 $this->product_ref = $obj->product_ref;
547 $this->fourn_id = $obj->fk_soc;
548 $this->fourn_ref = $obj->ref_fourn;
549 $this->ref_supplier = $obj->ref_fourn;
550 $this->desc_supplier = $obj->desc_fourn;
551 $this->fourn_price = $obj->price;
552 $this->fourn_charges = $obj->charges;
553 $this->fourn_qty = $obj->quantity;
554 $this->fourn_remise_percent = $obj->remise_percent;
555 $this->fourn_remise = $obj->remise;
556 $this->fourn_unitprice = $obj->unitprice;
557 $this->fourn_tva_tx = $obj->tva_tx;
558 $this->fourn_tva_npr = $obj->fourn_tva_npr;
560 $this->fk_availability = $obj->fk_availability;
561 $this->delivery_time_days = $obj->delivery_time_days;
562 $this->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
563 $this->supplier_reputation = $obj->supplier_reputation;
564 $this->default_vat_code = $obj->default_vat_code;
565 $this->user_id = $obj->fk_user;
566 $this->date_creation = $this->
db->jdate($obj->datec);
567 $this->fourn_multicurrency_price = $obj->multicurrency_price;
568 $this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
569 $this->fourn_multicurrency_tx = $obj->multicurrency_tx;
570 $this->fourn_multicurrency_id = $obj->fk_multicurrency;
571 $this->fourn_multicurrency_code = $obj->multicurrency_code;
572 if (!empty($conf->barcode->enabled)) {
573 $this->fourn_barcode = $obj->barcode;
574 $this->fourn_fk_barcode_type = $obj->fk_barcode_type;
575 $this->supplier_barcode = $obj->barcode;
576 $this->supplier_fk_barcode_type = $obj->fk_barcode_type;
579 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
580 $this->packaging = $obj->packaging;
581 if ($this->packaging < $this->fourn_qty) $this->packaging = $this->fourn_qty;
584 if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression))
587 $price_result = $priceparser->parseProductSupplier($this);
588 if ($price_result >= 0) {
589 $this->fourn_price = $price_result;
591 if ($this->fourn_qty != 0)
593 $this->fourn_unitprice =
price2num($this->fourn_price / $this->fourn_qty,
'MU');
595 $this->fourn_unitprice =
"";
605 $this->error = $this->
db->lasterror();
627 $sql =
"SELECT s.nom as supplier_name, s.rowid as fourn_id, p.ref as product_ref,";
628 $sql .=
" pfp.rowid as product_fourn_pri_id, pfp.entity, pfp.ref_fourn, pfp.desc_fourn, pfp.fk_product as product_fourn_id, pfp.fk_supplier_price_expression,";
629 $sql .=
" pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability, pfp.charges, pfp.info_bits, pfp.delivery_time_days, pfp.supplier_reputation,";
630 $sql .=
" pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code, pfp.datec, pfp.tms,";
631 $sql .=
" pfp.barcode, pfp.fk_barcode_type";
632 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .=
", pfp.packaging";
633 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_fournisseur_price as pfp, ".MAIN_DB_PREFIX.
"product as p, ".MAIN_DB_PREFIX.
"societe as s";
634 $sql .=
" WHERE pfp.entity IN (".getEntity(
'productsupplierprice').
")";
635 $sql .=
" AND pfp.fk_soc = s.rowid AND pfp.fk_product = p.rowid";
636 $sql .=
" AND s.status=1";
637 $sql .=
" AND pfp.fk_product = ".$prodid;
638 if (empty($sortfield)) $sql .=
" ORDER BY s.nom, pfp.quantity, pfp.price";
639 else $sql .= $this->
db->order($sortfield, $sortorder);
640 $sql .= $this->
db->plimit($limit, $offset);
641 dol_syslog(get_class($this).
"::list_product_fournisseur_price", LOG_DEBUG);
648 while ($record = $this->
db->fetch_array(
$resql))
653 $prodfourn->product_ref = $record[
"product_ref"];
654 $prodfourn->product_fourn_price_id = $record[
"product_fourn_pri_id"];
655 $prodfourn->product_fourn_id = $record[
"product_fourn_id"];
656 $prodfourn->product_fourn_entity = $record[
"entity"];
657 $prodfourn->ref_supplier = $record[
"ref_fourn"];
658 $prodfourn->fourn_ref = $record[
"ref_fourn"];
659 $prodfourn->desc_supplier = $record[
"desc_fourn"];
660 $prodfourn->fourn_price = $record[
"price"];
661 $prodfourn->fourn_qty = $record[
"quantity"];
662 $prodfourn->fourn_remise_percent = $record[
"remise_percent"];
663 $prodfourn->fourn_remise = $record[
"remise"];
664 $prodfourn->fourn_unitprice = $record[
"unitprice"];
665 $prodfourn->fourn_charges = $record[
"charges"];
666 $prodfourn->fourn_tva_tx = $record[
"tva_tx"];
667 $prodfourn->fourn_id = $record[
"fourn_id"];
668 $prodfourn->fourn_name = $record[
"supplier_name"];
669 $prodfourn->fk_availability = $record[
"fk_availability"];
670 $prodfourn->delivery_time_days = $record[
"delivery_time_days"];
671 $prodfourn->id = $prodid;
672 $prodfourn->fourn_tva_npr = $record[
"info_bits"];
673 $prodfourn->fk_supplier_price_expression = $record[
"fk_supplier_price_expression"];
674 $prodfourn->supplier_reputation = $record[
"supplier_reputation"];
675 $prodfourn->fourn_date_creation = $this->
db->jdate($record[
'datec']);
676 $prodfourn->fourn_date_modification = $this->
db->jdate($record[
'tms']);
678 $prodfourn->fourn_multicurrency_price = $record[
"multicurrency_price"];
679 $prodfourn->fourn_multicurrency_unitprice = $record[
"multicurrency_unitprice"];
680 $prodfourn->fourn_multicurrency_tx = $record[
"multicurrency_tx"];
681 $prodfourn->fourn_multicurrency_id = $record[
"fk_multicurrency"];
682 $prodfourn->fourn_multicurrency_code = $record[
"multicurrency_code"];
684 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
685 $prodfourn->packaging = $record[
"packaging"];
686 if ($prodfourn->packaging < $prodfourn->fourn_qty) $prodfourn->packaging = $prodfourn->fourn_qty;
689 if (!empty($conf->barcode->enabled)) {
690 $prodfourn->supplier_barcode = $record[
"barcode"];
691 $prodfourn->supplier_fk_barcode_type = $record[
"fk_barcode_type"];
694 if (!empty($conf->dynamicprices->enabled) && !empty($prodfourn->fk_supplier_price_expression)) {
696 $price_result = $priceparser->parseProductSupplier($prodfourn);
697 if ($price_result >= 0) {
698 $prodfourn->fourn_price = $price_result;
699 $prodfourn->fourn_unitprice = null;
703 if (!isset($prodfourn->fourn_unitprice))
705 if ($prodfourn->fourn_qty != 0)
707 $prodfourn->fourn_unitprice =
price2num($prodfourn->fourn_price / $prodfourn->fourn_qty,
'MU');
709 $prodfourn->fourn_unitprice =
"";
713 $retarray[] = $prodfourn;
719 $this->error = $this->
db->error();
740 dol_syslog(
"Warning function find_min_price_product_fournisseur were called with prodid empty. May be a bug.", LOG_WARNING);
744 $this->product_fourn_price_id =
'';
745 $this->product_fourn_id =
'';
746 $this->fourn_ref =
'';
747 $this->fourn_price =
'';
748 $this->fourn_qty =
'';
749 $this->fourn_remise_percent =
'';
750 $this->fourn_remise =
'';
751 $this->fourn_unitprice =
'';
752 $this->fourn_id =
'';
753 $this->fourn_name =
'';
754 $this->delivery_time_days =
'';
757 $this->fourn_multicurrency_price =
'';
758 $this->fourn_multicurrency_unitprice =
'';
759 $this->fourn_multicurrency_tx =
'';
760 $this->fourn_multicurrency_id =
'';
761 $this->fourn_multicurrency_code =
'';
763 $sql =
"SELECT s.nom as supplier_name, s.rowid as fourn_id,";
764 $sql .=
" pfp.rowid as product_fourn_price_id, pfp.ref_fourn,";
765 $sql .=
" pfp.price, pfp.quantity, pfp.unitprice, pfp.tva_tx, pfp.charges,";
766 $sql .=
" pfp.remise, pfp.remise_percent, pfp.fk_supplier_price_expression, pfp.delivery_time_days";
767 $sql .=
" ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code";
768 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"product_fournisseur_price as pfp";
769 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
770 $sql .=
" AND pfp.entity = ".$conf->entity;
771 $sql .=
" AND pfp.fk_product = ".$prodid;
772 $sql .=
" AND pfp.fk_soc = s.rowid";
773 $sql .=
" AND s.status = 1";
774 if ($qty > 0) $sql .=
" AND pfp.quantity <= ".$qty;
775 if ($socid > 0) $sql .=
' AND pfp.fk_soc = '.$socid;
777 dol_syslog(get_class($this).
"::find_min_price_product_fournisseur", LOG_DEBUG);
782 $record_array = array();
785 while ($record = $this->
db->fetch_array(
$resql))
787 $record_array[] = $record;
790 if (count($record_array) == 0)
796 foreach ($record_array as $record)
798 $fourn_price = $record[
"price"];
800 $fourn_unitprice = $record[
"unitprice"] * (1 - $record[
"remise_percent"] / 100) - $record[
"remise"];
801 if (!empty($conf->dynamicprices->enabled) && !empty($record[
"fk_supplier_price_expression"])) {
803 $prod_supplier->product_fourn_price_id = $record[
"product_fourn_price_id"];
804 $prod_supplier->id = $prodid;
805 $prod_supplier->fourn_qty = $record[
"quantity"];
806 $prod_supplier->fourn_tva_tx = $record[
"tva_tx"];
807 $prod_supplier->fk_supplier_price_expression = $record[
"fk_supplier_price_expression"];
809 $price_result = $priceparser->parseProductSupplier($prod_supplier);
810 if ($price_result >= 0) {
811 $fourn_price =
price2num($price_result,
'MU');
812 if ($record[
"quantity"] != 0)
814 $fourn_unitprice =
price2num($fourn_price / $record[
"quantity"],
'MU');
816 $fourn_unitprice = $fourn_price;
820 if ($fourn_unitprice < $min || $min == -1)
822 $this->product_fourn_price_id = $record[
"product_fourn_price_id"];
823 $this->ref_supplier = $record[
"ref_fourn"];
824 $this->ref_fourn = $record[
"ref_fourn"];
825 $this->fourn_ref = $record[
"ref_fourn"];
826 $this->fourn_price = $fourn_price;
827 $this->fourn_qty = $record[
"quantity"];
828 $this->fourn_remise_percent = $record[
"remise_percent"];
829 $this->fourn_remise = $record[
"remise"];
830 $this->fourn_unitprice = $record[
"unitprice"];
831 $this->fourn_charges = $record[
"charges"];
832 $this->fourn_tva_tx = $record[
"tva_tx"];
833 $this->fourn_id = $record[
"fourn_id"];
834 $this->fourn_name = $record[
"supplier_name"];
835 $this->delivery_time_days = $record[
"delivery_time_days"];
836 $this->fk_supplier_price_expression = $record[
"fk_supplier_price_expression"];
838 $this->fourn_multicurrency_price = $record[
"multicurrency_price"];
839 $this->fourn_multicurrency_unitprice = $record[
"multicurrency_unitprice"];
840 $this->fourn_multicurrency_tx = $record[
"multicurrency_tx"];
841 $this->fourn_multicurrency_id = $record[
"fk_multicurrency"];
842 $this->fourn_multicurrency_code = $record[
"multicurrency_code"];
843 $min = $fourn_unitprice;
851 $this->error = $this->
db->error();
868 $expression_id = $expression_id != 0 ? $expression_id :
'NULL';
870 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_fournisseur_price";
871 $sql .=
" SET fk_supplier_price_expression = ".$expression_id;
872 $sql .=
" WHERE rowid = ".$this->product_fourn_price_id;
874 dol_syslog(get_class($this).
"::setSupplierPriceExpression", LOG_DEBUG);
882 $this->error = $this->
db->error().
" sql=".$sql;
883 $this->
db->rollback();
898 public function getSocNomUrl($withpicto = 0, $option =
'supplier', $maxlen = 0, $notooltip = 0)
901 $thirdparty->fetch($this->fourn_id);
903 return $thirdparty->getNomUrl($withpicto, $option, $maxlen, $notooltip);
924 $langs->load(
"suppliers");
925 if (count($productFournList) > 0) {
926 $out .=
'<table class="nobordernopadding" width="100%">';
927 $out .=
'<tr><td class="liste_titre right">'.($showunitprice ? $langs->trans(
"Price").
' '.$langs->trans(
"HT") :
'').
'</td>';
928 $out .=
'<td class="liste_titre right">'.($showunitprice ? $langs->trans(
"QtyMin") :
'').
'</td>';
929 $out .=
'<td class="liste_titre">'.$langs->trans(
"Supplier").
'</td>';
930 $out .=
'<td class="liste_titre">'.$langs->trans(
"SupplierRef").
'</td></tr>';
931 foreach ($productFournList as $productFourn) {
932 $out .=
'<tr><td class="right">'.($showunitprice ?
price($productFourn->fourn_unitprice * (1 - $productFourn->fourn_remise_percent / 100) - $productFourn->fourn_remise) :
'').
'</td>';
933 $out .=
'<td class="right">'.($showunitprice ? $productFourn->fourn_qty :
'').
'</td>';
934 $out .=
'<td>'.$productFourn->getSocNomUrl(1,
'supplier', $maxlen, $notooltip).
'</td>';
935 $out .=
'<td>'.$productFourn->fourn_ref.
'<td></tr>';
939 $out = ($showunitprice ?
price($this->fourn_unitprice * (1 - $this->fourn_remise_percent / 100) + $this->fourn_remise).
' '.$langs->trans(
"HT").
' (' :
'').($showsuptitle ? $langs->trans(
"Supplier").
': ' :
'').$this->
getSocNomUrl(1,
'supplier', $maxlen, $notooltip).
' / '.$langs->trans(
"SupplierRef").
': '.$this->fourn_ref.($showunitprice ?
')' :
'');
955 'product_fournisseur_price'
974 $sql .=
" u.lastname,";
975 $sql .=
" pfpl.rowid, pfp.ref_fourn as supplier_ref, pfpl.datec,";
976 $sql .=
" pfpl.price, pfpl.quantity,";
977 $sql .=
" pfpl.fk_multicurrency, pfpl.multicurrency_code, pfpl.multicurrency_tx, pfpl.multicurrency_price, pfpl.multicurrency_unitprice";
978 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_fournisseur_price_log as pfpl,";
979 $sql .=
" ".MAIN_DB_PREFIX.
"product_fournisseur_price as pfp,";
980 $sql .=
" ".MAIN_DB_PREFIX.
"user as u";
981 $sql .=
" WHERE pfp.entity IN (".getEntity(
'productprice').
")";
982 $sql .=
" AND pfpl.fk_user = u.rowid";
983 $sql .=
" AND pfp.rowid = pfpl.fk_product_fournisseur";
984 $sql .=
" AND pfpl.fk_product_fournisseur = ".$product_fourn_price_id;
985 if (empty($sortfield)) $sql .=
" ORDER BY pfpl.datec";
986 else $sql .= $this->
db->order($sortfield, $sortorder);
987 $sql .= $this->
db->plimit($limit, $offset);
988 dol_syslog(get_class($this).
"::list_product_fournisseur_price_log", LOG_DEBUG);
995 while ($obj = $this->
db->fetch_object(
$resql))
998 $tmparray[
'rowid'] = $obj->rowid;
999 $tmparray[
'supplier_ref'] = $obj->supplier_ref;
1000 $tmparray[
'datec'] = $this->
db->jdate($obj->datec);
1001 $tmparray[
'lastname'] = $obj->lastname;
1002 $tmparray[
'price'] = $obj->price;
1003 $tmparray[
'quantity'] = $obj->quantity;
1004 $tmparray[
'fk_multicurrency'] = $obj->fk_multicurrency;
1005 $tmparray[
'multicurrency_code'] = $obj->multicurrency_code;
1006 $tmparray[
'multicurrency_tx'] = $obj->multicurrency_tx;
1007 $tmparray[
'multicurrency_price'] = $obj->multicurrency_price;
1008 $tmparray[
'multicurrency_unitprice'] = $obj->multicurrency_unitprice;
1010 $retarray[] = $tmparray;
1016 $this->error = $this->
db->error();
1030 global $conf, $langs;
1033 $langs->load(
"suppliers");
1034 if (count($productFournLogList) > 0) {
1035 $out .=
'<table class="noborder centpercent">';
1036 $out .=
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Date").
'</td>';
1037 $out .=
'<td class="liste_titre right">'.$langs->trans(
"Price").
'</td>';
1039 $out .=
'<td class="liste_titre">'.$langs->trans(
"User").
'</td></tr>';
1040 foreach ($productFournLogList as $productFournLog) {
1041 $out .=
'<tr><td class="right">'.dol_print_date($productFournLog[
'datec'],
'dayhour',
'tzuser').
'</td>';
1042 $out .=
'<td class="right">'.price($productFournLog[
'price'], 0, $langs, 1, -1, -1, $conf->currency);
1043 if ($productFournLog[
'multicurrency_code'] != $conf->currency) {
1044 $out .=
' ('.price($productFournLog[
'multicurrency_price'], 0, $langs, 1, -1, -1, $productFournLog[
'multicurrency_code']).
')';
1048 $out .=
'<td>'.$productFournLog[
'lastname'].
'</td></tr>';
1067 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1069 global $db, $conf, $langs;
1071 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
1075 if (!empty($this->entity)) {
1076 $tmpphoto = $this->
show_photos(
'product', $conf->product->multidir_output[$this->entity], 1, 1, 0, 0, 0, 80);
1077 if ($this->nbphoto > 0) {
1078 $label .=
'<div class="photointooltip">';
1079 $label .= $tmpphoto;
1080 $label .=
'</div><div style="clear: both;"></div>';
1085 $label .=
img_picto(
'',
'product').
' <u class="paddingrightonly">'.$langs->trans(
"Product").
'</u>';
1087 $label .=
img_picto(
'',
'service').
' <u class="paddingrightonly">'.$langs->trans(
"Service").
'</u>';
1089 if (isset($this->status) && isset($this->status_buy)) {
1090 $label .=
' '.$this->getLibStatut(5, 0);
1091 $label .=
' '.$this->getLibStatut(5, 1);
1094 if (!empty($this->ref)) {
1095 $label .=
'<br><b>'.$langs->trans(
'ProductRef').
':</b> '.($this->ref ? $this->ref : $this->product_ref);
1097 if (!empty($this->label)) {
1098 $label .=
'<br><b>'.$langs->trans(
'ProductLabel').
':</b> '.$this->label;
1100 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
1103 if (!empty($conf->productbatch->enabled)) {
1104 $langs->load(
"productbatch");
1105 $label .=
"<br><b>".$langs->trans(
"ManageLotSerial").
'</b>: '.$this->
getLibStatut(0, 2);
1108 if (!empty($conf->barcode->enabled)) {
1109 $label .=
'<br><b>'.$langs->trans(
'BarCode').
':</b> '.$this->barcode;
1114 if ($this->weight) {
1115 $label .=
"<br><b>".$langs->trans(
"Weight").
'</b>: '.$this->weight.
' '.
measuringUnitString(0,
"weight", $this->weight_units);
1118 if ($this->length) {
1119 $labelsize .= ($labelsize ?
" - " :
"").
"<b>".$langs->trans(
"Length").
'</b>: '.$this->length.
' '.
measuringUnitString(0,
'size', $this->length_units);
1122 $labelsize .= ($labelsize ?
" - " :
"").
"<b>".$langs->trans(
"Width").
'</b>: '.$this->width.
' '.
measuringUnitString(0,
'size', $this->width_units);
1124 if ($this->height) {
1125 $labelsize .= ($labelsize ?
" - " :
"").
"<b>".$langs->trans(
"Height").
'</b>: '.$this->height.
' '.
measuringUnitString(0,
'size', $this->height_units);
1127 if ($labelsize) $label .=
"<br>".$labelsize;
1129 $labelsurfacevolume =
"";
1130 if ($this->surface) {
1131 $labelsurfacevolume .= ($labelsurfacevolume ?
" - " :
"").
"<b>".$langs->trans(
"Surface").
'</b>: '.$this->surface.
' '.
measuringUnitString(0,
'surface', $this->surface_units);
1133 if ($this->volume) {
1134 $labelsurfacevolume .= ($labelsurfacevolume ?
" - " :
"").
"<b>".$langs->trans(
"Volume").
'</b>: '.$this->volume.
' '.
measuringUnitString(0,
'volume', $this->volume_units);
1136 if ($labelsurfacevolume) $label .=
"<br>".$labelsurfacevolume;
1139 if (!empty($conf->accounting->enabled) && $this->status) {
1140 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1141 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancySellCode').
':</b> '.
length_accountg($this->accountancy_code_sell);
1142 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancySellIntraCode').
':</b> '.
length_accountg($this->accountancy_code_sell_intra);
1143 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancySellExportCode').
':</b> '.
length_accountg($this->accountancy_code_sell_export);
1145 if (!empty($conf->accounting->enabled) && $this->status_buy) {
1146 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1147 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyCode').
':</b> '.
length_accountg($this->accountancy_code_buy);
1148 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyIntraCode').
':</b> '.
length_accountg($this->accountancy_code_buy_intra);
1149 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyExportCode').
':</b> '.
length_accountg($this->accountancy_code_buy_export);
1153 if (is_array($logPrices) && count($logPrices) > 0) {
1154 $label .=
'<br><br>';
1155 $label .=
'<u>'.$langs->trans(
"History").
'</u>';
1159 $url =
dol_buildpath(
'/product/fournisseurs.php', 1).
'?id='.$this->
id.
'&action=add_price&socid='.$this->fourn_id.
'&rowid='.$this->product_fourn_price_id;
1161 if ($option !=
'nolink')
1164 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1165 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
1166 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
1170 if (empty($notooltip))
1172 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1174 $label = $langs->trans(
"SupplierRef");
1175 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1177 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1178 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1179 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1181 $linkstart =
'<a href="'.$url.
'"';
1182 $linkstart .= $linkclose.
'>';
1185 $result .= $linkstart;
1186 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1187 if ($withpicto != 2) $result .= $this->ref.($this->ref_supplier ?
' ('.$this->ref_supplier.
')' :
'');
1188 $result .= $linkend;
1209 private function logPrice($user, $datec, $buyprice, $qty, $multicurrency_buyprice = null, $multicurrency_unitBuyPrice = null, $multicurrency_tx = null, $fk_multicurrency = null, $multicurrency_code = null)
1212 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_fournisseur_price_log(";
1213 $sql .=
" multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,";
1214 $sql .=
"datec, fk_product_fournisseur,fk_user,price,quantity)";
1216 $sql .= (isset($multicurrency_buyprice) ?
"'".$this->db->escape(
price2num($multicurrency_buyprice)).
"'" :
'null').
",";
1217 $sql .= (isset($multicurrency_unitBuyPrice) ?
"'".$this->db->escape(
price2num($multicurrency_unitBuyPrice)).
"'" :
'null').
",";
1218 $sql .= (isset($multicurrency_tx) ?
"'".$this->db->escape($multicurrency_tx).
"'" :
'1').
",";
1219 $sql .= (isset($fk_multicurrency) ?
"'".$this->db->escape($fk_multicurrency).
"'" :
'null').
",";
1220 $sql .= (isset($multicurrency_code) ?
"'".$this->db->escape($multicurrency_code).
"'" :
'null').
",";
1221 $sql .=
"'".$this->db->idate($datec).
"',";
1222 $sql .=
" ".$this->product_fourn_price_id.
",";
1223 $sql .=
" ".$user->id.
",";
1224 $sql .=
" ".price2num($buyprice).
",";
listProductFournisseurPriceLog($product_fourn_price_id, $sortfield= '', $sortorder= '', $limit=0, $offset=0)
List supplier prices log of a supplier price.
__construct($db)
Constructor.
Class to parse product price expressions.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0, $newnpr=0, $delivery_time_days=0, $supplier_reputation= '', $localtaxes_array=array(), $newdefaultvatcode= '', $multicurrency_buyprice=0, $multicurrency_price_base_type= 'HT', $multicurrency_tx=1, $multicurrency_code= '', $desc_fourn= '', $barcode= '', $fk_barcode_type= '')
Modify the purchase price for a supplier.
const TYPE_SERVICE
Service.
setSupplierPriceExpression($expression_id)
Sets the supplier price expression.
const TYPE_PRODUCT
Regular product.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller Note: This function applies same rules than get_default_tva.
$conf db
API class for accounts.
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...
find_min_price_product_fournisseur($prodid, $qty=0, $socid=0)
Load properties for minimum price.
remove_fournisseur($id_fourn)
Remove all prices for this couple supplier-product.
$tva_tx
Default VAT rate of product.
remove_product_fournisseur_price($rowid)
Remove a price for a couple supplier-product.
displayPriceProductFournisseurLog($productFournLogList=array())
Display log price of product supplier price.
list_product_fournisseur_price($prodid, $sortfield= '', $sortorder= '', $limit=0, $offset=0)
List all supplier prices of a product.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
getSocNomUrl($withpicto=0, $option= 'supplier', $maxlen=0, $notooltip=0)
Display supplier of product.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static getIdFromCode($db, $code)
Get id of currency from code.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
display_price_product_fournisseur($showunitprice=1, $showsuptitle=1, $maxlen=0, $notooltip=0, $productFournList=array())
Display price of product.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
print $_SERVER["PHP_SELF"]
Edit parameters.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto).
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
fetch_product_fournisseur_price($rowid, $ignore_expression=0)
Loads the price information of a provider.
show_photos($modulepart, $sdir, $size=0, $nbmax=0, $nbbyrow=5, $showfilename=0, $showaction=0, $maxHeight=120, $maxWidth=160, $nolink=0, $notitle=0, $usesharelink=0)
Show photos of an object (nbmax maximum), into several columns.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
logPrice($user, $datec, $buyprice, $qty, $multicurrency_buyprice=null, $multicurrency_unitBuyPrice=null, $multicurrency_tx=null, $fk_multicurrency=null, $multicurrency_code=null)
Private function to log price history.
getLibStatut($mode=0, $type=0)
Return label of status of object.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Class to manage predefined suppliers products.
measuringUnitString($unit, $measuring_style= '', $scale= '', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.