dolibarr 24.0.0-beta
productfournisseurprice.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 Alexis LAURIER <contact@alexislaurier.fr>
4 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29
34{
38 public $element = 'productfournisseurprice';
39
43 public $table_element = 'product_fournisseur_price';
44
48 public $picto = 'productfournisseurprice@buypricehistory';
49
50
51 const STATUS_DRAFT = 0;
52 const STATUS_VALIDATED = 1;
53 const STATUS_CANCELED = 9;
54
55
82 // BEGIN MODULEBUILDER PROPERTIES
86 public $fields = array(
87 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => '1', 'position' => 10, 'notnull' => 1, 'visible' => 0,),
88 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => '1', 'position' => 15, 'notnull' => 1, 'visible' => -2, 'default' => '1', 'index' => 1,),
89 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => '1', 'position' => 20, 'notnull' => 0, 'visible' => -1,),
90 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => '1', 'position' => 25, 'notnull' => 1, 'visible' => -1,),
91 'fk_product' => array('type' => 'integer:Product:product/class/product.class.php:1', 'label' => 'Fkproduct', 'enabled' => '1', 'position' => 30, 'notnull' => 0, 'visible' => -1,),
92 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => '1', 'position' => 35, 'notnull' => 0, 'visible' => -1,),
93 'ref_fourn' => array('type' => 'varchar(255)', 'label' => 'Reffourn', 'enabled' => '1', 'position' => 40, 'notnull' => 0, 'visible' => -1,),
94 'desc_fourn' => array('type' => 'text', 'label' => 'Descfourn', 'enabled' => '1', 'position' => 45, 'notnull' => 0, 'visible' => -1,),
95 'fk_availability' => array('type' => 'integer', 'label' => 'Fkavailability', 'enabled' => '1', 'position' => 50, 'notnull' => 0, 'visible' => -1,),
96 'price' => array('type' => 'double(24,8)', 'label' => 'Price', 'enabled' => '1', 'position' => 55, 'notnull' => 0, 'visible' => -1,),
97 'quantity' => array('type' => 'double', 'label' => 'Quantity', 'enabled' => '1', 'position' => 60, 'notnull' => 0, 'visible' => -1,),
98 'remise_percent' => array('type' => 'double', 'label' => 'Remisepercent', 'enabled' => '1', 'position' => 65, 'notnull' => 1, 'visible' => -1,),
99 'remise' => array('type' => 'double', 'label' => 'Remise', 'enabled' => '1', 'position' => 70, 'notnull' => 1, 'visible' => -1,),
100 'unitprice' => array('type' => 'double(24,8)', 'label' => 'Unitprice', 'enabled' => '1', 'position' => 75, 'notnull' => 0, 'visible' => -1,),
101 'charges' => array('type' => 'double(24,8)', 'label' => 'Charges', 'enabled' => '1', 'position' => 80, 'notnull' => 0, 'visible' => -1,),
102 'default_vat_code' => array('type' => 'varchar(10)', 'label' => 'Defaultvatcode', 'enabled' => '1', 'position' => 85, 'notnull' => 0, 'visible' => -1,),
103 'tva_tx' => array('type' => 'double(6,3)', 'label' => 'Tvatx', 'enabled' => '1', 'position' => 90, 'notnull' => 1, 'visible' => -1,),
104 'info_bits' => array('type' => 'integer', 'label' => 'Infobits', 'enabled' => '1', 'position' => 95, 'notnull' => 1, 'visible' => -1,),
105 'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fkuser', 'enabled' => '1', 'position' => 100, 'notnull' => 0, 'visible' => -1,),
106 'fk_supplier_price_expression' => array('type' => 'integer', 'label' => 'Fksupplierpriceexpression', 'enabled' => '1', 'position' => 105, 'notnull' => 0, 'visible' => -1,),
107 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => '1', 'position' => 900, 'notnull' => 0, 'visible' => -2,),
108 'delivery_time_days' => array('type' => 'integer', 'label' => 'Deliverytimedays', 'enabled' => '1', 'position' => 115, 'notnull' => 0, 'visible' => -1,),
109 'supplier_reputation' => array('type' => 'varchar(10)', 'label' => 'Supplierreputation', 'enabled' => '1', 'position' => 120, 'notnull' => 0, 'visible' => -1,),
110 'fk_multicurrency' => array('type' => 'integer', 'label' => 'Fkmulticurrency', 'enabled' => '1', 'position' => 125, 'notnull' => 0, 'visible' => -1,),
111 'multicurrency_code' => array('type' => 'varchar(255)', 'label' => 'Multicurrencycode', 'enabled' => '1', 'position' => 130, 'notnull' => 0, 'visible' => -1,),
112 'multicurrency_tx' => array('type' => 'double(24,8)', 'label' => 'Multicurrencytx', 'enabled' => '1', 'position' => 135, 'notnull' => 0, 'visible' => -1,),
113 'multicurrency_price' => array('type' => 'double(24,8)', 'label' => 'Multicurrencyprice', 'enabled' => '1', 'position' => 140, 'notnull' => 0, 'visible' => -1,),
114 'multicurrency_unitprice' => array('type' => 'double(24,8)', 'label' => 'Multicurrencyunitprice', 'enabled' => '1', 'position' => 145, 'notnull' => 0, 'visible' => -1,),
115 'localtax1_tx' => array('type' => 'double(6,3)', 'label' => 'Localtax1tx', 'enabled' => '1', 'position' => 150, 'notnull' => 0, 'visible' => -1,),
116 'localtax1_type' => array('type' => 'varchar(10)', 'label' => 'Localtax1type', 'enabled' => '1', 'position' => 155, 'notnull' => 1, 'visible' => -1,),
117 'localtax2_tx' => array('type' => 'double(6,3)', 'label' => 'Localtax2tx', 'enabled' => '1', 'position' => 160, 'notnull' => 0, 'visible' => -1,),
118 'localtax2_type' => array('type' => 'varchar(10)', 'label' => 'Localtax2type', 'enabled' => '1', 'position' => 165, 'notnull' => 1, 'visible' => -1,),
119 'barcode' => array('type' => 'varchar(180)', 'label' => 'Barcode', 'enabled' => '1', 'position' => 170, 'notnull' => 0, 'visible' => -1,),
120 'fk_barcode_type' => array('type' => 'integer', 'label' => 'Fkbarcodetype', 'enabled' => '1', 'position' => 175, 'notnull' => 0, 'visible' => -1,),
121 'packaging' => array('type' => 'varchar(64)', 'label' => 'Packaging', 'enabled' => '1', 'position' => 180, 'notnull' => 0, 'visible' => -1,),
122 );
126 public $rowid;
130 public $entity;
134 public $datec;
138 public $fk_product;
142 public $fk_soc;
146 public $ref_fourn;
150 public $desc_fourn;
154 public $fk_availability;
158 public $price;
162 public $quantity;
166 public $remise_percent;
170 public $remise;
174 public $unitprice;
178 public $charges;
182 public $default_vat_code;
186 public $tva_tx;
190 public $info_bits;
194 public $fk_user;
198 public $fk_supplier_price_expression;
202 public $import_key;
206 public $delivery_time_days;
210 public $supplier_reputation;
214 public $fk_multicurrency;
218 public $multicurrency_code;
222 public $multicurrency_tx;
226 public $multicurrency_price;
230 public $multicurrency_unitprice;
234 public $localtax1_tx;
238 public $localtax1_type;
242 public $localtax2_tx;
246 public $localtax2_type;
250 public $barcode;
254 public $fk_barcode_type;
258 public $packaging;
259 // END MODULEBUILDER PROPERTIES
260
266 public function __construct(DoliDB $db)
267 {
268 $this->db = $db;
269
270 $this->ismultientitymanaged = 1;
271 $this->isextrafieldmanaged = 1;
272
273 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
274 $this->fields['rowid']['visible'] = 0;
275 }
276 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
277 $this->fields['entity']['enabled'] = 0;
278 }
279
280 // Unset fields that are disabled
281 foreach ($this->fields as $key => $val) {
282 if (isset($val['enabled']) && empty($val['enabled'])) {
283 unset($this->fields[$key]);
284 }
285 }
286 }
287
295 public function create(User $user, $notrigger = 0)
296 {
297 return $this->createCommon($user, $notrigger);
298 }
299
307 public function createFromClone(User $user, $fromid)
308 {
309 global $langs, $extrafields;
310 $error = 0;
311
312 dol_syslog(__METHOD__, LOG_DEBUG);
313
314 $object = new self($this->db);
315
316 $this->db->begin();
317
318 // Load source object
319 $result = $object->fetchCommon($fromid);
320 if ($result > 0 && !empty($object->table_element_line)) {
321 $object->fetchLines();
322 }
323
324 // get lines so they will be clone
325 //foreach($this->lines as $line)
326 // $line->fetch_optionals();
327
328 // Reset some properties
329 unset($object->id);
330 unset($object->fk_user_creat);
331 unset($object->user_creation_id);
332 unset($object->import_key);
333
334 // Clear fields
335 if (property_exists($object, 'ref')) {
336 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
337 }
338 /*if (property_exists($object, 'label')) {
339 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
340 }*/
341 if (property_exists($object, 'status')) {
342 $object->status = self::STATUS_DRAFT;
343 }
344 if (property_exists($object, 'date_creation')) {
345 $object->date_creation = dol_now();
346 }
347 if (property_exists($object, 'date_modification')) {
348 $object->date_modification = null;
349 }
350 // ...
351 // Clear extrafields that are unique
352 if (is_array($object->array_options) && count($object->array_options) > 0) {
353 $extrafields->fetch_name_optionals_label($this->table_element);
354 foreach ($object->array_options as $key => $option) {
355 $shortkey = preg_replace('/options_/', '', $key);
356 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
357 unset($object->array_options[$key]);
358 }
359 }
360 }
361
362 // Create clone
363 $object->context['createfromclone'] = 'createfromclone';
364 $result = $object->createCommon($user);
365 if ($result < 0) {
366 $error++;
368 }
369
370 if (!$error) {
371 // copy internal contacts
372 if ($this->copy_linked_contact($object, 'internal') < 0) {
373 $error++;
374 }
375 }
376
377 if (!$error) {
378 // copy external contacts if same company
379 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
380 if ($this->copy_linked_contact($object, 'external') < 0) {
381 $error++;
382 }
383 }
384 }
385
386 unset($object->context['createfromclone']);
387
388 // End
389 if (!$error) {
390 $this->db->commit();
391 return $object;
392 } else {
393 $this->db->rollback();
394 return -1;
395 }
396 }
397
404 public function fetch($id)
405 {
406 return $this->fetchCommon($id);
407 }
408
420 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
421 {
422 dol_syslog(__METHOD__, LOG_DEBUG);
423
424 $records = array();
425
426 $sql = "SELECT ";
427 $sql .= $this->getFieldList();
428 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
429 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
430 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
431 } else {
432 $sql .= " WHERE 1 = 1";
433 }
434
435 // Manage filter
436 if (is_array($filter)) {
437 $sqlwhere = array();
438 if (count($filter) > 0) {
439 foreach ($filter as $key => $value) {
440 if ($key == 't.rowid') {
441 $sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value);
442 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
443 $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate($value)."'";
444 } elseif (strpos($value, '%') === false) {
445 $sqlwhere[] = $this->db->sanitize($key).' IN ('.$this->db->sanitize($this->db->escape($value)).')';
446 } else {
447 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
448 }
449 }
450 }
451 if (count($sqlwhere) > 0) {
452 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
453 }
454
455 $filter = '';
456 }
457
458 // Manage filter
459 $errormessage = '';
460 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
461 if ($errormessage) {
462 $this->errors[] = $errormessage;
463 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
464 return -1;
465 }
466
467 if (!empty($sortfield)) {
468 $sql .= $this->db->order($sortfield, $sortorder);
469 }
470 if (!empty($limit)) {
471 $sql .= $this->db->plimit($limit, $offset);
472 }
473
474 $resql = $this->db->query($sql);
475 if ($resql) {
476 $num = $this->db->num_rows($resql);
477 $i = 0;
478 while ($i < ($limit ? min($limit, $num) : $num)) {
479 $obj = $this->db->fetch_object($resql);
480
481 $record = new self($this->db);
482 $record->setVarsFromFetchObj($obj);
483
484 $records[$record->id] = $record;
485
486 $i++;
487 }
488 $this->db->free($resql);
489
490 return $records;
491 } else {
492 $this->errors[] = 'Error '.$this->db->lasterror();
493 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
494
495 return -1;
496 }
497 }
498
506 public function update(User $user, $notrigger = 0)
507 {
508 return $this->updateCommon($user, $notrigger);
509 }
510
518 public function delete(User $user, $notrigger = 0)
519 {
520 $this->db->begin();
521
522 // Delete log entries first
523 $sql = "DELETE FROM " . $this->db->prefix() . "product_fournisseur_price_log";
524 $sql .= " WHERE fk_product_fournisseur = " . ((int) $this->id);
525
526 $resql = $this->db->query($sql);
527 if (!$resql) {
528 $this->db->rollback();
529 $this->error = $this->db->lasterror();
530 return -1;
531 }
532
533 // Delete parent record (deleteCommon nests inside our transaction)
534 $result = $this->deleteCommon($user, $notrigger);
535
536 if ($result < 0) {
537 $this->db->rollback();
538 return -1;
539 }
540
541 $this->db->commit();
542 return $result;
543 }
544
552 public function validate($user, $notrigger = 0)
553 {
554 global $conf;
555
556 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
557
558 $error = 0;
559
560 // Protection
561 if ($this->status == self::STATUS_VALIDATED) {
562 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
563 return 0;
564 }
565
566 $now = dol_now();
567
568 $this->db->begin();
569
570 // Define new ref
571 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
572 $num = $this->getNextNumRef();
573 } else {
574 $num = (string) $this->ref;
575 }
576 $this->newref = $num;
577
578 if (!empty($num)) {
579 // Validate
580 $sql = "UPDATE ".$this->db->prefix().$this->table_element;
581 $sql .= " SET ref = '".$this->db->escape($num)."',";
582 $sql .= " status = ".self::STATUS_VALIDATED;
583 if (!empty($this->fields['date_validation'])) {
584 $sql .= ", date_validation = '".$this->db->idate($now)."'";
585 }
586 if (!empty($this->fields['fk_user_valid'])) {
587 $sql .= ", fk_user_valid = ".((int) $user->id);
588 }
589 $sql .= " WHERE rowid = ".((int) $this->id);
590
591 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
592 $resql = $this->db->query($sql);
593 if (!$resql) {
594 dol_print_error($this->db);
595 $this->error = $this->db->lasterror();
596 $error++;
597 }
598
599 if (!$error && !$notrigger) {
600 // Call trigger
601 $result = $this->call_trigger('PRODUCTFOURNISSEURPRICE_VALIDATE', $user);
602 if ($result < 0) {
603 $error++;
604 }
605 // End call triggers
606 }
607 }
608
609 if (!$error) {
610 $this->oldref = $this->ref;
611
612 // Rename directory if dir was a temporary ref
613 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
614 // Now we rename also files into index
615 $sql = 'UPDATE '.$this->db->prefix()."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'";
616 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
617 $resql = $this->db->query($sql);
618 if (!$resql) {
619 $error++;
620 $this->error = $this->db->lasterror();
621 }
622 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'";
623 $sql .= " WHERE filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
624 $resql = $this->db->query($sql);
625 if (!$resql) {
626 $error++;
627 $this->error = $this->db->lasterror();
628 }
629
630 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
631 $oldref = dol_sanitizeFileName($this->ref);
632 $newref = dol_sanitizeFileName($num);
633 $dirsource = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$oldref;
634 $dirdest = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref;
635 if (!$error && file_exists($dirsource)) {
636 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
637
638 if (@rename($dirsource, $dirdest)) {
639 dol_syslog("Rename ok");
640 // Rename docs starting with $oldref with $newref
641 $listoffiles = dol_dir_list($conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
642 foreach ($listoffiles as $fileentry) {
643 $dirsource = $fileentry['name'];
644 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
645 $dirsource = $fileentry['path'].'/'.$dirsource;
646 $dirdest = $fileentry['path'].'/'.$dirdest;
647 @rename($dirsource, $dirdest);
648 }
649 }
650 }
651 }
652 }
653
654 // Set new ref and current status
655 if (!$error) {
656 $this->ref = $num;
657 $this->status = self::STATUS_VALIDATED;
658 }
659
660 if (!$error) {
661 $this->db->commit();
662 return 1;
663 } else {
664 $this->db->rollback();
665 return -1;
666 }
667 }
668
669
677 public function setDraft($user, $notrigger = 0)
678 {
679 // Protection
680 if ($this->status <= self::STATUS_DRAFT) {
681 return 0;
682 }
683
684 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'PRODUCTFOURNISSEURPRICE_UNVALIDATE');
685 }
686
694 public function cancel($user, $notrigger = 0)
695 {
696 // Protection
697 if ($this->status != self::STATUS_VALIDATED) {
698 return 0;
699 }
700
701 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'PRODUCTFOURNISSEURPRICE_CANCEL');
702 }
703
711 public function reopen($user, $notrigger = 0)
712 {
713 // Protection
714 if ($this->status != self::STATUS_CANCELED) {
715 return 0;
716 }
717
718 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'PRODUCTFOURNISSEURPRICE_REOPEN');
719 }
720
731 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
732 {
733 global $conf, $langs, $hookmanager;
734
735 if (!empty($conf->dol_no_mouse_hover)) {
736 $notooltip = 1;
737 } // Force disable tooltips
738
739 $result = '';
740
741 $label = img_picto('', $this->picto).' <u>'.$langs->trans("ProductFournisseurPrice").'</u>';
742 if (isset($this->status)) {
743 $label .= ' '.$this->getLibStatut(5);
744 }
745 $label .= '<br>';
746 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
747
748 $url = dol_buildpath('/buypricehistory/productfournisseurprice_card.php', 1).'?id='.$this->id;
749
750 if ($option != 'nolink') {
751 // Add param to save lastsearch_values or not
752 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
753 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
754 $add_save_lastsearch_values = 1;
755 }
756 if ($add_save_lastsearch_values) {
757 $url .= '&save_lastsearch_values=1';
758 }
759 }
760
761 $linkclose = '';
762 if (empty($notooltip)) {
763 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
764 $label = $langs->trans("ShowProductFournisseurPrice");
765 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
766 }
767 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
768 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
769 } else {
770 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
771 }
772
773 $linkstart = '<a href="'.$url.'"';
774 $linkstart .= $linkclose.'>';
775 $linkend = '</a>';
776
777 $result .= $linkstart;
778
779 if (empty($this->showphoto_on_popup)) {
780 if ($withpicto) {
781 $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);
782 }
783 } else {
784 if ($withpicto) {
785 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
786
787 list($class, $module) = explode('@', $this->picto);
788 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
789 $filearray = dol_dir_list($upload_dir, "files");
790 $filename = $filearray[0]['name'];
791 if (!empty($filename)) {
792 $pospoint = strpos($filearray[0]['name'], '.');
793
794 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
795 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
796 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
797 } else {
798 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
799 }
800
801 $result .= '</div>';
802 } else {
803 $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);
804 }
805 }
806 }
807
808 if ($withpicto != 2) {
809 $result .= $this->ref;
810 }
811
812 $result .= $linkend;
813 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
814
815 global $action, $hookmanager;
816 $hookmanager->initHooks(array('productfournisseurpricedao'));
817 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
818 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
819 if ($reshook > 0) {
820 $result = $hookmanager->resPrint;
821 } else {
822 $result .= $hookmanager->resPrint;
823 }
824
825 return $result;
826 }
827
834 public function getLibStatut($mode = 0)
835 {
836 return $this->LibStatut($this->status, $mode);
837 }
838
839 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
847 public function LibStatut($status, $mode = 0)
848 {
849 // phpcs:enable
850 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
851 global $langs;
852 //$langs->load("buypricehistory@buypricehistory");
853 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
854 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
855 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
856 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
857 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
858 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
859 }
860
861 $statusType = 'status'.$status;
862 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
863 if ($status == self::STATUS_CANCELED) {
864 $statusType = 'status6';
865 }
866
867 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
868 }
869
876 public function info($id)
877 {
878 $sql = "SELECT rowid, date_creation as datec, tms as datem,";
879 $sql .= " fk_user_creat, fk_user_modif";
880 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
881 $sql .= " WHERE t.rowid = ".((int) $id);
882 $result = $this->db->query($sql);
883 if ($result) {
884 if ($this->db->num_rows($result)) {
885 $obj = $this->db->fetch_object($result);
886
887 $this->id = $obj->rowid;
888
889 $this->user_creation_id = $obj->fk_user_author;
890 $this->user_validation_id = $obj->fk_user_valid;
891
892 $this->date_creation = $this->db->jdate($obj->datec);
893 $this->date_modification = $this->db->jdate($obj->datem);
894 }
895
896 $this->db->free($result);
897 } else {
898 dol_print_error($this->db);
899 }
900 }
901
908 public function initAsSpecimen()
909 {
910 return $this->initAsSpecimenCommon();
911 }
912
918 public function getNextNumRef()
919 {
920 global $langs, $conf;
921 $langs->load("buypricehistory@buypricehistory");
922
923 if (!getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON')) {
924 $conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON = 'mod_productfournisseurprice_standard';
925 }
926
927 if (getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON')) {
928 $mybool = false;
929
930 $file = getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON') . ".php";
931 $classname = getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON');
932
933 // Include file with class
934 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
935 foreach ($dirmodels as $reldir) {
936 $dir = dol_buildpath($reldir."core/modules/buypricehistory/");
937
938 // Load file with numbering class (if found)
939 $mybool = ((bool) @include_once $dir.$file) || $mybool;
940 }
941
942 if (!$mybool) {
943 dol_print_error(null, "Failed to include file ".$file);
944 return '';
945 }
946
947 if (class_exists($classname)) {
948 $obj = new $classname();
949 '@phan-var-force CommonNumRefGenerator $obj';
950 $numref = $obj->getNextValue($this);
951
952 if ($numref != '' && $numref != '-1') {
953 return $numref;
954 } else {
955 $this->error = $obj->error;
956 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
957 return "";
958 }
959 } else {
960 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
961 return "";
962 }
963 } else {
964 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
965 return "";
966 }
967 }
968
980 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
981 {
982 global $langs;
983
984 $result = 0;
985 $includedocgeneration = 0;
986
987 $langs->load("buypricehistory@buypricehistory");
988
989 if (!dol_strlen($modele)) {
990 $modele = 'standard_productfournisseurprice';
991
992 if (!empty($this->model_pdf)) {
993 $modele = $this->model_pdf;
994 } elseif (getDolGlobalString('PRODUCTFOURNISSEURPRICE_ADDON_PDF')) {
995 $modele = getDolGlobalString('PRODUCTFOURNISSEURPRICE_ADDON_PDF');
996 }
997 }
998
999 $modelpath = "core/modules/buypricehistory/doc/";
1000
1001 if ($includedocgeneration && !empty($modele)) {
1002 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1003 }
1004
1005 return $result;
1006 }
1007}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class for ProductFournisseurPrice.
createFromClone(User $user, $fromid)
Clone an object into another one.
reopen($user, $notrigger=0)
Set back to validated status.
info($id)
Load the info information in the object.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
create(User $user, $notrigger=0)
Create object into database.
validate($user, $notrigger=0)
Validate object.
fetch($id)
Load object in memory from the database.
getLibStatut($mode=0)
Return the label of the status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
setDraft($user, $notrigger=0)
Set draft status.
cancel($user, $notrigger=0)
Set cancel status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
LibStatut($status, $mode=0)
Return the status.
update(User $user, $notrigger=0)
Update object into database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:168
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php