1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<?php
// src/functions.php
use Doctrine\ORM\EntityManager;
// commande pour lancer une application graphique en ouvrant un fichier
function windowAppCommand(string $app, string $path = ''): string
{
// attention, ne supporte que la syntaxe la plus simple avec un seul paramètre:"app fichier"
// fonctionne avec choisis: gimp, scribus, sqlite, "l'explorateur de fichiers par défaut"
$command = 'nohup ' . $app; // détache l'appli du script PHP
if($path !== '')
{
$command .= ' ' . $path;
}
$command .= ' > /dev/null 2>&1 &';
// stdout > /dev/null et & permettent de rendre la main à PHP
// stderr > 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
}
}
|