summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2026-10-21 16:18:35 +0200
committerpolo <ordipolo@gmx.fr>2026-10-21 16:18:35 +0200
commit26fbb91d0047e901afffbc6e21e7767d546fec9b (patch)
tree5712b2b60d4d5dce9931b21578c4ba55cf231504
parent30b3819db6742a1851ca8af8b9763cbd17bffeca (diff)
downloadAppliGestionPHP-polo1.tar.gz
AppliGestionPHP-polo1.tar.bz2
AppliGestionPHP-polo1.zip
fonction livre de recettesHEADpolo1master
-rwxr-xr-xbin/livre_recettes.php46
-rw-r--r--src/functions.php47
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 @@
14// chemins des dossiers et nom de la base 14// chemins des dossiers et nom de la base
15require('src/File.php'); 15require('src/File.php');
16require('src/Config.php'); // lit le config.ini et gère certaines erreurs (exemple les / aux chemins manquants) 16require('src/Config.php'); // lit le config.ini et gère certaines erreurs (exemple les / aux chemins manquants)
17require('src/functions.php');
17Config::readFile('config/config.ini'); 18Config::readFile('config/config.ini');
18Config::hydrate(); 19Config::hydrate();
19 20
@@ -50,46 +51,5 @@ catch(Exception $e){
50 die; 51 die;
51} 52}
52 53
53 54// fichiers et sortie console
54// requête 55makeRecipeBook($entityManager, $years); \ No newline at end of file
55foreach($years as $year){
56 /*$date_debut = $year . '-01-01';
57 $date_fin = $year . '-12-31';
58
59 $debut = new DateTime($date_debut, new DateTimeZone('Europe/Paris'));
60 $fin = new DateTime($date_fin, new DateTimeZone('Europe/Paris'));;
61 $fin->setTime(23, 59, 59);*/
62
63 $dql = 'SELECT n FROM Prestation n WHERE n.date >= :debut AND n.date <= :fin';
64 $bulk_data = $entityManager
65 ->createQuery($dql)
66 ->setParameter('debut', $year . '-01-01')
67 ->setParameter('fin', $year . '-12-31')
68 ->getResult();
69
70 // affichage
71 $result = "client|date|type|mode paiement|débours|total HT|salaire CESU|code presta\n";
72
73 foreach($bulk_data as $presta){
74 if($presta->getTypePresta() !== 'devis' && $presta->getTypePresta() !== 'non_vendue'){
75 $result .= $presta->getClient()->getPrenomNom() . '|'
76 . $presta->getDate() . '|'
77 . $presta->getTypePresta() . '|'
78 . $presta->getModePaiement() . '|';
79
80 if($presta->getTypePresta() === 'facture'){
81 $result .= $presta->getTotalPieces() . '|';
82 $result .= $presta->getTotalHT() . '||';
83 }
84 elseif($presta->getTypePresta() === 'cesu'){
85 $result .= '||' . $presta->getSalaire() . '|';
86 }
87 elseif($presta->getTypePresta() === 'location'){
88 $result .= '|' . (string)($presta->getLoyer() * (float)$presta->getLoyersPayes()) . '||';
89 }
90 $result .= $presta->getCodePresta() . "\n";
91 }
92 }
93 file_put_contents('data/livre_recettes_' . $year . '.csv', $result); // sortie fichier
94 echo $result . "\n"; // sortie console
95}
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 @@
1<?php 1<?php
2// src/functions.php 2// src/functions.php
3 3
4use Doctrine\ORM\EntityManager;
4 5
5// commande pour lancer une application graphique en ouvrant un fichier 6// commande pour lancer une application graphique en ouvrant un fichier
6function windowAppCommand(string $app, string $path = ''): string 7function windowAppCommand(string $app, string $path = ''): string
@@ -18,3 +19,49 @@ function windowAppCommand(string $app, string $path = ''): string
18 // stderr > stdout pour cacher un message inutile 19 // stderr > stdout pour cacher un message inutile
19 return $command; 20 return $command;
20} 21}
22
23// appelée par bin/livre_recettes.php
24function makeRecipeBook(EntityManager $entityManager, array $years): void
25{
26 foreach($years as $year){
27 /*$date_debut = $year . '-01-01';
28 $date_fin = $year . '-12-31';
29
30 $debut = new DateTime($date_debut, new DateTimeZone('Europe/Paris'));
31 $fin = new DateTime($date_fin, new DateTimeZone('Europe/Paris'));;
32 $fin->setTime(23, 59, 59);*/
33
34 $dql = 'SELECT n FROM Prestation n WHERE n.date >= :debut AND n.date <= :fin';
35 $bulk_data = $entityManager
36 ->createQuery($dql)
37 ->setParameter('debut', $year . '-01-01')
38 ->setParameter('fin', $year . '-12-31')
39 ->getResult();
40
41 // affichage
42 $result = "client|date|type|mode paiement|débours|total HT|salaire CESU|code presta\n";
43
44 foreach($bulk_data as $presta){
45 if($presta->getTypePresta() !== 'devis' && $presta->getTypePresta() !== 'non_vendue'){
46 $result .= $presta->getClient()->getPrenomNom() . '|'
47 . $presta->getDate() . '|'
48 . $presta->getTypePresta() . '|'
49 . $presta->getModePaiement() . '|';
50
51 if($presta->getTypePresta() === 'facture'){
52 $result .= $presta->getTotalPieces() . '|';
53 $result .= $presta->getTotalHT() . '||';
54 }
55 elseif($presta->getTypePresta() === 'cesu'){
56 $result .= '||' . $presta->getSalaire() . '|';
57 }
58 elseif($presta->getTypePresta() === 'location'){
59 $result .= '|' . (string)($presta->getLoyer() * (float)$presta->getLoyersPayes()) . '||';
60 }
61 $result .= $presta->getCodePresta() . "\n";
62 }
63 }
64 file_put_contents('data/livre_recettes_' . $year . '.csv', $result); // sortie fichier
65 echo $result . "\n"; // sortie console
66 }
67} \ No newline at end of file