don.class.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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) 2013 Florian Henry <florian.henry@open-concept.pro>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/dons/class/don.class.php
  22. * \ingroup don
  23. * \brief Fichier de la classe des dons
  24. */
  25. require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
  26. /**
  27. * \class Don
  28. * \brief Class to manage donations
  29. */
  30. class Don extends CommonObject
  31. {
  32. public $element='don';
  33. public $table_element='don';
  34. var $id;
  35. var $ref;
  36. var $date;
  37. var $amount;
  38. var $firstname;
  39. var $lastname;
  40. var $societe;
  41. var $address;
  42. var $zip;
  43. var $town;
  44. var $country;
  45. var $email;
  46. var $public;
  47. var $fk_project;
  48. var $modepaiement;
  49. var $modepaiementid;
  50. var $note_private;
  51. var $note_public;
  52. var $statut;
  53. var $projet;
  54. /**
  55. * Constructor
  56. *
  57. * @param DoliDB $db Database handler
  58. */
  59. function __construct($db)
  60. {
  61. global $langs;
  62. $this->db = $db;
  63. $this->modepaiementid = 0;
  64. $langs->load("donations");
  65. $this->labelstatut[-1]=$langs->trans("Canceled");
  66. $this->labelstatut[0]=$langs->trans("DonationStatusPromiseNotValidated");
  67. $this->labelstatut[1]=$langs->trans("DonationStatusPromiseValidated");
  68. $this->labelstatut[2]=$langs->trans("DonationStatusPaid");
  69. $this->labelstatutshort[-1]=$langs->trans("Canceled");
  70. $this->labelstatutshort[0]=$langs->trans("DonationStatusPromiseNotValidatedShort");
  71. $this->labelstatutshort[1]=$langs->trans("DonationStatusPromiseValidatedShort");
  72. $this->labelstatutshort[2]=$langs->trans("DonationStatusPaidShort");
  73. }
  74. /**
  75. * Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee)
  76. *
  77. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
  78. * @return string Libelle
  79. */
  80. function getLibStatut($mode=0)
  81. {
  82. return $this->LibStatut($this->statut,$mode);
  83. }
  84. /**
  85. * Renvoi le libelle d'un statut donne
  86. *
  87. * @param int $statut Id statut
  88. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  89. * @return string Libelle du statut
  90. */
  91. function LibStatut($statut,$mode=0)
  92. {
  93. global $langs;
  94. if ($mode == 0)
  95. {
  96. return $this->labelstatut[$statut];
  97. }
  98. if ($mode == 1)
  99. {
  100. return $this->labelstatutshort[$statut];
  101. }
  102. if ($mode == 2)
  103. {
  104. if ($statut == -1) return img_picto($this->labelstatut[$statut],'statut5').' '.$this->labelstatutshort[$statut];
  105. if ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0').' '.$this->labelstatutshort[$statut];
  106. if ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1').' '.$this->labelstatutshort[$statut];
  107. if ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6').' '.$this->labelstatutshort[$statut];
  108. }
  109. if ($mode == 3)
  110. {
  111. $prefix='Short';
  112. if ($statut == -1) return img_picto($this->labelstatut[$statut],'statut5');
  113. if ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0');
  114. if ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1');
  115. if ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6');
  116. }
  117. if ($mode == 4)
  118. {
  119. if ($statut == -1) return img_picto($this->labelstatut[$statut],'statut5').' '.$this->labelstatut[$statut];
  120. if ($statut == 0) return img_picto($this->labelstatut[$statut],'statut0').' '.$this->labelstatut[$statut];
  121. if ($statut == 1) return img_picto($this->labelstatut[$statut],'statut1').' '.$this->labelstatut[$statut];
  122. if ($statut == 2) return img_picto($this->labelstatut[$statut],'statut6').' '.$this->labelstatut[$statut];
  123. }
  124. if ($mode == 5)
  125. {
  126. $prefix='Short';
  127. if ($statut == -1) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut5');
  128. if ($statut == 0) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut0');
  129. if ($statut == 1) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut1');
  130. if ($statut == 2) return $this->labelstatutshort[$statut].' '.img_picto($this->labelstatut[$statut],'statut6');
  131. }
  132. }
  133. /**
  134. * Initialise an instance with random values.
  135. * Used to build previews or test instances.
  136. * id must be 0 if object instance is a specimen.
  137. *
  138. * @return void
  139. */
  140. function initAsSpecimen()
  141. {
  142. global $conf, $user,$langs;
  143. // Charge tableau des id de societe socids
  144. $socids = array();
  145. $sql = "SELECT rowid";
  146. $sql.= " FROM ".MAIN_DB_PREFIX."societe";
  147. $sql.= " WHERE client IN (1, 3)";
  148. $sql.= " AND entity = ".$conf->entity;
  149. $sql.= " LIMIT 10";
  150. $resql = $this->db->query($sql);
  151. if ($resql)
  152. {
  153. $num_socs = $this->db->num_rows($resql);
  154. $i = 0;
  155. while ($i < $num_socs)
  156. {
  157. $i++;
  158. $row = $this->db->fetch_row($resql);
  159. $socids[$i] = $row[0];
  160. }
  161. }
  162. // Initialise parametres
  163. $this->id=0;
  164. $this->ref = 'SPECIMEN';
  165. $this->specimen=1;
  166. $this->lastname = 'Doe';
  167. $this->firstname = 'John';
  168. $this->socid = 1;
  169. $this->date = dol_now();
  170. $this->amount = 100;
  171. $this->public = 1;
  172. $this->societe = 'The Company';
  173. $this->address = 'Twist road';
  174. $this->zip = '99999';
  175. $this->town = 'Town';
  176. $this->note_private='Private note';
  177. $this->note_public='Public note';
  178. $this->email='email@email.com';
  179. $this->note='';
  180. $this->statut=1;
  181. }
  182. /**
  183. * Check params
  184. *
  185. * @param int $minimum Minimum
  186. * @return int 0 if KO, >0 if OK
  187. */
  188. function check($minimum=0)
  189. {
  190. $err = 0;
  191. if (dol_strlen(trim($this->societe)) == 0)
  192. {
  193. if ((dol_strlen(trim($this->lastname)) + dol_strlen(trim($this->firstname))) == 0)
  194. {
  195. $error_string[$err] = "Vous devez saisir vos nom et prenom ou le nom de votre societe.";
  196. $err++;
  197. }
  198. }
  199. if (dol_strlen(trim($this->address)) == 0)
  200. {
  201. $error_string[$err] = "L'adresse saisie est invalide";
  202. $err++;
  203. }
  204. if (dol_strlen(trim($this->zip)) == 0)
  205. {
  206. $error_string[$err] = "Le code postal saisi est invalide";
  207. $err++;
  208. }
  209. if (dol_strlen(trim($this->town)) == 0)
  210. {
  211. $error_string[$err] = "La ville saisie est invalide";
  212. $err++;
  213. }
  214. if (dol_strlen(trim($this->email)) == 0)
  215. {
  216. $error_string[$err] = "L'email saisi est invalide";
  217. $err++;
  218. }
  219. $this->amount = trim($this->amount);
  220. $map = range(0,9);
  221. $len=dol_strlen($this->amount);
  222. for ($i = 0; $i < $len; $i++)
  223. {
  224. if (!isset($map[substr($this->amount, $i, 1)] ))
  225. {
  226. $error_string[$err] = "Le montant du don contient un/des caractere(s) invalide(s)";
  227. $err++;
  228. $amount_invalid = 1;
  229. break;
  230. }
  231. }
  232. if (! $amount_invalid)
  233. {
  234. if ($this->amount == 0)
  235. {
  236. $error_string[$err] = "Le montant du don est null";
  237. $err++;
  238. }
  239. else
  240. {
  241. if ($this->amount < $minimum && $minimum > 0)
  242. {
  243. $error_string[$err] = "Le montant minimum du don est de $minimum";
  244. $err++;
  245. }
  246. }
  247. }
  248. if ($err)
  249. {
  250. $this->error = $error_string;
  251. return 0;
  252. }
  253. else
  254. {
  255. return 1;
  256. }
  257. }
  258. /**
  259. * Create donation record into database
  260. *
  261. * @param User $user Objet utilisateur qui cree le don
  262. * @return int Id don cree si ok, <0 si ko
  263. * TODO add numbering module for Ref
  264. */
  265. function create($user)
  266. {
  267. global $conf;
  268. // Clean parameters
  269. $this->address=($this->address>0?$this->address:$this->address);
  270. $this->zip=($this->zip>0?$this->zip:$this->zip);
  271. $this->town=($this->town>0?$this->town:$this->town);
  272. $this->country_id=($this->country_id>0?$this->country_id:$this->country_id);
  273. $this->country=($this->country?$this->country:$this->country);
  274. $now=dol_now();
  275. $sql = "INSERT INTO ".MAIN_DB_PREFIX."don (";
  276. $sql.= "datec";
  277. $sql.= ", entity";
  278. $sql.= ", amount";
  279. $sql.= ", fk_paiement";
  280. $sql.= ", firstname";
  281. $sql.= ", lastname";
  282. $sql.= ", societe";
  283. $sql.= ", address";
  284. $sql.= ", zip";
  285. $sql.= ", town";
  286. $sql.= ", country";
  287. $sql.= ", public";
  288. $sql.= ", fk_don_projet";
  289. $sql.= ", note_private";
  290. $sql.= ", note_public";
  291. $sql.= ", fk_user_author";
  292. $sql.= ", fk_user_valid";
  293. $sql.= ", datedon";
  294. $sql.= ", email";
  295. $sql.= ", phone";
  296. $sql.= ", phone_mobile";
  297. $sql.= ") VALUES (";
  298. $sql.= " '".$this->db->idate($now)."'";
  299. $sql.= ", ".$conf->entity;
  300. $sql.= ", ".price2num($this->amount);
  301. $sql.= ", ".($this->modepaiementid?$this->modepaiementid:"null");
  302. $sql.= ", '".$this->db->escape($this->firstname)."'";
  303. $sql.= ", '".$this->db->escape($this->lastname)."'";
  304. $sql.= ", '".$this->db->escape($this->societe)."'";
  305. $sql.= ", '".$this->db->escape($this->address)."'";
  306. $sql.= ", '".$this->db->escape($this->zip)."'";
  307. $sql.= ", '".$this->db->escape($this->town)."'";
  308. $sql.= ", '".$this->db->escape($this->country)."'"; // TODO use country_id
  309. $sql.= ", ".$this->public;
  310. $sql.= ", ".($this->fk_project > 0?$this->fk_project:"null");
  311. $sql.= ", ".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL");
  312. $sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
  313. $sql.= ", ".$user->id;
  314. $sql.= ", null";
  315. $sql.= ", '".$this->db->idate($this->date)."'";
  316. $sql.= ", '".$this->db->escape($this->email)."'";
  317. $sql.= ", '".$this->db->escape($this->phone)."'";
  318. $sql.= ", '".$this->db->escape($this->phone_mobile)."'";
  319. $sql.= ")";
  320. dol_syslog("Don::create sql=".$sql, LOG_DEBUG);
  321. $result = $this->db->query($sql);
  322. if ($result)
  323. {
  324. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."don");
  325. // Appel des triggers
  326. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  327. $interface=new Interfaces($this->db);
  328. $result=$interface->run_triggers('DON_CREATE',$this,$user,$langs,$conf);
  329. if ($result < 0) {
  330. $error++; $this->errors=$interface->errors;
  331. }
  332. // Fin appel triggers
  333. return $this->id;
  334. }
  335. else
  336. {
  337. dol_print_error($this->db);
  338. return -1;
  339. }
  340. }
  341. /**
  342. * Update a donation record
  343. *
  344. * @param User $user Objet utilisateur qui met a jour le don
  345. * @return int >0 if OK, <0 if KO
  346. */
  347. function update($user)
  348. {
  349. // Clean parameters
  350. $this->address=($this->address>0?$this->address:$this->address);
  351. $this->zip=($this->zip>0?$this->zip:$this->zip);
  352. $this->town=($this->town>0?$this->town:$this->town);
  353. $this->country_id=($this->country_id>0?$this->country_id:$this->country_id);
  354. $this->country=($this->country?$this->country:$this->country);
  355. $sql = "UPDATE ".MAIN_DB_PREFIX."don SET ";
  356. $sql .= "amount = " . price2num($this->amount);
  357. $sql .= ",fk_paiement = ".($this->modepaiementid?$this->modepaiementid:"null");
  358. $sql .= ",firstname = '".$this->db->escape($this->firstname)."'";
  359. $sql .= ",lastname='".$this->db->escape($this->lastname)."'";
  360. $sql .= ",societe='".$this->db->escape($this->societe)."'";
  361. $sql .= ",address='".$this->db->escape($this->address)."'";
  362. $sql .= ",zip='".$this->db->escape($this->zip)."'";
  363. $sql .= ",town='".$this->db->escape($this->town)."'";
  364. $sql .= ",country='".$this->db->escape($this->country)."'"; // TODO use country_id
  365. $sql .= ",public=".$this->public;
  366. $sql .= ",fk_don_projet=".($this->fk_project>0?$this->fk_project:'null');
  367. $sql .= ",note_private=".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL");
  368. $sql .= ",note_public=".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
  369. $sql .= ",datedon='".$this->db->idate($this->date)."'";
  370. $sql .= ",email='".$this->email."'";
  371. $sql .= ",phone='".$this->phone."'";
  372. $sql .= ",phone_mobile='".$this->phone_mobile."'";
  373. $sql .= ",fk_statut=".$this->statut;
  374. $sql .= " WHERE rowid = $this->id";
  375. dol_syslog("Don::update sql=".$sql);
  376. $result = $this->db->query($sql);
  377. if ($result)
  378. {
  379. return 1;
  380. }
  381. else
  382. {
  383. dol_print_error($this->db);
  384. return -1;
  385. }
  386. }
  387. /**
  388. * Delete a donation
  389. *
  390. * @param int $rowid Id of donation to delete
  391. * @return int <0 if KO, >0 if OK
  392. */
  393. function delete($rowid)
  394. {
  395. $sql = "DELETE FROM ".MAIN_DB_PREFIX."don WHERE rowid = $rowid AND fk_statut = 0;";
  396. $resql=$this->db->query($sql);
  397. if ($resql)
  398. {
  399. if ( $this->db->affected_rows($resql) )
  400. {
  401. return 1;
  402. }
  403. else
  404. {
  405. return -1;
  406. }
  407. }
  408. else
  409. {
  410. dol_print_error($this->db);
  411. return -1;
  412. }
  413. }
  414. /**
  415. * Load donation from database
  416. *
  417. * @param int $rowid Id of donation to load
  418. * @param string $ref Ref of donation to load
  419. * @return int <0 if KO, >0 if OK
  420. */
  421. function fetch($rowid,$ref='')
  422. {
  423. global $conf;
  424. $sql = "SELECT d.rowid, d.datec, d.tms as datem, d.datedon,";
  425. $sql.= " d.firstname, d.lastname, d.societe, d.amount, d.fk_statut, d.address, d.zip, d.town, ";
  426. $sql.= " d.country, d.public, d.amount, d.fk_paiement, d.note_private, d.note_public, cp.libelle, d.email, d.phone, ";
  427. $sql.= " d.phone_mobile, d.fk_don_projet,";
  428. $sql.= " p.title as project_label";
  429. $sql.= " FROM ".MAIN_DB_PREFIX."don as d";
  430. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_don_projet";
  431. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_paiement";
  432. $sql.= " WHERE d.rowid = ".$rowid." AND d.entity = ".$conf->entity;
  433. dol_syslog(get_class($this)."::fetch sql=".$sql);
  434. $resql=$this->db->query($sql);
  435. if ($resql)
  436. {
  437. if ($this->db->num_rows($resql))
  438. {
  439. $obj = $this->db->fetch_object($resql);
  440. $this->id = $obj->rowid;
  441. $this->ref = $obj->rowid;
  442. $this->datec = $this->db->jdate($obj->datec);
  443. $this->datem = $this->db->jdate($obj->datem);
  444. $this->date = $this->db->jdate($obj->datedon);
  445. $this->firstname = $obj->firstname;
  446. $this->lastname = $obj->lastname;
  447. $this->societe = $obj->societe;
  448. $this->statut = $obj->fk_statut;
  449. $this->address = $obj->address;
  450. $this->town = $obj->town;
  451. $this->zip = $obj->zip;
  452. $this->town = $obj->town;
  453. $this->country = $obj->country;
  454. $this->email = $obj->email;
  455. $this->phone = $obj->phone;
  456. $this->phone_mobile = $obj->phone_mobile;
  457. $this->projet = $obj->project_label;
  458. $this->fk_project = $obj->fk_don_projet;
  459. $this->public = $obj->public;
  460. $this->modepaiementid = $obj->fk_paiement;
  461. $this->modepaiement = $obj->libelle;
  462. $this->amount = $obj->amount;
  463. $this->note_private = $obj->note_private;
  464. $this->note_public = $obj->note_public;
  465. $this->commentaire = $obj->note; // deprecated
  466. }
  467. return 1;
  468. }
  469. else
  470. {
  471. dol_print_error($this->db);
  472. return -1;
  473. }
  474. }
  475. /**
  476. * Valide une promesse de don
  477. *
  478. * @param int $rowid id du don a modifier
  479. * @param int $userid utilisateur qui valide la promesse
  480. * @return int <0 if KO, >0 if OK
  481. */
  482. function valid_promesse($rowid, $userid)
  483. {
  484. $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid AND fk_statut = 0";
  485. $resql=$this->db->query($sql);
  486. if ($resql)
  487. {
  488. if ( $this->db->affected_rows($resql) )
  489. {
  490. return 1;
  491. }
  492. else
  493. {
  494. return 0;
  495. }
  496. }
  497. else
  498. {
  499. dol_print_error($this->db);
  500. return -1;
  501. }
  502. }
  503. /**
  504. * Classe le don comme paye, le don a ete recu
  505. *
  506. * @param int $rowid id du don a modifier
  507. * @param int $modepaiement mode de paiement
  508. * @return int <0 if KO, >0 if OK
  509. */
  510. function set_paye($rowid, $modepaiement='')
  511. {
  512. $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2";
  513. if ($modepaiement)
  514. {
  515. $sql .= ", fk_paiement=$modepaiement";
  516. }
  517. $sql .= " WHERE rowid = $rowid AND fk_statut = 1";
  518. $resql=$this->db->query($sql);
  519. if ($resql)
  520. {
  521. if ($this->db->affected_rows($resql))
  522. {
  523. return 1;
  524. }
  525. else
  526. {
  527. return 0;
  528. }
  529. }
  530. else
  531. {
  532. dol_print_error($this->db);
  533. return -1;
  534. }
  535. }
  536. /**
  537. * Classe le don comme encaisse
  538. *
  539. * @param int $rowid id du don a modifier
  540. * @return int <0 if KO, >0 if OK
  541. */
  542. function set_encaisse($rowid)
  543. {
  544. $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 3 WHERE rowid = $rowid AND fk_statut = 2";
  545. $resql=$this->db->query($sql);
  546. if ($resql)
  547. {
  548. if ( $this->db->affected_rows($resql) )
  549. {
  550. return 1;
  551. }
  552. else
  553. {
  554. return 0;
  555. }
  556. }
  557. else
  558. {
  559. dol_print_error($this->db);
  560. return -1;
  561. }
  562. }
  563. /**
  564. * Set donation sto status canceled
  565. *
  566. * @param int $rowid id du don a modifier
  567. * @return int <0 if KO, >0 if OK
  568. */
  569. function set_cancel($rowid)
  570. {
  571. $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = -1 WHERE rowid = ".$rowid;
  572. $resql=$this->db->query($sql);
  573. if ($resql)
  574. {
  575. if ( $this->db->affected_rows($resql) )
  576. {
  577. return 1;
  578. }
  579. else
  580. {
  581. return 0;
  582. }
  583. }
  584. else
  585. {
  586. dol_print_error($this->db);
  587. return -1;
  588. }
  589. }
  590. /**
  591. * Somme des dons
  592. *
  593. * @param string $param 1=promesses de dons validees , 2=xxx, 3=encaisses
  594. * @return int Summ of donations
  595. */
  596. function sum_donations($param)
  597. {
  598. global $conf;
  599. $result=0;
  600. $sql = "SELECT sum(amount) as total";
  601. $sql.= " FROM ".MAIN_DB_PREFIX."don";
  602. $sql.= " WHERE fk_statut = ".$param;
  603. $sql.= " AND entity = ".$conf->entity;
  604. $resql=$this->db->query($sql);
  605. if ($resql)
  606. {
  607. $obj = $this->db->fetch_object($resql);
  608. $result=$obj->total;
  609. }
  610. return $result;
  611. }
  612. /**
  613. * Return clicable name (with picto eventually)
  614. *
  615. * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
  616. * @return string Chaine avec URL
  617. */
  618. function getNomUrl($withpicto=0)
  619. {
  620. global $langs;
  621. $result='';
  622. $lien = '<a href="'.DOL_URL_ROOT.'/compta/dons/fiche.php?rowid='.$this->id.'">';
  623. $lienfin='</a>';
  624. $picto='generic';
  625. $label=$langs->trans("ShowDonation").': '.$this->id;
  626. if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
  627. if ($withpicto && $withpicto != 2) $result.=' ';
  628. if ($withpicto != 2) $result.=$lien.$this->id.$lienfin;
  629. return $result;
  630. }
  631. }