Task # 608 : forgot to clone lines... Now lines are also cloned and prices are valid prices at the clone date

This commit is contained in:
Maxime Kohlhaas 2012-11-23 09:00:17 +01:00
parent 0bb3f766f6
commit 3306d91ce1

View File

@ -953,35 +953,68 @@ class CommandeFournisseur extends CommonOrder
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur");
if ($this->id) {
$num=count($this->lines);
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; /*
$sql.= " SET ref='(PROV".$this->id.")'"; * Insertion du detail des produits dans la base
$sql.= " WHERE rowid=".$this->id; */
dol_syslog(get_class($this)."::create sql=".$sql); for ($i=0;$i<$num;$i++)
if ($this->db->query($sql)) {
{ $result = $this->addline(
// On logue creation pour historique $this->lines[$i]->desc,
$this->log($user, 0, time()); $this->lines[$i]->subprice,
$this->lines[$i]->qty,
$this->lines[$i]->tva_tx,
$this->lines[$i]->localtax1_tx,
$this->lines[$i]->localtax2_tx,
$this->lines[$i]->fk_product,
0,
$this->lines[$i]->ref_fourn,
$this->lines[$i]->remise_percent,
'HT',
0,
$this->lines[$i]->info_bits
);
if ($result < 0)
{
$this->error=$this->db->lasterror();
dol_print_error($this->db);
$this->db->rollback();
return -1;
}
}
if (! $notrigger) $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
{ $sql.= " SET ref='(PROV".$this->id.")'";
// Appel des triggers $sql.= " WHERE rowid=".$this->id;
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; dol_syslog(get_class($this)."::create sql=".$sql);
$interface=new Interfaces($this->db); if ($this->db->query($sql))
$result=$interface->run_triggers('ORDER_SUPPLIER_CREATE',$this,$user,$langs,$conf); {
if ($result < 0) { $error++; $this->errors=$interface->errors; } // On logue creation pour historique
// Fin appel triggers $this->log($user, 0, time());
}
if (! $notrigger)
$this->db->commit(); {
return $this->id; // Appel des triggers
} include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
else $interface=new Interfaces($this->db);
{ $result=$interface->run_triggers('ORDER_SUPPLIER_CREATE',$this,$user,$langs,$conf);
$this->error=$this->db->error(); if ($result < 0) { $error++; $this->errors=$interface->errors; }
dol_syslog(get_class($this)."::create: Failed -2 - ".$this->error, LOG_ERR); // Fin appel triggers
$this->db->rollback(); }
return -2;
$this->db->commit();
return $this->id;
}
else
{
$this->error=$this->db->error();
dol_syslog(get_class($this)."::create: Failed -2 - ".$this->error, LOG_ERR);
$this->db->rollback();
return -2;
}
} }
} }
else else
@ -1107,7 +1140,6 @@ class CommandeFournisseur extends CommonOrder
} }
$desc=trim($desc); $desc=trim($desc);
// Check parameters // Check parameters
if ($qty < 1 && ! $fk_product) if ($qty < 1 && ! $fk_product)
{ {
@ -1116,7 +1148,6 @@ class CommandeFournisseur extends CommonOrder
} }
if ($type < 0) return -1; if ($type < 0) return -1;
if ($this->statut == 0) if ($this->statut == 0)
{ {
$this->db->begin(); $this->db->begin();