From 64ee49be81c2c0e4d5a834d0248f69519b707904 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 9 Dec 2005 23:22:24 +0000 Subject: [PATCH] =?UTF-8?q?Cloture=20de=20propal=20mis=20en=20transaction.?= =?UTF-8?q?=20Le=20addslashes=20est=20d=E9plac=E9=20dans=20le=20insertp=20?= =?UTF-8?q?plutot=20que=20dans=20la=20variable=20appelante=20car=20elle=20?= =?UTF-8?q?peut=20etre=20utilis=E9=20pour=20d'autres=20finalit=E9=20(exemp?= =?UTF-8?q?le=20trigger)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/comm/propal.php | 6 +- htdocs/commande/commande.class.php | 10 +- htdocs/propal.class.php | 167 +++++++++++++++++------------ 3 files changed, 106 insertions(+), 77 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 4a23a78a529..c1ff22a4da3 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -159,9 +159,9 @@ if ($_GET['action'] == 'pdf') */ if ($_POST['action'] == 'setstatut' && $user->rights->propale->cloturer) { - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $propal->cloture($user, $_POST['statut'], addslashes($_POST['note'])); + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + $propal->cloture($user, $_POST['statut'], $_POST['note']); } /* diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index a2393413c26..cb531a726d6 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -72,10 +72,11 @@ class Commande $this->sources[5] = $langs->trans('OrderSource5'); $this->products = array(); } - /** \brief Créé la facture depuis une propale existante - \param user Utilisateur qui crée - \param propale_id id de la propale qui sert de modèle - */ + + /** \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 create_from_propale($user, $propale_id) { $propal = new Propal($this->db); @@ -103,6 +104,7 @@ class Commande $soc->id = $this->soc_id; $soc->set_as_client(); $this->propale_id = $propal->id; + return $this->create($user); } diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 51114de287d..2dbadb02a68 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -782,84 +782,111 @@ class Propal } } - /** - * \brief Cloture de la proposition commerciale - * - */ - - function cloture($user, $statut, $note) + /** + * \brief Cloture de la proposition commerciale + * \param user Utilisateur qui cloture + * \param statut Statut + * \param note Commentaire + * \return int <0 si ko, >0 si ok + */ + function cloture($user, $statut, $note) { - $this->statut = $statut; + $this->statut = $statut; + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; + $sql.= " SET fk_statut = $statut, note = '".addslashes($note)."', date_cloture=now(), fk_user_cloture=".$user->id; + $sql.= " WHERE rowid = ".$this->id; + + $resql=$this->db->query($sql); + if ($resql) + { + if ($statut == 2) + { + // Propale signée + include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = $statut, note = '$note', date_cloture=now(), fk_user_cloture=$user->id"; - $sql .= " WHERE rowid = $this->id;"; - - if ($this->db->query($sql)) - { - if ($statut == 2) - { - /* Propale signée */ - include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); + $result=$this->create_commande($user); - $this->create_commande($user); + if ($result >= 0) + { + // Classe la société rattachée comme client + $soc=new Societe($this->db); + $soc->id = $this->socidp; + $result=$soc->set_as_client(); + } + + if ($result < 0) + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -2; + } + } + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('PROP_CLOSE',$this,$user,$langs,$conf); + // Fin appel triggers - /* Classe la société rattachée comme client */ - - $soc = new Societe($this->db); - $soc->id = $this->socidp; - $soc->set_as_client(); - - - return 1; - } - else - { - /* Propale non signée */ - return 1; - } - } - else - { - dolibarr_print_error($this->db); - } + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } } - - /** - * \brief Créée une commande à partir de la proposition commerciale - * - */ - - function create_commande($user) + + + /** + * \brief Crée une commande à partir de la proposition commerciale + * \param user Utilisateur + * \return int <0 si ko, >=0 si ok + */ + function create_commande($user) { - if ($this->statut == 2) - { - /* Propale signée */ - include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); - $commande = new Commande($this->db); - $commande->create_from_propale($user, $this->id); - return 1; - } + global $conf; + + if ($conf->commande->enabled) + { + if ($this->statut == 2) + { + // Propale signée + include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); + $commande = new Commande($this->db); + $result=$commande->create_from_propale($user, $this->id); + + return $result; + } + else return 0; + } + else return 0; } - - /** - * - * - */ - - function reopen($userid) + + + /** + * + * + */ + function reopen($userid) { - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 0"; - - $sql .= " WHERE rowid = $this->id;"; - - if ($this->db->query($sql) ) - { - return 1; - } - else - { - dolibarr_print_error($this->db); - } + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 0"; + + $sql .= " WHERE rowid = $this->id;"; + + if ($this->db->query($sql) ) + { + return 1; + } + else + { + dolibarr_print_error($this->db); + } }