30require_once DOL_DOCUMENT_ROOT.
'/core/modules/dons/modules_don.php';
31require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/functionsnumtoword.lib.php';
52 $this->
name =
"cerfafr";
53 $this->
description = $langs->trans(
'DonationsReceiptModel').
' - fr_FR - Cerfa 11580*04';
80 public function write_file($don, $outputlangs, $currency =
'')
86 $id = (!is_object($don) ? $don :
'');
88 if (!is_object($outputlangs)) {
89 $outputlangs = $langs;
93 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"donations"));
95 $currency = !empty($currency) ? $currency :
$conf->currency;
97 if (!empty(
$conf->don->dir_output)) {
99 if (!is_object($don)) {
100 $don =
new Don($this->db);
101 $ret = $don->fetch(
$id);
106 if (!empty($don->specimen)) {
107 $dir =
$conf->don->dir_output;
108 $file = $dir.
"/SPECIMEN.html";
111 $dir =
$conf->don->dir_output.
"/".$donref;
112 $file = $dir.
"/".$donref.
".html";
115 if (!file_exists($dir)) {
117 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
122 if (file_exists($dir)) {
123 $formclass =
new Form($this->db);
127 $formclass->load_cache_types_paiements();
131 $modepaymentid = !empty($don->mode_reglement_id) ? $don->mode_reglement_id : $don->modepaymentid;
132 if ($modepaymentid) {
133 $paymentmode = !empty($formclass->cache_types_paiements[(
int) $modepaymentid][
'label']) ? $formclass->cache_types_paiements[$modepaymentid][
'label'] :
'';
137 $modepaymentcode = !empty($formclass->cache_types_paiements[(
int) $modepaymentid][
'code']) ? $formclass->cache_types_paiements[(int) $modepaymentid][
'code'] :
"";
138 if ($modepaymentcode ==
'CHQ') {
139 $ModePaiement =
'<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox" disabled="true" checked="checked"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>';
140 } elseif ($modepaymentcode ==
'LIQ') {
141 $ModePaiement =
'<td width="25%"><input type="checkbox" checked="checked"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>';
142 } elseif ($modepaymentcode ==
'VIR' || $modepaymentcode ==
'PRE' || $modepaymentcode ==
'CB') {
143 $ModePaiement =
'<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox" checked="checked"> Virement, prélèvement, carte bancaire</td>';
145 $ModePaiement =
'<td width="25%"><input type="checkbox"> Remise d\'espèces</td><td width="25%"><input type="checkbox"> Chèque</td><td width="50%"><input type="checkbox"> Virement, prélèvement, carte bancaire</td>';
163 $donatorsociete = (string) $don->societe;
164 $donatorlastname = (string) $don->lastname;
165 $donatorfirstname = (string) $don->firstname;
166 $donatoraddress = (string) $don->address;
167 $donatorzip = (string) $don->zip;
168 $donatortown = (string) $don->town;
170 if (!empty($don->socid) && $don->socid > 0) {
171 $donatorthirdparty =
new Societe($this->db);
172 if ($donatorthirdparty->fetch($don->socid) > 0) {
173 if (
dol_strlen(trim($donatorsociete.$donatorlastname.$donatorfirstname)) == 0) {
176 $donatorsociete = (string) $donatorthirdparty->name;
179 $donatoraddress = (string) $donatorthirdparty->address;
182 $donatorzip = (string) $donatorthirdparty->zip;
185 $donatortown = (string) $donatorthirdparty->town;
188 dol_syslog(
"html_cerfafr::write_file Failed to load thirdparty ".$don->socid.
" linked to donation ".$don->id.
", donator block will remain empty - ".$donatorthirdparty->error, LOG_ERR);
192 if (
dol_strlen(trim($donatorsociete.$donatorlastname.$donatorfirstname)) == 0) {
193 dol_syslog(
"html_cerfafr::write_file No name found for the donator of donation ".$don->id.
", the receipt will not be compliant", LOG_WARNING);
197 $donmodel = DOL_DOCUMENT_ROOT.
"/core/modules/dons/html_cerfafr.html";
199 $form = file_get_contents($donmodel);
202 $form = str_replace(
'__REF__', (
string) $don->id, $form);
203 $form = str_replace(
'__DATE__',
dol_print_date($don->date,
'day',
false, $outputlangs), $form);
205 $form = str_replace(
'__AMOUNT__',
price($don->amount), $form);
206 $form = str_replace(
'__AMOUNT_TEXT__',
dol_convertToWord($don->amount, $outputlangs, $outputlangs->transnoentitiesnoconv(
"Currency".$currency),
true), $form);
208 $form = str_replace(
'__DONATOR_FIRSTNAME__',
dol_escape_htmltag($donatorfirstname), $form);
211 $donatorlastnameprefix = (
dol_strlen(trim($donatorsociete)) > 0 &&
dol_strlen(trim($donatorlastname)) > 0) ?
'<br>' :
'';
212 $form = str_replace(
'__DONATOR_LASTNAME__', $donatorlastnameprefix.dol_escape_htmltag($donatorlastname), $form);
213 $form = str_replace(
'__DONATOR_SOCIETE__',
dol_escape_htmltag($donatorsociete), $form);
215 $form = str_replace(
'__DONATOR_STATUT__', (
string) $don->statut, $form);
220 $form = str_replace(
'__PAYMENTMODE_LIB__ ', (
string) $paymentmode, $form);
221 $form = str_replace(
'__NOW__',
dol_print_date($now,
'day',
false, $outputlangs), $form);
222 $form = str_replace(
'__DONATION_PAYMENT_MODE__', $ModePaiement, $form);
223 $form = str_replace(
'__DONATION_MESSAGE__',
getDolGlobalString(
'DONATION_MESSAGE'), $form);
226 $substitutionkey = getCommonSubstitutionArray($outputlangs, 0,
null, $don);
232 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
233 $frencharticle =
'<font size="+1">Article 200, 238 bis et 978 du code général des impôts (CGI)</font>';
235 $form = str_replace(
'__FrenchArticle__', $frencharticle, $form);
237 $frencheligibility =
'';
238 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
239 $frencheligibility =
'Le bénéficiaire certifie sur l\'honneur que les dons et versements qu\'il reçoit ouvrent droit à la réduction d\'impôt prévue à l\'article :';
241 $form = str_replace(
'__FrenchEligibility__', $frencheligibility, $form);
244 if (
$mysoc->country_code ==
'FR') {
246 $art200 =
'<input type="checkbox" disabled="true" checked="checked" >200 du CGI';
248 $art200 =
'<input type="checkbox" disabled="true">200 du CGI';
251 $form = str_replace(
'__ARTICLE200__', $art200, $form);
254 if (
$mysoc->country_code ==
'FR') {
256 $art238 =
'<input type="checkbox" disabled="true" checked="checked" >238 bis du CGI';
258 $art238 =
'<input type="checkbox" disabled="true">238 bis du CGI';
261 $form = str_replace(
'__ARTICLE238__', $art238, $form);
264 if (
$mysoc->country_code ==
'FR') {
266 $art978 =
'<input type="checkbox" disabled="true" checked="checked" >978 du CGI';
268 $art978 =
'<input type="checkbox" disabled="true">978 du CGI';
271 $form = str_replace(
'__ARTICLE978__', $art978, $form);
275 $handle = fopen($file,
"w");
276 fwrite($handle, $form);
280 $this->result = array(
'fullpath' => $file);
284 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
288 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"DON_OUTPUTDIR");
$id
Support class for third parties, contacts, members, users or resources.
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Class to manage donations.
Parent class of subscription templates.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to generate document for subscriptions.
write_file($don, $outputlangs, $currency='')
Write the object to document file to disk.
isEnabled()
Return if a module can be used or not.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_now($mode='gmt')
Return date for now.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_convertToWord($num, $langs, $currency='', $centimes=false)
Function to return a number into a text.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
$conf db name
Only used if Module[ID]Name translation string is not found.