79 public function write_file($don, $outputlangs, $currency =
'')
82 global $user, $conf, $langs,
$mysoc;
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__',
$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);
211 $form = str_replace(
'__MAIN_INFO_SOCIETE_OBJECT__',
$mysoc->socialobject, $form);
213 $form = str_replace(
'__DONATOR_FIRSTNAME__',
dol_escape_htmltag($donatorfirstname), $form);
216 $donatorlastnameprefix = (
dol_strlen(trim($donatorsociete)) > 0 &&
dol_strlen(trim($donatorlastname)) > 0) ?
'<br>' :
'';
217 $form = str_replace(
'__DONATOR_LASTNAME__', $donatorlastnameprefix.dol_escape_htmltag($donatorlastname), $form);
218 $form = str_replace(
'__DONATOR_SOCIETE__',
dol_escape_htmltag($donatorsociete), $form);
219 $form = str_replace(
'__DONATOR_STATUT__', (
string) $don->statut, $form);
224 $form = str_replace(
'__PAYMENTMODE_LIB__ ', (
string) $paymentmode, $form);
225 $form = str_replace(
'__NOW__',
dol_print_date($now,
'day',
false, $outputlangs), $form);
226 $form = str_replace(
'__DONATION_PAYMENT_MODE__', $ModePaiement, $form);
227 $form = str_replace(
'__DONATION_MESSAGE__',
getDolGlobalString(
'DONATION_MESSAGE'), $form);
233 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
234 $frencharticle =
'<font size="+1">Article 200, 238 bis et 978 du code général des impôts (CGI)</font>';
236 $form = str_replace(
'__FrenchArticle__', $frencharticle, $form);
238 $frencheligibility =
'';
239 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
240 $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 :';
242 $form = str_replace(
'__FrenchEligibility__', $frencheligibility, $form);
245 if (
$mysoc->country_code ==
'FR') {
247 $art200 =
'<input type="checkbox" disabled="true" checked="checked" >200 du CGI';
249 $art200 =
'<input type="checkbox" disabled="true">200 du CGI';
252 $form = str_replace(
'__ARTICLE200__', $art200, $form);
255 if (
$mysoc->country_code ==
'FR') {
257 $art238 =
'<input type="checkbox" disabled="true" checked="checked" >238 bis du CGI';
259 $art238 =
'<input type="checkbox" disabled="true">238 bis du CGI';
262 $form = str_replace(
'__ARTICLE238__', $art238, $form);
265 if (
$mysoc->country_code ==
'FR') {
267 $art978 =
'<input type="checkbox" disabled="true" checked="checked" >978 du CGI';
269 $art978 =
'<input type="checkbox" disabled="true">978 du CGI';
272 $form = str_replace(
'__ARTICLE978__', $art978, $form);
276 $handle = fopen($file,
"w");
277 fwrite($handle, $form);
281 $this->result = array(
'fullpath' => $file);
285 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
289 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"DON_OUTPUTDIR");
307 if (empty($devise1)) {
312 if (empty($devise2)) {
317 $valeur_entiere = intval($montant);
318 $valeur_decimal = intval(round($montant - intval($montant), 2) * 100);
319 $dix_c = intval($valeur_decimal % 100 / 10);
320 $cent_c = intval($valeur_decimal % 1000 / 100);
321 $unite[1] = $valeur_entiere % 10;
322 $dix[1] = intval($valeur_entiere % 100 / 10);
323 $cent[1] = intval($valeur_entiere % 1000 / 100);
324 $unite[2] = intval($valeur_entiere % 10000 / 1000);
325 $dix[2] = intval($valeur_entiere % 100000 / 10000);
326 $cent[2] = intval($valeur_entiere % 1000000 / 100000);
327 $unite[3] = intval($valeur_entiere % 10000000 / 1000000);
328 $dix[3] = intval($valeur_entiere % 100000000 / 10000000);
329 $cent[3] = intval($valeur_entiere % 1000000000 / 100000000);
330 $chif = array(
'',
'un',
'deux',
'trois',
'quatre',
'cinq',
'six',
'sept',
'huit',
'neuf',
'dix',
'onze',
'douze',
'treize',
'quatorze',
'quinze',
'seize',
'dix sept',
'dix huit',
'dix neuf');
337 '@phan-var string[] $prim
338 @phan-var string[] $secon
339 @phan-var string[] $trio
341 for ($i = 1; $i <= 3; $i++) {
347 $prim[$i] = $chif[$unite[$i]];
348 } elseif ($dix[$i] == 1) {
350 $prim[$i] = $chif[($unite[$i] + 10)];
351 } elseif ($dix[$i] == 2) {
352 if ($unite[$i] == 1) {
353 $secon[$i] =
'vingt et';
354 $prim[$i] = $chif[$unite[$i]];
356 $secon[$i] =
'vingt';
357 $prim[$i] = $chif[$unite[$i]];
359 } elseif ($dix[$i] == 3) {
360 if ($unite[$i] == 1) {
361 $secon[$i] =
'trente et';
362 $prim[$i] = $chif[$unite[$i]];
364 $secon[$i] =
'trente';
365 $prim[$i] = $chif[$unite[$i]];
367 } elseif ($dix[$i] == 4) {
368 if ($unite[$i] == 1) {
369 $secon[$i] =
'quarante et';
370 $prim[$i] = $chif[$unite[$i]];
372 $secon[$i] =
'quarante';
373 $prim[$i] = $chif[$unite[$i]];
375 } elseif ($dix[$i] == 5) {
376 if ($unite[$i] == 1) {
377 $secon[$i] =
'cinquante et';
378 $prim[$i] = $chif[$unite[$i]];
380 $secon[$i] =
'cinquante';
381 $prim[$i] = $chif[$unite[$i]];
383 } elseif ($dix[$i] == 6) {
384 if ($unite[$i] == 1) {
385 $secon[$i] =
'soixante et';
386 $prim[$i] = $chif[$unite[$i]];
388 $secon[$i] =
'soixante';
389 $prim[$i] = $chif[$unite[$i]];
391 } elseif ($dix[$i] == 7) {
392 if ($unite[$i] == 1) {
393 $secon[$i] =
'soixante et';
394 $prim[$i] = $chif[$unite[$i] + 10];
396 $secon[$i] =
'soixante';
397 $prim[$i] = $chif[$unite[$i] + 10];
399 } elseif ($dix[$i] == 8) {
400 if ($unite[$i] == 1) {
401 $secon[$i] =
'quatre-vingts et';
402 $prim[$i] = $chif[$unite[$i]];
404 $secon[$i] =
'quatre-vingt';
405 $prim[$i] = $chif[$unite[$i]];
407 } elseif ($dix[$i] == 9) {
408 if ($unite[$i] == 1) {
409 $secon[$i] =
'quatre-vingts et';
410 $prim[$i] = $chif[$unite[$i] + 10];
412 $secon[$i] =
'quatre-vingts';
413 $prim[$i] = $chif[$unite[$i] + 10];
416 if ($cent[$i] == 1) {
418 } elseif ($cent[$i] != 0 || $cent[$i] !=
'') {
419 $trio[$i] = $chif[$cent[$i]].
' cents';
424 $chif2 = array(
'',
'dix',
'vingt',
'trente',
'quarante',
'cinquante',
'soixante',
'soixante-dix',
'quatre-vingts',
'quatre-vingts dix');
425 $secon_c = $chif2[$dix_c];
428 } elseif ($cent_c != 0 || $cent_c !=
'') {
429 $trio_c = $chif[$cent_c].
' cents';
432 if (($cent[3] == 0 || $cent[3] ==
'') && ($dix[3] == 0 || $dix[3] ==
'') && ($unite[3] == 1)) {
433 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' million ';
434 } elseif (($cent[3] != 0 && $cent[3] !=
'') || ($dix[3] != 0 && $dix[3] !=
'') || ($unite[3] != 0 && $unite[3] !=
'')) {
435 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' millions ';
437 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3];
440 if (($cent[2] == 0 || $cent[2] ==
'') && ($dix[2] == 0 || $dix[2] ==
'') && ($unite[2] == 1)) {
442 } elseif (($cent[2] != 0 && $cent[2] !=
'') || ($dix[2] != 0 && $dix[2] !=
'') || ($unite[2] != 0 && $unite[2] !=
'')) {
443 $somme .= $trio[2].
' '.$secon[2].
' '.$prim[2].
' milles ';
445 $somme .= $trio[2].
' '.$secon[2].
' '.$prim[2];
448 $somme .= $trio[1].
' '.$secon[1].
' '.$prim[1];
450 $somme .=
' '.$dev1.
' ';
452 if (($cent_c ==
'0' || $cent_c ==
'') && ($dix_c ==
'0' || $dix_c ==
'')) {
453 return $somme.
' et zéro '.$dev2;
455 return $somme.$trio_c.
' '.$secon_c.
' '.$dev2;