30require_once DOL_DOCUMENT_ROOT.
'/core/modules/dons/modules_don.php';
31require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/functionsnumtoword.lib.php';
46 public $version =
'dolibarr';
51 public $position = 60;
64 $this->
name =
"Cerfa HTML FR";
65 $this->
description = $langs->trans(
'DonationsReceiptModel').
' - fr_FR - Cerfa 11580*04';
92 public function write_file($don, $outputlangs, $currency =
'')
98 $id = (!is_object($don) ? $don :
'');
100 if (!is_object($outputlangs)) {
101 $outputlangs = $langs;
105 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"donations"));
107 $currency = !empty($currency) ? $currency :
$conf->currency;
109 if (!empty(
$conf->don->dir_output)) {
111 if (!is_object($don)) {
112 $don =
new Don($this->db);
113 $ret = $don->fetch(
$id);
118 if (!empty($don->specimen)) {
119 $dir =
$conf->don->dir_output;
120 $file = $dir.
"/SPECIMEN.html";
123 $dir =
$conf->don->dir_output.
"/".$donref;
124 $file = $dir.
"/".$donref.
".html";
127 if (!file_exists($dir)) {
129 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
134 if (file_exists($dir)) {
135 $formclass =
new Form($this->db);
139 $formclass->load_cache_types_paiements();
143 $modepaymentid = !empty($don->mode_reglement_id) ? $don->mode_reglement_id : $don->modepaymentid;
144 if ($modepaymentid) {
145 $paymentmode = !empty($formclass->cache_types_paiements[(
int) $modepaymentid][
'label']) ? $formclass->cache_types_paiements[$modepaymentid][
'label'] :
'';
149 $modepaymentcode = !empty($formclass->cache_types_paiements[(
int) $modepaymentid][
'code']) ? $formclass->cache_types_paiements[(int) $modepaymentid][
'code'] :
"";
150 if ($modepaymentcode ==
'CHQ') {
151 $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>';
152 } elseif ($modepaymentcode ==
'LIQ') {
153 $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>';
154 } elseif ($modepaymentcode ==
'VIR' || $modepaymentcode ==
'PRE' || $modepaymentcode ==
'CB') {
155 $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>';
157 $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>';
175 $donatorsociete = (string) $don->societe;
176 $donatorlastname = (string) $don->lastname;
177 $donatorfirstname = (string) $don->firstname;
178 $donatoraddress = (string) $don->address;
179 $donatorzip = (string) $don->zip;
180 $donatortown = (string) $don->town;
182 if (!empty($don->socid) && $don->socid > 0) {
183 $donatorthirdparty =
new Societe($this->db);
184 if ($donatorthirdparty->fetch($don->socid) > 0) {
185 if (
dol_strlen(trim($donatorsociete.$donatorlastname.$donatorfirstname)) == 0) {
188 $donatorsociete = (string) $donatorthirdparty->name;
191 $donatoraddress = (string) $donatorthirdparty->address;
194 $donatorzip = (string) $donatorthirdparty->zip;
197 $donatortown = (string) $donatorthirdparty->town;
200 dol_syslog(
"html_cerfafr::write_file Failed to load thirdparty ".$don->socid.
" linked to donation ".$don->id.
", donator block will remain empty - ".$donatorthirdparty->error, LOG_ERR);
204 if (
dol_strlen(trim($donatorsociete.$donatorlastname.$donatorfirstname)) == 0) {
205 dol_syslog(
"html_cerfafr::write_file No name found for the donator of donation ".$don->id.
", the receipt will not be compliant", LOG_WARNING);
209 $donmodel = DOL_DOCUMENT_ROOT.
"/core/modules/dons/html_cerfafr.html";
211 $form = file_get_contents($donmodel);
214 $form = str_replace(
'__REF__', (
string) $don->id, $form);
215 $form = str_replace(
'__DATE__',
dol_print_date($don->date,
'day',
false, $outputlangs), $form);
217 $form = str_replace(
'__AMOUNT__',
price($don->amount), $form);
218 $form = str_replace(
'__AMOUNT_TEXT__',
dol_convertToWord($don->amount, $outputlangs, $outputlangs->transnoentitiesnoconv(
"Currency".$currency),
true), $form);
220 $form = str_replace(
'__DONATOR_FIRSTNAME__',
dol_escape_htmltag($donatorfirstname), $form);
223 $donatorlastnameprefix = (
dol_strlen(trim($donatorsociete)) > 0 &&
dol_strlen(trim($donatorlastname)) > 0) ?
'<br>' :
'';
224 $form = str_replace(
'__DONATOR_LASTNAME__', $donatorlastnameprefix.dol_escape_htmltag($donatorlastname), $form);
225 $form = str_replace(
'__DONATOR_SOCIETE__',
dol_escape_htmltag($donatorsociete), $form);
227 $form = str_replace(
'__DONATOR_STATUT__', (
string) $don->statut, $form);
232 $form = str_replace(
'__PAYMENTMODE_LIB__ ', (
string) $paymentmode, $form);
233 $form = str_replace(
'__NOW__',
dol_print_date($now,
'day',
false, $outputlangs), $form);
234 $form = str_replace(
'__DONATION_PAYMENT_MODE__', $ModePaiement, $form);
235 $form = str_replace(
'__DONATION_MESSAGE__',
getDolGlobalString(
'DONATION_MESSAGE'), $form);
238 $substitutionkey = getCommonSubstitutionArray($outputlangs, 0,
null, $don);
244 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
245 $frencharticle =
'<font size="+1">Article 200, 238 bis et 978 du code général des impôts (CGI)</font>';
247 $form = str_replace(
'__FrenchArticle__', $frencharticle, $form);
249 $frencheligibility =
'';
250 if (preg_match(
'/fr/i', $outputlangs->defaultlang)) {
251 $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 :';
253 $form = str_replace(
'__FrenchEligibility__', $frencheligibility, $form);
256 if (
$mysoc->country_code ==
'FR') {
258 $art200 =
'<input type="checkbox" disabled="true" checked="checked" >200 du CGI';
260 $art200 =
'<input type="checkbox" disabled="true">200 du CGI';
263 $form = str_replace(
'__ARTICLE200__', $art200, $form);
266 if (
$mysoc->country_code ==
'FR') {
268 $art238 =
'<input type="checkbox" disabled="true" checked="checked" >238 bis du CGI';
270 $art238 =
'<input type="checkbox" disabled="true">238 bis du CGI';
273 $form = str_replace(
'__ARTICLE238__', $art238, $form);
276 if (
$mysoc->country_code ==
'FR') {
278 $art978 =
'<input type="checkbox" disabled="true" checked="checked" >978 du CGI';
280 $art978 =
'<input type="checkbox" disabled="true">978 du CGI';
283 $form = str_replace(
'__ARTICLE978__', $art978, $form);
287 $handle = fopen($file,
"w");
288 fwrite($handle, $form);
292 $this->result = array(
'fullpath' => $file);
296 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
300 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"DON_OUTPUTDIR");
$id
Support class for third parties, contacts, members, users or resources.
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage donations.
Parent class of subscription templates.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to generate document for subscriptions.
write_file($don, $outputlangs, $currency='')
Write the object to document file to disk.
isEnabled()
Return if a module can be used or not.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_convertToWord($num, $langs, $currency='', $centimes=false)
Function to return a number into a text.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
$conf db name
Only used if Module[ID]Name translation string is not found.