-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
html_cerfafr.modules.php
439 lines (401 loc) · 15.4 KB
/
html_cerfafr.modules.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2014-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Benoit Bruchard <benoitb21@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/modules/dons/html_cerfafr.modules.php
* \ingroup don
* \brief Form of donation
*/
require_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php';
require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
/**
* Class to generate document for subscriptions
*/
class html_cerfafr extends ModeleDon
{
/**
* Constructor
*
* @param DoliDb $db Database handler
*/
function __construct($db)
{
global $conf,$langs;
$this->db = $db;
$this->name = "cerfafr";
$this->description = $langs->trans('DonationsReceiptModel').' - fr_FR - Cerfa 11580*03';
// Dimension page for size A4
$this->type = 'html';
}
/**
* Return if a module can be used or not
*
* @return boolean true if module can be used
*/
function isEnabled()
{
return true;
}
/**
* Write the object to document file to disk
*
* @param Don $don Donation object
* @param Translate $outputlangs Lang object for output language
* @param string $currency Currency code
* @return int >0 if OK, <0 if KO
*/
// phpcs:ignore PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
function write_file($don,$outputlangs,$currency='')
{
global $user,$conf,$langs,$mysoc;
$now=dol_now();
$id = (! is_object($don)?$don:'');
if (! is_object($outputlangs)) $outputlangs=$langs;
$outputlangs->load("main");
$outputlangs->load("dict");
$outputlangs->load("companies");
$outputlangs->load("bills");
$outputlangs->load("products");
$outputlangs->load("donations");
$currency = !empty($currency) ? $currency : $conf->currency;
if (! empty($conf->don->dir_output))
{
// Definition of the object don (for upward compatibility)
if (! is_object($don))
{
$don = new Don($this->db);
$ret=$don->fetch($id);
$id=$don->id;
}
// Definition of $dir and $file
if (! empty($don->specimen))
{
$dir = $conf->don->dir_output;
$file = $dir . "/SPECIMEN.html";
}
else
{
$donref = dol_sanitizeFileName($don->ref);
$dir = $conf->don->dir_output . "/" . $donref;
$file = $dir . "/" . $donref . ".html";
}
if (! file_exists($dir))
{
if (dol_mkdir($dir) < 0)
{
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
return -1;
}
}
if (file_exists($dir))
{
$formclass = new Form($this->db);
// This is not the proper way to do it but $formclass->form_modes_reglement
// prints the translation instead of returning it
if ($don->modepaiementid)
{
$formclass->load_cache_types_paiements();
$paymentmode = $formclass->cache_types_paiements[$don->modepaiementid]['label'];
}
else $paymentmode = '';
if ($don->modepaymentcode=='CHQ'){
$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>';
}
else if ($don->modepaymentcode=='LIQ'){
$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>';
}
else if ($don->modepaymentcode=='VIR' || $don->modepaymentcode=='PRE' || $don->modepaymentcode=='CB'){
$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>';
}
else
{
$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>';
}
/*
if (empty($don->societe))
{
$CodeDon = '<td width="33%"><input type="checkbox" disabled="true" checked="checked" > 200 du CGI</td><td width="33%"><input type="checkbox" disabled="true" > 238 bis du CGI</td><td width="33%"><input type="checkbox" disabled="true" > 885-0 V bis A du CGI</td>';
}
else
{
$CodeDon = '<td width="33%"><input type="checkbox" disabled="true" > 200 du CGI</td><td width="33%"><input type="checkbox" disabled="true" checked="checked" > 238 bis du CGI</td><td width="33%"><input type="checkbox" disabled="true" > 885-0 V bis A du CGI</td>';
}
*/
// Define contents
$donmodel=DOL_DOCUMENT_ROOT ."/core/modules/dons/html_cerfafr.html";
$form = implode('', file($donmodel));
$form = str_replace('__REF__',$don->id,$form);
$form = str_replace('__DATE__',dol_print_date($don->date,'day',false,$outputlangs),$form);
//$form = str_replace('__IP__',$user->ip,$form); // TODO $user->ip not exist
$form = str_replace('__AMOUNT__', price($don->amount), $form);
$form = str_replace('__AMOUNTLETTERS__', $this->amountToLetters($don->amount),$form);
$form = str_replace('__CURRENCY__',$outputlangs->transnoentitiesnoconv("Currency".$currency),$form);
$form = str_replace('__CURRENCYCODE__',$conf->currency,$form);
$form = str_replace('__MAIN_INFO_SOCIETE_NOM__',$mysoc->name,$form);
$form = str_replace('__MAIN_INFO_SOCIETE_ADDRESS__',$mysoc->address,$form);
$form = str_replace('__MAIN_INFO_SOCIETE_ZIP__',$mysoc->zip,$form);
$form = str_replace('__MAIN_INFO_SOCIETE_TOWN__',$mysoc->town,$form);
$form = str_replace('__MAIN_INFO_SOCIETE_OBJECT__',$mysoc->object,$form);
$form = str_replace('__DONATOR_FIRSTNAME__',$don->firstname,$form);
$form = str_replace('__DONATOR_LASTNAME__',$don->lastname,$form);
$form = str_replace('__DONATOR_SOCIETE__',$don->societe,$form);
$form = str_replace('__DONATOR_STATUT__',$don->statut,$form);
$form = str_replace('__DONATOR_ADDRESS__',$don->address,$form);
$form = str_replace('__DONATOR_ZIP__',$don->zip,$form);
$form = str_replace('__DONATOR_TOWN__',$don->town,$form);
$form = str_replace('__PAYMENTMODE_LIB__ ', $paymentmode,$form);
$form = str_replace('__NOW__',dol_print_date($now,'day',false,$outputlangs),$form);
$form = str_replace('__DonationRef__',$outputlangs->trans("DonationRef"),$form);
$form = str_replace('__DonationTitle__',$outputlangs->trans("DonationTitle"),$form);
$form = str_replace('__DonationReceipt__',$outputlangs->trans("DonationReceipt"),$form);
$form = str_replace('__DonationRecipient__',$outputlangs->trans("DonationRecipient"),$form);
$form = str_replace('__DonationDatePayment__',$outputlangs->trans("DonationDatePayment"),$form);
$form = str_replace('__PaymentMode__',$outputlangs->trans("PaymentMode"),$form);
// $form = str_replace('__CodeDon__',$CodeDon,$form);
$form = str_replace('__Name__',$outputlangs->trans("Name"),$form);
$form = str_replace('__Address__',$outputlangs->trans("Address"),$form);
$form = str_replace('__Zip__',$outputlangs->trans("Zip"),$form);
$form = str_replace('__Town__',$outputlangs->trans("Town"),$form);
$form = str_replace('__Object__',$outputlangs->trans("Object"),$form);
$form = str_replace('__Donor__',$outputlangs->trans("Donor"),$form);
$form = str_replace('__Date__',$outputlangs->trans("Date"),$form);
$form = str_replace('__Signature__',$outputlangs->trans("Signature"),$form);
$form = str_replace('__Message__',$outputlangs->trans("Message"),$form);
$form = str_replace('__IConfirmDonationReception__',$outputlangs->trans("IConfirmDonationReception"),$form);
$form = str_replace('__DonationMessage__',$conf->global->DONATION_MESSAGE,$form);
$form = str_replace('__ModePaiement__', $ModePaiement,$form);
$frencharticle='';
if (preg_match('/fr/i',$outputlangs->defaultlang)) $frencharticle='<font size="+1">Article 200, 238 bis et 885-0 V bis A du code général des impôts (CGI)</font>';
$form = str_replace('__FrenchArticle__',$frencharticle,$form);
$frencheligibility='';
if (preg_match('/fr/i',$outputlangs->defaultlang)) $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 :';
$form = str_replace('__FrenchEligibility__',$frencheligibility,$form);
$art200='';
if (preg_match('/fr/i',$outputlangs->defaultlang)) {
if ($conf->global->DONATION_ART200 >= 1)
{
$art200='<input type="checkbox" disabled="true" checked="checked" >200 du CGI';
}
else
{
$art200='<input type="checkbox" disabled="true">200 du CGI';
}
}
$form = str_replace('__ARTICLE200__',$art200,$form);
$art238='';
if (preg_match('/fr/i',$outputlangs->defaultlang)) {
if ($conf->global->DONATION_ART238 >= 1)
{
$art238='<input type="checkbox" disabled="true" checked="checked" >238 bis du CGI';
}
else
{
$art238='<input type="checkbox" disabled="true">238 bis du CGI';
}
}
$form = str_replace('__ARTICLE238__',$art238,$form);
$art885='';
if (preg_match('/fr/i',$outputlangs->defaultlang)) {
if ($conf->global->DONATION_ART885 >= 1)
{
$art885='<input type="checkbox" disabled="true" checked="checked" >885-0 V bis du CGI';
}
else
{
$art885='<input type="checkbox" disabled="true">885-0 V bis du CGI';
}
}
$form = str_replace('__ARTICLE885__',$art885,$form);
// Save file on disk
dol_syslog("html_cerfafr::write_file $file");
$handle=fopen($file,"w");
fwrite($handle,$form);
fclose($handle);
if (! empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK));
$this->result = array('fullpath'=>$file);
return 1;
}
else
{
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
return 0;
}
}
else
{
$this->error=$langs->trans("ErrorConstantNotDefined","DON_OUTPUTDIR");
return 0;
}
}
/**
* numbers to letters
*
* @param mixed $montant amount
* @param mixed $devise1 devise 1 ex: euro
* @param mixed $devise2 devise 2 ex: centimes
* @return string amount in letters
*/
private function amountToLetters($montant, $devise1='', $devise2='')
{
$unite = array();
$dix = array();
$cent = array();
if(empty($devise1)) $dev1='euros';
else $dev1=$devise1;
if(empty($devise2)) $dev2='centimes';
else $dev2=$devise2;
$valeur_entiere=intval($montant);
$valeur_decimal=intval(round($montant-intval($montant), 2)*100);
$dix_c=intval($valeur_decimal%100/10);
$cent_c=intval($valeur_decimal%1000/100);
$unite[1]=$valeur_entiere%10;
$dix[1]=intval($valeur_entiere%100/10);
$cent[1]=intval($valeur_entiere%1000/100);
$unite[2]=intval($valeur_entiere%10000/1000);
$dix[2]=intval($valeur_entiere%100000/10000);
$cent[2]=intval($valeur_entiere%1000000/100000);
$unite[3]=intval($valeur_entiere%10000000/1000000);
$dix[3]=intval($valeur_entiere%100000000/10000000);
$cent[3]=intval($valeur_entiere%1000000000/100000000);
$chif=array('', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit', 'neuf', 'dix', 'onze', 'douze', 'treize', 'quatorze', 'quinze', 'seize', 'dix sept', 'dix huit', 'dix neuf');
$secon_c='';
$trio_c='';
for($i=1; $i<=3; $i++){
$prim[$i]='';
$secon[$i]='';
$trio[$i]='';
if($dix[$i]==0){
$secon[$i]='';
$prim[$i]=$chif[$unite[$i]];
}
else if($dix[$i]==1){
$secon[$i]='';
$prim[$i]=$chif[($unite[$i]+10)];
}
else if($dix[$i]==2){
if($unite[$i]==1){
$secon[$i]='vingt et';
$prim[$i]=$chif[$unite[$i]];
}
else {
$secon[$i]='vingt';
$prim[$i]=$chif[$unite[$i]];
}
}
else if($dix[$i]==3){
if($unite[$i]==1){
$secon[$i]='trente et';
$prim[$i]=$chif[$unite[$i]];
}
else {
$secon[$i]='trente';
$prim[$i]=$chif[$unite[$i]];
}
}
else if($dix[$i]==4){
if($unite[$i]==1){
$secon[$i]='quarante et';
$prim[$i]=$chif[$unite[$i]];
}
else {
$secon[$i]='quarante';
$prim[$i]=$chif[$unite[$i]];
}
}
else if($dix[$i]==5){
if($unite[$i]==1){
$secon[$i]='cinquante et';
$prim[$i]=$chif[$unite[$i]];
}
else {
$secon[$i]='cinquante';
$prim[$i]=$chif[$unite[$i]];
}
}
else if($dix[$i]==6){
if($unite[$i]==1){
$secon[$i]='soixante et';
$prim[$i]=$chif[$unite[$i]];
}
else {
$secon[$i]='soixante';
$prim[$i]=$chif[$unite[$i]];
}
}
else if($dix[$i]==7){
if($unite[$i]==1){
$secon[$i]='soixante et';
$prim[$i]=$chif[$unite[$i]+10];
}
else {
$secon[$i]='soixante';
$prim[$i]=$chif[$unite[$i]+10];
}
}
else if($dix[$i]==8){
if($unite[$i]==1){
$secon[$i]='quatre-vingts et';
$prim[$i]=$chif[$unite[$i]];
}
else {
$secon[$i]='quatre-vingt';
$prim[$i]=$chif[$unite[$i]];
}
}
else if($dix[$i]==9){
if($unite[$i]==1){
$secon[$i]='quatre-vingts et';
$prim[$i]=$chif[$unite[$i]+10];
}
else {
$secon[$i]='quatre-vingts';
$prim[$i]=$chif[$unite[$i]+10];
}
}
if($cent[$i]==1) $trio[$i]='cent';
else if($cent[$i]!=0 || $cent[$i]!='') $trio[$i]=$chif[$cent[$i]] .' cents';
}
$chif2=array('', 'dix', 'vingt', 'trente', 'quarante', 'cinquante', 'soixante', 'soixante-dix', 'quatre-vingts', 'quatre-vingts dix');
$secon_c=$chif2[$dix_c];
if($cent_c==1) $trio_c='cent';
else if($cent_c!=0 || $cent_c!='') $trio_c=$chif[$cent_c] .' cents';
if(($cent[3]==0 || $cent[3]=='') && ($dix[3]==0 || $dix[3]=='') && ($unite[3]==1))
$somme = $trio[3]. ' ' .$secon[3]. ' ' . $prim[3]. ' million ';
else if(($cent[3]!=0 && $cent[3]!='') || ($dix[3]!=0 && $dix[3]!='') || ($unite[3]!=0 && $unite[3]!=''))
$somme = $trio[3]. ' ' .$secon[3]. ' ' . $prim[3]. ' millions ';
else
$somme = $trio[3]. ' ' .$secon[3]. ' ' . $prim[3];
if(($cent[2]==0 || $cent[2]=='') && ($dix[2]==0 || $dix[2]=='') && ($unite[2]==1))
$somme = $somme.' mille ';
else if(($cent[2]!=0 && $cent[2]!='') || ($dix[2]!=0 && $dix[2]!='') || ($unite[2]!=0 && $unite[2]!=''))
$somme = $somme. $trio[2]. ' ' .$secon[2]. ' ' . $prim[2]. ' milles ';
else
$somme = $somme. $trio[2]. ' ' .$secon[2]. ' ' . $prim[2];
$somme = $somme. $trio[1]. ' ' .$secon[1]. ' ' . $prim[1];
$somme = $somme. ' '. $dev1 .' ' ;
if(($cent_c=='0' || $cent_c=='') && ($dix_c=='0' || $dix_c==''))
return $somme. ' et zéro '. $dev2;
else
return $somme. $trio_c. ' ' .$secon_c. ' ' . $dev2;
}
}