From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sections/1_customer.php | 46 ++++++++-------- src/sections/2_service.php | 103 +++++++++++++++++------------------- src/sections/3-1_windows.php | 6 +-- src/sections/3_modify_data.php | 113 +++++++++++++++++++++++----------------- src/sections/4_get_document.php | 14 ++--- 5 files changed, 147 insertions(+), 135 deletions(-) (limited to 'src/sections') diff --git a/src/sections/1_customer.php b/src/sections/1_customer.php index b0e3283..db5c448 100644 --- a/src/sections/1_customer.php +++ b/src/sections/1_customer.php @@ -3,42 +3,46 @@ // // -- SECTION 1: Fichier clients et propects -- +use Doctrine\ORM\EntityManager; + function newCustomer(): array { // fenêtres - $TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']); + //$TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']); + $NouveauClient = new ZenityForms(ZenitySetup::$nouveau_client['text'], ZenitySetup::$nouveau_client['entrees']); $FinSection1 = new ZenityList(ZenitySetup::$fin_section_1['text'], ZenitySetup::$fin_section_1['entrees']); - + + $Customer = new Client; + // -- partie 1: client ou prospect? -- - $Client = new Clients; - $choix_niv2 = exec($TypeDeClient->get()); - if($choix_niv2 === ZenitySetup::$type_client['entrees'][0]) - { - echo "choix: " . $choix_niv2 . "\n"; - $Client->setType('client'); - } - elseif($choix_niv2 === ZenitySetup::$type_client['entrees'][1]) - { - echo "choix: " . $choix_niv2 . "\n"; - $Client->setType('prospect'); - } - else - { - return [0, null]; // menu principal - } + //~ $choix_niv2 = exec($TypeDeClient->get()); + //~ if($choix_niv2 === ZenitySetup::$type_client['entrees'][0]) + //~ { + //~ echo "choix: " . $choix_niv2 . "\n"; + //~ $Customer->setType('client'); + //~ } + //~ elseif($choix_niv2 === ZenitySetup::$type_client['entrees'][1]) + //~ { + //~ echo "choix: " . $choix_niv2 . "\n"; + //~ $Customer->setType('prospect'); + //~ } + //~ else + //~ { + //~ return [0, null]; // menu principal + //~ } // -- partie 2: saisie des infos -- - if(enterCustomer($Client)) + if($Customer->enterCustomer($NouveauClient)) { // -- partie 3: on fait quoi maintenant -- $choix_niv3 = exec($FinSection1->get()); if($choix_niv3 === ZenitySetup::$fin_section_1['entrees'][0]) { - return [2, $Client]; // section 2: newService() + return [2, $Customer]; // section 2: newService() } elseif($choix_niv3 === ZenitySetup::$fin_section_1['entrees'][1]) { - return [3, $Client]; // section 3: modifyData() + return [3, $Customer]; // section 3: modifyData() } elseif($choix_niv3 === ZenitySetup::$fin_section_1['entrees'][2]) { diff --git a/src/sections/2_service.php b/src/sections/2_service.php index 3dd620d..e25d677 100644 --- a/src/sections/2_service.php +++ b/src/sections/2_service.php @@ -3,26 +3,33 @@ // // -- SECTION 2: Prestation et devis -- +use Doctrine\ORM\EntityManager; + function newService($Client): array // $Client est un Client ou null { + // fenêtres recherche d'un client + $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']); + $ResultatsRechercheClient = new ZenityList(ZenitySetup::$resultats_recherche_client['text'], []); + // fenêtres - $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement_text, ZenitySetup::$menu_enregistrement_entrees); + $MenuEnregistrement = new ZenityList(ZenitySetup::$menu_enregistrement['text'], ZenitySetup::$menu_enregistrement['entrees']); $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section2']); $FormulaireDevis = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['devis_entrees']); $FormulaireFacture = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['facture_entrees']); $FormulaireFactureReduit = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['facture_entrees_reduit']); $FormulaireCesu = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['cesu_entrees']); $FormulaireLocation = new ZenityForms(ZenitySetup::$formulaire['text'], ZenitySetup::$formulaire['location_entrees']); - $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation_text); + $CommentairePrestation = new ZenityEntry(ZenitySetup::$commentaire_prestation['text']); //$Recapitulatif = new ZenityList(ZenitySetup::$recapitulatif_text, ZenitySetup::$recapitulatif_entrees); // tableau à multiples colonnes $FinSection2 = new ZenityList(ZenitySetup::$fin_section_2['text'], ZenitySetup::$fin_section_2['entrees']); // -- partie 1: le client -- - if($Client == null || get_class($Client) !== 'Clients') + if($Client == null || get_class($Client) !== 'Client') { - $Client = makeObjectClient(); // retourne 0 ou un objet "Clients" - if($Client == 0) + $Client = Client::getObject($RechercheClient, $ResultatsRechercheClient); // retourne un Client ou 0 + //$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction + if($Client === 0) { echo "debug: annulation sélection client\n"; return [0, null]; // menu principal @@ -48,49 +55,50 @@ function newService($Client): array // $Client est un Client ou null return [0, null]; // menu principal } - $Presta = new Prestations($Client->getId()); - $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD + $Presta = new Prestation($Client); + //var_dump($Client);die; + //$Presta->setDate($Date->getTimestamp()); + $Presta->setDate($Date); // envoi d'un objet, la BDD gardera le timestamp // formulaire - étape 2/3 switch($choix_niv2) { // comparaison retour de $MenuEnregistrement->get() avec les noms des entrées du même menu - case ZenitySetup::$menu_enregistrement_entrees[0]: // "Devis" - $PrestaDetails = new DevisFactures('devis'); + case ZenitySetup::$menu_enregistrement['entrees'][0]: // "Devis" + $PrestaDetails = new Devis($Presta); $Presta->setTypePresta('devis'); $answers = exec($FormulaireDevis->get()); break; - case ZenitySetup::$menu_enregistrement_entrees[1]: // "Facture" - $PrestaDetails = new DevisFactures('factures'); // attention! type "facture" mais table "factures" + case ZenitySetup::$menu_enregistrement['entrees'][1]: // "Facture" + $PrestaDetails = new Facture($Presta); $Presta->setTypePresta('facture'); $answers = exec($FormulaireFacture->get()); break; - case ZenitySetup::$menu_enregistrement_entrees[2]: // "Facture à partir d'un devis" + case ZenitySetup::$menu_enregistrement['entrees'][2]: // "Facture à partir d'un devis" // recherche du devis - $Quotation = getServices($Client, 'devis'); // rechercher un devis, type 'devis' spécifié pour $Presta->getIdsByIdClient() - if(!is_object($Quotation) || get_class($Quotation) != 'Prestations' || $Quotation->getTypePresta() != 'devis') + $Quotation = Prestation::getServices($Client, 'devis'); // rechercher un devis, type 'devis' spécifié + if(!is_object($Quotation) || get_class($Quotation) != 'Prestation' || $Quotation->getTypePresta() != 'devis') { echo "debug: annulation sélection client\n"; return [2, $Client]; // menu précédent } - $QuotationDetails = new DevisFactures('devis'); - // facture: objet vide et formulaire - $PrestaDetails = new DevisFactures('factures'); + $QuotationDetails = Devis::getQuotation($Quotation); + $PrestaDetails = new Facture($Presta); + $PrestaDetails->hydrateWithQuotation($QuotationDetails); // du devis à la facture $Presta->setTypePresta('facture'); $answers = exec($FormulaireFactureReduit->get()); - //var_dump($answers); break; - case ZenitySetup::$menu_enregistrement_entrees[3]: // "CESU" - $PrestaDetails = new CESU(); + case ZenitySetup::$menu_enregistrement['entrees'][3]: // "CESU" + $PrestaDetails = new CESU($Presta); $Presta->setTypePresta('cesu'); $answers = exec($FormulaireCesu->get()); break; - case ZenitySetup::$menu_enregistrement_entrees[4]: // "Location" - $PrestaDetails = new Locations(); + case ZenitySetup::$menu_enregistrement['entrees'][4]: // "Location" + $PrestaDetails = new Location($Presta); $Presta->setTypePresta('location'); $answers = exec($FormulaireLocation->get()); break; - case ZenitySetup::$menu_enregistrement_entrees[5]: // "Prestation non vendue" + case ZenitySetup::$menu_enregistrement['entrees'][5]: // "Prestation non vendue" $Presta->setTypePresta('non_vendue'); break; default: // inutile normallement, cas déjà géré avant @@ -98,7 +106,9 @@ function newService($Client): array // $Client est un Client ou null return [0, null]; } - $Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre + //$Presta->makeCodePresta($Date, $Client->getCodeClient()); // d'un objet à l'autre + //$Presta->makeCodePresta($Client->getCodeClient()); // d'un objet à l'autre + $Presta->setCodePresta(1); // d'un objet à l'autre // commentaire - étape 3/3 $comment = exec($CommentairePrestation->get()); @@ -120,48 +130,27 @@ function newService($Client): array // $Client est un Client ou null //~ } $Presta->setCommentaires($comment); - // hydratation d'une facture à partir d'un devis - if($choix_niv2 === ZenitySetup::$menu_enregistrement_entrees[2]) // cas: facture à partir d'un devis - { - // devis retrouvé ($Quotation est déjà hydraté) - $QuotationDetails->setIdPresta($Quotation->getId()); - $QuotationDetails->hydrate($QuotationDetails->getDetailsByIdPresta()); - - // facture avec le devis - $QuotationDetails->hydrateReceiptWithQuotation($PrestaDetails); - } - // hydratation avec la saisie du formulaire - if($choix_niv2 != ZenitySetup::$menu_enregistrement_entrees[5]) // cas: tous les cas sauf presta non vendue + if($choix_niv2 != ZenitySetup::$menu_enregistrement['entrees'][5]) // cas: tous les cas sauf presta non vendue { + //var_dump($answers); + $Client->typeToClient(); if($answers == '') // annulation { echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; return [0, null]; } - elseif(isset($PrestaDetails) && !$PrestaDetails->hydrateFromForm($answers, $Presta)) // echec de l'hydratation - { - echo "debug: erreur de hydrateFromForm()\n"; // messages d'erreur à mettre ici ou dans hydrateFromForm()? - return [0, null]; - } - } - - // mise à jour base de données - $Presta->create(); - $Presta->setId(); // sans paramètre, exécute un $this->db->lastInsertId() - - if(isset($PrestaDetails)) // presta vendue - { - $PrestaDetails->setIdPresta($Presta->getId()); // d'un objet à l'autre - $PrestaDetails->create(); - $PrestaDetails->setId(); // sans paramètre, exécute un $this->db->lastInsertId() + $PrestaDetails->hydrate($answers); + + // déléguer la synchronisation (flush) avec la BDD à une classe "Manager" } // si encore de type prospect, devient un type client - if($Client->typeToClient()) // utile si $Client est renvoyé dans le "return" + // déjà fait ailleurs je crois! + /*if($Client->typeToClient()) // utile si $Client est renvoyé dans le "return" { $Client->updateOneValue('type', 'client'); // base synchronisée - } + }*/ // -- partie 3: LaTeX -- @@ -213,7 +202,11 @@ function newService($Client): array // $Client est un Client ou null { return [3, $Client]; // section 3: modifyData() } - elseif($choix_niv2 === ZenitySetup::$fin_section_2['entrees'][2]) // enregistrer une autre prestation + elseif($choix_niv2 === ZenitySetup::$fin_section_2['entrees'][2]) // enregistrer une autre prestation (même client) + { + return [2, $Client]; // relancer section 2: newService() + } + elseif($choix_niv2 === ZenitySetup::$fin_section_2['entrees'][3]) // enregistrer une autre prestation (autre client) { return [2, null]; // relancer section 2: newService() } diff --git a/src/sections/3-1_windows.php b/src/sections/3-1_windows.php index 31c6cee..76d01dd 100644 --- a/src/sections/3-1_windows.php +++ b/src/sections/3-1_windows.php @@ -1,9 +1,9 @@ cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction + //if(!is_object($Client) || !get_class($Client) == 'Client') + if($Client === 0) { echo "debug: annulation sélection client\n"; return [0, null]; // menu principal @@ -26,7 +34,7 @@ function modifyData($Client): array // -- partie 2: modifier un client -- - // fenêtre + // fenêtre dynamique $ModificationClientMenu = makeModifyCustomerWindow($Client); $choix_niv2 = exec($ModificationClientMenu->get()); @@ -53,20 +61,22 @@ function modifyData($Client): array { echo "choix: annulation\n"; } - $Client->update(); + Client::$entityManager->flush(); // à mettre dans une classe Manager + return [3, $Client]; // menu précédent } - elseif(is_string($choix_niv2) && $choix_niv2 != '') // autres choix, modifier une valeur + elseif(is_string($choix_niv2) && $choix_niv2 != '') // modifier autre chose chez le client { - echo "choix: modifier" . $choix_niv2 . "\n"; + 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->update(); + $Client::$entityManager->flush(); - // mettre à jour les documents (il faudrait modifier tous les documents!!) + // documents (les factures, etc, ne sont pas modifiées ici) $EnveloppeRecto = Latex::makeInstance('enveloppe_recto'); $EnveloppeRecto->setData($Client); $EnveloppeRecto->makeLatex(); @@ -86,36 +96,35 @@ function modifyData($Client): array // -- partie 3: rechercher une prestation -- - $Presta = getServices($Client); // = 0 ou type "Prestations" - if(!is_object($Presta) || !get_class($Presta) == 'Prestations') + $Presta = Prestation::getServices($Client); // = 0 ou type "Prestation" + if(!is_object($Presta) || !get_class($Presta) == 'Prestation') { - echo "debug: annulation sélection client\n"; + echo "debug: annulation sélection d'une prestation\n"; return [3, $Client]; // menu précédent } - - $type = $Presta->getTypePresta(); - switch($type) + $type_presta = $Presta->getTypePresta(); + switch($type_presta) { case 'facture': - $PrestaDetails = new DevisFactures('factures'); + $classe = 'Facture'; break; case 'devis': - $PrestaDetails = new DevisFactures('devis'); + $classe = 'Devis'; break; case 'cesu': - $PrestaDetails = new CESU(); + $classe = 'CESU'; break; case 'location': - $PrestaDetails = new Locations(); + $classe = 'Location'; break; case 'non_vendue': $PrestaDetails = null; break; } - if($type != 'non_vendue') + if($type_presta != 'non_vendue') { - $PrestaDetails->setIdPresta($Presta->getId()); - $PrestaDetails->hydrate($PrestaDetails->getDetailsByIdPresta()); + $repository = $classe::$entityManager->getRepository($classe); + $PrestaDetails = $repository->findOneBy(['presta' => $Presta->getId()]); } @@ -125,11 +134,7 @@ function modifyData($Client): array $ModificationPrestaMenu = makeModifyServiceWindow($Presta, $PrestaDetails); $choix_niv3 = exec($ModificationPrestaMenu->get()); - //~ if($choix_niv3 === ZenitySetup::$modification_presta['devis_facture']) // devis -> facture - //~ { - //~ echo "choix: changer un devis en facture\n"; - //~ return [2, $Client]; // menu "client" - //~ } + if($choix_niv3 === 'Date:') { $Date = new Dates(exec($Calendrier->get())); // exec() renvoie soit une chaîne soit un false @@ -139,50 +144,60 @@ function modifyData($Client): array } else { - // mettre à jour la base de données - $Presta->setDate($Date->getTimestamp(), true); // un entier pour la BDD, "true" pour modifier le code_presta - $Presta->update(); + // entités et BDD + $Presta->set($choix_niv3, $Date); + $old_code = $Presta->getCodePresta(); + $Presta->setCodePresta(0); + $Presta::$entityManager->flush(); - // mettre à jour les documents - if($type === 'devis' || $type === 'facture' || $type === 'location') + // documents + if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') { $DocumentPresta = Latex::makeInstance($Presta->getTypePresta()); // $type = facture, devis, location $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); - $DocumentPresta->makeLatex(); - makeTexAndPdf($DocumentPresta); + $DocumentPresta->makeLatex(); // en mémoire + + renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); + makeTexAndPdf($DocumentPresta); // une nouvelle facture est créée, supprimer l'ancienne ou la renommer avec la nouvelle date } } return [3, $Client]; // menu précédent } - //~ elseif($choix_niv3 === 'Type de Presta:') // choix impossible pour le moment + //~ 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"; + 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)) // chaine vide autorisée + if(is_string($input)) // chaîne vide autorisée { - // mettre à jour la base de données + // entités et BDD $Presta->set($choix_niv3, $input); - $Presta->update(); - - if($type != 'non_vendue') + $old_code = $Presta->getCodePresta(); + $Presta->setCodePresta(0); + if($type_presta != 'non_vendue') { $PrestaDetails->set($choix_niv3, $input); - $PrestaDetails->update(); + $PrestaDetails::$entityManager->flush(); + } + else + { + $Presta::$entityManager->flush(); } - // mettre à jour les documents - if($type === 'devis' || $type === 'facture' || $type === 'location') + // documents + if($type_presta === 'devis' || $type_presta === 'facture' || $type_presta === 'location') { - $DocumentPresta = Latex::makeInstance($type); + $DocumentPresta = Latex::makeInstance($type_presta); $DocumentPresta->setData($Client)->setData($Presta)->setData($PrestaDetails); $DocumentPresta->makeLatex(); + + renameFiles($DocumentPresta, $old_code, $Presta->getCodePresta()); makeTexAndPdf($DocumentPresta); } } diff --git a/src/sections/4_get_document.php b/src/sections/4_get_document.php index baad117..e682d26 100644 --- a/src/sections/4_get_document.php +++ b/src/sections/4_get_document.php @@ -5,32 +5,32 @@ function getOrPrintDocument(): array { - $MenuDocuments = new ZenityList(ZenitySetup::$menu_documents_text, ZenitySetup::$menu_documents_entrees); + $MenuDocuments = new ZenityList(ZenitySetup::$menu_documents['text'], ZenitySetup::$menu_documents['entrees']); // -- partie 1: type de document -- $choix_niv2 = exec($MenuDocuments->get()); - if($choix_niv2 === ZenitySetup::$menu_documents_entrees[0]) + if($choix_niv2 === ZenitySetup::$menu_documents['entrees'][0]) { } - elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[1]) // = Facture + elseif($choix_niv2 === ZenitySetup::$menu_documents['entrees'][1]) // = Facture, devis, etc { } - elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[2]) // = Lettre avec adresse + elseif($choix_niv2 === ZenitySetup::$menu_documents['entrees'][2]) // = Lettre avec adresse { } - elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[3]) // = Livre des recettes + elseif($choix_niv2 === ZenitySetup::$menu_documents['entrees'][3]) // = Livre des recettes { } - elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[4]) // = Registre des achats + elseif($choix_niv2 === ZenitySetup::$menu_documents['entrees'][4]) // = Registre des achats { } - elseif($choix_niv2 === ZenitySetup::$menu_documents_entrees[5]) // = Bilan annuel + elseif($choix_niv2 === ZenitySetup::$menu_documents['entrees'][5]) // = Bilan annuel { } -- cgit v1.2.3