public function defalquer_stock($retourenstock = false) { try { $modules = new Modules(); if ($modules->charger_id($this->paiement)) { $modpaiement = ActionsModules::instance()->instancier($modules->nom); if ($retourenstock) { $defalquer = $modpaiement->defalqcmd != 0 || $modpaiement->defalqcmd == 0 && $this->statut != self::NONPAYE; } else { $defalquer = $modpaiement->defalqcmd == 0; } if ($defalquer) { $delta = $retourenstock ? 1 : -1; $venteprod = new Venteprod(); $query = "select * from {$venteprod->table} where commande='" . $this->id . "'"; $resul = $venteprod->query($query); while ($resul && ($row = $venteprod->fetch_object($resul))) { // Mise à jour du stock général $produit = new Produit($row->ref); $produit->stock += $delta * $row->quantite; $produit->maj(); $vdec = new Ventedeclidisp(); $query2 = "select * from {$vdec->table} where venteprod='" . $row->id . "'"; $resul2 = $vdec->query($query2); while ($resul2 && ($row2 = $vdec->fetch_object($resul2))) { $stock = new Stock(); // Mise à jour du stock des declinaisons if ($stock->charger($row2->declidisp, $produit->id)) { $stock->valeur += $delta * $row->quantite; $stock->maj(); } } } } } } catch (Exception $ex) { // Rien } }