dolibarr 19.0.3
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@open-dsi.fr>
7 * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
9 * Copyright (C) 2019-2020 Frédéric France <frederic.france@netlogic.fr>
10 * Copyright (C) 2021 Maxime DEMAREST <maxime@indelog.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/commonpeople.class.php';
34
35
39class Don extends CommonObject
40{
41 use CommonPeople;
42
46 public $element = 'don';
47
51 public $table_element = 'don';
52
56 public $fk_element = 'fk_donation';
57
62 public $ismultientitymanaged = 1;
63
67 public $picto = 'donation';
68
72 public $date;
73
74 public $datec;
75 public $datem;
76
81 public $amount;
82
86 public $socid;
87
91 public $societe;
92
96 public $address;
97
101 public $zip;
102
106 public $town;
107
111 public $email;
112
113 public $phone;
114 public $phone_mobile;
115
116
120 public $mode_reglement;
121
125 public $mode_reglement_code;
126
130 public $public;
131
135 public $fk_project;
136
140 public $fk_typepayment;
141
142 public $num_payment;
143 public $date_valid;
144
148 public $modepaymentid = 0;
149
150 public $paid;
151
152
156 public $labelStatus;
157
161 public $labelStatusShort;
162
163
164 const STATUS_DRAFT = 0;
165 const STATUS_VALIDATED = 1;
166 const STATUS_PAID = 2;
167 const STATUS_CANCELED = -1;
168
169
175 public function __construct($db)
176 {
177 $this->db = $db;
178 }
179
180
187 public function getLibStatut($mode = 0)
188 {
189 return $this->LibStatut($this->statut, $mode);
190 }
191
192 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
200 public function LibStatut($status, $mode = 0)
201 {
202 // phpcs:enable
203 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
204 global $langs;
205 $langs->load("donations");
206 $this->labelStatus[-1] = $langs->transnoentitiesnoconv("Canceled");
207 $this->labelStatus[0] = $langs->transnoentitiesnoconv("DonationStatusPromiseNotValidated");
208 $this->labelStatus[1] = $langs->transnoentitiesnoconv("DonationStatusPromiseValidated");
209 $this->labelStatus[2] = $langs->transnoentitiesnoconv("DonationStatusPaid");
210 $this->labelStatusShort[-1] = $langs->transnoentitiesnoconv("Canceled");
211 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv("DonationStatusPromiseNotValidatedShort");
212 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv("DonationStatusPromiseValidatedShort");
213 $this->labelStatusShort[2] = $langs->transnoentitiesnoconv("DonationStatusPaidShort");
214 }
215
216 $statusType = 'status'.$status;
217 if ($status == self::STATUS_CANCELED) {
218 $statusType = 'status9';
219 }
220 if ($status == self::STATUS_PAID) {
221 $statusType = 'status6';
222 }
223
224 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
225 }
226
227
235 public function initAsSpecimen()
236 {
237 global $conf;
238
239 $now = dol_now();
240
241 // Charge tableau des id de societe socids
242 $socids = array();
243
244 $sql = "SELECT rowid";
245 $sql .= " FROM ".MAIN_DB_PREFIX."societe";
246 $sql .= " WHERE client IN (1, 3)";
247 $sql .= " AND entity = ".$conf->entity;
248 $sql .= " LIMIT 10";
249
250 $resql = $this->db->query($sql);
251 if ($resql) {
252 $num_socs = $this->db->num_rows($resql);
253 $i = 0;
254 while ($i < $num_socs) {
255 $row = $this->db->fetch_row($resql);
256 $socids[$i] = $row[0];
257
258 $i++;
259 }
260 }
261
262 // Initialise parametres
263 $this->id = 0;
264 $this->ref = 'SPECIMEN';
265 $this->specimen = 1;
266 $this->lastname = 'Doe';
267 $this->firstname = 'John';
268 $this->socid = empty($socids[0]) ? 0 : $socids[0];
269 $this->date = $now;
270 $this->date_valid = $now;
271 $this->amount = 100.90;
272 $this->public = 1;
273 $this->societe = 'The Company';
274 $this->address = 'Twist road';
275 $this->zip = '99999';
276 $this->town = 'Town';
277 $this->note_private = 'Private note';
278 $this->note_public = 'Public note';
279 $this->email = 'email@email.com';
280 $this->phone = '0123456789';
281 $this->phone_mobile = '0606060606';
282 $this->statut = 1;
283 }
284
285
293 public function check($minimum = 0)
294 {
295 global $langs;
296 $langs->load('main');
297 $langs->load('companies');
298
299 $error_string = array();
300 $err = 0;
301
302 if (dol_strlen(trim($this->societe)) == 0) {
303 if ((dol_strlen(trim($this->lastname)) + dol_strlen(trim($this->firstname))) == 0) {
304 $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Company').'/'.$langs->transnoentitiesnoconv('Firstname').'-'.$langs->transnoentitiesnoconv('Lastname'));
305 $err++;
306 }
307 }
308
309 if (dol_strlen(trim($this->address)) == 0) {
310 $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Address'));
311 $err++;
312 }
313
314 if (dol_strlen(trim($this->zip)) == 0) {
315 $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Zip'));
316 $err++;
317 }
318
319 if (dol_strlen(trim($this->town)) == 0) {
320 $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Town'));
321 $err++;
322 }
323
324 if (dol_strlen(trim($this->email)) == 0) {
325 $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('EMail'));
326 $err++;
327 }
328
329 $this->amount = trim($this->amount);
330
331 $map = range(0, 9);
332 $len = dol_strlen($this->amount);
333 for ($i = 0; $i < $len; $i++) {
334 if (!isset($map[substr($this->amount, $i, 1)])) {
335 $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Amount'));
336 $err++;
337 $amount_invalid = 1;
338 break;
339 }
340 }
341
342 if (!$amount_invalid) {
343 if ($this->amount == 0) {
344 $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Amount'));
345 $err++;
346 } else {
347 if ($this->amount < $minimum && $minimum > 0) {
348 $error_string[] = $langs->trans('MinimumAmount', $langs->transnoentitiesnoconv('$minimum'));
349 $err++;
350 }
351 }
352 }
353
354 if ($err) {
355 $this->errors = $error_string;
356 return 0;
357 } else {
358 return 1;
359 }
360 }
361
370 public function create($user, $notrigger = 0)
371 {
372 global $conf, $langs;
373
374 $error = 0;
375 $ret = 0;
376 $now = dol_now();
377
378 // Clean parameters
379 $this->address = ($this->address > 0 ? $this->address : $this->address);
380 $this->zip = ($this->zip > 0 ? $this->zip : $this->zip);
381 $this->town = ($this->town > 0 ? $this->town : $this->town);
382 $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
383 $this->country = ($this->country ? $this->country : $this->country);
384 $this->amount = price2num($this->amount);
385
386 // Check parameters
387 if ($this->amount < 0) {
388 $this->error = $langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv("Amount"));
389 return -1;
390 }
391
392 $this->db->begin();
393
394 $sql = "INSERT INTO ".MAIN_DB_PREFIX."don (";
395 $sql .= "datec";
396 $sql .= ", entity";
397 $sql .= ", amount";
398 $sql .= ", fk_payment";
399 $sql .= ", fk_soc";
400 $sql .= ", firstname";
401 $sql .= ", lastname";
402 $sql .= ", societe";
403 $sql .= ", address";
404 $sql .= ", zip";
405 $sql .= ", town";
406 $sql .= ", fk_country";
407 $sql .= ", public";
408 $sql .= ", fk_projet";
409 $sql .= ", note_private";
410 $sql .= ", note_public";
411 $sql .= ", fk_user_author";
412 $sql .= ", fk_user_valid";
413 $sql .= ", datedon";
414 $sql .= ", email";
415 $sql .= ", phone";
416 $sql .= ", phone_mobile";
417 $sql .= ") VALUES (";
418 $sql .= "'".$this->db->idate($this->date ? $this->date : $now)."'";
419 $sql .= ", ".((int) $conf->entity);
420 $sql .= ", ".((float) $this->amount);
421 $sql .= ", ".($this->modepaymentid ? $this->modepaymentid : "null");
422 $sql .= ", ".($this->socid > 0 ? $this->socid : "null");
423 $sql .= ", '".$this->db->escape($this->firstname)."'";
424 $sql .= ", '".$this->db->escape($this->lastname)."'";
425 $sql .= ", '".$this->db->escape($this->societe)."'";
426 $sql .= ", '".$this->db->escape($this->address)."'";
427 $sql .= ", '".$this->db->escape($this->zip)."'";
428 $sql .= ", '".$this->db->escape($this->town)."'";
429 $sql .= ", ".(int) ($this->country_id > 0 ? $this->country_id : 0);
430 $sql .= ", ".(int) $this->public;
431 $sql .= ", ".($this->fk_project > 0 ? (int) $this->fk_project : "null");
432 $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL");
433 $sql .= ", ".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL");
434 $sql .= ", ".((int) $user->id);
435 $sql .= ", null";
436 $sql .= ", '".$this->db->idate($this->date)."'";
437 $sql .= ", '".(!empty($this->email) ? $this->db->escape(trim($this->email)) : "")."'";
438 $sql .= ", '".(!empty($this->phone) ? $this->db->escape(trim($this->phone)) : "")."'";
439 $sql .= ", '".(!empty($this->phone_mobile) ? $this->db->escape(trim($this->phone_mobile)) : "")."'";
440 $sql .= ")";
441
442 $resql = $this->db->query($sql);
443 if ($resql) {
444 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."don");
445 $ret = $this->id;
446
447 if (!$notrigger) {
448 // Call trigger
449 $result = $this->call_trigger('DON_CREATE', $user);
450 if ($result < 0) {
451 $error++;
452 }
453 // End call triggers
454 }
455 } else {
456 $this->error = $this->db->lasterror();
457 $error++;
458 }
459
460 // Update extrafield
461 if (!$error) {
462 $result = $this->insertExtraFields();
463 if ($result < 0) {
464 $error++;
465 }
466 }
467
468 if (!$error && (getDolGlobalString('MAIN_DISABLEDRAFTSTATUS') || getDolGlobalString('MAIN_DISABLEDRAFTSTATUS_DONATION'))) {
469 //$res = $this->setValid($user);
470 //if ($res < 0) $error++;
471 }
472
473 if (!$error) {
474 $this->db->commit();
475 return $ret;
476 } else {
477 $this->db->rollback();
478 return -1;
479 }
480 }
481
489 public function update($user, $notrigger = 0)
490 {
491 global $langs;
492
493 $error = 0;
494
495 // Clean parameters
496 $this->address = ($this->address > 0 ? $this->address : $this->address);
497 $this->zip = ($this->zip > 0 ? $this->zip : $this->zip);
498 $this->town = ($this->town > 0 ? $this->town : $this->town);
499 $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
500 $this->country = ($this->country ? $this->country : $this->country);
501 $this->amount = price2num($this->amount);
502
503 // Check parameters
504 if ($this->amount < 0) {
505 $this->error = $langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv("Amount"));
506 return -1;
507 }
508
509 $this->db->begin();
510
511 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET";
512 $sql .= " amount = ".((float) $this->amount);
513 $sql .= ", fk_payment = ".($this->modepaymentid ? $this->modepaymentid : "null");
514 $sql .= ", firstname = '".$this->db->escape($this->firstname)."'";
515 $sql .= ", lastname='".$this->db->escape($this->lastname)."'";
516 $sql .= ", societe='".$this->db->escape($this->societe)."'";
517 $sql .= ", address='".$this->db->escape($this->address)."'";
518 $sql .= ", zip='".$this->db->escape($this->zip)."'";
519 $sql .= ", town='".$this->db->escape($this->town)."'";
520 $sql .= ", fk_country = ".($this->country_id > 0 ? ((int) $this->country_id) : '0');
521 $sql .= ", public=".((int) $this->public);
522 $sql .= ", fk_projet=".($this->fk_project > 0 ? $this->fk_project : 'null');
523 $sql .= ", note_private=".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL");
524 $sql .= ", note_public=".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL");
525 $sql .= ", datedon='".$this->db->idate($this->date)."'";
526 $sql .= ", date_valid=".($this->date_valid ? "'".$this->db->idate($this->date)."'" : "null");
527 $sql .= ", email='".$this->db->escape(trim($this->email))."'";
528 $sql .= ", phone='".$this->db->escape(trim($this->phone))."'";
529 $sql .= ", phone_mobile='".$this->db->escape(trim($this->phone_mobile))."'";
530 $sql .= ", fk_statut=".((int) $this->statut);
531 $sql .= " WHERE rowid = ".((int) $this->id);
532
533 dol_syslog(get_class($this)."::Update", LOG_DEBUG);
534 $resql = $this->db->query($sql);
535 if ($resql) {
536 if (!$notrigger) {
537 // Call trigger
538 $result = $this->call_trigger('DON_MODIFY', $user);
539 if ($result < 0) {
540 $error++;
541 }
542 // End call triggers
543 }
544
545 // Update extrafield
546 if (!$error) {
547 $result = $this->insertExtraFields();
548 if ($result < 0) {
549 $error++;
550 }
551 }
552
553 if (!$error) {
554 $this->db->commit();
555 $result = 1;
556 } else {
557 $this->db->rollback();
558 $result = -1;
559 }
560 } else {
561 $this->error = $this->db->lasterror();
562 $this->errors[] = $this->error;
563 $this->db->rollback();
564 dol_syslog(get_class($this)."::Update error -2 ".$this->error, LOG_ERR);
565 $result = -2;
566 }
567 return $result;
568 }
569
577 public function delete($user, $notrigger = 0)
578 {
579 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
580
581 $error = 0;
582
583 $this->db->begin();
584
585 if (!$error && !$notrigger) {
586 // Call trigger
587 $result = $this->call_trigger('DON_DELETE', $user);
588
589 if ($result < 0) {
590 $error++;
591 }
592 // End call triggers
593 }
594
595 // Delete donation
596 if (!$error) {
597 $sql = "DELETE FROM ".MAIN_DB_PREFIX."don_extrafields";
598 $sql .= " WHERE fk_object = ".((int) $this->id);
599
600 $resql = $this->db->query($sql);
601 if (!$resql) {
602 $this->errors[] = $this->db->lasterror();
603 $error++;
604 }
605 }
606
607 if (!$error) {
608 $sql = "DELETE FROM ".MAIN_DB_PREFIX."don";
609 $sql .= " WHERE rowid=".((int) $this->id);
610
611 $resql = $this->db->query($sql);
612 if (!$resql) {
613 $this->errors[] = $this->db->lasterror();
614 $error++;
615 }
616 }
617
618 if (!$error) {
619 $this->db->commit();
620 return 1;
621 } else {
622 foreach ($this->errors as $errmsg) {
623 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
624 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
625 }
626 dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
627 $this->db->rollback();
628 return -1;
629 }
630 }
631
639 public function fetch($id, $ref = '')
640 {
641 $sql = "SELECT d.rowid, d.datec, d.date_valid, d.tms as datem, d.datedon,";
642 $sql .= " d.fk_soc as socid, d.firstname, d.lastname, d.societe, d.amount, d.fk_statut as status, d.address, d.zip, d.town, ";
643 $sql .= " d.fk_country, d.public, d.amount, d.fk_payment, d.paid, d.note_private, d.note_public, d.email, d.phone, ";
644 $sql .= " d.phone_mobile, d.fk_projet as fk_project, d.model_pdf,";
645 $sql .= " p.ref as project_ref,";
646 $sql .= " cp.libelle as payment_label, cp.code as payment_code,";
647 $sql .= " c.code as country_code, c.label as country";
648 $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
649 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_projet";
650 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_payment";
651 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.fk_country = c.rowid";
652 $sql .= " WHERE d.entity IN (".getEntity('donation').")";
653 if (!empty($id)) {
654 $sql .= " AND d.rowid=".((int) $id);
655 } elseif (!empty($ref)) {
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 if ($this->db->num_rows($resql)) {
663 $obj = $this->db->fetch_object($resql);
664
665 $this->id = $obj->rowid;
666 $this->ref = $obj->rowid;
667 $this->date_creation = $this->db->jdate($obj->datec);
668 $this->datec = $this->db->jdate($obj->datec);
669 $this->date_validation = $this->db->jdate($obj->date_valid);
670 $this->date_valid = $this->db->jdate($obj->date_valid);
671 $this->date_modification = $this->db->jdate($obj->datem);
672 $this->datem = $this->db->jdate($obj->datem);
673 $this->date = $this->db->jdate($obj->datedon);
674 $this->socid = $obj->socid;
675 $this->firstname = $obj->firstname;
676 $this->lastname = $obj->lastname;
677 $this->societe = $obj->societe;
678 $this->status = $obj->status;
679 $this->statut = $obj->status;
680 $this->address = $obj->address;
681 $this->zip = $obj->zip;
682 $this->town = $obj->town;
683 $this->country_id = $obj->fk_country;
684 $this->country_code = $obj->country_code;
685 $this->country = $obj->country;
686 $this->email = $obj->email;
687 $this->phone = $obj->phone;
688 $this->phone_mobile = $obj->phone_mobile;
689 $this->project = $obj->project_ref;
690 $this->fk_projet = $obj->fk_project; // deprecated
691 $this->fk_project = $obj->fk_project;
692 $this->public = $obj->public;
693 $this->mode_reglement_id = $obj->fk_payment;
694 $this->mode_reglement_code = $obj->payment_code;
695 $this->mode_reglement = $obj->payment_label;
696 $this->paid = $obj->paid;
697 $this->amount = $obj->amount;
698 $this->note_private = $obj->note_private;
699 $this->note_public = $obj->note_public;
700 $this->model_pdf = $obj->model_pdf;
701
702 // Retrieve all extrafield
703 // fetch optionals attributes and labels
704 $this->fetch_optionals();
705 }
706 return 1;
707 } else {
708 dol_print_error($this->db);
709 return -1;
710 }
711 }
712
720 public function setValid($user, $notrigger = 0)
721 {
722 return $this->valid_promesse($this->id, $user->id, $notrigger);
723 }
724
725 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
734 public function valid_promesse($id, $userid, $notrigger = 0)
735 {
736 // phpcs:enable
737 global $user;
738
739 $error = 0;
740
741 $this->db->begin();
742
743 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = ".((int) $userid)." WHERE rowid = ".((int) $id)." AND fk_statut = 0";
744
745 $resql = $this->db->query($sql);
746 if ($resql) {
747 if ($this->db->affected_rows($resql)) {
748 if (!$notrigger) {
749 // Call trigger
750 $result = $this->call_trigger('DON_VALIDATE', $user);
751 if ($result < 0) {
752 $error++;
753 }
754 // End call triggers
755 }
756 }
757 } else {
758 $error++;
759 $this->error = $this->db->lasterror();
760 }
761
762 if (!$error) {
763 $this->statut = 1;
764 $this->db->commit();
765 return 1;
766 } else {
767 $this->db->rollback();
768 return -1;
769 }
770 }
771
779 public function setPaid($id, $modepayment = 0)
780 {
781 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2, paid = 1";
782 if ($modepayment) {
783 $sql .= ", fk_payment = ".((int) $modepayment);
784 }
785 $sql .= " WHERE rowid = ".((int) $id)." AND fk_statut = 1";
786
787 $resql = $this->db->query($sql);
788 if ($resql) {
789 if ($this->db->affected_rows($resql)) {
790 $this->statut = 2;
791 $this->paid = 1;
792 return 1;
793 } else {
794 return 0;
795 }
796 } else {
797 dol_print_error($this->db);
798 return -1;
799 }
800 }
801
802 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
809 public function set_cancel($id)
810 {
811 // phpcs:enable
812 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = -1 WHERE rowid = ".((int) $id);
813
814 $resql = $this->db->query($sql);
815 if ($resql) {
816 if ($this->db->affected_rows($resql)) {
817 $this->statut = -1;
818 return 1;
819 } else {
820 return 0;
821 }
822 } else {
823 dol_print_error($this->db);
824 return -1;
825 }
826 }
827
835 public function reopen($user, $notrigger = 0)
836 {
837 // Protection
838 if ($this->statut != self::STATUS_CANCELED) {
839 return 0;
840 }
841
842 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->bom->write))
843 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->bom->bom_advance->validate))))
844 {
845 $this->error='Permission denied';
846 return -1;
847 }*/
848
849 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'DON_REOPEN');
850 }
851
852 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
859 public function sum_donations($param)
860 {
861 // phpcs:enable
862 global $conf;
863
864 $result = 0;
865
866 $sql = "SELECT sum(amount) as total";
867 $sql .= " FROM ".MAIN_DB_PREFIX."don";
868 $sql .= " WHERE fk_statut = ".((int) $param);
869 $sql .= " AND entity = ".$conf->entity;
870
871 $resql = $this->db->query($sql);
872 if ($resql) {
873 $obj = $this->db->fetch_object($resql);
874 $result = $obj->total;
875 }
876
877 return $result;
878 }
879
880 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
886 public function load_state_board()
887 {
888 // phpcs:enable
889 $this->nb = array();
890
891 $sql = "SELECT count(d.rowid) as nb";
892 $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
893 $sql .= " WHERE d.fk_statut > 0";
894 $sql .= " AND d.entity IN (".getEntity('donation').")";
895
896 $resql = $this->db->query($sql);
897 if ($resql) {
898 while ($obj = $this->db->fetch_object($resql)) {
899 $this->nb["donations"] = $obj->nb;
900 }
901 $this->db->free($resql);
902 return 1;
903 } else {
904 dol_print_error($this->db);
905 $this->error = $this->db->error();
906 return -1;
907 }
908 }
909
919 public function getNomUrl($withpicto = 0, $notooltip = 0, $moretitle = '', $save_lastsearch_value = -1)
920 {
921 global $conf, $langs, $hookmanager;
922
923 if (!empty($conf->dol_no_mouse_hover)) {
924 $notooltip = 1; // Force disable tooltips
925 }
926
927 $result = '';
928 $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Donation").'</u>';
929 if (isset($this->status)) {
930 $label .= ' '.$this->getLibStatut(5);
931 }
932 if (!empty($this->id)) {
933 $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->id;
934 $label .= '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->date, 'day');
935 }
936 if ($moretitle) {
937 $label .= ' - '.$moretitle;
938 }
939
940 $url = DOL_URL_ROOT.'/don/card.php?id='.$this->id;
941
942 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
943 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
944 $add_save_lastsearch_values = 1;
945 }
946 if ($add_save_lastsearch_values) {
947 $url .= '&save_lastsearch_values=1';
948 }
949
950 $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
951 $linkend = '</a>';
952
953 $result .= $linkstart;
954 if ($withpicto) {
955 $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
956 }
957 if ($withpicto != 2) {
958 $result .= $this->ref;
959 }
960 $result .= $linkend;
961 global $action;
962 $hookmanager->initHooks(array($this->element . 'dao'));
963 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
964 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
965 if ($reshook > 0) {
966 $result = $hookmanager->resPrint;
967 } else {
968 $result .= $hookmanager->resPrint;
969 }
970 return $result;
971 }
972
979 public function info($id)
980 {
981 $sql = 'SELECT d.rowid, d.datec, d.fk_user_author, d.fk_user_valid,';
982 $sql .= ' d.tms as datem';
983 $sql .= ' FROM '.MAIN_DB_PREFIX.'don as d';
984 $sql .= ' WHERE d.rowid = '.((int) $id);
985
986 dol_syslog(get_class($this).'::info', LOG_DEBUG);
987 $result = $this->db->query($sql);
988
989 if ($result) {
990 if ($this->db->num_rows($result)) {
991 $obj = $this->db->fetch_object($result);
992 $this->id = $obj->rowid;
993
994 $this->user_creation_id = $obj->fk_user_author;
995 $this->user_validation_id = $obj->fk_user_valid;
996 $this->date_creation = $this->db->jdate($obj->datec);
997 $this->date_modification = (!empty($obj->tms) ? $this->db->jdate($obj->tms) : "");
998 }
999 $this->db->free($result);
1000 } else {
1001 dol_print_error($this->db);
1002 }
1003 }
1004
1005
1016 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1017 {
1018 global $conf, $langs;
1019
1020 $langs->load("bills");
1021
1022 if (!dol_strlen($modele)) {
1023 $modele = 'html_cerfafr';
1024
1025 if ($this->model_pdf) {
1026 $modele = $this->model_pdf;
1027 } elseif (getDolGlobalString('DON_ADDON_MODEL')) {
1028 $modele = $conf->global->DON_ADDON_MODEL;
1029 }
1030 }
1031
1032 //$modelpath = "core/modules/dons/";
1033
1034 // TODO Restore use of commonGenerateDocument instead of dedicated code here
1035 //return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1036
1037 // Increase limit for PDF build
1038 $err = error_reporting();
1039 error_reporting(0);
1040 @set_time_limit(120);
1041 error_reporting($err);
1042
1043 $srctemplatepath = '';
1044
1045 // If selected modele is a filename template (then $modele="modelname:filename")
1046 $tmp = explode(':', $modele, 2);
1047 if (!empty($tmp[1])) {
1048 $modele = $tmp[0];
1049 $srctemplatepath = $tmp[1];
1050 }
1051
1052 // Search template files
1053 $file = '';
1054 $classname = '';
1055 $filefound = 0;
1056 $dirmodels = array('/');
1057 if (is_array($conf->modules_parts['models'])) {
1058 $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
1059 }
1060 foreach ($dirmodels as $reldir) {
1061 foreach (array('html', 'doc', 'pdf') as $prefix) {
1062 $file = $prefix."_".preg_replace('/^html_/', '', $modele).".modules.php";
1063
1064 // On verifie l'emplacement du modele
1065 $file = dol_buildpath($reldir."core/modules/dons/".$file, 0);
1066 if (file_exists($file)) {
1067 $filefound = 1;
1068 $classname = $prefix.'_'.$modele;
1069 break;
1070 }
1071 }
1072 if ($filefound) {
1073 break;
1074 }
1075 }
1076
1077 // Charge le modele
1078 if ($filefound) {
1079 require_once $file;
1080
1081 $object = $this;
1082
1083 $classname = $modele;
1084 $obj = new $classname($this->db);
1085
1086 // We save charset_output to restore it because write_file can change it if needed for
1087 // output format that does not support UTF8.
1088 $sav_charset_output = $outputlangs->charset_output;
1089 if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) {
1090 $outputlangs->charset_output = $sav_charset_output;
1091
1092 // we delete preview files
1093 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1094 dol_delete_preview($object);
1095 return 1;
1096 } else {
1097 $outputlangs->charset_output = $sav_charset_output;
1098 dol_syslog("Erreur dans don_create");
1099 dol_print_error($this->db, $obj->error);
1100 return 0;
1101 }
1102 } else {
1103 print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file);
1104 return 0;
1105 }
1106 }
1107
1116 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1117 {
1118 $tables = array(
1119 'don'
1120 );
1121
1122 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1123 }
1124
1130 public function getRemainToPay()
1131 {
1132 dol_syslog(__METHOD__, LOG_DEBUG);
1133
1134 if (empty($this->id)) {
1135 $this->error = 'Missing object id';
1136 $this->errors[] = $this->error;
1137 dol_syslog(__METHOD__.' : '.$this->error, LOG_ERR);
1138 return -1;
1139 }
1140
1141 $sql = "SELECT SUM(amount) as sum_amount FROM ".MAIN_DB_PREFIX."payment_donation WHERE fk_donation = ".((int) $this->id);
1142 $resql = $this->db->query($sql);
1143 if (!$resql) {
1144 dol_print_error($this->db);
1145 return -2;
1146 } else {
1147 $sum_amount = (float) $this->db->fetch_object($resql)->sum_amount;
1148 return (float) $this->amount - $sum_amount;
1149 }
1150 }
1151
1159 public function getKanbanView($option = '', $arraydata = null)
1160 {
1161 global $langs;
1162
1163 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1164
1165 $return = '<div class="box-flex-item box-flex-grow-zero">';
1166 $return .= '<div class="info-box info-box-sm">';
1167 $return .= '<span class="info-box-icon bg-infobox-action">';
1168 $return .= img_picto('', $this->picto);
1169 $return .= '</span>';
1170 $return .= '<div class="info-box-content">';
1171 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
1172 if ($selected >= 0) {
1173 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1174 }
1175 if (property_exists($this, 'date')) {
1176 $return .= ' | <span class="opacitymedium" >'.$langs->trans("Date").'</span> : <span class="info-box-label">'.dol_print_date($this->date).'</span>';
1177 }
1178 if (property_exists($this, 'societe') && !empty($this->societe)) {
1179 $return .= '<br><span class="opacitymedium">'.$langs->trans("Company").'</span> : <span class="info-box-label">'.$this->societe.'</span>';
1180 }
1181 if (property_exists($this, 'amount')) {
1182 $return .= '<br><span class="opacitymedium" >'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
1183 }
1184 if (method_exists($this, 'LibStatut')) {
1185 $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).'</div>';
1186 }
1187 $return .= '</div>';
1188 $return .= '</div>';
1189 $return .= '</div>';
1190 return $return;
1191 }
1192}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
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...
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage donations.
Definition don.class.php:40
getLibStatut($mode=0)
Returns the donation status label (draft, valid, abandoned, paid)
__construct($db)
Constructor.
initAsSpecimen()
Initialise an instance with random values.
create($user, $notrigger=0)
Create donation record into database.
getRemainToPay()
Function to get reamain to pay for a donation.
check($minimum=0)
Check params and init ->errors array.
setValid($user, $notrigger=0)
Validate a intervention.
valid_promesse($id, $userid, $notrigger=0)
Validate a promise of donation.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
LibStatut($status, $mode=0)
Return the label of a given status.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
fetch($id, $ref='')
Load donation from database.
reopen($user, $notrigger=0)
Set cancel status.
sum_donations($param)
Sum of donations.
info($id)
Information on record.
update($user, $notrigger=0)
Update a donation record.
load_state_board()
Charge indicateurs this->nb pour le tableau de bord.
set_cancel($id)
Set donation to status cancelled.
setPaid($id, $modepayment=0)
Classify the donation as paid, the donation was received.
getNomUrl($withpicto=0, $notooltip=0, $moretitle='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
trait CommonPeople
Superclass for thirdparties, contacts, members or users.
dol_delete_preview($object)
Delete all preview files linked to object instance.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
Definition invoice.php:1926