diff options
Diffstat (limited to 'src/model/Prestations.php')
| -rw-r--r-- | src/model/Prestations.php | 165 |
1 files changed, 0 insertions, 165 deletions
diff --git a/src/model/Prestations.php b/src/model/Prestations.php deleted file mode 100644 index 3a415be..0000000 --- a/src/model/Prestations.php +++ /dev/null | |||
| @@ -1,165 +0,0 @@ | |||
| 1 | <?php | ||
| 2 | // src/model/Prestations.php | ||
| 3 | |||
| 4 | class Prestations extends Model | ||
| 5 | { | ||
| 6 | // lecture des données ou hydratation | ||
| 7 | protected $id; // auto-incrémentée | ||
| 8 | protected $id_client = 0; | ||
| 9 | protected $code_presta = ''; | ||
| 10 | protected $date = 0; // timestamp unix | ||
| 11 | protected $type_presta = ''; | ||
| 12 | protected $mode_paiement = ''; | ||
| 13 | protected $commentaires = ''; | ||
| 14 | //protected $numero_presta = 0; | ||
| 15 | |||
| 16 | public function __construct(int $id_client) | ||
| 17 | { | ||
| 18 | $this->id_client = $id_client; | ||
| 19 | $this->table = strtolower(__CLASS__); // prestations | ||
| 20 | } | ||
| 21 | |||
| 22 | // getters | ||
| 23 | public function getId(): int | ||
| 24 | { | ||
| 25 | return $this->id; | ||
| 26 | } | ||
| 27 | public function getIdClient(): int | ||
| 28 | { | ||
| 29 | return $this->id_client; | ||
| 30 | } | ||
| 31 | public function getIdsByIdClient() // obtenir une entrée avec son id_client, comportement différent si le type est connu | ||
| 32 | { | ||
| 33 | $sql = 'SELECT id FROM ' . $this->table . ' WHERE id_client = ' . $this->id_client; | ||
| 34 | if($this->type_presta != '') | ||
| 35 | { | ||
| 36 | $sql .= " AND type_presta = '" . $this->type_presta . "'"; | ||
| 37 | } | ||
| 38 | $data = $this->execQuery($sql)->fetchAll(); // tableau de tableaux | ||
| 39 | |||
| 40 | $IDs = []; // si $IDs reste vide, ne pas être de type NULL | ||
| 41 | for($i = 0; $i < count($data); $i++) | ||
| 42 | { | ||
| 43 | $IDs[$i] = $data[$i]['id']; // tableau simple | ||
| 44 | } | ||
| 45 | return($IDs); | ||
| 46 | } | ||
| 47 | public function getCodePresta(): string | ||
| 48 | { | ||
| 49 | return $this->code_presta; | ||
| 50 | } | ||
| 51 | public function getDate(): int // timestamp unix | ||
| 52 | { | ||
| 53 | return $this->date; | ||
| 54 | } | ||
| 55 | public function getTypePresta(): string | ||
| 56 | { | ||
| 57 | return $this->type_presta; | ||
| 58 | } | ||
| 59 | public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) | ||
| 60 | { | ||
| 61 | $code_presta_tableau = explode('-', $this->code_presta); | ||
| 62 | $Date = new Dates($this->date); | ||
| 63 | |||
| 64 | return [ | ||
| 65 | "Numéro prestation:" => end($code_presta_tableau), // dernière case | ||
| 66 | "Date:" => $Date->getDate(), | ||
| 67 | //"Type de Presta:" => $this->type_presta, // choix impossible pour le moment | ||
| 68 | "Mode de paiement:" => $this->mode_paiement, // non pertinent pour un devis | ||
| 69 | "Commentaires:" => $this->commentaires]; | ||
| 70 | } | ||
| 71 | public function set(string $entry, string $input) | ||
| 72 | { | ||
| 73 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide | ||
| 74 | switch($entry) | ||
| 75 | { | ||
| 76 | case "Numéro prestation:": | ||
| 77 | $this->setNumeroPresta($input); | ||
| 78 | break; | ||
| 79 | //~ case "Date:": // inutile, setDate() est appelé directement après choix fenêtre calendrier | ||
| 80 | //~ $this->setDate($input); | ||
| 81 | //~ break; | ||
| 82 | //~ case "Type de Presta:": // choix impossible pour le moment | ||
| 83 | //~ $this->setTypePresta($input); | ||
| 84 | //~ break; | ||
| 85 | case "Mode de paiement:": | ||
| 86 | $this->setModePaiement($input); | ||
| 87 | break; | ||
| 88 | case "Commentaires:": | ||
| 89 | $this->setCommentaires($input); | ||
| 90 | break; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | // setters | ||
| 95 | public function setIdClient(int $value) | ||
| 96 | { | ||
| 97 | $this->id_client = $value; | ||
| 98 | return $this; | ||
| 99 | } | ||
| 100 | //~ public function setCombientiemeFois(int $value) | ||
| 101 | //~ { | ||
| 102 | //~ $this->combientieme_fois = $value; | ||
| 103 | //~ return($this); | ||
| 104 | //~ } | ||
| 105 | public function setCodePresta(string $value) | ||
| 106 | { | ||
| 107 | $this->code_presta = $value; | ||
| 108 | return $this; | ||
| 109 | } | ||
| 110 | public function setDate($value, bool $set_code_presta = false) // attend un timestamp | ||
| 111 | { | ||
| 112 | $this->date = (int) $value; | ||
| 113 | |||
| 114 | if($set_code_presta) | ||
| 115 | { | ||
| 116 | $code_presta_tableau = explode('-', $this->code_presta); | ||
| 117 | $Date = new Dates($value); | ||
| 118 | $code_presta_tableau[0] = $Date->getYear(); | ||
| 119 | $code_presta_tableau[1] = $Date->getMonth(); | ||
| 120 | $code_presta_tableau[2] = $Date->getDay(); | ||
| 121 | $this->code_presta = implode('-', $code_presta_tableau); | ||
| 122 | } | ||
| 123 | |||
| 124 | return $this; | ||
| 125 | } | ||
| 126 | public function setTypePresta(string $value) | ||
| 127 | { | ||
| 128 | $this->type_presta = $value; | ||
| 129 | return $this; | ||
| 130 | } | ||
| 131 | public function setModePaiement(string $value) | ||
| 132 | { | ||
| 133 | $this->mode_paiement = $value; | ||
| 134 | return $this; | ||
| 135 | } | ||
| 136 | public function setCommentaires(string $value) | ||
| 137 | { | ||
| 138 | $this->commentaires = $this->cleanSpecialChars($value); // nettoyage ici parce que pas possible ailleurs | ||
| 139 | return $this; | ||
| 140 | } | ||
| 141 | public function setNumeroPresta($value) | ||
| 142 | { | ||
| 143 | // modifier le code presta, on pourrait aussi utiliser une regex | ||
| 144 | $code_presta_tableau = explode('-', $this->code_presta); | ||
| 145 | $code_presta_tableau[count($code_presta_tableau) - 1] = (int) $value; | ||
| 146 | $this->code_presta = implode('-', $code_presta_tableau); | ||
| 147 | return $this; | ||
| 148 | } | ||
| 149 | |||
| 150 | // code client = année-mois-jour-codeclient-typedepresta-combientièmefois | ||
| 151 | public function makeCodePresta(Dates $Date, string $code_client) | ||
| 152 | { | ||
| 153 | // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) | ||
| 154 | // inconvénient: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer | ||
| 155 | $combientieme_fois = count($this->find(['id_client' => $this->id_client])) + 1; | ||
| 156 | |||
| 157 | $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $this->type_presta, $combientieme_fois]; | ||
| 158 | $this->code_presta = implode('-', $array_code); | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | //~ class CodePresta extends Prestations | ||
| 163 | //~ { | ||
| 164 | //~ protected $numero_presta; | ||
| 165 | //~ } | ||
