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