Qual: Mutualize code
This commit is contained in:
parent
7ac9943ba4
commit
a1ba46588e
@ -92,7 +92,7 @@ class Propal extends CommonObject
|
||||
var $products=array();
|
||||
|
||||
var $lines = array();
|
||||
|
||||
|
||||
var $origin;
|
||||
var $origin_id;
|
||||
|
||||
@ -544,7 +544,7 @@ class Propal extends CommonObject
|
||||
}
|
||||
if (! empty($this->ref))
|
||||
{
|
||||
$this->verifyNumRef($soc); // Check ref is not yet used
|
||||
$result=$this->verifyNumRef(); // Check ref is not yet used
|
||||
}
|
||||
|
||||
|
||||
@ -636,7 +636,7 @@ class Propal extends CommonObject
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add linked object
|
||||
if ($this->origin && $this->origin_id)
|
||||
{
|
||||
@ -1241,6 +1241,7 @@ class Propal extends CommonObject
|
||||
// Propale signee
|
||||
include_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php");
|
||||
|
||||
// TODO move in triggers
|
||||
$result=$this->create_commande($user);
|
||||
|
||||
if ($result >= 0)
|
||||
@ -1313,6 +1314,7 @@ class Propal extends CommonObject
|
||||
* \brief Cree une commande a partir de la proposition commerciale
|
||||
* \param user Utilisateur
|
||||
* \return int <0 si ko, >=0 si ok
|
||||
* TODO move in triggers
|
||||
*/
|
||||
function create_commande($user)
|
||||
{
|
||||
@ -1611,7 +1613,7 @@ class Propal extends CommonObject
|
||||
$this->db->rollback();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// We remove directory
|
||||
$propalref = dol_sanitizeFileName($this->ref);
|
||||
if ($conf->propale->dir_output)
|
||||
@ -2020,30 +2022,6 @@ class Propal extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Check if ref is used. And if used tkae next one.
|
||||
* \param soc objet societe
|
||||
*/
|
||||
function verifyNumRef($soc)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
|
||||
$sql.= " WHERE ref = '".$this->ref."'";
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows($result);
|
||||
if ($num > 0)
|
||||
{
|
||||
$this->ref = $this->getNextNumRef($soc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Renvoie la reference de propale suivante non utilisee en fonction du module
|
||||
|
||||
@ -32,6 +32,34 @@
|
||||
|
||||
class CommonObject
|
||||
{
|
||||
/**
|
||||
* \brief Check if ref is used.
|
||||
* \return int <0 if KO, 0 if not found, >0 if found
|
||||
*/
|
||||
function verifyNumRef()
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$this->element;
|
||||
$sql.= " WHERE ref = '".$this->ref."'";
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
|
||||
dol_syslog("CommonObject::verifyNumRef sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $this->db->num_rows($resql);
|
||||
return $num;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("CommonObject::verifyNumRef ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Ajoute un contact associe au l'entite definie dans $this->element
|
||||
* \param fk_socpeople Id du contact a ajouter
|
||||
@ -160,7 +188,7 @@ class CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Supprime une ligne de contact
|
||||
* \return statur >0 si ok, <0 si ko
|
||||
@ -169,13 +197,13 @@ class CommonObject
|
||||
{
|
||||
$temp = array();
|
||||
$typeContact = $this->liste_type_contact(0);
|
||||
|
||||
|
||||
foreach($typeContact as $key => $value)
|
||||
{
|
||||
array_push($temp,$key);
|
||||
}
|
||||
$listId = implode(",", $temp);
|
||||
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
|
||||
$sql.= " WHERE element_id =".$this->id;
|
||||
$sql.= " AND fk_c_type_contact IN (".$listId.")";
|
||||
|
||||
@ -101,20 +101,23 @@ class Fichinter extends CommonObject
|
||||
// on verifie si la ref n'est pas utilisee
|
||||
$soc = new Societe($this->db);
|
||||
$result=$soc->fetch($this->socid);
|
||||
$result=$this->verifyNumRef($soc);
|
||||
if ($result > 0)
|
||||
if (! empty($this->ref))
|
||||
{
|
||||
$this->error='ErrorRefAlreadyExists';
|
||||
dol_syslog("Fichinter::create ".$this->error,LOG_WARNING);
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
else if ($result < 0)
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("Fichinter::create ".$this->error,LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
$result=$this->verifyNumRef(); // Check ref is not yet used
|
||||
if ($result > 0)
|
||||
{
|
||||
$this->error='ErrorRefAlreadyExists';
|
||||
dol_syslog("Fichinter::create ".$this->error,LOG_WARNING);
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
else if ($result < 0)
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("Fichinter::create ".$this->error,LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
$now=dol_now();
|
||||
@ -409,39 +412,6 @@ class Fichinter extends CommonObject
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Verifie si la ref n'est pas deja utilisee. Si oui, la modifie avec la prochaine libre.
|
||||
* \param soc objet societe
|
||||
* \return int <0 if KO, 0 if not found, >0 if found
|
||||
*/
|
||||
function verifyNumRef($soc)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."fichinter";
|
||||
$sql.= " WHERE ref = '".$this->ref."'";
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows($result);
|
||||
if ($num > 0)
|
||||
{
|
||||
$this->ref = $this->getNextNumRef($soc);
|
||||
}
|
||||
dol_syslog("Fichinter::verifyNumber num=".$num,LOG_DEBUG);
|
||||
return $num;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("Fichinter::verifyNumber ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Renvoie la reference de fiche intervention suivante non utilisee en fonction du module
|
||||
|
||||
@ -610,7 +610,7 @@ elseif ($fichinterid)
|
||||
print '<table class="nobordernopadding" width="100%"><tr><td>';
|
||||
print $langs->trans('Description');
|
||||
print '</td>';
|
||||
if ($_GET['action'] != 'editdescription' && $fichinter->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdescription&id='.$fichinter->id.'">'.img_edit($langs->trans('Modify'),1).'</a></td>';
|
||||
if ($_GET['action'] != 'editdescription' && $fichinter->statut == 0) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdescription&id='.$fichinter->id.'">'.img_edit($langs->trans('Modify'),1).'</a></td>';
|
||||
print '</tr></table>';
|
||||
print '</td><td colspan="3">';
|
||||
if ($_GET['action'] == 'editdescription')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user