From a4d88fd1913758cc95b395eefcf5e9d730450382 Mon Sep 17 00:00:00 2001 From: polo Date: Sat, 23 Dec 2023 10:00:24 +0100 Subject: =?UTF-8?q?devis=20payant,=20cr=C3=A9er=20devis=20depuis=20facture?= =?UTF-8?q?,=20changement=20dans=20getIDsByIdClient(),=20suppression=20d?= =?UTF-8?q?=C3=A9pendance=20paquet=20latex=20"ulem",=20(string)=20dans=20s?= =?UTF-8?q?etTelephone()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/Clients.php | 14 ++++---------- src/model/DevisFactures.php | 32 ++++++++++++++++++++++++++------ src/model/Model.php | 35 ++++++++++++++++++++++------------- src/model/Prestations.php | 24 +++++++++++++++--------- src/model/StructTablesDB.php | 2 +- 5 files changed, 68 insertions(+), 39 deletions(-) (limited to 'src/model') diff --git a/src/model/Clients.php b/src/model/Clients.php index 524070a..a5cc276 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php @@ -102,17 +102,11 @@ class Clients extends Model $this->ville = (string) $value; return $this; } - public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début + public function setTelephone($value) { - if(is_numeric($value)) - { - $this->telephone = (string) $value; - } - else - { - $this->telephone = ''; - echo 'debug: le champ "telephone" ne doit comporter que des nombres, aucun numéro ne sera utilisé' . "\n"; - } + // type string parce que + // zenity renvoie une chaine, on peut ainsi garder le 0 au début et avoir plusieurs numéros (séparés par virgule et espace) + $this->telephone = (string) $value; return $this; } public function setCourriel($value) diff --git a/src/model/DevisFactures.php b/src/model/DevisFactures.php index 259690b..7c31f13 100644 --- a/src/model/DevisFactures.php +++ b/src/model/DevisFactures.php @@ -17,6 +17,7 @@ class DevisFactures extends Model protected $pieces; protected $total_pieces; protected $deplacement; + protected $prix_devis; protected $total_HT; protected $delai_livraison; protected $validite_devis; @@ -26,6 +27,7 @@ class DevisFactures extends Model { $this->table = $table; // deux tables séparées devis et factures } + public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) { $taches = ["Tâches:" => $this->taches]; @@ -60,7 +62,8 @@ class DevisFactures extends Model return []; } } - public function set(string $entry, string $input) + + public function set(string $entry, string $input) // trouve la bonne méthode { switch($entry) { @@ -91,6 +94,9 @@ class DevisFactures extends Model case "Déplacement:": $this->setDeplacement($input); break; + case "Prix du devis:": + $this->setPrixDevis($input); + break; case "Total HT:": $this->setTotalHT($input); break; @@ -142,11 +148,6 @@ class DevisFactures extends Model $this->cles_licences = $value; return($this); } - //~ public function setTemps(string $value) - //~ { - //~ $this->temps = $value; - //~ return($this); - //~ } public function setTotalMainDOeuvre($value) { $value = str_replace(',', '.', $value); @@ -176,6 +177,12 @@ class DevisFactures extends Model $this->total_HT = (float) $value; return($this); } + public function setPrixDevis($value) + { + $value = str_replace(',', '.', $value); + $this->prix_devis = (float) $value; + return($this); + } public function setDelaiLivraison(string $value) { $this->delai_livraison = $value; @@ -192,6 +199,19 @@ class DevisFactures extends Model return($this); } + // création d'une facture à partir d'un devis + public function hydrateReceiptWithQuotation($ReceiptDetails) + { + $ReceiptDetails->hydrate([ + 'taches' => $this->taches, + 'total_main_d_oeuvre' => $this->total_main_d_oeuvre, + 'pieces' => $this->pieces, + 'total_pieces' => $this->total_pieces, + 'deplacement' => $this->deplacement, + 'total_HT' => $this->total_HT + ]); + } + //~ public function newRow(array $input) //~ { //~ if($this->table === 'devis') // comme la table 'factures' avec deux champs en plus diff --git a/src/model/Model.php b/src/model/Model.php index 07826af..d6597f0 100644 --- a/src/model/Model.php +++ b/src/model/Model.php @@ -37,6 +37,11 @@ abstract class Model extends DB } return $this; } + public function setTable(string $value) + { + $this->table = $value; + return($this); + } public function hydrate(array $data): bool // $data = tableau associatif en entrée: nom_du_champ => valeur { @@ -60,6 +65,7 @@ abstract class Model extends DB } // cette fonction reçoit des données d'un tableau simple, permettant d'associer des champs de formulaires aux noms différents des champs de la BDD + // méthode lancée par des objets de type enfants function hydrateFromForm(string $data_string, Object $Presta = NULL): bool // quand l'objet est $Details, on hydrate aussi $Presta { //~ $tableSize = count(StructTablesDB::$structureOfTables[$this->getTable()]); // int @@ -84,18 +90,25 @@ abstract class Model extends DB case 'prestations'; // inutilisé break; case 'devis'; - //~ $check = $Presta->hydrate(['mode_paiement' => $data_array[6]]); - //~ if($check) - //~ { - //~ $check = $this->hydrate(['taches' => $data_array[0], 'total_main_d_oeuvre' => $data_array[1], 'pieces' => $data_array[2], 'total_pieces' => $data_array[3], 'deplacement' => $data_array[4], 'total_HT' => $data_array[5], 'delai_livraison' => $data_array[7], 'validite_devis' => $data_array[8], 'signature_devis' => $data_array[9]]); - $check = $this->hydrate(['taches' => $data_array[0], 'total_main_d_oeuvre' => $data_array[1], 'pieces' => $data_array[2], 'total_pieces' => $data_array[3], 'deplacement' => $data_array[4], 'total_HT' => $data_array[5], 'delai_livraison' => $data_array[6], 'validite_devis' => $data_array[7]]); - //~ } + $check = $this->hydrate(['taches' => $data_array[0], 'total_main_d_oeuvre' => $data_array[1], 'pieces' => $data_array[2], 'total_pieces' => $data_array[3], 'deplacement' => $data_array[4], 'prix_devis' => $data_array[5], 'total_HT' => $data_array[6], 'delai_livraison' => $data_array[7], 'validite_devis' => $data_array[8]]); break; case 'factures'; - $check = $Presta->hydrate(['mode_paiement' => $data_array[10]]); - if($check) + if(count($data_array) === 11) + { + $check = $Presta->hydrate(['mode_paiement' => $data_array[10]]); + if($check) + { + $check = $this->hydrate(['taches' => $data_array[0], 'machine' => $data_array[1], 'OS' => $data_array[2], 'donnees' => $data_array[3], 'cles_licences' => $data_array[4], 'total_main_d_oeuvre' => $data_array[5], 'pieces' => $data_array[6], 'total_pieces' => $data_array[7], 'deplacement' => $data_array[8], 'total_HT' => $data_array[9]]); + } + } + elseif(count($data_array) === 5) { - $check = $this->hydrate(['taches' => $data_array[0], 'machine' => $data_array[1], 'OS' => $data_array[2], 'donnees' => $data_array[3], 'cles_licences' => $data_array[4], 'total_main_d_oeuvre' => $data_array[5], 'pieces' => $data_array[6], 'total_pieces' => $data_array[7], 'deplacement' => $data_array[8], 'total_HT' => $data_array[9]]); + $check = $this->hydrate(['machine' => $data_array[1], 'OS' => $data_array[2], 'donnees' => $data_array[3], 'cles_licences' => $data_array[4]]); + } + else + { + echo "debug: le tableau \$data_array n'a pas la taille attendue.\n"; + return false; } break; case 'cesu'; @@ -106,11 +119,7 @@ abstract class Model extends DB } break; case 'locations'; - //~ $check = $Presta->hydrate(['mode_paiement' => $data_array[11]]); - //~ if($check) - //~ { $check = $this->hydrate(['designation' => $data_array[0], 'modele_description' => $data_array[1], 'valeur' => $data_array[2], 'etat_des_lieux_debut' => $data_array[3], 'etat_des_lieux_fin' => $data_array[4], 'duree_location' => $data_array[5], 'loyer_mensuel' => $data_array[6], 'loyers_payes' => $data_array[7], 'caution' => $data_array[8]]); - //~ } break; default: // inutilisé echo "debug: table inconnue hydrateFromForm()"; diff --git a/src/model/Prestations.php b/src/model/Prestations.php index 54ad4b7..8591e83 100644 --- a/src/model/Prestations.php +++ b/src/model/Prestations.php @@ -28,13 +28,19 @@ class Prestations extends Model { return $this->ID_client; } - public function getIDsByIdClient() // obtenir une entrée avec son ID_client + public function getIDsByIdClient() // obtenir une entrée avec son ID_client, comportement différent si le type est connu { - $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++) + $sql = 'SELECT id FROM ' . $this->table . ' WHERE id_client = ' . $this->ID_client; + if($this->type_presta != '') { - $IDs[$i] = $IDs[$i]['ID']; + $sql .= " AND type_presta = '" . $this->type_presta . "'"; + } + $data = $this->execQuery($sql)->fetchAll(); // tableau de tableaux + + $IDs = []; // si $IDs reste vide, ne pas être de type NULL + for($i = 0; $i < count($data); $i++) + { + $IDs[$i] = $data[$i]['ID']; // tableau simple } return($IDs); } @@ -152,7 +158,7 @@ class Prestations extends Model } } -class CodePresta extends Prestations -{ - protected $numero_presta; -} +//~ class CodePresta extends Prestations +//~ { + //~ protected $numero_presta; +//~ } diff --git a/src/model/StructTablesDB.php b/src/model/StructTablesDB.php index 679adde..48bf8e5 100644 --- a/src/model/StructTablesDB.php +++ b/src/model/StructTablesDB.php @@ -11,7 +11,7 @@ class StructTablesDB // les tables devis_factures, cesu et locations sont liées à la table prestations 'clients' => ['ID' => 'INTEGER', 'prenom_nom' => 'TEXT', 'code_client' => 'TEXT', 'adresse' => 'TEXT', 'code_postal' => 'TEXT', 'ville' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'apropos' => 'TEXT', 'type' => 'TEXT DEFAULT prospect'], 'prestations' => ['ID' => 'INTEGER', 'ID_client' => 'INTEGER', 'code_presta' => 'TEXT', 'date' => 'INTEGER', 'type_presta' => 'TEXT', 'mode_paiement' => 'TEXT', 'commentaires' => 'TEXT'], - 'devis' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL', 'delai_livraison' => 'TEXT', 'validite_devis' => 'TEXT', 'signature_devis' => 'TEXT DEFAULT non'], + 'devis' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'prix_devis' => 'REAL', 'total_HT' => 'REAL', 'delai_livraison' => 'TEXT', 'validite_devis' => 'TEXT', 'signature_devis' => 'TEXT DEFAULT non'], 'factures' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'machine' => 'TEXT', 'OS' => 'TEXT', 'donnees' => 'TEXT', 'cles_licences' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL'], 'cesu' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'duree_travail' => 'TEXT', 'salaire' => 'REAL'], 'locations' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'designation' => 'TEXT', 'modele_description' => 'TEXT', 'valeur' => 'REAL', 'etat_des_lieux_debut' => 'TEXT', 'etat_des_lieux_fin' => 'TEXT', 'duree_location' => 'TEXT', 'loyer_mensuel' => 'REAL', 'loyers_payes' => 'INTEGER', 'caution' => 'INTEGER'] -- cgit v1.2.3