From 26fbb91d0047e901afffbc6e21e7767d546fec9b Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 21 Oct 2026 16:18:35 +0200 Subject: fonction livre de recettes --- bin/livre_recettes.php | 46 +++------------------------------------------- src/functions.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/bin/livre_recettes.php b/bin/livre_recettes.php index 85e3265..859725e 100755 --- a/bin/livre_recettes.php +++ b/bin/livre_recettes.php @@ -14,6 +14,7 @@ // chemins des dossiers et nom de la base require('src/File.php'); require('src/Config.php'); // lit le config.ini et gère certaines erreurs (exemple les / aux chemins manquants) +require('src/functions.php'); Config::readFile('config/config.ini'); Config::hydrate(); @@ -50,46 +51,5 @@ catch(Exception $e){ die; } - -// requête -foreach($years as $year){ - /*$date_debut = $year . '-01-01'; - $date_fin = $year . '-12-31'; - - $debut = new DateTime($date_debut, new DateTimeZone('Europe/Paris')); - $fin = new DateTime($date_fin, new DateTimeZone('Europe/Paris'));; - $fin->setTime(23, 59, 59);*/ - - $dql = 'SELECT n FROM Prestation n WHERE n.date >= :debut AND n.date <= :fin'; - $bulk_data = $entityManager - ->createQuery($dql) - ->setParameter('debut', $year . '-01-01') - ->setParameter('fin', $year . '-12-31') - ->getResult(); - - // affichage - $result = "client|date|type|mode paiement|débours|total HT|salaire CESU|code presta\n"; - - foreach($bulk_data as $presta){ - if($presta->getTypePresta() !== 'devis' && $presta->getTypePresta() !== 'non_vendue'){ - $result .= $presta->getClient()->getPrenomNom() . '|' - . $presta->getDate() . '|' - . $presta->getTypePresta() . '|' - . $presta->getModePaiement() . '|'; - - if($presta->getTypePresta() === 'facture'){ - $result .= $presta->getTotalPieces() . '|'; - $result .= $presta->getTotalHT() . '||'; - } - elseif($presta->getTypePresta() === 'cesu'){ - $result .= '||' . $presta->getSalaire() . '|'; - } - elseif($presta->getTypePresta() === 'location'){ - $result .= '|' . (string)($presta->getLoyer() * (float)$presta->getLoyersPayes()) . '||'; - } - $result .= $presta->getCodePresta() . "\n"; - } - } - file_put_contents('data/livre_recettes_' . $year . '.csv', $result); // sortie fichier - echo $result . "\n"; // sortie console -} +// fichiers et sortie console +makeRecipeBook($entityManager, $years); \ No newline at end of file diff --git a/src/functions.php b/src/functions.php index d9fbfca..6042eaf 100644 --- a/src/functions.php +++ b/src/functions.php @@ -1,6 +1,7 @@ stdout pour cacher un message inutile return $command; } + +// appelée par bin/livre_recettes.php +function makeRecipeBook(EntityManager $entityManager, array $years): void +{ + foreach($years as $year){ + /*$date_debut = $year . '-01-01'; + $date_fin = $year . '-12-31'; + + $debut = new DateTime($date_debut, new DateTimeZone('Europe/Paris')); + $fin = new DateTime($date_fin, new DateTimeZone('Europe/Paris'));; + $fin->setTime(23, 59, 59);*/ + + $dql = 'SELECT n FROM Prestation n WHERE n.date >= :debut AND n.date <= :fin'; + $bulk_data = $entityManager + ->createQuery($dql) + ->setParameter('debut', $year . '-01-01') + ->setParameter('fin', $year . '-12-31') + ->getResult(); + + // affichage + $result = "client|date|type|mode paiement|débours|total HT|salaire CESU|code presta\n"; + + foreach($bulk_data as $presta){ + if($presta->getTypePresta() !== 'devis' && $presta->getTypePresta() !== 'non_vendue'){ + $result .= $presta->getClient()->getPrenomNom() . '|' + . $presta->getDate() . '|' + . $presta->getTypePresta() . '|' + . $presta->getModePaiement() . '|'; + + if($presta->getTypePresta() === 'facture'){ + $result .= $presta->getTotalPieces() . '|'; + $result .= $presta->getTotalHT() . '||'; + } + elseif($presta->getTypePresta() === 'cesu'){ + $result .= '||' . $presta->getSalaire() . '|'; + } + elseif($presta->getTypePresta() === 'location'){ + $result .= '|' . (string)($presta->getLoyer() * (float)$presta->getLoyersPayes()) . '||'; + } + $result .= $presta->getCodePresta() . "\n"; + } + } + file_put_contents('data/livre_recettes_' . $year . '.csv', $result); // sortie fichier + echo $result . "\n"; // sortie console + } +} \ No newline at end of file -- cgit v1.2.3