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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
<?php
// src/sections/3_modify_data.php
//
// -- SECTION 3: Modifier un client, un prospect, une prestation, un devis --
require('3-1_windows.php');
function modifyData(?Client $Client = null): array
{
// fenêtres
$RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']);
$ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []);
$TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']);
$Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section3']);
// -- partie 1: rechercher un client --
if(!$Client)
{
$Client = Client::find($RechercheClient, $ResultatsRechercheClient);
//$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction
if(!$Client)
{
echo "debug: annulation sélection client\n";
return [0, null]; // menu principal
}
}
// -- partie 2: modifier un client --
// fenêtre dynamique
$ModificationClientMenu = makeModifyCustomerWindow($Client);
$choix_niv2 = exec($ModificationClientMenu->get());
if($choix_niv2 === ZenitySetup::$modification_client['service']) // clic sur "Modifier une prestation"
{
echo "choix: modifier une prestation\n";
// ne rien faire dans cette partie et passer à la suite
}
elseif($choix_niv2 === "Client ou Prospect?")
{
echo "choix: modifier" . $choix_niv2 . "\n";
$input = exec($TypeDeClient->get());
if($input === ZenitySetup::$type_client['entrees'][0])
{
echo "choix: " . $input . "\n";
$Client->setType('client');
}
elseif($input === ZenitySetup::$type_client['entrees'][1])
{
echo "choix: " . $input . "\n";
$Client->setType('prospect');
}
else
{
echo "choix: annulation\n";
}
Client::$entityManager->flush(); // à mettre dans une classe Manager
return [3, $Client]; // menu précédent
}
elseif(is_string($choix_niv2) && $choix_niv2 != '') // modifier autre chose chez le client
{
echo "choix: modifier " . $choix_niv2 . "\n";
$ModificationClient = new ZenityEntry($choix_niv2);
$input = exec($ModificationClient->get());
if(is_string($input) && $input != '')
{
// entités et BDD
$Client->set($choix_niv2, $input);
$Client::$entityManager->flush();
// documents (les factures, etc, ne sont pas modifiées ici)
$EnveloppeRecto = Latex::makeInstance('enveloppe_recto');
$EnveloppeRecto->setData($Client);
$EnveloppeRecto->makeLatex();
$EnveloppeRecto->makeTexAndPdf();
}
else
{
echo "choix: annulation\n";
}
return [3, $Client]; // menu précédent
}
else
{
echo "annulation: retour au menu principal\n";
return [0, null]; // menu principal
}
// -- partie 3: rechercher une prestation --
$Presta = Prestation::getServices($Client);
if(!is_object($Presta) || !get_class($Presta) == 'Prestation')
{
echo "debug: annulation sélection d'une prestation\n";
return [3, $Client]; // menu précédent
}
$type_presta = $Presta->getTypePresta();
$classe = match($type_presta){
'facture' => Facture::class,
'devis' => Devis::class,
'cesu' => CESU::class,
'location' => Location::class,
'non_vendue' => NonVendue::class,
};
$repository = Prestation::$entityManager->getRepository($classe);
$Presta = $repository->findOneBy(['id' => $Presta->getId()]);
// -- partie 4: modifier une prestation --
// fenêtre
$ModificationPrestaMenu = makeModifyServiceWindow($Presta);
$choix_niv3 = exec($ModificationPrestaMenu->get());
if($choix_niv3 === 'Date:'){
$date_array = explode('/', exec($Calendrier->get())); // 17/10/2026
if(count($date_array) === 1){
echo "debug: annulation à la saisie d'une date\n";
return [3, $Client];
}
$input = $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]; // 2026-10-17
}
//~ elseif($choix_niv3 === 'Type de Presta:') // compliqué! choix impossible pour le moment
//~ {
//~ echo "choix: changer le type de prestation (devis, facture, etc)\n";
//~ return [3, $Client]; // menu "client"
//~ }
elseif(is_string($choix_niv3) && $choix_niv3 != ''){ // modifier une valeur
echo "choix: modifier " . $choix_niv3 . "\n";
$ModificationPrestaForm = new ZenityEntry($choix_niv3);
$input = shell_exec($ModificationPrestaForm->get()); // shell_exec() retourne null si la commande échoue, exec() retourne la dernière ligne de texte en sortie ou null si aucune commande ne réussit
if(!is_string($input)){ // chaîne vide autorisée
echo "choix: annulation\n";
return [3, $Client]; // menu précédent
}
}
else{
echo "annulation: retour au menu précédent\n";
return [3, $Client]; // menu précédent
}
// entités et BDD
$Presta->set($choix_niv3, $input);
$old_code = $Presta->getCodePresta();
$Presta->setCodePresta(0);
$Presta::$entityManager->flush();
// documents
if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location'){
$DocumentPresta = Latex::makeInstance($type_presta);
$DocumentPresta->setData($Client)->setData($Presta);
$DocumentPresta->makeLatex();
File::renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta());
$DocumentPresta->makeTexAndPdf();
}
return [3, $Client]; // menu précédent
}
|