23require_once DOL_DOCUMENT_ROOT.
'/core/modules/dons/modules_don.php';
24require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
25require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
26require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/functionsnumtoword.lib.php';
40 public $version =
'dolibarr';
45 public $heightforfooter;
50 public $position = 50;
62 $langs->loadLangs(array(
"main",
"donations"));
65 $this->
name =
"Standard";
66 $this->
description = $langs->trans(
'DonationsReceiptModel').
' - '.$langs->trans(
'DocumentModelStandardPDF');
70 $this->page_largeur = $formatarray[
'width'];
71 $this->page_hauteur = $formatarray[
'height'];
72 $this->format = array($this->page_largeur, $this->page_hauteur);
77 $this->corner_radius =
getDolGlobalInt(
'MAIN_PDF_FRAME_CORNER_RADIUS', 0);
78 $this->option_logo = 1;
79 $this->option_multilang = 1;
87 if (!$this->emetteur->country_code) {
88 $this->emetteur->country_code = substr($langs->defaultlang, -2);
113 public function write_file($don, $outputlangs, $currency =
'')
116 global $user,
$conf, $langs, $hookmanager;
118 if (!is_object($outputlangs)) {
119 $outputlangs = $langs;
123 $outputlangs->charset_output =
'ISO-8859-1';
126 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"donations"));
128 $currency = !empty($currency) ? $currency :
$conf->currency;
130 if (empty(
$conf->don->dir_output)) {
131 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"DON_OUTPUTDIR");
135 if (!is_object($don)) {
137 $don =
new Don($this->db);
142 if (!empty($don->specimen)) {
143 $dir =
$conf->don->dir_output;
144 $file = $dir.
"/SPECIMEN.pdf";
147 $dir =
$conf->don->dir_output.
"/".$donref;
148 $file = $dir.
"/".$donref.
".pdf";
151 if (!file_exists($dir)) {
153 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
159 if (!is_object($hookmanager)) {
160 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
163 $hookmanager->initHooks(array(
'pdfgeneration'));
164 $parameters = array(
'file' => $file,
'object' => $don,
'outputlangs' => $outputlangs);
166 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $don, $action);
170 $this->heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
171 $pdf->setAutoPageBreak(
true, $this->heightforfooter);
173 if (class_exists(
'TCPDF')) {
174 $pdf->setPrintHeader(
false);
175 $pdf->setPrintFooter(
false);
181 $pagecount = $pdf->setSourceFile(
$conf->mycompany->dir_output.
'/'.
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
182 $tplidx = $pdf->importPage(1);
186 $pdf->SetDrawColor(128, 128, 128);
188 $pdf->SetTitle($outputlangs->convToOutputCharset($outputlangs->transnoentities(
"DonationReceipt").
" ".$don->ref));
189 $pdf->SetSubject($outputlangs->transnoentities(
"DonationReceipt"));
190 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
191 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
192 $pdf->SetKeyWords($outputlangs->convToOutputCharset($don->ref).
" ".$outputlangs->transnoentities(
"DonationReceipt"));
194 $pdf->SetCompression(
false);
198 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
201 if (!empty($tplidx)) {
202 $pdf->useTemplate($tplidx);
207 $posy = $this->
_pagehead($pdf, $don, $donor, $outputlangs);
209 $posy = $this->
tableauDon($pdf, $don, $posy + 8, $outputlangs, $currency);
212 $notetoshow = empty($don->note_public) ?
'' : (string) $don->note_public;
219 $pdf->SetFont(
'',
'', $default_font_size - 1);
220 $pdf->writeHTMLCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 3, $this->marge_gauche, $posy + 6,
dol_htmlentitiesbr($notetoshow), 0, 1);
221 $posy = $pdf->GetY();
227 $nbpages = $pdf->getNumPages();
228 for ($i = 1; $i <= $nbpages; $i++) {
230 $pdf->setAutoPageBreak(
false, 0);
231 $this->
_pagefoot($pdf, $don, $outputlangs);
233 if (method_exists($pdf,
'AliasNbPages')) {
234 $pdf->AliasNbPages();
239 $pdf->Output($file,
'F');
242 $hookmanager->initHooks(array(
'pdfgeneration'));
243 $parameters = array(
'file' => $file,
'object' => $don,
'outputlangs' => $outputlangs);
245 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
246 $this->warnings = $hookmanager->warnings;
248 $this->error = $hookmanager->error;
249 $this->errors = $hookmanager->errors;
256 $this->result = array(
'fullpath' => $file);
272 protected function tableauDon(&$pdf, $don, $posy, $outputlangs, $currency)
275 $width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
278 $pdf->SetTextColor(0, 0, 0);
279 $pdf->SetFont(
'',
'', $default_font_size);
280 $pdf->SetXY($this->marge_gauche, $posy);
281 $pdf->MultiCell($width, 4, $outputlangs->transnoentities(
"DonationReceivedAmount"), 0,
'L');
282 $posy = $pdf->GetY() + 4;
285 $amount = (float)
price2num($don->amount,
'MT');
286 $pdf->SetFillColor(230, 230, 230);
287 $pdf->RoundedRect($this->marge_gauche, $posy, $width, 16, $this->corner_radius,
'1234',
'F');
288 $pdf->SetFont(
'',
'B', $default_font_size + 4);
289 $pdf->SetXY($this->marge_gauche + 2, $posy + 2);
290 $pdf->MultiCell($width - 4, 6,
price($amount, 0, $outputlangs, 1, -1,
'MT', $currency), 0,
'C');
292 if ($amountinletters) {
293 $pdf->SetFont(
'',
'I', $default_font_size - 1);
294 $pdf->SetXY($this->marge_gauche + 2, $posy + 9);
295 $pdf->MultiCell($width - 4, 4, $outputlangs->convToOutputCharset($amountinletters), 0,
'C');
301 $details[] = array($outputlangs->transnoentities(
"DonationDate"),
dol_print_date($don->date,
'day',
false, $outputlangs,
true));
302 if (!empty($don->mode_reglement_code)) {
303 $details[] = array($outputlangs->transnoentities(
"PaymentMode"), $outputlangs->transnoentitiesnoconv(
"PaymentType".$don->mode_reglement_code) !=
"PaymentType".$don->mode_reglement_code ? $outputlangs->transnoentitiesnoconv(
"PaymentType".$don->mode_reglement_code) : (string) $don->mode_reglement);
305 if (
isModEnabled(
'project') && !empty($don->fk_project) && $don->fetchProject() > 0 && is_object($don->project)) {
306 $outputlangs->load(
"projects");
307 $details[] = array($outputlangs->transnoentities(
"Project"), $don->project->ref.(empty($don->project->title) ?
'' :
' - '.$don->project->title));
310 $pdf->SetFont(
'',
'', $default_font_size - 1);
311 foreach ($details as $detail) {
312 $pdf->SetXY($this->marge_gauche, $posy);
313 $pdf->MultiCell($widthlabel, 5, $detail[0], 0,
'L');
314 $pdf->SetXY($this->marge_gauche + $widthlabel, $posy);
315 $pdf->MultiCell($width - $widthlabel, 5, $outputlangs->convToOutputCharset($detail[1]), 0,
'L');
316 $posy = max($posy + 5, $pdf->GetY());
339 if ($posy + 10 + $heightbox > $this->page_hauteur - $this->heightforfooter) {
341 $posy = $this->marge_haute;
344 $posx = $this->page_largeur - $this->marge_droite - $widthbox;
345 $place = (string) $this->emetteur->town;
348 $pdf->SetTextColor(0, 0, 0);
349 $pdf->SetFont(
'',
'', $default_font_size - 1);
350 $pdf->SetXY($posx, $posy);
351 $pdf->MultiCell($widthbox, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
352 $pdf->SetXY($posx, $posy + 5);
353 $pdf->MultiCell($widthbox, 4, $outputlangs->transnoentities(
"Signature"), 0,
'L');
354 $pdf->RoundedRect($posx, $posy + 10, $widthbox, $heightbox, $this->corner_radius,
'1234',
'D');
356 return $posy + 10 + $heightbox;
370 protected function _pagehead(&$pdf, $don, $donor, $outputlangs)
379 $pdf->SetTextColor(0, 0, 60);
380 $pdf->SetFont(
'',
'B', $default_font_size + 3);
383 $posy = $this->marge_haute;
384 $posx = $this->page_largeur - $this->marge_droite - $w;
386 $pdf->SetXY($this->marge_gauche, $posy);
389 if ($this->emetteur->logo) {
390 $logodir =
$conf->mycompany->dir_output;
391 if (!empty(
$conf->mycompany->multidir_output[$don->entity ??
$conf->entity])) {
392 $logodir =
$conf->mycompany->multidir_output[$don->entity ??
$conf->entity];
395 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
397 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
399 if (is_readable($logo)) {
401 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
403 $pdf->SetTextColor(200, 0, 0);
404 $pdf->SetFont(
'',
'B', $default_font_size - 2);
405 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
406 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
409 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
413 $pdf->SetFont(
'',
'B', $default_font_size + 3);
414 $pdf->SetXY($posx, $posy);
415 $pdf->SetTextColor(0, 0, 60);
416 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"DonationReceipt"), 0,
'R');
419 $pdf->SetFont(
'',
'B', $default_font_size);
420 $pdf->SetXY($posx, $posy);
421 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset((
string) $don->ref), 0,
'R');
424 $pdf->SetFont(
'',
'', $default_font_size - 1);
425 $pdf->SetXY($posx, $posy);
426 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
dol_now(),
'day',
false, $outputlangs,
true), 0,
'R');
432 if ($this->page_largeur < 210) {
435 $posx = $this->marge_gauche;
437 $posx = $this->page_largeur - $this->marge_droite - 82;
440 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur,
null,
null, 0,
'source', $don);
442 $pdf->SetTextColor(0, 0, 0);
443 $pdf->SetFont(
'',
'', $default_font_size - 2);
444 $pdf->SetXY($posx, $posy - 5);
445 $pdf->MultiCell(82, 5, $outputlangs->transnoentities(
"DonationRecipient"), 0,
'L');
446 $pdf->SetFillColor(230, 230, 230);
447 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
448 $pdf->SetTextColor(0, 0, 60);
450 $pdf->SetXY($posx + 2, $posy + 3);
451 $pdf->SetFont(
'',
'B', $default_font_size);
452 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
453 $pdf->SetXY($posx + 2, $pdf->GetY());
454 $pdf->SetFont(
'',
'', $default_font_size - 1);
455 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
458 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
460 $posx = $this->marge_gauche;
464 if ($donor[
'address'] !==
'') {
465 $carac_donor .= $donor[
'address'].
"\n";
467 $carac_donor .= trim($donor[
'zip'].
' '.$donor[
'town']);
468 if ($donor[
'country_code'] !==
'' && $donor[
'country_code'] != $this->emetteur->country_code) {
469 $carac_donor .=
"\n".$donor[
'country'];
472 $pdf->SetTextColor(0, 0, 0);
473 $pdf->SetFont(
'',
'', $default_font_size - 2);
474 $pdf->SetXY($posx + 2, $posy - 5);
475 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"Donor"), 0,
'L');
476 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
478 $pdf->SetXY($posx + 2, $posy + 3);
479 $pdf->SetFont(
'',
'B', $default_font_size);
480 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($donor[
'name']), 0,
'L');
481 $pdf->SetXY($posx + 2, $pdf->GetY());
482 $pdf->SetFont(
'',
'', $default_font_size - 1);
483 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($carac_donor), 0,
'L');
485 $pdf->SetTextColor(0, 0, 0);
487 return $posy + $hautcadre;
501 protected function _pagefoot(&$pdf, $don, $outputlangs, $hidefreetext = 0)
504 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
505 return pdf_pagefoot($pdf, $outputlangs,
'DONATION_MESSAGE', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $don, $showdetails, $hidefreetext, $this->page_largeur);
$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.
getDonorInfos($don, $outputlangs)
Return the identity of the donor of a donation.
Class to generate a PDF donation receipt with the standard model.
__construct($db)
Constructor.
tableauDon(&$pdf, $don, $posy, $outputlangs, $currency)
Show the amount and the details of the donation.
write_file($don, $outputlangs, $currency='')
Write the donation receipt to a PDF file on disk.
isEnabled()
Return if a module can be used or not.
_pagehead(&$pdf, $don, $donor, $outputlangs)
Show top header of page.
signatureArea(&$pdf, $don, $posy, $outputlangs)
Show the place, date and signature area of the receipt.
_pagefoot(&$pdf, $don, $outputlangs, $hidefreetext=0)
Show footer of page.
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.
if(!function_exists( 'dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
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.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
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).
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
pdf_pagehead($pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
pdf_pagefoot($pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
$conf db name
Only used if Module[ID]Name translation string is not found.