Qual: Mise en transaction de la cration de propales et leur validation. Ajout des appels aux triggers.
This commit is contained in:
parent
543b7e7ec0
commit
8dfd0b0fa0
@ -333,77 +333,81 @@ class Propal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
function create()
|
/**
|
||||||
|
* \brief Crée une propal
|
||||||
|
* \return int <0 si ko, >=0 si ok
|
||||||
|
*/
|
||||||
|
function create()
|
||||||
{
|
{
|
||||||
/*
|
global $langs,$conf;
|
||||||
* Insertion dans la base
|
|
||||||
*/
|
|
||||||
$this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
|
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, fk_soc_contact, price, remise, tva, total, datep, datec, ref, fk_user_author, note, model_pdf, fin_validite) ";
|
// Définition paramètres
|
||||||
$sql .= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, 0,0,".$this->db->idate($this->datep).", now(), '$this->ref', $this->author, '".addslashes($this->note)."','$this->modelpdf',".$this->db->idate($this->fin_validite).")";
|
$this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
|
||||||
$sqlok = 0;
|
|
||||||
|
|
||||||
if ( $this->db->query($sql) )
|
$this->db->begin();
|
||||||
{
|
|
||||||
|
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal");
|
// Insertion dans la base
|
||||||
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, fk_soc_contact, price, remise, tva, total, datep, datec, ref, fk_user_author, note, model_pdf, fin_validite) ";
|
||||||
|
$sql.= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, 0,0,".$this->db->idate($this->datep).", now(), '$this->ref', $this->author, '".addslashes($this->note)."','$this->modelpdf',".$this->db->idate($this->fin_validite).")";
|
||||||
|
|
||||||
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE ref='$this->ref';";
|
$resql=$this->db->query($sql);
|
||||||
if ( $this->db->query($sql) )
|
if ($resql)
|
||||||
{
|
{
|
||||||
/*
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal");
|
||||||
* Insertion du detail des produits dans la base
|
|
||||||
*/
|
|
||||||
if ( $this->db->num_rows() )
|
|
||||||
{
|
|
||||||
$propalid = $this->db->result( 0, 0);
|
|
||||||
$this->db->free();
|
|
||||||
|
|
||||||
for ($i = 0 ; $i < sizeof($this->products) ; $i++)
|
if ($this->id)
|
||||||
{
|
{
|
||||||
$prod = new Product($this->db, $this->products[$i]);
|
/*
|
||||||
$prod->fetch($this->products[$i]);
|
* Insertion du detail des produits dans la base
|
||||||
|
*/
|
||||||
|
for ($i = 0 ; $i < sizeof($this->products) ; $i++)
|
||||||
|
{
|
||||||
|
$prod = new Product($this->db, $this->products[$i]);
|
||||||
|
$result=$prod->fetch($this->products[$i]);
|
||||||
|
|
||||||
$this->insert_product($this->products[$i],
|
$result=$this->insert_product($this->products[$i],
|
||||||
$this->products_qty[$i],
|
$this->products_qty[$i],
|
||||||
$this->products_remise_percent[$i]);
|
$this->products_remise_percent[$i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Affectation au projet
|
||||||
*
|
if ($this->projetidp)
|
||||||
*/
|
{
|
||||||
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_projet=$this->projetidp WHERE ref='$this->ref'";
|
||||||
|
$result=$this->db->query($sql);
|
||||||
|
}
|
||||||
|
|
||||||
$this->update_price();
|
$resql=$this->update_price();
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
// Appel des triggers
|
||||||
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('PROPAL_CREATE',$this,$user,$langs,$conf);
|
||||||
|
// Fin appel triggers
|
||||||
|
|
||||||
/*
|
$this->db->commit();
|
||||||
* Affectation au projet
|
return $this->id;
|
||||||
*/
|
}
|
||||||
if ($this->projetidp)
|
else
|
||||||
{
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_projet=$this->projetidp WHERE ref='$this->ref';";
|
$this->error=$this->db->error();
|
||||||
$this->db->query($sql);
|
dolibarr_syslog("Propal::Create -2 ".$this->error);
|
||||||
}
|
$this->db->rollback();
|
||||||
}
|
return -2;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
dolibarr_syslog("Propal::Create -2");
|
else
|
||||||
return -2;
|
{
|
||||||
}
|
$this->error=$this->db->error();
|
||||||
}
|
dolibarr_syslog("Propal::Create -1 ".$this->error);
|
||||||
else
|
$this->db->rollback();
|
||||||
{
|
return -1;
|
||||||
dolibarr_syslog("Propal::Create -1 $sql");
|
}
|
||||||
return -1;
|
|
||||||
}
|
return $this->id;
|
||||||
return $this->id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -610,29 +614,42 @@ class Propal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/*
|
* \brief Passe au statut valider une propale
|
||||||
*
|
* \param user Objet utilisateur qui valide
|
||||||
*
|
* \return int <0 si ko, >=0 si ok
|
||||||
*/
|
*/
|
||||||
function valid($user)
|
function valid($user)
|
||||||
{
|
{
|
||||||
if ($user->rights->propale->valider)
|
global $conf,$langs;
|
||||||
{
|
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 1, date_valid=now(), fk_user_valid=$user->id";
|
if ($user->rights->propale->valider)
|
||||||
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
{
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal";
|
||||||
{
|
$sql.= " SET fk_statut = 1, date_valid=now(), fk_user_valid=".$user->id;
|
||||||
return 1;
|
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
|
||||||
}
|
|
||||||
else
|
if ($this->db->query($sql))
|
||||||
{
|
{
|
||||||
return -1;
|
|
||||||
}
|
// Appel des triggers
|
||||||
}
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
}
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('PROPAL_VALIDATE',$this,$user,$langs,$conf);
|
||||||
|
// Fin appel triggers
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user