dolibarr 19.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
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 (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
181 $this->fields['rowid']['visible'] = 0;
182 }
183 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
184 $this->fields['entity']['enabled'] = 0;
185 }
186
187 // Unset fields that are disabled
188 foreach ($this->fields as $key => $val) {
189 if (isset($val['enabled']) && empty($val['enabled'])) {
190 unset($this->fields[$key]);
191 }
192 }
193 }
194
202 public function create(User $user, $notrigger = false)
203 {
204 return $this->createCommon($user, $notrigger);
205 }
206
214 public function createFromClone(User $user, $fromid)
215 {
216 global $langs, $extrafields;
217 $error = 0;
218
219 dol_syslog(__METHOD__, LOG_DEBUG);
220
221 $object = new self($this->db);
222
223 $this->db->begin();
224
225 // Load source object
226 $result = $object->fetchCommon($fromid);
227 if ($result > 0 && !empty($object->table_element_line)) {
228 $object->fetchLines();
229 }
230
231 // get lines so they will be clone
232 //foreach($this->lines as $line)
233 // $line->fetch_optionals();
234
235 // Reset some properties
236 unset($object->id);
237 unset($object->fk_user_creat);
238 unset($object->import_key);
239
240 // Clear fields
241 if (property_exists($object, 'ref')) {
242 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
243 }
244 if (property_exists($object, 'label')) {
245 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
246 }
247 if (property_exists($object, 'status')) {
248 $object->status = self::STATUS_DRAFT;
249 }
250 if (property_exists($object, 'date_creation')) {
251 $object->date_creation = dol_now();
252 }
253 if (property_exists($object, 'date_modification')) {
254 $object->date_modification = null;
255 }
256 // ...
257 // Clear extrafields that are unique
258 if (is_array($object->array_options) && count($object->array_options) > 0) {
259 $extrafields->fetch_name_optionals_label($this->table_element);
260 foreach ($object->array_options as $key => $option) {
261 $shortkey = preg_replace('/options_/', '', $key);
262 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
263 //var_dump($key);
264 //var_dump($clonedObj->array_options[$key]); exit;
265 unset($object->array_options[$key]);
266 }
267 }
268 }
269
270 // Create clone
271 $object->context['createfromclone'] = 'createfromclone';
272 $result = $object->createCommon($user);
273 if ($result < 0) {
274 $error++;
275 $this->error = $object->error;
276 $this->errors = $object->errors;
277 }
278
279 if (!$error) {
280 // copy internal contacts
281 if ($this->copy_linked_contact($object, 'internal') < 0) {
282 $error++;
283 }
284 }
285
286 if (!$error) {
287 // copy external contacts if same company
288 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
289 if ($this->copy_linked_contact($object, 'external') < 0) {
290 $error++;
291 }
292 }
293 }
294
295 unset($object->context['createfromclone']);
296
297 // End
298 if (!$error) {
299 $this->db->commit();
300 return $object;
301 } else {
302 $this->db->rollback();
303 return -1;
304 }
305 }
306
313 public function fetch($id)
314 {
315 return $this->fetchCommon($id);
316 }
317
329 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
330 {
331 global $conf;
332
333 dol_syslog(__METHOD__, LOG_DEBUG);
334
335 $records = array();
336
337 $sql = "SELECT ";
338 $sql .= $this->getFieldList();
339 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
340 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
341 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
342 } else {
343 $sql .= " WHERE 1 = 1";
344 }
345 // Manage filter
346 $sqlwhere = array();
347 if (count($filter) > 0) {
348 foreach ($filter as $key => $value) {
349 if ($key == 't.rowid') {
350 $sqlwhere[] = $key." = ".((int) $value);
351 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
352 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
353 } elseif ($key == 'customsql') {
354 $sqlwhere[] = $value;
355 } elseif (strpos($value, '%') === false) {
356 $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
357 } else {
358 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
359 }
360 }
361 }
362 if (count($sqlwhere) > 0) {
363 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
364 }
365
366 if (!empty($sortfield)) {
367 $sql .= $this->db->order($sortfield, $sortorder);
368 }
369 if (!empty($limit)) {
370 $sql .= $this->db->plimit($limit, $offset);
371 }
372
373 $resql = $this->db->query($sql);
374 if ($resql) {
375 $num = $this->db->num_rows($resql);
376 $i = 0;
377 while ($i < ($limit ? min($limit, $num) : $num)) {
378 $obj = $this->db->fetch_object($resql);
379
380 $record = new self($this->db);
381 $record->setVarsFromFetchObj($obj);
382
383 $records[$record->id] = $record;
384
385 $i++;
386 }
387 $this->db->free($resql);
388
389 return $records;
390 } else {
391 $this->errors[] = 'Error '.$this->db->lasterror();
392 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
393
394 return -1;
395 }
396 }
397
405 public function update(User $user, $notrigger = false)
406 {
407 return $this->updateCommon($user, $notrigger);
408 }
409
417 public function delete(User $user, $notrigger = false)
418 {
419 return $this->deleteCommon($user, $notrigger);
420 }
421
429 public function validate($user, $notrigger = 0)
430 {
431 global $conf, $langs;
432
433 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
434
435 $error = 0;
436
437 // Protection
438 if ($this->status == self::STATUS_VALIDATED) {
439 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
440 return 0;
441 }
442
443 $now = dol_now();
444
445 $this->db->begin();
446
447 // Define new ref
448 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
449 $num = $this->getNextNumRef();
450 } else {
451 $num = $this->ref;
452 }
453 $this->newref = $num;
454
455 if (!empty($num)) {
456 // Validate
457 $sql = "UPDATE ".$this->db->prefix().$this->table_element;
458 $sql .= " SET ref = '".$this->db->escape($num)."',";
459 $sql .= " status = ".self::STATUS_VALIDATED;
460 if (!empty($this->fields['date_validation'])) {
461 $sql .= ", date_validation = '".$this->db->idate($now)."'";
462 }
463 if (!empty($this->fields['fk_user_valid'])) {
464 $sql .= ", fk_user_valid = ".$user->id;
465 }
466 $sql .= " WHERE rowid = ".((int) $this->id);
467
468 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
469 $resql = $this->db->query($sql);
470 if (!$resql) {
471 dol_print_error($this->db);
472 $this->error = $this->db->lasterror();
473 $error++;
474 }
475
476 if (!$error && !$notrigger) {
477 // Call trigger
478 $result = $this->call_trigger('PRODUCTFOURNISSEURPRICE_VALIDATE', $user);
479 if ($result < 0) {
480 $error++;
481 }
482 // End call triggers
483 }
484 }
485
486 if (!$error) {
487 $this->oldref = $this->ref;
488
489 // Rename directory if dir was a temporary ref
490 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
491 // Now we rename also files into index
492 $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)."'";
493 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
494 $resql = $this->db->query($sql);
495 if (!$resql) {
496 $error++;
497 $this->error = $this->db->lasterror();
498 }
499 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'";
500 $sql .= " WHERE filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
501 $resql = $this->db->query($sql);
502 if (!$resql) {
503 $error++;
504 $this->error = $this->db->lasterror();
505 }
506
507 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
508 $oldref = dol_sanitizeFileName($this->ref);
509 $newref = dol_sanitizeFileName($num);
510 $dirsource = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$oldref;
511 $dirdest = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref;
512 if (!$error && file_exists($dirsource)) {
513 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
514
515 if (@rename($dirsource, $dirdest)) {
516 dol_syslog("Rename ok");
517 // Rename docs starting with $oldref with $newref
518 $listoffiles = dol_dir_list($conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
519 foreach ($listoffiles as $fileentry) {
520 $dirsource = $fileentry['name'];
521 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
522 $dirsource = $fileentry['path'].'/'.$dirsource;
523 $dirdest = $fileentry['path'].'/'.$dirdest;
524 @rename($dirsource, $dirdest);
525 }
526 }
527 }
528 }
529 }
530
531 // Set new ref and current status
532 if (!$error) {
533 $this->ref = $num;
534 $this->status = self::STATUS_VALIDATED;
535 }
536
537 if (!$error) {
538 $this->db->commit();
539 return 1;
540 } else {
541 $this->db->rollback();
542 return -1;
543 }
544 }
545
546
554 public function setDraft($user, $notrigger = 0)
555 {
556 // Protection
557 if ($this->status <= self::STATUS_DRAFT) {
558 return 0;
559 }
560
561 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'PRODUCTFOURNISSEURPRICE_UNVALIDATE');
562 }
563
571 public function cancel($user, $notrigger = 0)
572 {
573 // Protection
574 if ($this->status != self::STATUS_VALIDATED) {
575 return 0;
576 }
577
578 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'PRODUCTFOURNISSEURPRICE_CANCEL');
579 }
580
588 public function reopen($user, $notrigger = 0)
589 {
590 // Protection
591 if ($this->status != self::STATUS_CANCELED) {
592 return 0;
593 }
594
595 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'PRODUCTFOURNISSEURPRICE_REOPEN');
596 }
597
608 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
609 {
610 global $conf, $langs, $hookmanager;
611
612 if (!empty($conf->dol_no_mouse_hover)) {
613 $notooltip = 1;
614 } // Force disable tooltips
615
616 $result = '';
617
618 $label = img_picto('', $this->picto).' <u>'.$langs->trans("ProductFournisseurPrice").'</u>';
619 if (isset($this->status)) {
620 $label .= ' '.$this->getLibStatut(5);
621 }
622 $label .= '<br>';
623 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
624
625 $url = dol_buildpath('/buypricehistory/productfournisseurprice_card.php', 1).'?id='.$this->id;
626
627 if ($option != 'nolink') {
628 // Add param to save lastsearch_values or not
629 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
630 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
631 $add_save_lastsearch_values = 1;
632 }
633 if ($add_save_lastsearch_values) {
634 $url .= '&save_lastsearch_values=1';
635 }
636 }
637
638 $linkclose = '';
639 if (empty($notooltip)) {
640 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
641 $label = $langs->trans("ShowProductFournisseurPrice");
642 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
643 }
644 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
645 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
646 } else {
647 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
648 }
649
650 $linkstart = '<a href="'.$url.'"';
651 $linkstart .= $linkclose.'>';
652 $linkend = '</a>';
653
654 $result .= $linkstart;
655
656 if (empty($this->showphoto_on_popup)) {
657 if ($withpicto) {
658 $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);
659 }
660 } else {
661 if ($withpicto) {
662 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
663
664 list($class, $module) = explode('@', $this->picto);
665 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
666 $filearray = dol_dir_list($upload_dir, "files");
667 $filename = $filearray[0]['name'];
668 if (!empty($filename)) {
669 $pospoint = strpos($filearray[0]['name'], '.');
670
671 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
672 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
673 $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>';
674 } else {
675 $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>';
676 }
677
678 $result .= '</div>';
679 } else {
680 $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);
681 }
682 }
683 }
684
685 if ($withpicto != 2) {
686 $result .= $this->ref;
687 }
688
689 $result .= $linkend;
690 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
691
692 global $action, $hookmanager;
693 $hookmanager->initHooks(array('productfournisseurpricedao'));
694 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
695 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
696 if ($reshook > 0) {
697 $result = $hookmanager->resPrint;
698 } else {
699 $result .= $hookmanager->resPrint;
700 }
701
702 return $result;
703 }
704
711 public function getLibStatut($mode = 0)
712 {
713 return $this->LibStatut($this->status, $mode);
714 }
715
716 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
724 public function LibStatut($status, $mode = 0)
725 {
726 // phpcs:enable
727 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
728 global $langs;
729 //$langs->load("buypricehistory@buypricehistory");
730 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
731 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
732 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
733 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
734 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
735 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
736 }
737
738 $statusType = 'status'.$status;
739 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
740 if ($status == self::STATUS_CANCELED) {
741 $statusType = 'status6';
742 }
743
744 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
745 }
746
753 public function info($id)
754 {
755 $sql = "SELECT rowid, date_creation as datec, tms as datem,";
756 $sql .= " fk_user_creat, fk_user_modif";
757 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
758 $sql .= " WHERE t.rowid = ".((int) $id);
759 $result = $this->db->query($sql);
760 if ($result) {
761 if ($this->db->num_rows($result)) {
762 $obj = $this->db->fetch_object($result);
763
764 $this->id = $obj->rowid;
765
766 $this->user_creation_id = $obj->fk_user_author;
767 $this->user_validation_id = $obj->fk_user_valid;
768
769 $this->date_creation = $this->db->jdate($obj->datec);
770 $this->date_modification = $this->db->jdate($obj->datem);
771 }
772
773 $this->db->free($result);
774 } else {
775 dol_print_error($this->db);
776 }
777 }
778
785 public function initAsSpecimen()
786 {
787 $this->initAsSpecimenCommon();
788 }
789
795 public function getNextNumRef()
796 {
797 global $langs, $conf;
798 $langs->load("buypricehistory@buypricehistory");
799
800 if (!getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON')) {
801 $conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON = 'mod_productfournisseurprice_standard';
802 }
803
804 if (getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON')) {
805 $mybool = false;
806
807 $file = getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON') . ".php";
808 $classname = $conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON;
809
810 // Include file with class
811 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
812 foreach ($dirmodels as $reldir) {
813 $dir = dol_buildpath($reldir."core/modules/buypricehistory/");
814
815 // Load file with numbering class (if found)
816 $mybool |= @include_once $dir.$file;
817 }
818
819 if ($mybool === false) {
820 dol_print_error('', "Failed to include file ".$file);
821 return '';
822 }
823
824 if (class_exists($classname)) {
825 $obj = new $classname();
826 $numref = $obj->getNextValue($this);
827
828 if ($numref != '' && $numref != '-1') {
829 return $numref;
830 } else {
831 $this->error = $obj->error;
832 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
833 return "";
834 }
835 } else {
836 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
837 return "";
838 }
839 } else {
840 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
841 return "";
842 }
843 }
844
856 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
857 {
858 global $conf, $langs;
859
860 $result = 0;
861 $includedocgeneration = 0;
862
863 $langs->load("buypricehistory@buypricehistory");
864
865 if (!dol_strlen($modele)) {
866 $modele = 'standard_productfournisseurprice';
867
868 if (!empty($this->model_pdf)) {
869 $modele = $this->model_pdf;
870 } elseif (getDolGlobalString('PRODUCTFOURNISSEURPRICE_ADDON_PDF')) {
871 $modele = $conf->global->PRODUCTFOURNISSEURPRICE_ADDON_PDF;
872 }
873 }
874
875 $modelpath = "core/modules/buypricehistory/doc/";
876
877 if ($includedocgeneration && !empty($modele)) {
878 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
879 }
880
881 return $result;
882 }
883}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$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=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.
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.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the 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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.