Qual: Mutualisation de la liste des produits par la fonction html->select_produit

This commit is contained in:
Laurent Destailleur 2005-04-27 00:29:32 +00:00
parent f274c5fa81
commit bb6209d3cb
3 changed files with 51 additions and 61 deletions

View File

@ -604,33 +604,6 @@ if ($_GET["action"] == 'create')
{
print '<tr><td colspan="3">&nbsp;</td></tr>';
print '<tr><td colspan="3">';
/*
*
* Liste des elements
*
*/
$sql = "SELECT p.rowid,p.label,p.ref,p.price FROM ".MAIN_DB_PREFIX."product as p ";
$sql .= " WHERE envente = 1";
$sql .= " ORDER BY p.nbvente DESC LIMIT ".$conf->liste_limit;
if ( $db->query($sql) )
{
$opt = "<option value=\"0\" selected></option>";
if ($result)
{
$num = $db->num_rows(); $i = 0;
while ($i < $num)
{
$objp = $db->fetch_object();
$opt .= "<option value=\"$objp->rowid\">[$objp->ref] $objp->label : $objp->price</option>\n";
$i++;
}
}
$db->free();
}
else
{
dolibarr_print_error($db);
}
print '<table class="noborder">';
print '<tr><td>Services/Produits prédéfinis</td><td>'.$langs->trans("Qty").'</td><td>'.$langs->trans("Discount").'</td><td> &nbsp; &nbsp; </td>';
@ -639,7 +612,9 @@ if ($_GET["action"] == 'create')
}
for ($i = 1 ; $i <= $NBLINES ; $i++)
{
print '<tr><td><select class="flat" name="idprod'.$i.'">'.$opt.'</select></td>';
print '<tr><td>';
$html->select_produits('',"idprod$i");
print '</td>';
print '<td><input type="text" size="3" name="qty'.$i.'" value="1"></td>';
print '<td><input type="text" size="4" name="remise_percent'.$i.'" value="0">%</td>';
print '<td>&nbsp;</td>';
@ -648,7 +623,7 @@ if ($_GET["action"] == 'create')
print '<td>';
print 'Du ';
print $html->select_date('',"date_start$i",0,0,1);
print ' au ';
print '<br>au ';
print $html->select_date('',"date_end$i",0,0,1);
print '</td>';
}
@ -1551,7 +1526,7 @@ else
else
{
/* Facture non trouvée */
print "Facture inexistante";
print "Facture ".$_GET["facid"]." inexistante";
}
}
else

View File

@ -619,33 +619,6 @@ else
*/
if ($user->rights->contrat->creer)
{
$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p ";
$sql.= " WHERE p.envente = 1";
$sql.= " ORDER BY p.nbvente DESC LIMIT 20";
if ( $db->query($sql) )
{
$opt = "<option value=\"0\" selected></option>";
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$objp = $db->fetch_object();
$opt .= "<option value=\"$objp->rowid\">[$objp->ref] $objp->label : $objp->price ".MAIN_MONNAIE;
if ($objp->duration) $opt .= " - ".$objp->duration;
print "</option>\n";
$i++;
}
$db->free();
}
else
{
dolibarr_print_error($db);
}
print '<form action="fiche.php?id='.$id.'" method="post">';
print '<input type="hidden" name="action" value="addligne">';
print '<input type="hidden" name="id" value="'.$id.'">';
@ -674,7 +647,9 @@ else
$var=!$var;
print "<tr $bc[$var]>";
print '<td>&nbsp;</td>';
print '<td colspan="2"><select name="p_idprod">'.$opt.'</select></td>';
print '<td colspan="2">';
$html->select_produits('','p_idprod');
print '</td>';
print '<td align="center"><input type="text" class="flat" size="2" name="pqty" value="1"></td>';
print '<td align="right"><input type="text" class="flat" size="2" name="premise" value="0">%</td>';
print '<td>&nbsp;</td>';

View File

@ -270,7 +270,6 @@ class Form
* \brief Retourne la liste déroulante des sociétés
* \param
*/
function select_societes($selected='',$htmlname='soc_id')
{
// On recherche les societes
@ -306,11 +305,11 @@ class Form
}
}
/**
* \brief Retourne la liste déroulante des contacts d'une société donnée
*
*/
function select_contacts($socid,$selected='',$htmlname='contactid')
{
// On recherche les societes
@ -350,11 +349,52 @@ class Form
}
/**
* \brief Retourne la liste des produits
* \param selected Produit présélectionné
* \param filtretype Pour filtre sur type de produit
*/
function select_produits($selected='',$htmlname='productid',$filtretype='',$limit=20)
{
$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p ";
$sql.= " WHERE p.envente = 1";
if ($filtretype && $filtretype != '') $sql.=" AND p.fk_product_type=".$filtretype;
$sql.= " ORDER BY p.nbvente DESC";
$sql.= " LIMIT $limit";
$result=$this->db->query($sql);
if ($result)
{
print '<select name="'.$htmlname.'">';
print "<option value=\"0\" selected>&nbsp;</option>";
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
$objp = $this->db->fetch_object($result);
$opt = "<option value=\"$objp->rowid\">[$objp->ref] $objp->label : $objp->price ".MAIN_MONNAIE;
if ($objp->duration) $opt .= " - ".$objp->duration;
$opt .= "</option>\n";
print $opt;
$i++;
}
print '</select>';
$this->db->free($result);
}
else
{
dolibarr_print_error($db);
}
}
/**
* \brief Retourne le nom d'un pays
* \param id id du pays
*/
function pays_name($id)
{
$sql = "SELECT rowid, libelle FROM ".MAIN_DB_PREFIX."c_pays";