Euro symbols on text description dos not creat bad pdf coding

This commit is contained in:
Laurent Destailleur 2008-04-13 22:30:09 +00:00
parent 7335e61176
commit 56e9b9cef7

View File

@ -103,308 +103,311 @@ class pdf_crabe extends ModelePDFFactures
* \return int 1=ok, 0=ko * \return int 1=ok, 0=ko
*/ */
function write_file($fac,$outputlangs='') function write_file($fac,$outputlangs='')
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
if (! is_object($outputlangs)) $outputlangs=$langs; if (! is_object($outputlangs)) $outputlangs=$langs;
$outputlangs->load("main"); $outputlangs->load("main");
$outputlangs->load("dict"); $outputlangs->load("dict");
$outputlangs->load("companies"); $outputlangs->load("companies");
$outputlangs->load("bills"); $outputlangs->load("bills");
$outputlangs->load("products"); $outputlangs->load("products");
$outputlangs->setPhpLang(); $outputlangs->setPhpLang();
if ($conf->facture->dir_output) if ($conf->facture->dir_output)
{ {
// Définition de l'objet $fac (pour compatibilite ascendante) // Définition de l'objet $fac (pour compatibilite ascendante)
if (! is_object($fac)) if (! is_object($fac))
{ {
$id = $fac; $id = $fac;
$fac = new Facture($this->db,"",$id); $fac = new Facture($this->db,"",$id);
$ret=$fac->fetch($id); $ret=$fac->fetch($id);
} }
$deja_regle = $fac->getSommePaiement(); $deja_regle = $fac->getSommePaiement();
$amount_credit_not_included = $fac->getSommeCreditNote(); $amount_credit_not_included = $fac->getSommeCreditNote();
// Définition de $dir et $file // Définition de $dir et $file
if ($fac->specimen) if ($fac->specimen)
{ {
$dir = $conf->facture->dir_output; $dir = $conf->facture->dir_output;
$file = $dir . "/SPECIMEN.pdf"; $file = $dir . "/SPECIMEN.pdf";
} }
else else
{ {
$facref = sanitize_string($fac->ref); $facref = sanitize_string($fac->ref);
$dir = $conf->facture->dir_output . "/" . $facref; $dir = $conf->facture->dir_output . "/" . $facref;
$file = $dir . "/" . $facref . ".pdf"; $file = $dir . "/" . $facref . ".pdf";
} }
if (! file_exists($dir)) if (! file_exists($dir))
{ {
if (create_exdir($dir) < 0) if (create_exdir($dir) < 0)
{ {
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir); $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
return 0; return 0;
} }
} }
if (file_exists($dir)) if (file_exists($dir))
{ {
$nblignes = sizeof($fac->lignes); $nblignes = sizeof($fac->lignes);
// Protection et encryption du pdf // Protection et encryption du pdf
if ($conf->global->PDF_SECURITY_ENCRYPTION) if ($conf->global->PDF_SECURITY_ENCRYPTION)
{ {
$pdf=new FPDI_Protection('P','mm',$this->format); $pdf=new FPDI_Protection('P','mm',$this->format);
$pdfrights = array('print'); // Ne permet que l'impression du document $pdfrights = array('print'); // Ne permet que l'impression du document
$pdfuserpass = ''; // Mot de passe pour l'utilisateur final $pdfuserpass = ''; // Mot de passe pour l'utilisateur final
$pdfownerpass = NULL; // Mot de passe du propriétire, crée aléatoirement si pas défini $pdfownerpass = NULL; // Mot de passe du propriétire, crée aléatoirement si pas défini
$pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass); $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass);
} }
else else
{ {
$pdf=new FPDI('P','mm',$this->format); $pdf=new FPDI('P','mm',$this->format);
} }
$pdf->Open(); $pdf->Open();
$pdf->AddPage(); $pdf->AddPage();
$pdf->SetDrawColor(128,128,128); $pdf->SetDrawColor(128,128,128);
$pdf->SetTitle($fac->ref); $pdf->SetTitle($fac->ref);
$pdf->SetSubject($outputlangs->transnoentities("Invoice")); $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
$pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetCreator("Dolibarr ".DOL_VERSION);
$pdf->SetAuthor($user->fullname); $pdf->SetAuthor($user->fullname);
$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
$pdf->SetAutoPageBreak(1,0); $pdf->SetAutoPageBreak(1,0);
// Positionne $this->atleastonediscount si on a au moins une remise // Positionne $this->atleastonediscount si on a au moins une remise
for ($i = 0 ; $i < $nblignes ; $i++) for ($i = 0 ; $i < $nblignes ; $i++)
{ {
if ($fac->lignes[$i]->remise_percent) if ($fac->lignes[$i]->remise_percent)
{ {
$this->atleastonediscount++; $this->atleastonediscount++;
} }
} }
// Tete de page // Tete de page
$this->_pagehead($pdf, $fac, 1, $outputlangs); $this->_pagehead($pdf, $fac, 1, $outputlangs);
$pagenb = 1; $pagenb = 1;
$tab_top = 90; $tab_top = 90;
$tab_top_newpage = 50; $tab_top_newpage = 50;
$tab_height = 110; $tab_height = 110;
$tab_height_newpage = 180; $tab_height_newpage = 180;
// Affiche notes // Affiche notes
if ($fac->note_public) if ($fac->note_public)
{ {
$tab_top = 88; $tab_top = 88;
$pdf->SetFont('Arial','', 9); // Dans boucle pour gerer multi-page $pdf->SetFont('Arial','', 9); // Dans boucle pour gerer multi-page
$pdf->SetXY ($this->posxdesc-1, $tab_top); $pdf->SetXY ($this->posxdesc-1, $tab_top);
$pdf->MultiCell(190, 3, $fac->note_public, 0, 'J'); $pdf->MultiCell(190, 3, $fac->note_public, 0, 'J');
$nexY = $pdf->GetY(); $nexY = $pdf->GetY();
$height_note=$nexY-$tab_top; $height_note=$nexY-$tab_top;
// Rect prend une longueur en 3eme param // Rect prend une longueur en 3eme param
$pdf->SetDrawColor(192,192,192); $pdf->SetDrawColor(192,192,192);
$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
$tab_height = $tab_height - $height_note; $tab_height = $tab_height - $height_note;
$tab_top = $nexY+6; $tab_top = $nexY+6;
} }
else else
{ {
$height_note=0; $height_note=0;
} }
$iniY = $tab_top + 8; $iniY = $tab_top + 8;
$curY = $tab_top + 8; $curY = $tab_top + 8;
$nexY = $tab_top + 8; $nexY = $tab_top + 8;
// Boucle sur les lignes // Boucle sur les lignes
for ($i = 0 ; $i < $nblignes ; $i++) for ($i = 0 ; $i < $nblignes ; $i++)
{ {
$curY = $nexY; $curY = $nexY;
// Description de la ligne produit // Description de la ligne produit
$libelleproduitservice=dol_htmlentitiesbr($fac->lignes[$i]->libelle,1); $libelleproduitservice=dol_htmlentitiesbr($fac->lignes[$i]->libelle,1);
if ($fac->lignes[$i]->desc&&$fac->lignes[$i]->desc!=$fac->lignes[$i]->libelle) if ($fac->lignes[$i]->desc&&$fac->lignes[$i]->desc!=$fac->lignes[$i]->libelle)
{ {
if ($libelleproduitservice) $libelleproduitservice.="<br>"; if ($libelleproduitservice) $libelleproduitservice.="<br>";
if ($fac->lignes[$i]->desc == '(CREDIT_NOTE)' && $fac->lignes[$i]->fk_remise_except) if ($fac->lignes[$i]->desc == '(CREDIT_NOTE)' && $fac->lignes[$i]->fk_remise_except)
{ {
$discount=new DiscountAbsolute($this->db); $discount=new DiscountAbsolute($this->db);
$discount->fetch($fac->lignes[$i]->fk_remise_except); $discount->fetch($fac->lignes[$i]->fk_remise_except);
$libelleproduitservice=dol_htmlentitiesbr($langs->trans("DiscountFromCreditNote",$discount->ref_facture_source),1); $libelleproduitservice=dol_htmlentitiesbr($langs->trans("DiscountFromCreditNote",$discount->ref_facture_source),1);
} }
else else
{ {
if ($fac->lignes[$i]->produit_id) if ($fac->lignes[$i]->produit_id)
{ {
$libelleproduitservice.=dol_htmlentitiesbr($fac->lignes[$i]->desc,1); $libelleproduitservice.=dol_htmlentitiesbr($fac->lignes[$i]->desc,1);
} }
else else
{ {
// On verifie si les lignes personnalisees sont formatees avec fckeditor $fac->lignes[$i]->desc='€zaaaa';
$libelleproduitservice.=dol_htmlentitiesbr($fac->lignes[$i]->desc,1); //print dol_string_is_good_iso($fac->lignes[$i]->desc);
} //print dol_htmlentitiesbr($fac->lignes[$i]->desc);
} //print exit;
} $libelleproduitservice.=dol_htmlentitiesbr($fac->lignes[$i]->desc,1);
}
}
}
// Si ligne associee a un code produit // Si ligne associee a un code produit
if ($fac->lignes[$i]->produit_id) if ($fac->lignes[$i]->produit_id)
{ {
$prodser = new Product($this->db); $prodser = new Product($this->db);
$prodser->fetch($fac->lignes[$i]->produit_id); $prodser->fetch($fac->lignes[$i]->produit_id);
// On ajoute la ref // On ajoute la ref
if ($prodser->ref) if ($prodser->ref)
{ {
$prefix_prodserv = ""; $prefix_prodserv = "";
if($prodser->isservice()) if($prodser->isservice())
{ {
$prefix_prodserv = $outputlangs->transnoentities("Service")." "; $prefix_prodserv = $outputlangs->transnoentities("Service")." ";
} }
else else
{ {
$prefix_prodserv = $outputlangs->transnoentities("Product")." "; $prefix_prodserv = $outputlangs->transnoentities("Product")." ";
} }
$libelleproduitservice=$prefix_prodserv.$prodser->ref." - ".$libelleproduitservice; $libelleproduitservice=$prefix_prodserv.$prodser->ref." - ".$libelleproduitservice;
} }
} }
if ($fac->lignes[$i]->date_start && $fac->lignes[$i]->date_end) if ($fac->lignes[$i]->date_start && $fac->lignes[$i]->date_end)
{ {
// Affichage duree si il y en a une // Affichage duree si il y en a une
$libelleproduitservice.="<br>".dol_htmlentitiesbr("(".$outputlangs->transnoentities("From")." ".dolibarr_print_date($fac->lignes[$i]->date_start)." ".$outputlangs->transnoentities("to")." ".dolibarr_print_date($fac->lignes[$i]->date_end).")",1); $libelleproduitservice.="<br>".dol_htmlentitiesbr("(".$outputlangs->transnoentities("From")." ".dolibarr_print_date($fac->lignes[$i]->date_start)." ".$outputlangs->transnoentities("to")." ".dolibarr_print_date($fac->lignes[$i]->date_end).")",1);
} }
//if ($i==0) { print $libelleproduitservice; exit; } //if ($i==0) { print $libelleproduitservice; exit; }
$pdf->SetFont('Arial','', 9); // Dans boucle pour gerer multi-page $pdf->SetFont('Arial','', 9); // Dans boucle pour gerer multi-page
// Description // Description
$pdf->writeHTMLCell($this->posxtva-$this->posxdesc-1, 3, $this->posxdesc-1, $curY, $libelleproduitservice, 0, 1); $pdf->writeHTMLCell($this->posxtva-$this->posxdesc-1, 3, $this->posxdesc-1, $curY, $libelleproduitservice, 0, 1);
$pdf->SetFont('Arial','', 9); // On repositionne la police par defaut $pdf->SetFont('Arial','', 9); // On repositionne la police par defaut
$nexY = $pdf->GetY(); $nexY = $pdf->GetY();
// TVA // TVA
$pdf->SetXY ($this->posxtva, $curY); $pdf->SetXY ($this->posxtva, $curY);
$pdf->MultiCell($this->posxup-$this->posxtva-1, 3, vatrate($fac->lignes[$i]->tva_tx,1,$fac->lignes[$i]->info_bits), 0, 'R'); $pdf->MultiCell($this->posxup-$this->posxtva-1, 3, vatrate($fac->lignes[$i]->tva_tx,1,$fac->lignes[$i]->info_bits), 0, 'R');
// Prix unitaire HT avant remise // Prix unitaire HT avant remise
$pdf->SetXY ($this->posxup, $curY); $pdf->SetXY ($this->posxup, $curY);
$pdf->MultiCell($this->posxqty-$this->posxup-1, 3, price($fac->lignes[$i]->subprice), 0, 'R', 0); $pdf->MultiCell($this->posxqty-$this->posxup-1, 3, price($fac->lignes[$i]->subprice), 0, 'R', 0);
// Quantity // Quantity
$pdf->SetXY ($this->posxqty, $curY); $pdf->SetXY ($this->posxqty, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 3, $fac->lignes[$i]->qty, 0, 'R'); // Enough for 6 chars $pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 3, $fac->lignes[$i]->qty, 0, 'R'); // Enough for 6 chars
// Remise sur ligne // Remise sur ligne
$pdf->SetXY ($this->posxdiscount, $curY); $pdf->SetXY ($this->posxdiscount, $curY);
if ($fac->lignes[$i]->remise_percent) if ($fac->lignes[$i]->remise_percent)
{ {
$pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 4, dolibarr_print_reduction($fac->lignes[$i]->remise_percent), 0, 'R'); $pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 4, dolibarr_print_reduction($fac->lignes[$i]->remise_percent), 0, 'R');
} }
// Total HT ligne // Total HT ligne
$pdf->SetXY ($this->postotalht, $curY); $pdf->SetXY ($this->postotalht, $curY);
$total = price($fac->lignes[$i]->total_ht); $total = price($fac->lignes[$i]->total_ht);
$pdf->MultiCell(26, 4, $total, 0, 'R', 0); $pdf->MultiCell(26, 4, $total, 0, 'R', 0);
// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
$tvaligne=$fac->lignes[$i]->total_tva; $tvaligne=$fac->lignes[$i]->total_tva;
if ($fac->remise_percent) $tvaligne-=($tvaligne*$fac->remise_percent)/100; if ($fac->remise_percent) $tvaligne-=($tvaligne*$fac->remise_percent)/100;
$vatrate=(string) $fac->lignes[$i]->tva_tx; $vatrate=(string) $fac->lignes[$i]->tva_tx;
if ($fac->lignes[$i]->info_bits & 0x01 == 0x01) $vatrate.='*'; if ($fac->lignes[$i]->info_bits & 0x01 == 0x01) $vatrate.='*';
$this->tva[$vatrate] += $tvaligne; $this->tva[$vatrate] += $tvaligne;
$nexY+=2; // Passe espace entre les lignes $nexY+=2; // Passe espace entre les lignes
if ($nexY > ($tab_top+$tab_height) && $i < ($nblignes - 1)) if ($nexY > ($tab_top+$tab_height) && $i < ($nblignes - 1))
{ {
if ($pagenb == 1) if ($pagenb == 1)
{ {
$this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs); $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs);
} }
else else
{ {
$this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs); $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
} }
$this->_pagefoot($pdf,$outputlangs); $this->_pagefoot($pdf,$outputlangs);
// Nouvelle page // Nouvelle page
$pdf->AddPage(); $pdf->AddPage();
$pagenb++; $pagenb++;
$this->_pagehead($pdf, $fac, 0, $outputlangs); $this->_pagehead($pdf, $fac, 0, $outputlangs);
$nexY = $tab_top_newpage + 8; $nexY = $tab_top_newpage + 8;
$pdf->SetTextColor(0,0,0); $pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','', 10); $pdf->SetFont('Arial','', 10);
} }
} }
// Affiche cadre tableau // Affiche cadre tableau
if ($pagenb == 1) if ($pagenb == 1)
{
$this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
$bottomlasttab=$tab_top + $tab_height + 1;
}
else
{
$this->_tableau($pdf, $tab_top_newpage, $tab_height, $nexY, $outputlangs);
$bottomlasttab=$tab_top_newpage + $tab_height + 1;
}
// Affiche zone infos
$posy=$this->_tableau_info($pdf, $fac, $bottomlasttab, $outputlangs);
// Affiche zone totaux
$posy=$this->_tableau_tot($pdf, $fac, $deja_regle, $bottomlasttab, $outputlangs);
// Affiche zone versements
if ($deja_regle || $amount_credit_not_included)
{ {
$posy=$this->_tableau_versements($pdf, $fac, $posy, $outputlangs); $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
} $bottomlasttab=$tab_top + $tab_height + 1;
}
else
{
$this->_tableau($pdf, $tab_top_newpage, $tab_height, $nexY, $outputlangs);
$bottomlasttab=$tab_top_newpage + $tab_height + 1;
}
// Pied de page // Affiche zone infos
$this->_pagefoot($pdf,$outputlangs); $posy=$this->_tableau_info($pdf, $fac, $bottomlasttab, $outputlangs);
$pdf->AliasNbPages();
$pdf->Close(); // Affiche zone totaux
$posy=$this->_tableau_tot($pdf, $fac, $deja_regle, $bottomlasttab, $outputlangs);
$pdf->Output($file); // Affiche zone versements
if ($deja_regle || $amount_credit_not_included)
{
$posy=$this->_tableau_versements($pdf, $fac, $posy, $outputlangs);
}
// Pied de page
$this->_pagefoot($pdf,$outputlangs);
$pdf->AliasNbPages();
$pdf->Close();
$pdf->Output($file);
$langs->setPhpLang(); // On restaure langue session $langs->setPhpLang(); // On restaure langue session
return 1; // Pas d'erreur return 1; // Pas d'erreur
} }
else else
{ {
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir); $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
$langs->setPhpLang(); // On restaure langue session $langs->setPhpLang(); // On restaure langue session
return 0; return 0;
} }
}
else
{
$this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR");
$langs->setPhpLang(); // On restaure langue session
return 0;
} }
$this->error=$langs->trans("ErrorUnknown"); else
{
$this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR");
$langs->setPhpLang(); // On restaure langue session
return 0;
}
$this->error=$langs->trans("ErrorUnknown");
$langs->setPhpLang(); // On restaure langue session $langs->setPhpLang(); // On restaure langue session
return 0; // Erreur par defaut return 0; // Erreur par defaut
} }
/** /**