dolibarr 19.0.3
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-2021 Frédéric France <frederic.france@netlogic.fr>
10 * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
33require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/class/productfournisseurprice.class.php';
35
36
41{
45 public $db;
46
50 public $error = '';
51
52 public $product_fourn_price_id; // id of ligne product-supplier
53
57 public $id;
58
63 public $fourn_ref;
64
65 public $delivery_time_days;
66 public $ref_supplier; // ref supplier (can be set by get_buyprice)
67 public $desc_supplier;
68 public $vatrate_supplier; // default vat rate for this supplier/qty/product (can be set by get_buyprice)
69
75 public $product_id;
76 public $product_ref;
77
78 public $fourn_id; //supplier id
79 public $fourn_name; // supplier name
80 public $fourn_qty; // quantity for price (can be set by get_buyprice)
81 public $fourn_pu; // unit price for quantity (can be set by get_buyprice)
82
83 public $fourn_price; // price for quantity
84 public $fourn_remise_percent; // discount for quantity (percent)
85 public $fourn_remise; // discount for quantity (amount)
86
87 public $fourn_charges; // when getDolGlobalString('PRODUCT_CHARGES') is set
88
89 public $product_fourn_id; // product-supplier id
90 public $product_fourn_entity;
91
95 public $user_id;
96
100 public $fk_availability;
101
102 public $fourn_unitprice;
103 public $fourn_unitprice_with_discount; // not saved into database
104 public $fourn_tva_tx;
105 public $fourn_tva_npr;
106
110 public $fk_supplier_price_expression;
111
112 public $supplier_reputation; // reputation of supplier
113 public $reputations = array(); // list of available supplier reputations
114
115 // Multicurreny
116 public $fourn_multicurrency_id;
117 public $fourn_multicurrency_code;
118 public $fourn_multicurrency_tx;
119 public $fourn_multicurrency_price;
120 public $fourn_multicurrency_unitprice;
121
127
131 public $supplier_barcode;
132
138
142 public $supplier_fk_barcode_type;
143
144 public $packaging;
145
146 public $labelStatusShort;
147 public $labelStatus;
148
149 const STATUS_OPEN = 1;
150 const STATUS_CANCELED = 0;
151
152
158 public function __construct($db)
159 {
160 global $langs;
161
162 $this->db = $db;
163 $langs->load("suppliers");
164 $this->reputations = array('-1'=>'', 'FAVORITE'=>$langs->trans('Favorite'), 'NOTTHGOOD'=>$langs->trans('NotTheGoodQualitySupplier'), 'DONOTORDER'=>$langs->trans('DoNotOrderThisProductToThisSupplier'));
165 }
166
167 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
174 public function remove_fournisseur($id_fourn)
175 {
176 // phpcs:enable
177 $ok = 1;
178
179 $this->db->begin();
180
181 $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
182 $sql .= " WHERE fk_product = ".((int) $this->id)." AND fk_soc = ".((int) $id_fourn);
183
184 dol_syslog(get_class($this)."::remove_fournisseur", LOG_DEBUG);
185 $resql2 = $this->db->query($sql);
186 if (!$resql2) {
187 $this->error = $this->db->lasterror();
188 $ok = 0;
189 }
190
191 if ($ok) {
192 $this->db->commit();
193 return 1;
194 } else {
195 $this->db->rollback();
196 return -1;
197 }
198 }
199
200
201 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
208 public function remove_product_fournisseur_price($rowid)
209 {
210 // phpcs:enable
211 global $conf, $user;
212
213 $error = 0;
214
215 $this->db->begin();
216
217 // Call trigger
218 $result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_DELETE', $user);
219 if ($result < 0) {
220 $error++;
221 }
222 // End call triggers
223
224 if (empty($error)) {
225 $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
226 $sql .= " WHERE rowid = ".((int) $rowid);
227
228 dol_syslog(get_class($this)."::remove_product_fournisseur_price", LOG_DEBUG);
229 $resql = $this->db->query($sql);
230 if (!$resql) {
231 $this->error = $this->db->lasterror();
232 $error++;
233 }
234 }
235
236 if (empty($error)) {
237 $this->db->commit();
238 return 1;
239 } else {
240 $this->db->rollback();
241 return -1;
242 }
243 }
244
245
246 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
276 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())
277 {
278 // phpcs:enable
279 global $conf, $langs;
280 //global $mysoc;
281
282 // Clean parameter
283 if (empty($qty)) {
284 $qty = 0;
285 }
286 if (empty($buyprice)) {
287 $buyprice = 0;
288 }
289 if (empty($charges)) {
290 $charges = 0;
291 }
292 if (empty($availability)) {
293 $availability = 0;
294 }
295 if (empty($remise_percent)) {
296 $remise_percent = 0;
297 }
298 if (empty($supplier_reputation) || $supplier_reputation == -1) {
299 $supplier_reputation = '';
300 }
301 if ($delivery_time_days != '' && !is_numeric($delivery_time_days)) {
302 $delivery_time_days = '';
303 }
304 if ($price_base_type == 'TTC') {
305 $ttx = $tva_tx;
306 $buyprice = $buyprice / (1 + ($ttx / 100));
307 }
308
309 // Multicurrency
310 $multicurrency_unitBuyPrice = null;
311 $fk_multicurrency = null;
312 if (isModEnabled("multicurrency")) {
313 if (empty($multicurrency_tx)) {
314 $multicurrency_tx = 1;
315 }
316 if (empty($multicurrency_buyprice)) {
317 $multicurrency_buyprice = 0;
318 }
319 if ($multicurrency_price_base_type == 'TTC') {
320 $ttx = $tva_tx;
321 $multicurrency_buyprice = $multicurrency_buyprice / (1 + ($ttx / 100));
322 }
323 $multicurrency_buyprice = price2num($multicurrency_buyprice, 'MU');
324 $multicurrency_unitBuyPrice = price2num($multicurrency_buyprice / $qty, 'MU');
325
326 $buyprice = $multicurrency_buyprice / $multicurrency_tx;
327 $fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $multicurrency_code);
328 }
329
330 $buyprice = (float) price2num($buyprice, 'MU');
331 $charges = (float) price2num($charges, 'MU');
332 $qty = (float) price2num($qty, 'MS');
333 $unitBuyPrice = (float) price2num($buyprice / $qty, 'MU');
334
335 // We can have a puchase ref that need to buy 100 min for a given price and with a packaging of 50.
336 //$packaging = price2num(((empty($this->packaging) || $this->packaging < $qty) ? $qty : $this->packaging), 'MS');
337 $packaging = price2num((empty($this->packaging) ? $qty : $this->packaging), 'MS');
338
339 $error = 0;
340 $now = dol_now();
341
342 $newvat = $tva_tx;
343
344 if (count($localtaxes_array) > 0) {
345 $localtaxtype1 = $localtaxes_array['0'];
346 $localtax1 = $localtaxes_array['1'];
347 $localtaxtype2 = $localtaxes_array['2'];
348 $localtax2 = $localtaxes_array['3'];
349 } else { // old method. deprecated because ot can't retrieve type
350 $localtaxtype1 = '0';
351 $localtax1 = get_localtax($newvat, 1);
352 $localtaxtype2 = '0';
353 $localtax2 = get_localtax($newvat, 2);
354 }
355 if (empty($localtax1)) {
356 $localtax1 = 0; // If = '' then = 0
357 }
358 if (empty($localtax2)) {
359 $localtax2 = 0; // If = '' then = 0
360 }
361
362 $this->db->begin();
363
364 if ($this->product_fourn_price_id > 0) {
365 // check if price already logged, if not first log current price
366 $logPrices = $this->listProductFournisseurPriceLog($this->product_fourn_price_id);
367 if (is_array($logPrices) && count($logPrices) == 0) {
368 $currentPfp = new self($this->db);
369 $result = $currentPfp->fetch_product_fournisseur_price($this->product_fourn_price_id);
370 if ($result > 0 && $currentPfp->fourn_price != 0) {
371 $currentPfpUser = new User($this->db);
372 $result = $currentPfpUser->fetch($currentPfp->user_id);
373 if ($result > 0) {
374 $currentPfp->logPrice(
375 $currentPfpUser,
376 $currentPfp->date_creation,
377 $currentPfp->fourn_price,
378 $currentPfp->fourn_qty,
379 $currentPfp->fourn_multicurrency_price,
380 $currentPfp->fourn_multicurrency_unitprice,
381 $currentPfp->fourn_multicurrency_tx,
382 $currentPfp->fourn_multicurrency_id,
383 $currentPfp->fourn_multicurrency_code
384 );
385 }
386 }
387 }
388 $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price";
389 $sql .= " SET fk_user = ".((int) $user->id)." ,";
390 $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.
391 $sql .= " ref_fourn = '".$this->db->escape($ref_fourn)."',";
392 $sql .= " desc_fourn = '".$this->db->escape($desc_fourn)."',";
393 $sql .= " price = ".((float) $buyprice).",";
394 $sql .= " quantity = ".((float) $qty).",";
395 $sql .= " remise_percent = ".((float) $remise_percent).",";
396 $sql .= " remise = ".((float) $remise).",";
397 $sql .= " unitprice = ".((float) $unitBuyPrice).",";
398 $sql .= " fk_availability = ".((int) $availability).",";
399 $sql .= " multicurrency_price = ".(isset($multicurrency_buyprice) ? "'".$this->db->escape(price2num($multicurrency_buyprice))."'" : 'null').",";
400 $sql .= " multicurrency_unitprice = ".(isset($multicurrency_unitBuyPrice) ? "'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'" : 'null').",";
401 $sql .= " multicurrency_tx = ".(isset($multicurrency_tx) ? "'".$this->db->escape($multicurrency_tx)."'" : '1').",";
402 $sql .= " fk_multicurrency = ".(isset($fk_multicurrency) ? "'".$this->db->escape($fk_multicurrency)."'" : 'null').",";
403 $sql .= " multicurrency_code = ".(isset($multicurrency_code) ? "'".$this->db->escape($multicurrency_code)."'" : 'null').",";
404 $sql .= " entity = ".$conf->entity.",";
405 $sql .= " tva_tx = ".price2num($tva_tx).",";
406 // TODO Add localtax1 and localtax2
407 //$sql.= " localtax1_tx=".($localtax1>=0?$localtax1:'NULL').",";
408 //$sql.= " localtax2_tx=".($localtax2>=0?$localtax2:'NULL').",";
409 //$sql.= " localtax1_type=".($localtaxtype1!=''?"'".$this->db->escape($localtaxtype1)."'":"'0'").",";
410 //$sql.= " localtax2_type=".($localtaxtype2!=''?"'".$this->db->escape($localtaxtype2)."'":"'0'").",";
411 $sql .= " default_vat_code=".($newdefaultvatcode ? "'".$this->db->escape($newdefaultvatcode)."'" : "null").",";
412 $sql .= " info_bits = ".((int) $newnpr).",";
413 $sql .= " charges = ".((float) $charges).","; // deprecated
414 $sql .= " delivery_time_days = ".($delivery_time_days != '' ? ((int) $delivery_time_days) : 'null').",";
415 $sql .= " supplier_reputation = ".(empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'").",";
416 $sql .= " barcode = ".(empty($barcode) ? 'NULL' : "'".$this->db->escape($barcode)."'").",";
417 $sql .= " fk_barcode_type = ".(empty($fk_barcode_type) ? 'NULL' : "'".$this->db->escape($fk_barcode_type)."'");
418 if (getDolGlobalString('PRODUCT_USE_SUPPLIER_PACKAGING')) {
419 $sql .= ", packaging = ".(empty($packaging) ? 1 : $packaging);
420 }
421 $sql .= " WHERE rowid = ".((int) $this->product_fourn_price_id);
422
423 if (!$error) {
424 if (!empty($options) && is_array($options)) {
425 $productfournisseurprice = new ProductFournisseurPrice($this->db);
426 $res = $productfournisseurprice->fetch($this->product_fourn_price_id);
427 if ($res > 0) {
428 foreach ($options as $key=>$value) {
429 $productfournisseurprice->array_options[$key] = $value;
430 }
431 $res = $productfournisseurprice->update($user);
432 if ($res < 0) {
433 $this->error = $productfournisseurprice->error;
434 $this->errors = $productfournisseurprice->errors;
435 $error++;
436 }
437 }
438 }
439 }
440
441 // TODO Add price_base_type and price_ttc
442
443 dol_syslog(get_class($this).'::update_buyprice update knowing id of line = product_fourn_price_id = '.$this->product_fourn_price_id, LOG_DEBUG);
444 $resql = $this->db->query($sql);
445 if ($resql) {
446 // Call trigger
447 $result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_MODIFY', $user);
448 if ($result < 0) {
449 $error++;
450 }
451 // End call triggers
452 if (!$error && !getDolGlobalString('PRODUCT_PRICE_SUPPLIER_NO_LOG')) {
453 $result = $this->logPrice($user, $now, $buyprice, $qty, $multicurrency_buyprice, $multicurrency_unitBuyPrice, $multicurrency_tx, $fk_multicurrency, $multicurrency_code);
454 if ($result < 0) {
455 $error++;
456 }
457 }
458 if (empty($error)) {
459 $this->db->commit();
460 return $this->product_fourn_price_id;
461 } else {
462 $this->db->rollback();
463 return -1;
464 }
465 } else {
466 $this->error = $this->db->error()." sql=".$sql;
467 $this->db->rollback();
468 return -2;
469 }
470 } else {
471 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
473 // Delete price for this quantity
474 $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
475 $sql .= " WHERE fk_soc = ".((int) $fourn->id)." AND ref_fourn = '".$this->db->escape($ref_fourn)."' AND quantity = ".((float) $qty)." AND entity = ".((int) $conf->entity);
476 $resql = $this->db->query($sql);
477 if ($resql) {
478 // Add price for this quantity to supplier
479 $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
480 $sql .= " multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,";
481 $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";
482 if (getDolGlobalString('PRODUCT_USE_SUPPLIER_PACKAGING')) {
483 $sql .= ", packaging";
484 }
485 $sql .= ") values(";
486 $sql .= (isset($multicurrency_buyprice) ? "'".$this->db->escape(price2num($multicurrency_buyprice))."'" : 'null').",";
487 $sql .= (isset($multicurrency_unitBuyPrice) ? "'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'" : 'null').",";
488 $sql .= (isset($multicurrency_tx) ? "'".$this->db->escape($multicurrency_tx)."'" : '1').",";
489 $sql .= (isset($fk_multicurrency) ? "'".$this->db->escape($fk_multicurrency)."'" : 'null').",";
490 $sql .= (isset($multicurrency_code) ? "'".$this->db->escape($multicurrency_code)."'" : 'null').",";
491 $sql .= " '".$this->db->idate($now)."',";
492 $sql .= " ".((int) $this->id).",";
493 $sql .= " ".((int) $fourn->id).",";
494 $sql .= " '".$this->db->escape($ref_fourn)."',";
495 $sql .= " '".$this->db->escape($desc_fourn)."',";
496 $sql .= " ".((int) $user->id).",";
497 $sql .= " ".price2num($buyprice).",";
498 $sql .= " ".((float) $qty).",";
499 $sql .= " ".((float) $remise_percent).",";
500 $sql .= " ".((float) $remise).",";
501 $sql .= " ".price2num($unitBuyPrice).",";
502 $sql .= " ".price2num($tva_tx).",";
503 $sql .= " ".price2num($charges).",";
504 $sql .= " ".((int) $availability).",";
505 $sql .= " ".($newdefaultvatcode ? "'".$this->db->escape($newdefaultvatcode)."'" : "null").",";
506 $sql .= " ".((int) $newnpr).",";
507 $sql .= $conf->entity.",";
508 $sql .= ($delivery_time_days != '' ? ((int) $delivery_time_days) : 'null').",";
509 $sql .= (empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'").",";
510 $sql .= (empty($barcode) ? 'NULL' : "'".$this->db->escape($barcode)."'").",";
511 $sql .= (empty($fk_barcode_type) ? 'NULL' : "'".$this->db->escape($fk_barcode_type)."'");
512 if (getDolGlobalString('PRODUCT_USE_SUPPLIER_PACKAGING')) {
513 $sql .= ", ".(empty($this->packaging) ? '1' : "'".$this->db->escape($this->packaging)."'");
514 }
515 $sql .= ")";
516
517 $this->product_fourn_price_id = 0;
518
519 $resql = $this->db->query($sql);
520 if ($resql) {
521 $this->product_fourn_price_id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_fournisseur_price");
522 } else {
523 $this->error = $this->db->lasterror();
524 $error++;
525 }
526
527 if (!$error) {
528 if (!empty($options) && is_array($options)) {
529 $productfournisseurprice = new ProductFournisseurPrice($this->db);
530 $res = $productfournisseurprice->fetch($this->product_fourn_price_id);
531 if ($res > 0) {
532 foreach ($options as $key=>$value) {
533 $productfournisseurprice->array_options[$key] = $value;
534 }
535 $res = $productfournisseurprice->update($user);
536 if ($res < 0) {
537 $this->error = $productfournisseurprice->error;
538 $this->errors = $productfournisseurprice->errors;
539 $error++;
540 }
541 }
542 }
543 }
544
545 if (!$error && !getDolGlobalString('PRODUCT_PRICE_SUPPLIER_NO_LOG')) {
546 // Add record into log table
547 // $this->product_fourn_price_id must be set
548 $result = $this->logPrice($user, $now, $buyprice, $qty, $multicurrency_buyprice, $multicurrency_unitBuyPrice, $multicurrency_tx, $fk_multicurrency, $multicurrency_code);
549 if ($result < 0) {
550 $error++;
551 }
552 }
553
554 if (!$error) {
555 // Call trigger
556 $result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_CREATE', $user);
557 if ($result < 0) {
558 $error++;
559 }
560 // End call triggers
561
562 if (empty($error)) {
563 $this->db->commit();
564 return $this->product_fourn_price_id;
565 } else {
566 $this->db->rollback();
567 return -1;
568 }
569 } else {
570 $this->error = $this->db->lasterror()." sql=".$sql;
571 $this->db->rollback();
572 return -2;
573 }
574 } else {
575 $this->error = $this->db->lasterror()." sql=".$sql;
576 $this->db->rollback();
577 return -1;
578 }
579 }
580 }
581
582 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
590 public function fetch_product_fournisseur_price($rowid, $ignore_expression = 0)
591 {
592 // phpcs:enable
593 global $conf;
594
595 $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,";
596 $sql .= " pfp.fk_soc, pfp.ref_fourn, pfp.desc_fourn, pfp.fk_product, pfp.charges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,";
597 $sql .= " pfp.supplier_reputation, pfp.fk_user, pfp.datec,";
598 $sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
599 $sql .= " pfp.barcode, pfp.fk_barcode_type, pfp.packaging,";
600 $sql .= " p.ref as product_ref, p.tosell as status, p.tobuy as status_buy";
601 $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product as p";
602 $sql .= " WHERE pfp.rowid = ".(int) $rowid;
603 $sql .= " AND pfp.fk_product = p.rowid";
604
605 dol_syslog(get_class($this)."::fetch_product_fournisseur_price", LOG_DEBUG);
606 $resql = $this->db->query($sql);
607 if ($resql) {
608 $obj = $this->db->fetch_object($resql);
609 if ($obj) {
610 $this->product_fourn_price_id = $rowid;
611 $this->id = $obj->fk_product;
612
613 $this->fk_product = $obj->fk_product;
614 $this->product_id = $obj->fk_product;
615 $this->product_ref = $obj->product_ref;
616 $this->status = $obj->status;
617 $this->status_buy = $obj->status_buy;
618 $this->fourn_id = $obj->fk_soc;
619 $this->fourn_ref = $obj->ref_fourn; // deprecated
620 $this->ref_supplier = $obj->ref_fourn;
621 $this->desc_supplier = $obj->desc_fourn;
622 $this->fourn_price = $obj->price;
623 $this->fourn_charges = $obj->charges; // when getDolGlobalString('PRODUCT_CHARGES') is set
624 $this->fourn_qty = $obj->quantity;
625 $this->fourn_remise_percent = $obj->remise_percent;
626 $this->fourn_remise = $obj->remise;
627 $this->fourn_unitprice = $obj->unitprice;
628 $this->fourn_tva_tx = $obj->tva_tx;
629 $this->fourn_tva_npr = $obj->fourn_tva_npr;
630 // Add also localtaxes
631 $this->fk_availability = $obj->fk_availability;
632 $this->delivery_time_days = $obj->delivery_time_days;
633 $this->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
634 $this->supplier_reputation = $obj->supplier_reputation;
635 $this->default_vat_code = $obj->default_vat_code;
636 $this->user_id = $obj->fk_user;
637 $this->date_creation = $this->db->jdate($obj->datec);
638 $this->fourn_multicurrency_price = $obj->multicurrency_price;
639 $this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
640 $this->fourn_multicurrency_tx = $obj->multicurrency_tx;
641 $this->fourn_multicurrency_id = $obj->fk_multicurrency;
642 $this->fourn_multicurrency_code = $obj->multicurrency_code;
643 if (isModEnabled('barcode')) {
644 $this->fourn_barcode = $obj->barcode; // deprecated
645 $this->fourn_fk_barcode_type = $obj->fk_barcode_type; // deprecated
646 $this->supplier_barcode = $obj->barcode;
647 $this->supplier_fk_barcode_type = $obj->fk_barcode_type;
648 }
649 $this->packaging = $obj->packaging;
650
651 if (isModEnabled('dynamicprices') && empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) {
652 require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
653 $priceparser = new PriceParser($this->db);
654 $price_result = $priceparser->parseProductSupplier($this);
655 if ($price_result >= 0) {
656 $this->fourn_price = $price_result;
657 //recalculation of unitprice, as probably the price changed...
658 if ($this->fourn_qty != 0) {
659 $this->fourn_unitprice = price2num($this->fourn_price / $this->fourn_qty, 'MU');
660 } else {
661 $this->fourn_unitprice = "";
662 }
663 }
664 }
665
666 return 1;
667 } else {
668 return 0;
669 }
670 } else {
671 $this->error = $this->db->lasterror();
672 return -1;
673 }
674 }
675
676
677 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
690 public function list_product_fournisseur_price($prodid, $sortfield = '', $sortorder = '', $limit = 0, $offset = 0, $socid = 0)
691 {
692 // phpcs:enable
693 global $conf;
694
695 $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, ";
696 $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,";
697 $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,";
698 $sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code, pfp.datec, pfp.tms,";
699 $sql .= " pfp.barcode, pfp.fk_barcode_type, pfp.packaging, pfp.status as pfstatus";
700 $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."societe as s";
701 $sql .= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")";
702 $sql .= " AND pfp.fk_soc = s.rowid AND pfp.fk_product = p.rowid";
703 $sql .= ($socid > 0 ? ' AND pfp.fk_soc = '.((int) $socid) : '');
704 $sql .= " AND s.status = 1"; // only enabled company selected
705 $sql .= " AND pfp.fk_product = ".((int) $prodid);
706 if (empty($sortfield)) {
707 $sql .= " ORDER BY s.nom, pfp.quantity, pfp.price";
708 } else {
709 $sql .= $this->db->order($sortfield, $sortorder);
710 }
711 $sql .= $this->db->plimit($limit, $offset);
712 dol_syslog(get_class($this)."::list_product_fournisseur_price", LOG_DEBUG);
713
714 $resql = $this->db->query($sql);
715 if ($resql) {
716 $retarray = array();
717
718 while ($record = $this->db->fetch_array($resql)) {
719 //define base attribute
720 $prodfourn = new ProductFournisseur($this->db);
721
722 $prodfourn->product_ref = $record["product_ref"];
723 $prodfourn->product_fourn_price_id = $record["product_fourn_pri_id"];
724 $prodfourn->status = $record["status"];
725 $prodfourn->status_buy = $record["status_buy"];
726 $prodfourn->product_fourn_id = $record["product_fourn_id"];
727 $prodfourn->product_fourn_entity = $record["entity"];
728 $prodfourn->ref_supplier = $record["ref_fourn"];
729 $prodfourn->fourn_ref = $record["ref_fourn"];
730 $prodfourn->desc_supplier = $record["desc_fourn"];
731 $prodfourn->fourn_price = $record["price"];
732 $prodfourn->fourn_qty = $record["quantity"];
733 $prodfourn->fourn_remise_percent = $record["remise_percent"];
734 $prodfourn->fourn_remise = $record["remise"];
735 $prodfourn->fourn_unitprice = $record["unitprice"];
736 $prodfourn->fourn_charges = $record["charges"]; // when getDolGlobalString('PRODUCT_CHARGES') is set
737 $prodfourn->fourn_tva_tx = $record["tva_tx"];
738 $prodfourn->fourn_id = $record["fourn_id"];
739 $prodfourn->fourn_name = $record["supplier_name"];
740 $prodfourn->fk_availability = $record["fk_availability"];
741 $prodfourn->delivery_time_days = $record["delivery_time_days"];
742 $prodfourn->id = $prodid;
743 $prodfourn->fourn_tva_npr = $record["info_bits"];
744 $prodfourn->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
745 $prodfourn->supplier_reputation = $record["supplier_reputation"];
746 $prodfourn->fourn_date_creation = $this->db->jdate($record['datec']);
747 $prodfourn->fourn_date_modification = $this->db->jdate($record['tms']);
748
749 $prodfourn->fourn_multicurrency_price = $record["multicurrency_price"];
750 $prodfourn->fourn_multicurrency_unitprice = $record["multicurrency_unitprice"];
751 $prodfourn->fourn_multicurrency_tx = $record["multicurrency_tx"];
752 $prodfourn->fourn_multicurrency_id = $record["fk_multicurrency"];
753 $prodfourn->fourn_multicurrency_code = $record["multicurrency_code"];
754
755 $prodfourn->packaging = $record["packaging"];
756 $prodfourn->status = $record["pfstatus"];
757
758 if (isModEnabled('barcode')) {
759 $prodfourn->supplier_barcode = $record["barcode"];
760 $prodfourn->supplier_fk_barcode_type = $record["fk_barcode_type"];
761 }
762
763 if (isModEnabled('dynamicprices') && !empty($prodfourn->fk_supplier_price_expression)) {
764 require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
765 $priceparser = new PriceParser($this->db);
766 $price_result = $priceparser->parseProductSupplier($prodfourn);
767 if ($price_result >= 0) {
768 $prodfourn->fourn_price = $price_result;
769 $prodfourn->fourn_unitprice = null; //force recalculation of unitprice, as probably the price changed...
770 }
771 }
772
773 if (!isset($prodfourn->fourn_unitprice)) {
774 if ($prodfourn->fourn_qty != 0) {
775 $prodfourn->fourn_unitprice = price2num($prodfourn->fourn_price / $prodfourn->fourn_qty, 'MU');
776 } else {
777 $prodfourn->fourn_unitprice = "";
778 }
779 }
780
781 $retarray[] = $prodfourn;
782 }
783
784 $this->db->free($resql);
785 return $retarray;
786 } else {
787 $this->error = $this->db->error();
788 return -1;
789 }
790 }
791
792 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
802 public function find_min_price_product_fournisseur($prodid, $qty = 0, $socid = 0)
803 {
804 // phpcs:enable
805 global $conf;
806
807 if (empty($prodid)) {
808 dol_syslog("Warning function find_min_price_product_fournisseur were called with prodid empty. May be a bug.", LOG_WARNING);
809 return 0;
810 }
811
812 $this->product_fourn_price_id = '';
813 $this->product_fourn_id = '';
814 $this->fourn_ref = '';
815 $this->fourn_price = '';
816 $this->fourn_qty = '';
817 $this->fourn_remise_percent = '';
818 $this->fourn_remise = '';
819 $this->fourn_unitprice = '';
820 $this->fourn_id = '';
821 $this->fourn_name = '';
822 $this->delivery_time_days = '';
823 $this->id = '';
824
825 $this->fourn_multicurrency_price = '';
826 $this->fourn_multicurrency_unitprice = '';
827 $this->fourn_multicurrency_tx = '';
828 $this->fourn_multicurrency_id = '';
829 $this->fourn_multicurrency_code = '';
830
831 $sql = "SELECT s.nom as supplier_name, s.rowid as fourn_id,";
832 $sql .= " pfp.rowid as product_fourn_price_id, pfp.ref_fourn,";
833 $sql .= " pfp.price, pfp.quantity, pfp.unitprice, pfp.tva_tx, pfp.charges,";
834 $sql .= " pfp.remise, pfp.remise_percent, pfp.fk_supplier_price_expression, pfp.delivery_time_days";
835 $sql .= " ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code";
836 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
837 $sql .= " WHERE s.entity IN (".getEntity('societe').")";
838 $sql .= " AND pfp.entity IN (".getEntity('productsupplierprice').")";
839 $sql .= " AND pfp.fk_product = ".((int) $prodid);
840 $sql .= " AND pfp.fk_soc = s.rowid";
841 $sql .= " AND s.status = 1"; // only enabled society
842 if ($qty > 0) {
843 $sql .= " AND pfp.quantity <= ".((float) $qty);
844 }
845 if ($socid > 0) {
846 $sql .= ' AND pfp.fk_soc = '.((int) $socid);
847 }
848
849 dol_syslog(get_class($this)."::find_min_price_product_fournisseur", LOG_DEBUG);
850
851 $resql = $this->db->query($sql);
852 if ($resql) {
853 $record_array = array();
854
855 //Store each record to array for later search of min
856 while ($record = $this->db->fetch_array($resql)) {
857 $record_array[] = $record;
858 }
859
860 if (count($record_array) == 0) {
861 $this->db->free($resql);
862 return 0;
863 } else {
864 $min = -1;
865 foreach ($record_array as $record) {
866 $fourn_price = $record["price"];
867 // calculate unit price for quantity 1
868 $fourn_unitprice = $record["unitprice"];
869 $fourn_unitprice_with_discount = $record["unitprice"] * (1 - $record["remise_percent"] / 100);
870
871 if (isModEnabled('dynamicprices') && !empty($record["fk_supplier_price_expression"])) {
872 $prod_supplier = new ProductFournisseur($this->db);
873 $prod_supplier->product_fourn_price_id = $record["product_fourn_price_id"];
874 $prod_supplier->id = $prodid;
875 $prod_supplier->fourn_qty = $record["quantity"];
876 $prod_supplier->fourn_tva_tx = $record["tva_tx"];
877 $prod_supplier->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
878
879 require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
880 $priceparser = new PriceParser($this->db);
881 $price_result = $priceparser->parseProductSupplier($prod_supplier);
882 if ($price_result >= 0) {
883 $fourn_price = price2num($price_result, 'MU');
884 if ($record["quantity"] != 0) {
885 $fourn_unitprice = price2num($fourn_price / $record["quantity"], 'MU');
886 } else {
887 $fourn_unitprice = $fourn_price;
888 }
889 $fourn_unitprice_with_discount = $fourn_unitprice * (1 - $record["remise_percent"] / 100);
890 }
891 }
892 if ($fourn_unitprice < $min || $min == -1) {
893 $this->product_fourn_price_id = $record["product_fourn_price_id"];
894 $this->ref_supplier = $record["ref_fourn"];
895 $this->ref_fourn = $record["ref_fourn"]; // deprecated
896 $this->fourn_ref = $record["ref_fourn"]; // deprecated
897 $this->fourn_price = $fourn_price;
898 $this->fourn_qty = $record["quantity"];
899 $this->fourn_remise_percent = $record["remise_percent"];
900 $this->fourn_remise = $record["remise"];
901 $this->fourn_unitprice = $fourn_unitprice;
902 $this->fourn_unitprice_with_discount = $fourn_unitprice_with_discount;
903 $this->fourn_charges = $record["charges"]; // when getDolGlobalString('PRODUCT_CHARGES') is set
904 $this->fourn_tva_tx = $record["tva_tx"];
905 $this->fourn_id = $record["fourn_id"];
906 $this->fourn_name = $record["supplier_name"];
907 $this->delivery_time_days = $record["delivery_time_days"];
908 $this->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
909 $this->id = $prodid;
910 $this->fourn_multicurrency_price = $record["multicurrency_price"];
911 $this->fourn_multicurrency_unitprice = $record["multicurrency_unitprice"];
912 $this->fourn_multicurrency_tx = $record["multicurrency_tx"];
913 $this->fourn_multicurrency_id = $record["fk_multicurrency"];
914 $this->fourn_multicurrency_code = $record["multicurrency_code"];
915 $min = $fourn_unitprice;
916 }
917 }
918 }
919
920 $this->db->free($resql);
921 return 1;
922 } else {
923 $this->error = $this->db->error();
924 return -1;
925 }
926 }
927
934 public function setSupplierPriceExpression($expression_id)
935 {
936 global $conf;
937
938 // Clean parameters
939 $this->db->begin();
940 $expression_id = $expression_id != 0 ? $expression_id : 'NULL';
941
942 $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price";
943 $sql .= " SET fk_supplier_price_expression = ".((int) $expression_id);
944 $sql .= " WHERE rowid = ".((int) $this->product_fourn_price_id);
945
946 dol_syslog(get_class($this)."::setSupplierPriceExpression", LOG_DEBUG);
947
948 $resql = $this->db->query($sql);
949 if ($resql) {
950 $this->db->commit();
951 return 1;
952 } else {
953 $this->error = $this->db->error()." sql=".$sql;
954 $this->db->rollback();
955 return -1;
956 }
957 }
958
969 public function getSocNomUrl($withpicto = 0, $option = 'supplier', $maxlen = 0, $notooltip = 0)
970 {
971 $thirdparty = new Fournisseur($this->db);
972 $thirdparty->fetch($this->fourn_id);
973
974 return $thirdparty->getNomUrl($withpicto, $option, $maxlen, $notooltip);
975 }
976
977 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
989 public function display_price_product_fournisseur($showunitprice = 1, $showsuptitle = 1, $maxlen = 0, $notooltip = 0, $productFournList = array())
990 {
991 // phpcs:enable
992 global $conf, $langs;
993
994 $out = '';
995 $langs->load("suppliers");
996 if (count($productFournList) > 0) {
997 $out .= '<table class="nobordernopadding" width="100%">';
998 $out .= '<tr><td class="liste_titre right">'.($showunitprice ? $langs->trans("Price").' '.$langs->trans("HT") : '').'</td>';
999 $out .= '<td class="liste_titre right">'.($showunitprice ? $langs->trans("QtyMin") : '').'</td>';
1000 $out .= '<td class="liste_titre">'.$langs->trans("Supplier").'</td>';
1001 $out .= '<td class="liste_titre">'.$langs->trans("SupplierRef").'</td></tr>';
1002 foreach ($productFournList as $productFourn) {
1003 $out .= '<tr><td class="right">'.($showunitprice ? price($productFourn->fourn_unitprice * (1 - $productFourn->fourn_remise_percent / 100) - $productFourn->fourn_remise) : '').'</td>';
1004 $out .= '<td class="right">'.($showunitprice ? $productFourn->fourn_qty : '').'</td>';
1005 $out .= '<td>'.$productFourn->getSocNomUrl(1, 'supplier', $maxlen, $notooltip).'</td>';
1006 $out .= '<td>'.$productFourn->fourn_ref.'<td></tr>';
1007 }
1008 $out .= '</table>';
1009 } else {
1010 $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>' : '');
1011 $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;
1012 $out .= ($showunitprice ? '<span class="opacitymedium">)</span>' : '');
1013 }
1014 return $out;
1015 }
1016
1025 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1026 {
1027 $tables = array(
1028 'product_fournisseur_price'
1029 );
1030
1031 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1032 }
1033
1042 public static function replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
1043 {
1044 $tables = array(
1045 'product_fournisseur_price'
1046 );
1047
1048 return CommonObject::commonReplaceProduct($dbs, $origin_id, $dest_id, $tables);
1049 }
1050
1061 public function listProductFournisseurPriceLog($product_fourn_price_id, $sortfield = '', $sortorder = '', $limit = 0, $offset = 0)
1062 {
1063 $sql = "SELECT";
1064 $sql .= " u.lastname,";
1065 $sql .= " pfpl.rowid, pfp.ref_fourn as supplier_ref, pfpl.datec,";
1066 $sql .= " pfpl.price, pfpl.quantity,";
1067 $sql .= " pfpl.fk_multicurrency, pfpl.multicurrency_code, pfpl.multicurrency_tx, pfpl.multicurrency_price, pfpl.multicurrency_unitprice";
1068 $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price_log as pfpl,";
1069 $sql .= " ".MAIN_DB_PREFIX."product_fournisseur_price as pfp,";
1070 $sql .= " ".MAIN_DB_PREFIX."user as u";
1071 $sql .= " WHERE pfp.entity IN (".getEntity('productprice').")";
1072 $sql .= " AND pfpl.fk_user = u.rowid";
1073 $sql .= " AND pfp.rowid = pfpl.fk_product_fournisseur";
1074 $sql .= " AND pfpl.fk_product_fournisseur = ".((int) $product_fourn_price_id);
1075 if (empty($sortfield)) {
1076 $sql .= " ORDER BY pfpl.datec";
1077 } else {
1078 $sql .= $this->db->order($sortfield, $sortorder);
1079 }
1080 $sql .= $this->db->plimit($limit, $offset);
1081 dol_syslog(get_class($this)."::list_product_fournisseur_price_log", LOG_DEBUG);
1082
1083 $resql = $this->db->query($sql);
1084 if ($resql) {
1085 $retarray = array();
1086
1087 while ($obj = $this->db->fetch_object($resql)) {
1088 $tmparray = array();
1089 $tmparray['rowid'] = $obj->rowid;
1090 $tmparray['supplier_ref'] = $obj->supplier_ref;
1091 $tmparray['datec'] = $this->db->jdate($obj->datec);
1092 $tmparray['lastname'] = $obj->lastname;
1093 $tmparray['price'] = $obj->price;
1094 $tmparray['quantity'] = $obj->quantity;
1095 $tmparray['fk_multicurrency'] = $obj->fk_multicurrency;
1096 $tmparray['multicurrency_code'] = $obj->multicurrency_code;
1097 $tmparray['multicurrency_tx'] = $obj->multicurrency_tx;
1098 $tmparray['multicurrency_price'] = $obj->multicurrency_price;
1099 $tmparray['multicurrency_unitprice'] = $obj->multicurrency_unitprice;
1100
1101 $retarray[] = $tmparray;
1102 }
1103
1104 $this->db->free($resql);
1105 return $retarray;
1106 } else {
1107 $this->error = $this->db->error();
1108 return -1;
1109 }
1110 }
1111
1119 public function displayPriceProductFournisseurLog($productFournLogList = array())
1120 {
1121 global $conf, $langs;
1122
1123 $out = '';
1124 $langs->load("suppliers");
1125 if (count($productFournLogList) > 0) {
1126 $out .= '<table class="noborder centpercent">';
1127 $out .= '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Date").'</td>';
1128 $out .= '<td class="liste_titre right">'.$langs->trans("Price").'</td>';
1129 //$out .= '<td class="liste_titre right">'.$langs->trans("QtyMin").'</td>';
1130 $out .= '<td class="liste_titre">'.$langs->trans("User").'</td></tr>';
1131 foreach ($productFournLogList as $productFournLog) {
1132 $out .= '<tr><td>'.dol_print_date($productFournLog['datec'], 'dayhour', 'tzuser').'</td>';
1133 $out .= '<td class="right">'.price($productFournLog['price'], 0, $langs, 1, -1, -1, $conf->currency);
1134 if ($productFournLog['multicurrency_code'] != $conf->currency) {
1135 $out .= ' ('.price($productFournLog['multicurrency_price'], 0, $langs, 1, -1, -1, $productFournLog['multicurrency_code']).')';
1136 }
1137 $out .= '</td>';
1138 //$out.= '<td class="right">'.$productFournLog['quantity'].'</td>';
1139 $out .= '<td>'.$productFournLog['lastname'].'</td></tr>';
1140 }
1141 $out .= '</table>';
1142 }
1143 return $out;
1144 }
1145
1146
1161 public function getNomUrl($withpicto = 0, $option = '', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss = '', $add_label = 0, $sep = ' - ')
1162 {
1163 global $db, $conf, $langs, $hookmanager;
1164
1165 if (!empty($conf->dol_no_mouse_hover)) {
1166 $notooltip = 1; // Force disable tooltips
1167 }
1168
1169 $result = '';
1170 $label = '';
1171
1172 $newref = $this->ref;
1173 if ($maxlength) {
1174 $newref = dol_trunc($newref, $maxlength, 'middle');
1175 }
1176
1177 if (!empty($this->entity)) {
1178 $tmpphoto = $this->show_photos('product', $conf->product->multidir_output[$this->entity], 1, 1, 0, 0, 0, 80);
1179 if ($this->nbphoto > 0) {
1180 $label .= '<div class="photointooltip">';
1181 $label .= $tmpphoto;
1182 $label .= '</div><div style="clear: both;"></div>';
1183 }
1184 }
1185
1186 if ($this->type == Product::TYPE_PRODUCT) {
1187 $label .= img_picto('', 'product').' <u class="paddingrightonly">'.$langs->trans("Product").'</u>';
1188 } elseif ($this->type == Product::TYPE_SERVICE) {
1189 $label .= img_picto('', 'service').' <u class="paddingrightonly">'.$langs->trans("Service").'</u>';
1190 }
1191 if (isset($this->status) && isset($this->status_buy)) {
1192 $label .= ' '.$this->getLibStatut(5, 0);
1193 $label .= ' '.$this->getLibStatut(5, 1);
1194 }
1195
1196 if (!empty($this->ref)) {
1197 $label .= '<br><b>'.$langs->trans('ProductRef').':</b> '.($this->ref ? $this->ref : $this->product_ref);
1198 }
1199 if (!empty($this->label)) {
1200 $label .= '<br><b>'.$langs->trans('ProductLabel').':</b> '.$this->label;
1201 }
1202 $label .= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_supplier;
1203
1204 if ($this->type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
1205 if (isModEnabled('productbatch')) {
1206 $langs->load("productbatch");
1207 $label .= "<br><b>".$langs->trans("ManageLotSerial").'</b>: '.$this->getLibStatut(0, 2);
1208 }
1209 }
1210 if (isModEnabled('barcode')) {
1211 $label .= '<br><b>'.$langs->trans('BarCode').':</b> '.$this->barcode;
1212 }
1213
1214 if ($this->type == Product::TYPE_PRODUCT) {
1215 if ($this->weight) {
1216 $label .= "<br><b>".$langs->trans("Weight").'</b>: '.$this->weight.' '.measuringUnitString(0, "weight", $this->weight_units);
1217 }
1218 $labelsize = "";
1219 if ($this->length) {
1220 $labelsize .= ($labelsize ? " - " : "")."<b>".$langs->trans("Length").'</b>: '.$this->length.' '.measuringUnitString(0, 'size', $this->length_units);
1221 }
1222 if ($this->width) {
1223 $labelsize .= ($labelsize ? " - " : "")."<b>".$langs->trans("Width").'</b>: '.$this->width.' '.measuringUnitString(0, 'size', $this->width_units);
1224 }
1225 if ($this->height) {
1226 $labelsize .= ($labelsize ? " - " : "")."<b>".$langs->trans("Height").'</b>: '.$this->height.' '.measuringUnitString(0, 'size', $this->height_units);
1227 }
1228 if ($labelsize) {
1229 $label .= "<br>".$labelsize;
1230 }
1231
1232 $labelsurfacevolume = "";
1233 if ($this->surface) {
1234 $labelsurfacevolume .= ($labelsurfacevolume ? " - " : "")."<b>".$langs->trans("Surface").'</b>: '.$this->surface.' '.measuringUnitString(0, 'surface', $this->surface_units);
1235 }
1236 if ($this->volume) {
1237 $labelsurfacevolume .= ($labelsurfacevolume ? " - " : "")."<b>".$langs->trans("Volume").'</b>: '.$this->volume.' '.measuringUnitString(0, 'volume', $this->volume_units);
1238 }
1239 if ($labelsurfacevolume) {
1240 $label .= "<br>".$labelsurfacevolume;
1241 }
1242 }
1243
1244 if (isModEnabled('accounting') && $this->status) {
1245 include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
1246 $label .= '<br><b>'.$langs->trans('ProductAccountancySellCode').':</b> '.length_accountg($this->accountancy_code_sell);
1247 $label .= '<br><b>'.$langs->trans('ProductAccountancySellIntraCode').':</b> '.length_accountg($this->accountancy_code_sell_intra);
1248 $label .= '<br><b>'.$langs->trans('ProductAccountancySellExportCode').':</b> '.length_accountg($this->accountancy_code_sell_export);
1249 }
1250 if (isModEnabled('accounting') && $this->status_buy) {
1251 include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
1252 $label .= '<br><b>'.$langs->trans('ProductAccountancyBuyCode').':</b> '.length_accountg($this->accountancy_code_buy);
1253 $label .= '<br><b>'.$langs->trans('ProductAccountancyBuyIntraCode').':</b> '.length_accountg($this->accountancy_code_buy_intra);
1254 $label .= '<br><b>'.$langs->trans('ProductAccountancyBuyExportCode').':</b> '.length_accountg($this->accountancy_code_buy_export);
1255 }
1256
1257 $logPrices = $this->listProductFournisseurPriceLog($this->product_fourn_price_id, 'pfpl.datec', 'DESC'); // set sort order here
1258 if (is_array($logPrices) && count($logPrices) > 0) {
1259 $label .= '<br><br>';
1260 $label .= '<u>'.$langs->trans("History").'</u>';
1261 $label .= $this->displayPriceProductFournisseurLog($logPrices);
1262 }
1263
1264 $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);
1265
1266 if ($option != 'nolink') {
1267 // Add param to save lastsearch_values or not
1268 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1269 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1270 $add_save_lastsearch_values = 1;
1271 }
1272 if ($add_save_lastsearch_values) {
1273 $url .= '&save_lastsearch_values=1';
1274 }
1275 }
1276
1277 $linkclose = '';
1278 if (empty($notooltip)) {
1279 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1280 $label = $langs->trans("SupplierRef");
1281 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1282 }
1283 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1284 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1285 } else {
1286 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1287 }
1288
1289 $linkstart = '<a href="'.$url.'"';
1290 $linkstart .= $linkclose.'>';
1291 $linkend = '</a>';
1292
1293 $result .= $linkstart;
1294 if ($withpicto) {
1295 $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);
1296 }
1297 if ($withpicto != 2) {
1298 $result .= $newref.($this->ref_supplier ? ' ('.$this->ref_supplier.')' : '');
1299 }
1300 $result .= $linkend;
1301 if ($withpicto != 2) {
1302 $result .= (($add_label && $this->label) ? $sep.dol_trunc($this->label, ($add_label > 1 ? $add_label : 0)) : '');
1303 }
1304
1305 global $action;
1306 $hookmanager->initHooks(array($this->element . 'dao'));
1307 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1308 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1309 if ($reshook > 0) {
1310 $result = $hookmanager->resPrint;
1311 } else {
1312 $result .= $hookmanager->resPrint;
1313 }
1314 return $result;
1315 }
1316
1324 public function getLibStatut($mode = 0, $type = 0) // must be compatible with getLibStatut of inherited Product
1325 {
1326 return $this->LibStatut($this->status, $mode);
1327 }
1328
1329 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1338 public function LibStatut($status, $mode = 0, $type = 0)
1339 {
1340 // phpcs:enable
1341 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1342 global $langs;
1343 //$langs->load("mymodule@mymodule");
1344 $this->labelStatus[self::STATUS_OPEN] = $langs->transnoentitiesnoconv('Enabled');
1345 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
1346 $this->labelStatusShort[self::STATUS_OPEN] = $langs->transnoentitiesnoconv('Enabled');
1347 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
1348 }
1349
1350 $statusType = 'status4';
1351 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
1352 if ($status == self::STATUS_CANCELED) {
1353 $statusType = 'status6';
1354 }
1355
1356 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1357 }
1358
1374 private function logPrice($user, $datec, $buyprice, $qty, $multicurrency_buyprice = null, $multicurrency_unitBuyPrice = null, $multicurrency_tx = null, $fk_multicurrency = null, $multicurrency_code = null)
1375 {
1376 // Add record into log table
1377 $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log(";
1378 $sql .= " multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,";
1379 $sql .= "datec, fk_product_fournisseur,fk_user,price,quantity)";
1380 $sql .= "values(";
1381 $sql .= (isset($multicurrency_buyprice) ? "'".$this->db->escape(price2num($multicurrency_buyprice))."'" : 'null').",";
1382 $sql .= (isset($multicurrency_unitBuyPrice) ? "'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'" : 'null').",";
1383 $sql .= (isset($multicurrency_tx) ? "'".$this->db->escape($multicurrency_tx)."'" : '1').",";
1384 $sql .= (isset($fk_multicurrency) ? "'".$this->db->escape($fk_multicurrency)."'" : 'null').",";
1385 $sql .= (isset($multicurrency_code) ? "'".$this->db->escape($multicurrency_code)."'" : 'null').",";
1386 $sql .= "'".$this->db->idate($datec)."',";
1387 $sql .= " ".((int) $this->product_fourn_price_id).",";
1388 $sql .= " ".$user->id.",";
1389 $sql .= " ".price2num($buyprice).",";
1390 $sql .= " ".price2num($qty);
1391 $sql .= ")";
1392
1393 $resql = $this->db->query($sql);
1394 if (!$resql) {
1395 return -1;
1396 } else {
1397 return 1;
1398 }
1399 }
1400}
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
Definition security.php:604
$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 optionaly 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='', $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.
$res
Path of subproducts.
const TYPE_SERVICE
Service.
Class to manage Dolibarr users.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
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.
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:121