diff --git a/htdocs/comm/mailing/mailing.class.php b/htdocs/comm/mailing/mailing.class.php index 65de6a3a735..edc585b8141 100644 --- a/htdocs/comm/mailing/mailing.class.php +++ b/htdocs/comm/mailing/mailing.class.php @@ -71,7 +71,6 @@ class Mailing extends CommonObject function Mailing($DB) { $this->db = $DB ; - $this->db_table = MAIN_DB_PREFIX."mailing"; // List of language codes for status $this->statuts[0] = 'MailingStatusDraft'; @@ -100,7 +99,7 @@ class Mailing extends CommonObject return -1; } - $sql = "INSERT INTO ".$this->db_table; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing"; $sql .= " (date_creat, fk_user_creat, entity)"; $sql .= " VALUES (".$this->db->idate(mktime()).", ".$user->id.", ".$conf->entity.")"; @@ -113,7 +112,7 @@ class Mailing extends CommonObject $result=$this->db->query($sql); if ($result) { - $this->id = $this->db->last_insert_id($this->db_table); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing"); if ($this->update($user) > 0) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 37cbd977447..7280227abdc 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -524,6 +524,8 @@ class Commande extends CommonObject { global $conf; + $error=0; + if ($user->rights->commande->valider) { $this->db->begin(); @@ -533,20 +535,26 @@ class Commande extends CommonObject $sql.= " WHERE rowid = ".$this->id; $sql.= " AND fk_statut = 1"; - if ($this->db->query($sql) ) + dol_syslog("Commande::cancel sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) { // If stock is decremented on validate order, we must reincrement it - if($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) + if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); - $mouvP = new MouvementStock($this->db); - // We increment stock of product (and sub-products) - $entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot - $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->subprice); - - if ($result > 0) + if ($this->lignes[$i]->fk_product > 0 && $this->lignes[$i]->product_type == 0) { + $mouvP = new MouvementStock($this->db); + // We increment stock of product (and sub-products) + $entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot + $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->subprice); + if ($result < 0) { $error++; } + } + + if (! $error) + { + $this->statut=-1; $this->db->commit(); return $result; } diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index a492ac089c3..2840cb4dde5 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -55,6 +55,8 @@ class MouvementStock $error = 0; dol_syslog("MouvementStock::_create start userid=$user->id, fk_product=$fk_product, warehouse=$entrepot_id, qty=$qty, type=$type, price=$price label=$label"); + $now=dol_now(); + $this->db->begin(); $product = new Product($this->db); @@ -69,7 +71,7 @@ class MouvementStock { $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement"; $sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, label, price)"; - $sql.= " VALUES (".$this->db->idate(gmmktime()).", ".$fk_product.", ".$entrepot_id.", ".$qty.", ".$type.","; + $sql.= " VALUES ('".$this->db->idate($now)."', ".$fk_product.", ".$entrepot_id.", ".$qty.", ".$type.","; $sql.= " ".$user->id.","; $sql.= " '".addslashes($label)."',"; $sql.= " '".price2num($price)."')"; @@ -77,7 +79,7 @@ class MouvementStock dol_syslog("MouvementStock::_create sql=".$sql, LOG_DEBUG); if ($resql = $this->db->query($sql)) { - $mvid = $this->db->last_insert_id($resql); + $mvid = $this->db->last_insert_id(MAIN_DB_PREFIX."stock_mouvement"); } else { diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index b9b668f990f..49e76e71a65 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -732,8 +732,7 @@ class User extends CommonObject dol_syslog("User::Create sql=".$sql, LOG_DEBUG); if ($result) { - $table = "".MAIN_DB_PREFIX."user"; - $this->id = $this->db->last_insert_id($table); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."user"); // Set default rights if ($this->set_default_rights() < 0)