271 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 =
'', $options = array())
274 global $conf, $langs;
281 if (empty($buyprice)) {
284 if (empty($charges)) {
287 if (empty($availability)) {
293 if (empty($supplier_reputation) || $supplier_reputation == -1) {
294 $supplier_reputation =
'';
296 if ($delivery_time_days !=
'' && !is_numeric($delivery_time_days)) {
297 $delivery_time_days =
'';
299 if ($price_base_type ==
'TTC') {
301 $buyprice = $buyprice / (1 + ($ttx / 100));
305 $multicurrency_unitBuyPrice =
null;
306 $fk_multicurrency =
null;
307 if (isModEnabled(
"multicurrency")) {
308 if (empty($multicurrency_tx)) {
309 $multicurrency_tx = 1;
311 if (empty($multicurrency_buyprice)) {
312 $multicurrency_buyprice = 0;
314 if ($multicurrency_price_base_type ==
'TTC') {
316 $multicurrency_buyprice = $multicurrency_buyprice / (1 + ($ttx / 100));
318 $multicurrency_buyprice =
price2num($multicurrency_buyprice,
'MU');
319 $multicurrency_unitBuyPrice =
price2num($multicurrency_buyprice / $qty,
'MU');
321 $buyprice = $multicurrency_buyprice / $multicurrency_tx;
328 $unitBuyPrice =
price2num($buyprice / $qty,
'MU');
332 $packaging =
price2num((empty($this->packaging) ? $qty : $this->packaging),
'MS');
339 if (count($localtaxes_array) > 0) {
340 $localtaxtype1 = $localtaxes_array[
'0'];
341 $localtax1 = $localtaxes_array[
'1'];
342 $localtaxtype2 = $localtaxes_array[
'2'];
343 $localtax2 = $localtaxes_array[
'3'];
345 $localtaxtype1 =
'0';
347 $localtaxtype2 =
'0';
350 if (empty($localtax1)) {
353 if (empty($localtax2)) {
358 if ($buyprice !=
'' && !is_numeric($buyprice)) {
363 if ($this->product_fourn_price_id > 0) {
366 if (is_array($logPrices) && count($logPrices) == 0) {
367 $currentPfp =
new self($this->db);
368 $result = $currentPfp->fetch_product_fournisseur_price($this->product_fourn_price_id);
369 if ($result > 0 && $currentPfp->fourn_price != 0) {
370 $currentPfpUser =
new User($this->db);
371 $result = $currentPfpUser->fetch($currentPfp->user_id);
373 $currentPfp->logPrice(
375 $currentPfp->date_creation,
376 $currentPfp->fourn_price,
377 $currentPfp->fourn_qty,
378 $currentPfp->fourn_multicurrency_price,
379 $currentPfp->fourn_multicurrency_unitprice,
380 $currentPfp->fourn_multicurrency_tx,
381 $currentPfp->fourn_multicurrency_id,
382 $currentPfp->fourn_multicurrency_code
387 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_fournisseur_price";
388 $sql .=
" SET fk_user = ".((int) $user->id).
" ,";
389 $sql .=
" ref_fourn = '".$this->db->escape(
$ref_fourn).
"',";
390 $sql .=
" desc_fourn = '".$this->db->escape($desc_fourn).
"',";
391 $sql .=
" price = ".((float) $buyprice).
",";
392 $sql .=
" quantity = ".((float) $qty).
",";
394 $sql .=
" remise = ".((float) $remise).
",";
395 $sql .=
" unitprice = ".((float) $unitBuyPrice).
",";
396 $sql .=
" fk_availability = ".((int) $availability).
",";
397 $sql .=
" multicurrency_price = ".(isset($multicurrency_buyprice) ?
"'".$this->db->escape(
price2num($multicurrency_buyprice)).
"'" :
'null').
",";
398 $sql .=
" multicurrency_unitprice = ".(isset($multicurrency_unitBuyPrice) ?
"'".$this->db->escape(
price2num($multicurrency_unitBuyPrice)).
"'" :
'null').
",";
399 $sql .=
" multicurrency_tx = ".(isset($multicurrency_tx) ?
"'".$this->db->escape($multicurrency_tx).
"'" :
'1').
",";
400 $sql .=
" fk_multicurrency = ".(isset($fk_multicurrency) ?
"'".$this->db->escape($fk_multicurrency).
"'" :
'null').
",";
401 $sql .=
" multicurrency_code = ".(isset($multicurrency_code) ?
"'".$this->db->escape($multicurrency_code).
"'" :
'null').
",";
402 $sql .=
" entity = ".$conf->entity.
",";
403 $sql .=
" tva_tx = ".price2num(
$tva_tx).
",";
409 $sql .=
" default_vat_code=".($newdefaultvatcode ?
"'".$this->db->escape($newdefaultvatcode).
"'" :
"null").
",";
410 $sql .=
" info_bits = ".((int) $newnpr).
",";
411 $sql .=
" charges = ".((float) $charges).
",";
412 $sql .=
" delivery_time_days = ".($delivery_time_days !=
'' ? ((int) $delivery_time_days) :
'null').
",";
413 $sql .=
" supplier_reputation = ".(empty($supplier_reputation) ?
'NULL' :
"'".$this->db->escape($supplier_reputation).
"'").
",";
414 $sql .=
" barcode = ".(empty($barcode) ?
'NULL' :
"'".$this->db->escape($barcode).
"'").
",";
415 $sql .=
" fk_barcode_type = ".(empty($fk_barcode_type) ?
'NULL' :
"'".$this->db->escape($fk_barcode_type).
"'");
416 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
417 $sql .=
", packaging = ".(empty($packaging) ? 1 : $packaging);
419 $sql .=
" WHERE rowid = ".((int) $this->product_fourn_price_id);
422 if (!empty($options) && is_array($options)) {
424 $res = $productfournisseurprice->fetch($this->product_fourn_price_id);
426 foreach ($options as $key=>$value) {
427 $productfournisseurprice->array_options[$key] = $value;
429 $res = $productfournisseurprice->update($user);
431 $this->error = $productfournisseurprice->error;
432 $this->errors = $productfournisseurprice->errors;
441 dol_syslog(get_class($this).
'::update_buyprice update knowing id of line = product_fourn_price_id = '.$this->product_fourn_price_id, LOG_DEBUG);
442 $resql = $this->db->query($sql);
445 $result = $this->
call_trigger(
'SUPPLIER_PRODUCT_BUYPRICE_MODIFY', $user);
450 if (!$error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG)) {
451 $result = $this->
logPrice($user, $now, $buyprice, $qty, $multicurrency_buyprice, $multicurrency_unitBuyPrice, $multicurrency_tx, $fk_multicurrency, $multicurrency_code);
458 return $this->product_fourn_price_id;
460 $this->db->rollback();
464 $this->error = $this->db->error().
" sql=".$sql;
465 $this->db->rollback();
469 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);
472 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_fournisseur_price";
473 $sql .=
" WHERE fk_soc = ".((int) $fourn->id).
" AND ref_fourn = '".$this->db->escape(
$ref_fourn).
"' AND quantity = ".((float) $qty).
" AND entity = ".((int) $conf->entity);
474 $resql = $this->db->query($sql);
477 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_fournisseur_price(";
478 $sql .=
" multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,";
479 $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";
480 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
481 $sql .=
", packaging";
484 $sql .= (isset($multicurrency_buyprice) ?
"'".$this->db->escape(
price2num($multicurrency_buyprice)).
"'" :
'null').
",";
485 $sql .= (isset($multicurrency_unitBuyPrice) ?
"'".$this->db->escape(
price2num($multicurrency_unitBuyPrice)).
"'" :
'null').
",";
486 $sql .= (isset($multicurrency_tx) ?
"'".$this->db->escape($multicurrency_tx).
"'" :
'1').
",";
487 $sql .= (isset($fk_multicurrency) ?
"'".$this->db->escape($fk_multicurrency).
"'" :
'null').
",";
488 $sql .= (isset($multicurrency_code) ?
"'".$this->db->escape($multicurrency_code).
"'" :
'null').
",";
489 $sql .=
" '".$this->db->idate($now).
"',";
490 $sql .=
" ".((int) $this->
id).
",";
491 $sql .=
" ".((int) $fourn->id).
",";
492 $sql .=
" '".$this->db->escape(
$ref_fourn).
"',";
493 $sql .=
" '".$this->db->escape($desc_fourn).
"',";
494 $sql .=
" ".((int) $user->id).
",";
495 $sql .=
" ".price2num($buyprice).
",";
496 $sql .=
" ".((float) $qty).
",";
498 $sql .=
" ".((float) $remise).
",";
499 $sql .=
" ".price2num($unitBuyPrice).
",";
500 $sql .=
" ".price2num(
$tva_tx).
",";
501 $sql .=
" ".price2num($charges).
",";
502 $sql .=
" ".((int) $availability).
",";
503 $sql .=
" ".($newdefaultvatcode ?
"'".$this->db->escape($newdefaultvatcode).
"'" :
"null").
",";
504 $sql .=
" ".((int) $newnpr).
",";
505 $sql .= $conf->entity.
",";
506 $sql .= ($delivery_time_days !=
'' ? ((int) $delivery_time_days) :
'null').
",";
507 $sql .= (empty($supplier_reputation) ?
'NULL' :
"'".$this->db->escape($supplier_reputation).
"'").
",";
508 $sql .= (empty($barcode) ?
'NULL' :
"'".$this->db->escape($barcode).
"'").
",";
509 $sql .= (empty($fk_barcode_type) ?
'NULL' :
"'".$this->db->escape($fk_barcode_type).
"'");
510 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
511 $sql .=
", ".(empty($this->packaging) ?
'1' :
"'".$this->db->escape($this->packaging).
"'");
515 $this->product_fourn_price_id = 0;
517 $resql = $this->db->query($sql);
519 $this->product_fourn_price_id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"product_fournisseur_price");
521 $this->error = $this->db->lasterror();
526 if (!empty($options) && is_array($options)) {
528 $res = $productfournisseurprice->fetch($this->product_fourn_price_id);
530 foreach ($options as $key=>$value) {
531 $productfournisseurprice->array_options[$key] = $value;
533 $res = $productfournisseurprice->update($user);
535 $this->error = $productfournisseurprice->error;
536 $this->errors = $productfournisseurprice->errors;
543 if (!$error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG)) {
546 $result = $this->
logPrice($user, $now, $buyprice, $qty, $multicurrency_buyprice, $multicurrency_unitBuyPrice, $multicurrency_tx, $fk_multicurrency, $multicurrency_code);
554 $result = $this->
call_trigger(
'SUPPLIER_PRODUCT_BUYPRICE_CREATE', $user);
562 return $this->product_fourn_price_id;
564 $this->db->rollback();
568 $this->error = $this->db->lasterror().
" sql=".$sql;
569 $this->db->rollback();
573 $this->error = $this->db->lasterror().
" sql=".$sql;
574 $this->db->rollback();
593 $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,";
594 $sql .=
" pfp.fk_soc, pfp.ref_fourn, pfp.desc_fourn, pfp.fk_product, pfp.charges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,";
595 $sql .=
" pfp.supplier_reputation, pfp.fk_user, pfp.datec,";
596 $sql .=
" pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
597 $sql .=
" pfp.barcode, pfp.fk_barcode_type, pfp.packaging,";
598 $sql .=
" p.ref as product_ref, p.tosell as status, p.tobuy as status_buy";
599 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_fournisseur_price as pfp, ".MAIN_DB_PREFIX.
"product as p";
600 $sql .=
" WHERE pfp.rowid = ".(int) $rowid;
601 $sql .=
" AND pfp.fk_product = p.rowid";
603 dol_syslog(get_class($this).
"::fetch_product_fournisseur_price", LOG_DEBUG);
604 $resql = $this->db->query($sql);
606 $obj = $this->db->fetch_object($resql);
608 $this->product_fourn_price_id = $rowid;
609 $this->
id = $obj->fk_product;
611 $this->fk_product = $obj->fk_product;
612 $this->product_id = $obj->fk_product;
613 $this->product_ref = $obj->product_ref;
614 $this->status = $obj->status;
615 $this->status_buy = $obj->status_buy;
616 $this->fourn_id = $obj->fk_soc;
617 $this->fourn_ref = $obj->ref_fourn;
618 $this->ref_supplier = $obj->ref_fourn;
619 $this->desc_supplier = $obj->desc_fourn;
620 $this->fourn_price = $obj->price;
621 $this->fourn_charges = $obj->charges;
622 $this->fourn_qty = $obj->quantity;
623 $this->fourn_remise_percent = $obj->remise_percent;
624 $this->fourn_remise = $obj->remise;
625 $this->fourn_unitprice = $obj->unitprice;
626 $this->fourn_tva_tx = $obj->tva_tx;
627 $this->fourn_tva_npr = $obj->fourn_tva_npr;
629 $this->fk_availability = $obj->fk_availability;
630 $this->delivery_time_days = $obj->delivery_time_days;
631 $this->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
632 $this->supplier_reputation = $obj->supplier_reputation;
633 $this->default_vat_code = $obj->default_vat_code;
634 $this->user_id = $obj->fk_user;
635 $this->date_creation = $this->db->jdate($obj->datec);
636 $this->fourn_multicurrency_price = $obj->multicurrency_price;
637 $this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
638 $this->fourn_multicurrency_tx = $obj->multicurrency_tx;
639 $this->fourn_multicurrency_id = $obj->fk_multicurrency;
640 $this->fourn_multicurrency_code = $obj->multicurrency_code;
641 if (isModEnabled(
'barcode')) {
642 $this->fourn_barcode = $obj->barcode;
643 $this->fourn_fk_barcode_type = $obj->fk_barcode_type;
644 $this->supplier_barcode = $obj->barcode;
645 $this->supplier_fk_barcode_type = $obj->fk_barcode_type;
647 $this->packaging = $obj->packaging;
649 if (isModEnabled(
'dynamicprices') && empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) {
650 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
652 $price_result = $priceparser->parseProductSupplier($this);
653 if ($price_result >= 0) {
654 $this->fourn_price = $price_result;
656 if ($this->fourn_qty != 0) {
657 $this->fourn_unitprice =
price2num($this->fourn_price / $this->fourn_qty,
'MU');
659 $this->fourn_unitprice =
"";
669 $this->error = $this->db->lasterror();
693 $sql =
"SELECT s.nom as supplier_name, s.rowid as fourn_id, p.ref as product_ref, p.tosell as status, p.tobuy as status_buy, ";
694 $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,";
695 $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,";
696 $sql .=
" pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code, pfp.datec, pfp.tms,";
697 $sql .=
" pfp.barcode, pfp.fk_barcode_type, pfp.packaging, pfp.status as pfstatus";
698 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_fournisseur_price as pfp, ".MAIN_DB_PREFIX.
"product as p, ".MAIN_DB_PREFIX.
"societe as s";
699 $sql .=
" WHERE pfp.entity IN (".getEntity(
'productsupplierprice').
")";
700 $sql .=
" AND pfp.fk_soc = s.rowid AND pfp.fk_product = p.rowid";
701 $sql .= ($socid > 0 ?
' AND pfp.fk_soc = '.((int) $socid) :
'');
702 $sql .=
" AND s.status = 1";
703 $sql .=
" AND pfp.fk_product = ".((int) $prodid);
704 if (empty($sortfield)) {
705 $sql .=
" ORDER BY s.nom, pfp.quantity, pfp.price";
707 $sql .= $this->db->order($sortfield, $sortorder);
709 $sql .= $this->db->plimit($limit, $offset);
710 dol_syslog(get_class($this).
"::list_product_fournisseur_price", LOG_DEBUG);
712 $resql = $this->db->query($sql);
716 while ($record = $this->db->fetch_array($resql)) {
720 $prodfourn->product_ref = $record[
"product_ref"];
721 $prodfourn->product_fourn_price_id = $record[
"product_fourn_pri_id"];
722 $prodfourn->status = $record[
"status"];
723 $prodfourn->status_buy = $record[
"status_buy"];
724 $prodfourn->product_fourn_id = $record[
"product_fourn_id"];
725 $prodfourn->product_fourn_entity = $record[
"entity"];
726 $prodfourn->ref_supplier = $record[
"ref_fourn"];
727 $prodfourn->fourn_ref = $record[
"ref_fourn"];
728 $prodfourn->desc_supplier = $record[
"desc_fourn"];
729 $prodfourn->fourn_price = $record[
"price"];
730 $prodfourn->fourn_qty = $record[
"quantity"];
731 $prodfourn->fourn_remise_percent = $record[
"remise_percent"];
732 $prodfourn->fourn_remise = $record[
"remise"];
733 $prodfourn->fourn_unitprice = $record[
"unitprice"];
734 $prodfourn->fourn_charges = $record[
"charges"];
735 $prodfourn->fourn_tva_tx = $record[
"tva_tx"];
736 $prodfourn->fourn_id = $record[
"fourn_id"];
737 $prodfourn->fourn_name = $record[
"supplier_name"];
738 $prodfourn->fk_availability = $record[
"fk_availability"];
739 $prodfourn->delivery_time_days = $record[
"delivery_time_days"];
740 $prodfourn->id = $prodid;
741 $prodfourn->fourn_tva_npr = $record[
"info_bits"];
742 $prodfourn->fk_supplier_price_expression = $record[
"fk_supplier_price_expression"];
743 $prodfourn->supplier_reputation = $record[
"supplier_reputation"];
744 $prodfourn->fourn_date_creation = $this->db->jdate($record[
'datec']);
745 $prodfourn->fourn_date_modification = $this->db->jdate($record[
'tms']);
747 $prodfourn->fourn_multicurrency_price = $record[
"multicurrency_price"];
748 $prodfourn->fourn_multicurrency_unitprice = $record[
"multicurrency_unitprice"];
749 $prodfourn->fourn_multicurrency_tx = $record[
"multicurrency_tx"];
750 $prodfourn->fourn_multicurrency_id = $record[
"fk_multicurrency"];
751 $prodfourn->fourn_multicurrency_code = $record[
"multicurrency_code"];
753 $prodfourn->packaging = $record[
"packaging"];
754 $prodfourn->status = $record[
"pfstatus"];
756 if (isModEnabled(
'barcode')) {
757 $prodfourn->supplier_barcode = $record[
"barcode"];
758 $prodfourn->supplier_fk_barcode_type = $record[
"fk_barcode_type"];
761 if (isModEnabled(
'dynamicprices') && !empty($prodfourn->fk_supplier_price_expression)) {
762 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
764 $price_result = $priceparser->parseProductSupplier($prodfourn);
765 if ($price_result >= 0) {
766 $prodfourn->fourn_price = $price_result;
767 $prodfourn->fourn_unitprice =
null;
771 if (!isset($prodfourn->fourn_unitprice)) {
772 if ($prodfourn->fourn_qty != 0) {
773 $prodfourn->fourn_unitprice =
price2num($prodfourn->fourn_price / $prodfourn->fourn_qty,
'MU');
775 $prodfourn->fourn_unitprice =
"";
779 $retarray[] = $prodfourn;
782 $this->db->free($resql);
785 $this->error = $this->db->error();
805 if (empty($prodid)) {
806 dol_syslog(
"Warning function find_min_price_product_fournisseur were called with prodid empty. May be a bug.", LOG_WARNING);
810 $this->product_fourn_price_id =
'';
811 $this->product_fourn_id =
'';
812 $this->fourn_ref =
'';
813 $this->fourn_price =
'';
814 $this->fourn_qty =
'';
815 $this->fourn_remise_percent =
'';
816 $this->fourn_remise =
'';
817 $this->fourn_unitprice =
'';
818 $this->fourn_id =
'';
819 $this->fourn_name =
'';
820 $this->delivery_time_days =
'';
823 $this->fourn_multicurrency_price =
'';
824 $this->fourn_multicurrency_unitprice =
'';
825 $this->fourn_multicurrency_tx =
'';
826 $this->fourn_multicurrency_id =
'';
827 $this->fourn_multicurrency_code =
'';
829 $sql =
"SELECT s.nom as supplier_name, s.rowid as fourn_id,";
830 $sql .=
" pfp.rowid as product_fourn_price_id, pfp.ref_fourn,";
831 $sql .=
" pfp.price, pfp.quantity, pfp.unitprice, pfp.tva_tx, pfp.charges,";
832 $sql .=
" pfp.remise, pfp.remise_percent, pfp.fk_supplier_price_expression, pfp.delivery_time_days";
833 $sql .=
" ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code";
834 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"product_fournisseur_price as pfp";
835 $sql .=
" WHERE s.entity IN (".getEntity(
'societe').
")";
836 $sql .=
" AND pfp.entity IN (".getEntity(
'productsupplierprice').
")";
837 $sql .=
" AND pfp.fk_product = ".((int) $prodid);
838 $sql .=
" AND pfp.fk_soc = s.rowid";
839 $sql .=
" AND s.status = 1";
841 $sql .=
" AND pfp.quantity <= ".((float) $qty);
844 $sql .=
' AND pfp.fk_soc = '.((int) $socid);
847 dol_syslog(get_class($this).
"::find_min_price_product_fournisseur", LOG_DEBUG);
849 $resql = $this->db->query($sql);
851 $record_array = array();
854 while ($record = $this->db->fetch_array($resql)) {
855 $record_array[] = $record;
858 if (count($record_array) == 0) {
859 $this->db->free($resql);
863 foreach ($record_array as $record) {
864 $fourn_price = $record[
"price"];
866 $fourn_unitprice = $record[
"unitprice"];
867 $fourn_unitprice_with_discount = $record[
"unitprice"] * (1 - $record[
"remise_percent"] / 100);
869 if (isModEnabled(
'dynamicprices') && !empty($record[
"fk_supplier_price_expression"])) {
871 $prod_supplier->product_fourn_price_id = $record[
"product_fourn_price_id"];
872 $prod_supplier->id = $prodid;
873 $prod_supplier->fourn_qty = $record[
"quantity"];
874 $prod_supplier->fourn_tva_tx = $record[
"tva_tx"];
875 $prod_supplier->fk_supplier_price_expression = $record[
"fk_supplier_price_expression"];
877 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
879 $price_result = $priceparser->parseProductSupplier($prod_supplier);
880 if ($price_result >= 0) {
881 $fourn_price =
price2num($price_result,
'MU');
882 if ($record[
"quantity"] != 0) {
883 $fourn_unitprice =
price2num($fourn_price / $record[
"quantity"],
'MU');
885 $fourn_unitprice = $fourn_price;
887 $fourn_unitprice_with_discount = $fourn_unitprice * (1 - $record[
"remise_percent"] / 100);
890 if ($fourn_unitprice < $min || $min == -1) {
891 $this->product_fourn_price_id = $record[
"product_fourn_price_id"];
892 $this->ref_supplier = $record[
"ref_fourn"];
893 $this->ref_fourn = $record[
"ref_fourn"];
894 $this->fourn_ref = $record[
"ref_fourn"];
895 $this->fourn_price = $fourn_price;
896 $this->fourn_qty = $record[
"quantity"];
897 $this->fourn_remise_percent = $record[
"remise_percent"];
898 $this->fourn_remise = $record[
"remise"];
899 $this->fourn_unitprice = $fourn_unitprice;
900 $this->fourn_unitprice_with_discount = $fourn_unitprice_with_discount;
901 $this->fourn_charges = $record[
"charges"];
902 $this->fourn_tva_tx = $record[
"tva_tx"];
903 $this->fourn_id = $record[
"fourn_id"];
904 $this->fourn_name = $record[
"supplier_name"];
905 $this->delivery_time_days = $record[
"delivery_time_days"];
906 $this->fk_supplier_price_expression = $record[
"fk_supplier_price_expression"];
908 $this->fourn_multicurrency_price = $record[
"multicurrency_price"];
909 $this->fourn_multicurrency_unitprice = $record[
"multicurrency_unitprice"];
910 $this->fourn_multicurrency_tx = $record[
"multicurrency_tx"];
911 $this->fourn_multicurrency_id = $record[
"fk_multicurrency"];
912 $this->fourn_multicurrency_code = $record[
"multicurrency_code"];
913 $min = $fourn_unitprice;
918 $this->db->free($resql);
921 $this->error = $this->db->error();
1159 public function getNomUrl($withpicto = 0, $option =
'', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'', $add_label = 0, $sep =
' - ')
1161 global $db, $conf, $langs, $hookmanager;
1163 if (!empty($conf->dol_no_mouse_hover)) {
1170 $newref = $this->ref;
1172 $newref =
dol_trunc($newref, $maxlength,
'middle');
1175 if (!empty($this->entity)) {
1176 $tmpphoto = $this->
show_photos(
'product', $conf->product->multidir_output[$this->entity], 1, 1, 0, 0, 0, 80);
1177 if ($this->nbphoto > 0) {
1178 $label .=
'<div class="photointooltip">';
1179 $label .= $tmpphoto;
1180 $label .=
'</div><div style="clear: both;"></div>';
1185 $label .=
img_picto(
'',
'product').
' <u class="paddingrightonly">'.$langs->trans(
"Product").
'</u>';
1187 $label .=
img_picto(
'',
'service').
' <u class="paddingrightonly">'.$langs->trans(
"Service").
'</u>';
1189 if (isset($this->status) && isset($this->status_buy)) {
1190 $label .=
' '.$this->getLibStatut(5, 0);
1191 $label .=
' '.$this->getLibStatut(5, 1);
1194 if (!empty($this->
ref)) {
1195 $label .=
'<br><b>'.$langs->trans(
'ProductRef').
':</b> '.($this->
ref ? $this->
ref : $this->product_ref);
1197 if (!empty($this->label)) {
1198 $label .=
'<br><b>'.$langs->trans(
'ProductLabel').
':</b> '.$this->label;
1200 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
1203 if (isModEnabled(
'productbatch')) {
1204 $langs->load(
"productbatch");
1205 $label .=
"<br><b>".$langs->trans(
"ManageLotSerial").
'</b>: '.$this->
getLibStatut(0, 2);
1208 if (isModEnabled(
'barcode')) {
1209 $label .=
'<br><b>'.$langs->trans(
'BarCode').
':</b> '.$this->barcode;
1213 if ($this->weight) {
1214 $label .=
"<br><b>".$langs->trans(
"Weight").
'</b>: '.$this->weight.
' '.
measuringUnitString(0,
"weight", $this->weight_units);
1217 if ($this->length) {
1218 $labelsize .= ($labelsize ?
" - " :
"").
"<b>".$langs->trans(
"Length").
'</b>: '.$this->length.
' '.
measuringUnitString(0,
'size', $this->length_units);
1221 $labelsize .= ($labelsize ?
" - " :
"").
"<b>".$langs->trans(
"Width").
'</b>: '.$this->width.
' '.
measuringUnitString(0,
'size', $this->width_units);
1223 if ($this->height) {
1224 $labelsize .= ($labelsize ?
" - " :
"").
"<b>".$langs->trans(
"Height").
'</b>: '.$this->height.
' '.
measuringUnitString(0,
'size', $this->height_units);
1227 $label .=
"<br>".$labelsize;
1230 $labelsurfacevolume =
"";
1231 if ($this->surface) {
1232 $labelsurfacevolume .= ($labelsurfacevolume ?
" - " :
"").
"<b>".$langs->trans(
"Surface").
'</b>: '.$this->surface.
' '.
measuringUnitString(0,
'surface', $this->surface_units);
1234 if ($this->volume) {
1235 $labelsurfacevolume .= ($labelsurfacevolume ?
" - " :
"").
"<b>".$langs->trans(
"Volume").
'</b>: '.$this->volume.
' '.
measuringUnitString(0,
'volume', $this->volume_units);
1237 if ($labelsurfacevolume) {
1238 $label .=
"<br>".$labelsurfacevolume;
1242 if (isModEnabled(
'accounting') && $this->status) {
1243 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1244 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancySellCode').
':</b> '.
length_accountg($this->accountancy_code_sell);
1245 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancySellIntraCode').
':</b> '.
length_accountg($this->accountancy_code_sell_intra);
1246 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancySellExportCode').
':</b> '.
length_accountg($this->accountancy_code_sell_export);
1248 if (isModEnabled(
'accounting') && $this->status_buy) {
1249 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1250 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyCode').
':</b> '.
length_accountg($this->accountancy_code_buy);
1251 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyIntraCode').
':</b> '.
length_accountg($this->accountancy_code_buy_intra);
1252 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyExportCode').
':</b> '.
length_accountg($this->accountancy_code_buy_export);
1256 if (is_array($logPrices) && count($logPrices) > 0) {
1257 $label .=
'<br><br>';
1258 $label .=
'<u>'.$langs->trans(
"History").
'</u>';
1262 $url = DOL_URL_ROOT.
'/product/fournisseurs.php?id='.((int) $this->
id).
'&action=create_price&token='.newToken().
'&socid='.((int) $this->fourn_id).
'&rowid='.((int) $this->product_fourn_price_id);
1264 if ($option !=
'nolink') {
1266 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1267 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1268 $add_save_lastsearch_values = 1;
1270 if ($add_save_lastsearch_values) {
1271 $url .=
'&save_lastsearch_values=1';
1276 if (empty($notooltip)) {
1277 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1278 $label = $langs->trans(
"SupplierRef");
1279 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1281 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1282 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1284 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1287 $linkstart =
'<a href="'.$url.
'"';
1288 $linkstart .= $linkclose.
'>';
1291 $result .= $linkstart;
1293 $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);
1295 if ($withpicto != 2) {
1296 $result .= $newref.($this->ref_supplier ?
' ('.$this->ref_supplier.
')' :
'');
1298 $result .= $linkend;
1299 if ($withpicto != 2) {
1300 $result .= (($add_label && $this->label) ? $sep.dol_trunc($this->label, ($add_label > 1 ? $add_label : 0)) :
'');
1304 $hookmanager->initHooks(array($this->element .
'dao'));
1305 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1306 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1308 $result = $hookmanager->resPrint;
1310 $result .= $hookmanager->resPrint;