dolibarr 21.0.0-alpha
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 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 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 global $conf, $langs;
269
270 $this->db = $db;
271
272 $this->ismultientitymanaged = 1;
273 $this->isextrafieldmanaged = 1;
274
275 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
276 $this->fields['rowid']['visible'] = 0;
277 }
278 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
279 $this->fields['entity']['enabled'] = 0;
280 }
281
282 // Unset fields that are disabled
283 foreach ($this->fields as $key => $val) {
284 if (isset($val['enabled']) && empty($val['enabled'])) {
285 unset($this->fields[$key]);
286 }
287 }
288 }
289
297 public function create(User $user, $notrigger = 0)
298 {
299 return $this->createCommon($user, $notrigger);
300 }
301
309 public function createFromClone(User $user, $fromid)
310 {
311 global $langs, $extrafields;
312 $error = 0;
313
314 dol_syslog(__METHOD__, LOG_DEBUG);
315
316 $object = new self($this->db);
317
318 $this->db->begin();
319
320 // Load source object
321 $result = $object->fetchCommon($fromid);
322 if ($result > 0 && !empty($object->table_element_line)) {
323 $object->fetchLines();
324 }
325
326 // get lines so they will be clone
327 //foreach($this->lines as $line)
328 // $line->fetch_optionals();
329
330 // Reset some properties
331 unset($object->id);
332 unset($object->fk_user_creat);
333 unset($object->import_key);
334
335 // Clear fields
336 if (property_exists($object, 'ref')) {
337 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
338 }
339 if (property_exists($object, 'label')) {
340 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
341 }
342 if (property_exists($object, 'status')) {
343 $object->status = self::STATUS_DRAFT;
344 }
345 if (property_exists($object, 'date_creation')) {
346 $object->date_creation = dol_now();
347 }
348 if (property_exists($object, 'date_modification')) {
349 $object->date_modification = null;
350 }
351 // ...
352 // Clear extrafields that are unique
353 if (is_array($object->array_options) && count($object->array_options) > 0) {
354 $extrafields->fetch_name_optionals_label($this->table_element);
355 foreach ($object->array_options as $key => $option) {
356 $shortkey = preg_replace('/options_/', '', $key);
357 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
358 //var_dump($key);
359 //var_dump($clonedObj->array_options[$key]); exit;
360 unset($object->array_options[$key]);
361 }
362 }
363 }
364
365 // Create clone
366 $object->context['createfromclone'] = 'createfromclone';
367 $result = $object->createCommon($user);
368 if ($result < 0) {
369 $error++;
370 $this->error = $object->error;
371 $this->errors = $object->errors;
372 }
373
374 if (!$error) {
375 // copy internal contacts
376 if ($this->copy_linked_contact($object, 'internal') < 0) {
377 $error++;
378 }
379 }
380
381 if (!$error) {
382 // copy external contacts if same company
383 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
384 if ($this->copy_linked_contact($object, 'external') < 0) {
385 $error++;
386 }
387 }
388 }
389
390 unset($object->context['createfromclone']);
391
392 // End
393 if (!$error) {
394 $this->db->commit();
395 return $object;
396 } else {
397 $this->db->rollback();
398 return -1;
399 }
400 }
401
408 public function fetch($id)
409 {
410 return $this->fetchCommon($id);
411 }
412
424 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
425 {
426 dol_syslog(__METHOD__, LOG_DEBUG);
427
428 $records = array();
429
430 $sql = "SELECT ";
431 $sql .= $this->getFieldList();
432 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
433 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
434 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
435 } else {
436 $sql .= " WHERE 1 = 1";
437 }
438
439 // Manage filter
440 if (is_array($filter)) {
441 $sqlwhere = array();
442 if (count($filter) > 0) {
443 foreach ($filter as $key => $value) {
444 if ($key == 't.rowid') {
445 $sqlwhere[] = $key." = ".((int) $value);
446 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
447 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
448 } elseif (strpos($value, '%') === false) {
449 $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
450 } else {
451 $sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
452 }
453 }
454 }
455 if (count($sqlwhere) > 0) {
456 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
457 }
458
459 $filter = '';
460 }
461
462 // Manage filter
463 $errormessage = '';
464 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
465 if ($errormessage) {
466 $this->errors[] = $errormessage;
467 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
468 return -1;
469 }
470
471 if (!empty($sortfield)) {
472 $sql .= $this->db->order($sortfield, $sortorder);
473 }
474 if (!empty($limit)) {
475 $sql .= $this->db->plimit($limit, $offset);
476 }
477
478 $resql = $this->db->query($sql);
479 if ($resql) {
480 $num = $this->db->num_rows($resql);
481 $i = 0;
482 while ($i < ($limit ? min($limit, $num) : $num)) {
483 $obj = $this->db->fetch_object($resql);
484
485 $record = new self($this->db);
486 $record->setVarsFromFetchObj($obj);
487
488 $records[$record->id] = $record;
489
490 $i++;
491 }
492 $this->db->free($resql);
493
494 return $records;
495 } else {
496 $this->errors[] = 'Error '.$this->db->lasterror();
497 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
498
499 return -1;
500 }
501 }
502
510 public function update(User $user, $notrigger = 0)
511 {
512 return $this->updateCommon($user, $notrigger);
513 }
514
522 public function delete(User $user, $notrigger = 0)
523 {
524 return $this->deleteCommon($user, $notrigger);
525 }
526
534 public function validate($user, $notrigger = 0)
535 {
536 global $conf, $langs;
537
538 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
539
540 $error = 0;
541
542 // Protection
543 if ($this->status == self::STATUS_VALIDATED) {
544 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
545 return 0;
546 }
547
548 $now = dol_now();
549
550 $this->db->begin();
551
552 // Define new ref
553 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
554 $num = $this->getNextNumRef();
555 } else {
556 $num = $this->ref;
557 }
558 $this->newref = $num;
559
560 if (!empty($num)) {
561 // Validate
562 $sql = "UPDATE ".$this->db->prefix().$this->table_element;
563 $sql .= " SET ref = '".$this->db->escape($num)."',";
564 $sql .= " status = ".self::STATUS_VALIDATED;
565 if (!empty($this->fields['date_validation'])) {
566 $sql .= ", date_validation = '".$this->db->idate($now)."'";
567 }
568 if (!empty($this->fields['fk_user_valid'])) {
569 $sql .= ", fk_user_valid = ".((int) $user->id);
570 }
571 $sql .= " WHERE rowid = ".((int) $this->id);
572
573 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
574 $resql = $this->db->query($sql);
575 if (!$resql) {
576 dol_print_error($this->db);
577 $this->error = $this->db->lasterror();
578 $error++;
579 }
580
581 if (!$error && !$notrigger) {
582 // Call trigger
583 $result = $this->call_trigger('PRODUCTFOURNISSEURPRICE_VALIDATE', $user);
584 if ($result < 0) {
585 $error++;
586 }
587 // End call triggers
588 }
589 }
590
591 if (!$error) {
592 $this->oldref = $this->ref;
593
594 // Rename directory if dir was a temporary ref
595 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
596 // Now we rename also files into index
597 $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)."'";
598 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
599 $resql = $this->db->query($sql);
600 if (!$resql) {
601 $error++;
602 $this->error = $this->db->lasterror();
603 }
604 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'";
605 $sql .= " WHERE filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
606 $resql = $this->db->query($sql);
607 if (!$resql) {
608 $error++;
609 $this->error = $this->db->lasterror();
610 }
611
612 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
613 $oldref = dol_sanitizeFileName($this->ref);
614 $newref = dol_sanitizeFileName($num);
615 $dirsource = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$oldref;
616 $dirdest = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref;
617 if (!$error && file_exists($dirsource)) {
618 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
619
620 if (@rename($dirsource, $dirdest)) {
621 dol_syslog("Rename ok");
622 // Rename docs starting with $oldref with $newref
623 $listoffiles = dol_dir_list($conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
624 foreach ($listoffiles as $fileentry) {
625 $dirsource = $fileentry['name'];
626 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
627 $dirsource = $fileentry['path'].'/'.$dirsource;
628 $dirdest = $fileentry['path'].'/'.$dirdest;
629 @rename($dirsource, $dirdest);
630 }
631 }
632 }
633 }
634 }
635
636 // Set new ref and current status
637 if (!$error) {
638 $this->ref = $num;
639 $this->status = self::STATUS_VALIDATED;
640 }
641
642 if (!$error) {
643 $this->db->commit();
644 return 1;
645 } else {
646 $this->db->rollback();
647 return -1;
648 }
649 }
650
651
659 public function setDraft($user, $notrigger = 0)
660 {
661 // Protection
662 if ($this->status <= self::STATUS_DRAFT) {
663 return 0;
664 }
665
666 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'PRODUCTFOURNISSEURPRICE_UNVALIDATE');
667 }
668
676 public function cancel($user, $notrigger = 0)
677 {
678 // Protection
679 if ($this->status != self::STATUS_VALIDATED) {
680 return 0;
681 }
682
683 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'PRODUCTFOURNISSEURPRICE_CANCEL');
684 }
685
693 public function reopen($user, $notrigger = 0)
694 {
695 // Protection
696 if ($this->status != self::STATUS_CANCELED) {
697 return 0;
698 }
699
700 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'PRODUCTFOURNISSEURPRICE_REOPEN');
701 }
702
713 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
714 {
715 global $conf, $langs, $hookmanager;
716
717 if (!empty($conf->dol_no_mouse_hover)) {
718 $notooltip = 1;
719 } // Force disable tooltips
720
721 $result = '';
722
723 $label = img_picto('', $this->picto).' <u>'.$langs->trans("ProductFournisseurPrice").'</u>';
724 if (isset($this->status)) {
725 $label .= ' '.$this->getLibStatut(5);
726 }
727 $label .= '<br>';
728 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
729
730 $url = dol_buildpath('/buypricehistory/productfournisseurprice_card.php', 1).'?id='.$this->id;
731
732 if ($option != 'nolink') {
733 // Add param to save lastsearch_values or not
734 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
735 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
736 $add_save_lastsearch_values = 1;
737 }
738 if ($add_save_lastsearch_values) {
739 $url .= '&save_lastsearch_values=1';
740 }
741 }
742
743 $linkclose = '';
744 if (empty($notooltip)) {
745 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
746 $label = $langs->trans("ShowProductFournisseurPrice");
747 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
748 }
749 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
750 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
751 } else {
752 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
753 }
754
755 $linkstart = '<a href="'.$url.'"';
756 $linkstart .= $linkclose.'>';
757 $linkend = '</a>';
758
759 $result .= $linkstart;
760
761 if (empty($this->showphoto_on_popup)) {
762 if ($withpicto) {
763 $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);
764 }
765 } else {
766 if ($withpicto) {
767 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
768
769 list($class, $module) = explode('@', $this->picto);
770 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
771 $filearray = dol_dir_list($upload_dir, "files");
772 $filename = $filearray[0]['name'];
773 if (!empty($filename)) {
774 $pospoint = strpos($filearray[0]['name'], '.');
775
776 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
777 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
778 $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>';
779 } else {
780 $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>';
781 }
782
783 $result .= '</div>';
784 } else {
785 $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);
786 }
787 }
788 }
789
790 if ($withpicto != 2) {
791 $result .= $this->ref;
792 }
793
794 $result .= $linkend;
795 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
796
797 global $action, $hookmanager;
798 $hookmanager->initHooks(array('productfournisseurpricedao'));
799 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
800 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
801 if ($reshook > 0) {
802 $result = $hookmanager->resPrint;
803 } else {
804 $result .= $hookmanager->resPrint;
805 }
806
807 return $result;
808 }
809
816 public function getLibStatut($mode = 0)
817 {
818 return $this->LibStatut($this->status, $mode);
819 }
820
821 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
829 public function LibStatut($status, $mode = 0)
830 {
831 // phpcs:enable
832 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
833 global $langs;
834 //$langs->load("buypricehistory@buypricehistory");
835 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
836 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
837 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
838 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
839 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
840 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
841 }
842
843 $statusType = 'status'.$status;
844 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
845 if ($status == self::STATUS_CANCELED) {
846 $statusType = 'status6';
847 }
848
849 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
850 }
851
858 public function info($id)
859 {
860 $sql = "SELECT rowid, date_creation as datec, tms as datem,";
861 $sql .= " fk_user_creat, fk_user_modif";
862 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
863 $sql .= " WHERE t.rowid = ".((int) $id);
864 $result = $this->db->query($sql);
865 if ($result) {
866 if ($this->db->num_rows($result)) {
867 $obj = $this->db->fetch_object($result);
868
869 $this->id = $obj->rowid;
870
871 $this->user_creation_id = $obj->fk_user_author;
872 $this->user_validation_id = $obj->fk_user_valid;
873
874 $this->date_creation = $this->db->jdate($obj->datec);
875 $this->date_modification = $this->db->jdate($obj->datem);
876 }
877
878 $this->db->free($result);
879 } else {
880 dol_print_error($this->db);
881 }
882 }
883
890 public function initAsSpecimen()
891 {
892 return $this->initAsSpecimenCommon();
893 }
894
900 public function getNextNumRef()
901 {
902 global $langs, $conf;
903 $langs->load("buypricehistory@buypricehistory");
904
905 if (!getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON')) {
906 $conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON = 'mod_productfournisseurprice_standard';
907 }
908
909 if (getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON')) {
910 $mybool = false;
911
912 $file = getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON') . ".php";
913 $classname = getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON');
914
915 // Include file with class
916 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
917 foreach ($dirmodels as $reldir) {
918 $dir = dol_buildpath($reldir."core/modules/buypricehistory/");
919
920 // Load file with numbering class (if found)
921 $mybool = ((bool) @include_once $dir.$file) || $mybool;
922 }
923
924 if (!$mybool) {
925 dol_print_error(null, "Failed to include file ".$file);
926 return '';
927 }
928
929 if (class_exists($classname)) {
930 $obj = new $classname();
931 '@phan-var-force CommonNumRefGenerator $obj';
932 $numref = $obj->getNextValue($this);
933
934 if ($numref != '' && $numref != '-1') {
935 return $numref;
936 } else {
937 $this->error = $obj->error;
938 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
939 return "";
940 }
941 } else {
942 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
943 return "";
944 }
945 } else {
946 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
947 return "";
948 }
949 }
950
962 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
963 {
964 global $conf, $langs;
965
966 $result = 0;
967 $includedocgeneration = 0;
968
969 $langs->load("buypricehistory@buypricehistory");
970
971 if (!dol_strlen($modele)) {
972 $modele = 'standard_productfournisseurprice';
973
974 if (!empty($this->model_pdf)) {
975 $modele = $this->model_pdf;
976 } elseif (getDolGlobalString('PRODUCTFOURNISSEURPRICE_ADDON_PDF')) {
977 $modele = getDolGlobalString('PRODUCTFOURNISSEURPRICE_ADDON_PDF');
978 }
979 }
980
981 $modelpath = "core/modules/buypricehistory/doc/";
982
983 if ($includedocgeneration && !empty($modele)) {
984 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
985 }
986
987 return $result;
988 }
989}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
$object ref
Definition info.php:79
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.
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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:162
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:63
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)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.