Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ js_dist
# uploads
/htdocs/uploads

/htdocs/factures

/app/config/parameters.yml
/build/
/phpunit.xml
Expand Down
36 changes: 24 additions & 12 deletions sources/Afup/Comptabilite/Facture.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

class Facture
{
private $cipher = 'aes-256-gcm';
private $key = 'PaiementFactureAFUP_AFUP';

/**
* @var \Afup\Site\Utils\Base_De_Donnees
*/
Expand Down Expand Up @@ -421,6 +424,20 @@ function genererFacture($reference, $chemin = null)
$requete = 'SELECT * FROM afup_compta_facture_details WHERE idafup_compta_facture=' . $this->_bdd->echapper($coordonnees['id']);
$details = $this->_bdd->obtenirTous($requete);

$pdf_name = sprintf('Facture - %s - %s.pdf', $coordonnees['societe'], $coordonnees['date_facture']);

$download = is_null($chemin);
if (is_null($chemin)) {
$chemin = AFUP_CHEMIN_RACINE . 'factures' . DIRECTORY_SEPARATOR . 'fact' . $reference . '.pdf';
}

if (!is_null($chemin) && is_readable($chemin)) {
header('Content-Type: application/pdf');
header('Content-Length: ' . strlen(file_get_contents($chemin)));
header('Content-disposition: attachment; filename="' . $pdf_name . '"');

return;
}

$configuration = $GLOBALS['AFUP_CONF'];

Expand Down Expand Up @@ -552,24 +569,21 @@ function genererFacture($reference, $chemin = null)
$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');
}
$pdf->Output($chemin, 'F');

if ($download) {
$pdf->Output($pdf_name, 'D');
}
}

/**
* Envoi par mail d'une facture au format PDF
*
* @param string $reference Reference de la facturation
* @access public
* @return bool Succès de l'envoi
*/
function envoyerFacture($reference)
{

$configuration = $GLOBALS['AFUP_CONF'];

$personne = $this->obtenirParNumeroFacture($reference, 'email, nom, prenom');
Expand All @@ -584,19 +598,17 @@ function envoyerFacture($reference)
$corps .= $configuration->obtenir('afup|adresse') . "\n";
$corps .= $configuration->obtenir('afup|code_postal') . " " . $configuration->obtenir('afup|ville') . "\n";

$chemin_facture = AFUP_CHEMIN_RACINE . 'cache' . DIRECTORY_SEPARATOR . 'fact' . $reference . '.pdf';
$chemin_facture = AFUP_CHEMIN_RACINE . 'factures' . DIRECTORY_SEPARATOR . 'fact' . $reference . '.pdf';
$this->genererFacture($reference, $chemin_facture);

$ok = Mailing::envoyerMail(
$GLOBALS['conf']->obtenir('mails|email_expediteur'),
array($personne['email'], $personne['nom']),
[$personne['email'], $personne['nom']],
$sujet,
$corps,
array('file' => array(array($chemin_facture, 'facture-' . $reference . '.pdf')))
['file' => [[$chemin_facture, 'facture-' . $reference . '.pdf']]]
);

@unlink($chemin_facture);

return $ok;
}
}