dolibarr 20.0.0
fournisseur.product.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2009-2014 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
8 * Copyright (C) 2016-2023 Charlene Benke <charlene@patas-monkey.com>
9 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
11 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/class/productfournisseurprice.class.php';
36
37
42{
46 public $db;
47
51 public $error = '';
52
56 public $product_fourn_price_id;
57
61 public $id;
62
67 public $fourn_ref;
68
72 public $delivery_time_days;
73
77 public $ref_supplier;
78
82 public $desc_supplier;
83
87 public $vatrate_supplier;
88
94
98 public $product_id;
99
103 public $product_ref;
104
108 public $fourn_id;
109
113 public $fourn_name;
114
118 public $fourn_qty;
119
123 public $fourn_pu;
124
128 public $fourn_price;
129
133 public $fourn_remise_percent;
134
138 public $fourn_remise;
139
140 public $fourn_charges; // when getDolGlobalString('PRODUCT_CHARGES') is set
141
145 public $product_fourn_id;
146
147 public $product_fourn_entity;
148
152 public $user_id;
153
157 public $fk_availability;
158
159 public $fourn_unitprice;
160 public $fourn_unitprice_with_discount; // not saved into database
161 public $fourn_tva_tx;
162 public $fourn_tva_npr;
163
167 public $fk_supplier_price_expression;
168
172 public $supplier_reputation;
173
177 public $reputations = array();
178
179 // Multicurreny
180 public $fourn_multicurrency_id;
181 public $fourn_multicurrency_code;
182 public $fourn_multicurrency_tx;
183 public $fourn_multicurrency_price;
184 public $fourn_multicurrency_unitprice;
185
191
195 public $supplier_barcode;
196
202
206 public $supplier_fk_barcode_type;
207
208 public $packaging;
209
210 public $labelStatusShort;
211 public $labelStatus;
212
213 const STATUS_OPEN = 1;
214 const STATUS_CANCELED = 0;
215
216
222 public function __construct($db)
223 {
224 global $langs;
225
226 $this->db = $db;
227 $langs->load("suppliers");
228 $this->reputations = array('-1' => '', 'FAVORITE' => $langs->trans('Favorite'), 'NOTTHGOOD' => $langs->trans('NotTheGoodQualitySupplier'), 'DONOTORDER' => $langs->trans('DoNotOrderThisProductToThisSupplier'));
229 }
230
231 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
238 public function remove_fournisseur($id_fourn)
239 {
240 // phpcs:enable
241 $ok = 1;
242
243 $this->db->begin();
244
245 $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
246 $sql .= " WHERE fk_product = ".((int) $this->id)." AND fk_soc = ".((int) $id_fourn);
247
248 dol_syslog(get_class($this)."::remove_fournisseur", LOG_DEBUG);
249 $resql2 = $this->db->query($sql);
250 if (!$resql2) {
251 $this->error = $this->db->lasterror();
252 $ok = 0;
253 }
254
255 if ($ok) {
256 $this->db->commit();
257 return 1;
258 } else {
259 $this->db->rollback();
260 return -1;
261 }
262 }
263
264
265 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
272 public function remove_product_fournisseur_price($rowid)
273 {
274 // phpcs:enable
275 global $conf, $user;
276
277 $error = 0;
278
279 $this->db->begin();
280
281 // Call trigger
282 $result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_DELETE', $user);
283 if ($result < 0) {
284 $error++;
285 }
286 // End call triggers
287
288 if (empty($error)) {
289 $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
290 $sql .= " WHERE rowid = ".((int) $rowid);
291
292 dol_syslog(get_class($this)."::remove_product_fournisseur_price", LOG_DEBUG);
293 $resql = $this->db->query($sql);
294 if (!$resql) {
295 $this->error = $this->db->lasterror();
296 $error++;
297 }
298 }
299
300 if (empty($error)) {
301 $this->db->commit();
302 return 1;
303 } else {
304 $this->db->rollback();
305 return -1;
306 }
307 }
308
309
310 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
340 public function update_buyprice(
341 $qty,
342 $buyprice,
343 $user,
344 $price_base_type,
345 $fourn,
346 $availability,
348 $tva_tx,
349 $charges = 0,
350 $remise_percent = 0,
351 $remise = 0,
352 $newnpr = 0,
353 $delivery_time_days = 0,
354 $supplier_reputation = '',
355 $localtaxes_array = array(),
356 $newdefaultvatcode = '',
357 $multicurrency_buyprice = 0,
358 $multicurrency_price_base_type = 'HT',
359 $multicurrency_tx = 1,
360 $multicurrency_code = '',
361 $desc_fourn = '',
362 $barcode = '',
363 $fk_barcode_type = 0,
364 $options = array()
365 ) {
366 // phpcs:enable
367 global $conf, $langs;
368 //global $mysoc;
369
370 // Clean parameter
371 if (empty($qty)) {
372 $qty = 0;
373 }
374 if (empty($buyprice)) {
375 $buyprice = 0;
376 }
377 if (empty($charges)) {
378 $charges = 0;
379 }
380 if (empty($availability)) {
381 $availability = 0;
382 }
383 if (empty($remise_percent)) {
384 $remise_percent = 0;
385 }
386 if (empty($supplier_reputation) || $supplier_reputation == -1) {
387 $supplier_reputation = '';
388 }
389 if ($delivery_time_days != '' && !is_numeric($delivery_time_days)) {
390 $delivery_time_days = 0;
391 }
392 if ($price_base_type == 'TTC') {
393 $ttx = $tva_tx;
394 $buyprice = $buyprice / (1 + ($ttx / 100));
395 }
396
397 // Multicurrency
398 $multicurrency_unitBuyPrice = null;
399 $fk_multicurrency = null;
400 if (isModEnabled("multicurrency")) {
401 if (empty($multicurrency_tx)) {
402 $multicurrency_tx = 1;
403 }
404 if (empty($multicurrency_buyprice)) {
405 $multicurrency_buyprice = 0;
406 }
407 if ($multicurrency_price_base_type == 'TTC') {
408 $ttx = $tva_tx;
409 $multicurrency_buyprice = $multicurrency_buyprice / (1 + ($ttx / 100));
410 }
411 $multicurrency_buyprice = price2num($multicurrency_buyprice, 'MU');
412 $multicurrency_unitBuyPrice = price2num($multicurrency_buyprice / $qty, 'MU');
413
414 $buyprice = $multicurrency_buyprice / $multicurrency_tx;
415 $fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $multicurrency_code);
416 }
417
418 $buyprice = (float) price2num($buyprice, 'MU');
419 $charges = (float) price2num($charges, 'MU');
420 $qty = (float) price2num($qty, 'MS');
421 $unitBuyPrice = (float) price2num($buyprice / $qty, 'MU');
422
423 // We can have a purchase ref that need to buy 100 min for a given price and with a packaging of 50.
424 //$packaging = price2num(((empty($this->packaging) || $this->packaging < $qty) ? $qty : $this->packaging), 'MS');
425 $packaging = price2num((empty($this->packaging) ? $qty : $this->packaging), 'MS');
426
427 $error = 0;
428 $now = dol_now();
429
430 $newvat = $tva_tx;
431
432 if (count($localtaxes_array) > 0) {
433 $localtaxtype1 = $localtaxes_array['0'];
434 $localtax1 = $localtaxes_array['1'];
435 $localtaxtype2 = $localtaxes_array['2'];
436 $localtax2 = $localtaxes_array['3'];
437 } else { // old method. deprecated because it can't retrieve type
438 $localtaxtype1 = '0';
439 $localtax1 = get_localtax($newvat, 1);
440 $localtaxtype2 = '0';
441 $localtax2 = get_localtax($newvat, 2);
442 }
443 if (empty($localtax1)) {
444 $localtax1 = 0; // If = '' then = 0
445 }
446 if (empty($localtax2)) {
447 $localtax2 = 0; // If = '' then = 0
448 }
449
450 $this->db->begin();
451
452 if ($this->product_fourn_price_id > 0) {
453 // check if price already logged, if not first log current price
454 $logPrices = $this->listProductFournisseurPriceLog($this->product_fourn_price_id);
455 if (is_array($logPrices) && count($logPrices) == 0) {
456 $currentPfp = new self($this->db);
457 $result = $currentPfp->fetch_product_fournisseur_price($this->product_fourn_price_id);
458 if ($result > 0 && $currentPfp->fourn_price != 0) {
459 $currentPfpUser = new User($this->db);
460 $result = $currentPfpUser->fetch($currentPfp->user_id);
461 if ($result > 0) {
462 $currentPfp->logPrice(
463 $currentPfpUser,
464 $currentPfp->date_creation,
465 $currentPfp->fourn_price,
466 $currentPfp->fourn_qty,
467 $currentPfp->fourn_multicurrency_price,
468 $currentPfp->fourn_multicurrency_unitprice,
469 $currentPfp->fourn_multicurrency_tx,
470 $currentPfp->fourn_multicurrency_id,
471 $currentPfp->fourn_multicurrency_code
472 );
473 }
474 }
475 }
476 $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price";
477 $sql .= " SET fk_user = ".((int) $user->id)." ,";
478 $sql .= " datec = '".$this->db->idate($now)."' ,"; // Note: Even if this is an update, we update the creation date as the log of each change is tracked into product_fournisseur_log.
479 $sql .= " ref_fourn = '".$this->db->escape($ref_fourn)."',";
480 $sql .= " desc_fourn = '".$this->db->escape($desc_fourn)."',";
481 $sql .= " price = ".((float) $buyprice).",";
482 $sql .= " quantity = ".((float) $qty).",";
483 $sql .= " remise_percent = ".((float) $remise_percent).",";
484 $sql .= " remise = ".((float) $remise).",";
485 $sql .= " unitprice = ".((float) $unitBuyPrice).",";
486 $sql .= " fk_availability = ".((int) $availability).",";
487 $sql .= " multicurrency_price = ".(isset($multicurrency_buyprice) ? "'".$this->db->escape(price2num($multicurrency_buyprice))."'" : 'null').",";
488 $sql .= " multicurrency_unitprice = ".(isset($multicurrency_unitBuyPrice) ? "'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'" : 'null').",";
489 $sql .= " multicurrency_tx = ".(isset($multicurrency_tx) ? "'".$this->db->escape($multicurrency_tx)."'" : '1').",";
490 $sql .= " fk_multicurrency = ".(isset($fk_multicurrency) ? "'".$this->db->escape($fk_multicurrency)."'" : 'null').",";
491 $sql .= " multicurrency_code = ".(isset($multicurrency_code) ? "'".$this->db->escape($multicurrency_code)."'" : 'null').",";
492 $sql .= " entity = ".$conf->entity.",";
493 $sql .= " tva_tx = ".price2num($tva_tx).",";
494 // TODO Add localtax1 and localtax2
495 //$sql.= " localtax1_tx=".($localtax1>=0?$localtax1:'NULL').",";
496 //$sql.= " localtax2_tx=".($localtax2>=0?$localtax2:'NULL').",";
497 //$sql.= " localtax1_type=".($localtaxtype1!=''?"'".$this->db->escape($localtaxtype1)."'":"'0'").",";
498 //$sql.= " localtax2_type=".($localtaxtype2!=''?"'".$this->db->escape($localtaxtype2)."'":"'0'").",";
499 $sql .= " default_vat_code=".($newdefaultvatcode ? "'".$this->db->escape($newdefaultvatcode)."'" : "null").",";
500 $sql .= " info_bits = ".((int) $newnpr).",";
501 $sql .= " charges = ".((float) $charges).","; // deprecated
502 $sql .= " delivery_time_days = ".($delivery_time_days != '' ? ((int) $delivery_time_days) : 'null').",";
503 $sql .= " supplier_reputation = ".(empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'").",";
504 $sql .= " barcode = ".(empty($barcode) ? 'NULL' : "'".$this->db->escape($barcode)."'").",";
505 $sql .= " fk_barcode_type = ".(empty($fk_barcode_type) ? 'NULL' : "'".$this->db->escape($fk_barcode_type)."'");
506 if (getDolGlobalString('PRODUCT_USE_SUPPLIER_PACKAGING')) {
507 $sql .= ", packaging = ".(empty($packaging) ? 1 : $packaging);
508 }
509 $sql .= " WHERE rowid = ".((int) $this->product_fourn_price_id);
510
511 if (!$error) {
512 if (!empty($options) && is_array($options)) {
513 $productfournisseurprice = new ProductFournisseurPrice($this->db);
514 $res = $productfournisseurprice->fetch($this->product_fourn_price_id);
515 if ($res > 0) {
516 foreach ($options as $key => $value) {
517 $productfournisseurprice->array_options[$key] = $value;
518 }
519 $res = $productfournisseurprice->update($user);
520 if ($res < 0) {
521 $this->error = $productfournisseurprice->error;
522 $this->errors = $productfournisseurprice->errors;
523 $error++;
524 }
525 }
526 }
527 }
528
529 // TODO Add price_base_type and price_ttc
530
531 dol_syslog(get_class($this).'::update_buyprice update knowing id of line = product_fourn_price_id = '.$this->product_fourn_price_id, LOG_DEBUG);
532 $resql = $this->db->query($sql);
533 if ($resql) {
534 // Call trigger
535 $result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_MODIFY', $user);
536 if ($result < 0) {
537 $error++;
538 }
539 // End call triggers
540 if (!$error && !getDolGlobalString('PRODUCT_PRICE_SUPPLIER_NO_LOG')) {
541 $result = $this->logPrice($user, $now, $buyprice, $qty, $multicurrency_buyprice, $multicurrency_unitBuyPrice, $multicurrency_tx, $fk_multicurrency, $multicurrency_code);
542 if ($result < 0) {
543 $error++;
544 }
545 }
546 if (empty($error)) {
547 $this->db->commit();
548 return $this->product_fourn_price_id;
549 } else {
550 $this->db->rollback();
551 return -1;
552 }
553 } else {
554 $this->error = $this->db->error()." sql=".$sql;
555 $this->db->rollback();
556 return -2;
557 }
558 } else {
559 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);
560
561 // Delete price for this quantity
562 $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
563 $sql .= " WHERE fk_soc = ".((int) $fourn->id)." AND ref_fourn = '".$this->db->escape($ref_fourn)."' AND quantity = ".((float) $qty)." AND entity = ".((int) $conf->entity);
564 $resql = $this->db->query($sql);
565 if ($resql) {
566 // Add price for this quantity to supplier
567 $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
568 $sql .= " multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,";
569 $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";
570 if (getDolGlobalString('PRODUCT_USE_SUPPLIER_PACKAGING')) {
571 $sql .= ", packaging";
572 }
573 $sql .= ") values(";
574 $sql .= (isset($multicurrency_buyprice) ? "'".$this->db->escape(price2num($multicurrency_buyprice))."'" : 'null').",";
575 $sql .= (isset($multicurrency_unitBuyPrice) ? "'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'" : 'null').",";
576 $sql .= (isset($multicurrency_tx) ? "'".$this->db->escape($multicurrency_tx)."'" : '1').",";
577 $sql .= (isset($fk_multicurrency) ? "'".$this->db->escape($fk_multicurrency)."'" : 'null').",";
578 $sql .= (isset($multicurrency_code) ? "'".$this->db->escape($multicurrency_code)."'" : 'null').",";
579 $sql .= " '".$this->db->idate($now)."',";
580 $sql .= " ".((int) $this->id).",";
581 $sql .= " ".((int) $fourn->id).",";
582 $sql .= " '".$this->db->escape($ref_fourn)."',";
583 $sql .= " '".$this->db->escape($desc_fourn)."',";
584 $sql .= " ".((int) $user->id).",";
585 $sql .= " ".price2num($buyprice).",";
586 $sql .= " ".((float) $qty).",";
587 $sql .= " ".((float) $remise_percent).",";
588 $sql .= " ".((float) $remise).",";
589 $sql .= " ".price2num($unitBuyPrice).",";
590 $sql .= " ".price2num($tva_tx).",";
591 $sql .= " ".price2num($charges).",";
592 $sql .= " ".((int) $availability).",";
593 $sql .= " ".($newdefaultvatcode ? "'".$this->db->escape($newdefaultvatcode)."'" : "null").",";
594 $sql .= " ".((int) $newnpr).",";
595 $sql .= $conf->entity.",";
596 $sql .= ($delivery_time_days != '' ? ((int) $delivery_time_days) : 'null').",";
597 $sql .= (empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'").",";
598 $sql .= (empty($barcode) ? 'NULL' : "'".$this->db->escape($barcode)."'").",";
599 $sql .= (empty($fk_barcode_type) ? 'NULL' : "'".$this->db->escape($fk_barcode_type)."'");
600 if (getDolGlobalString('PRODUCT_USE_SUPPLIER_PACKAGING')) {
601 $sql .= ", ".(empty($this->packaging) ? '1' : "'".$this->db->escape($this->packaging)."'");
602 }
603 $sql .= ")";
604
605 $this->product_fourn_price_id = 0;
606
607 $resql = $this->db->query($sql);
608 if ($resql) {
609 $this->product_fourn_price_id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_fournisseur_price");
610 } else {
611 $this->error = $this->db->lasterror();
612 $error++;
613 }
614
615 if (!$error) {
616 if (!empty($options) && is_array($options)) {
617 $productfournisseurprice = new ProductFournisseurPrice($this->db);
618 $res = $productfournisseurprice->fetch($this->product_fourn_price_id);
619 if ($res > 0) {
620 foreach ($options as $key => $value) {
621 $productfournisseurprice->array_options[$key] = $value;
622 }
623 $res = $productfournisseurprice->update($user);
624 if ($res < 0) {
625 $this->error = $productfournisseurprice->error;
626 $this->errors = $productfournisseurprice->errors;
627 $error++;
628 }
629 }
630 }
631 }
632
633 if (!$error && !getDolGlobalString('PRODUCT_PRICE_SUPPLIER_NO_LOG')) {
634 // Add record into log table
635 // $this->product_fourn_price_id must be set
636 $result = $this->logPrice($user, $now, $buyprice, $qty, $multicurrency_buyprice, $multicurrency_unitBuyPrice, $multicurrency_tx, $fk_multicurrency, $multicurrency_code);
637 if ($result < 0) {
638 $error++;
639 }
640 }
641
642 if (!$error) {
643 // Call trigger
644 $result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_CREATE', $user);
645 if ($result < 0) {
646 $error++;
647 }
648 // End call triggers
649
650 if (empty($error)) {
651 $this->db->commit();
652 return $this->product_fourn_price_id;
653 } else {
654 $this->db->rollback();
655 return -1;
656 }
657 } else {
658 $this->error = $this->db->lasterror()." sql=".$sql;
659 $this->db->rollback();
660 return -2;
661 }
662 } else {
663 $this->error = $this->db->lasterror()." sql=".$sql;
664 $this->db->rollback();
665 return -1;
666 }
667 }
668 }
669
670 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
678 public function fetch_product_fournisseur_price($rowid, $ignore_expression = 0)
679 {
680 // phpcs:enable
681 global $conf;
682
683 $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,";
684 $sql .= " pfp.fk_soc, pfp.ref_fourn, pfp.desc_fourn, pfp.fk_product, pfp.charges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,";
685 $sql .= " pfp.supplier_reputation, pfp.fk_user, pfp.datec,";
686 $sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
687 $sql .= " pfp.barcode, pfp.fk_barcode_type, pfp.packaging,";
688 $sql .= " p.ref as product_ref, p.tosell as status, p.tobuy as status_buy";
689 $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product as p";
690 $sql .= " WHERE pfp.rowid = ".(int) $rowid;
691 $sql .= " AND pfp.fk_product = p.rowid";
692
693 dol_syslog(get_class($this)."::fetch_product_fournisseur_price", LOG_DEBUG);
694 $resql = $this->db->query($sql);
695 if ($resql) {
696 $obj = $this->db->fetch_object($resql);
697 if ($obj) {
698 $this->product_fourn_price_id = $rowid;
699 $this->id = $obj->fk_product;
700
701 $this->fk_product = $obj->fk_product;
702 $this->product_id = $obj->fk_product;
703 $this->product_ref = $obj->product_ref;
704 $this->status = $obj->status;
705 $this->status_buy = $obj->status_buy;
706 $this->fourn_id = $obj->fk_soc;
707 $this->fourn_ref = $obj->ref_fourn; // deprecated
708 $this->ref_supplier = $obj->ref_fourn;
709 $this->desc_supplier = $obj->desc_fourn;
710 $this->fourn_price = $obj->price;
711 $this->fourn_charges = $obj->charges; // when getDolGlobalString('PRODUCT_CHARGES') is set
712 $this->fourn_qty = $obj->quantity;
713 $this->fourn_remise_percent = $obj->remise_percent;
714 $this->fourn_remise = $obj->remise;
715 $this->fourn_unitprice = $obj->unitprice;
716 $this->fourn_tva_tx = $obj->tva_tx;
717 $this->fourn_tva_npr = $obj->fourn_tva_npr;
718 // Add also localtaxes
719 $this->fk_availability = $obj->fk_availability;
720 $this->delivery_time_days = $obj->delivery_time_days;
721 $this->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
722 $this->supplier_reputation = $obj->supplier_reputation;
723 $this->default_vat_code = $obj->default_vat_code;
724 $this->user_id = $obj->fk_user;
725 $this->date_creation = $this->db->jdate($obj->datec);
726 $this->fourn_multicurrency_price = $obj->multicurrency_price;
727 $this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
728 $this->fourn_multicurrency_tx = $obj->multicurrency_tx;
729 $this->fourn_multicurrency_id = $obj->fk_multicurrency;
730 $this->fourn_multicurrency_code = $obj->multicurrency_code;
731 if (isModEnabled('barcode')) {
732 $this->fourn_barcode = $obj->barcode; // deprecated
733 $this->fourn_fk_barcode_type = $obj->fk_barcode_type; // deprecated
734 $this->supplier_barcode = $obj->barcode;
735 $this->supplier_fk_barcode_type = $obj->fk_barcode_type;
736 }
737 $this->packaging = $obj->packaging;
738
739 if (isModEnabled('dynamicprices') && empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) {
740 require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
741 $priceparser = new PriceParser($this->db);
742 $price_result = $priceparser->parseProductSupplier($this);
743 if ($price_result >= 0) {
744 $this->fourn_price = $price_result;
745 //recalculation of unitprice, as probably the price changed...
746 if ($this->fourn_qty != 0) {
747 $this->fourn_unitprice = price2num($this->fourn_price / $this->fourn_qty, 'MU');
748 } else {
749 $this->fourn_unitprice = "";
750 }
751 }
752 }
753
754 return 1;
755 } else {
756 return 0;
757 }
758 } else {
759 $this->error = $this->db->lasterror();
760 return -1;
761 }
762 }
763
764
765 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
778 public function list_product_fournisseur_price($prodid, $sortfield = '', $sortorder = '', $limit = 0, $offset = 0, $socid = 0)
779 {
780 // phpcs:enable
781 global $conf;
782
783 $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, ";
784 $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,";
785 $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,";
786 $sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code, pfp.datec, pfp.tms,";
787 $sql .= " pfp.barcode, pfp.fk_barcode_type, pfp.packaging, pfp.status as pfstatus";
788 $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."societe as s";
789 $sql .= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")";
790 $sql .= " AND pfp.fk_soc = s.rowid AND pfp.fk_product = p.rowid";
791 $sql .= ($socid > 0 ? ' AND pfp.fk_soc = '.((int) $socid) : '');
792 $sql .= " AND s.status = 1"; // only enabled company selected
793 $sql .= " AND pfp.fk_product = ".((int) $prodid);
794 if (empty($sortfield)) {
795 $sql .= " ORDER BY s.nom, pfp.quantity, pfp.price";
796 } else {
797 $sql .= $this->db->order($sortfield, $sortorder);
798 }
799 $sql .= $this->db->plimit($limit, $offset);
800 dol_syslog(get_class($this)."::list_product_fournisseur_price", LOG_DEBUG);
801
802 $resql = $this->db->query($sql);
803 if ($resql) {
804 $retarray = array();
805
806 while ($record = $this->db->fetch_array($resql)) {
807 //define base attribute
808 $prodfourn = new ProductFournisseur($this->db);
809
810 $prodfourn->product_ref = $record["product_ref"];
811 $prodfourn->product_fourn_price_id = $record["product_fourn_pri_id"];
812 $prodfourn->status = $record["status"];
813 $prodfourn->status_buy = $record["status_buy"];
814 $prodfourn->product_fourn_id = $record["product_fourn_id"];
815 $prodfourn->product_fourn_entity = $record["entity"];
816 $prodfourn->ref_supplier = $record["ref_fourn"];
817 $prodfourn->fourn_ref = $record["ref_fourn"];
818 $prodfourn->desc_supplier = $record["desc_fourn"];
819 $prodfourn->fourn_price = $record["price"];
820 $prodfourn->fourn_qty = $record["quantity"];
821 $prodfourn->fourn_remise_percent = $record["remise_percent"];
822 $prodfourn->fourn_remise = $record["remise"];
823 $prodfourn->fourn_unitprice = $record["unitprice"];
824 $prodfourn->fourn_charges = $record["charges"]; // when getDolGlobalString('PRODUCT_CHARGES') is set
825 $prodfourn->fourn_tva_tx = $record["tva_tx"];
826 $prodfourn->fourn_id = $record["fourn_id"];
827 $prodfourn->fourn_name = $record["supplier_name"];
828 $prodfourn->fk_availability = $record["fk_availability"];
829 $prodfourn->delivery_time_days = $record["delivery_time_days"];
830 $prodfourn->id = $prodid;
831 $prodfourn->fourn_tva_npr = $record["info_bits"];
832 $prodfourn->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
833 $prodfourn->supplier_reputation = $record["supplier_reputation"];
834 $prodfourn->fourn_date_creation = $this->db->jdate($record['datec']);
835 $prodfourn->fourn_date_modification = $this->db->jdate($record['tms']);
836
837 $prodfourn->fourn_multicurrency_price = $record["multicurrency_price"];
838 $prodfourn->fourn_multicurrency_unitprice = $record["multicurrency_unitprice"];
839 $prodfourn->fourn_multicurrency_tx = $record["multicurrency_tx"];
840 $prodfourn->fourn_multicurrency_id = $record["fk_multicurrency"];
841 $prodfourn->fourn_multicurrency_code = $record["multicurrency_code"];
842
843 $prodfourn->packaging = $record["packaging"];
844 $prodfourn->status = $record["pfstatus"];
845
846 if (isModEnabled('barcode')) {
847 $prodfourn->supplier_barcode = $record["barcode"];
848 $prodfourn->supplier_fk_barcode_type = $record["fk_barcode_type"];
849 }
850
851 if (isModEnabled('dynamicprices') && !empty($prodfourn->fk_supplier_price_expression)) {
852 require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
853 $priceparser = new PriceParser($this->db);
854 $price_result = $priceparser->parseProductSupplier($prodfourn);
855 if ($price_result >= 0) {
856 $prodfourn->fourn_price = $price_result;
857 $prodfourn->fourn_unitprice = null; //force recalculation of unitprice, as probably the price changed...
858 }
859 }
860
861 if (!isset($prodfourn->fourn_unitprice)) {
862 if ($prodfourn->fourn_qty != 0) {
863 $prodfourn->fourn_unitprice = price2num($prodfourn->fourn_price / $prodfourn->fourn_qty, 'MU');
864 } else {
865 $prodfourn->fourn_unitprice = "";
866 }
867 }
868
869 $retarray[] = $prodfourn;
870 }
871
872 $this->db->free($resql);
873 return $retarray;
874 } else {
875 $this->error = $this->db->error();
876 return -1;
877 }
878 }
879
880 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
890 public function find_min_price_product_fournisseur($prodid, $qty = 0, $socid = 0)
891 {
892 // phpcs:enable
893 if (empty($prodid)) {
894 dol_syslog("Warning function find_min_price_product_fournisseur were called with prodid empty. May be a bug.", LOG_WARNING);
895 return 0;
896 }
897
898 $this->product_fourn_price_id = 0;
899 $this->product_fourn_id = 0;
900 $this->fourn_ref = '';
901 $this->fourn_price = 0;
902 $this->fourn_qty = 0;
903 $this->fourn_remise_percent = 0;
904 $this->fourn_remise = 0;
905 $this->fourn_unitprice = 0;
906 $this->fourn_id = 0;
907 $this->fourn_name = '';
908 $this->delivery_time_days = 0;
909 $this->id = 0;
910
911 $this->fourn_multicurrency_price = 0;
912 $this->fourn_multicurrency_unitprice = 0;
913 $this->fourn_multicurrency_tx = 0;
914 $this->fourn_multicurrency_id = '';
915 $this->fourn_multicurrency_code = '';
916
917 $sql = "SELECT s.nom as supplier_name, s.rowid as fourn_id,";
918 $sql .= " pfp.rowid as product_fourn_price_id, pfp.ref_fourn,";
919 $sql .= " pfp.price, pfp.quantity, pfp.unitprice, pfp.tva_tx, pfp.charges,";
920 $sql .= " pfp.remise, pfp.remise_percent, pfp.fk_supplier_price_expression, pfp.delivery_time_days,";
921 $sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code";
922 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
923 $sql .= " WHERE s.entity IN (".getEntity('societe').")";
924 $sql .= " AND pfp.entity IN (".getEntity('productsupplierprice').")";
925 $sql .= " AND pfp.fk_product = ".((int) $prodid);
926 $sql .= " AND pfp.fk_soc = s.rowid";
927 $sql .= " AND s.status = 1"; // only enabled society
928 if ($qty > 0) {
929 $sql .= " AND pfp.quantity <= ".((float) $qty);
930 }
931 if ($socid > 0) {
932 $sql .= ' AND pfp.fk_soc = '.((int) $socid);
933 }
934
935 dol_syslog(get_class($this)."::find_min_price_product_fournisseur", LOG_DEBUG);
936
937 $resql = $this->db->query($sql);
938 if ($resql) {
939 $record_array = array();
940
941 //Store each record to array for later search of min
942 while ($record = $this->db->fetch_array($resql)) {
943 $record_array[] = $record;
944 }
945
946 if (count($record_array) == 0) {
947 $this->db->free($resql);
948 return 0;
949 } else {
950 $min = -1;
951 foreach ($record_array as $record) {
952 $fourn_price = $record["price"];
953 // calculate unit price for quantity 1
954 $fourn_unitprice = $record["unitprice"];
955 $fourn_unitprice_with_discount = $record["unitprice"] * (1 - $record["remise_percent"] / 100);
956
957 if (isModEnabled('dynamicprices') && !empty($record["fk_supplier_price_expression"])) {
958 $prod_supplier = new ProductFournisseur($this->db);
959 $prod_supplier->product_fourn_price_id = $record["product_fourn_price_id"];
960 $prod_supplier->id = $prodid;
961 $prod_supplier->fourn_qty = $record["quantity"];
962 $prod_supplier->fourn_tva_tx = $record["tva_tx"];
963 $prod_supplier->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
964
965 require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
966 $priceparser = new PriceParser($this->db);
967 $price_result = $priceparser->parseProductSupplier($prod_supplier);
968 if ($price_result >= 0) {
969 $fourn_price = price2num($price_result, 'MU');
970 if ($record["quantity"] != 0) {
971 $fourn_unitprice = price2num($fourn_price / $record["quantity"], 'MU');
972 } else {
973 $fourn_unitprice = $fourn_price;
974 }
975 $fourn_unitprice_with_discount = $fourn_unitprice * (1 - $record["remise_percent"] / 100);
976 }
977 }
978
979 if ($fourn_unitprice < $min || $min == -1) {
980 $this->id = $prodid;
981 $this->product_fourn_price_id = $record["product_fourn_price_id"];
982 $this->ref_supplier = $record["ref_fourn"];
983 $this->ref_fourn = $record["ref_fourn"]; // deprecated
984 $this->fourn_ref = $record["ref_fourn"]; // deprecated
985 $this->fourn_price = $fourn_price;
986 $this->fourn_qty = $record["quantity"];
987 $this->fourn_remise_percent = $record["remise_percent"];
988 $this->fourn_remise = $record["remise"];
989 $this->fourn_unitprice = $fourn_unitprice;
990 $this->fourn_unitprice_with_discount = $fourn_unitprice_with_discount;
991 $this->fourn_charges = $record["charges"]; // when getDolGlobalString('PRODUCT_CHARGES') is set
992 $this->fourn_tva_tx = $record["tva_tx"];
993 $this->fourn_id = $record["fourn_id"]; // thirdparty id
994 $this->fourn_name = $record["supplier_name"];
995 $this->delivery_time_days = $record["delivery_time_days"];
996 $this->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
997 $this->fourn_multicurrency_price = $record["multicurrency_price"];
998 $this->fourn_multicurrency_unitprice = $record["multicurrency_unitprice"];
999 $this->fourn_multicurrency_tx = $record["multicurrency_tx"];
1000 $this->fourn_multicurrency_id = $record["fk_multicurrency"];
1001 $this->fourn_multicurrency_code = $record["multicurrency_code"];
1002
1003 $min = $fourn_unitprice;
1004 }
1005 }
1006 }
1007
1008 $this->db->free($resql);
1009
1010 return $this->product_fourn_price_id;
1011 } else {
1012 $this->error = $this->db->error();
1013 return -1;
1014 }
1015 }
1016
1023 public function setSupplierPriceExpression($expression_id)
1024 {
1025 global $conf;
1026
1027 // Clean parameters
1028 $this->db->begin();
1029 $expression_id = $expression_id != 0 ? $expression_id : 'NULL';
1030
1031 $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price";
1032 $sql .= " SET fk_supplier_price_expression = ".((int) $expression_id);
1033 $sql .= " WHERE rowid = ".((int) $this->product_fourn_price_id);
1034
1035 dol_syslog(get_class($this)."::setSupplierPriceExpression", LOG_DEBUG);
1036
1037 $resql = $this->db->query($sql);
1038 if ($resql) {
1039 $this->db->commit();
1040 return 1;
1041 } else {
1042 $this->error = $this->db->error()." sql=".$sql;
1043 $this->db->rollback();
1044 return -1;
1045 }
1046 }
1047
1058 public function getSocNomUrl($withpicto = 0, $option = 'supplier', $maxlen = 0, $notooltip = 0)
1059 {
1060 $thirdparty = new Fournisseur($this->db);
1061 $thirdparty->fetch($this->fourn_id);
1062
1063 return $thirdparty->getNomUrl($withpicto, $option, $maxlen, $notooltip);
1064 }
1065
1066 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1078 public function display_price_product_fournisseur($showunitprice = 1, $showsuptitle = 1, $maxlen = 0, $notooltip = 0, $productFournList = array())
1079 {
1080 // phpcs:enable
1081 global $conf, $langs;
1082
1083 $out = '';
1084 $langs->load("suppliers");
1085 if (count($productFournList) > 0) {
1086 $out .= '<table class="nobordernopadding" width="100%">';
1087 $out .= '<tr><td class="liste_titre right">'.($showunitprice ? $langs->trans("Price").' '.$langs->trans("HT") : '').'</td>';
1088 $out .= '<td class="liste_titre right">'.($showunitprice ? $langs->trans("QtyMin") : '').'</td>';
1089 $out .= '<td class="liste_titre">'.$langs->trans("Supplier").'</td>';
1090 $out .= '<td class="liste_titre">'.$langs->trans("SupplierRef").'</td></tr>';
1091 foreach ($productFournList as $productFourn) {
1092 $out .= '<tr><td class="right">'.($showunitprice ? price($productFourn->fourn_unitprice * (1 - $productFourn->fourn_remise_percent / 100) - $productFourn->fourn_remise) : '').'</td>';
1093 $out .= '<td class="right">'.($showunitprice ? $productFourn->fourn_qty : '').'</td>';
1094 $out .= '<td>'.$productFourn->getSocNomUrl(1, 'supplier', $maxlen, $notooltip).'</td>';
1095 $out .= '<td>'.$productFourn->fourn_ref.'<td></tr>';
1096 }
1097 $out .= '</table>';
1098 } else {
1099 $out = ($showunitprice ? price($this->fourn_unitprice * (1 - $this->fourn_remise_percent / 100) + $this->fourn_remise, 0, $langs, 1, -1, -1, $conf->currency).' '.$langs->trans("HT").' &nbsp; <span class="opacitymedium">(</span>' : '');
1100 $out .= ($showsuptitle ? '<span class="opacitymedium">'.$langs->trans("Supplier").'</span>: ' : '').$this->getSocNomUrl(1, 'supplier', $maxlen, $notooltip).' / <span class="opacitymedium">'.$langs->trans("SupplierRef").'</span>: '.$this->ref_supplier;
1101 $out .= ($showunitprice ? '<span class="opacitymedium">)</span>' : '');
1102 }
1103 return $out;
1104 }
1105
1114 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1115 {
1116 $tables = array(
1117 'product_fournisseur_price'
1118 );
1119
1120 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1121 }
1122
1131 public static function replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
1132 {
1133 $tables = array(
1134 'product_fournisseur_price'
1135 );
1136
1137 return CommonObject::commonReplaceProduct($dbs, $origin_id, $dest_id, $tables);
1138 }
1139
1150 public function listProductFournisseurPriceLog($product_fourn_price_id, $sortfield = '', $sortorder = '', $limit = 0, $offset = 0)
1151 {
1152 $sql = "SELECT";
1153 $sql .= " u.lastname,";
1154 $sql .= " pfpl.rowid, pfp.ref_fourn as supplier_ref, pfpl.datec,";
1155 $sql .= " pfpl.price, pfpl.quantity,";
1156 $sql .= " pfpl.fk_multicurrency, pfpl.multicurrency_code, pfpl.multicurrency_tx, pfpl.multicurrency_price, pfpl.multicurrency_unitprice";
1157 $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price_log as pfpl,";
1158 $sql .= " ".MAIN_DB_PREFIX."product_fournisseur_price as pfp,";
1159 $sql .= " ".MAIN_DB_PREFIX."user as u";
1160 $sql .= " WHERE pfp.entity IN (".getEntity('productprice').")";
1161 $sql .= " AND pfpl.fk_user = u.rowid";
1162 $sql .= " AND pfp.rowid = pfpl.fk_product_fournisseur";
1163 $sql .= " AND pfpl.fk_product_fournisseur = ".((int) $product_fourn_price_id);
1164 if (empty($sortfield)) {
1165 $sql .= " ORDER BY pfpl.datec";
1166 } else {
1167 $sql .= $this->db->order($sortfield, $sortorder);
1168 }
1169 $sql .= $this->db->plimit($limit, $offset);
1170 dol_syslog(get_class($this)."::list_product_fournisseur_price_log", LOG_DEBUG);
1171
1172 $resql = $this->db->query($sql);
1173 if ($resql) {
1174 $retarray = array();
1175
1176 while ($obj = $this->db->fetch_object($resql)) {
1177 $tmparray = array();
1178 $tmparray['rowid'] = $obj->rowid;
1179 $tmparray['supplier_ref'] = $obj->supplier_ref;
1180 $tmparray['datec'] = $this->db->jdate($obj->datec);
1181 $tmparray['lastname'] = $obj->lastname;
1182 $tmparray['price'] = $obj->price;
1183 $tmparray['quantity'] = $obj->quantity;
1184 $tmparray['fk_multicurrency'] = $obj->fk_multicurrency;
1185 $tmparray['multicurrency_code'] = $obj->multicurrency_code;
1186 $tmparray['multicurrency_tx'] = $obj->multicurrency_tx;
1187 $tmparray['multicurrency_price'] = $obj->multicurrency_price;
1188 $tmparray['multicurrency_unitprice'] = $obj->multicurrency_unitprice;
1189
1190 $retarray[] = $tmparray;
1191 }
1192
1193 $this->db->free($resql);
1194 return $retarray;
1195 } else {
1196 $this->error = $this->db->error();
1197 return -1;
1198 }
1199 }
1200
1208 public function displayPriceProductFournisseurLog($productFournLogList = array())
1209 {
1210 global $conf, $langs;
1211
1212 $out = '';
1213 $langs->load("suppliers");
1214 if (count($productFournLogList) > 0) {
1215 $out .= '<table class="noborder centpercent">';
1216 $out .= '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Date").'</td>';
1217 $out .= '<td class="liste_titre right">'.$langs->trans("Price").'</td>';
1218 //$out .= '<td class="liste_titre right">'.$langs->trans("QtyMin").'</td>';
1219 $out .= '<td class="liste_titre">'.$langs->trans("User").'</td></tr>';
1220 foreach ($productFournLogList as $productFournLog) {
1221 $out .= '<tr><td>'.dol_print_date($productFournLog['datec'], 'dayhour', 'tzuser').'</td>';
1222 $out .= '<td class="right">'.price($productFournLog['price'], 0, $langs, 1, -1, -1, $conf->currency);
1223 if ($productFournLog['multicurrency_code'] != $conf->currency) {
1224 $out .= ' ('.price($productFournLog['multicurrency_price'], 0, $langs, 1, -1, -1, $productFournLog['multicurrency_code']).')';
1225 }
1226 $out .= '</td>';
1227 //$out.= '<td class="right">'.$productFournLog['quantity'].'</td>';
1228 $out .= '<td>'.$productFournLog['lastname'].'</td></tr>';
1229 }
1230 $out .= '</table>';
1231 }
1232 return $out;
1233 }
1234
1235
1250 public function getNomUrl($withpicto = 0, $option = '', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss = '', $add_label = 0, $sep = ' - ')
1251 {
1252 global $db, $conf, $langs, $hookmanager;
1253
1254 if (!empty($conf->dol_no_mouse_hover)) {
1255 $notooltip = 1; // Force disable tooltips
1256 }
1257
1258 $result = '';
1259 $label = '';
1260
1261 $newref = $this->ref;
1262 if ($maxlength) {
1263 $newref = dol_trunc($newref, $maxlength, 'middle');
1264 }
1265
1266 if (!empty($this->entity)) {
1267 $tmpphoto = $this->show_photos('product', $conf->product->multidir_output[$this->entity], 1, 1, 0, 0, 0, 80);
1268 if ($this->nbphoto > 0) {
1269 $label .= '<div class="photointooltip">';
1270 $label .= $tmpphoto;
1271 $label .= '</div><div style="clear: both;"></div>';
1272 }
1273 }
1274
1275 if ($this->type == Product::TYPE_PRODUCT) {
1276 $label .= img_picto('', 'product').' <u class="paddingrightonly">'.$langs->trans("Product").'</u>';
1277 } elseif ($this->type == Product::TYPE_SERVICE) {
1278 $label .= img_picto('', 'service').' <u class="paddingrightonly">'.$langs->trans("Service").'</u>';
1279 }
1280 if (isset($this->status) && isset($this->status_buy)) {
1281 $label .= ' '.$this->getLibStatut(5, 0);
1282 $label .= ' '.$this->getLibStatut(5, 1);
1283 }
1284
1285 if (!empty($this->ref)) {
1286 $label .= '<br><b>'.$langs->trans('ProductRef').':</b> '.($this->ref ? $this->ref : $this->product_ref);
1287 }
1288 if (!empty($this->label)) {
1289 $label .= '<br><b>'.$langs->trans('ProductLabel').':</b> '.$this->label;
1290 }
1291 $label .= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_supplier;
1292
1293 if ($this->type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
1294 if (isModEnabled('productbatch')) {
1295 $langs->load("productbatch");
1296 $label .= "<br><b>".$langs->trans("ManageLotSerial").'</b>: '.$this->getLibStatut(0, 2);
1297 }
1298 }
1299 if (isModEnabled('barcode')) {
1300 $label .= '<br><b>'.$langs->trans('BarCode').':</b> '.$this->barcode;
1301 }
1302
1303 if ($this->type == Product::TYPE_PRODUCT) {
1304 if ($this->weight) {
1305 $label .= "<br><b>".$langs->trans("Weight").'</b>: '.$this->weight.' '.measuringUnitString(0, "weight", $this->weight_units);
1306 }
1307 $labelsize = "";
1308 if ($this->length) {
1309 $labelsize .= ($labelsize ? " - " : "")."<b>".$langs->trans("Length").'</b>: '.$this->length.' '.measuringUnitString(0, 'size', $this->length_units);
1310 }
1311 if ($this->width) {
1312 $labelsize .= ($labelsize ? " - " : "")."<b>".$langs->trans("Width").'</b>: '.$this->width.' '.measuringUnitString(0, 'size', $this->width_units);
1313 }
1314 if ($this->height) {
1315 $labelsize .= ($labelsize ? " - " : "")."<b>".$langs->trans("Height").'</b>: '.$this->height.' '.measuringUnitString(0, 'size', $this->height_units);
1316 }
1317 if ($labelsize) {
1318 $label .= "<br>".$labelsize;
1319 }
1320
1321 $labelsurfacevolume = "";
1322 if ($this->surface) {
1323 $labelsurfacevolume .= ($labelsurfacevolume ? " - " : "")."<b>".$langs->trans("Surface").'</b>: '.$this->surface.' '.measuringUnitString(0, 'surface', $this->surface_units);
1324 }
1325 if ($this->volume) {
1326 $labelsurfacevolume .= ($labelsurfacevolume ? " - " : "")."<b>".$langs->trans("Volume").'</b>: '.$this->volume.' '.measuringUnitString(0, 'volume', $this->volume_units);
1327 }
1328 if ($labelsurfacevolume) {
1329 $label .= "<br>".$labelsurfacevolume;
1330 }
1331 }
1332
1333 if (isModEnabled('accounting') && $this->status) {
1334 include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
1335 $label .= '<br><b>'.$langs->trans('ProductAccountancySellCode').':</b> '.length_accountg($this->accountancy_code_sell);
1336 $label .= '<br><b>'.$langs->trans('ProductAccountancySellIntraCode').':</b> '.length_accountg($this->accountancy_code_sell_intra);
1337 $label .= '<br><b>'.$langs->trans('ProductAccountancySellExportCode').':</b> '.length_accountg($this->accountancy_code_sell_export);
1338 }
1339 if (isModEnabled('accounting') && $this->status_buy) {
1340 include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
1341 $label .= '<br><b>'.$langs->trans('ProductAccountancyBuyCode').':</b> '.length_accountg($this->accountancy_code_buy);
1342 $label .= '<br><b>'.$langs->trans('ProductAccountancyBuyIntraCode').':</b> '.length_accountg($this->accountancy_code_buy_intra);
1343 $label .= '<br><b>'.$langs->trans('ProductAccountancyBuyExportCode').':</b> '.length_accountg($this->accountancy_code_buy_export);
1344 }
1345
1346 $logPrices = $this->listProductFournisseurPriceLog($this->product_fourn_price_id, 'pfpl.datec', 'DESC'); // set sort order here
1347 if (is_array($logPrices) && count($logPrices) > 0) {
1348 $label .= '<br><br>';
1349 $label .= '<u>'.$langs->trans("History").'</u>';
1350 $label .= $this->displayPriceProductFournisseurLog($logPrices);
1351 }
1352
1353 $url = DOL_URL_ROOT.'/product/price_suppliers.php?id='.((int) $this->id).'&action=create_price&token='.newToken().'&socid='.((int) $this->fourn_id).'&rowid='.((int) $this->product_fourn_price_id);
1354
1355 if ($option != 'nolink') {
1356 // Add param to save lastsearch_values or not
1357 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1358 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1359 $add_save_lastsearch_values = 1;
1360 }
1361 if ($add_save_lastsearch_values) {
1362 $url .= '&save_lastsearch_values=1';
1363 }
1364 }
1365
1366 $linkclose = '';
1367 if (empty($notooltip)) {
1368 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1369 $label = $langs->trans("SupplierRef");
1370 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1371 }
1372 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1373 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1374 } else {
1375 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1376 }
1377
1378 $linkstart = '<a href="'.$url.'"';
1379 $linkstart .= $linkclose.'>';
1380 $linkend = '</a>';
1381
1382 $result .= $linkstart;
1383 if ($withpicto) {
1384 $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);
1385 }
1386 if ($withpicto != 2) {
1387 $result .= $newref.($this->ref_supplier ? ' ('.$this->ref_supplier.')' : '');
1388 }
1389 $result .= $linkend;
1390 if ($withpicto != 2) {
1391 $result .= (($add_label && $this->label) ? $sep.dol_trunc($this->label, ($add_label > 1 ? $add_label : 0)) : '');
1392 }
1393
1394 global $action;
1395 $hookmanager->initHooks(array($this->element . 'dao'));
1396 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1397 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1398 if ($reshook > 0) {
1399 $result = $hookmanager->resPrint;
1400 } else {
1401 $result .= $hookmanager->resPrint;
1402 }
1403 return $result;
1404 }
1405
1413 public function getLibStatut($mode = 0, $type = 0) // must be compatible with getLibStatut of inherited Product
1414 {
1415 return $this->LibStatut($this->status, $mode);
1416 }
1417
1418 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1427 public function LibStatut($status, $mode = 0, $type = 0)
1428 {
1429 // phpcs:enable
1430 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1431 global $langs;
1432 //$langs->load("mymodule@mymodule");
1433 $this->labelStatus[self::STATUS_OPEN] = $langs->transnoentitiesnoconv('Enabled');
1434 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
1435 $this->labelStatusShort[self::STATUS_OPEN] = $langs->transnoentitiesnoconv('Enabled');
1436 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
1437 }
1438
1439 $statusType = 'status4';
1440 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
1441 if ($status == self::STATUS_CANCELED) {
1442 $statusType = 'status6';
1443 }
1444
1445 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1446 }
1447
1463 private function logPrice($user, $datec, $buyprice, $qty, $multicurrency_buyprice = null, $multicurrency_unitBuyPrice = null, $multicurrency_tx = null, $fk_multicurrency = null, $multicurrency_code = null)
1464 {
1465 // Add record into log table
1466 $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log(";
1467 $sql .= " multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,";
1468 $sql .= "datec, fk_product_fournisseur,fk_user,price,quantity)";
1469 $sql .= "values(";
1470 $sql .= (isset($multicurrency_buyprice) ? "'".$this->db->escape(price2num($multicurrency_buyprice))."'" : 'null').",";
1471 $sql .= (isset($multicurrency_unitBuyPrice) ? "'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'" : 'null').",";
1472 $sql .= (isset($multicurrency_tx) ? "'".$this->db->escape($multicurrency_tx)."'" : '1').",";
1473 $sql .= (isset($fk_multicurrency) ? "'".$this->db->escape($fk_multicurrency)."'" : 'null').",";
1474 $sql .= (isset($multicurrency_code) ? "'".$this->db->escape($multicurrency_code)."'" : 'null').",";
1475 $sql .= "'".$this->db->idate($datec)."',";
1476 $sql .= " ".((int) $this->product_fourn_price_id).",";
1477 $sql .= " ".$user->id.",";
1478 $sql .= " ".price2num($buyprice).",";
1479 $sql .= " ".price2num($qty);
1480 $sql .= ")";
1481
1482 $resql = $this->db->query($sql);
1483 if (!$resql) {
1484 return -1;
1485 } else {
1486 return 1;
1487 }
1488 }
1489}
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:637
$object ref
Definition info.php:79
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
show_photos($modulepart, $sdir, $size=0, $nbmax=0, $nbbyrow=5, $showfilename=0, $showaction=0, $maxHeight=120, $maxWidth=160, $nolink=0, $overwritetitle=0, $usesharelink=0, $cache='', $addphotorefcss='photoref')
Show photos of an object (nbmax maximum), into several columns.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage suppliers.
static getIdFromCode($dbs, $code)
Get id of currency from code.
Class to parse product price expressions.
Class to manage predefined suppliers products.
displayPriceProductFournisseurLog($productFournLogList=array())
Display log price of product supplier price.
listProductFournisseurPriceLog($product_fourn_price_id, $sortfield='', $sortorder='', $limit=0, $offset=0)
List supplier prices log of a supplier price.
getSocNomUrl($withpicto=0, $option='supplier', $maxlen=0, $notooltip=0)
Display supplier of product.
LibStatut($status, $mode=0, $type=0)
Return the status.
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.
setSupplierPriceExpression($expression_id)
Sets the supplier price expression.
find_min_price_product_fournisseur($prodid, $qty=0, $socid=0)
Load properties for minimum price.
list_product_fournisseur_price($prodid, $sortfield='', $sortorder='', $limit=0, $offset=0, $socid=0)
List all supplier prices of a product.
fetch_product_fournisseur_price($rowid, $ignore_expression=0)
Loads the price information of a provider.
remove_fournisseur($id_fourn)
Remove all prices for this couple supplier-product.
getNomUrl($withpicto=0, $option='', $maxlength=0, $save_lastsearch_value=-1, $notooltip=0, $morecss='', $add_label=0, $sep=' - ')
Return a link to the object card (with optionally the picto).
getLibStatut($mode=0, $type=0)
Return the label of the status.
remove_product_fournisseur_price($rowid)
Remove a price for a couple supplier-product.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
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=0, $options=array())
Modify the purchase price for a supplier.
display_price_product_fournisseur($showunitprice=1, $showsuptitle=1, $maxlen=0, $notooltip=0, $productFournList=array())
Display price of product.
Class for ProductFournisseurPrice.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
$remise_percent
Default discount percent.
$tva_tx
Default VAT rate of product.
const TYPE_SERVICE
Service.
Class to manage Dolibarr users.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
dol_now($mode='auto')
Return date for now.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137