diff options
| author | polo <ordipolo@gmx.fr> | 2026-07-18 11:07:33 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-07-18 11:07:33 +0200 |
| commit | 23936ef2f56f147855c498d917e3243e42d93dc1 (patch) | |
| tree | ecf4430a1d12ed59b035bc6fde5f9a361d06968b /bin | |
| parent | a8a6c6178efc97247c4859e183e4360f52d8893e (diff) | |
| download | AppliGestionPHP-23936ef2f56f147855c498d917e3243e42d93dc1.tar.gz AppliGestionPHP-23936ef2f56f147855c498d917e3243e42d93dc1.tar.bz2 AppliGestionPHP-23936ef2f56f147855c498d917e3243e42d93dc1.zip | |
année au choix et fichier csv dans bin/libre_recettes.php
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/livre_recettes.php | 99 |
1 files changed, 64 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); | |||
| 22 | //require 'src/model/doctrine-bootstrap.php'; | 22 | //require 'src/model/doctrine-bootstrap.php'; |
| 23 | require __DIR__ . '/../src/model/doctrine-bootstrap.php'; // chemin absolu | 23 | require __DIR__ . '/../src/model/doctrine-bootstrap.php'; // chemin absolu |
| 24 | 24 | ||
| 25 | |||
| 26 | // année en paramètre | ||
| 27 | $years = []; | ||
| 28 | try{ | ||
| 29 | if($argc === 1){ | ||
| 30 | $years[0] = new DateTime()->format('Y') . "\n"; | ||
| 31 | } | ||
| 32 | elseif($argc > 1){ | ||
| 33 | for($i = 0; $i < $argc - 1; $i++){ | ||
| 34 | $year = filter_var($argv[$i + 1], FILTER_VALIDATE_INT); | ||
| 35 | if($year === false){ | ||
| 36 | throw new InvalidArgumentException("Année invalide: saisir un ou plusieurs nombres entiers ou aucun\n"); | ||
| 37 | } | ||
| 38 | $years[$i] = (string)$year; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | else{ | ||
| 42 | throw new LogicException('Erreur de logique: $argc ne peut être inférieur à 1' . "\n"); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | catch(Exception $e){ | ||
| 46 | echo $e->getMessage(); | ||
| 47 | die; | ||
| 48 | } | ||
| 49 | |||
| 50 | |||
| 25 | // requête | 51 | // requête |
| 26 | $date_debut = '2024-01-01'; | 52 | foreach($years as $year){ |
| 27 | $date_fin = '2024-12-31'; | 53 | $date_debut = $year . '-01-01'; |
| 54 | $date_fin = $year . '-12-31'; | ||
| 28 | 55 | ||
| 29 | $debut = new DateTime($date_debut, new DateTimeZone('Europe/Paris')); | 56 | $debut = new DateTime($date_debut, new DateTimeZone('Europe/Paris')); |
| 30 | $fin = new DateTime($date_fin, new DateTimeZone('Europe/Paris'));; | 57 | $fin = new DateTime($date_fin, new DateTimeZone('Europe/Paris'));; |
| 31 | $fin->setTime(23, 59, 59); | 58 | $fin->setTime(23, 59, 59); |
| 32 | 59 | ||
| 33 | $dql = 'SELECT n FROM Prestation n WHERE n.date >= :debut AND n.date <= :fin'; | 60 | $dql = 'SELECT n FROM Prestation n WHERE n.date >= :debut AND n.date <= :fin'; |
| 34 | $bulk_data = $entityManager | 61 | $bulk_data = $entityManager |
| 35 | ->createQuery($dql) | 62 | ->createQuery($dql) |
| 36 | ->setParameter('debut', $debut->getTimestamp()) | 63 | ->setParameter('debut', $debut->getTimestamp()) |
| 37 | ->setParameter('fin', $fin->getTimestamp()) | 64 | ->setParameter('fin', $fin->getTimestamp()) |
| 38 | ->getResult(); | 65 | ->getResult(); |
| 39 | 66 | ||
| 40 | // affichage | 67 | // affichage |
| 41 | echo "client|date|type|mode paiement|débours|total HT|salaire CESU|code presta\n"; | 68 | $result = "client|date|type|mode paiement|débours|total HT|salaire CESU|code presta\n"; |
| 42 | 69 | ||
| 43 | foreach($bulk_data as $presta){ | 70 | foreach($bulk_data as $presta){ |
| 44 | if($presta->getTypePresta() !== 'devis' && $presta->getTypePresta() !== 'non_vendue'){ | 71 | if($presta->getTypePresta() !== 'devis' && $presta->getTypePresta() !== 'non_vendue'){ |
| 45 | $date = new DateTime()->setTimestamp($presta->getDate()); | 72 | $date = new DateTime()->setTimestamp($presta->getDate()); |
| 46 | 73 | ||
| 47 | echo $presta->getClient()->getPrenomNom() . '|' | 74 | $result .= $presta->getClient()->getPrenomNom() . '|' |
| 48 | . $date->format('d/m/Y') . '|' | 75 | . $date->format('d/m/Y') . '|' |
| 49 | . $presta->getTypePresta() . '|' | 76 | . $presta->getTypePresta() . '|' |
| 50 | . $presta->getModePaiement() . '|'; | 77 | . $presta->getModePaiement() . '|'; |
| 51 | 78 | ||
| 52 | if($presta->getTypePresta() === 'facture'){ | 79 | if($presta->getTypePresta() === 'facture'){ |
| 53 | echo $presta->getFacture()->getTotalPieces() . '|'; | 80 | $result .= $presta->getFacture()->getTotalPieces() . '|'; |
| 54 | echo $presta->getFacture()->getTotalHT() . '||'; | 81 | $result .= $presta->getFacture()->getTotalHT() . '||'; |
| 55 | } | 82 | } |
| 56 | elseif($presta->getTypePresta() === 'cesu'){ | 83 | elseif($presta->getTypePresta() === 'cesu'){ |
| 57 | echo '||' . $presta->getCESU()->getSalaire() . '|'; | 84 | $result .= '||' . $presta->getCESU()->getSalaire() . '|'; |
| 58 | } | 85 | } |
| 59 | elseif($presta->getTypePresta() === 'location'){ | 86 | elseif($presta->getTypePresta() === 'location'){ |
| 60 | echo '|' . (string)($presta->getLocation()->getLoyer() * (float)$presta->getLocation()->getLoyersPayes()) . '||'; | 87 | $result .= '|' . (string)($presta->getLocation()->getLoyer() * (float)$presta->getLocation()->getLoyersPayes()) . '||'; |
| 88 | } | ||
| 89 | |||
| 90 | $result .= $presta->getCodePresta() . "\n"; | ||
| 91 | } | ||
| 61 | } | 92 | } |
| 62 | 93 | file_put_contents('data/livre_recettes_' . $year . '.csv', $result); // sortie fichier | |
| 63 | echo $presta->getCodePresta(); | 94 | echo $result . "\n"; // sortie console |
| 64 | echo "\n"; | ||
| 65 | } | ||
| 66 | } | 95 | } |
