dolibarr 25.0.0-alpha
modules_don.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5 * Copyright (C) 2005 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2026 Philippe Grand <philippe.grand@atoo-net.com>
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 <https://www.gnu.org/licenses/>.
21 * or see https://www.gnu.org/
22 */
23
29require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/commonnumrefgenerator.class.php';
31require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
32
33
34
38abstract class ModeleDon extends CommonDocGenerator
39{
40 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
48 public static function liste_modeles($db, $maxfilenamelength = 0)
49 {
50 // phpcs:enable
51 $type = 'donation';
52 $list = array();
53
54 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
55 $list = getListOfModels($db, $type, $maxfilenamelength);
56
57 return $list;
58 }
59
60 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
69 abstract public function write_file($don, $outputlangs, $currency = '');
70
76 abstract public function isEnabled();
77
87 public function getDonorInfos($don, $outputlangs)
88 {
89 $donor = array(
90 'company' => (string) $don->societe,
91 'lastname' => (string) $don->lastname,
92 'firstname' => (string) $don->firstname,
93 'name' => '',
94 'address' => (string) $don->address,
95 'zip' => (string) $don->zip,
96 'town' => (string) $don->town,
97 'country_code' => (string) $don->country_code,
98 'country' => '',
99 'idprof1' => '',
100 'thirdparty' => null,
101 );
102
103 if (!empty($don->socid) && $don->socid > 0) {
104 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
105 $thirdparty = new Societe($this->db);
106 if ($thirdparty->fetch($don->socid) > 0) {
107 $donor['thirdparty'] = $thirdparty;
108 if (dol_strlen(trim($donor['company'].$donor['lastname'].$donor['firstname'])) == 0) {
109 // A third party holds a single name field, even for a private individual
110 $donor['company'] = (string) $thirdparty->name;
111 }
112 foreach (array('address', 'zip', 'town', 'country_code') as $field) {
113 if (dol_strlen(trim($donor[$field])) == 0) {
114 $donor[$field] = (string) $thirdparty->$field;
115 }
116 }
117 $donor['idprof1'] = (string) $thirdparty->idprof1;
118 } else {
119 dol_syslog(get_class($this)."::getDonorInfos Failed to load thirdparty ".$don->socid." linked to donation ".$don->id, LOG_ERR);
120 }
121 }
122
123 $donor['name'] = trim(dolGetFirstLastname($donor['firstname'], $donor['lastname']));
124 if ($donor['company'] !== '') {
125 $donor['name'] = $donor['company'].($donor['name'] !== '' ? ' - '.$donor['name'] : '');
126 }
127 if ($donor['country_code'] !== '') {
128 $donor['country'] = $outputlangs->transnoentitiesnoconv("Country".$donor['country_code']);
129 }
130 if ($donor['name'] === '') {
131 dol_syslog(get_class($this)."::getDonorInfos No name found for the donor of donation ".$don->id, LOG_WARNING);
132 }
133
134 return $donor;
135 }
136}
137
138
143{
144 // No overload code
145}
Parent class for documents (PDF, ODT, ...) generators.
Parent class for number ref generators.
Parent class of subscription templates.
isEnabled()
Return if a module can be used or not.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
write_file($don, $outputlangs, $currency='')
Write the object to document file to disk.
getDonorInfos($don, $outputlangs)
Return the identity of the donor of a donation.
Parent class of donation numbering templates.
Class to manage third parties objects (customers, suppliers, prospects...)
getListOfModels($db, $type, $maxfilenamelength=0, $showempty=0)
Return list of activated modules usable for document generation.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.