/** * Génère une facture au format PDF * * @param string $reference Reference de la facture * @param string $chemin Chemin du fichier PDF à générer. Si ce chemin est omi, le PDF est renvoyé au navigateur. * @access public * @return bool */ function genererFacture($reference, $chemin = null) { $requete = 'SELECT * FROM afup_facturation_forum WHERE reference=' . $this->_bdd->echapper($reference); $facture = $this->_bdd->obtenirEnregistrement($requete); $requete = 'SELECT * FROM afup_inscription_forum WHERE reference=' . $this->_bdd->echapper($reference); $inscriptions = $this->_bdd->obtenirTous($requete); require_once 'AFUP_Configuration.php'; $configuration = $GLOBALS['AFUP_CONF']; require_once 'AFUP_Pays.php'; $pays = new AFUP_Pays($this->_bdd); // Construction du PDF require_once 'AFUP_PDF_Facture.php'; $pdf = new AFUP_PDF_Facture($configuration); $pdf->AddPage(); $pdf->Cell(130, 5); $pdf->Cell(60, 5, 'Le ' . date('d/m/Y', isset($facture['date_facture']) && !empty($facture['date_facture']) ? $facture['date_facture'] : time())); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); if (empty($facture['societe'])) { $facture['societe'] = $facture['nom'] . " " . $facture['prenom']; } // A l'attention du client [adresse] $pdf->SetFont('Arial', 'BU', 10); $pdf->Cell(130, 5, utf8_decode('Objet : Facture n°' . $reference)); $pdf->SetFont('Arial', '', 10); $pdf->Ln(10); $pdf->MultiCell(130, 5, utf8_decode($facture['societe']) . "\n" . utf8_decode($facture['adresse']) . "\n" . utf8_decode($facture['code_postal']) . "\n" . utf8_decode($facture['ville']) . "\n" . utf8_decode($pays->obtenirNom($facture['id_pays']))); $pdf->Ln(15); $pdf->MultiCell(180, 5, utf8_decode("Facture concernant votre participation au forum organisé par l'Association Française des Utilisateurs de PHP (AFUP).")); if ($facture['informations_reglement']) { $pdf->Ln(10); $pdf->Cell(32, 5, utf8_decode('Référence client : ')); $infos = explode("\n", $facture['informations_reglement']); foreach ($infos as $info) { $pdf->Cell(100, 5, utf8_decode($info)); $pdf->Ln(); $pdf->Cell(32, 5); } } // Cadre $pdf->Ln(10); $pdf->SetFillColor(200, 200, 200); $pdf->Cell(50, 5, 'Type', 1, 0, 'L', 1); $pdf->Cell(100, 5, 'Personne inscrite', 1, 0, 'L', 1); $pdf->Cell(40, 5, 'Prix', 1, 0, 'L', 1); $total = 0; foreach ($inscriptions as $inscription) { $pdf->Ln(); $pdf->SetFillColor(255, 255, 255); switch ($inscription['type_inscription']) { case AFUP_FORUM_PREMIERE_JOURNEE: $code = 'FONC'; break; case AFUP_FORUM_DEUXIEME_JOURNEE: $code = 'TECH'; break; case AFUP_FORUM_2_JOURNEES: $code = '2JOU'; break; case AFUP_FORUM_2_JOURNEES_AFUP: $code = 'AFUP'; break; case AFUP_FORUM_2_JOURNEES_ETUDIANT: $code = 'ETUD'; break; case AFUP_FORUM_2_JOURNEES_PREVENTE: $code = 'PREV'; break; case AFUP_FORUM_2_JOURNEES_AFUP_PREVENTE: $code = 'AFUP-PRE'; break; case AFUP_FORUM_2_JOURNEES_ETUDIANT_PREVENTE: $code = 'ETUD-PRE'; break; case AFUP_FORUM_2_JOURNEES_COUPON: $code = 'COUPON'; break; case AFUP_FORUM_ORGANISATION: $code = 'ORGANISATION'; break; case AFUP_FORUM_SPONSOR: $code = 'SPONSOR'; break; case AFUP_FORUM_PRESSE: $code = 'PRESSE'; break; case AFUP_FORUM_CONFERENCIER: $code = 'CONFERENCIER'; break; case AFUP_FORUM_INVITATION: $code = 'INVITATION'; break; case AFUP_FORUM_PROJET: $code = 'PROJET'; break; case AFUP_FORUM_2_JOURNEES_SPONSOR: $code = '2_JOURNEES_SPONSOR'; break; case AFUP_FORUM_PROF: $code = 'PROF'; break; case AFUP_FORUM_PREMIERE_JOURNEE_ETUDIANT_PREVENTE: $code = 'PREMIERE_JOURNEE_ETUDIANT_PREVENTE'; break; case AFUP_FORUM_DEUXIEME_JOURNEE_ETUDIANT_PREVENTE: $code = 'DEUXIEME_JOURNEE_ETUDIANT_PREVENTE'; break; case AFUP_FORUM_2_JOURNEES_PREVENTE_ADHESION: $code = '2_JOURNEES_PREVENTE_ADHESION'; break; case AFUP_FORUM_PREMIERE_JOURNEE_AFUP: $code = 'PREMIERE_JOURNEE_AFUP'; break; case AFUP_FORUM_DEUXIEME_JOURNEE_AFUP: $code = 'DEUXIEME_JOURNEE_AFUP'; break; case AFUP_FORUM_PREMIERE_JOURNEE_ETUDIANT: $code = 'PREMIERE_JOURNEE_ETUDIANT'; break; case AFUP_FORUM_DEUXIEME_JOURNEE_ETUDIANT: $code = 'DEUXIEME_JOURNEE_ETUDIANT'; break; default: $code = 'XXX'; } $pdf->Cell(50, 5, $code, 1); $pdf->Cell(100, 5, utf8_decode($inscription['prenom']) . ' ' . utf8_decode($inscription['nom']), 1); $pdf->Cell(40, 5, utf8_decode($inscription['montant']) . utf8_decode(' '), 1); $total += $inscription['montant']; } if ($facture['type_reglement'] == 1) { // Paiement par chèque $pdf->Ln(); $pdf->Cell(50, 5, 'FRAIS', 1); $pdf->Cell(100, 5, utf8_decode('Paiement par chèque'), 1); $pdf->Cell(40, 5, '25' . utf8_decode(' '), 1); $total += 25; } $pdf->Ln(); $pdf->SetFillColor(225, 225, 225); $pdf->Cell(150, 5, 'TOTAL', 1, 0, 'L', 1); $pdf->Cell(40, 5, $total . utf8_decode(' '), 1, 0, 'L', 1); $pdf->Ln(15); if ($facture['etat'] == 4) { switch ($facture['type_reglement']) { case 0: $type = 'par CB'; break; case 1: $type = 'par chèque'; break; case 2: $type = 'par virement'; break; } $pdf->SetTextColor(255, 0, 0); $pdf->Cell(130, 5); $pdf->Cell(60, 5, utf8_decode('Payé ' . $type . ' le ' . date('d/m/Y', $facture['date_reglement']))); $pdf->SetTextColor(0, 0, 0); } $pdf->Ln(); $pdf->Cell(10, 5, 'TVA non applicable - art. 293B du CGI'); if (is_null($chemin)) { $pdf->Output('Facture - ' . ($facture['societe'] ? $facture['societe'] : $facture['nom'] . '_' . $facture['prenom']) . ' - ' . date('Y-m-d_H-i', $facture['date_facture']) . '.pdf', 'D'); } else { $pdf->Output($chemin, 'F'); } return $reference; }
/** * Génère une facture au format PDF * * @param int $id_cotisation Identifiant de la cotisation * @param string $chemin Chemin du fichier PDF à générer. Si ce chemin est omi, le PDF est renvoyé au navigateur. * @access public * @return int Le numero de la facture */ function genererFacture($id_cotisation, $chemin = null) { $requete = 'SELECT * FROM afup_cotisations WHERE id=' . $id_cotisation; $cotisation = $this->_bdd->obtenirEnregistrement($requete); $table = $cotisation['type_personne'] == AFUP_PERSONNES_MORALES ? 'afup_personnes_morales' : 'afup_personnes_physiques'; $requete = 'SELECT * FROM ' . $table . ' WHERE id=' . $cotisation['id_personne']; $personne = $this->_bdd->obtenirEnregistrement($requete); require_once 'Afup/AFUP_Configuration.php'; $configuration = $GLOBALS['AFUP_CONF']; // Construction du PDF require_once 'Afup/AFUP_PDF_Facture.php'; $pdf = new AFUP_PDF_Facture($configuration); $pdf->AddPage(); $pdf->Cell(130, 5); $pdf->Cell(60, 5, 'Le ' . date('d/m/Y', $cotisation['date_debut'])); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); // A l'attention du client [adresse] $pdf->SetFont('Arial', 'BU', 10); $pdf->Cell(130, 5, utf8_decode('Objet : Facture n°' . $cotisation['numero_facture'])); $pdf->SetFont('Arial', '', 10); if ($cotisation['type_personne'] == AFUP_PERSONNES_MORALES) { $nom = $personne['raison_sociale']; } else { $nom = $personne['prenom'] . ' ' . $personne['nom']; } $pdf->Ln(10); $pdf->MultiCell(130, 5, utf8_decode($nom . "\n" . $personne['adresse'] . "\n" . $personne['code_postal'] . "\n" . $personne['ville'])); $pdf->Ln(15); $pdf->MultiCell(180, 5, utf8_decode("Facture concernant votre adhésion à l'Association Française des Utilisateurs de PHP (AFUP).")); // Cadre $pdf->Ln(10); $pdf->SetFillColor(200, 200, 200); $pdf->Cell(50, 5, 'Code', 1, 0, 'L', 1); $pdf->Cell(100, 5, utf8_decode('Désignation'), 1, 0, 'L', 1); $pdf->Cell(40, 5, 'Prix', 1, 0, 'L', 1); $pdf->Ln(); $pdf->SetFillColor(255, 255, 255); $pdf->Cell(50, 5, 'ADH', 1); $pdf->Cell(100, 5, utf8_decode("Adhésion AFUP jusqu'au " . date('d/m/Y', $cotisation['date_fin'])), 1); $pdf->Cell(40, 5, utf8_decode($cotisation['montant'] . ' '), 1); $pdf->Ln(15); $pdf->Cell(10, 5, 'TVA non applicable - art. 293B du CGI'); $pdf->Ln(15); $pdf->Cell(10, 5, utf8_decode('Lors de votre règlement, merci de préciser la mention : "Facture n°' . $cotisation['numero_facture']) . '"'); if (is_null($chemin)) { $pdf->Output('facture-' . $cotisation['numero_facture'] . '.pdf', 'D'); } else { $pdf->Output($chemin, 'F'); } return $cotisation['numero_facture']; }
function genererFacture($reference, $chemin = null) { $requete = 'SELECT * FROM afup_compta_facture WHERE numero_facture=' . $this->_bdd->echapper($reference); $coordonnees = $this->_bdd->obtenirEnregistrement($requete); $requete = 'SELECT * FROM afup_compta_facture_details WHERE idafup_compta_facture=' . $this->_bdd->echapper($coordonnees['id']); $details = $this->_bdd->obtenirTous($requete); require_once 'Afup/AFUP_Configuration.php'; $configuration = $GLOBALS['AFUP_CONF']; require_once 'Afup/AFUP_Pays.php'; $pays = new AFUP_Pays($this->_bdd); // Construction du PDF require_once 'Afup/AFUP_PDF_Facture.php'; $pdf = new AFUP_PDF_Facture($configuration); $pdf->AddPage(); $pdf->Cell(130, 5); $pdf->Cell(60, 5, 'Le ' . date('d/m/Y', isset($coordonnees['date_facture']) && !empty($coordonnees['date_facture']) ? strtotime($coordonnees['date_facture']) : time())); $pdf->Ln(); $pdf->Ln(); $pdf->Ln(); // A l'attention du client [adresse] $pdf->SetFont('Arial', '', 10); $pdf->Ln(10); $pdf->setx(120); $pdf->MultiCell(130, 5, utf8_decode($coordonnees['societe']) . "\n" . utf8_decode($coordonnees['service']) . "\n" . utf8_decode($coordonnees['adresse']) . "\n" . utf8_decode($coordonnees['code_postal']) . "\n" . utf8_decode($coordonnees['ville']) . "\n" . utf8_decode($pays->obtenirNom($coordonnees['id_pays']))); $pdf->Ln(10); $pdf->SetFont('Arial', 'BU', 10); $pdf->Cell(0, 5, utf8_decode('Facture n° ' . $reference), 0, 0, "C"); $pdf->SetFont('Arial', '', 10); if ($coordonnees['ref_clt1'] || $coordonnees['ref_clt2'] || $coordonnees['ref_clt3']) { $pdf->Ln(15); $pdf->Cell(40, 5, utf8_decode('Repère(s) : ')); } if ($coordonnees['ref_clt1']) { $pdf->setx(30); $pdf->Cell(100, 5, utf8_decode($coordonnees['ref_clt1'])); $pdf->Ln(5); } if ($coordonnees['ref_clt2']) { $pdf->setx(30); $pdf->Cell(100, 5, utf8_decode($coordonnees['ref_clt2'])); $pdf->Ln(5); } if ($coordonnees['ref_clt3']) { $pdf->setx(30); $pdf->Cell(100, 5, utf8_decode($coordonnees['ref_clt3'])); $pdf->Ln(5); } $pdf->Ln(10); $pdf->MultiCell(180, 5, utf8_decode("Comme convenu, nous vous prions de trouver votre facture")); // Cadre $pdf->Ln(5); $pdf->SetFillColor(200, 200, 200); $pdf->Cell(30, 5, 'Type', 1, 0, 'L', 1); $pdf->Cell(80, 5, 'Description', 1, 0, 'L', 1); $pdf->Cell(20, 5, 'Quantite', 1, 0, 'L', 1); $pdf->Cell(30, 5, 'Prix', 1, 0, 'L', 1); $pdf->Cell(30, 5, 'Total', 1, 0, 'L', 1); $total = 0; switch ($coordonnees['devise_facture']) { case 'DOL': $devise = ' $'; break; case 'EUR': default: $devise = utf8_decode(' '); break; } $yInitial = $pdf->getY(); $columns = [0, 30, 110, 130, 160, 190]; foreach ($details as $detail) { if ($detail['quantite'] != 0) { $montant = $detail['quantite'] * $detail['pu']; $pdf->Ln(); $pdf->SetFillColor(255, 255, 255); $y = $pdf->GetY(); $x = $pdf->GetX(); $pdf->MultiCell(30, 5, $detail['ref'], 'T'); $x += 30; $pdf->SetXY($x, $y); $pdf->MultiCell(80, 5, utf8_decode($detail['designation']), 'T'); $x += 80; $pdf->SetXY($x, $y); $pdf->MultiCell(20, 5, utf8_decode($detail['quantite']), 'T', 0, "C"); $x += 20; $pdf->SetXY($x, $y); $pdf->MultiCell(30, 5, utf8_decode($detail['pu']) . $devise, 'T', 0, "R"); $x += 30; $pdf->SetXY($x, $y); $pdf->MultiCell(30, 5, utf8_decode($montant) . $devise, 'T', 0, "R"); $total += $montant; } } $pdf->Ln(); foreach ($columns as $column) { $pdf->Line($pdf->GetX() + $column, $yInitial, $pdf->GetX() + $column, $pdf->GetY()); } $pdf->SetFillColor(225, 225, 225); $pdf->Cell(160, 5, 'TOTAL', 1, 0, 'L', 1); $pdf->Cell(30, 5, $total . $devise, 1, 0, 'R', 1); $pdf->Ln(15); $pdf->Cell(10, 5, 'TVA non applicable - art. 293B du CGI'); $pdf->Ln(10); if ($coordonnees['observation']) { $pdf->Cell(10, 5, 'Observations : '); $pdf->Ln(5); $pdf->SetFont('Arial', '', 8); $pdf->MultiCell(130, 5, utf8_decode($coordonnees['observation'])); } if (is_null($chemin)) { $pdf->Output('Facture - ' . $coordonnees['societe'] . ' - ' . $coordonnees['date_facture'] . '.pdf', 'D'); } else { $pdf->Output($chemin, 'F'); } }