76 public function write_file($don, $outputlangs, $currency =
'')
79 global $user, $conf, $langs, $mysoc;
82 $id = (!is_object($don) ? $don :
'');
84 if (!is_object($outputlangs)) {
85 $outputlangs = $langs;
89 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"donations"));
91 $currency = !empty($currency) ? $currency : $conf->currency;
93 if (!empty($conf->don->dir_output)) {
95 if (!is_object($don)) {
96 $don =
new Don($this->db);
97 $ret = $don->fetch($id);
102 if (!empty($don->specimen)) {
103 $dir = $conf->don->dir_output;
104 $file = $dir.
"/SPECIMEN.html";
107 $dir = $conf->don->dir_output.
"/".$donref;
108 $file = $dir.
"/".$donref.
".html";
111 if (!file_exists($dir)) {
113 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
118 if (file_exists($dir)) {
119 $formclass =
new Form($this->db);
123 $formclass->load_cache_types_paiements();
124 if ($don->modepaymentid) {
125 $paymentmode = $formclass->cache_types_paiements[$don->modepaymentid][
'label'];
129 $modepaymentcode = !empty($formclass->cache_types_paiements[$don->modepaymentid][
'code']) ? $formclass->cache_types_paiements[$don->modepaymentid][
'code'] :
"";
130 if ($modepaymentcode ==
'CHQ') {
131 $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>';
132 } elseif ($modepaymentcode ==
'LIQ') {
133 $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>';
134 } elseif ($modepaymentcode ==
'VIR' || $modepaymentcode ==
'PRE' || $modepaymentcode ==
'CB') {
135 $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>';
137 $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>';
152 $donmodel = DOL_DOCUMENT_ROOT.
"/core/modules/dons/html_cerfafr.html";
153 $form = implode(
'', file($donmodel));
154 $form = str_replace(
'__REF__', $don->id, $form);
155 $form = str_replace(
'__DATE__',
dol_print_date($don->date,
'day',
false, $outputlangs), $form);
157 $form = str_replace(
'__AMOUNT__',
price($don->amount), $form);
158 $form = str_replace(
'__AMOUNTLETTERS__', $this->
amountToLetters($don->amount), $form);
159 $form = str_replace(
'__CURRENCY__', $outputlangs->transnoentitiesnoconv(
"Currency".$currency), $form);
160 $form = str_replace(
'__CURRENCYCODE__', $conf->currency, $form);
161 $form = str_replace(
'__MAIN_INFO_SOCIETE_NOM__', $mysoc->name, $form);
162 $form = str_replace(
'__MAIN_INFO_SOCIETE_ADDRESS__', $mysoc->address, $form);
163 $form = str_replace(
'__MAIN_INFO_SOCIETE_ZIP__', $mysoc->zip, $form);
164 $form = str_replace(
'__MAIN_INFO_SOCIETE_TOWN__', $mysoc->town, $form);
165 $form = str_replace(
'__MAIN_INFO_SOCIETE_OBJECT__', $mysoc->socialobject, $form);
166 $form = str_replace(
'__DONATOR_FIRSTNAME__', $don->firstname, $form);
167 $form = str_replace(
'__DONATOR_LASTNAME__', $don->lastname, $form);
168 $form = str_replace(
'__DONATOR_SOCIETE__', $don->societe, $form);
169 $form = str_replace(
'__DONATOR_STATUT__', $don->statut, $form);
170 $form = str_replace(
'__DONATOR_ADDRESS__', $don->address, $form);
171 $form = str_replace(
'__DONATOR_ZIP__', $don->zip, $form);
172 $form = str_replace(
'__DONATOR_TOWN__', $don->town, $form);
173 $form = str_replace(
'__PAYMENTMODE_LIB__ ', $paymentmode, $form);
174 $form = str_replace(
'__NOW__',
dol_print_date($now,
'day',
false, $outputlangs), $form);
175 $form = str_replace(
'__DonationRef__', $outputlangs->trans(
"DonationRef"), $form);
176 $form = str_replace(
'__DonationTitle__', $outputlangs->trans(
"DonationTitle"), $form);
177 $form = str_replace(
'__DonationReceipt__', $outputlangs->trans(
"DonationReceipt"), $form);
178 $form = str_replace(
'__DonationRecipient__', $outputlangs->trans(
"DonationRecipient"), $form);
179 $form = str_replace(
'__DonationDatePayment__', $outputlangs->trans(
"DonationDatePayment"), $form);
180 $form = str_replace(
'__PaymentMode__', $outputlangs->trans(
"PaymentMode"), $form);
182 $form = str_replace(
'__Name__', $outputlangs->trans(
"Name"), $form);
183 $form = str_replace(
'__Address__', $outputlangs->trans(
"Address"), $form);
184 $form = str_replace(
'__Zip__', $outputlangs->trans(
"Zip"), $form);
185 $form = str_replace(
'__Town__', $outputlangs->trans(
"Town"), $form);
186 $form = str_replace(
'__Object__', $outputlangs->trans(
"Object"), $form);
187 $form = str_replace(
'__Donor__', $outputlangs->trans(
"Donor"), $form);
188 $form = str_replace(
'__Date__', $outputlangs->trans(
"Date"), $form);
189 $form = str_replace(
'__Signature__', $outputlangs->trans(
"Signature"), $form);
190 $form = str_replace(
'__Message__', $outputlangs->trans(
"Message"), $form);
191 $form = str_replace(
'__IConfirmDonationReception__', $outputlangs->trans(
"IConfirmDonationReception"), $form);
192 $form = str_replace(
'__DonationMessage__', $conf->global->DONATION_MESSAGE, $form);
194 $form = str_replace(
'__ModePaiement__', $ModePaiement, $form);
197 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
198 $frencharticle =
'<font size="+1">Article 200, 238 bis et 978 du code général des impôts (CGI)</font>';
200 $form = str_replace(
'__FrenchArticle__', $frencharticle, $form);
202 $frencheligibility =
'';
203 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
204 $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 :';
206 $form = str_replace(
'__FrenchEligibility__', $frencheligibility, $form);
209 if ($mysoc->country_code ==
'FR') {
210 if ($conf->global->DONATION_ART200 >= 1) {
211 $art200 =
'<input type="checkbox" disabled="true" checked="checked" >200 du CGI';
213 $art200 =
'<input type="checkbox" disabled="true">200 du CGI';
216 $form = str_replace(
'__ARTICLE200__', $art200, $form);
219 if ($mysoc->country_code ==
'FR') {
220 if ($conf->global->DONATION_ART238 >= 1) {
221 $art238 =
'<input type="checkbox" disabled="true" checked="checked" >238 bis du CGI';
223 $art238 =
'<input type="checkbox" disabled="true">238 bis du CGI';
226 $form = str_replace(
'__ARTICLE238__', $art238, $form);
229 if ($mysoc->country_code ==
'FR') {
230 if ($conf->global->DONATION_ART978 >= 1) {
231 $art978 =
'<input type="checkbox" disabled="true" checked="checked" >978 du CGI';
233 $art978 =
'<input type="checkbox" disabled="true">978 du CGI';
236 $form = str_replace(
'__ARTICLE978__', $art978, $form);
240 $handle = fopen($file,
"w");
241 fwrite($handle, $form);
245 $this->result = array(
'fullpath'=>$file);
249 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
253 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"DON_OUTPUTDIR");
271 if (empty($devise1)) {
276 if (empty($devise2)) {
281 $valeur_entiere = intval($montant);
282 $valeur_decimal = intval(round($montant - intval($montant), 2) * 100);
283 $dix_c = intval($valeur_decimal % 100 / 10);
284 $cent_c = intval($valeur_decimal % 1000 / 100);
285 $unite[1] = $valeur_entiere % 10;
286 $dix[1] = intval($valeur_entiere % 100 / 10);
287 $cent[1] = intval($valeur_entiere % 1000 / 100);
288 $unite[2] = intval($valeur_entiere % 10000 / 1000);
289 $dix[2] = intval($valeur_entiere % 100000 / 10000);
290 $cent[2] = intval($valeur_entiere % 1000000 / 100000);
291 $unite[3] = intval($valeur_entiere % 10000000 / 1000000);
292 $dix[3] = intval($valeur_entiere % 100000000 / 10000000);
293 $cent[3] = intval($valeur_entiere % 1000000000 / 100000000);
294 $chif = array(
'',
'un',
'deux',
'trois',
'quatre',
'cinq',
'six',
'sept',
'huit',
'neuf',
'dix',
'onze',
'douze',
'treize',
'quatorze',
'quinze',
'seize',
'dix sept',
'dix huit',
'dix neuf');
297 for ($i = 1; $i <= 3; $i++) {
303 $prim[$i] = $chif[$unite[$i]];
304 } elseif ($dix[$i] == 1) {
306 $prim[$i] = $chif[($unite[$i] + 10)];
307 } elseif ($dix[$i] == 2) {
308 if ($unite[$i] == 1) {
309 $secon[$i] =
'vingt et';
310 $prim[$i] = $chif[$unite[$i]];
312 $secon[$i] =
'vingt';
313 $prim[$i] = $chif[$unite[$i]];
315 } elseif ($dix[$i] == 3) {
316 if ($unite[$i] == 1) {
317 $secon[$i] =
'trente et';
318 $prim[$i] = $chif[$unite[$i]];
320 $secon[$i] =
'trente';
321 $prim[$i] = $chif[$unite[$i]];
323 } elseif ($dix[$i] == 4) {
324 if ($unite[$i] == 1) {
325 $secon[$i] =
'quarante et';
326 $prim[$i] = $chif[$unite[$i]];
328 $secon[$i] =
'quarante';
329 $prim[$i] = $chif[$unite[$i]];
331 } elseif ($dix[$i] == 5) {
332 if ($unite[$i] == 1) {
333 $secon[$i] =
'cinquante et';
334 $prim[$i] = $chif[$unite[$i]];
336 $secon[$i] =
'cinquante';
337 $prim[$i] = $chif[$unite[$i]];
339 } elseif ($dix[$i] == 6) {
340 if ($unite[$i] == 1) {
341 $secon[$i] =
'soixante et';
342 $prim[$i] = $chif[$unite[$i]];
344 $secon[$i] =
'soixante';
345 $prim[$i] = $chif[$unite[$i]];
347 } elseif ($dix[$i] == 7) {
348 if ($unite[$i] == 1) {
349 $secon[$i] =
'soixante et';
350 $prim[$i] = $chif[$unite[$i] + 10];
352 $secon[$i] =
'soixante';
353 $prim[$i] = $chif[$unite[$i] + 10];
355 } elseif ($dix[$i] == 8) {
356 if ($unite[$i] == 1) {
357 $secon[$i] =
'quatre-vingts et';
358 $prim[$i] = $chif[$unite[$i]];
360 $secon[$i] =
'quatre-vingt';
361 $prim[$i] = $chif[$unite[$i]];
363 } elseif ($dix[$i] == 9) {
364 if ($unite[$i] == 1) {
365 $secon[$i] =
'quatre-vingts et';
366 $prim[$i] = $chif[$unite[$i] + 10];
368 $secon[$i] =
'quatre-vingts';
369 $prim[$i] = $chif[$unite[$i] + 10];
372 if ($cent[$i] == 1) {
374 } elseif ($cent[$i] != 0 || $cent[$i] !=
'') {
375 $trio[$i] = $chif[$cent[$i]].
' cents';
380 $chif2 = array(
'',
'dix',
'vingt',
'trente',
'quarante',
'cinquante',
'soixante',
'soixante-dix',
'quatre-vingts',
'quatre-vingts dix');
381 $secon_c = $chif2[$dix_c];
384 } elseif ($cent_c != 0 || $cent_c !=
'') {
385 $trio_c = $chif[$cent_c].
' cents';
388 if (($cent[3] == 0 || $cent[3] ==
'') && ($dix[3] == 0 || $dix[3] ==
'') && ($unite[3] == 1)) {
389 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' million ';
390 } elseif (($cent[3] != 0 && $cent[3] !=
'') || ($dix[3] != 0 && $dix[3] !=
'') || ($unite[3] != 0 && $unite[3] !=
'')) {
391 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' millions ';
393 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3];
396 if (($cent[2] == 0 || $cent[2] ==
'') && ($dix[2] == 0 || $dix[2] ==
'') && ($unite[2] == 1)) {
397 $somme = $somme.
' mille ';
398 } elseif (($cent[2] != 0 && $cent[2] !=
'') || ($dix[2] != 0 && $dix[2] !=
'') || ($unite[2] != 0 && $unite[2] !=
'')) {
399 $somme = $somme.$trio[2].
' '.$secon[2].
' '.$prim[2].
' milles ';
401 $somme = $somme.$trio[2].
' '.$secon[2].
' '.$prim[2];
404 $somme = $somme.$trio[1].
' '.$secon[1].
' '.$prim[1];
406 $somme = $somme.
' '.$dev1.
' ';
408 if (($cent_c ==
'0' || $cent_c ==
'') && ($dix_c ==
'0' || $dix_c ==
'')) {
409 return $somme.
' et zéro '.$dev2;
411 return $somme.$trio_c.
' '.$secon_c.
' '.$dev2;