78 public function write_file($don, $outputlangs, $currency =
'')
81 global $user, $conf, $langs, $mysoc;
84 $id = (!is_object($don) ? $don :
'');
86 if (!is_object($outputlangs)) {
87 $outputlangs = $langs;
91 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"donations"));
93 $currency = !empty($currency) ? $currency : $conf->currency;
95 if (!empty($conf->don->dir_output)) {
97 if (!is_object($don)) {
98 $don =
new Don($this->db);
99 $ret = $don->fetch($id);
104 if (!empty($don->specimen)) {
105 $dir = $conf->don->dir_output;
106 $file = $dir.
"/SPECIMEN.html";
109 $dir = $conf->don->dir_output.
"/".$donref;
110 $file = $dir.
"/".$donref.
".html";
113 if (!file_exists($dir)) {
115 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
120 if (file_exists($dir)) {
121 $formclass =
new Form($this->db);
125 $formclass->load_cache_types_paiements();
129 $modepaymentid = !empty($don->mode_reglement_id) ? $don->mode_reglement_id : $don->modepaymentid;
130 if ($modepaymentid) {
131 $paymentmode = !empty($formclass->cache_types_paiements[$modepaymentid][
'label']) ? $formclass->cache_types_paiements[$modepaymentid][
'label'] :
'';
135 $modepaymentcode = !empty($formclass->cache_types_paiements[$modepaymentid][
'code']) ? $formclass->cache_types_paiements[$modepaymentid][
'code'] :
"";
136 if ($modepaymentcode ==
'CHQ') {
137 $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>';
138 } elseif ($modepaymentcode ==
'LIQ') {
139 $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>';
140 } elseif ($modepaymentcode ==
'VIR' || $modepaymentcode ==
'PRE' || $modepaymentcode ==
'CB') {
141 $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>';
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"> Virement, prélèvement, carte bancaire</td>';
161 $donatorsociete = (string) $don->societe;
162 $donatorlastname = (string) $don->lastname;
163 $donatorfirstname = (string) $don->firstname;
164 $donatoraddress = (string) $don->address;
165 $donatorzip = (string) $don->zip;
166 $donatortown = (string) $don->town;
168 if (!empty($don->socid) && $don->socid > 0) {
169 $donatorthirdparty =
new Societe($this->db);
170 if ($donatorthirdparty->fetch($don->socid) > 0) {
171 if (
dol_strlen(trim($donatorsociete.$donatorlastname.$donatorfirstname)) == 0) {
174 $donatorsociete = (string) $donatorthirdparty->name;
177 $donatoraddress = (string) $donatorthirdparty->address;
180 $donatorzip = (string) $donatorthirdparty->zip;
183 $donatortown = (string) $donatorthirdparty->town;
186 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);
190 if (
dol_strlen(trim($donatorsociete.$donatorlastname.$donatorfirstname)) == 0) {
191 dol_syslog(
"html_cerfafr::write_file No name found for the donator of donation ".$don->id.
", the receipt will not be compliant", LOG_WARNING);
195 $donmodel = DOL_DOCUMENT_ROOT.
"/core/modules/dons/html_cerfafr.html";
196 $form = implode(
'', file($donmodel));
197 $form = str_replace(
'__REF__', (
string) $don->id, $form);
198 $form = str_replace(
'__DATE__',
dol_print_date($don->date,
'day',
false, $outputlangs), $form);
200 $form = str_replace(
'__AMOUNT__',
price($don->amount), $form);
201 $form = str_replace(
'__AMOUNTLETTERS__', $this->
amountToLetters($don->amount), $form);
202 $form = str_replace(
'__CURRENCY__', $outputlangs->transnoentitiesnoconv(
"Currency".$currency), $form);
203 $form = str_replace(
'__CURRENCYCODE__', $conf->currency, $form);
204 $form = str_replace(
'__MAIN_INFO_SOCIETE_NOM__', $mysoc->name, $form);
205 $form = str_replace(
'__MAIN_INFO_SOCIETE_ADDRESS__', $mysoc->address, $form);
206 $form = str_replace(
'__MAIN_INFO_SOCIETE_ZIP__', $mysoc->zip, $form);
207 $form = str_replace(
'__MAIN_INFO_SOCIETE_TOWN__', $mysoc->town, $form);
208 $form = str_replace(
'__MAIN_INFO_SOCIETE_OBJECT__', $mysoc->socialobject, $form);
210 $form = str_replace(
'__DONATOR_FIRSTNAME__',
dol_escape_htmltag($donatorfirstname), $form);
213 $donatorlastnameprefix = (
dol_strlen(trim($donatorsociete)) > 0 &&
dol_strlen(trim($donatorlastname)) > 0) ?
'<br>' :
'';
214 $form = str_replace(
'__DONATOR_LASTNAME__', $donatorlastnameprefix.dol_escape_htmltag($donatorlastname), $form);
215 $form = str_replace(
'__DONATOR_SOCIETE__',
dol_escape_htmltag($donatorsociete), $form);
216 $form = str_replace(
'__DONATOR_STATUT__', $don->statut, $form);
221 $form = str_replace(
'__PAYMENTMODE_LIB__ ', $paymentmode, $form);
222 $form = str_replace(
'__NOW__',
dol_print_date($now,
'day',
false, $outputlangs), $form);
223 $form = str_replace(
'__DonationRef__', $outputlangs->trans(
"DonationRef"), $form);
224 $form = str_replace(
'__DonationTitle__', $outputlangs->trans(
"DonationTitle"), $form);
225 $form = str_replace(
'__DonationReceipt__', $outputlangs->trans(
"DonationReceipt"), $form);
226 $form = str_replace(
'__DonationRecipient__', $outputlangs->trans(
"DonationRecipient"), $form);
227 $form = str_replace(
'__DonationDatePayment__', $outputlangs->trans(
"DonationDatePayment"), $form);
228 $form = str_replace(
'__PaymentMode__', $outputlangs->trans(
"PaymentMode"), $form);
230 $form = str_replace(
'__Name__', $outputlangs->trans(
"Name"), $form);
231 $form = str_replace(
'__Address__', $outputlangs->trans(
"Address"), $form);
232 $form = str_replace(
'__Zip__', $outputlangs->trans(
"Zip"), $form);
233 $form = str_replace(
'__Town__', $outputlangs->trans(
"Town"), $form);
234 $form = str_replace(
'__Object__', $outputlangs->trans(
"Object"), $form);
235 $form = str_replace(
'__Donor__', $outputlangs->trans(
"Donor"), $form);
236 $form = str_replace(
'__Date__', $outputlangs->trans(
"Date"), $form);
237 $form = str_replace(
'__Signature__', $outputlangs->trans(
"Signature"), $form);
238 $form = str_replace(
'__Message__', $outputlangs->trans(
"Message"), $form);
239 $form = str_replace(
'__IConfirmDonationReception__', $outputlangs->trans(
"IConfirmDonationReception"), $form);
240 $form = str_replace(
'__DonationMessage__', $conf->global->DONATION_MESSAGE, $form);
242 $form = str_replace(
'__ModePaiement__', $ModePaiement, $form);
245 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
246 $frencharticle =
'<font size="+1">Article 200, 238 bis et 978 du code général des impôts (CGI)</font>';
248 $form = str_replace(
'__FrenchArticle__', $frencharticle, $form);
250 $frencheligibility =
'';
251 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
252 $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 :';
254 $form = str_replace(
'__FrenchEligibility__', $frencheligibility, $form);
257 if ($mysoc->country_code ==
'FR') {
259 $art200 =
'<input type="checkbox" disabled="true" checked="checked" >200 du CGI';
261 $art200 =
'<input type="checkbox" disabled="true">200 du CGI';
264 $form = str_replace(
'__ARTICLE200__', $art200, $form);
267 if ($mysoc->country_code ==
'FR') {
269 $art238 =
'<input type="checkbox" disabled="true" checked="checked" >238 bis du CGI';
271 $art238 =
'<input type="checkbox" disabled="true">238 bis du CGI';
274 $form = str_replace(
'__ARTICLE238__', $art238, $form);
277 if ($mysoc->country_code ==
'FR') {
279 $art978 =
'<input type="checkbox" disabled="true" checked="checked" >978 du CGI';
281 $art978 =
'<input type="checkbox" disabled="true">978 du CGI';
284 $form = str_replace(
'__ARTICLE978__', $art978, $form);
288 $handle = fopen($file,
"w");
289 fwrite($handle, $form);
293 $this->result = array(
'fullpath' => $file);
297 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
301 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"DON_OUTPUTDIR");
319 if (empty($devise1)) {
324 if (empty($devise2)) {
329 $valeur_entiere = intval($montant);
330 $valeur_decimal = intval(round($montant - intval($montant), 2) * 100);
331 $dix_c = intval($valeur_decimal % 100 / 10);
332 $cent_c = intval($valeur_decimal % 1000 / 100);
333 $unite[1] = $valeur_entiere % 10;
334 $dix[1] = intval($valeur_entiere % 100 / 10);
335 $cent[1] = intval($valeur_entiere % 1000 / 100);
336 $unite[2] = intval($valeur_entiere % 10000 / 1000);
337 $dix[2] = intval($valeur_entiere % 100000 / 10000);
338 $cent[2] = intval($valeur_entiere % 1000000 / 100000);
339 $unite[3] = intval($valeur_entiere % 10000000 / 1000000);
340 $dix[3] = intval($valeur_entiere % 100000000 / 10000000);
341 $cent[3] = intval($valeur_entiere % 1000000000 / 100000000);
342 $chif = array(
'',
'un',
'deux',
'trois',
'quatre',
'cinq',
'six',
'sept',
'huit',
'neuf',
'dix',
'onze',
'douze',
'treize',
'quatorze',
'quinze',
'seize',
'dix sept',
'dix huit',
'dix neuf');
349 '@phan-var string[] $prim
350 @phan-var string[] $secon
351 @phan-var string[] $trio
353 for ($i = 1; $i <= 3; $i++) {
359 $prim[$i] = $chif[$unite[$i]];
360 } elseif ($dix[$i] == 1) {
362 $prim[$i] = $chif[($unite[$i] + 10)];
363 } elseif ($dix[$i] == 2) {
364 if ($unite[$i] == 1) {
365 $secon[$i] =
'vingt et';
366 $prim[$i] = $chif[$unite[$i]];
368 $secon[$i] =
'vingt';
369 $prim[$i] = $chif[$unite[$i]];
371 } elseif ($dix[$i] == 3) {
372 if ($unite[$i] == 1) {
373 $secon[$i] =
'trente et';
374 $prim[$i] = $chif[$unite[$i]];
376 $secon[$i] =
'trente';
377 $prim[$i] = $chif[$unite[$i]];
379 } elseif ($dix[$i] == 4) {
380 if ($unite[$i] == 1) {
381 $secon[$i] =
'quarante et';
382 $prim[$i] = $chif[$unite[$i]];
384 $secon[$i] =
'quarante';
385 $prim[$i] = $chif[$unite[$i]];
387 } elseif ($dix[$i] == 5) {
388 if ($unite[$i] == 1) {
389 $secon[$i] =
'cinquante et';
390 $prim[$i] = $chif[$unite[$i]];
392 $secon[$i] =
'cinquante';
393 $prim[$i] = $chif[$unite[$i]];
395 } elseif ($dix[$i] == 6) {
396 if ($unite[$i] == 1) {
397 $secon[$i] =
'soixante et';
398 $prim[$i] = $chif[$unite[$i]];
400 $secon[$i] =
'soixante';
401 $prim[$i] = $chif[$unite[$i]];
403 } elseif ($dix[$i] == 7) {
404 if ($unite[$i] == 1) {
405 $secon[$i] =
'soixante et';
406 $prim[$i] = $chif[$unite[$i] + 10];
408 $secon[$i] =
'soixante';
409 $prim[$i] = $chif[$unite[$i] + 10];
411 } elseif ($dix[$i] == 8) {
412 if ($unite[$i] == 1) {
413 $secon[$i] =
'quatre-vingts et';
414 $prim[$i] = $chif[$unite[$i]];
416 $secon[$i] =
'quatre-vingt';
417 $prim[$i] = $chif[$unite[$i]];
419 } elseif ($dix[$i] == 9) {
420 if ($unite[$i] == 1) {
421 $secon[$i] =
'quatre-vingts et';
422 $prim[$i] = $chif[$unite[$i] + 10];
424 $secon[$i] =
'quatre-vingts';
425 $prim[$i] = $chif[$unite[$i] + 10];
428 if ($cent[$i] == 1) {
430 } elseif ($cent[$i] != 0 || $cent[$i] !=
'') {
431 $trio[$i] = $chif[$cent[$i]].
' cents';
436 $chif2 = array(
'',
'dix',
'vingt',
'trente',
'quarante',
'cinquante',
'soixante',
'soixante-dix',
'quatre-vingts',
'quatre-vingts dix');
437 $secon_c = $chif2[$dix_c];
440 } elseif ($cent_c != 0 || $cent_c !=
'') {
441 $trio_c = $chif[$cent_c].
' cents';
444 if (($cent[3] == 0 || $cent[3] ==
'') && ($dix[3] == 0 || $dix[3] ==
'') && ($unite[3] == 1)) {
445 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' million ';
446 } elseif (($cent[3] != 0 && $cent[3] !=
'') || ($dix[3] != 0 && $dix[3] !=
'') || ($unite[3] != 0 && $unite[3] !=
'')) {
447 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' millions ';
449 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3];
452 if (($cent[2] == 0 || $cent[2] ==
'') && ($dix[2] == 0 || $dix[2] ==
'') && ($unite[2] == 1)) {
453 $somme = $somme.
' mille ';
454 } elseif (($cent[2] != 0 && $cent[2] !=
'') || ($dix[2] != 0 && $dix[2] !=
'') || ($unite[2] != 0 && $unite[2] !=
'')) {
455 $somme = $somme.$trio[2].
' '.$secon[2].
' '.$prim[2].
' milles ';
457 $somme = $somme.$trio[2].
' '.$secon[2].
' '.$prim[2];
460 $somme = $somme.$trio[1].
' '.$secon[1].
' '.$prim[1];
462 $somme = $somme.
' '.$dev1.
' ';
464 if (($cent_c ==
'0' || $cent_c ==
'') && ($dix_c ==
'0' || $dix_c ==
'')) {
465 return $somme.
' et zéro '.$dev2;
467 return $somme.$trio_c.
' '.$secon_c.
' '.$dev2;