From 23936ef2f56f147855c498d917e3243e42d93dc1 Mon Sep 17 00:00:00 2001 From: polo Date: Sat, 18 Jul 2026 11:07:33 +0200 Subject: =?UTF-8?q?ann=C3=A9e=20au=20choix=20et=20fichier=20csv=20dans=20b?= =?UTF-8?q?in/libre=5Frecettes.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/livre_recettes.php | 99 ++++++++++++++++++++++++++++++++------------------ "\303\240 faire.txt" | 2 + 2 files changed, 66 insertions(+), 35 deletions(-) diff --git a/bin/livre_recettes.php b/bin/livre_recettes.php index 63bcdec..22c5c88 100755 --- a/bin/livre_recettes.php +++ b/bin/livre_recettes.php @@ -22,45 +22,74 @@ makeFolder(Config::$pdf_path); //require 'src/model/doctrine-bootstrap.php'; require __DIR__ . '/../src/model/doctrine-bootstrap.php'; // chemin absolu + +// année en paramètre +$years = []; +try{ + if($argc === 1){ + $years[0] = new DateTime()->format('Y') . "\n"; + } + elseif($argc > 1){ + for($i = 0; $i < $argc - 1; $i++){ + $year = filter_var($argv[$i + 1], FILTER_VALIDATE_INT); + if($year === false){ + throw new InvalidArgumentException("Année invalide: saisir un ou plusieurs nombres entiers ou aucun\n"); + } + $years[$i] = (string)$year; + } + } + else{ + throw new LogicException('Erreur de logique: $argc ne peut être inférieur à 1' . "\n"); + } +} +catch(Exception $e){ + echo $e->getMessage(); + die; +} + + // requête -$date_debut = '2024-01-01'; -$date_fin = '2024-12-31'; +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); + $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', $debut->getTimestamp()) - ->setParameter('fin', $fin->getTimestamp()) - ->getResult(); + $dql = 'SELECT n FROM Prestation n WHERE n.date >= :debut AND n.date <= :fin'; + $bulk_data = $entityManager + ->createQuery($dql) + ->setParameter('debut', $debut->getTimestamp()) + ->setParameter('fin', $fin->getTimestamp()) + ->getResult(); -// affichage -echo "client|date|type|mode paiement|débours|total HT|salaire CESU|code presta\n"; + // 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'){ - $date = new DateTime()->setTimestamp($presta->getDate()); - - echo $presta->getClient()->getPrenomNom() . '|' - . $date->format('d/m/Y') . '|' - . $presta->getTypePresta() . '|' - . $presta->getModePaiement() . '|'; - - if($presta->getTypePresta() === 'facture'){ - echo $presta->getFacture()->getTotalPieces() . '|'; - echo $presta->getFacture()->getTotalHT() . '||'; - } - elseif($presta->getTypePresta() === 'cesu'){ - echo '||' . $presta->getCESU()->getSalaire() . '|'; - } - elseif($presta->getTypePresta() === 'location'){ - echo '|' . (string)($presta->getLocation()->getLoyer() * (float)$presta->getLocation()->getLoyersPayes()) . '||'; + foreach($bulk_data as $presta){ + if($presta->getTypePresta() !== 'devis' && $presta->getTypePresta() !== 'non_vendue'){ + $date = new DateTime()->setTimestamp($presta->getDate()); + + $result .= $presta->getClient()->getPrenomNom() . '|' + . $date->format('d/m/Y') . '|' + . $presta->getTypePresta() . '|' + . $presta->getModePaiement() . '|'; + + if($presta->getTypePresta() === 'facture'){ + $result .= $presta->getFacture()->getTotalPieces() . '|'; + $result .= $presta->getFacture()->getTotalHT() . '||'; + } + elseif($presta->getTypePresta() === 'cesu'){ + $result .= '||' . $presta->getCESU()->getSalaire() . '|'; + } + elseif($presta->getTypePresta() === 'location'){ + $result .= '|' . (string)($presta->getLocation()->getLoyer() * (float)$presta->getLocation()->getLoyersPayes()) . '||'; + } + + $result .= $presta->getCodePresta() . "\n"; + } } - - echo $presta->getCodePresta(); - echo "\n"; - } + file_put_contents('data/livre_recettes_' . $year . '.csv', $result); // sortie fichier + echo $result . "\n"; // sortie console } diff --git "a/\303\240 faire.txt" "b/\303\240 faire.txt" index 5c38aa0..646f534 100644 --- "a/\303\240 faire.txt" +++ "b/\303\240 faire.txt" @@ -6,6 +6,8 @@ une fenêtre au lancement pour prévenir si la BDD ou le mapping ne sont pas cr exécuter la commande: php bin/doctrine orm:schema-tool:create et en afficher la sortie dans la console et si possible dans la fenêtre +relier ZenitySetup et les fonctions getAllWithWindowFileds() + changer les fichiers dans "pub" factoriser la partie 4 dans 3_modify_data.php -- cgit v1.2.3