dolibarr  7.0.0-beta
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@capnetworks.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 {
37  public $element='don'; // Id that identify managed objects
38  public $table_element='don'; // Name of table without prefix where object is stored
39  public $fk_element = 'fk_donation';
40  public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
41  var $picto = 'generic';
42 
43  var $date;
44  var $amount;
45  var $societe;
46  var $address;
47  var $zip;
48  var $town;
49  var $email;
50  var $public;
51  var $fk_project;
52  var $fk_typepayment;
53  var $num_payment;
54  var $date_valid;
55 
61 
67  function __construct($db)
68  {
69  global $langs;
70 
71  $this->db = $db;
72  $this->modepaiementid = 0;
73 
74  $langs->load("donations");
75  $this->labelstatut[-1]=$langs->trans("Canceled");
76  $this->labelstatut[0]=$langs->trans("DonationStatusPromiseNotValidated");
77  $this->labelstatut[1]=$langs->trans("DonationStatusPromiseValidated");
78  $this->labelstatut[2]=$langs->trans("DonationStatusPaid");
79  $this->labelstatutshort[-1]=$langs->trans("Canceled");
80  $this->labelstatutshort[0]=$langs->trans("DonationStatusPromiseNotValidatedShort");
81  $this->labelstatutshort[1]=$langs->trans("DonationStatusPromiseValidatedShort");
82  $this->labelstatutshort[2]=$langs->trans("DonationStatusPaidShort");
83  }
84 
85 
92  function getLibStatut($mode=0)
93  {
94  return $this->LibStatut($this->statut,$mode);
95  }
96 
104  function LibStatut($statut,$mode=0)
105  {
106  global $langs;
107 
108  if ($mode == 0)
109  {
110  return $this->labelstatut[$statut];
111  }
112  if ($mode == 1)
113  {
114  return $this->labelstatutshort[$statut];
115  }
116  if ($mode == 2)
117  {
118  if ($statut == -1) return img_picto($this->labelstatut[$statut],'statut5').' '.$this->labelstatutshort[$statut];
119  if ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0').' '.$this->labelstatutshort[$statut];
120  if ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1').' '.$this->labelstatutshort[$statut];
121  if ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6').' '.$this->labelstatutshort[$statut];
122  }
123  if ($mode == 3)
124  {
125  if ($statut == -1) return img_picto($this->labelstatut[$statut],'statut5');
126  if ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0');
127  if ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1');
128  if ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6');
129  }
130  if ($mode == 4)
131  {
132  if ($statut == -1) return img_picto($this->labelstatut[$statut],'statut5').' '.$this->labelstatut[$statut];
133  if ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0').' '.$this->labelstatut[$statut];
134  if ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1').' '.$this->labelstatut[$statut];
135  if ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6').' '.$this->labelstatut[$statut];
136  }
137  if ($mode == 5)
138  {
139  if ($statut == -1) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut5');
140  if ($statut == 0) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut0');
141  if ($statut == 1) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut1');
142  if ($statut == 2) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut6');
143  }
144  if ($mode == 6)
145  {
146  if ($statut == -1) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut5');
147  if ($statut == 0) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut0');
148  if ($statut == 1) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut1');
149  if ($statut == 2) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut6');
150  }
151  }
152 
153 
161  function initAsSpecimen()
162  {
163  global $conf, $user,$langs;
164 
165  $now = dol_now();
166 
167  // Charge tableau des id de societe socids
168  $socids = array();
169 
170  $sql = "SELECT rowid";
171  $sql.= " FROM ".MAIN_DB_PREFIX."societe";
172  $sql.= " WHERE client IN (1, 3)";
173  $sql.= " AND entity = ".$conf->entity;
174  $sql.= " LIMIT 10";
175 
176  $resql = $this->db->query($sql);
177  if ($resql)
178  {
179  $num_socs = $this->db->num_rows($resql);
180  $i = 0;
181  while ($i < $num_socs)
182  {
183  $i++;
184 
185  $row = $this->db->fetch_row($resql);
186  $socids[$i] = $row[0];
187  }
188  }
189 
190  // Initialise parametres
191  $this->id=0;
192  $this->ref = 'SPECIMEN';
193  $this->specimen=1;
194  $this->lastname = 'Doe';
195  $this->firstname = 'John';
196  $this->socid = 1;
197  $this->date = $now;
198  $this->date_valid = $now;
199  $this->amount = 100;
200  $this->public = 1;
201  $this->societe = 'The Company';
202  $this->address = 'Twist road';
203  $this->zip = '99999';
204  $this->town = 'Town';
205  $this->note_private='Private note';
206  $this->note_public='Public note';
207  $this->email='email@email.com';
208  $this->note='';
209  $this->statut=1;
210  }
211 
212 
220  function check($minimum=0)
221  {
222  global $langs;
223  $langs->load('main');
224  $langs->load('companies');
225 
226  $error_string = array();
227  $err = 0;
228 
229  if (dol_strlen(trim($this->societe)) == 0)
230  {
231  if ((dol_strlen(trim($this->lastname)) + dol_strlen(trim($this->firstname))) == 0)
232  {
233  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Company').'/'.$langs->trans('Firstname').'-'.$langs->trans('Lastname'));
234  $err++;
235  }
236  }
237 
238  if (dol_strlen(trim($this->address)) == 0)
239  {
240  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Address'));
241  $err++;
242  }
243 
244  if (dol_strlen(trim($this->zip)) == 0)
245  {
246  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Zip'));
247  $err++;
248  }
249 
250  if (dol_strlen(trim($this->town)) == 0)
251  {
252  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Town'));
253  $err++;
254  }
255 
256  if (dol_strlen(trim($this->email)) == 0)
257  {
258  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('EMail'));
259  $err++;
260  }
261 
262  $this->amount = trim($this->amount);
263 
264  $map = range(0,9);
265  $len=dol_strlen($this->amount);
266  for ($i = 0; $i < $len; $i++)
267  {
268  if (!isset($map[substr($this->amount, $i, 1)] ))
269  {
270  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Amount'));
271  $err++;
272  $amount_invalid = 1;
273  break;
274  }
275  }
276 
277  if (! $amount_invalid)
278  {
279  if ($this->amount == 0)
280  {
281  $error_string[] = $langs->trans('ErrorFieldRequired',$langs->trans('Amount'));
282  $err++;
283  }
284  else
285  {
286  if ($this->amount < $minimum && $minimum > 0)
287  {
288  $error_string[] = $langs->trans('MinimumAmount',$langs->trans('$minimum'));
289  $err++;
290  }
291  }
292  }
293 
294  if ($err)
295  {
296  $this->errors = $error_string;
297  return 0;
298  }
299  else
300  {
301  return 1;
302  }
303  }
304 
313  function create($user, $notrigger=0)
314  {
315  global $conf, $langs;
316 
317  $error = 0;
318  $ret = 0;
319  $now=dol_now();
320 
321  // Clean parameters
322  $this->address=($this->address>0?$this->address:$this->address);
323  $this->zip=($this->zip>0?$this->zip:$this->zip);
324  $this->town=($this->town>0?$this->town:$this->town);
325  $this->country_id=($this->country_id>0?$this->country_id:$this->country_id);
326  $this->country=($this->country?$this->country:$this->country);
327 
328  $this->db->begin();
329 
330  $sql = "INSERT INTO ".MAIN_DB_PREFIX."don (";
331  $sql.= "datec";
332  $sql.= ", entity";
333  $sql.= ", amount";
334  $sql.= ", fk_payment";
335  $sql.= ", firstname";
336  $sql.= ", lastname";
337  $sql.= ", societe";
338  $sql.= ", address";
339  $sql.= ", zip";
340  $sql.= ", town";
341  // $sql.= ", country"; -- Deprecated
342  $sql.= ", fk_country";
343  $sql.= ", public";
344  $sql.= ", fk_projet";
345  $sql.= ", note_private";
346  $sql.= ", note_public";
347  $sql.= ", fk_user_author";
348  $sql.= ", fk_user_valid";
349  $sql.= ", datedon";
350  $sql.= ", email";
351  $sql.= ", phone";
352  $sql.= ", phone_mobile";
353  $sql.= ") VALUES (";
354  $sql.= " '".$this->db->idate($now)."'";
355  $sql.= ", ".$conf->entity;
356  $sql.= ", ".price2num($this->amount);
357  $sql.= ", ".($this->modepaiementid?$this->modepaiementid:"null");
358  $sql.= ", '".$this->db->escape($this->firstname)."'";
359  $sql.= ", '".$this->db->escape($this->lastname)."'";
360  $sql.= ", '".$this->db->escape($this->societe)."'";
361  $sql.= ", '".$this->db->escape($this->address)."'";
362  $sql.= ", '".$this->db->escape($this->zip)."'";
363  $sql.= ", '".$this->db->escape($this->town)."'";
364  $sql.= ", ".$this->country_id;
365  $sql.= ", ".$this->public;
366  $sql.= ", ".($this->fk_project > 0?$this->fk_project:"null");
367  $sql.= ", ".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL");
368  $sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
369  $sql.= ", ".$user->id;
370  $sql.= ", null";
371  $sql.= ", '".$this->db->idate($this->date)."'";
372  $sql.= ", '".$this->db->escape($this->email)."'";
373  $sql.= ", '".$this->db->escape($this->phone)."'";
374  $sql.= ", '".$this->db->escape($this->phone_mobile)."'";
375  $sql.= ")";
376 
377  dol_syslog(get_class($this)."::create", LOG_DEBUG);
378  $resql = $this->db->query($sql);
379  if ($resql)
380  {
381  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."don");
382  $ret = $this->id;
383 
384  if (!$notrigger)
385  {
386  // Call trigger
387  $result=$this->call_trigger('DON_CREATE',$user);
388  if ($result < 0) { $error++; }
389  // End call triggers
390  }
391  }
392  else
393  {
394  $this->error = $this->db->lasterror();
395  $this->errno = $this->db->lasterrno();
396  $error++;
397  }
398 
399  // Update extrafield
400  if (!$error) {
401  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
402  {
403  $result=$this->insertExtraFields();
404  if ($result < 0)
405  {
406  $error++;
407  }
408  }
409  }
410 
411  if (!$error && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
412  {
413  $res = $this->setValid($user);
414  if ($res < 0) $error++;
415  }
416 
417  if (!$error)
418  {
419  $this->db->commit();
420  return $ret;
421  }
422  else
423  {
424  $this->db->rollback();
425  return -1;
426  }
427  }
428 
436  function update($user, $notrigger=0)
437  {
438  global $langs, $conf;
439 
440  $error=0;
441 
442  // Clean parameters
443  $this->address=($this->address>0?$this->address:$this->address);
444  $this->zip=($this->zip>0?$this->zip:$this->zip);
445  $this->town=($this->town>0?$this->town:$this->town);
446  $this->country_id=($this->country_id>0?$this->country_id:$this->country_id);
447  $this->country=($this->country?$this->country:$this->country);
448 
449  $this->db->begin();
450 
451  $sql = "UPDATE ".MAIN_DB_PREFIX."don SET ";
452  $sql .= "amount = " . price2num($this->amount);
453  $sql .= ",fk_payment = ".($this->modepaymentid?$this->modepaymentid:"null");
454  $sql .= ",firstname = '".$this->db->escape($this->firstname)."'";
455  $sql .= ",lastname='".$this->db->escape($this->lastname)."'";
456  $sql .= ",societe='".$this->db->escape($this->societe)."'";
457  $sql .= ",address='".$this->db->escape($this->address)."'";
458  $sql .= ",zip='".$this->db->escape($this->zip)."'";
459  $sql .= ",town='".$this->db->escape($this->town)."'";
460  $sql .= ",fk_country = ".$this->country_id;
461  $sql .= ",public=".$this->public;
462  $sql .= ",fk_projet=".($this->fk_project>0?$this->fk_project:'null');
463  $sql .= ",note_private=".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL");
464  $sql .= ",note_public=".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
465  $sql .= ",datedon='".$this->db->idate($this->date)."'";
466  $sql .= ",date_valid=".($this->date_valid?"'".$this->db->idate($this->date)."'":"null");
467  $sql .= ",email='".$this->db->escape($this->email)."'";
468  $sql .= ",phone='".$this->db->escape($this->phone)."'";
469  $sql .= ",phone_mobile='".$this->db->escape($this->phone_mobile)."'";
470  $sql .= ",fk_statut=".$this->statut;
471  $sql .= " WHERE rowid = ".$this->id;
472 
473  dol_syslog(get_class($this)."::Update", LOG_DEBUG);
474  $resql=$this->db->query($sql);
475  if ($resql)
476  {
477  if (!$notrigger)
478  {
479  // Call trigger
480  $result=$this->call_trigger('DON_MODIFY',$user);
481  if ($result < 0) { $error++; }
482  // End call triggers
483  }
484 
485  // Update extrafield
486  if (!$error)
487  {
488  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
489  {
490  $result=$this->insertExtraFields();
491  if ($result < 0)
492  {
493  $error++;
494  }
495  }
496  }
497 
498  if (! $error )
499  {
500  $this->db->commit();
501  $result = 1;
502  }
503  else
504  {
505  $this->db->rollback();
506  $result = -1;
507  }
508  }
509  else
510  {
511  $this->error = $this->db->lasterror();
512  $this->errors[] = $this->error;
513  $this->db->rollback();
514  dol_syslog(get_class($this)."::Update error -2 " . $this->error, LOG_ERR);
515  $result = -2;
516  }
517  return $result;
518  }
519 
527  function delete($user, $notrigger=0)
528  {
529  global $user, $conf, $langs;
530  require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
531 
532  $error = 0;
533 
534  $this->db->begin();
535 
536  if (! $error)
537  {
538  if (!$notrigger)
539  {
540  // Call trigger
541  $result=$this->call_trigger('DON_DELETE',$user);
542 
543  if ($result < 0) {
544  $error++;
545  }
546  // End call triggers
547  }
548  }
549 
550  // Delete donation
551  if (! $error)
552  {
553  $sql = "DELETE FROM " . MAIN_DB_PREFIX . "don_extrafields";
554  $sql.= " WHERE fk_object=" . $this->id;
555 
556  $resql = $this->db->query($sql);
557  if (! $resql)
558  {
559  $this->errors[] = $this->db->lasterror();
560  $error++;
561  }
562  }
563 
564  if (! $error)
565  {
566  $sql = "DELETE FROM " . MAIN_DB_PREFIX . "don";
567  $sql.= " WHERE rowid=" . $this->id;
568 
569  $resql = $this->db->query($sql);
570  if (!$resql)
571  {
572  $this->errors[] = $this->db->lasterror();
573  $error++;
574  }
575  }
576 
577  if (! $error)
578  {
579  $this->db->commit();
580  return 1;
581  }
582  else
583  {
584  foreach($this->errors as $errmsg)
585  {
586  dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR);
587  $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
588  }
589  dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR);
590  $this->db->rollback();
591  return -1;
592  }
593  }
594 
602  function fetch($id, $ref='')
603  {
604  global $conf;
605 
606  $sql = "SELECT d.rowid, d.datec, d.date_valid, d.tms as datem, d.datedon,";
607  $sql.= " d.firstname, d.lastname, d.societe, d.amount, d.fk_statut, d.address, d.zip, d.town, ";
608  $sql.= " d.fk_country, d.country as country_olddata, d.public, d.amount, d.fk_payment, d.paid, d.note_private, d.note_public, cp.libelle, d.email, d.phone, ";
609  $sql.= " d.phone_mobile, d.fk_projet as fk_project, d.model_pdf,";
610  $sql.= " p.ref as project_ref,";
611  $sql.= " c.code as country_code, c.label as country";
612  $sql.= " FROM ".MAIN_DB_PREFIX."don as d";
613  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_projet";
614  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_payment AND cp.entity IN (".getEntity('c_paiement').")";
615  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.fk_country = c.rowid";
616  $sql.= " WHERE d.entity IN (".getEntity('donation').")";
617  if (! empty($id))
618  {
619  $sql.= " AND d.rowid=".$id;
620  }
621  else if (! empty($ref))
622  {
623  $sql.= " AND ref='".$this->db->escape($ref)."'";
624  }
625 
626  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
627  $resql=$this->db->query($sql);
628  if ($resql)
629  {
630  if ($this->db->num_rows($resql))
631  {
632  $obj = $this->db->fetch_object($resql);
633 
634  $this->id = $obj->rowid;
635  $this->ref = $obj->rowid;
636  $this->datec = $this->db->jdate($obj->datec);
637  $this->date_valid = $this->db->jdate($obj->date_valid);
638  $this->datem = $this->db->jdate($obj->datem);
639  $this->date = $this->db->jdate($obj->datedon);
640  $this->firstname = $obj->firstname;
641  $this->lastname = $obj->lastname;
642  $this->societe = $obj->societe;
643  $this->statut = $obj->fk_statut;
644  $this->address = $obj->address;
645  $this->town = $obj->town;
646  $this->zip = $obj->zip;
647  $this->town = $obj->town;
648  $this->country_id = $obj->fk_country;
649  $this->country_code = $obj->country_code;
650  $this->country = $obj->country;
651  $this->country_olddata= $obj->country_olddata; // deprecated
652  $this->email = $obj->email;
653  $this->phone = $obj->phone;
654  $this->phone_mobile = $obj->phone_mobile;
655  $this->project = $obj->project_ref;
656  $this->fk_projet = $obj->fk_project; // deprecated
657  $this->fk_project = $obj->fk_project;
658  $this->public = $obj->public;
659  $this->modepaymentid = $obj->fk_payment;
660  $this->modepayment = $obj->libelle;
661  $this->paid = $obj->paid;
662  $this->amount = $obj->amount;
663  $this->note_private = $obj->note_private;
664  $this->note_public = $obj->note_public;
665  $this->modelpdf = $obj->model_pdf;
666  $this->commentaire = $obj->note; // deprecated
667 
668  // Retrieve all extrafield for thirdparty
669  // fetch optionals attributes and labels
670  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
671  $extrafields=new ExtraFields($this->db);
672  $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
673  $this->fetch_optionals($this->id,$extralabels);
674  }
675  return 1;
676  }
677  else
678  {
679  dol_print_error($this->db);
680  return -1;
681  }
682 
683  }
684 
693  function valid_promesse($id, $userid, $notrigger=0)
694  {
695  global $langs, $user;
696 
697  $error=0;
698 
699  $this->db->begin();
700 
701  $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = ".$userid." WHERE rowid = ".$id." AND fk_statut = 0";
702 
703  $resql=$this->db->query($sql);
704  if ($resql)
705  {
706  if ($this->db->affected_rows($resql))
707  {
708  if (!$notrigger)
709  {
710  // Call trigger
711  $result=$this->call_trigger('DON_VALIDATE',$user);
712  if ($result < 0) { $error++; }
713  // End call triggers
714  }
715  }
716  }
717  else
718  {
719  $error++;
720  $this->error = $this->db->lasterror();
721  }
722 
723  if (!$error)
724  {
725  $this->db->commit();
726  return 1;
727  }
728  else
729  {
730  $this->db->rollback();
731  return -1;
732  }
733  }
734 
742  function set_paid($id, $modepayment=0)
743  {
744  $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2";
745  if ($modepayment)
746  {
747  $sql .= ", fk_payment=".$modepayment;
748  }
749  $sql .= " WHERE rowid = ".$id." AND fk_statut = 1";
750 
751  $resql=$this->db->query($sql);
752  if ($resql)
753  {
754  if ($this->db->affected_rows($resql))
755  {
756  return 1;
757  }
758  else
759  {
760  return 0;
761  }
762  }
763  else
764  {
765  dol_print_error($this->db);
766  return -1;
767  }
768  }
769 
776  function set_cancel($id)
777  {
778  $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = -1 WHERE rowid = ".$id;
779 
780  $resql=$this->db->query($sql);
781  if ($resql)
782  {
783  if ( $this->db->affected_rows($resql) )
784  {
785  return 1;
786  }
787  else
788  {
789  return 0;
790  }
791  }
792  else
793  {
794  dol_print_error($this->db);
795  return -1;
796  }
797  }
798 
805  function sum_donations($param)
806  {
807  global $conf;
808 
809  $result=0;
810 
811  $sql = "SELECT sum(amount) as total";
812  $sql.= " FROM ".MAIN_DB_PREFIX."don";
813  $sql.= " WHERE fk_statut = ".$param;
814  $sql.= " AND entity = ".$conf->entity;
815 
816  $resql=$this->db->query($sql);
817  if ($resql)
818  {
819  $obj = $this->db->fetch_object($resql);
820  $result=$obj->total;
821  }
822 
823  return $result;
824  }
825 
831  function load_state_board()
832  {
833  global $conf;
834 
835  $this->nb=array();
836 
837  $sql = "SELECT count(d.rowid) as nb";
838  $sql.= " FROM ".MAIN_DB_PREFIX."don as d";
839  $sql.= " WHERE d.fk_statut > 0";
840  $sql.= " AND d.entity IN (".getEntity('donation').")";
841 
842  $resql=$this->db->query($sql);
843  if ($resql)
844  {
845  while ($obj=$this->db->fetch_object($resql))
846  {
847  $this->nb["donations"]=$obj->nb;
848  }
849  $this->db->free($resql);
850  return 1;
851  }
852  else
853  {
854  dol_print_error($this->db);
855  $this->error=$this->db->error();
856  return -1;
857  }
858  }
859 
867  function getNomUrl($withpicto=0, $notooltip=0)
868  {
869  global $langs;
870 
871  $result='';
872  $label=$langs->trans("ShowDonation").': '.$this->id;
873 
874  $linkstart = '<a href="'.DOL_URL_ROOT.'/don/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
875  $linkend='</a>';
876 
877  $result .= $linkstart;
878  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);
879  if ($withpicto != 2) $result.= $this->ref;
880  $result .= $linkend;
881 
882  return $result;
883  }
884 
891  function info($id)
892  {
893  $sql = 'SELECT d.rowid, d.datec, d.fk_user_author, d.fk_user_valid,';
894  $sql.= ' d.tms';
895  $sql.= ' FROM '.MAIN_DB_PREFIX.'don as d';
896  $sql.= ' WHERE d.rowid = '.$id;
897 
898  dol_syslog(get_class($this).'::info', LOG_DEBUG);
899  $result = $this->db->query($sql);
900 
901  if ($result)
902  {
903  if ($this->db->num_rows($result))
904  {
905  $obj = $this->db->fetch_object($result);
906  $this->id = $obj->rowid;
907  if ($obj->fk_user_author)
908  {
909  $cuser = new User($this->db);
910  $cuser->fetch($obj->fk_user_author);
911  $this->user_creation = $cuser;
912  }
913  if ($obj->fk_user_valid)
914  {
915  $vuser = new User($this->db);
916  $vuser->fetch($obj->fk_user_valid);
917  $this->user_modification = $vuser;
918  }
919  $this->date_creation = $this->db->jdate($obj->datec);
920  $this->date_modification = $this->db->jdate($obj->tms);
921  }
922  $this->db->free($result);
923  }
924  else
925  {
926  dol_print_error($this->db);
927  }
928  }
929 
930 }
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
update($user, $notrigger=0)
Update a donation record.
Definition: don.class.php:436
valid_promesse($id, $userid, $notrigger=0)
Validate a promise of donation.
Definition: don.class.php:693
set_cancel($id)
Set donation to status cancelled.
Definition: don.class.php:776
set_paid($id, $modepayment=0)
Classify the donation as paid, the donation was received.
Definition: don.class.php:742
Class to manage Dolibarr users.
Definition: user.class.php:39
load_state_board()
Charge indicateurs this->nb pour le tableau de bord.
Definition: don.class.php:831
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
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...
$commentaire
Definition: don.class.php:60
getNomUrl($withpicto=0, $notooltip=0)
Return clicable name (with picto eventually)
Definition: don.class.php:867
getLibStatut($mode=0)
Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee)
Definition: don.class.php:92
Class to manage standard extra fields.
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:891
__construct($db)
Constructor.
Definition: don.class.php:67
initAsSpecimen()
Initialise an instance with random values.
Definition: don.class.php:161
create($user, $notrigger=0)
Create donation record into database.
Definition: don.class.php:313
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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'un statut donne.
Definition: don.class.php:104
fetch($id, $ref='')
Load donation from database.
Definition: don.class.php:602
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:1013
check($minimum=0)
Check params and init ->errors array.
Definition: don.class.php:220
call_trigger($trigger_name, $user)
Call trigger based on this instance.
sum_donations($param)
Sum of donations.
Definition: don.class.php:805
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)