78 public function write_file($don, $outputlangs, $currency =
'')
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();
126 if ($don->modepaymentid) {
127 $paymentmode = $formclass->cache_types_paiements[$don->modepaymentid][
'label'];
131 $modepaymentcode = !empty($formclass->cache_types_paiements[$don->modepaymentid][
'code']) ? $formclass->cache_types_paiements[$don->modepaymentid][
'code'] :
"";
132 if ($modepaymentcode ==
'CHQ') {
133 $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>';
134 } elseif ($modepaymentcode ==
'LIQ') {
135 $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>';
136 } elseif ($modepaymentcode ==
'VIR' || $modepaymentcode ==
'PRE' || $modepaymentcode ==
'CB') {
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" checked="checked"> Virement, prélèvement, carte bancaire</td>';
139 $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>';
154 $donmodel = DOL_DOCUMENT_ROOT.
"/core/modules/dons/html_cerfafr.html";
156 $form = file_get_contents($donmodel);
158 $form = str_replace(
'__REF__', (
string) $don->id, $form);
159 $form = str_replace(
'__DATE__',
dol_print_date($don->date,
'day',
false, $outputlangs), $form);
161 $form = str_replace(
'__AMOUNT__',
price($don->amount), $form);
162 $form = str_replace(
'__AMOUNTLETTERS__', $this->
amountToLetters($don->amount), $form);
163 $form = str_replace(
'__CURRENCY__', $outputlangs->transnoentitiesnoconv(
"Currency".$currency), $form);
164 $form = str_replace(
'__CURRENCYCODE__',
$conf->currency, $form);
165 $form = str_replace(
'__MAIN_INFO_SOCIETE_NOM__', (
string)
$mysoc->name, $form);
166 $form = str_replace(
'__MAIN_INFO_SOCIETE_ADDRESS__', (
string)
$mysoc->address, $form);
167 $form = str_replace(
'__MAIN_INFO_SOCIETE_ZIP__', (
string)
$mysoc->zip, $form);
168 $form = str_replace(
'__MAIN_INFO_SOCIETE_TOWN__', (
string)
$mysoc->town, $form);
169 $form = str_replace(
'__MAIN_INFO_SOCIETE_OBJECT__', (
string)
$mysoc->socialobject, $form);
170 $form = str_replace(
'__DONATOR_FIRSTNAME__', (
string) $don->firstname, $form);
171 $form = str_replace(
'__DONATOR_LASTNAME__', (
string) $don->lastname, $form);
172 $form = str_replace(
'__DONATOR_SOCIETE__', (
string) $don->societe, $form);
173 $form = str_replace(
'__DONATOR_STATUT__', (
string) $don->statut, $form);
174 $form = str_replace(
'__DONATOR_ADDRESS__', (
string) $don->address, $form);
175 $form = str_replace(
'__DONATOR_ZIP__', (
string) $don->zip, $form);
176 $form = str_replace(
'__DONATOR_TOWN__', (
string) $don->town, $form);
177 $form = str_replace(
'__PAYMENTMODE_LIB__ ', (
string) $paymentmode, $form);
178 $form = str_replace(
'__NOW__',
dol_print_date($now,
'day',
false, $outputlangs), $form);
179 $form = str_replace(
'__DONATION_PAYMENT_MODE__', $ModePaiement, $form);
180 $form = str_replace(
'__DONATION_MESSAGE__',
getDolGlobalString(
'DONATION_MESSAGE'), $form);
186 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
187 $frencharticle =
'<font size="+1">Article 200, 238 bis et 978 du code général des impôts (CGI)</font>';
189 $form = str_replace(
'__FrenchArticle__', $frencharticle, $form);
191 $frencheligibility =
'';
192 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
193 $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 :';
195 $form = str_replace(
'__FrenchEligibility__', $frencheligibility, $form);
198 if (
$mysoc->country_code ==
'FR') {
200 $art200 =
'<input type="checkbox" disabled="true" checked="checked" >200 du CGI';
202 $art200 =
'<input type="checkbox" disabled="true">200 du CGI';
205 $form = str_replace(
'__ARTICLE200__', $art200, $form);
208 if (
$mysoc->country_code ==
'FR') {
210 $art238 =
'<input type="checkbox" disabled="true" checked="checked" >238 bis du CGI';
212 $art238 =
'<input type="checkbox" disabled="true">238 bis du CGI';
215 $form = str_replace(
'__ARTICLE238__', $art238, $form);
218 if (
$mysoc->country_code ==
'FR') {
220 $art978 =
'<input type="checkbox" disabled="true" checked="checked" >978 du CGI';
222 $art978 =
'<input type="checkbox" disabled="true">978 du CGI';
225 $form = str_replace(
'__ARTICLE978__', $art978, $form);
229 $handle = fopen($file,
"w");
230 fwrite($handle, $form);
234 $this->result = array(
'fullpath' => $file);
238 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
242 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"DON_OUTPUTDIR");
260 if (empty($devise1)) {
265 if (empty($devise2)) {
270 $integerAmount = intval($amount);
271 $fractionalAmount = intval(round($amount - intval($amount), 2) * 100);
272 $dix_c = intval($fractionalAmount % 100 / 10);
273 $cent_c = intval($fractionalAmount % 1000 / 100);
274 $unite[1] = $integerAmount % 10;
275 $dix[1] = intval($integerAmount % 100 / 10);
276 $cent[1] = intval($integerAmount % 1000 / 100);
277 $unite[2] = intval($integerAmount % 10000 / 1000);
278 $dix[2] = intval($integerAmount % 100000 / 10000);
279 $cent[2] = intval($integerAmount % 1000000 / 100000);
280 $unite[3] = intval($integerAmount % 10000000 / 1000000);
281 $dix[3] = intval($integerAmount % 100000000 / 10000000);
282 $cent[3] = intval($integerAmount % 1000000000 / 100000000);
283 $chif = array(
'',
'un',
'deux',
'trois',
'quatre',
'cinq',
'six',
'sept',
'huit',
'neuf',
'dix',
'onze',
'douze',
'treize',
'quatorze',
'quinze',
'seize',
'dix sept',
'dix huit',
'dix neuf');
290 '@phan-var string[] $prim
291 @phan-var string[] $secon
292 @phan-var string[] $trio
294 for ($i = 1; $i <= 3; $i++) {
300 $prim[$i] = $chif[$unite[$i]];
301 } elseif ($dix[$i] == 1) {
303 $prim[$i] = $chif[($unite[$i] + 10)];
304 } elseif ($dix[$i] == 2) {
305 if ($unite[$i] == 1) {
306 $secon[$i] =
'vingt et';
307 $prim[$i] = $chif[$unite[$i]];
309 $secon[$i] =
'vingt';
310 $prim[$i] = $chif[$unite[$i]];
312 } elseif ($dix[$i] == 3) {
313 if ($unite[$i] == 1) {
314 $secon[$i] =
'trente et';
315 $prim[$i] = $chif[$unite[$i]];
317 $secon[$i] =
'trente';
318 $prim[$i] = $chif[$unite[$i]];
320 } elseif ($dix[$i] == 4) {
321 if ($unite[$i] == 1) {
322 $secon[$i] =
'quarante et';
323 $prim[$i] = $chif[$unite[$i]];
325 $secon[$i] =
'quarante';
326 $prim[$i] = $chif[$unite[$i]];
328 } elseif ($dix[$i] == 5) {
329 if ($unite[$i] == 1) {
330 $secon[$i] =
'cinquante et';
331 $prim[$i] = $chif[$unite[$i]];
333 $secon[$i] =
'cinquante';
334 $prim[$i] = $chif[$unite[$i]];
336 } elseif ($dix[$i] == 6) {
337 if ($unite[$i] == 1) {
338 $secon[$i] =
'soixante et';
339 $prim[$i] = $chif[$unite[$i]];
341 $secon[$i] =
'soixante';
342 $prim[$i] = $chif[$unite[$i]];
344 } elseif ($dix[$i] == 7) {
345 if ($unite[$i] == 1) {
346 $secon[$i] =
'soixante et';
347 $prim[$i] = $chif[$unite[$i] + 10];
349 $secon[$i] =
'soixante';
350 $prim[$i] = $chif[$unite[$i] + 10];
352 } elseif ($dix[$i] == 8) {
353 if ($unite[$i] == 1) {
354 $secon[$i] =
'quatre-vingts et';
355 $prim[$i] = $chif[$unite[$i]];
357 $secon[$i] =
'quatre-vingt';
358 $prim[$i] = $chif[$unite[$i]];
360 } elseif ($dix[$i] == 9) {
361 if ($unite[$i] == 1) {
362 $secon[$i] =
'quatre-vingts et';
363 $prim[$i] = $chif[$unite[$i] + 10];
365 $secon[$i] =
'quatre-vingts';
366 $prim[$i] = $chif[$unite[$i] + 10];
369 if ($cent[$i] == 1) {
371 } elseif ($cent[$i] != 0 || $cent[$i] !=
'') {
372 $trio[$i] = $chif[$cent[$i]].
' cents';
377 $chif2 = array(
'',
'dix',
'vingt',
'trente',
'quarante',
'cinquante',
'soixante',
'soixante-dix',
'quatre-vingts',
'quatre-vingts dix');
378 $secon_c = $chif2[$dix_c];
381 } elseif ($cent_c != 0 || $cent_c !=
'') {
382 $trio_c = $chif[$cent_c].
' cents';
385 if (($cent[3] == 0 || $cent[3] ==
'') && ($dix[3] == 0 || $dix[3] ==
'') && ($unite[3] == 1)) {
386 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' million ';
387 } elseif (($cent[3] != 0 && $cent[3] !=
'') || ($dix[3] != 0 && $dix[3] !=
'') || ($unite[3] != 0 && $unite[3] !=
'')) {
388 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3].
' millions ';
390 $somme = $trio[3].
' '.$secon[3].
' '.$prim[3];
393 if (($cent[2] == 0 || $cent[2] ==
'') && ($dix[2] == 0 || $dix[2] ==
'') && ($unite[2] == 1)) {
395 } elseif (($cent[2] != 0 && $cent[2] !=
'') || ($dix[2] != 0 && $dix[2] !=
'') || ($unite[2] != 0 && $unite[2] !=
'')) {
396 $somme .= $trio[2].
' '.$secon[2].
' '.$prim[2].
' milles ';
398 $somme .= $trio[2].
' '.$secon[2].
' '.$prim[2];
401 $somme .= $trio[1].
' '.$secon[1].
' '.$prim[1];
403 $somme .=
' '.$dev1.
' ';
405 if (($cent_c ==
'0' || $cent_c ==
'') && ($dix_c ==
'0' || $dix_c ==
'')) {
406 return $somme.
' et zéro '.$dev2;
408 return $somme.$trio_c.
' '.$secon_c.
' '.$dev2;