dolibarr  19.0.0-dev
partnership.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 NextGestion <contact@nextgestion.com>
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 
26 // Put here all includes required by your class file
27 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28 
33 {
37  public $module = 'partnership';
38 
42  public $element = 'partnership';
43 
47  public $table_element = 'partnership';
48 
53  public $ismultientitymanaged = 0;
54 
58  public $isextrafieldmanaged = 1;
59 
63  public $picto = 'partnership';
64 
65  public $type_code;
66  public $type_label;
67 
68 
69  const STATUS_DRAFT = 0;
70  const STATUS_VALIDATED = 1; // Validate (no more draft)
71  const STATUS_APPROVED = 2; // Approved
72  const STATUS_REFUSED = 3; // Refused
73  const STATUS_CANCELED = 9;
74 
75 
102  // BEGIN MODULEBUILDER PROPERTIES
106  public $fields=array(
107  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
108  'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>4, 'noteditable'=>'1', 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"),
109  'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>'1', 'position'=>15, 'notnull'=>1, 'visible'=>-2, 'default'=>'1', 'index'=>1,),
110  'fk_type' => array('type'=>'integer:PartnershipType:partnership/class/partnership_type.class.php:0:(active:=:1)', 'label'=>'Type', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'csslist'=>'tdoverflowmax100'),
111  'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label'=>'ThirdParty', 'picto'=>'company', 'enabled'=>'1', 'position'=>50, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'css'=>'maxwidth500', 'csslist'=>'tdoverflowmax125',),
112  'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,),
113  'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,),
114  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
115  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
116  'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
117  'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
118  'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>0,),
119  'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
120  'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
121  'date_partnership_start' => array('type'=>'date', 'label'=>'DatePartnershipStart', 'enabled'=>'1', 'position'=>52, 'notnull'=>1, 'visible'=>1,),
122  'date_partnership_end' => array('type'=>'date', 'label'=>'DatePartnershipEnd', 'enabled'=>'1', 'position'=>53, 'notnull'=>0, 'visible'=>1,),
123  'url_to_check' => array('type'=>'varchar(255)', 'label'=>'UrlToCheck', 'enabled'=>'1', 'position'=>70, 'notnull'=>0, 'visible'=>-1,),
124  'count_last_url_check_error' => array('type'=>'integer', 'label'=>'CountLastUrlCheckError', 'enabled'=>'1', 'position'=>71, 'notnull'=>0, 'visible'=>-2, 'default'=>'0',),
125  'last_check_backlink' => array('type'=>'datetime', 'label'=>'LastCheckBacklink', 'enabled'=>'1', 'position'=>72, 'notnull'=>0, 'visible'=>-2,),
126  'reason_decline_or_cancel' => array('type'=>'text', 'label'=>'ReasonDeclineOrCancel', 'enabled'=>'1', 'position'=>73, 'notnull'=>0, 'visible'=>-2,),
127  'ip' => array('type'=>'varchar(250)', 'label'=>'Ip', 'enabled'=>'1', 'position'=>74, 'notnull'=>0, 'visible'=>-2,),
128  'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>2000, 'notnull'=>1, 'visible'=>2, 'default'=>'0', 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Accepted', '2'=>'Refused', '8'=>'Suspended', '9'=>'Terminated'),),
129  );
130  public $rowid;
131  public $ref;
132  public $entity;
133  public $fk_type;
134  public $note_public;
135  public $note_private;
136  public $date_creation;
137  public $tms;
138  public $fk_user_creat;
139  public $fk_user_modif;
140  public $last_main_doc;
141  public $import_key;
142  public $model_pdf;
143  public $date_partnership_start;
144  public $date_partnership_end;
145  public $url_to_check;
146  public $count_last_url_check_error;
147  public $last_check_backlink;
148  public $reason_decline_or_cancel;
149  public $fk_soc;
150  public $fk_member;
151  public $ip;
152  public $status;
153  // END MODULEBUILDER PROPERTIES
154 
155 
156  // If this object has a subtable with lines
157 
158  // /**
159  // * @var string Name of subtable line
160  // */
161  // public $table_element_line = 'partnershipline';
162 
163  // /**
164  // * @var string Field with ID of parent key if this object has a parent
165  // */
166  // public $fk_element = 'fk_partnership';
167 
168  // /**
169  // * @var string Name of subtable class that manage subtable lines
170  // */
171  // public $class_element_line = 'Partnershipline';
172 
173  // /**
174  // * @var array List of child tables. To test if we can delete object.
175  // */
176  // protected $childtables = array();
177 
178  // /**
179  // * @var array List of child tables. To know object to delete on cascade.
180  // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
181  // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
182  // */
183  // protected $childtablesoncascade = array('partnershipdet');
184 
185  // /**
186  // * @var PartnershipLine[] Array of subtable lines
187  // */
188  // public $lines = array();
189 
190 
196  public function __construct(DoliDB $db)
197  {
198  global $conf, $langs;
199 
200  $this->db = $db;
201 
202  if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
203  $this->fields['fk_member'] = array('type'=>'integer:Adherent:adherents/class/adherent.class.php:1', 'label'=>'Member', 'enabled'=>'1', 'position'=>50, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'picto'=>'member', 'csslist'=>'tdoverflowmax150');
204  } else {
205  $this->fields['fk_soc'] = array('type'=>'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>50, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'picto'=>'company', 'css'=>'maxwidth500', 'csslist'=>'tdoverflowmax150');
206  }
207 
208  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
209  $this->fields['rowid']['visible'] = 0;
210  }
211  // if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
212  // $this->fields['entity']['enabled'] = 0;
213  // }
214 
215  // Example to show how to set values of fields definition dynamically
216  /*if ($user->rights->partnership->read) {
217  $this->fields['myfield']['visible'] = 1;
218  $this->fields['myfield']['noteditable'] = 0;
219  }*/
220 
221  // Unset fields that are disabled
222  foreach ($this->fields as $key => $val) {
223  if (isset($val['enabled']) && empty($val['enabled'])) {
224  unset($this->fields[$key]);
225  }
226  }
227 
228  // Translate some data of arrayofkeyval
229  if (is_object($langs)) {
230  foreach ($this->fields as $key => $val) {
231  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
232  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
233  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
234  }
235  }
236  }
237  }
238  }
239 
247  public function create(User $user, $notrigger = false)
248  {
249  if ($this->fk_soc <= 0 && $this->fk_member <= 0) {
250  $this->error[] = "ErrorThirpdartyOrMemberidIsMandatory";
251  return -1;
252  }
253 
254  $this->status = 0;
255  return $this->createCommon($user, $notrigger);
256  }
257 
265  public function createFromClone(User $user, $fromid)
266  {
267  global $langs, $extrafields;
268  $error = 0;
269 
270  dol_syslog(__METHOD__, LOG_DEBUG);
271 
272  $object = new self($this->db);
273 
274  $this->db->begin();
275 
276  // Load source object
277  $result = $object->fetchCommon($fromid);
278  if ($result > 0 && !empty($object->table_element_line)) {
279  $object->fetchLines();
280  }
281 
282  // get lines so they will be clone
283  //foreach($this->lines as $line)
284  // $line->fetch_optionals();
285 
286  // Reset some properties
287  unset($object->id);
288  unset($object->fk_user_creat);
289  unset($object->import_key);
290 
291  // Clear fields
292  if (property_exists($object, 'ref')) {
293  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
294  }
295  if (property_exists($object, 'label')) {
296  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
297  }
298  if (property_exists($object, 'status')) {
299  $object->status = self::STATUS_DRAFT;
300  }
301  if (property_exists($object, 'date_creation')) {
302  $object->date_creation = dol_now();
303  }
304  if (property_exists($object, 'date_modification')) {
305  $object->date_modification = null;
306  }
307  // ...
308  // Clear extrafields that are unique
309  if (is_array($object->array_options) && count($object->array_options) > 0) {
310  $extrafields->fetch_name_optionals_label($this->table_element);
311  foreach ($object->array_options as $key => $option) {
312  $shortkey = preg_replace('/options_/', '', $key);
313  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
314  //var_dump($key);
315  //var_dump($clonedObj->array_options[$key]); exit;
316  unset($object->array_options[$key]);
317  }
318  }
319  }
320 
321  // Create clone
322  $object->context['createfromclone'] = 'createfromclone';
323  $result = $object->createCommon($user);
324  if ($result < 0) {
325  $error++;
326  $this->error = $object->error;
327  $this->errors = $object->errors;
328  }
329 
330  if (!$error) {
331  // copy internal contacts
332  if ($this->copy_linked_contact($object, 'internal') < 0) {
333  $error++;
334  }
335  }
336 
337  if (!$error) {
338  // copy external contacts if same company
339  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
340  if ($this->copy_linked_contact($object, 'external') < 0) {
341  $error++;
342  }
343  }
344  }
345 
346  unset($object->context['createfromclone']);
347 
348  // End
349  if (!$error) {
350  $this->db->commit();
351  return $object;
352  } else {
353  $this->db->rollback();
354  return -1;
355  }
356  }
357 
368  public function fetch($id, $ref = null, $fk_member = null, $fk_soc = null)
369  {
370  global $conf;
371 
372  // Check parameters
373  if (empty($id) && empty($ref) && empty($fk_member) && empty($fk_soc)) {
374  return -1;
375  }
376 
377  $sql = 'SELECT p.rowid, p.ref, p.fk_type, p.fk_soc, p.fk_member, p.status';
378  $sql .= ', p.entity, p.date_partnership_start, p.date_partnership_end, p.date_creation';
379  $sql .= ', p.fk_user_creat, p.tms, p.fk_user_modif, p.fk_user_modif';
380  $sql .= ', p.note_private, p.note_public, p.url_to_check';
381  $sql .= ', p.last_main_doc, p.count_last_url_check_error, p.last_check_backlink, p.reason_decline_or_cancel';
382  $sql .= ', p.import_key, p.model_pdf';
383  $sql .= ', pt.code as type_code, pt.label as type_label';
384  $sql .= ' FROM '.MAIN_DB_PREFIX.'partnership as p';
385  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_partnership_type as pt ON p.fk_type = pt.rowid';
386 
387  if ($id) {
388  $sql .= " WHERE p.rowid = ".((int) $id);
389  } else {
390  $sql .= " WHERE p.entity IN (0,".getEntity('partnership').")"; // Dont't use entity if you use rowid
391  }
392 
393  if ($ref) {
394  $sql .= " AND p.ref='".$this->db->escape($ref)."'";
395  }
396 
397  if ($fk_member > 0) {
398  $sql .= ' AND p.fk_member = '.((int) $fk_member);
399  }
400  if ($fk_soc > 0) {
401  $sql .= ' AND p.fk_soc = '.((int) $fk_soc);
402  }
403  $sql .= ' ORDER BY p.date_partnership_end DESC';
404 
405  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
406  $result = $this->db->query($sql);
407  if ($result) {
408  $obj = $this->db->fetch_object($result);
409  if ($obj) {
410  $this->id = $obj->rowid;
411  $this->entity = $obj->entity;
412  $this->ref = $obj->ref;
413 
414  $this->fk_type = $obj->fk_type;
415  $this->type_code = $obj->type_code;
416  $this->type_label = $obj->type_label;
417 
418  $this->fk_soc = $obj->fk_soc;
419  $this->fk_member = $obj->fk_member;
420  $this->status = $obj->status;
421  $this->date_partnership_start = $this->db->jdate($obj->date_partnership_start);
422  $this->date_partnership_end = $this->db->jdate($obj->date_partnership_end);
423  $this->date_creation = $this->db->jdate($obj->date_creation);
424  $this->fk_user_creat = $obj->fk_user_creat;
425  $this->tms = $obj->tms;
426  $this->fk_user_modif = $obj->fk_user_modif;
427  $this->note_private = $obj->note_private;
428  $this->note_public = $obj->note_public;
429  $this->last_main_doc = $obj->last_main_doc;
430  $this->count_last_url_check_error = $obj->count_last_url_check_error;
431  $this->last_check_backlink = $this->db->jdate($obj->last_check_backlink);
432  $this->reason_decline_or_cancel = $obj->reason_decline_or_cancel;
433  $this->import_key = $obj->import_key;
434  $this->model_pdf = $obj->model_pdf;
435  $this->url_to_check = $obj->url_to_check;
436 
437  // Retrieve all extrafield
438  // fetch optionals attributes and labels
439  $this->fetch_optionals();
440 
441  $this->db->free($result);
442 
443  return 1;
444  } else {
445  // $this->error = 'Partnership with id '.$id.' not found sql='.$sql;
446  return 0;
447  }
448  } else {
449  $this->error = $this->db->error();
450  return -1;
451  }
452  }
453 
454 
460  public function fetchLines()
461  {
462  $this->lines = array();
463 
464  $result = $this->fetchLinesCommon();
465  return $result;
466  }
467 
468 
480  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
481  {
482  global $conf;
483 
484  dol_syslog(__METHOD__, LOG_DEBUG);
485 
486  $records = array();
487 
488  $sql = 'SELECT ';
489  $sql .= $this->getFieldList('t');
490  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
491  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
492  $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
493  } else {
494  $sql .= ' WHERE 1 = 1';
495  }
496  // Manage filter
497  $sqlwhere = array();
498  if (count($filter) > 0) {
499  foreach ($filter as $key => $value) {
500  if ($key == 't.rowid') {
501  $sqlwhere[] = $key." = ".((int) $value);
502  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
503  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
504  } elseif ($key == 'customsql') {
505  $sqlwhere[] = $value;
506  } elseif (strpos($value, '%') === false) {
507  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
508  } else {
509  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
510  }
511  }
512  }
513  if (count($sqlwhere) > 0) {
514  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
515  }
516 
517  if (!empty($sortfield)) {
518  $sql .= $this->db->order($sortfield, $sortorder);
519  }
520  if (!empty($limit)) {
521  $sql .= $this->db->plimit($limit, $offset);
522  }
523 
524  $resql = $this->db->query($sql);
525  if ($resql) {
526  $num = $this->db->num_rows($resql);
527  $i = 0;
528  while ($i < ($limit ? min($limit, $num) : $num)) {
529  $obj = $this->db->fetch_object($resql);
530 
531  $record = new self($this->db);
532  $record->setVarsFromFetchObj($obj);
533 
534  $records[$record->id] = $record;
535 
536  $i++;
537  }
538  $this->db->free($resql);
539 
540  return $records;
541  } else {
542  $this->errors[] = 'Error '.$this->db->lasterror();
543  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
544 
545  return -1;
546  }
547  }
548 
556  public function update(User $user, $notrigger = false)
557  {
558  if ($this->fk_soc <= 0 && $this->fk_member <= 0) {
559  $this->error[] = "ErrorThirpdartyOrMemberidIsMandatory";
560  return -1;
561  }
562  if (empty($this->fk_user_creat)) { // For the case the object was created with empty user (from public page).
563  $this->fk_user_creat = $user->id;
564  }
565 
566  return $this->updateCommon($user, $notrigger);
567  }
568 
576  public function delete(User $user, $notrigger = false)
577  {
578  return $this->deleteCommon($user, $notrigger);
579  //return $this->deleteCommon($user, $notrigger, 1);
580  }
581 
590  public function deleteLine(User $user, $idline, $notrigger = false)
591  {
592  if ($this->status < 0) {
593  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
594  return -2;
595  }
596 
597  return $this->deleteLineCommon($user, $idline, $notrigger);
598  }
599 
600 
608  public function validate($user, $notrigger = 0)
609  {
610  global $conf, $langs;
611 
612  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
613 
614  $error = 0;
615 
616  // Protection
617  if ($this->status == self::STATUS_VALIDATED) {
618  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
619  return 0;
620  }
621 
622  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
623  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->partnership_advance->validate))))
624  {
625  $this->error='NotEnoughPermissions';
626  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
627  return -1;
628  }*/
629 
630  $now = dol_now();
631 
632  $this->db->begin();
633 
634  // Define new ref
635  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
636  $num = $this->getNextNumRef();
637  } else {
638  $num = $this->ref;
639  }
640  $this->newref = $num;
641 
642  if (!empty($num)) {
643  // Validate
644  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
645  $sql .= " SET ref = '".$this->db->escape($num)."',";
646  $sql .= " status = ".self::STATUS_VALIDATED;
647  if (!empty($this->fields['date_validation'])) {
648  $sql .= ", date_validation = '".$this->db->idate($now)."'";
649  }
650  if (!empty($this->fields['fk_user_valid'])) {
651  $sql .= ", fk_user_valid = ".$user->id;
652  }
653  $sql .= " WHERE rowid = ".((int) $this->id);
654 
655  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
656  $resql = $this->db->query($sql);
657  if (!$resql) {
658  dol_print_error($this->db);
659  $this->error = $this->db->lasterror();
660  $error++;
661  }
662 
663  if (!$error && !$notrigger) {
664  // Call trigger
665  $result = $this->call_trigger('PARTNERSHIP_VALIDATE', $user);
666  if ($result < 0) {
667  $error++;
668  }
669  // End call triggers
670  }
671  }
672 
673  if (!$error) {
674  $this->oldref = $this->ref;
675 
676  // Rename directory if dir was a temporary ref
677  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
678  // Now we rename also files into index
679  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'partnership/".$this->db->escape($this->newref)."'";
680  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'partnership/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
681  $resql = $this->db->query($sql);
682  if (!$resql) {
683  $error++; $this->error = $this->db->lasterror();
684  }
685 
686  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
687  $oldref = dol_sanitizeFileName($this->ref);
688  $newref = dol_sanitizeFileName($num);
689  $dirsource = $conf->partnership->dir_output.'/partnership/'.$oldref;
690  $dirdest = $conf->partnership->dir_output.'/partnership/'.$newref;
691  if (!$error && file_exists($dirsource)) {
692  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
693 
694  if (@rename($dirsource, $dirdest)) {
695  dol_syslog("Rename ok");
696  // Rename docs starting with $oldref with $newref
697  $listoffiles = dol_dir_list($conf->partnership->dir_output.'/partnership/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
698  foreach ($listoffiles as $fileentry) {
699  $dirsource = $fileentry['name'];
700  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
701  $dirsource = $fileentry['path'].'/'.$dirsource;
702  $dirdest = $fileentry['path'].'/'.$dirdest;
703  @rename($dirsource, $dirdest);
704  }
705  }
706  }
707  }
708  }
709 
710  // Set new ref and current status
711  if (!$error) {
712  $this->ref = $num;
713  $this->status = self::STATUS_VALIDATED;
714  }
715 
716  if (!$error) {
717  $this->db->commit();
718  return 1;
719  } else {
720  $this->db->rollback();
721  return -1;
722  }
723  }
724 
732  public function approve($user, $notrigger = 0)
733  {
734  global $conf, $langs;
735 
736  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
737 
738  $error = 0;
739 
740  // Protection
741  if ($this->status == self::STATUS_APPROVED) {
742  dol_syslog(get_class($this)."::accept action abandonned: already acceptd", LOG_WARNING);
743  return 0;
744  }
745 
746  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
747  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->partnership_advance->accept))))
748  {
749  $this->error='NotEnoughPermissions';
750  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
751  return -1;
752  }*/
753 
754  $now = dol_now();
755 
756  $this->db->begin();
757 
758  // Define new ref
759  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
760  $num = $this->getNextNumRef();
761  } else {
762  $num = $this->ref;
763  }
764  $this->newref = $num;
765 
766  if (!empty($num)) {
767  // Accept
768  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
769  $sql .= " SET ref = '".$this->db->escape($num)."',";
770  $sql .= " status = ".self::STATUS_APPROVED;
771  // if (!empty($this->fields['date_validation'])) {
772  // $sql .= ", date_validation = '".$this->db->idate($now)."'";
773  // }
774  // if (!empty($this->fields['fk_user_valid'])) {
775  // $sql .= ", fk_user_valid = ".$user->id;
776  // }
777  $sql .= " WHERE rowid = ".((int) $this->id);
778 
779  dol_syslog(get_class($this)."::accept()", LOG_DEBUG);
780  $resql = $this->db->query($sql);
781  if (!$resql) {
782  dol_print_error($this->db);
783  $this->error = $this->db->lasterror();
784  $error++;
785  }
786 
787  if (!$error && !$notrigger) {
788  // Call trigger
789  $result = $this->call_trigger('PARTNERSHIP_ACCEPT', $user);
790  if ($result < 0) {
791  $error++;
792  }
793  // End call triggers
794  }
795  }
796 
797  if (!$error) {
798  $this->oldref = $this->ref;
799 
800  // Rename directory if dir was a temporary ref
801  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
802  // Now we rename also files into index
803  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'partnership/".$this->db->escape($this->newref)."'";
804  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'partnership/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
805  $resql = $this->db->query($sql);
806  if (!$resql) {
807  $error++; $this->error = $this->db->lasterror();
808  }
809 
810  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
811  $oldref = dol_sanitizeFileName($this->ref);
812  $newref = dol_sanitizeFileName($num);
813  $dirsource = $conf->partnership->dir_output.'/partnership/'.$oldref;
814  $dirdest = $conf->partnership->dir_output.'/partnership/'.$newref;
815  if (!$error && file_exists($dirsource)) {
816  dol_syslog(get_class($this)."::accept() rename dir ".$dirsource." into ".$dirdest);
817 
818  if (@rename($dirsource, $dirdest)) {
819  dol_syslog("Rename ok");
820  // Rename docs starting with $oldref with $newref
821  $listoffiles = dol_dir_list($conf->partnership->dir_output.'/partnership/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
822  foreach ($listoffiles as $fileentry) {
823  $dirsource = $fileentry['name'];
824  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
825  $dirsource = $fileentry['path'].'/'.$dirsource;
826  $dirdest = $fileentry['path'].'/'.$dirdest;
827  @rename($dirsource, $dirdest);
828  }
829  }
830  }
831  }
832  }
833 
834  // Set new ref and current status
835  if (!$error) {
836  $this->ref = $num;
837  $this->status = self::STATUS_APPROVED;
838  }
839 
840  if (!$error) {
841  $this->db->commit();
842  return 1;
843  } else {
844  $this->db->rollback();
845  return -1;
846  }
847  }
848 
849 
857  public function setDraft($user, $notrigger = 0)
858  {
859  // Protection
860  if ($this->status <= self::STATUS_DRAFT) {
861  return 0;
862  }
863 
864  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
865  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership_advance->validate))))
866  {
867  $this->error='Permission denied';
868  return -1;
869  }*/
870 
871  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'PARTNERSHIP_UNVALIDATE');
872  }
873 
882  public function refused($user, $reasondeclinenote = '', $notrigger = 0)
883  {
884  // Protection
885  if ($this->status == self::STATUS_REFUSED) {
886  return 0;
887  }
888 
889  $this->status = self::STATUS_REFUSED;
890  $this->reason_decline_or_cancel = $reasondeclinenote;
891 
892  $result = $this->update($user);
893 
894  if ($result) {
895  $this->reason_decline_or_cancel = $reasondeclinenote;
896  return 1;
897  }
898 
899  return -1;
900  }
901 
909  public function cancel($user, $notrigger = 0)
910  {
911  // Protection
912  if ($this->status != self::STATUS_APPROVED) {
913  return 0;
914  }
915 
916  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
917  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership_advance->validate))))
918  {
919  $this->error='Permission denied';
920  return -1;
921  }*/
922 
923  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'PARTNERSHIP_CANCEL');
924  }
925 
933  public function reopen($user, $notrigger = 0)
934  {
935  // Protection
936  if ($this->status != self::STATUS_CANCELED && $this->status != self::STATUS_REFUSED) {
937  return 0;
938  }
939 
940  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
941  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership_advance->validate))))
942  {
943  $this->error='Permission denied';
944  return -1;
945  }*/
946 
947  return $this->setStatusCommon($user, self::STATUS_APPROVED, $notrigger, 'PARTNERSHIP_REOPEN');
948  }
949 
957  public function getTooltipContentArray($params)
958  {
959  global $langs;
960 
961  $langs->load('partnership');
962 
963  $datas = [];
964  $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Partnership").'</u>';
965  if (isset($this->status)) {
966  $datas['picto'] .= ' '.$this->getLibStatut(5);
967  }
968  $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
969 
970  return $datas;
971  }
972 
983  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
984  {
985  global $conf, $langs, $hookmanager;
986 
987  if (!empty($conf->dol_no_mouse_hover)) {
988  $notooltip = 1; // Force disable tooltips
989  }
990 
991  $result = '';
992  $params = [
993  'id' => $this->id,
994  'objecttype' => $this->element,
995  'option' => $option,
996  ];
997  $classfortooltip = 'classfortooltip';
998  $dataparams = '';
999  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1000  $classfortooltip = 'classforajaxtooltip';
1001  $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1002  $label = '';
1003  } else {
1004  $label = implode($this->getTooltipContentArray($params));
1005  }
1006 
1007  $url = DOL_URL_ROOT.'/partnership/partnership_card.php?id='.$this->id;
1008 
1009  if ($option != 'nolink') {
1010  // Add param to save lastsearch_values or not
1011  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1012  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1013  $add_save_lastsearch_values = 1;
1014  }
1015  if ($add_save_lastsearch_values) {
1016  $url .= '&save_lastsearch_values=1';
1017  }
1018  }
1019 
1020  $linkclose = '';
1021  if (empty($notooltip)) {
1022  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1023  $label = $langs->trans("ShowPartnership");
1024  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1025  }
1026  $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
1027  $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1028  } else {
1029  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1030  }
1031 
1032  if ($option == 'nolink') {
1033  $linkstart = '<span';
1034  } else {
1035  $linkstart = '<a href="'.$url.'"';
1036  }
1037  $linkstart .= $linkclose.'>';
1038  if ($option == 'nolink') {
1039  $linkend = '</span>';
1040  } else {
1041  $linkend = '</a>';
1042  }
1043 
1044  $result .= $linkstart;
1045 
1046  if (empty($this->showphoto_on_popup)) {
1047  if ($withpicto) {
1048  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1);
1049  }
1050  } else {
1051  if ($withpicto) {
1052  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1053 
1054  list($class, $module) = explode('@', $this->picto);
1055  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
1056  $filearray = dol_dir_list($upload_dir, "files");
1057  $filename = $filearray[0]['name'];
1058  if (!empty($filename)) {
1059  $pospoint = strpos($filearray[0]['name'], '.');
1060 
1061  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
1062  if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
1063  $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>';
1064  } else {
1065  $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>';
1066  }
1067 
1068  $result .= '</div>';
1069  } else {
1070  $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);
1071  }
1072  }
1073  }
1074 
1075  if ($withpicto != 2) {
1076  $result .= $this->ref;
1077  }
1078 
1079  $result .= $linkend;
1080  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
1081 
1082  global $action, $hookmanager;
1083  $hookmanager->initHooks(array('partnershipdao'));
1084  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1085  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1086  if ($reshook > 0) {
1087  $result = $hookmanager->resPrint;
1088  } else {
1089  $result .= $hookmanager->resPrint;
1090  }
1091 
1092  return $result;
1093  }
1094 
1101  public function getLibStatut($mode = 0)
1102  {
1103  return $this->LibStatut($this->status, $mode);
1104  }
1105 
1106  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1114  public function LibStatut($status, $mode = 0)
1115  {
1116  // phpcs:enable
1117  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1118  global $langs;
1119  //$langs->load("partnership");
1120  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1121  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1122  $this->labelStatus[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('Approved');
1123  $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
1124  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Terminated');
1125  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1126  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1127  $this->labelStatusShort[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('Approved');
1128  $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
1129  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Terminated');
1130  }
1131 
1132  $statusType = 'status'.$status;
1133  if ($status == self::STATUS_APPROVED) {
1134  $statusType = 'status4';
1135  }
1136  if ($status == self::STATUS_REFUSED) {
1137  $statusType = 'status9';
1138  }
1139  if ($status == self::STATUS_CANCELED) {
1140  $statusType = 'status6';
1141  }
1142 
1143  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1144  }
1145 
1152  public function info($id)
1153  {
1154  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
1155  $sql .= ' fk_user_creat, fk_user_modif';
1156  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
1157  $sql .= ' WHERE t.rowid = '.((int) $id);
1158  $result = $this->db->query($sql);
1159  if ($result) {
1160  if ($this->db->num_rows($result)) {
1161  $obj = $this->db->fetch_object($result);
1162  $this->id = $obj->rowid;
1163 
1164  $this->user_creation_id = $obj->fk_user_creat;
1165  $this->user_modification_id = $obj->fk_user_modif;
1166  $this->date_creation = $this->db->jdate($obj->datec);
1167  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1168  }
1169 
1170  $this->db->free($result);
1171  } else {
1172  dol_print_error($this->db);
1173  }
1174  }
1175 
1182  public function initAsSpecimen()
1183  {
1184  $this->initAsSpecimenCommon();
1185  }
1186 
1192  public function getLinesArray()
1193  {
1194  $this->lines = array();
1195 
1196  $objectline = new PartnershipLine($this->db);
1197  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_partnership = '.((int) $this->id)));
1198 
1199  if (is_numeric($result)) {
1200  $this->error = $objectline->error;
1201  $this->errors = $objectline->errors;
1202  return $result;
1203  } else {
1204  $this->lines = $result;
1205  return $this->lines;
1206  }
1207  }
1208 
1214  public function getNextNumRef()
1215  {
1216  global $langs, $conf;
1217  $langs->load("partnership");
1218 
1219  if (empty($conf->global->PARTNERSHIP_ADDON)) {
1220  $conf->global->PARTNERSHIP_ADDON = 'mod_partnership_standard';
1221  }
1222 
1223  if (!empty($conf->global->PARTNERSHIP_ADDON)) {
1224  $mybool = false;
1225 
1226  $file = $conf->global->PARTNERSHIP_ADDON.".php";
1227  $classname = $conf->global->PARTNERSHIP_ADDON;
1228 
1229  // Include file with class
1230  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1231  foreach ($dirmodels as $reldir) {
1232  $dir = dol_buildpath($reldir."core/modules/partnership/");
1233 
1234  // Load file with numbering class (if found)
1235  $mybool |= @include_once $dir.$file;
1236  }
1237 
1238  if ($mybool === false) {
1239  dol_print_error('', "Failed to include file ".$file);
1240  return '';
1241  }
1242 
1243  if (class_exists($classname)) {
1244  $obj = new $classname();
1245  $numref = $obj->getNextValue($this);
1246 
1247  if ($numref != '' && $numref != '-1') {
1248  return $numref;
1249  } else {
1250  $this->error = $obj->error;
1251  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1252  return "";
1253  }
1254  } else {
1255  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1256  return "";
1257  }
1258  } else {
1259  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1260  return "";
1261  }
1262  }
1263 
1275  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1276  {
1277  global $conf, $langs;
1278 
1279  $result = 0;
1280  $includedocgeneration = 0;
1281 
1282  $langs->load("partnership");
1283 
1284  if (!dol_strlen($modele)) {
1285  $modele = 'standard_partnership';
1286 
1287  if (!empty($this->model_pdf)) {
1288  $modele = $this->model_pdf;
1289  } elseif (!empty($conf->global->PARTNERSHIP_ADDON_PDF)) {
1290  $modele = $conf->global->PARTNERSHIP_ADDON_PDF;
1291  }
1292  }
1293 
1294  $modelpath = "core/modules/partnership/doc/";
1295 
1296  if ($includedocgeneration && !empty($modele)) {
1297  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1298  }
1299 
1300  return $result;
1301  }
1302 
1310  public function doScheduledJob()
1311  {
1312  global $conf, $langs;
1313 
1314  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1315 
1316  $error = 0;
1317  $this->output = '';
1318  $this->error = '';
1319 
1320  dol_syslog(__METHOD__, LOG_DEBUG);
1321 
1322  $now = dol_now();
1323 
1324  $this->db->begin();
1325 
1326  // ...
1327 
1328  $this->db->commit();
1329 
1330  return $error;
1331  }
1332 
1340  public function getKanbanView($option = '', $arraydata = null)
1341  {
1342  $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1343 
1344  $return = '<div class="box-flex-item box-flex-grow-zero">';
1345  $return .= '<div class="info-box info-box-sm">';
1346  $return .= '<span class="info-box-icon bg-infobox-action">';
1347  $return .= img_picto('', $this->picto);
1348  $return .= '</span>';
1349  $return .= '<div class="info-box-content">';
1350  $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1351  $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1352  if (property_exists($this, 'label')) {
1353  $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
1354  }
1355  if (method_exists($this, 'getLibStatut')) {
1356  $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).'</div>';
1357  }
1358  $return .= '</div>';
1359  $return .= '</div>';
1360  $return .= '</div>';
1361 
1362  return $return;
1363  }
1364 }
1365 
1366 
1367 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1368 
1373 {
1374  // To complete with content of an object PartnershipLine
1375  // We should have a field rowid, fk_partnership and position
1376 
1380  public $isextrafieldmanaged = 0;
1381 
1387  public function __construct(DoliDB $db)
1388  {
1389  $this->db = $db;
1390  }
1391 }
$object ref
Definition: info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
getFieldList($alias='')
Function to concat keys of fields.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in 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.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='')
Load object in memory from the database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class for Partnership.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
__construct(DoliDB $db)
Constructor.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
validate($user, $notrigger=0)
Validate object.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
createFromClone(User $user, $fromid)
Clone an object into another one.
setDraft($user, $notrigger=0)
Set draft status.
refused($user, $reasondeclinenote='', $notrigger=0)
Set refused status.
update(User $user, $notrigger=false)
Update object into database.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
fetch($id, $ref=null, $fk_member=null, $fk_soc=null)
Load object in memory from the database Get object from database.
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
getLinesArray()
Create an array of lines.
getTooltipContentArray($params)
getTooltipContentArray
cancel($user, $notrigger=0)
Set cancel status.
reopen($user, $notrigger=0)
Set back to validated status.
fetchLines()
Load object lines in memory from the database.
create(User $user, $notrigger=false)
Create object into database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
getLibStatut($mode=0)
Return the label of the status.
LibStatut($status, $mode=0)
Return the status.
info($id)
Load the info information in the object.
approve($user, $notrigger=0)
Approve object.
Class PartnershipLine.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
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.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.