dolibarr 21.0.0-alpha
productfournisseurprice.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 Alexis LAURIER <contact@alexislaurier.fr>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29
34{
38 public $element = 'productfournisseurprice';
39
43 public $table_element = 'product_fournisseur_price';
44
48 public $picto = 'productfournisseurprice@buypricehistory';
49
50
51 const STATUS_DRAFT = 0;
52 const STATUS_VALIDATED = 1;
53 const STATUS_CANCELED = 9;
54
55
82 // BEGIN MODULEBUILDER PROPERTIES
86 public $fields = array(
87 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => '1', 'position' => 10, 'notnull' => 1, 'visible' => 0,),
88 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => '1', 'position' => 15, 'notnull' => 1, 'visible' => -2, 'default' => '1', 'index' => 1,),
89 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => '1', 'position' => 20, 'notnull' => 0, 'visible' => -1,),
90 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => '1', 'position' => 25, 'notnull' => 1, 'visible' => -1,),
91 'fk_product' => array('type' => 'integer:Product:product/class/product.class.php:1', 'label' => 'Fkproduct', 'enabled' => '1', 'position' => 30, 'notnull' => 0, 'visible' => -1,),
92 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => '1', 'position' => 35, 'notnull' => 0, 'visible' => -1,),
93 'ref_fourn' => array('type' => 'varchar(255)', 'label' => 'Reffourn', 'enabled' => '1', 'position' => 40, 'notnull' => 0, 'visible' => -1,),
94 'desc_fourn' => array('type' => 'text', 'label' => 'Descfourn', 'enabled' => '1', 'position' => 45, 'notnull' => 0, 'visible' => -1,),
95 'fk_availability' => array('type' => 'integer', 'label' => 'Fkavailability', 'enabled' => '1', 'position' => 50, 'notnull' => 0, 'visible' => -1,),
96 'price' => array('type' => 'double(24,8)', 'label' => 'Price', 'enabled' => '1', 'position' => 55, 'notnull' => 0, 'visible' => -1,),
97 'quantity' => array('type' => 'double', 'label' => 'Quantity', 'enabled' => '1', 'position' => 60, 'notnull' => 0, 'visible' => -1,),
98 'remise_percent' => array('type' => 'double', 'label' => 'Remisepercent', 'enabled' => '1', 'position' => 65, 'notnull' => 1, 'visible' => -1,),
99 'remise' => array('type' => 'double', 'label' => 'Remise', 'enabled' => '1', 'position' => 70, 'notnull' => 1, 'visible' => -1,),
100 'unitprice' => array('type' => 'double(24,8)', 'label' => 'Unitprice', 'enabled' => '1', 'position' => 75, 'notnull' => 0, 'visible' => -1,),
101 'charges' => array('type' => 'double(24,8)', 'label' => 'Charges', 'enabled' => '1', 'position' => 80, 'notnull' => 0, 'visible' => -1,),
102 'default_vat_code' => array('type' => 'varchar(10)', 'label' => 'Defaultvatcode', 'enabled' => '1', 'position' => 85, 'notnull' => 0, 'visible' => -1,),
103 'tva_tx' => array('type' => 'double(6,3)', 'label' => 'Tvatx', 'enabled' => '1', 'position' => 90, 'notnull' => 1, 'visible' => -1,),
104 'info_bits' => array('type' => 'integer', 'label' => 'Infobits', 'enabled' => '1', 'position' => 95, 'notnull' => 1, 'visible' => -1,),
105 'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fkuser', 'enabled' => '1', 'position' => 100, 'notnull' => 0, 'visible' => -1,),
106 'fk_supplier_price_expression' => array('type' => 'integer', 'label' => 'Fksupplierpriceexpression', 'enabled' => '1', 'position' => 105, 'notnull' => 0, 'visible' => -1,),
107 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => '1', 'position' => 900, 'notnull' => 0, 'visible' => -2,),
108 'delivery_time_days' => array('type' => 'integer', 'label' => 'Deliverytimedays', 'enabled' => '1', 'position' => 115, 'notnull' => 0, 'visible' => -1,),
109 'supplier_reputation' => array('type' => 'varchar(10)', 'label' => 'Supplierreputation', 'enabled' => '1', 'position' => 120, 'notnull' => 0, 'visible' => -1,),
110 'fk_multicurrency' => array('type' => 'integer', 'label' => 'Fkmulticurrency', 'enabled' => '1', 'position' => 125, 'notnull' => 0, 'visible' => -1,),
111 'multicurrency_code' => array('type' => 'varchar(255)', 'label' => 'Multicurrencycode', 'enabled' => '1', 'position' => 130, 'notnull' => 0, 'visible' => -1,),
112 'multicurrency_tx' => array('type' => 'double(24,8)', 'label' => 'Multicurrencytx', 'enabled' => '1', 'position' => 135, 'notnull' => 0, 'visible' => -1,),
113 'multicurrency_price' => array('type' => 'double(24,8)', 'label' => 'Multicurrencyprice', 'enabled' => '1', 'position' => 140, 'notnull' => 0, 'visible' => -1,),
114 'multicurrency_unitprice' => array('type' => 'double(24,8)', 'label' => 'Multicurrencyunitprice', 'enabled' => '1', 'position' => 145, 'notnull' => 0, 'visible' => -1,),
115 'localtax1_tx' => array('type' => 'double(6,3)', 'label' => 'Localtax1tx', 'enabled' => '1', 'position' => 150, 'notnull' => 0, 'visible' => -1,),
116 'localtax1_type' => array('type' => 'varchar(10)', 'label' => 'Localtax1type', 'enabled' => '1', 'position' => 155, 'notnull' => 1, 'visible' => -1,),
117 'localtax2_tx' => array('type' => 'double(6,3)', 'label' => 'Localtax2tx', 'enabled' => '1', 'position' => 160, 'notnull' => 0, 'visible' => -1,),
118 'localtax2_type' => array('type' => 'varchar(10)', 'label' => 'Localtax2type', 'enabled' => '1', 'position' => 165, 'notnull' => 1, 'visible' => -1,),
119 'barcode' => array('type' => 'varchar(180)', 'label' => 'Barcode', 'enabled' => '1', 'position' => 170, 'notnull' => 0, 'visible' => -1,),
120 'fk_barcode_type' => array('type' => 'integer', 'label' => 'Fkbarcodetype', 'enabled' => '1', 'position' => 175, 'notnull' => 0, 'visible' => -1,),
121 'packaging' => array('type' => 'varchar(64)', 'label' => 'Packaging', 'enabled' => '1', 'position' => 180, 'notnull' => 0, 'visible' => -1,),
122 );
123 public $rowid;
124 public $entity;
125 public $datec;
126 public $fk_product;
127 public $fk_soc;
128 public $ref_fourn;
129 public $desc_fourn;
130 public $fk_availability;
131 public $price;
132 public $quantity;
133 public $remise_percent;
134 public $remise;
135 public $unitprice;
136 public $charges;
137 public $default_vat_code;
138 public $tva_tx;
139 public $info_bits;
140 public $fk_user;
141 public $fk_supplier_price_expression;
142 public $import_key;
143 public $delivery_time_days;
144 public $supplier_reputation;
145 public $fk_multicurrency;
146 public $multicurrency_code;
147 public $multicurrency_tx;
148 public $multicurrency_price;
149 public $multicurrency_unitprice;
150 public $localtax1_tx;
151 public $localtax1_type;
152 public $localtax2_tx;
153 public $localtax2_type;
154 public $barcode;
155 public $fk_barcode_type;
156 public $packaging;
157 // END MODULEBUILDER PROPERTIES
158
164 public function __construct(DoliDB $db)
165 {
166 global $conf, $langs;
167
168 $this->db = $db;
169
170 $this->ismultientitymanaged = 1;
171 $this->isextrafieldmanaged = 1;
172
173 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
174 $this->fields['rowid']['visible'] = 0;
175 }
176 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
177 $this->fields['entity']['enabled'] = 0;
178 }
179
180 // Unset fields that are disabled
181 foreach ($this->fields as $key => $val) {
182 if (isset($val['enabled']) && empty($val['enabled'])) {
183 unset($this->fields[$key]);
184 }
185 }
186 }
187
195 public function create(User $user, $notrigger = 0)
196 {
197 return $this->createCommon($user, $notrigger);
198 }
199
207 public function createFromClone(User $user, $fromid)
208 {
209 global $langs, $extrafields;
210 $error = 0;
211
212 dol_syslog(__METHOD__, LOG_DEBUG);
213
214 $object = new self($this->db);
215
216 $this->db->begin();
217
218 // Load source object
219 $result = $object->fetchCommon($fromid);
220 if ($result > 0 && !empty($object->table_element_line)) {
221 $object->fetchLines();
222 }
223
224 // get lines so they will be clone
225 //foreach($this->lines as $line)
226 // $line->fetch_optionals();
227
228 // Reset some properties
229 unset($object->id);
230 unset($object->fk_user_creat);
231 unset($object->import_key);
232
233 // Clear fields
234 if (property_exists($object, 'ref')) {
235 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
236 }
237 if (property_exists($object, 'label')) {
238 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
239 }
240 if (property_exists($object, 'status')) {
241 $object->status = self::STATUS_DRAFT;
242 }
243 if (property_exists($object, 'date_creation')) {
244 $object->date_creation = dol_now();
245 }
246 if (property_exists($object, 'date_modification')) {
247 $object->date_modification = null;
248 }
249 // ...
250 // Clear extrafields that are unique
251 if (is_array($object->array_options) && count($object->array_options) > 0) {
252 $extrafields->fetch_name_optionals_label($this->table_element);
253 foreach ($object->array_options as $key => $option) {
254 $shortkey = preg_replace('/options_/', '', $key);
255 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
256 //var_dump($key);
257 //var_dump($clonedObj->array_options[$key]); exit;
258 unset($object->array_options[$key]);
259 }
260 }
261 }
262
263 // Create clone
264 $object->context['createfromclone'] = 'createfromclone';
265 $result = $object->createCommon($user);
266 if ($result < 0) {
267 $error++;
268 $this->error = $object->error;
269 $this->errors = $object->errors;
270 }
271
272 if (!$error) {
273 // copy internal contacts
274 if ($this->copy_linked_contact($object, 'internal') < 0) {
275 $error++;
276 }
277 }
278
279 if (!$error) {
280 // copy external contacts if same company
281 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
282 if ($this->copy_linked_contact($object, 'external') < 0) {
283 $error++;
284 }
285 }
286 }
287
288 unset($object->context['createfromclone']);
289
290 // End
291 if (!$error) {
292 $this->db->commit();
293 return $object;
294 } else {
295 $this->db->rollback();
296 return -1;
297 }
298 }
299
306 public function fetch($id)
307 {
308 return $this->fetchCommon($id);
309 }
310
322 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
323 {
324 dol_syslog(__METHOD__, LOG_DEBUG);
325
326 $records = array();
327
328 $sql = "SELECT ";
329 $sql .= $this->getFieldList();
330 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
331 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
332 $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
333 } else {
334 $sql .= " WHERE 1 = 1";
335 }
336
337 // Manage filter
338 if (is_array($filter)) {
339 $sqlwhere = array();
340 if (count($filter) > 0) {
341 foreach ($filter as $key => $value) {
342 if ($key == 't.rowid') {
343 $sqlwhere[] = $key." = ".((int) $value);
344 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
345 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
346 } elseif (strpos($value, '%') === false) {
347 $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
348 } else {
349 $sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
350 }
351 }
352 }
353 if (count($sqlwhere) > 0) {
354 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
355 }
356
357 $filter = '';
358 }
359
360 // Manage filter
361 $errormessage = '';
362 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
363 if ($errormessage) {
364 $this->errors[] = $errormessage;
365 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
366 return -1;
367 }
368
369 if (!empty($sortfield)) {
370 $sql .= $this->db->order($sortfield, $sortorder);
371 }
372 if (!empty($limit)) {
373 $sql .= $this->db->plimit($limit, $offset);
374 }
375
376 $resql = $this->db->query($sql);
377 if ($resql) {
378 $num = $this->db->num_rows($resql);
379 $i = 0;
380 while ($i < ($limit ? min($limit, $num) : $num)) {
381 $obj = $this->db->fetch_object($resql);
382
383 $record = new self($this->db);
384 $record->setVarsFromFetchObj($obj);
385
386 $records[$record->id] = $record;
387
388 $i++;
389 }
390 $this->db->free($resql);
391
392 return $records;
393 } else {
394 $this->errors[] = 'Error '.$this->db->lasterror();
395 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
396
397 return -1;
398 }
399 }
400
408 public function update(User $user, $notrigger = 0)
409 {
410 return $this->updateCommon($user, $notrigger);
411 }
412
420 public function delete(User $user, $notrigger = 0)
421 {
422 return $this->deleteCommon($user, $notrigger);
423 }
424
432 public function validate($user, $notrigger = 0)
433 {
434 global $conf, $langs;
435
436 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
437
438 $error = 0;
439
440 // Protection
441 if ($this->status == self::STATUS_VALIDATED) {
442 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
443 return 0;
444 }
445
446 $now = dol_now();
447
448 $this->db->begin();
449
450 // Define new ref
451 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
452 $num = $this->getNextNumRef();
453 } else {
454 $num = $this->ref;
455 }
456 $this->newref = $num;
457
458 if (!empty($num)) {
459 // Validate
460 $sql = "UPDATE ".$this->db->prefix().$this->table_element;
461 $sql .= " SET ref = '".$this->db->escape($num)."',";
462 $sql .= " status = ".self::STATUS_VALIDATED;
463 if (!empty($this->fields['date_validation'])) {
464 $sql .= ", date_validation = '".$this->db->idate($now)."'";
465 }
466 if (!empty($this->fields['fk_user_valid'])) {
467 $sql .= ", fk_user_valid = ".$user->id;
468 }
469 $sql .= " WHERE rowid = ".((int) $this->id);
470
471 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
472 $resql = $this->db->query($sql);
473 if (!$resql) {
474 dol_print_error($this->db);
475 $this->error = $this->db->lasterror();
476 $error++;
477 }
478
479 if (!$error && !$notrigger) {
480 // Call trigger
481 $result = $this->call_trigger('PRODUCTFOURNISSEURPRICE_VALIDATE', $user);
482 if ($result < 0) {
483 $error++;
484 }
485 // End call triggers
486 }
487 }
488
489 if (!$error) {
490 $this->oldref = $this->ref;
491
492 // Rename directory if dir was a temporary ref
493 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
494 // Now we rename also files into index
495 $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)."'";
496 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
497 $resql = $this->db->query($sql);
498 if (!$resql) {
499 $error++;
500 $this->error = $this->db->lasterror();
501 }
502 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'";
503 $sql .= " WHERE filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
504 $resql = $this->db->query($sql);
505 if (!$resql) {
506 $error++;
507 $this->error = $this->db->lasterror();
508 }
509
510 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
511 $oldref = dol_sanitizeFileName($this->ref);
512 $newref = dol_sanitizeFileName($num);
513 $dirsource = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$oldref;
514 $dirdest = $conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref;
515 if (!$error && file_exists($dirsource)) {
516 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
517
518 if (@rename($dirsource, $dirdest)) {
519 dol_syslog("Rename ok");
520 // Rename docs starting with $oldref with $newref
521 $listoffiles = dol_dir_list($conf->buypricehistory->dir_output.'/productfournisseurprice/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
522 foreach ($listoffiles as $fileentry) {
523 $dirsource = $fileentry['name'];
524 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
525 $dirsource = $fileentry['path'].'/'.$dirsource;
526 $dirdest = $fileentry['path'].'/'.$dirdest;
527 @rename($dirsource, $dirdest);
528 }
529 }
530 }
531 }
532 }
533
534 // Set new ref and current status
535 if (!$error) {
536 $this->ref = $num;
537 $this->status = self::STATUS_VALIDATED;
538 }
539
540 if (!$error) {
541 $this->db->commit();
542 return 1;
543 } else {
544 $this->db->rollback();
545 return -1;
546 }
547 }
548
549
557 public function setDraft($user, $notrigger = 0)
558 {
559 // Protection
560 if ($this->status <= self::STATUS_DRAFT) {
561 return 0;
562 }
563
564 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'PRODUCTFOURNISSEURPRICE_UNVALIDATE');
565 }
566
574 public function cancel($user, $notrigger = 0)
575 {
576 // Protection
577 if ($this->status != self::STATUS_VALIDATED) {
578 return 0;
579 }
580
581 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'PRODUCTFOURNISSEURPRICE_CANCEL');
582 }
583
591 public function reopen($user, $notrigger = 0)
592 {
593 // Protection
594 if ($this->status != self::STATUS_CANCELED) {
595 return 0;
596 }
597
598 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'PRODUCTFOURNISSEURPRICE_REOPEN');
599 }
600
611 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
612 {
613 global $conf, $langs, $hookmanager;
614
615 if (!empty($conf->dol_no_mouse_hover)) {
616 $notooltip = 1;
617 } // Force disable tooltips
618
619 $result = '';
620
621 $label = img_picto('', $this->picto).' <u>'.$langs->trans("ProductFournisseurPrice").'</u>';
622 if (isset($this->status)) {
623 $label .= ' '.$this->getLibStatut(5);
624 }
625 $label .= '<br>';
626 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
627
628 $url = dol_buildpath('/buypricehistory/productfournisseurprice_card.php', 1).'?id='.$this->id;
629
630 if ($option != 'nolink') {
631 // Add param to save lastsearch_values or not
632 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
633 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
634 $add_save_lastsearch_values = 1;
635 }
636 if ($add_save_lastsearch_values) {
637 $url .= '&save_lastsearch_values=1';
638 }
639 }
640
641 $linkclose = '';
642 if (empty($notooltip)) {
643 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
644 $label = $langs->trans("ShowProductFournisseurPrice");
645 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
646 }
647 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
648 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
649 } else {
650 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
651 }
652
653 $linkstart = '<a href="'.$url.'"';
654 $linkstart .= $linkclose.'>';
655 $linkend = '</a>';
656
657 $result .= $linkstart;
658
659 if (empty($this->showphoto_on_popup)) {
660 if ($withpicto) {
661 $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);
662 }
663 } else {
664 if ($withpicto) {
665 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
666
667 list($class, $module) = explode('@', $this->picto);
668 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
669 $filearray = dol_dir_list($upload_dir, "files");
670 $filename = $filearray[0]['name'];
671 if (!empty($filename)) {
672 $pospoint = strpos($filearray[0]['name'], '.');
673
674 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
675 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
676 $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>';
677 } else {
678 $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>';
679 }
680
681 $result .= '</div>';
682 } else {
683 $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);
684 }
685 }
686 }
687
688 if ($withpicto != 2) {
689 $result .= $this->ref;
690 }
691
692 $result .= $linkend;
693 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
694
695 global $action, $hookmanager;
696 $hookmanager->initHooks(array('productfournisseurpricedao'));
697 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
698 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
699 if ($reshook > 0) {
700 $result = $hookmanager->resPrint;
701 } else {
702 $result .= $hookmanager->resPrint;
703 }
704
705 return $result;
706 }
707
714 public function getLibStatut($mode = 0)
715 {
716 return $this->LibStatut($this->status, $mode);
717 }
718
719 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
727 public function LibStatut($status, $mode = 0)
728 {
729 // phpcs:enable
730 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
731 global $langs;
732 //$langs->load("buypricehistory@buypricehistory");
733 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
734 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
735 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
736 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
737 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
738 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
739 }
740
741 $statusType = 'status'.$status;
742 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
743 if ($status == self::STATUS_CANCELED) {
744 $statusType = 'status6';
745 }
746
747 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
748 }
749
756 public function info($id)
757 {
758 $sql = "SELECT rowid, date_creation as datec, tms as datem,";
759 $sql .= " fk_user_creat, fk_user_modif";
760 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
761 $sql .= " WHERE t.rowid = ".((int) $id);
762 $result = $this->db->query($sql);
763 if ($result) {
764 if ($this->db->num_rows($result)) {
765 $obj = $this->db->fetch_object($result);
766
767 $this->id = $obj->rowid;
768
769 $this->user_creation_id = $obj->fk_user_author;
770 $this->user_validation_id = $obj->fk_user_valid;
771
772 $this->date_creation = $this->db->jdate($obj->datec);
773 $this->date_modification = $this->db->jdate($obj->datem);
774 }
775
776 $this->db->free($result);
777 } else {
778 dol_print_error($this->db);
779 }
780 }
781
788 public function initAsSpecimen()
789 {
790 return $this->initAsSpecimenCommon();
791 }
792
798 public function getNextNumRef()
799 {
800 global $langs, $conf;
801 $langs->load("buypricehistory@buypricehistory");
802
803 if (!getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON')) {
804 $conf->global->BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON = 'mod_productfournisseurprice_standard';
805 }
806
807 if (getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON')) {
808 $mybool = false;
809
810 $file = getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON') . ".php";
811 $classname = getDolGlobalString('BUYPRICEHISTORY_PRODUCTFOURNISSEURPRICE_ADDON');
812
813 // Include file with class
814 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
815 foreach ($dirmodels as $reldir) {
816 $dir = dol_buildpath($reldir."core/modules/buypricehistory/");
817
818 // Load file with numbering class (if found)
819 $mybool = ((bool) @include_once $dir.$file) || $mybool;
820 }
821
822 if ($mybool === false) {
823 dol_print_error(null, "Failed to include file ".$file);
824 return '';
825 }
826
827 if (class_exists($classname)) {
828 $obj = new $classname();
829 $numref = $obj->getNextValue($this);
830
831 if ($numref != '' && $numref != '-1') {
832 return $numref;
833 } else {
834 $this->error = $obj->error;
835 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
836 return "";
837 }
838 } else {
839 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
840 return "";
841 }
842 } else {
843 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
844 return "";
845 }
846 }
847
859 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
860 {
861 global $conf, $langs;
862
863 $result = 0;
864 $includedocgeneration = 0;
865
866 $langs->load("buypricehistory@buypricehistory");
867
868 if (!dol_strlen($modele)) {
869 $modele = 'standard_productfournisseurprice';
870
871 if (!empty($this->model_pdf)) {
872 $modele = $this->model_pdf;
873 } elseif (getDolGlobalString('PRODUCTFOURNISSEURPRICE_ADDON_PDF')) {
874 $modele = getDolGlobalString('PRODUCTFOURNISSEURPRICE_ADDON_PDF');
875 }
876 }
877
878 $modelpath = "core/modules/buypricehistory/doc/";
879
880 if ($includedocgeneration && !empty($modele)) {
881 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
882 }
883
884 return $result;
885 }
886}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:626
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class for ProductFournisseurPrice.
createFromClone(User $user, $fromid)
Clone an object into another one.
reopen($user, $notrigger=0)
Set back to validated status.
info($id)
Load the info information in the object.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
create(User $user, $notrigger=0)
Create object into database.
validate($user, $notrigger=0)
Validate object.
fetch($id)
Load object in memory from the database.
getLibStatut($mode=0)
Return the label of the status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
setDraft($user, $notrigger=0)
Set draft status.
cancel($user, $notrigger=0)
Set cancel status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
LibStatut($status, $mode=0)
Return the status.
update(User $user, $notrigger=0)
Update object into database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Class to manage Dolibarr users.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.