summaryrefslogtreecommitdiff
path: root/src/model/Prestations.php
blob: fe091330e96e88e03ddb4dcffe8f1f89940124f6 (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
<?php
// src/model/Prestations.php

class Prestations extends Model
{
    // lecture des données ou hydratation
    protected $ID; // auto-incrémentée
    protected $ID_client = 0;
    protected $code_presta = '';
    protected $date = 0; // timestamp unix
    protected $type_presta = '';
    protected $mode_paiement = '';
    protected $commentaires = '';
    
    public function __construct(int $ID_client)
    {
	$this->ID_client = $ID_client;
        $this->table = strtolower(__CLASS__); // prestations
    }
    
    // getters
    public function getID(): int
    {
        return $this->ID;
    }
    public function getIDClient(): int
    {
        return $this->ID_client;
    }
    public function getIDsByIdClient() // obtenir une entrée avec son ID_client
    {
        $IDs = $this->execQuery('SELECT id FROM ' . $this->table . ' WHERE id_client = ' . $this->ID_client)->fetchAll();
	// changer le tableau de tableaux en tableau simple
	for($i = 0; $i < count($IDs); $i++)
	{
	    $IDs[$i] = $IDs[$i]['ID'];
	}
	return($IDs);
    }
    public function getCodePresta(): string
    {
        return $this->code_presta;
    }
    public function getDate(): int // timestamp unix
    {
        return $this->date;
    }
    public function getTypePresta(): string
    {
        return $this->type_presta;
    }
    public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this)
    {
	$code_presta_tableau = explode('-', $this->code_presta);
	$Date = new Dates($this->date);
	
        return [
            "Numéro prestation:" => end($code_presta_tableau), // dernière case
            "Date:" => $Date->getDate(),
            "Type de Presta:" => $this->type_presta,
            "Mode de paiement:" => $this->mode_paiement,
            "Commentaires:" => $this->commentaires];
    }

    // setters
    //~ public function setID() -> dans le trait ModelChildren
    
    public function setIDClient(int $value)
    {
	$this->ID_client = $value;
	return $this;
    }
    //~ public function setCombientiemeFois(int $value)
    //~ {
	//~ $this->combientieme_fois = $value;
	//~ return($this);
    //~ }
    public function setCodePresta(string $value)
    {
	$this->code_presta = $value;
	return $this;
    }
    public function setDate(int $value)
    {
	$this->date = $value;
	return $this;
    }
    public function setTypePresta(string $value)
    {
	$this->type_presta = $value;
	return $this;
    }
    public function setModePaiement(string $value)
    {
	$this->mode_paiement = $value;
	return $this;
    }
    public function setCommentaires(string $value)
    {
	$this->commentaires = $value;
	return $this;
    }
    
    // code client = année-mois-jour-codeclient-typedepresta-combientièmefois
    public function makeCodePresta(Dates $Date, string $code_client)
    {
	// on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente)
	// inconvénient: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer
	$combientieme_fois = count($this->find(['ID_client' => $this->ID_client])) + 1;
	
	$array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $this->type_presta, $combientieme_fois];
	$this->code_presta = implode('-', $array_code);
    }
}