Qual: Mutualize code

This commit is contained in:
Laurent Destailleur 2010-05-04 18:33:22 +00:00
parent 7ac9943ba4
commit a1ba46588e
4 changed files with 54 additions and 78 deletions

View File

@ -544,7 +544,7 @@ class Propal extends CommonObject
} }
if (! empty($this->ref)) if (! empty($this->ref))
{ {
$this->verifyNumRef($soc); // Check ref is not yet used $result=$this->verifyNumRef(); // Check ref is not yet used
} }
@ -1241,6 +1241,7 @@ class Propal extends CommonObject
// Propale signee // Propale signee
include_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php"); include_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php");
// TODO move in triggers
$result=$this->create_commande($user); $result=$this->create_commande($user);
if ($result >= 0) if ($result >= 0)
@ -1313,6 +1314,7 @@ class Propal extends CommonObject
* \brief Cree une commande a partir de la proposition commerciale * \brief Cree une commande a partir de la proposition commerciale
* \param user Utilisateur * \param user Utilisateur
* \return int <0 si ko, >=0 si ok * \return int <0 si ko, >=0 si ok
* TODO move in triggers
*/ */
function create_commande($user) function create_commande($user)
{ {
@ -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 * \brief Renvoie la reference de propale suivante non utilisee en fonction du module

View File

@ -32,6 +32,34 @@
class CommonObject 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 * \brief Ajoute un contact associe au l'entite definie dans $this->element
* \param fk_socpeople Id du contact a ajouter * \param fk_socpeople Id du contact a ajouter

View File

@ -101,20 +101,23 @@ class Fichinter extends CommonObject
// on verifie si la ref n'est pas utilisee // on verifie si la ref n'est pas utilisee
$soc = new Societe($this->db); $soc = new Societe($this->db);
$result=$soc->fetch($this->socid); $result=$soc->fetch($this->socid);
$result=$this->verifyNumRef($soc); if (! empty($this->ref))
if ($result > 0)
{ {
$this->error='ErrorRefAlreadyExists'; $result=$this->verifyNumRef(); // Check ref is not yet used
dol_syslog("Fichinter::create ".$this->error,LOG_WARNING); if ($result > 0)
$this->db->rollback(); {
return -3; $this->error='ErrorRefAlreadyExists';
} dol_syslog("Fichinter::create ".$this->error,LOG_WARNING);
else if ($result < 0) $this->db->rollback();
{ return -3;
$this->error=$this->db->error(); }
dol_syslog("Fichinter::create ".$this->error,LOG_ERR); else if ($result < 0)
$this->db->rollback(); {
return -2; $this->error=$this->db->error();
dol_syslog("Fichinter::create ".$this->error,LOG_ERR);
$this->db->rollback();
return -2;
}
} }
$now=dol_now(); $now=dol_now();
@ -409,39 +412,6 @@ class Fichinter extends CommonObject
return $result; 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 * \brief Renvoie la reference de fiche intervention suivante non utilisee en fonction du module

View File

@ -610,7 +610,7 @@ elseif ($fichinterid)
print '<table class="nobordernopadding" width="100%"><tr><td>'; print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Description'); print $langs->trans('Description');
print '</td>'; print '</td>';
if ($_GET['action'] != 'editdescription' && $fichinter->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdescription&amp;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&amp;id='.$fichinter->id.'">'.img_edit($langs->trans('Modify'),1).'</a></td>';
print '</tr></table>'; print '</tr></table>';
print '</td><td colspan="3">'; print '</td><td colspan="3">';
if ($_GET['action'] == 'editdescription') if ($_GET['action'] == 'editdescription')