New: Show name of sales representatives if number is lower than 3

This commit is contained in:
Laurent Destailleur 2011-02-06 19:36:28 +00:00
parent c5b96bd327
commit b21d3fad2a
2 changed files with 65 additions and 27 deletions

View File

@ -1225,6 +1225,41 @@ class Societe extends CommonObject
} }
} }
/**
* Return array of sales representatives
* @return array Array of sales representatives of third party
*/
function getSalesRepresentatives($user='')
{
global $conf;
$reparray=array();
$sql = "SELECT u.rowid, u.name, u.firstname";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE u.rowid = sc.fk_user AND sc.fk_soc =".$this->id;
$sql.= " AND entity in (0, ".$conf->entity.")";
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i=0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$reparray[$i]['id']=$obj->rowid;
$reparray[$i]['name']=$obj->name;
$reparray[$i]['firstname']=$obj->firstname;
$i++;
}
return $reparray;
}
else {
dol_print_error($this->db);
return -1;
}
}
/** /**
* Set the price level * Set the price level

View File

@ -877,11 +877,11 @@ else
print '<td nowrap="nowrap">'.$langs->trans('VATIntra').'</td>'; print '<td nowrap="nowrap">'.$langs->trans('VATIntra').'</td>';
print '<td nowrap="nowrap">'; print '<td nowrap="nowrap">';
$s = '<input type="text" class="flat" name="tva_intra" size="12" maxlength="20" value="'.$soc->tva_intra.'">'; $s = '<input type="text" class="flat" name="tva_intra" size="12" maxlength="20" value="'.$soc->tva_intra.'">';
if (empty($conf->global->MAIN_DISABLEVATCHECK)) if (empty($conf->global->MAIN_DISABLEVATCHECK))
{ {
$s.=' '; $s.=' ';
if ($conf->use_javascript_ajax) if ($conf->use_javascript_ajax)
{ {
print "\n"; print "\n";
@ -899,7 +899,7 @@ else
$s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$soc->id_pays).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>'; $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$soc->id_pays).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
} }
} }
print $s; print $s;
print '</td>'; print '</td>';
@ -1259,11 +1259,11 @@ else
print '<td nowrap="nowrap">'.$langs->trans('VATIntra').'</td>'; print '<td nowrap="nowrap">'.$langs->trans('VATIntra').'</td>';
print '<td nowrap="nowrap">'; print '<td nowrap="nowrap">';
$s ='<input type="text" class="flat" name="tva_intra" size="12" maxlength="20" value="'.$soc->tva_intra.'">'; $s ='<input type="text" class="flat" name="tva_intra" size="12" maxlength="20" value="'.$soc->tva_intra.'">';
if (empty($conf->global->MAIN_DISABLEVATCHECK)) if (empty($conf->global->MAIN_DISABLEVATCHECK))
{ {
$s.=' &nbsp; '; $s.=' &nbsp; ';
if ($conf->use_javascript_ajax) if ($conf->use_javascript_ajax)
{ {
print "\n"; print "\n";
@ -1281,9 +1281,9 @@ else
$s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$soc->id_pays).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>'; $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$soc->id_pays).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
} }
} }
print $s; print $s;
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -1526,11 +1526,11 @@ else
$s=''; $s='';
$s.=$soc->tva_intra; $s.=$soc->tva_intra;
$s.='<input type="hidden" name="tva_intra" size="12" maxlength="20" value="'.$soc->tva_intra.'">'; $s.='<input type="hidden" name="tva_intra" size="12" maxlength="20" value="'.$soc->tva_intra.'">';
if (empty($conf->global->MAIN_DISABLEVATCHECK)) if (empty($conf->global->MAIN_DISABLEVATCHECK))
{ {
$s.=' &nbsp; '; $s.=' &nbsp; ';
if ($conf->use_javascript_ajax) if ($conf->use_javascript_ajax)
{ {
print "\n"; print "\n";
@ -1664,26 +1664,29 @@ else
print '</td>'; print '</td>';
print '<td colspan="3">'; print '<td colspan="3">';
$sql = "SELECT count(sc.rowid) as nb"; $listsalesrepresentatives=$soc->getSalesRepresentatives($user);
$sql.= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $nbofsalesrepresentative=sizeof($listsalesrepresentatives);
$sql.= " WHERE sc.fk_soc =".$soc->id; if ($nbofsalesrepresentative > 3) // We print only number
$resql = $db->query($sql);
if ($resql)
{ {
$num = $db->num_rows($resql); print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$soc->id.'">';
$obj = $db->fetch_object($resql); print $nbofsalesrepresentative;
if ($obj->nb) print '</a>';
{
print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$soc->id.'">';
print $obj->nb;
print '</a>';
}
else print $langs->trans("NoSalesRepresentativeAffected");
}
else {
dol_print_error($db);
} }
else if ($nbofsalesrepresentative > 0)
{
$userstatic=new User($db);
$i=1;
foreach($listsalesrepresentatives as $val)
{
$userstatic->id=$val['id'];
$userstatic->nom=$val['name'];
$userstatic->prenom=$val['firstname'];
print $userstatic->getNomUrl(1);
$i++;
if ($i < 3) print ', ';
}
}
else print $langs->trans("NoSalesRepresentativeAffected");
print '</td></tr>'; print '</td></tr>';
// Module Adherent // Module Adherent