alpha_full/admin/extensions/makeFact/123factPdf_contenu.php
2026-04-06 22:58:51 +02:00

286 lines
9.7 KiB
PHP
Executable File

<?php
$nomFicAppelant = basename(__FILE__);
class monpdf extends FPDF{
// -----------------------------------------------------
// Constructeur1
// -----------------------------------------------------
function pdf() {
parent::__construct();
$this->ZoomMode="real";
// $this->SetCreator("Eric DIENOT, www.123ventes.com");
$this->SetCreator($contactMsg[10],$_SESSION['siteNomTech']);
}
// -----------------------------------------------------
// En-tete de la facture
// -----------------------------------------------------
function hautDePage($nomGestionnaire, $raisonSoc, $add, $villeAdm, $cp, $pays, $tel, $idCde, $dateCdeCrea) {
global $includeAdminDesign;
if (empty($adresseCli2)) $adresseCli2="-";
if (empty($adrLiv2)) $adrLiv2="-";
$position=0;
date_default_timezone_set( 'Europe/Paris' ) ;
if (empty($lg)) $lg='FRA';
if ($lg=='FRA') {
setlocale (LC_TIME, 'fr_FR.utf8','fra');
}
if ($lg=='ENG') {
setlocale (LC_TIME, 'en_US.utf8','ang');
}
if (empty($today)) {
$dateTimeObj = new DateTime('now', new DateTimeZone('Europe/Paris'));
$today = IntlDateFormatter::formatObject($dateTimeObj, "y-MM-dd_HH-mm:ss", 'fr');
}
// les messages finalement pas besoin de les passer en param on peut mettre un include ici
$includePathConf="../../_conf";
include ("../_include/dataBaseConnect.php");
include ("../_include/req/09-init.enteteMsgList.php");
include ("../_include/req/06-init.cliMsgList.php");
include ("../_include/req/07-init.cdeMsgList.php");
// logo
$posVertical0=10;
// $this->Image("https://123ventes.com/images/logo-bleu.svg",10,$posVertical0,20);
$this->Image($includeAdminDesign. "/logo-bleu.png",10,$posVertical0,20);
// raison sociale
$posVertical1=$posVertical0 + 38;
$this->SetFont('helvetica','B',12);
$this->SetTextColor(0,0,200);
$this->SetXY(10,$posVertical1);
$this->Cell(50,5,"\n\n".ltrim(strip_tags("123ventes")),0,2,'',false);
// infos business
$this->SetFont('helvetica','',12);
$this->SetTextColor(0,0,200);
$this->MultiCell(100,5,strip_tags("Eric DIENOT"). " \n".strip_tags("Siret : 9188008710017"). "\n".strip_tags('Tel : +33 614 993 058'). "\n",0,'L',false);
// adresse business
$this->SetFont('helvetica','B',12);
$this->SetTextColor(0,0,200);
$this->SetXY(110,$posVertical1 + 7);
$this->SetFont('helvetica','',12);
$this->SetTextColor(0,0,0);
$this->MultiCell(100,5,strip_tags('713 Chemin du camp'). "\n".strip_tags('06140'). " ".strip_tags('Vence'). "\n".strip_tags('FRANCE'). "\n",0,'L',false);
// Titre = Facture
$posVertical2=$posVertical1+25;
$this->SetXY(10,$posVertical2);
$this->SetFillColor(200,200,200);
$this->SetFont('helvetica','B',15);
$this->Cell(190,6,strtoupper($cdeMsg[86]),1,2,'C',true);
$this->SetFont('helvetica','',12);
$posVertical3=$posVertical2+10;
$this->SetXY(60,$posVertical3);
$this->MultiCell(130,5,mb_convert_encoding($cdeMsg[86]. " n° : ", 'ISO-8859-1', 'UTF-8') .$idCde. "\n" .$cdeMsg[74]. " : " .$today. "\n",'',false);
// blocs infos client fact
$posVertical4=$posVertical3 + 20;
$this->SetXY(10,$posVertical4);
$this->SetFillColor(200,200,200);
$this->SetFont('helvetica','B',12);
$this->Cell(90,6,$clientMsg[2],1,2,'C',true);
$this->SetFont('helvetica','',12);
$pays=strip_tags($pays);
$this->MultiCell(90,5,"\n" .$nomGestionnaire. "\n" .$add. "\n" .$cp. " " .$villeAdm. "\n" .$pays. "\n\n",'LRB','L',false);
$position=$this->getY();
if ($this->getY()>$position) {
$position=$this->getY();
}
$this->SetXY(10,$position+5);
}
// -----------------------------------------------------
// Préparation de la generation de la table
// -----------------------------------------------------
function tableArticles($designation, $tva, $quantite, $totalTTC) {
$header = array();
$datas = array();
// Tableau contenant les titres des colonnes panier
$header=array( mb_convert_encoding('Désignation', 'ISO-8859-1', 'UTF-8'), mb_convert_encoding('Tva', 'ISO-8859-1', 'UTF-8'), mb_convert_encoding('Quantité', 'ISO-8859-1', 'UTF-8'), mb_convert_encoding('Total TTC', 'ISO-8859-1', 'UTF-8') );
$datas[0]=array( mb_convert_encoding($designation, 'ISO-8859-1', 'UTF-8'), $tva, $quantite, $totalTTC .chr(128));
// Tableau contenant la largeur des colonnes
$w=array(120,20,20,25);
// Tableau contenant le centrage des colonnes
$al=array('C','C','C','C');
// -----------------------------------------------------
// Génération de la table panier proprement dite
// -----------------------------------------------------
$this->table($header, $w, $al, $datas);
}
// -----------------------------------------------------
// Pied de page
// -----------------------------------------------------
function Footer() {
// Positionnement 1,5 cm du bas
$this->SetY(-15);
// Police helvetica italique 8
$this->SetFont('helvetica','I',8);
// Numéro de page
$this->Cell(0,4,'Page ' .$this->PageNo(). '/{nb}',0,2,'C');
$this->MultiCell(0,4,mb_convert_encoding($_SESSION['siteNomTech'], 'ISO-8859-1', 'UTF-8'). "\n",0,'C',false);
}
// -----------------------------------------------------
// Impression de l'entree du tableau
// -----------------------------------------------------
function printTableHeader($header,$w) {
// Couleurs, epaisseur du trait et police grasse
$this->SetFillColor(200,200,200);
$this->SetTextColor(0);
$this->SetDrawColor(0,0,0);
$this->SetFont('helvetica','B',9);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
$this->Ln();
// Restauration des couleurs et de la police pour les données du tableau
$this->SetFillColor(245,245,245);
$this->SetTextColor(0);
$this->SetFont('helvetica');
}
// -----------------------------------------------------
// Generation du tableau
// table(données de l'entete tableau, largeur des colonnes, alignement des colonnes, donnees)
// -----------------------------------------------------
function table($header,$w,$al,$datas) {
// Impression de l'entete tableau
$this->SetLineWidth(.3);
$this->printTableHeader($header,$w);
$posStartX=$this->getX();
$posBeforeX=$posStartX;
$posBeforeY=$this->getY();
$posAfterY=$posBeforeY;
$posStartY=$posBeforeY;
// On parcours le tableau des données
foreach($datas as $row) {
$posBeforeX=$posStartX;
$posBeforeY=$posAfterY;
// On verifie qu'il n'y a pas débordement de page.
$nb=0;
for($i=0;$i<count($header);$i++) {
$nb=max($nb,$this->NbLines($w[$i],$row[$i]));
}
$h=6*$nb;
// Effectue un saut de page si il y a debordement
$resultat = $this->CheckPageBreak($h,$w,$header,$posStartX,$posStartY,$posAfterY);
if ($resultat>0) {
$posAfterY=$resultat;
$posBeforeY=$resultat;
$posStartY=$resultat;
}
// Impression de la ligne
for($i=0;$i<count($header);$i++) {
$this->MultiCell($w[$i],6,strip_tags($row[$i]),'',$al[$i],false);
// On enregistre la plus grande hauteur de cellule
if ($posAfterY<$this->getY()) {
$posAfterY=$this->getY();
}
$posBeforeX+=$w[$i];
$this->setXY($posBeforeX,$posBeforeY);
}
// Trace de la ligne du dessous
$this->Line($posStartX,$posAfterY,$posBeforeX,$posAfterY);
$this->setXY($posStartX,$posAfterY);
}
// Trace des colonnes
$this->PrintCols($w,$posStartX,$posStartY,$posAfterY);
}
// -----------------------------------------------------
// Tracé des colonnes
// -----------------------------------------------------
function PrintCols($w,$posStartX,$posStartY,$posAfterY) {
$this->Line($posStartX,$posStartY,$posStartX,$posAfterY);
$colX=$posStartX;
// On trace la ligne pour chaque colonne
foreach($w as $row) {
$colX+=$row;
$this->Line($colX,$posStartY,$colX,$posAfterY);
}
}
// -----------------------------------------------------
// Verification du debordement de page
// -----------------------------------------------------
function CheckPageBreak($h,$w,$header,$posStartX,$posStartY,$posAfterY) {
// Si la hauteur h provoque un debordement, saut de page manuel
if ($this->GetY()+$h>$this->PageBreakTrigger) {
// On imprime les colonnes de la page actuelle
$this->PrintCols($w,$posStartX,$posStartY,$posAfterY);
// On ajoute une page
$this->AddPage();
// On reimprime l'enttte du tableau
$this->printTableHeader($header,$w);
// On renvoi la position courante sur la nouvelle page
return $this->GetY();
}
// On a pas effectue de saut on revoie 0
return 0;
}
// -----------------------------------------------------
// Calcule le nombre de lignes qu'occupe un MultiCell de largeur w
// -----------------------------------------------------
function NbLines($w,$txt) {
$cw=&$this->CurrentFont['cw'];
if ($w==0)
$w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
$s=str_replace("\r",'',$txt);
$nb=strlen($s);
if ($nb>0 and $s[$nb-1]=="\n")
$nb--;
$sep=-1;
$i=0;
$j=0;
$l=0;
$nl=1;
while($i<$nb) {
$c=$s[$i];
if ($c=="\n") {
$i++;$sep=-1;$j=$i;$l=0;$nl++;
continue;
}
if ($c==' ') $sep=$i;
$l+=$cw[$c];
if ($l>$wmax) {
if ($sep==-1)
{ if ($i==$j) $i++; }
else
$i=$sep+1;
$sep=-1;
$j=$i;
$l=0;
$nl++;
}
else
$i++;
}
return $nl;
}
}
?>