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:
parent
ba9b9b5211
commit
64ee49be81
@ -161,7 +161,7 @@ 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']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -72,7 +72,8 @@ 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
|
|
||||||
|
/** \brief Créé la commande depuis une propale existante
|
||||||
\param user Utilisateur qui crée
|
\param user Utilisateur qui crée
|
||||||
\param propale_id id de la propale qui sert de modèle
|
\param propale_id id de la propale qui sert de modèle
|
||||||
*/
|
*/
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -784,68 +784,95 @@ 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
|
||||||
|
* \return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function cloture($user, $statut, $note)
|
function cloture($user, $statut, $note)
|
||||||
{
|
{
|
||||||
$this->statut = $statut;
|
$this->statut = $statut;
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = $statut, note = '$note', date_cloture=now(), fk_user_cloture=$user->id";
|
$this->db->begin();
|
||||||
$sql .= " WHERE rowid = $this->id;";
|
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
$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)
|
if ($statut == 2)
|
||||||
{
|
{
|
||||||
/* Propale signée */
|
// Propale signée
|
||||||
include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
|
include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
|
||||||
|
|
||||||
$this->create_commande($user);
|
$result=$this->create_commande($user);
|
||||||
|
|
||||||
/* Classe la société rattachée comme client */
|
if ($result >= 0)
|
||||||
|
{
|
||||||
$soc = new Societe($this->db);
|
// Classe la société rattachée comme client
|
||||||
|
$soc=new Societe($this->db);
|
||||||
$soc->id = $this->socidp;
|
$soc->id = $this->socidp;
|
||||||
$soc->set_as_client();
|
$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
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Propale non signée */
|
$this->error=$this->db->error();
|
||||||
return 1;
|
$this->db->rollback();
|
||||||
}
|
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)
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
if ($conf->commande->enabled)
|
||||||
{
|
{
|
||||||
if ($this->statut == 2)
|
if ($this->statut == 2)
|
||||||
{
|
{
|
||||||
/* Propale signée */
|
// Propale signée
|
||||||
include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
|
include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
|
||||||
$commande = new Commande($this->db);
|
$commande = new Commande($this->db);
|
||||||
$commande->create_from_propale($user, $this->id);
|
$result=$commande->create_from_propale($user, $this->id);
|
||||||
return 1;
|
|
||||||
|
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";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user