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';
51 $this->
name =
"cerfafr";
52 $this->
description = $langs->trans(
'DonationsReceiptModel').
' - fr_FR - Cerfa 11580*04';
79 public function write_file($don, $outputlangs, $currency =
'')
85 $id = (!is_object($don) ? $don :
'');
87 if (!is_object($outputlangs)) {
88 $outputlangs = $langs;
92 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"donations"));
94 $currency = !empty($currency) ? $currency :
$conf->currency;
96 if (!empty(
$conf->don->dir_output)) {
98 if (!is_object($don)) {
99 $don =
new Don($this->db);
100 $ret = $don->fetch(
$id);
105 if (!empty($don->specimen)) {
106 $dir =
$conf->don->dir_output;
107 $file = $dir.
"/SPECIMEN.html";
110 $dir =
$conf->don->dir_output.
"/".$donref;
111 $file = $dir.
"/".$donref.
".html";
114 if (!file_exists($dir)) {
116 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
121 if (file_exists($dir)) {
122 $formclass =
new Form($this->db);
126 $formclass->load_cache_types_paiements();
130 $modepaymentid = !empty($don->mode_reglement_id) ? $don->mode_reglement_id : $don->modepaymentid;
131 if ($modepaymentid) {
132 $paymentmode = !empty($formclass->cache_types_paiements[(
int) $modepaymentid][
'label']) ? $formclass->cache_types_paiements[$modepaymentid][
'label'] :
'';
136 $modepaymentcode = !empty($formclass->cache_types_paiements[(
int) $modepaymentid][
'code']) ? $formclass->cache_types_paiements[(int) $modepaymentid][
'code'] :
"";
137 if ($modepaymentcode ==
'CHQ') {
138 $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>';
139 } elseif ($modepaymentcode ==
'LIQ') {
140 $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>';
141 } elseif ($modepaymentcode ==
'VIR' || $modepaymentcode ==
'PRE' || $modepaymentcode ==
'CB') {
142 $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>';
144 $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>';
162 $donatorsociete = (
string) $don->societe;
163 $donatorlastname = (
string) $don->lastname;
164 $donatorfirstname = (
string) $don->firstname;
165 $donatoraddress = (
string) $don->address;
166 $donatorzip = (
string) $don->zip;
167 $donatortown = (
string) $don->town;
169 if (!empty($don->socid) && $don->socid > 0) {
170 $donatorthirdparty =
new Societe($this->db);
171 if ($donatorthirdparty->fetch($don->socid) > 0) {
172 if (
dol_strlen(trim($donatorsociete.$donatorlastname.$donatorfirstname)) == 0) {
175 $donatorsociete = (
string) $donatorthirdparty->name;
178 $donatoraddress = (
string) $donatorthirdparty->address;
181 $donatorzip = (
string) $donatorthirdparty->zip;
184 $donatortown = (
string) $donatorthirdparty->town;
187 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);
191 if (
dol_strlen(trim($donatorsociete.$donatorlastname.$donatorfirstname)) == 0) {
192 dol_syslog(
"html_cerfafr::write_file No name found for the donator of donation ".$don->id.
", the receipt will not be compliant", LOG_WARNING);
196 $donmodel = DOL_DOCUMENT_ROOT.
"/core/modules/dons/html_cerfafr.html";
198 $form = file_get_contents($donmodel);
200 $form = str_replace(
'__REF__', (
string) $don->id, $form);
201 $form = str_replace(
'__DATE__',
dol_print_date($don->date,
'day',
false, $outputlangs), $form);
203 $form = str_replace(
'__AMOUNT__',
price($don->amount), $form);
204 $form = str_replace(
'__AMOUNTLETTERS__', $this->
amountToLetters($don->amount), $form);
205 $form = str_replace(
'__CURRENCY__', $outputlangs->transnoentitiesnoconv(
"Currency".$currency), $form);
206 $form = str_replace(
'__CURRENCYCODE__',
$conf->currency, $form);
207 $form = str_replace(
'__MAIN_INFO_SOCIETE_NOM__', (
string)
$mysoc->name, $form);
208 $form = str_replace(
'__MAIN_INFO_SOCIETE_ADDRESS__', (
string)
$mysoc->address, $form);
209 $form = str_replace(
'__MAIN_INFO_SOCIETE_ZIP__', (
string)
$mysoc->zip, $form);
210 $form = str_replace(
'__MAIN_INFO_SOCIETE_TOWN__', (
string)
$mysoc->town, $form);
212 $form = str_replace(
'__MAIN_INFO_SOCIETE_OBJECT__', (
string)
$mysoc->socialobject, $form);
214 $form = str_replace(
'__DONATOR_FIRSTNAME__',
dol_escape_htmltag($donatorfirstname), $form);
217 $donatorlastnameprefix = (
dol_strlen(trim($donatorsociete)) > 0 &&
dol_strlen(trim($donatorlastname)) > 0) ?
'<br>' :
'';
218 $form = str_replace(
'__DONATOR_LASTNAME__', $donatorlastnameprefix.dol_escape_htmltag($donatorlastname), $form);
219 $form = str_replace(
'__DONATOR_SOCIETE__',
dol_escape_htmltag($donatorsociete), $form);
221 $form = str_replace(
'__DONATOR_STATUT__', (
string) $don->statut, $form);
226 $form = str_replace(
'__PAYMENTMODE_LIB__ ', (
string) $paymentmode, $form);
227 $form = str_replace(
'__NOW__',
dol_print_date($now,
'day',
false, $outputlangs), $form);
228 $form = str_replace(
'__DONATION_PAYMENT_MODE__', $ModePaiement, $form);
229 $form = str_replace(
'__DONATION_MESSAGE__',
getDolGlobalString(
'DONATION_MESSAGE'), $form);
235 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
236 $frencharticle =
'<font size="+1">Article 200, 238 bis et 978 du code général des impôts (CGI)</font>';
238 $form = str_replace(
'__FrenchArticle__', $frencharticle, $form);
240 $frencheligibility =
'';
241 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
242 $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 :';
244 $form = str_replace(
'__FrenchEligibility__', $frencheligibility, $form);
247 if (
$mysoc->country_code ==
'FR') {
249 $art200 =
'<input type="checkbox" disabled="true" checked="checked" >200 du CGI';
251 $art200 =
'<input type="checkbox" disabled="true">200 du CGI';
254 $form = str_replace(
'__ARTICLE200__', $art200, $form);
257 if (
$mysoc->country_code ==
'FR') {
259 $art238 =
'<input type="checkbox" disabled="true" checked="checked" >238 bis du CGI';
261 $art238 =
'<input type="checkbox" disabled="true">238 bis du CGI';
264 $form = str_replace(
'__ARTICLE238__', $art238, $form);
267 if (
$mysoc->country_code ==
'FR') {
269 $art978 =
'<input type="checkbox" disabled="true" checked="checked" >978 du CGI';
271 $art978 =
'<input type="checkbox" disabled="true">978 du CGI';
274 $form = str_replace(
'__ARTICLE978__', $art978, $form);
278 $handle = fopen($file,
"w");
279 fwrite($handle, $form);
283 $this->result = array(
'fullpath' => $file);
287 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
291 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"DON_OUTPUTDIR");
309 if (empty($devise1)) {
314 if (empty($devise2)) {
319 $integerAmount = intval($amount);
320 $fractionalAmount = intval(round($amount - intval($amount), 2) * 100);
321 $dix_c = intval($fractionalAmount % 100 / 10);
322 $cent_c = intval($fractionalAmount % 1000 / 100);
323 $unite[1] = $integerAmount % 10;
324 $dix[1] = intval($integerAmount % 100 / 10);
325 $cent[1] = intval($integerAmount % 1000 / 100);
326 $unite[2] = intval($integerAmount % 10000 / 1000);
327 $dix[2] = intval($integerAmount % 100000 / 10000);
328 $cent[2] = intval($integerAmount % 1000000 / 100000);
329 $unite[3] = intval($integerAmount % 10000000 / 1000000);
330 $dix[3] = intval($integerAmount % 100000000 / 10000000);
331 $cent[3] = intval($integerAmount % 1000000000 / 100000000);
332 $chif = array(
'',
'un',
'deux',
'trois',
'quatre',
'cinq',
'six',
'sept',
'huit',
'neuf',
'dix',
'onze',
'douze',
'treize',
'quatorze',
'quinze',
'seize',
'dix sept',
'dix huit',
'dix neuf');
339 '@phan-var string[] $prim
340 @phan-var string[] $secon
341 @phan-var string[] $trio
343 for ($i = 1; $i <= 3; $i++) {
349 $prim[$i] = $chif[$unite[$i]];
350 } elseif ($dix[$i] == 1) {
352 $prim[$i] = $chif[($unite[$i] + 10)];
353 } elseif ($dix[$i] == 2) {
354 if ($unite[$i] == 1) {
355 $secon[$i] =
'vingt et';
356 $prim[$i] = $chif[$unite[$i]];
358 $secon[$i] =
'vingt';
359 $prim[$i] = $chif[$unite[$i]];
361 } elseif ($dix[$i] == 3) {
362 if ($unite[$i] == 1) {
363 $secon[$i] =
'trente et';
364 $prim[$i] = $chif[$unite[$i]];
366 $secon[$i] =
'trente';
367 $prim[$i] = $chif[$unite[$i]];
369 } elseif ($dix[$i] == 4) {
370 if ($unite[$i] == 1) {
371 $secon[$i] =
'quarante et';
372 $prim[$i] = $chif[$unite[$i]];
374 $secon[$i] =
'quarante';
375 $prim[$i] = $chif[$unite[$i]];
377 } elseif ($dix[$i] == 5) {
378 if ($unite[$i] == 1) {
379 $secon[$i] =
'cinquante et';
380 $prim[$i] = $chif[$unite[$i]];
382 $secon[$i] =
'cinquante';
383 $prim[$i] = $chif[$unite[$i]];
385 } elseif ($dix[$i] == 6) {
386 if ($unite[$i] == 1) {
387 $secon[$i] =
'soixante et';
388 $prim[$i] = $chif[$unite[$i]];
390 $secon[$i] =
'soixante';
391 $prim[$i] = $chif[$unite[$i]];
393 } elseif ($dix[$i] == 7) {
394 if ($unite[$i] == 1) {
395 $secon[$i] =
'soixante et';
396 $prim[$i] = $chif[$unite[$i] + 10];
398 $secon[$i] =
'soixante';
399 $prim[$i] = $chif[$unite[$i] + 10];
401 } elseif ($dix[$i] == 8) {
402 if ($unite[$i] == 1) {
403 $secon[$i] =
'quatre-vingts et';
404 $prim[$i] = $chif[$unite[$i]];
406 $secon[$i] =
'quatre-vingt';
407 $prim[$i] = $chif[$unite[$i]];
409 } elseif ($dix[$i] == 9) {
410 if ($unite[$i] == 1) {
411 $secon[$i] =
'quatre-vingts et';
412 $prim[$i] = $chif[$unite[$i] + 10];
414 $secon[$i] =
'quatre-vingts';
415 $prim[$i] = $chif[$unite[$i] + 10];
418 if ($cent[$i] == 1) {
420 } elseif ($cent[$i] != 0 || $cent[$i] !=
'') {
421 $trio[$i] = $chif[$cent[$i]].
' cents';
426 $chif2 = array(
'',
'dix',
'vingt',
'trente',
'quarante',
'cinquante',
'soixante',
'soixante-dix',
'quatre-vingts',
'quatre-vingts dix');
427 $secon_c = $chif2[$dix_c];
430 } elseif ($cent_c != 0 || $cent_c !=
'') {
431 $trio_c = $chif[$cent_c].
' cents';
434 if (($cent[3] == 0 || $cent[3] ==
'') && ($dix[3] == 0 || $dix[3] ==
'') && ($unite[3] == 1)) {
435 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' million ';
436 } elseif (($cent[3] != 0 && $cent[3] !=
'') || ($dix[3] != 0 && $dix[3] !=
'') || ($unite[3] != 0 && $unite[3] !=
'')) {
437 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' millions ';
439 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3];
442 if (($cent[2] == 0 || $cent[2] ==
'') && ($dix[2] == 0 || $dix[2] ==
'') && ($unite[2] == 1)) {
444 } elseif (($cent[2] != 0 && $cent[2] !=
'') || ($dix[2] != 0 && $dix[2] !=
'') || ($unite[2] != 0 && $unite[2] !=
'')) {
445 $somme .= $trio[2].
' '.$secon[2].
' '.$prim[2].
' milles ';
447 $somme .= $trio[2].
' '.$secon[2].
' '.$prim[2];
450 $somme .= $trio[1].
' '.$secon[1].
' '.$prim[1];
452 $somme .=
' '.$dev1.
' ';
454 if (($cent_c ==
'0' || $cent_c ==
'') && ($dix_c ==
'0' || $dix_c ==
'')) {
455 return $somme.
' et zéro '.$dev2;
457 return $somme.$trio_c.
' '.$secon_c.
' '.$dev2;
$id
Support class for third parties, contacts, members, users or resources.
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.
amountToLetters($amount, $devise1='', $devise2='')
numbers to letters
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_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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
$conf db name
Only used if Module[ID]Name translation string is not found.