dolibarr 18.0.6
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
26require_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) {
470 $error++; $this->error = $this->db->lasterror();
471 }
472 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'";
473 $sql .= " WHERE filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
474 $resql = $this->db->query($sql);
475 if (!$resql) {
476 $error++; $this->error = $this->db->lasterror();
477 }
478
479 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
480 $oldref = dol_sanitizeFileName($this->ref);
481 $newref = dol_sanitizeFileName($num);
482 $dirsource = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$oldref;
483 $dirdest = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref;
484 if (!$error && file_exists($dirsource)) {
485 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
486
487 if (@rename($dirsource, $dirdest)) {
488 dol_syslog("Rename ok");
489 // Rename docs starting with $oldref with $newref
490 $listoffiles = dol_dir_list($conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
491 foreach ($listoffiles as $fileentry) {
492 $dirsource = $fileentry['name'];
493 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
494 $dirsource = $fileentry['path'].'/'.$dirsource;
495 $dirdest = $fileentry['path'].'/'.$dirdest;
496 @rename($dirsource, $dirdest);
497 }
498 }
499 }
500 }
501 }
502
503 // Set new ref and current status
504 if (!$error) {
505 $this->ref = $num;
506 $this->status = self::STATUS_VALIDATED;
507 }
508
509 if (!$error) {
510 $this->db->commit();
511 return 1;
512 } else {
513 $this->db->rollback();
514 return -1;
515 }
516 }
517
518
526 public function setDraft($user, $notrigger = 0)
527 {
528 // Protection
529 if ($this->status <= self::STATUS_DRAFT) {
530 return 0;
531 }
532
533 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'PRODUCTFOURNISSEURPRICE_UNVALIDATE');
534 }
535
543 public function cancel($user, $notrigger = 0)
544 {
545 // Protection
546 if ($this->status != self::STATUS_VALIDATED) {
547 return 0;
548 }
549
550 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'PRODUCTFOURNISSEURPRICE_CANCEL');
551 }
552
560 public function reopen($user, $notrigger = 0)
561 {
562 // Protection
563 if ($this->status != self::STATUS_CANCELED) {
564 return 0;
565 }
566
567 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'PRODUCTFOURNISSEURPRICE_REOPEN');
568 }
569
580 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
581 {
582 global $conf, $langs, $hookmanager;
583
584 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
585
586 $result = '';
587
588 $label = img_picto('', $this->picto).' <u>'.$langs->trans("ProductFournisseurPrice").'</u>';
589 if (isset($this->status)) {
590 $label .= ' '.$this->getLibStatut(5);
591 }
592 $label .= '<br>';
593 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
594
595 $url = dol_buildpath('/buypricehistory/productfournisseurprice_card.php', 1).'?id='.$this->id;
596
597 if ($option != 'nolink') {
598 // Add param to save lastsearch_values or not
599 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
600 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
601 if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
602 }
603
604 $linkclose = '';
605 if (empty($notooltip)) {
606 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
607 $label = $langs->trans("ShowProductFournisseurPrice");
608 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
609 }
610 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
611 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
612 } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
613
614 $linkstart = '<a href="'.$url.'"';
615 $linkstart .= $linkclose.'>';
616 $linkend = '</a>';
617
618 $result .= $linkstart;
619
620 if (empty($this->showphoto_on_popup)) {
621 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);
622 } else {
623 if ($withpicto) {
624 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
625
626 list($class, $module) = explode('@', $this->picto);
627 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
628 $filearray = dol_dir_list($upload_dir, "files");
629 $filename = $filearray[0]['name'];
630 if (!empty($filename)) {
631 $pospoint = strpos($filearray[0]['name'], '.');
632
633 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
634 if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
635 $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>';
636 } else {
637 $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>';
638 }
639
640 $result .= '</div>';
641 } else {
642 $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);
643 }
644 }
645 }
646
647 if ($withpicto != 2) $result .= $this->ref;
648
649 $result .= $linkend;
650 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
651
652 global $action, $hookmanager;
653 $hookmanager->initHooks(array('productfournisseurpricedao'));
654 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
655 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
656 if ($reshook > 0) $result = $hookmanager->resPrint;
657 else $result .= $hookmanager->resPrint;
658
659 return $result;
660 }
661
668 public function getLibStatut($mode = 0)
669 {
670 return $this->LibStatut($this->status, $mode);
671 }
672
673 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
681 public function LibStatut($status, $mode = 0)
682 {
683 // phpcs:enable
684 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
685 global $langs;
686 //$langs->load("buypricehistory@buypricehistory");
687 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
688 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
689 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
690 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
691 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
692 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
693 }
694
695 $statusType = 'status'.$status;
696 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
697 if ($status == self::STATUS_CANCELED) $statusType = 'status6';
698
699 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
700 }
701
708 public function info($id)
709 {
710 $sql = "SELECT rowid, date_creation as datec, tms as datem,";
711 $sql .= " fk_user_creat, fk_user_modif";
712 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
713 $sql .= " WHERE t.rowid = ".((int) $id);
714 $result = $this->db->query($sql);
715 if ($result) {
716 if ($this->db->num_rows($result)) {
717 $obj = $this->db->fetch_object($result);
718 $this->id = $obj->rowid;
719 if ($obj->fk_user_author) {
720 $cuser = new User($this->db);
721 $cuser->fetch($obj->fk_user_author);
722 $this->user_creation = $cuser;
723 }
724
725 if ($obj->fk_user_valid) {
726 $vuser = new User($this->db);
727 $vuser->fetch($obj->fk_user_valid);
728 $this->user_validation = $vuser;
729 }
730
731 if ($obj->fk_user_cloture) {
732 $cluser = new User($this->db);
733 $cluser->fetch($obj->fk_user_cloture);
734 $this->user_cloture = $cluser;
735 }
736
737 $this->date_creation = $this->db->jdate($obj->datec);
738 $this->date_modification = $this->db->jdate($obj->datem);
739 $this->date_validation = $this->db->jdate($obj->datev);
740 }
741
742 $this->db->free($result);
743 } else {
744 dol_print_error($this->db);
745 }
746 }
747
754 public function initAsSpecimen()
755 {
756 $this->initAsSpecimenCommon();
757 }
758
764 public function getNextNumRef()
765 {
766 global $langs, $conf;
767 $langs->load("buypricehistory@buypricehistory");
768
769 if (empty($conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON)) {
770 $conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON = 'mod_productfournisseurprice_standard';
771 }
772
773 if (!empty($conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON)) {
774 $mybool = false;
775
776 $file = $conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON.".php";
777 $classname = $conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON;
778
779 // Include file with class
780 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
781 foreach ($dirmodels as $reldir) {
782 $dir = dol_buildpath($reldir."core/modules/buypricehistory/");
783
784 // Load file with numbering class (if found)
785 $mybool |= @include_once $dir.$file;
786 }
787
788 if ($mybool === false) {
789 dol_print_error('', "Failed to include file ".$file);
790 return '';
791 }
792
793 if (class_exists($classname)) {
794 $obj = new $classname();
795 $numref = $obj->getNextValue($this);
796
797 if ($numref != '' && $numref != '-1') {
798 return $numref;
799 } else {
800 $this->error = $obj->error;
801 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
802 return "";
803 }
804 } else {
805 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
806 return "";
807 }
808 } else {
809 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
810 return "";
811 }
812 }
813
825 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
826 {
827 global $conf, $langs;
828
829 $result = 0;
830 $includedocgeneration = 0;
831
832 $langs->load("buypricehistory@buypricehistory");
833
834 if (!dol_strlen($modele)) {
835 $modele = 'standard_productfournisseurprice';
836
837 if (!empty($this->model_pdf)) {
838 $modele = $this->model_pdf;
839 } elseif (!empty($conf->global->PRODUCTFOURNISSEURPRICE_ADDON_PDF)) {
840 $modele = $conf->global->PRODUCTFOURNISSEURPRICE_ADDON_PDF;
841 }
842 }
843
844 $modelpath = "core/modules/buypricehistory/doc/";
845
846 if ($includedocgeneration && !empty($modele)) {
847 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
848 }
849
850 return $result;
851 }
852}
$object ref
Definition info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class for ProductFournisseurPrice.
update(User $user, $notrigger=false)
Update object into database.
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.
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 optionaly 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.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
LibStatut($status, $mode=0)
Return the status.
create(User $user, $notrigger=false)
Create 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.
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:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.