diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 13fd0727a72..a0876250a77 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -502,12 +502,15 @@ class Commande extends CommonObject } /** - * \brief Create order - * \param user Objet utilisateur qui cree + * \brief Create order + * \param user Objet user that make creation + * \return int <0 if KO, >0 if OK + * \remarks this->ref can be set or empty. If empty, we will use "(PROV)" */ function create($user) { global $conf,$langs,$mysoc; + $error=0; // Clean parameters $this->brouillon = 1; // On positionne en mode brouillon la commande @@ -515,11 +518,13 @@ class Commande extends CommonObject dol_syslog("Commande::create user=".$user->id); // Check parameters - if (empty($this->ref)) - { - $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Ref")); + $soc = new Societe($this->db); + $result=$soc->fetch($this->socid); + if ($result < 0) + { + $this->error="Failed to fetch company"; dol_syslog("Commande::create ".$this->error, LOG_ERR); - return -1; + return -2; } if (! empty($conf->global->COMMANDE_REQUIRE_SOURCE) && $this->source < 0) { @@ -530,14 +535,6 @@ class Commande extends CommonObject if (! $remise) $remise=0; if (! $this->projetid) $this->projetid = 0; - $soc = new Societe($this->db); - $result=$soc->fetch($this->socid); - if ($result < 0) - { - $this->error="Failed to fetch company"; - dol_syslog("Commande::create ".$this->error, LOG_ERR); - return -2; - } $this->db->begin(); diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 641442eb48b..4b048bc0c53 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -130,11 +130,13 @@ class Facture extends CommonObject * \brief Create invoice in database * \param user Object user that create * \param notrigger 1 ne declenche pas les triggers, 0 sinon - * \return int <0 si ko, >0 si ok + * \return int <0 if KO, >0 if OK + * \remarks this->ref can be set or empty. If empty, we will use "(PROV)" */ function create($user,$notrigger=0) { global $langs,$conf,$mysoc; + $error=0; // Clean parameters if (! $this->type) $this->type = 0; @@ -148,21 +150,15 @@ class Facture extends CommonObject dol_syslog("Facture::Create user=".$user->id); // Check parameters - // TODO suppression de cette verification a confirmer - // la ref est toujours vide puisque c'est une création - /* - if (empty($this->ref)) - { - $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Ref")); - dol_syslog("Facture::create ".$this->error, LOG_ERR); - return -1; - } - */ - $soc = new Societe($this->db); - $soc->fetch($this->socid); + $result=$soc->fetch($this->socid); + if ($result < 0) + { + $this->error="Failed to fetch company"; + dol_syslog("Facture::create ".$this->error, LOG_ERR); + return -2; + } - $error=0; $this->db->begin(); diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 22b25557a43..8fc94994195 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -512,27 +512,32 @@ class Propal extends CommonObject /** * \brief Create commercial proposal * \param user User that create - * \return int <0 si ko, >=0 si ok + * \return int <0 if KO, >=0 if OK + * \remarks this->ref can be set or empty. If empty, we will use "(PROV)" */ function create($user='') { global $langs,$conf,$mysoc; + $error=0; // Clean parameters $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600); - + dol_syslog("Propal::Create"); - + // Check parameters - if (empty($this->ref)) - { - $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Ref")); - dol_syslog("Facture::create ".$this->error, LOG_ERR); - return -1; - } $soc = new Societe($this->db); - $soc->fetch($this->socid); - $this->verifyNumRef($soc); // Check ref is not yet used + $result=$soc->fetch($this->socid); + if ($result < 0) + { + $this->error="Failed to fetch company"; + dol_syslog("Propal::create ".$this->error, LOG_ERR); + return -2; + } + if (! empty($this->ref)) + { + $this->verifyNumRef($soc); // Check ref is not yet used + } $this->db->begin(); @@ -1972,7 +1977,7 @@ class Propal extends CommonObject } /** - * \brief Verifie si la ref n'est pas deja utilisee + * \brief Check if ref is used. And if used tkae next one. * \param soc objet societe */ function verifyNumRef($soc)