77 public function write_file($don, $outputlangs, $currency =
'')
80 global $user, $conf, $langs, $mysoc;
83 $id = (!is_object($don) ? $don :
'');
85 if (!is_object($outputlangs)) {
86 $outputlangs = $langs;
90 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"donations"));
92 $currency = !empty($currency) ? $currency : $conf->currency;
94 if (!empty($conf->don->dir_output)) {
96 if (!is_object($don)) {
97 $don =
new Don($this->db);
98 $ret = $don->fetch(
$id);
103 if (!empty($don->specimen)) {
104 $dir = $conf->don->dir_output;
105 $file = $dir.
"/SPECIMEN.html";
108 $dir = $conf->don->dir_output.
"/".$donref;
109 $file = $dir.
"/".$donref.
".html";
112 if (!file_exists($dir)) {
114 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
119 if (file_exists($dir)) {
120 $formclass =
new Form($this->db);
124 $formclass->load_cache_types_paiements();
125 if ($don->modepaymentid) {
126 $paymentmode = $formclass->cache_types_paiements[$don->modepaymentid][
'label'];
130 $modepaymentcode = !empty($formclass->cache_types_paiements[$don->modepaymentid][
'code']) ? $formclass->cache_types_paiements[$don->modepaymentid][
'code'] :
"";
131 if ($modepaymentcode ==
'CHQ') {
132 $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>';
133 } elseif ($modepaymentcode ==
'LIQ') {
134 $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>';
135 } elseif ($modepaymentcode ==
'VIR' || $modepaymentcode ==
'PRE' || $modepaymentcode ==
'CB') {
136 $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>';
138 $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>';
153 $donmodel = DOL_DOCUMENT_ROOT.
"/core/modules/dons/html_cerfafr.html";
154 $form = implode(
'', file($donmodel));
155 $form = str_replace(
'__REF__', (
string) $don->id, $form);
156 $form = str_replace(
'__DATE__',
dol_print_date($don->date,
'day',
false, $outputlangs), $form);
158 $form = str_replace(
'__AMOUNT__',
price($don->amount), $form);
159 $form = str_replace(
'__AMOUNTLETTERS__', $this->
amountToLetters($don->amount), $form);
160 $form = str_replace(
'__CURRENCY__', $outputlangs->transnoentitiesnoconv(
"Currency".$currency), $form);
161 $form = str_replace(
'__CURRENCYCODE__', $conf->currency, $form);
162 $form = str_replace(
'__MAIN_INFO_SOCIETE_NOM__', $mysoc->name, $form);
163 $form = str_replace(
'__MAIN_INFO_SOCIETE_ADDRESS__', $mysoc->address, $form);
164 $form = str_replace(
'__MAIN_INFO_SOCIETE_ZIP__', $mysoc->zip, $form);
165 $form = str_replace(
'__MAIN_INFO_SOCIETE_TOWN__', $mysoc->town, $form);
166 $form = str_replace(
'__MAIN_INFO_SOCIETE_OBJECT__', $mysoc->socialobject, $form);
167 $form = str_replace(
'__DONATOR_FIRSTNAME__', $don->firstname, $form);
168 $form = str_replace(
'__DONATOR_LASTNAME__', $don->lastname, $form);
169 $form = str_replace(
'__DONATOR_SOCIETE__', $don->societe, $form);
170 $form = str_replace(
'__DONATOR_STATUT__', (
string) $don->statut, $form);
171 $form = str_replace(
'__DONATOR_ADDRESS__', $don->address, $form);
172 $form = str_replace(
'__DONATOR_ZIP__', $don->zip, $form);
173 $form = str_replace(
'__DONATOR_TOWN__', $don->town, $form);
174 $form = str_replace(
'__PAYMENTMODE_LIB__ ', $paymentmode, $form);
175 $form = str_replace(
'__NOW__',
dol_print_date($now,
'day',
false, $outputlangs), $form);
176 $form = str_replace(
'__DonationRef__', $outputlangs->trans(
"DonationRef"), $form);
177 $form = str_replace(
'__DonationTitle__', $outputlangs->trans(
"DonationTitle"), $form);
178 $form = str_replace(
'__DonationReceipt__', $outputlangs->trans(
"DonationReceipt"), $form);
179 $form = str_replace(
'__DonationRecipient__', $outputlangs->trans(
"DonationRecipient"), $form);
180 $form = str_replace(
'__DonationDatePayment__', $outputlangs->trans(
"DonationDatePayment"), $form);
181 $form = str_replace(
'__PaymentMode__', $outputlangs->trans(
"PaymentMode"), $form);
183 $form = str_replace(
'__Name__', $outputlangs->trans(
"Name"), $form);
184 $form = str_replace(
'__Address__', $outputlangs->trans(
"Address"), $form);
185 $form = str_replace(
'__Zip__', $outputlangs->trans(
"Zip"), $form);
186 $form = str_replace(
'__Town__', $outputlangs->trans(
"Town"), $form);
187 $form = str_replace(
'__Object__', $outputlangs->trans(
"Object"), $form);
188 $form = str_replace(
'__Donor__', $outputlangs->trans(
"Donor"), $form);
189 $form = str_replace(
'__Date__', $outputlangs->trans(
"Date"), $form);
190 $form = str_replace(
'__Signature__', $outputlangs->trans(
"Signature"), $form);
191 $form = str_replace(
'__Message__', $outputlangs->trans(
"Message"), $form);
192 $form = str_replace(
'__IConfirmDonationReception__', $outputlangs->trans(
"IConfirmDonationReception"), $form);
193 $form = str_replace(
'__DonationMessage__', $conf->global->DONATION_MESSAGE, $form);
195 $form = str_replace(
'__ModePaiement__', $ModePaiement, $form);
198 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
199 $frencharticle =
'<font size="+1">Article 200, 238 bis et 978 du code général des impôts (CGI)</font>';
201 $form = str_replace(
'__FrenchArticle__', $frencharticle, $form);
203 $frencheligibility =
'';
204 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
205 $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 :';
207 $form = str_replace(
'__FrenchEligibility__', $frencheligibility, $form);
210 if ($mysoc->country_code ==
'FR') {
212 $art200 =
'<input type="checkbox" disabled="true" checked="checked" >200 du CGI';
214 $art200 =
'<input type="checkbox" disabled="true">200 du CGI';
217 $form = str_replace(
'__ARTICLE200__', $art200, $form);
220 if ($mysoc->country_code ==
'FR') {
222 $art238 =
'<input type="checkbox" disabled="true" checked="checked" >238 bis du CGI';
224 $art238 =
'<input type="checkbox" disabled="true">238 bis du CGI';
227 $form = str_replace(
'__ARTICLE238__', $art238, $form);
230 if ($mysoc->country_code ==
'FR') {
232 $art978 =
'<input type="checkbox" disabled="true" checked="checked" >978 du CGI';
234 $art978 =
'<input type="checkbox" disabled="true">978 du CGI';
237 $form = str_replace(
'__ARTICLE978__', $art978, $form);
241 $handle = fopen($file,
"w");
242 fwrite($handle, $form);
246 $this->result = array(
'fullpath' => $file);
250 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
254 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"DON_OUTPUTDIR");
272 if (empty($devise1)) {
277 if (empty($devise2)) {
282 $valeur_entiere = intval($montant);
283 $valeur_decimal = intval(round($montant - intval($montant), 2) * 100);
284 $dix_c = intval($valeur_decimal % 100 / 10);
285 $cent_c = intval($valeur_decimal % 1000 / 100);
286 $unite[1] = $valeur_entiere % 10;
287 $dix[1] = intval($valeur_entiere % 100 / 10);
288 $cent[1] = intval($valeur_entiere % 1000 / 100);
289 $unite[2] = intval($valeur_entiere % 10000 / 1000);
290 $dix[2] = intval($valeur_entiere % 100000 / 10000);
291 $cent[2] = intval($valeur_entiere % 1000000 / 100000);
292 $unite[3] = intval($valeur_entiere % 10000000 / 1000000);
293 $dix[3] = intval($valeur_entiere % 100000000 / 10000000);
294 $cent[3] = intval($valeur_entiere % 1000000000 / 100000000);
295 $chif = array(
'',
'un',
'deux',
'trois',
'quatre',
'cinq',
'six',
'sept',
'huit',
'neuf',
'dix',
'onze',
'douze',
'treize',
'quatorze',
'quinze',
'seize',
'dix sept',
'dix huit',
'dix neuf');
302 '@phan-var string[] $prim
303 @phan-var string[] $secon
304 @phan-var string[] $trio
306 for ($i = 1; $i <= 3; $i++) {
312 $prim[$i] = $chif[$unite[$i]];
313 } elseif ($dix[$i] == 1) {
315 $prim[$i] = $chif[($unite[$i] + 10)];
316 } elseif ($dix[$i] == 2) {
317 if ($unite[$i] == 1) {
318 $secon[$i] =
'vingt et';
319 $prim[$i] = $chif[$unite[$i]];
321 $secon[$i] =
'vingt';
322 $prim[$i] = $chif[$unite[$i]];
324 } elseif ($dix[$i] == 3) {
325 if ($unite[$i] == 1) {
326 $secon[$i] =
'trente et';
327 $prim[$i] = $chif[$unite[$i]];
329 $secon[$i] =
'trente';
330 $prim[$i] = $chif[$unite[$i]];
332 } elseif ($dix[$i] == 4) {
333 if ($unite[$i] == 1) {
334 $secon[$i] =
'quarante et';
335 $prim[$i] = $chif[$unite[$i]];
337 $secon[$i] =
'quarante';
338 $prim[$i] = $chif[$unite[$i]];
340 } elseif ($dix[$i] == 5) {
341 if ($unite[$i] == 1) {
342 $secon[$i] =
'cinquante et';
343 $prim[$i] = $chif[$unite[$i]];
345 $secon[$i] =
'cinquante';
346 $prim[$i] = $chif[$unite[$i]];
348 } elseif ($dix[$i] == 6) {
349 if ($unite[$i] == 1) {
350 $secon[$i] =
'soixante et';
351 $prim[$i] = $chif[$unite[$i]];
353 $secon[$i] =
'soixante';
354 $prim[$i] = $chif[$unite[$i]];
356 } elseif ($dix[$i] == 7) {
357 if ($unite[$i] == 1) {
358 $secon[$i] =
'soixante et';
359 $prim[$i] = $chif[$unite[$i] + 10];
361 $secon[$i] =
'soixante';
362 $prim[$i] = $chif[$unite[$i] + 10];
364 } elseif ($dix[$i] == 8) {
365 if ($unite[$i] == 1) {
366 $secon[$i] =
'quatre-vingts et';
367 $prim[$i] = $chif[$unite[$i]];
369 $secon[$i] =
'quatre-vingt';
370 $prim[$i] = $chif[$unite[$i]];
372 } elseif ($dix[$i] == 9) {
373 if ($unite[$i] == 1) {
374 $secon[$i] =
'quatre-vingts et';
375 $prim[$i] = $chif[$unite[$i] + 10];
377 $secon[$i] =
'quatre-vingts';
378 $prim[$i] = $chif[$unite[$i] + 10];
381 if ($cent[$i] == 1) {
383 } elseif ($cent[$i] != 0 || $cent[$i] !=
'') {
384 $trio[$i] = $chif[$cent[$i]].
' cents';
389 $chif2 = array(
'',
'dix',
'vingt',
'trente',
'quarante',
'cinquante',
'soixante',
'soixante-dix',
'quatre-vingts',
'quatre-vingts dix');
390 $secon_c = $chif2[$dix_c];
393 } elseif ($cent_c != 0 || $cent_c !=
'') {
394 $trio_c = $chif[$cent_c].
' cents';
397 if (($cent[3] == 0 || $cent[3] ==
'') && ($dix[3] == 0 || $dix[3] ==
'') && ($unite[3] == 1)) {
398 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' million ';
399 } elseif (($cent[3] != 0 && $cent[3] !=
'') || ($dix[3] != 0 && $dix[3] !=
'') || ($unite[3] != 0 && $unite[3] !=
'')) {
400 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' millions ';
402 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3];
405 if (($cent[2] == 0 || $cent[2] ==
'') && ($dix[2] == 0 || $dix[2] ==
'') && ($unite[2] == 1)) {
407 } elseif (($cent[2] != 0 && $cent[2] !=
'') || ($dix[2] != 0 && $dix[2] !=
'') || ($unite[2] != 0 && $unite[2] !=
'')) {
408 $somme .= $trio[2].
' '.$secon[2].
' '.$prim[2].
' milles ';
410 $somme .= $trio[2].
' '.$secon[2].
' '.$prim[2];
413 $somme .= $trio[1].
' '.$secon[1].
' '.$prim[1];
415 $somme .=
' '.$dev1.
' ';
417 if (($cent_c ==
'0' || $cent_c ==
'') && ($dix_c ==
'0' || $dix_c ==
'')) {
418 return $somme.
' et zéro '.$dev2;
420 return $somme.$trio_c.
' '.$secon_c.
' '.$dev2;