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
- $id_type (int) Le type ID du devis
- $id_obje (int) L'ID du devis
⚠️ Throws
- Exception: Si les données du devis sont invalides
đź”§ 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
- Exception: Si les données sont invalides
đź”§ 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");
// S'il n'y a pas de date de signature,
// on met la date du jour par défaut pour gérer le cas de création de commande
// en passant par la modal de signature manuel.
if (empty($this->devis['attf107'])) {
$dateSignature = date('Ymd');
} else {
$dateSignature = $this->devis['attf107'];
}
// ... (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
'lig16' => $ligne['lig20'], // Unité
'lig23' => $ligne['lig23'], // Section
'lig22' => $ligne['lig22'], // Designation personnalisée
'lig91' => $ligne['lig91'], // Designation pdf
];
$result = fwc7_modify_lig_create('', MapperCommande::TYPE_COMMANDE($this->typeDevis), $this->idCommande, MapperCommande::TYPE_LIGNE_COMMANDE($this->typeDevis), $donneesLigne, 'new');
if (!$result) {
throw new Exception("Échec de la création d'une ligne de commande");
}
}
}
⚠️ Throws
- Exception: Si erreur pendant la création des lignes