dolibarr  9.0.0
don.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@zendsi.com>
7  * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
30 
31 
35 class Don extends CommonObject
36 {
40  public $element='don';
41 
45  public $table_element='don';
46 
50  public $fk_element = 'fk_donation';
51 
56  public $ismultientitymanaged = 1;
57 
61  public $picto = 'generic';
62 
63  public $date;
64  public $amount;
65  public $societe;
66 
70  public $address;
71 
72  public $zip;
73  public $town;
74  public $email;
75  public $public;
76 
80  public $fk_project;
81 
85  public $fk_typepayment;
86 
87  public $num_payment;
88  public $date_valid;
89  public $modepaymentid = 0;
90 
91  public $labelstatut;
92  public $labelstatutshort;
93 
94 
100  function __construct($db)
101  {
102  $this->db = $db;
103  }
104 
105 
112  function getLibStatut($mode=0)
113  {
114  return $this->LibStatut($this->statut,$mode);
115  }
116 
117  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
125  function LibStatut($statut,$mode=0)
126  {
127  // phpcs:enable
128  if (empty($this->labelstatut) || empty($this->labelstatutshort))
129  {
130  global $langs;
131  $langs->load("donations");
132  $this->labelstatut[-1]=$langs->trans("Canceled");
133  $this->labelstatut[0]=$langs->trans("DonationStatusPromiseNotValidated");
134  $this->labelstatut[1]=$langs->trans("DonationStatusPromiseValidated");
135  $this->labelstatut[2]=$langs->trans("DonationStatusPaid");
136  $this->labelstatutshort[-1]=$langs->trans("Canceled");
137  $this->labelstatutshort[0]=$langs->trans("DonationStatusPromiseNotValidatedShort");
138  $this->labelstatutshort[1]=$langs->trans("DonationStatusPromiseValidatedShort");
139  $this->labelstatutshort[2]=$langs->trans("DonationStatusPaidShort");
140  }
141 
142  if ($mode == 0)
143  {
144  return $this->labelstatut[$statut];
145  }
146  elseif ($mode == 1)
147  {
148  return $this->labelstatutshort[$statut];
149  }
150  elseif ($mode == 2)
151  {
152  if ($statut == -1) return img_picto($this->labelstatut[$statut],'statut5').' '.$this->labelstatutshort[$statut];
153  elseif ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0').' '.$this->labelstatutshort[$statut];
154  elseif ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1').' '.$this->labelstatutshort[$statut];
155  elseif ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6').' '.$this->labelstatutshort[$statut];
156  }
157  elseif ($mode == 3)
158  {
159  if ($statut == -1) return img_picto($this->labelstatut[$statut],'statut5');
160  elseif ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0');
161  elseif ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1');
162  elseif ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6');
163  }
164  elseif ($mode == 4)
165  {
166  if ($statut == -1) return img_picto($this->labelstatut[$statut],'statut5').' '.$this->labelstatut[$statut];
167  elseif ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0').' '.$this->labelstatut[$statut];
168  elseif ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1').' '.$this->labelstatut[$statut];
169  elseif ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6').' '.$this->labelstatut[$statut];
170  }
171  elseif ($mode == 5)
172  {
173  if ($statut == -1) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut5');
174  elseif ($statut == 0) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut0');
175  elseif ($statut == 1) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut1');
176  elseif ($statut == 2) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut6');
177  }
178  elseif ($mode == 6)
179  {
180  if ($statut == -1) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut5');
181  elseif ($statut == 0) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut0');
182  elseif ($statut == 1) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut1');
183  elseif ($statut == 2) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut6');
184  }
185  }
186 
187 
195  function initAsSpecimen()
196  {
197  global $conf, $user,$langs;
198 
199  $now = dol_now();
200 
201  // Charge tableau des id de societe socids
202  $socids = array();
203 
204  $sql = "SELECT rowid";
205  $sql.= " FROM ".MAIN_DB_PREFIX."societe";
206  $sql.= " WHERE client IN (1, 3)";
207  $sql.= " AND entity = ".$conf->entity;
208  $sql.= " LIMIT 10";
209 
210  $resql = $this->db->query($sql);
211  if ($resql)
212  {
213  $num_socs = $this->db->num_rows($resql);
214  $i = 0;
215  while ($i < $num_socs)
216  {
217  $i++;
218 
219  $row = $this->db->fetch_row($resql);
220  $socids[$i] = $row[0];
221  }
222  }
223 
224  // Initialise parametres
225  $this->id=0;
226  $this->ref = 'SPECIMEN';
227  $this->specimen=1;
228  $this->lastname = 'Doe';
229  $this->firstname = 'John';
230  $this->socid = 1;
231  $this->date = $now;
232  $this->date_valid = $now;
233  $this->amount = 100;
234  $this->public = 1;
235  $this->societe = 'The Company';
236  $this->address = 'Twist road';
237  $this->zip = '99999';
238  $this->town = 'Town';
239  $this->note_private='Private note';
240  $this->note_public='Public note';
241  $this->email='email@email.com';
242  $this->note='';
243  $this->statut=1;
244  }
245 
246 
254  function check($minimum=0)
255  {
256  global $langs;
257  $langs->load('main');
258  $langs->load('companies');
259 
260  $error_string = array();
261  $err = 0;
262 
263  if (dol_strlen(trim($this->societe)) == 0)
264  {
265  if ((dol_strlen(trim($this->lastname)) + dol_strlen(trim($this->firstname))) == 0)
266  {
267  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Company').'/'.$langs->trans('Firstname').'-'.$langs->trans('Lastname'));
268  $err++;
269  }
270  }
271 
272  if (dol_strlen(trim($this->address)) == 0)
273  {
274  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Address'));
275  $err++;
276  }
277 
278  if (dol_strlen(trim($this->zip)) == 0)
279  {
280  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Zip'));
281  $err++;
282  }
283 
284  if (dol_strlen(trim($this->town)) == 0)
285  {
286  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Town'));
287  $err++;
288  }
289 
290  if (dol_strlen(trim($this->email)) == 0)
291  {
292  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('EMail'));
293  $err++;
294  }
295 
296  $this->amount = trim($this->amount);
297 
298  $map = range(0,9);
299  $len=dol_strlen($this->amount);
300  for ($i = 0; $i < $len; $i++)
301  {
302  if (!isset($map[substr($this->amount, $i, 1)] ))
303  {
304  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Amount'));
305  $err++;
306  $amount_invalid = 1;
307  break;
308  }
309  }
310 
311  if (! $amount_invalid)
312  {
313  if ($this->amount == 0)
314  {
315  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Amount'));
316  $err++;
317  }
318  else
319  {
320  if ($this->amount < $minimum && $minimum > 0)
321  {
322  $error_string[] = $langs->trans('MinimumAmount',$langs->trans('$minimum'));
323  $err++;
324  }
325  }
326  }
327 
328  if ($err)
329  {
330  $this->errors = $error_string;
331  return 0;
332  }
333  else
334  {
335  return 1;
336  }
337  }
338 
347  function create($user, $notrigger=0)
348  {
349  global $conf, $langs;
350 
351  $error = 0;
352  $ret = 0;
353  $now=dol_now();
354 
355  // Clean parameters
356  $this->address=($this->address>0?$this->address:$this->address);
357  $this->zip=($this->zip>0?$this->zip:$this->zip);
358  $this->town=($this->town>0?$this->town:$this->town);
359  $this->country_id=($this->country_id>0?$this->country_id:$this->country_id);
360  $this->country=($this->country?$this->country:$this->country);
361 
362  $this->db->begin();
363 
364  $sql = "INSERT INTO ".MAIN_DB_PREFIX."don (";
365  $sql.= "datec";
366  $sql.= ", entity";
367  $sql.= ", amount";
368  $sql.= ", fk_payment";
369  $sql.= ", firstname";
370  $sql.= ", lastname";
371  $sql.= ", societe";
372  $sql.= ", address";
373  $sql.= ", zip";
374  $sql.= ", town";
375  $sql.= ", fk_country";
376  $sql.= ", public";
377  $sql.= ", fk_projet";
378  $sql.= ", note_private";
379  $sql.= ", note_public";
380  $sql.= ", fk_user_author";
381  $sql.= ", fk_user_valid";
382  $sql.= ", datedon";
383  $sql.= ", email";
384  $sql.= ", phone";
385  $sql.= ", phone_mobile";
386  $sql.= ") VALUES (";
387  $sql.= " '".$this->db->idate($now)."'";
388  $sql.= ", ".$conf->entity;
389  $sql.= ", ".price2num($this->amount);
390  $sql.= ", ".($this->modepaymentid?$this->modepaymentid:"null");
391  $sql.= ", '".$this->db->escape($this->firstname)."'";
392  $sql.= ", '".$this->db->escape($this->lastname)."'";
393  $sql.= ", '".$this->db->escape($this->societe)."'";
394  $sql.= ", '".$this->db->escape($this->address)."'";
395  $sql.= ", '".$this->db->escape($this->zip)."'";
396  $sql.= ", '".$this->db->escape($this->town)."'";
397  $sql.= ", ".($this->country_id > 0 ? $this->country_id : '0');
398  $sql.= ", ".((int) $this->public);
399  $sql.= ", ".($this->fk_project > 0?$this->fk_project:"null");
400  $sql.= ", ".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL");
401  $sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
402  $sql.= ", ".$user->id;
403  $sql.= ", null";
404  $sql.= ", '".$this->db->idate($this->date)."'";
405  $sql.= ", '".$this->db->escape($this->email)."'";
406  $sql.= ", '".$this->db->escape($this->phone)."'";
407  $sql.= ", '".$this->db->escape($this->phone_mobile)."'";
408  $sql.= ")";
409 
410  $resql = $this->db->query($sql);
411  if ($resql)
412  {
413  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."don");
414  $ret = $this->id;
415 
416  if (!$notrigger)
417  {
418  // Call trigger
419  $result=$this->call_trigger('DON_CREATE',$user);
420  if ($result < 0) { $error++; }
421  // End call triggers
422  }
423  }
424  else
425  {
426  $this->error = $this->db->lasterror();
427  $this->errno = $this->db->lasterrno();
428  $error++;
429  }
430 
431  // Update extrafield
432  if (! $error) {
433  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
434  {
435  $result=$this->insertExtraFields();
436  if ($result < 0)
437  {
438  $error++;
439  }
440  }
441  }
442 
443  if (!$error && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
444  {
445  //$res = $this->setValid($user);
446  //if ($res < 0) $error++;
447  }
448 
449  if (!$error)
450  {
451  $this->db->commit();
452  return $ret;
453  }
454  else
455  {
456  $this->db->rollback();
457  return -1;
458  }
459  }
460 
468  function update($user, $notrigger=0)
469  {
470  global $langs, $conf;
471 
472  $error=0;
473 
474  // Clean parameters
475  $this->address=($this->address>0?$this->address:$this->address);
476  $this->zip=($this->zip>0?$this->zip:$this->zip);
477  $this->town=($this->town>0?$this->town:$this->town);
478  $this->country_id=($this->country_id>0?$this->country_id:$this->country_id);
479  $this->country=($this->country?$this->country:$this->country);
480 
481  $this->db->begin();
482 
483  $sql = "UPDATE ".MAIN_DB_PREFIX."don SET ";
484  $sql .= "amount = " . price2num($this->amount);
485  $sql .= ",fk_payment = ".($this->modepaymentid?$this->modepaymentid:"null");
486  $sql .= ",firstname = '".$this->db->escape($this->firstname)."'";
487  $sql .= ",lastname='".$this->db->escape($this->lastname)."'";
488  $sql .= ",societe='".$this->db->escape($this->societe)."'";
489  $sql .= ",address='".$this->db->escape($this->address)."'";
490  $sql .= ",zip='".$this->db->escape($this->zip)."'";
491  $sql .= ",town='".$this->db->escape($this->town)."'";
492  $sql .= ",fk_country = ".$this->country_id;
493  $sql .= ",public=".$this->public;
494  $sql .= ",fk_projet=".($this->fk_project>0?$this->fk_project:'null');
495  $sql .= ",note_private=".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL");
496  $sql .= ",note_public=".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
497  $sql .= ",datedon='".$this->db->idate($this->date)."'";
498  $sql .= ",date_valid=".($this->date_valid?"'".$this->db->idate($this->date)."'":"null");
499  $sql .= ",email='".$this->db->escape($this->email)."'";
500  $sql .= ",phone='".$this->db->escape($this->phone)."'";
501  $sql .= ",phone_mobile='".$this->db->escape($this->phone_mobile)."'";
502  $sql .= ",fk_statut=".$this->statut;
503  $sql .= " WHERE rowid = ".$this->id;
504 
505  dol_syslog(get_class($this)."::Update", LOG_DEBUG);
506  $resql=$this->db->query($sql);
507  if ($resql)
508  {
509  if (!$notrigger)
510  {
511  // Call trigger
512  $result=$this->call_trigger('DON_MODIFY',$user);
513  if ($result < 0) { $error++; }
514  // End call triggers
515  }
516 
517  // Update extrafield
518  if (! $error)
519  {
520  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
521  {
522  $result=$this->insertExtraFields();
523  if ($result < 0)
524  {
525  $error++;
526  }
527  }
528  }
529 
530  if (! $error )
531  {
532  $this->db->commit();
533  $result = 1;
534  }
535  else
536  {
537  $this->db->rollback();
538  $result = -1;
539  }
540  }
541  else
542  {
543  $this->error = $this->db->lasterror();
544  $this->errors[] = $this->error;
545  $this->db->rollback();
546  dol_syslog(get_class($this)."::Update error -2 " . $this->error, LOG_ERR);
547  $result = -2;
548  }
549  return $result;
550  }
551 
559  function delete($user, $notrigger=0)
560  {
561  global $user, $conf, $langs;
562  require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
563 
564  $error = 0;
565 
566  $this->db->begin();
567 
568  if (! $error)
569  {
570  if (!$notrigger)
571  {
572  // Call trigger
573  $result=$this->call_trigger('DON_DELETE',$user);
574 
575  if ($result < 0) {
576  $error++;
577  }
578  // End call triggers
579  }
580  }
581 
582  // Delete donation
583  if (! $error)
584  {
585  $sql = "DELETE FROM " . MAIN_DB_PREFIX . "don_extrafields";
586  $sql.= " WHERE fk_object=" . $this->id;
587 
588  $resql = $this->db->query($sql);
589  if (! $resql)
590  {
591  $this->errors[] = $this->db->lasterror();
592  $error++;
593  }
594  }
595 
596  if (! $error)
597  {
598  $sql = "DELETE FROM " . MAIN_DB_PREFIX . "don";
599  $sql.= " WHERE rowid=" . $this->id;
600 
601  $resql = $this->db->query($sql);
602  if (!$resql)
603  {
604  $this->errors[] = $this->db->lasterror();
605  $error++;
606  }
607  }
608 
609  if (! $error)
610  {
611  $this->db->commit();
612  return 1;
613  }
614  else
615  {
616  foreach($this->errors as $errmsg)
617  {
618  dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR);
619  $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
620  }
621  dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR);
622  $this->db->rollback();
623  return -1;
624  }
625  }
626 
634  function fetch($id, $ref='')
635  {
636  global $conf;
637 
638  $sql = "SELECT d.rowid, d.datec, d.date_valid, d.tms as datem, d.datedon,";
639  $sql.= " d.firstname, d.lastname, d.societe, d.amount, d.fk_statut, d.address, d.zip, d.town, ";
640  $sql.= " d.fk_country, d.country as country_olddata, d.public, d.amount, d.fk_payment, d.paid, d.note_private, d.note_public, d.email, d.phone, ";
641  $sql.= " d.phone_mobile, d.fk_projet as fk_project, d.model_pdf,";
642  $sql.= " p.ref as project_ref,";
643  $sql.= " cp.libelle as payment_label, cp.code as payment_code,";
644  $sql.= " c.code as country_code, c.label as country";
645  $sql.= " FROM ".MAIN_DB_PREFIX."don as d";
646  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_projet";
647  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_payment";
648  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.fk_country = c.rowid";
649  $sql.= " WHERE d.entity IN (".getEntity('donation').")";
650  if (! empty($id))
651  {
652  $sql.= " AND d.rowid=".$id;
653  }
654  else if (! empty($ref))
655  {
656  $sql.= " AND d.ref='".$this->db->escape($ref)."'";
657  }
658 
659  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
660  $resql=$this->db->query($sql);
661  if ($resql)
662  {
663  if ($this->db->num_rows($resql))
664  {
665  $obj = $this->db->fetch_object($resql);
666 
667  $this->id = $obj->rowid;
668  $this->ref = $obj->rowid;
669  $this->datec = $this->db->jdate($obj->datec);
670  $this->date_valid = $this->db->jdate($obj->date_valid);
671  $this->datem = $this->db->jdate($obj->datem);
672  $this->date = $this->db->jdate($obj->datedon);
673  $this->firstname = $obj->firstname;
674  $this->lastname = $obj->lastname;
675  $this->societe = $obj->societe;
676  $this->statut = $obj->fk_statut;
677  $this->address = $obj->address;
678  $this->town = $obj->town;
679  $this->zip = $obj->zip;
680  $this->town = $obj->town;
681  $this->country_id = $obj->fk_country;
682  $this->country_code = $obj->country_code;
683  $this->country = $obj->country;
684  $this->country_olddata= $obj->country_olddata; // deprecated
685  $this->email = $obj->email;
686  $this->phone = $obj->phone;
687  $this->phone_mobile = $obj->phone_mobile;
688  $this->project = $obj->project_ref;
689  $this->fk_projet = $obj->fk_project; // deprecated
690  $this->fk_project = $obj->fk_project;
691  $this->public = $obj->public;
692  $this->modepaymentid = $obj->fk_payment;
693  $this->modepaymentcode = $obj->payment_code;
694  $this->modepayment = $obj->payment_label;
695  $this->paid = $obj->paid;
696  $this->amount = $obj->amount;
697  $this->note_private = $obj->note_private;
698  $this->note_public = $obj->note_public;
699  $this->modelpdf = $obj->model_pdf;
700 
701  // Retreive all extrafield
702  // fetch optionals attributes and labels
703  $this->fetch_optionals();
704  }
705  return 1;
706  }
707  else
708  {
709  dol_print_error($this->db);
710  return -1;
711  }
712  }
713 
721  function setValid($user, $notrigger=0)
722  {
723  return $this->valid_promesse($this->id, $user->id, $notrigger);
724  }
725 
726  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
735  function valid_promesse($id, $userid, $notrigger=0)
736  {
737  // phpcs:enable
738  global $langs, $user;
739 
740  $error=0;
741 
742  $this->db->begin();
743 
744  $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = ".$userid." WHERE rowid = ".$id." AND fk_statut = 0";
745 
746  $resql=$this->db->query($sql);
747  if ($resql)
748  {
749  if ($this->db->affected_rows($resql))
750  {
751  if (!$notrigger)
752  {
753  // Call trigger
754  $result=$this->call_trigger('DON_VALIDATE',$user);
755  if ($result < 0) { $error++; }
756  // End call triggers
757  }
758  }
759  }
760  else
761  {
762  $error++;
763  $this->error = $this->db->lasterror();
764  }
765 
766  if (!$error)
767  {
768  $this->db->commit();
769  return 1;
770  }
771  else
772  {
773  $this->db->rollback();
774  return -1;
775  }
776  }
777 
778  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
786  function set_paid($id, $modepayment=0)
787  {
788  // phpcs:enable
789  $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2";
790  if ($modepayment)
791  {
792  $sql .= ", fk_payment=".$modepayment;
793  }
794  $sql .= " WHERE rowid = ".$id." AND fk_statut = 1";
795 
796  $resql=$this->db->query($sql);
797  if ($resql)
798  {
799  if ($this->db->affected_rows($resql))
800  {
801  return 1;
802  }
803  else
804  {
805  return 0;
806  }
807  }
808  else
809  {
810  dol_print_error($this->db);
811  return -1;
812  }
813  }
814 
815  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
822  function set_cancel($id)
823  {
824  // phpcs:enable
825  $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = -1 WHERE rowid = ".$id;
826 
827  $resql=$this->db->query($sql);
828  if ($resql)
829  {
830  if ( $this->db->affected_rows($resql) )
831  {
832  return 1;
833  }
834  else
835  {
836  return 0;
837  }
838  }
839  else
840  {
841  dol_print_error($this->db);
842  return -1;
843  }
844  }
845 
846  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
853  function sum_donations($param)
854  {
855  // phpcs:enable
856  global $conf;
857 
858  $result=0;
859 
860  $sql = "SELECT sum(amount) as total";
861  $sql.= " FROM ".MAIN_DB_PREFIX."don";
862  $sql.= " WHERE fk_statut = ".$param;
863  $sql.= " AND entity = ".$conf->entity;
864 
865  $resql=$this->db->query($sql);
866  if ($resql)
867  {
868  $obj = $this->db->fetch_object($resql);
869  $result=$obj->total;
870  }
871 
872  return $result;
873  }
874 
875  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
881  function load_state_board()
882  {
883  // phpcs:enable
884  global $conf;
885 
886  $this->nb=array();
887 
888  $sql = "SELECT count(d.rowid) as nb";
889  $sql.= " FROM ".MAIN_DB_PREFIX."don as d";
890  $sql.= " WHERE d.fk_statut > 0";
891  $sql.= " AND d.entity IN (".getEntity('donation').")";
892 
893  $resql=$this->db->query($sql);
894  if ($resql)
895  {
896  while ($obj=$this->db->fetch_object($resql))
897  {
898  $this->nb["donations"]=$obj->nb;
899  }
900  $this->db->free($resql);
901  return 1;
902  }
903  else
904  {
905  dol_print_error($this->db);
906  $this->error=$this->db->error();
907  return -1;
908  }
909  }
910 
918  function getNomUrl($withpicto=0, $notooltip=0)
919  {
920  global $langs;
921 
922  $result='';
923  $label=$langs->trans("ShowDonation").': '.$this->id;
924 
925  $linkstart = '<a href="'.DOL_URL_ROOT.'/don/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
926  $linkend='</a>';
927 
928  $result .= $linkstart;
929  if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
930  if ($withpicto != 2) $result.= $this->ref;
931  $result .= $linkend;
932 
933  return $result;
934  }
935 
942  function info($id)
943  {
944  $sql = 'SELECT d.rowid, d.datec, d.fk_user_author, d.fk_user_valid,';
945  $sql.= ' d.tms';
946  $sql.= ' FROM '.MAIN_DB_PREFIX.'don as d';
947  $sql.= ' WHERE d.rowid = '.$id;
948 
949  dol_syslog(get_class($this).'::info', LOG_DEBUG);
950  $result = $this->db->query($sql);
951 
952  if ($result)
953  {
954  if ($this->db->num_rows($result))
955  {
956  $obj = $this->db->fetch_object($result);
957  $this->id = $obj->rowid;
958  if ($obj->fk_user_author)
959  {
960  $cuser = new User($this->db);
961  $cuser->fetch($obj->fk_user_author);
962  $this->user_creation = $cuser;
963  }
964  if ($obj->fk_user_valid)
965  {
966  $vuser = new User($this->db);
967  $vuser->fetch($obj->fk_user_valid);
968  $this->user_modification = $vuser;
969  }
970  $this->date_creation = $this->db->jdate($obj->datec);
971  $this->date_modification = $this->db->jdate($obj->tms);
972  }
973  $this->db->free($result);
974  }
975  else
976  {
977  dol_print_error($this->db);
978  }
979  }
980 
981 
992  public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
993  {
994  global $conf,$langs;
995 
996  $langs->load("bills");
997 
998  if (! dol_strlen($modele)) {
999 
1000  $modele = 'html_cerfafr';
1001 
1002  if ($this->modelpdf) {
1003  $modele = $this->modelpdf;
1004  } elseif (! empty($conf->global->DON_ADDON_MODEL)) {
1005  $modele = $conf->global->DON_ADDON_MODEL;
1006  }
1007  }
1008 
1009  $modelpath = "core/modules/dons/";
1010 
1011  // TODO Restore use of commonGenerateDocument instead of dedicated code here
1012  //return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1013 
1014  // Increase limit for PDF build
1015  $err=error_reporting();
1016  error_reporting(0);
1017  @set_time_limit(120);
1018  error_reporting($err);
1019 
1020  $srctemplatepath='';
1021 
1022  // If selected modele is a filename template (then $modele="modelname:filename")
1023  $tmp=explode(':',$modele,2);
1024  if (! empty($tmp[1]))
1025  {
1026  $modele=$tmp[0];
1027  $srctemplatepath=$tmp[1];
1028  }
1029 
1030  // Search template files
1031  $file=''; $classname=''; $filefound=0;
1032  $dirmodels=array('/');
1033  if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
1034  foreach($dirmodels as $reldir)
1035  {
1036  foreach(array('html','doc','pdf') as $prefix)
1037  {
1038  $file = $prefix."_".preg_replace('/^html_/','',$modele).".modules.php";
1039 
1040  // On verifie l'emplacement du modele
1041  $file=dol_buildpath($reldir."core/modules/dons/".$file,0);
1042  if (file_exists($file))
1043  {
1044  $filefound=1;
1045  $classname=$prefix.'_'.$modele;
1046  break;
1047  }
1048  }
1049  if ($filefound) break;
1050  }
1051 
1052  // Charge le modele
1053  if ($filefound)
1054  {
1055  require_once $file;
1056 
1057  $object=$this;
1058 
1059  $classname = $modele;
1060  $obj = new $classname($this->db);
1061 
1062  // We save charset_output to restore it because write_file can change it if needed for
1063  // output format that does not support UTF8.
1064  $sav_charset_output=$outputlangs->charset_output;
1065  if ($obj->write_file($object,$outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
1066  {
1067  $outputlangs->charset_output=$sav_charset_output;
1068 
1069  // we delete preview files
1070  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1071  dol_delete_preview($object);
1072  return 1;
1073  }
1074  else
1075  {
1076  $outputlangs->charset_output=$sav_charset_output;
1077  dol_syslog("Erreur dans don_create");
1078  dol_print_error($this->db,$obj->error);
1079  return 0;
1080  }
1081  }
1082  else
1083  {
1084  print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
1085  return 0;
1086  }
1087  }
1088 }
print
Draft customers invoices.
Definition: index.php:91
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
update($user, $notrigger=0)
Update a donation record.
Definition: don.class.php:468
valid_promesse($id, $userid, $notrigger=0)
Validate a promise of donation.
Definition: don.class.php:735
set_cancel($id)
Set donation to status cancelled.
Definition: don.class.php:822
if(! empty($search_group)) natural_search(array("g.nom" g note
Definition: list.php:123
set_paid($id, $modepayment=0)
Classify the donation as paid, the donation was received.
Definition: don.class.php:786
dol_delete_preview($object)
Delete all preview files linked to object instance.
Definition: files.lib.php:1324
Class to manage Dolibarr users.
Definition: user.class.php:41
load_state_board()
Charge indicateurs this->nb pour le tableau de bord.
Definition: don.class.php:881
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
getNomUrl($withpicto=0, $notooltip=0)
Return clicable name (with picto eventually)
Definition: don.class.php:918
getLibStatut($mode=0)
Retourne le libelle du statut d&#39;un don (brouillon, validee, abandonnee, payee)
Definition: don.class.php:112
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
info($id)
Information on record.
Definition: don.class.php:942
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
Definition: don.class.php:992
__construct($db)
Constructor.
Definition: don.class.php:100
initAsSpecimen()
Initialise an instance with random values.
Definition: don.class.php:195
create($user, $notrigger=0)
Create donation record into database.
Definition: don.class.php:347
setValid($user, $notrigger=0)
Validate a intervention.
Definition: don.class.php:721
dol_now($mode='gmt')
Return date for now.
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...
Class to manage donations.
Definition: don.class.php:35
LibStatut($statut, $mode=0)
Renvoi le libelle d&#39;un statut donne.
Definition: don.class.php:125
fetch($id, $ref='')
Load donation from database.
Definition: don.class.php:634
check($minimum=0)
Check params and init ->errors array.
Definition: don.class.php:254
call_trigger($trigger_name, $user)
Call trigger based on this instance.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
sum_donations($param)
Sum of donations.
Definition: don.class.php:853
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)