Skip to content

Commit

Permalink
Merge pull request #1364 from stakovicz/feat-1347-invoice-id-generator
Browse files Browse the repository at this point in the history
Génération des ids de facture
  • Loading branch information
stakovicz authored Nov 28, 2023
2 parents 871b2b2 + f80950c commit 595e14d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions sources/Afup/Comptabilite/Facture.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,21 @@ function transfertDevis($numero_devis)

function genererNumeroFacture()
{
// afup_cotisations
$requete = 'SELECT';
$requete .= " MAX(CAST(SUBSTRING_INDEX(numero_facture, '-', -1) AS UNSIGNED)) + 1 ";
$requete .= 'FROM';
$requete .= ' afup_compta_facture ';
$requete .= 'WHERE';
$requete .= ' LEFT(numero_facture, 4)=' . $this->_bdd->echapper(date('Y'));
$index = $this->_bdd->obtenirUn($requete);
return date('Y') . '-' . (is_null($index) ? 1 : $index);
$year = (int) date('Y');

$sql = "SELECT MAX(CAST(SUBSTRING_INDEX(numero_facture, '-', -1) AS UNSIGNED)) + 1
FROM afup_compta_facture
WHERE LEFT(numero_facture, 4)=";
$index = $this->_bdd->obtenirUn($sql.$year);

// index null = changement d'année
// on va chercher l'index de l'année dernière
if (null === $index) {
$index = $this->_bdd->obtenirUn($sql.($year-1));
$index = (int) (is_null($index) ? 1 : $index);
}

return "$year-$index";
}

function genererNumeroDevis()
Expand Down

0 comments on commit 595e14d

Please sign in to comment.