summaryrefslogtreecommitdiff
path: root/bin/livre_recettes.php
diff options
context:
space:
mode:
Diffstat (limited to 'bin/livre_recettes.php')
-rwxr-xr-xbin/livre_recettes.php99
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';
23require __DIR__ . '/../src/model/doctrine-bootstrap.php'; // chemin absolu 23require __DIR__ . '/../src/model/doctrine-bootstrap.php'; // chemin absolu
24 24
25
26// année en paramètre
27$years = [];
28try{
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}
45catch(Exception $e){
46 echo $e->getMessage();
47 die;
48}
49
50
25// requête 51// requête
26$date_debut = '2024-01-01'; 52foreach($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
41echo "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
43foreach($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}