summaryrefslogtreecommitdiff
path: root/src/sections/3_modify_data.php
blob: e16a58f0a937c86bbcbd484cf9cf690744734638 (plain)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
// src/sections/3_modify_data.php
//
// -- SECTION 3: Modifier un client, un prospect, une prestation, un devis --

function modifyData($Client): array
{
    // -- partie 1: rechercher un client --
    if($Client == null || get_class($Client) !== 'Clients') // étape sautable
    {
        $Client = makeObjectClient(); // = 0 ou type "Clients"
        if(!is_object($Client) || !get_class($Client) == 'Clients')
        {
            echo "debug: annulation sélection client\n";
            return [0, null]; // menu principal
        }
    }
    
    
    // -- partie 2: modifier un client --
    
    // fenêtre $ModificationClient
    $ModificationClientMenu = new ZenityList(ZenitySetup::$modification_client['text'], []);
    $entrees = [];
    $i = 0;
    $client_data = $Client->getAllWithWindowFields();
    //var_dump($client_data);
    foreach($client_data as $key => $value)
    {
        $entrees[$i][] = $key;
        $entrees[$i][] = $value;
        $i++;
    }
    $entrees[$i][] = ZenitySetup::$modification_client['service'];
    $entrees[$i][] = '';
    $i++;
    $entrees[$i][] = ZenitySetup::$modification_client['return'];
    $entrees[$i][] = '';
    $ModificationClientMenu->setListRows($entrees, 2, 2.5);
    
    // modifier une valeur
    $choix_niv2 = exec($ModificationClientMenu->get());
    if($choix_niv2 === ZenitySetup::$modification_client['service']) // ne pas modifier le client mais une prestation
    {
        echo "choix: modifier une prestation\n";
        // on passe à la suite
    }
    elseif($choix_niv2 === ZenitySetup::$modification_client['return']) // annuler
    {
        echo "choix: retour au menu principal\n";
        return [0, null]; // menu principal
    }
    elseif($choix_niv2 === "Client ou Prospect?") // modifier le client
    {
        echo "choix: modifier" . $choix_niv2 . "\n";
        $TypeDeClient = new ZenityList(ZenitySetup::$type_client_text, ZenitySetup::$type_client_entrees);
        $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->update();
        return [3, $Client]; // menu précédent
    }
    elseif(is_string($choix_niv2) && $choix_niv2 != '') // modifier le client
    {
        echo "choix: modifier" . $choix_niv2 . "\n";
        $ModificationClient = new ZenityEntry($choix_niv2);
        $input = exec($ModificationClient->get());
        if(is_string($input) && $input != '')
        {
            $Client->getSetterAndSet($choix_niv2, $input);
            $Client->update();
            
            // mettre à jour les documents
            
        }
        else
        {
            echo "choix: annulation\n";
        }
        return [3, $Client]; // menu précédent
    }
    else // annuler
    {
        echo "annulation: retour au menu principal\n";
        return [0, null]; // menu principal
    }
    
    
    // -- partie 3: rechercher une prestation --
    $Presta = getServices($Client); // = 0 ou type "Prestations"
    if(!is_object($Presta) || !get_class($Presta) == 'Prestations')
    {
        echo "debug: annulation sélection client\n";
        return [3, $Client]; // menu précédent
    }
    
    
    // -- partie 4: modifier une prestation --
    
    // fenêtre $ModificationPresta
    $ModificationPrestaMenu = new ZenityList(ZenitySetup::$modification_presta['text'], []);
    $entrees = [];
    $i = 0;
    
    $presta_data = $Presta->getAllWithWindowFields();
    var_dump($presta_data);
    foreach($presta_data as $key => $value)
    {
        $entrees[$i][] = $key;
        $entrees[$i][] = $value;
        $i++;
    }
    
    // infos des sous-tables 'facture', 'devis', etc
    switch($Presta->getTypePresta())
    {
        case 'facture':
            $PrestaDetails = new DevisFactures('factures');
            break;
        
        case 'devis':
            $PrestaDetails = new DevisFactures('devis');
            break;
        case 'cesu':
            $PrestaDetails = new CESU();
            break;
        case 'location':
            $PrestaDetails = new Locations();
            break;
    }
    if(isset($PrestaDetails))
    {
        $PrestaDetails->setIDPresta($Presta->getID());
        $PrestaDetails->hydrate($PrestaDetails->getDetailsByIdPresta());
        $presta_data = $PrestaDetails->getAllWithWindowFields();
        var_dump($presta_data);
        foreach($presta_data as $key => $value)
        {
            $entrees[$i][] = $key;
            $entrees[$i][] = $value;
            $i++;
        }
    }
    
    if($Presta->getTypePresta() === 'devis')
    {
        $entrees[$i][] = ZenitySetup::$modification_presta['devis_facture']; // option changer le devis en facture
        $entrees[$i][] = '';
        $i++;
    }
    $entrees[$i][] = ZenitySetup::$modification_presta['service'];
    $entrees[$i][] = '';
    $i++;
    $entrees[$i][] = ZenitySetup::$modification_presta['return'];
    $entrees[$i][] = '';
    $ModificationPrestaMenu->setListRows($entrees, 2, 2.5);
    
    // modifier une valeur
    $choix_niv3 = exec($ModificationPrestaMenu->get());
    var_dump($choix_niv3);
    
    // si changement de type de prestation autre que de devis à facture, ça devient compliqué!
    
    return [0, null]; // menu principal
}