From 78000e1dc17fd0cdaf01815bc5be4910651d5e0f Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 5 Oct 2006 08:33:04 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20fonction=20pour=20permettre=20une=20cr?= =?UTF-8?q?=E9ation=20de=20commande=20fournisseur=20=E0=20partir=20d'une?= =?UTF-8?q?=20commande=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/fourn/fournisseur.class.php | 12 +++++++ htdocs/fourn/fournisseur.commande.class.php | 38 +++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/htdocs/fourn/fournisseur.class.php b/htdocs/fourn/fournisseur.class.php index 26ce7842b4f..a8a19dfbf77 100644 --- a/htdocs/fourn/fournisseur.class.php +++ b/htdocs/fourn/fournisseur.class.php @@ -104,6 +104,18 @@ class Fournisseur extends Societe } + /** + * \brief Créé la commande au statut brouillon + * \param user Utilisateur qui crée + * \return int <0 si ko, id de la commande créée si ok + */ + function updateFromCommandeClient($user, $idc, $comclientid) + { + $comm = new CommandeFournisseur($this->db); + $comm->socid = $this->id; + + $comm->updateFromCommandeClient($user, $idc, $comclientid); + } /** * \brief Créé la commande au statut brouillon diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php index b104a71c406..2f2c7943870 100644 --- a/htdocs/fourn/fournisseur.commande.class.php +++ b/htdocs/fourn/fournisseur.commande.class.php @@ -900,6 +900,44 @@ class CommandeFournisseur extends Commande return $result ; } + /** \brief Créé la commande depuis une propale existante + \param user Utilisateur qui crée + \param propale_id id de la propale qui sert de modèle + */ + function updateFromCommandeClient($user, $idc, $comclientid) + { + $comclient = new Commande($this->db); + $comclient->fetch($comclientid); + + $this->id = $idc; + + $this->lines = array(); + + for ($i = 0 ; $i < sizeof($comclient->lignes) ; $i++) + { + $prod = new Product($this->db, $comclient->lignes[$i]->fk_product); + if ($prod->fetch($comclient->lignes[$i]->fk_product) > 0) + { + $libelle = $prod->libelle; + $ref = $prod->ref; + } + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet"; + $sql .= " (fk_commande,label,description,fk_product, price, qty, tva_tx, remise_percent, subprice, remise, ref)"; + $sql .= " VALUES (".$idc.", '" . addslashes($libelle) . "','" . addslashes($comclient->lignes[$i]->desc) . "'"; + $sql .= ",".$comclient->lignes[$i]->fk_product.",'".price2num($comclient->lignes[$i]->price)."'"; + $sql .= ", '".$comclient->lignes[$i]->qty."', ".$comclient->lignes[$i]->tva_tx.", ".$comclient->lignes[$i]->remise_percent; + $sql .= ", '".price2num($comclient->lignes[$i]->subprice)."','0','".$ref."') ;"; + if ( $this->db->query( $sql) ) + { + $this->update_price(); + } + } + + return 1; + } + + /** * \brief Met a jour les notes * \return int <0 si ko, >=0 si ok