CommandeService

🔧 __construct

Initialise le service avec les données nécessaires
function __construct($id_type, $id_obje) { $this->DIR = __DIR__; $this->typeDevis = $id_type; $this->idDevis = $id_obje; // Vérifie si une commande existe déjà $this->verifierCommandeExistante(); // Si pas de commande existante, charge les données du devis if (!$this->commandeExistante) { $this->chargerDonneesDevis(); } else { //$this->Notifaction("Commande déjà existante", "warning"); } }

⚙️ Parameters

⚠️ Throws


🔧 verifierCommandeExistante

Vérifie si une commande existe déjà pour ce devis
function verifierCommandeExistante() { $wc = ["att14 = " . $this->idDevis]; $commande = fwc7_data_objet_atts('', MapperCommande::TYPE_COMMANDE($this->typeDevis), "1", $wc); $this->commandeExistante = !empty($commande); }

🔧 chargerDonneesDevis

Charge les données du devis et ses lignes
function chargerDonneesDevis() { global $global_message; $this->devis = fwc7_data_objet_att('', $this->typeDevis, $this->idDevis); if (empty($this->devis)) { fwk7_affiche_alert_message('Devis introuvable','danger'); } $this->lignes = fwc7_data_objet_ligs('', $this->typeDevis, $this->idDevis, MapperCommande::TYPE_LIGNE_DEVIS($this->typeDevis), '', '1', []); if (empty($this->lignes)) { fwk7_affiche_alert_message('Aucune ligne trouvée pour ce devis"','danger'); } // ... (truncated)

⚠️ Throws


🔧 genererNumeroCommande

Génère un nouveau numéro de commande
function genererNumeroCommande() { $this->params = fwk7_TS_NOOA_get_Entiteinfos_byUserID($this->devis['att11']); $idEntite = array_keys($this->params)[0]; $conditions = ["lig3 = " . MapperCommande::TYPE_COMMANDE($this->typeDevis)]; $donneesCompteur = fwc7_data_objet_lig('', MapperCommande::TYPE_PARAMETRE($this->typeDevis), $idEntite, MapperCommande::TYPE_LIGNE_PARAMETRE($this->typeDevis), '', $conditions, ''); $nouveauNumero = (int)$donneesCompteur['lig2'] + 1; // Mise à jour du compteur $donneesMAJ = ['lig2' => $nouveauNumero]; fwc7_modify_lig_merge('', MapperCommande::TYPE_PARAMETRE($this->typeDevis), $idEntite, MapperCommande::TYPE_LIGNE_PARAMETRE($this->typeDevis), '', $conditions, $donneesMAJ); $this->numeroCommande = [ 'numero' => $nouveauNumero, // ... (truncated)

🔧 creerCommande

Crée la commande et ses lignes
function creerCommande() { if ($this->commandeExistante) { return false; // Si la commande existe on retourne false } try { // Création de l'en-tête de la commande $idClient = fwc7_data_att_getraw('', MapperCommande::TYPE_OPPORTUNITE($this->typeDevis), $this->devis['att1'], "att2"); $donneesCommande = [ 'att4' => 'TEMPNUM', 'att1' => $this->devis['att17'], 'att90' => $this->devis['att13'], 'att3' => $this->devis['att90'], // ... (truncated)

↩️ Returns

(int|false) L'ID de la commande créée ou false si échec

🔧 creerLignesCommande

Crée les lignes de la commande
function creerLignesCommande() { foreach ($this->lignes as $ligne) { $donneesLigne = [ 'lig3' => $ligne['lig3'], // Quantité 'lig2' => $ligne['lig2'], // Prix unitaire 'lig1' => $ligne['lig1'], // Produit (non spé) 'lig4' => $ligne['lig4'], // Total HT 'lig5' => $ligne['lig5'], // Taux TVA 'lig6' => $ligne['lig15'], // Total TTC Remisé 'lig7' => $ligne['lig6'], // Total TVA 'lig8' => $ligne['lig7'], // Total TTC 'lig90' => $ligne['lig90'], // Description 'lig9' => $ligne['lig10'], // Produit (spé) 'lig10' => $ligne['lig9'], // Type remise 'lig11' => $ligne['lig14'], // Remise TTC ou Euros ]; // il y a t-il des unités dans les ligne de devis ? alors on les reprends dans les lignes de commande $uniteDevis = fwp7_param_template_lig_get_number('',$this->typeDevis, fwp7_param_objet_setting_get('',$this->typeDevis,'devis','id_lig'),'unite'); $uniteCommande = fwp7_param_template_lig_get_number('','168',fwp7_param_objet_setting_get('','168','commande','tlig'),'unite'); if (!empty($uniteDevis) && !empty($uniteCommande)) { $donneesLigne[$uniteCommande] = $ligne[$uniteDevis]; } // ... (truncated)

⚠️ Throws