Cloture de propal mis en transaction.

Le addslashes est déplacé dans le insertp plutot que dans la variable appelante car elle peut etre utilisé pour d'autres finalité (exemple trigger)
This commit is contained in:
Laurent Destailleur 2005-12-09 23:22:24 +00:00
parent ba9b9b5211
commit 64ee49be81
3 changed files with 106 additions and 77 deletions

View File

@ -159,9 +159,9 @@ if ($_GET['action'] == 'pdf')
*/ */
if ($_POST['action'] == 'setstatut' && $user->rights->propale->cloturer) if ($_POST['action'] == 'setstatut' && $user->rights->propale->cloturer)
{ {
$propal = new Propal($db); $propal = new Propal($db);
$propal->fetch($_GET['propalid']); $propal->fetch($_GET['propalid']);
$propal->cloture($user, $_POST['statut'], addslashes($_POST['note'])); $propal->cloture($user, $_POST['statut'], $_POST['note']);
} }
/* /*

View File

@ -72,10 +72,11 @@ class Commande
$this->sources[5] = $langs->trans('OrderSource5'); $this->sources[5] = $langs->trans('OrderSource5');
$this->products = array(); $this->products = array();
} }
/** \brief Créé la facture depuis une propale existante
\param user Utilisateur qui crée /** \brief Créé la commande depuis une propale existante
\param propale_id id de la propale qui sert de modèle \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) function create_from_propale($user, $propale_id)
{ {
$propal = new Propal($this->db); $propal = new Propal($this->db);
@ -103,6 +104,7 @@ class Commande
$soc->id = $this->soc_id; $soc->id = $this->soc_id;
$soc->set_as_client(); $soc->set_as_client();
$this->propale_id = $propal->id; $this->propale_id = $propal->id;
return $this->create($user); return $this->create($user);
} }

View File

@ -782,84 +782,111 @@ class Propal
} }
} }
/** /**
* \brief Cloture de la proposition commerciale * \brief Cloture de la proposition commerciale
* * \param user Utilisateur qui cloture
*/ * \param statut Statut
* \param note Commentaire
function cloture($user, $statut, $note) * \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"; $result=$this->create_commande($user);
$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");
$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 */ $this->db->commit();
return 1;
$soc = new Societe($this->db); }
$soc->id = $this->socidp; else
$soc->set_as_client(); {
$this->error=$this->db->error();
$this->db->rollback();
return 1; return -1;
} }
else
{
/* Propale non signée */
return 1;
}
}
else
{
dolibarr_print_error($this->db);
}
} }
/**
* \brief Créée une commande à partir de la proposition commerciale /**
* * \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) */
function create_commande($user)
{ {
if ($this->statut == 2) global $conf;
{
/* Propale signée */ if ($conf->commande->enabled)
include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); {
$commande = new Commande($this->db); if ($this->statut == 2)
$commande->create_from_propale($user, $this->id); {
return 1; // 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 = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 0";
$sql .= " WHERE rowid = $this->id;"; $sql .= " WHERE rowid = $this->id;";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
return 1; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
} }
} }