dolibarr  17.0.3
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  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 // Put here all includes required by your class file
26 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27 
32 {
36  public $element = 'productfournisseurprice';
37 
41  public $table_element = 'product_fournisseur_price';
42 
47  public $ismultientitymanaged = 1;
48 
52  public $isextrafieldmanaged = 1;
53 
57  public $picto = 'productfournisseurprice@buypricehistory';
58 
59 
60  const STATUS_DRAFT = 0;
61  const STATUS_VALIDATED = 1;
62  const STATUS_CANCELED = 9;
63 
64 
91  // BEGIN MODULEBUILDER PROPERTIES
95  public $fields=array(
96  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>0,),
97  'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>'1', 'position'=>15, 'notnull'=>1, 'visible'=>-2, 'default'=>'1', 'index'=>1,),
98  'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>20, 'notnull'=>0, 'visible'=>-1,),
99  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>25, 'notnull'=>1, 'visible'=>-1,),
100  'fk_product' => array('type'=>'integer:Product:product/class/product.class.php:1', 'label'=>'Fkproduct', 'enabled'=>'1', 'position'=>30, 'notnull'=>0, 'visible'=>-1,),
101  'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>35, 'notnull'=>0, 'visible'=>-1,),
102  'ref_fourn' => array('type'=>'varchar(255)', 'label'=>'Reffourn', 'enabled'=>'1', 'position'=>40, 'notnull'=>0, 'visible'=>-1,),
103  'desc_fourn' => array('type'=>'text', 'label'=>'Descfourn', 'enabled'=>'1', 'position'=>45, 'notnull'=>0, 'visible'=>-1,),
104  'fk_availability' => array('type'=>'integer', 'label'=>'Fkavailability', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>-1,),
105  'price' => array('type'=>'double(24,8)', 'label'=>'Price', 'enabled'=>'1', 'position'=>55, 'notnull'=>0, 'visible'=>-1,),
106  'quantity' => array('type'=>'double', 'label'=>'Quantity', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>-1,),
107  'remise_percent' => array('type'=>'double', 'label'=>'Remisepercent', 'enabled'=>'1', 'position'=>65, 'notnull'=>1, 'visible'=>-1,),
108  'remise' => array('type'=>'double', 'label'=>'Remise', 'enabled'=>'1', 'position'=>70, 'notnull'=>1, 'visible'=>-1,),
109  'unitprice' => array('type'=>'double(24,8)', 'label'=>'Unitprice', 'enabled'=>'1', 'position'=>75, 'notnull'=>0, 'visible'=>-1,),
110  'charges' => array('type'=>'double(24,8)', 'label'=>'Charges', 'enabled'=>'1', 'position'=>80, 'notnull'=>0, 'visible'=>-1,),
111  'default_vat_code' => array('type'=>'varchar(10)', 'label'=>'Defaultvatcode', 'enabled'=>'1', 'position'=>85, 'notnull'=>0, 'visible'=>-1,),
112  'tva_tx' => array('type'=>'double(6,3)', 'label'=>'Tvatx', 'enabled'=>'1', 'position'=>90, 'notnull'=>1, 'visible'=>-1,),
113  'info_bits' => array('type'=>'integer', 'label'=>'Infobits', 'enabled'=>'1', 'position'=>95, 'notnull'=>1, 'visible'=>-1,),
114  'fk_user' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Fkuser', 'enabled'=>'1', 'position'=>100, 'notnull'=>0, 'visible'=>-1,),
115  'fk_supplier_price_expression' => array('type'=>'integer', 'label'=>'Fksupplierpriceexpression', 'enabled'=>'1', 'position'=>105, 'notnull'=>0, 'visible'=>-1,),
116  'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>900, 'notnull'=>0, 'visible'=>-2,),
117  'delivery_time_days' => array('type'=>'integer', 'label'=>'Deliverytimedays', 'enabled'=>'1', 'position'=>115, 'notnull'=>0, 'visible'=>-1,),
118  'supplier_reputation' => array('type'=>'varchar(10)', 'label'=>'Supplierreputation', 'enabled'=>'1', 'position'=>120, 'notnull'=>0, 'visible'=>-1,),
119  'fk_multicurrency' => array('type'=>'integer', 'label'=>'Fkmulticurrency', 'enabled'=>'1', 'position'=>125, 'notnull'=>0, 'visible'=>-1,),
120  'multicurrency_code' => array('type'=>'varchar(255)', 'label'=>'Multicurrencycode', 'enabled'=>'1', 'position'=>130, 'notnull'=>0, 'visible'=>-1,),
121  'multicurrency_tx' => array('type'=>'double(24,8)', 'label'=>'Multicurrencytx', 'enabled'=>'1', 'position'=>135, 'notnull'=>0, 'visible'=>-1,),
122  'multicurrency_price' => array('type'=>'double(24,8)', 'label'=>'Multicurrencyprice', 'enabled'=>'1', 'position'=>140, 'notnull'=>0, 'visible'=>-1,),
123  'multicurrency_unitprice' => array('type'=>'double(24,8)', 'label'=>'Multicurrencyunitprice', 'enabled'=>'1', 'position'=>145, 'notnull'=>0, 'visible'=>-1,),
124  'localtax1_tx' => array('type'=>'double(6,3)', 'label'=>'Localtax1tx', 'enabled'=>'1', 'position'=>150, 'notnull'=>0, 'visible'=>-1,),
125  'localtax1_type' => array('type'=>'varchar(10)', 'label'=>'Localtax1type', 'enabled'=>'1', 'position'=>155, 'notnull'=>1, 'visible'=>-1,),
126  'localtax2_tx' => array('type'=>'double(6,3)', 'label'=>'Localtax2tx', 'enabled'=>'1', 'position'=>160, 'notnull'=>0, 'visible'=>-1,),
127  'localtax2_type' => array('type'=>'varchar(10)', 'label'=>'Localtax2type', 'enabled'=>'1', 'position'=>165, 'notnull'=>1, 'visible'=>-1,),
128  'barcode' => array('type'=>'varchar(180)', 'label'=>'Barcode', 'enabled'=>'1', 'position'=>170, 'notnull'=>0, 'visible'=>-1,),
129  'fk_barcode_type' => array('type'=>'integer', 'label'=>'Fkbarcodetype', 'enabled'=>'1', 'position'=>175, 'notnull'=>0, 'visible'=>-1,),
130  'packaging' => array('type'=>'varchar(64)', 'label'=>'Packaging', 'enabled'=>'1', 'position'=>180, 'notnull'=>0, 'visible'=>-1,),
131  );
132  public $rowid;
133  public $entity;
134  public $datec;
135  public $tms;
136  public $fk_product;
137  public $fk_soc;
138  public $ref_fourn;
139  public $desc_fourn;
140  public $fk_availability;
141  public $price;
142  public $quantity;
143  public $remise_percent;
144  public $remise;
145  public $unitprice;
146  public $charges;
147  public $default_vat_code;
148  public $tva_tx;
149  public $info_bits;
150  public $fk_user;
151  public $fk_supplier_price_expression;
152  public $import_key;
153  public $delivery_time_days;
154  public $supplier_reputation;
155  public $fk_multicurrency;
156  public $multicurrency_code;
157  public $multicurrency_tx;
158  public $multicurrency_price;
159  public $multicurrency_unitprice;
160  public $localtax1_tx;
161  public $localtax1_type;
162  public $localtax2_tx;
163  public $localtax2_type;
164  public $barcode;
165  public $fk_barcode_type;
166  public $packaging;
167  // END MODULEBUILDER PROPERTIES
168 
174  public function __construct(DoliDB $db)
175  {
176  global $conf, $langs;
177 
178  $this->db = $db;
179 
180  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
181  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
182 
183  // Unset fields that are disabled
184  foreach ($this->fields as $key => $val) {
185  if (isset($val['enabled']) && empty($val['enabled'])) {
186  unset($this->fields[$key]);
187  }
188  }
189  }
190 
198  public function create(User $user, $notrigger = false)
199  {
200  return $this->createCommon($user, $notrigger);
201  }
202 
210  public function createFromClone(User $user, $fromid)
211  {
212  global $langs, $extrafields;
213  $error = 0;
214 
215  dol_syslog(__METHOD__, LOG_DEBUG);
216 
217  $object = new self($this->db);
218 
219  $this->db->begin();
220 
221  // Load source object
222  $result = $object->fetchCommon($fromid);
223  if ($result > 0 && !empty($object->table_element_line)) $object->fetchLines();
224 
225  // get lines so they will be clone
226  //foreach($this->lines as $line)
227  // $line->fetch_optionals();
228 
229  // Reset some properties
230  unset($object->id);
231  unset($object->fk_user_creat);
232  unset($object->import_key);
233 
234  // Clear fields
235  if (property_exists($object, 'ref')) $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
236  if (property_exists($object, 'label')) $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
237  if (property_exists($object, 'status')) { $object->status = self::STATUS_DRAFT; }
238  if (property_exists($object, 'date_creation')) { $object->date_creation = dol_now(); }
239  if (property_exists($object, 'date_modification')) { $object->date_modification = null; }
240  // ...
241  // Clear extrafields that are unique
242  if (is_array($object->array_options) && count($object->array_options) > 0) {
243  $extrafields->fetch_name_optionals_label($this->table_element);
244  foreach ($object->array_options as $key => $option) {
245  $shortkey = preg_replace('/options_/', '', $key);
246  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
247  //var_dump($key);
248  //var_dump($clonedObj->array_options[$key]); exit;
249  unset($object->array_options[$key]);
250  }
251  }
252  }
253 
254  // Create clone
255  $object->context['createfromclone'] = 'createfromclone';
256  $result = $object->createCommon($user);
257  if ($result < 0) {
258  $error++;
259  $this->error = $object->error;
260  $this->errors = $object->errors;
261  }
262 
263  if (!$error) {
264  // copy internal contacts
265  if ($this->copy_linked_contact($object, 'internal') < 0) {
266  $error++;
267  }
268  }
269 
270  if (!$error) {
271  // copy external contacts if same company
272  if (property_exists($this, 'socid') && $this->socid == $object->socid) {
273  if ($this->copy_linked_contact($object, 'external') < 0)
274  $error++;
275  }
276  }
277 
278  unset($object->context['createfromclone']);
279 
280  // End
281  if (!$error) {
282  $this->db->commit();
283  return $object;
284  } else {
285  $this->db->rollback();
286  return -1;
287  }
288  }
289 
296  public function fetch($id)
297  {
298  return $this->fetchCommon($id);
299  }
300 
312  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
313  {
314  global $conf;
315 
316  dol_syslog(__METHOD__, LOG_DEBUG);
317 
318  $records = array();
319 
320  $sql = "SELECT ";
321  $sql .= $this->getFieldList();
322  $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
323  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
324  else $sql .= " WHERE 1 = 1";
325  // Manage filter
326  $sqlwhere = array();
327  if (count($filter) > 0) {
328  foreach ($filter as $key => $value) {
329  if ($key == 't.rowid') {
330  $sqlwhere[] = $key." = ".((int) $value);
331  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
332  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
333  } elseif ($key == 'customsql') {
334  $sqlwhere[] = $value;
335  } elseif (strpos($value, '%') === false) {
336  $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
337  } else {
338  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
339  }
340  }
341  }
342  if (count($sqlwhere) > 0) {
343  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
344  }
345 
346  if (!empty($sortfield)) {
347  $sql .= $this->db->order($sortfield, $sortorder);
348  }
349  if (!empty($limit)) {
350  $sql .= $this->db->plimit($limit, $offset);
351  }
352 
353  $resql = $this->db->query($sql);
354  if ($resql) {
355  $num = $this->db->num_rows($resql);
356  $i = 0;
357  while ($i < ($limit ? min($limit, $num) : $num)) {
358  $obj = $this->db->fetch_object($resql);
359 
360  $record = new self($this->db);
361  $record->setVarsFromFetchObj($obj);
362 
363  $records[$record->id] = $record;
364 
365  $i++;
366  }
367  $this->db->free($resql);
368 
369  return $records;
370  } else {
371  $this->errors[] = 'Error '.$this->db->lasterror();
372  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
373 
374  return -1;
375  }
376  }
377 
385  public function update(User $user, $notrigger = false)
386  {
387  return $this->updateCommon($user, $notrigger);
388  }
389 
397  public function delete(User $user, $notrigger = false)
398  {
399  return $this->deleteCommon($user, $notrigger);
400  }
401 
409  public function validate($user, $notrigger = 0)
410  {
411  global $conf, $langs;
412 
413  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
414 
415  $error = 0;
416 
417  // Protection
418  if ($this->status == self::STATUS_VALIDATED) {
419  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
420  return 0;
421  }
422 
423  $now = dol_now();
424 
425  $this->db->begin();
426 
427  // Define new ref
428  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
429  $num = $this->getNextNumRef();
430  } else {
431  $num = $this->ref;
432  }
433  $this->newref = $num;
434 
435  if (!empty($num)) {
436  // Validate
437  $sql = "UPDATE ".$this->db->prefix().$this->table_element;
438  $sql .= " SET ref = '".$this->db->escape($num)."',";
439  $sql .= " status = ".self::STATUS_VALIDATED;
440  if (!empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."'";
441  if (!empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".$user->id;
442  $sql .= " WHERE rowid = ".((int) $this->id);
443 
444  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
445  $resql = $this->db->query($sql);
446  if (!$resql) {
447  dol_print_error($this->db);
448  $this->error = $this->db->lasterror();
449  $error++;
450  }
451 
452  if (!$error && !$notrigger) {
453  // Call trigger
454  $result = $this->call_trigger('PRODUCTFOURNISSEURPRICE_VALIDATE', $user);
455  if ($result < 0) $error++;
456  // End call triggers
457  }
458  }
459 
460  if (!$error) {
461  $this->oldref = $this->ref;
462 
463  // Rename directory if dir was a temporary ref
464  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
465  // Now we rename also files into index
466  $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)."'";
467  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
468  $resql = $this->db->query($sql);
469  if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
470 
471  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
472  $oldref = dol_sanitizeFileName($this->ref);
473  $newref = dol_sanitizeFileName($num);
474  $dirsource = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$oldref;
475  $dirdest = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref;
476  if (!$error && file_exists($dirsource)) {
477  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
478 
479  if (@rename($dirsource, $dirdest)) {
480  dol_syslog("Rename ok");
481  // Rename docs starting with $oldref with $newref
482  $listoffiles = dol_dir_list($conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
483  foreach ($listoffiles as $fileentry) {
484  $dirsource = $fileentry['name'];
485  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
486  $dirsource = $fileentry['path'].'/'.$dirsource;
487  $dirdest = $fileentry['path'].'/'.$dirdest;
488  @rename($dirsource, $dirdest);
489  }
490  }
491  }
492  }
493  }
494 
495  // Set new ref and current status
496  if (!$error) {
497  $this->ref = $num;
498  $this->status = self::STATUS_VALIDATED;
499  }
500 
501  if (!$error) {
502  $this->db->commit();
503  return 1;
504  } else {
505  $this->db->rollback();
506  return -1;
507  }
508  }
509 
510 
518  public function setDraft($user, $notrigger = 0)
519  {
520  // Protection
521  if ($this->status <= self::STATUS_DRAFT) {
522  return 0;
523  }
524 
525  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'PRODUCTFOURNISSEURPRICE_UNVALIDATE');
526  }
527 
535  public function cancel($user, $notrigger = 0)
536  {
537  // Protection
538  if ($this->status != self::STATUS_VALIDATED) {
539  return 0;
540  }
541 
542  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'PRODUCTFOURNISSEURPRICE_CANCEL');
543  }
544 
552  public function reopen($user, $notrigger = 0)
553  {
554  // Protection
555  if ($this->status != self::STATUS_CANCELED) {
556  return 0;
557  }
558 
559  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'PRODUCTFOURNISSEURPRICE_REOPEN');
560  }
561 
572  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
573  {
574  global $conf, $langs, $hookmanager;
575 
576  if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
577 
578  $result = '';
579 
580  $label = img_picto('', $this->picto).' <u>'.$langs->trans("ProductFournisseurPrice").'</u>';
581  if (isset($this->status)) {
582  $label .= ' '.$this->getLibStatut(5);
583  }
584  $label .= '<br>';
585  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
586 
587  $url = dol_buildpath('/buypricehistory/productfournisseurprice_card.php', 1).'?id='.$this->id;
588 
589  if ($option != 'nolink') {
590  // Add param to save lastsearch_values or not
591  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
592  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
593  if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
594  }
595 
596  $linkclose = '';
597  if (empty($notooltip)) {
598  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
599  $label = $langs->trans("ShowProductFournisseurPrice");
600  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
601  }
602  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
603  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
604  } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
605 
606  $linkstart = '<a href="'.$url.'"';
607  $linkstart .= $linkclose.'>';
608  $linkend = '</a>';
609 
610  $result .= $linkstart;
611 
612  if (empty($this->showphoto_on_popup)) {
613  if ($withpicto) $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);
614  } else {
615  if ($withpicto) {
616  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
617 
618  list($class, $module) = explode('@', $this->picto);
619  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
620  $filearray = dol_dir_list($upload_dir, "files");
621  $filename = $filearray[0]['name'];
622  if (!empty($filename)) {
623  $pospoint = strpos($filearray[0]['name'], '.');
624 
625  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
626  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
627  $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>';
628  } else {
629  $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>';
630  }
631 
632  $result .= '</div>';
633  } else {
634  $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);
635  }
636  }
637  }
638 
639  if ($withpicto != 2) $result .= $this->ref;
640 
641  $result .= $linkend;
642  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
643 
644  global $action, $hookmanager;
645  $hookmanager->initHooks(array('productfournisseurpricedao'));
646  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
647  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
648  if ($reshook > 0) $result = $hookmanager->resPrint;
649  else $result .= $hookmanager->resPrint;
650 
651  return $result;
652  }
653 
660  public function getLibStatut($mode = 0)
661  {
662  return $this->LibStatut($this->status, $mode);
663  }
664 
665  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
673  public function LibStatut($status, $mode = 0)
674  {
675  // phpcs:enable
676  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
677  global $langs;
678  //$langs->load("buypricehistory@buypricehistory");
679  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
680  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
681  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
682  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
683  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
684  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
685  }
686 
687  $statusType = 'status'.$status;
688  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
689  if ($status == self::STATUS_CANCELED) $statusType = 'status6';
690 
691  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
692  }
693 
700  public function info($id)
701  {
702  $sql = "SELECT rowid, date_creation as datec, tms as datem,";
703  $sql .= " fk_user_creat, fk_user_modif";
704  $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
705  $sql .= " WHERE t.rowid = ".((int) $id);
706  $result = $this->db->query($sql);
707  if ($result) {
708  if ($this->db->num_rows($result)) {
709  $obj = $this->db->fetch_object($result);
710  $this->id = $obj->rowid;
711  if ($obj->fk_user_author) {
712  $cuser = new User($this->db);
713  $cuser->fetch($obj->fk_user_author);
714  $this->user_creation = $cuser;
715  }
716 
717  if ($obj->fk_user_valid) {
718  $vuser = new User($this->db);
719  $vuser->fetch($obj->fk_user_valid);
720  $this->user_validation = $vuser;
721  }
722 
723  if ($obj->fk_user_cloture) {
724  $cluser = new User($this->db);
725  $cluser->fetch($obj->fk_user_cloture);
726  $this->user_cloture = $cluser;
727  }
728 
729  $this->date_creation = $this->db->jdate($obj->datec);
730  $this->date_modification = $this->db->jdate($obj->datem);
731  $this->date_validation = $this->db->jdate($obj->datev);
732  }
733 
734  $this->db->free($result);
735  } else {
736  dol_print_error($this->db);
737  }
738  }
739 
746  public function initAsSpecimen()
747  {
748  $this->initAsSpecimenCommon();
749  }
750 
756  public function getNextNumRef()
757  {
758  global $langs, $conf;
759  $langs->load("buypricehistory@buypricehistory");
760 
761  if (empty($conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON)) {
762  $conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON = 'mod_productfournisseurprice_standard';
763  }
764 
765  if (!empty($conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON)) {
766  $mybool = false;
767 
768  $file = $conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON.".php";
769  $classname = $conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON;
770 
771  // Include file with class
772  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
773  foreach ($dirmodels as $reldir) {
774  $dir = dol_buildpath($reldir."core/modules/buypricehistory/");
775 
776  // Load file with numbering class (if found)
777  $mybool |= @include_once $dir.$file;
778  }
779 
780  if ($mybool === false) {
781  dol_print_error('', "Failed to include file ".$file);
782  return '';
783  }
784 
785  if (class_exists($classname)) {
786  $obj = new $classname();
787  $numref = $obj->getNextValue($this);
788 
789  if ($numref != '' && $numref != '-1') {
790  return $numref;
791  } else {
792  $this->error = $obj->error;
793  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
794  return "";
795  }
796  } else {
797  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
798  return "";
799  }
800  } else {
801  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
802  return "";
803  }
804  }
805 
817  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
818  {
819  global $conf, $langs;
820 
821  $result = 0;
822  $includedocgeneration = 0;
823 
824  $langs->load("buypricehistory@buypricehistory");
825 
826  if (!dol_strlen($modele)) {
827  $modele = 'standard_productfournisseurprice';
828 
829  if (!empty($this->model_pdf)) {
830  $modele = $this->model_pdf;
831  } elseif (!empty($conf->global->PRODUCTFOURNISSEURPRICE_ADDON_PDF)) {
832  $modele = $conf->global->PRODUCTFOURNISSEURPRICE_ADDON_PDF;
833  }
834  }
835 
836  $modelpath = "core/modules/buypricehistory/doc/";
837 
838  if ($includedocgeneration && !empty($modele)) {
839  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
840  }
841 
842  return $result;
843  }
844 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9573
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9851
db
$conf db
API class for accounts.
Definition: inc.php:41
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9363
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1225
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1236
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
ProductFournisseurPrice\info
info($id)
Load the info information in the object.
Definition: productfournisseurprice.class.php:700
ProductFournisseurPrice\update
update(User $user, $notrigger=false)
Update object into database.
Definition: productfournisseurprice.class.php:385
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
ProductFournisseurPrice\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: productfournisseurprice.class.php:746
ProductFournisseurPrice\fetch
fetch($id)
Load object in memory from the database.
Definition: productfournisseurprice.class.php:296
ref
$object ref
Definition: info.php:78
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1061
dol_dir_list
dol_dir_list($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:61
ProductFournisseurPrice\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: productfournisseurprice.class.php:518
ProductFournisseurPrice
Class for ProductFournisseurPrice.
Definition: productfournisseurprice.class.php:31
ProductFournisseurPrice\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: productfournisseurprice.class.php:756
ProductFournisseurPrice\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: productfournisseurprice.class.php:312
ProductFournisseurPrice\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: productfournisseurprice.class.php:817
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4024
ProductFournisseurPrice\__construct
__construct(DoliDB $db)
Constructor.
Definition: productfournisseurprice.class.php:174
ProductFournisseurPrice\create
create(User $user, $notrigger=false)
Create object into database.
Definition: productfournisseurprice.class.php:198
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9191
ProductFournisseurPrice\validate
validate($user, $notrigger=0)
Validate object.
Definition: productfournisseurprice.class.php:409
ProductFournisseurPrice\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: productfournisseurprice.class.php:673
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
ProductFournisseurPrice\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: productfournisseurprice.class.php:535
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9469
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3887
ProductFournisseurPrice\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: productfournisseurprice.class.php:660
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
User
Class to manage Dolibarr users.
Definition: user.class.php:46
ProductFournisseurPrice\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: productfournisseurprice.class.php:210
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10745
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4360
ProductFournisseurPrice\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: productfournisseurprice.class.php:552
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5818
ProductFournisseurPrice\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: productfournisseurprice.class.php:572
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:9143