Fix: Fix awfull code for subproduct option

This commit is contained in:
Laurent Destailleur 2010-03-04 19:42:01 +00:00
parent b7201c5c5d
commit 87dccc1e76
7 changed files with 172 additions and 75 deletions

View File

@ -541,7 +541,16 @@ if ($_GET["action"] == 'create')
{
foreach($prods_arbo as $key => $value)
{
print $value[0];
//print $value[0];
$img='';
if ($value['stock'] < $value['stock_alert'])
{
$img=img_warning($langs->trans("StockTooLow"));
}
print "<tr><td>&nbsp; &nbsp; &nbsp; ->
<a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$value['id']."\">".$value['fullpath']."
</a> (".$value['nb'].")</td><td align=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>
<td align=\"center\">".$value['stock']." ".$img."</td></tr>";
}
}
}

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -26,6 +26,7 @@
*/
require("../main.inc.php");
require(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
$langs->load("orders");
$langs->load("sendings");
@ -34,6 +35,9 @@ $langs->load("sendings");
* View
*/
$orderstatic=new Commande($db);
$companystatic=new Societe($db);
$helpurl='EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
llxHeader('',$langs->trans("Sendings"),$helpurl);
@ -126,13 +130,18 @@ if ( $db->query($sql) )
$var = True;
while ($i < $num)
{
$var=!$var;
$obj = $db->fetch_object();
print "<tr $bc[$var]>";
print '<td nowrap="nowrap">';
print "<a href=\"commande.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.dol_trunc($obj->nom,20).'</a></td></tr>';
$i++;
$var=!$var;
$obj = $db->fetch_object();
print "<tr $bc[$var]>";
print '<td nowrap="nowrap">';
$orderstatic->id=$obj->rowid;
$orderstatic->ref=$obj->ref;
print $orderstatic->getNomUrl(1);
print '</td>';
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.dol_trunc($obj->nom,20).'</a>';
print '</td></tr>';
$i++;
}
print "</table><br>";
}
@ -173,12 +182,15 @@ if ( $resql )
$var = True;
while ($i < $num)
{
$var=!$var;
$obj = $db->fetch_object($resql);
print "<tr $bc[$var]><td width=\"30%\"><a href=\"commande.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' ';
print $obj->ref.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.$obj->nom.'</a></td></tr>';
$i++;
$var=!$var;
$obj = $db->fetch_object($resql);
print "<tr $bc[$var]><td width=\"30%\">";
$orderstatic->id=$obj->rowid;
$orderstatic->ref=$obj->ref;
print $orderstatic->getNomUrl(1);
print '</td>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.$obj->nom.'</a></td></tr>';
$i++;
}
print "</table><br>";
}
@ -230,9 +242,11 @@ if ($resql)
print '<td>';
if ($obj->commande_id)
{
print '<a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$obj->commande_id.'">';
print img_object($langs->trans("ShowOrder"),"order").' '.$obj->commande_ref.'</a>';
} else print '&nbsp;';
$orderstatic->id=$obj->commande_id;
$orderstatic->ref=$obj->commande_ref;
print $orderstatic->getNomUrl(1);
}
else print '&nbsp;';
print '</td></tr>';
$i++;
}

View File

@ -528,7 +528,18 @@ if ($id > 0 || ! empty($ref))
foreach($prods_arbo as $key => $value)
{
print '<tr><td colspan="4">';
$img='';
if ($value['stock'] < $value['stock_alert'])
{
$img=img_warning($langs->trans("StockTooLow"));
}
print "<tr><td>&nbsp; &nbsp; &nbsp; ->
<a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$value['id']."\">".$value['fullpath']."
</a> (".$value['nb'].")</td><td align=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>
<td align=\"center\">".$value['stock']." ".$img."</td></tr>";
print $value[0];
print '</td></tr>'."\n";
}
}

View File

@ -106,9 +106,9 @@ ServiceLimitedDuration=If product is a service with limited duration:
MultiPricesAbility=Activate the multi-prices
MultiPricesNumPrices=Number of price
MultiPriceLevelsName=Price categories
AssociatedProductsAbility=Activate the associated products
AssociatedProducts=Associated products
AssociatedProductsNumber=Number of associated products
AssociatedProductsAbility=Activate the sub-products
AssociatedProducts=Sub-products
AssociatedProductsNumber=Number of products composing this product
EditAssociate=Associate
Translation=Translation
KeywordFilter=Keyword filter

View File

@ -106,10 +106,10 @@ ServiceLimitedDuration=Si produit de type service à durée limitée :
MultiPricesAbility=Prise en charges de prix multiples
MultiPricesNumPrices=Nombre de prix
MultiPriceLevelsName=Catégorie de prix
AssociatedProductsAbility=Prise en charges des produits associés
AssociatedProducts=Produits associés
AssociatedProductsNumber=Nbre de produits associés
EditAssociate=Associer
AssociatedProductsAbility=Prise en charges des produits composés
AssociatedProducts=Composition
AssociatedProductsNumber=Nbre de sous-produits composant ce produit
EditAssociate=Composer
Translation=Traduction
KeywordFilter=Filtre par mot-clé
CategoryFilter=Filtre par catégorie
@ -117,7 +117,7 @@ ProductToAddSearch=Recherche des produits à ajouter
AddDel=Ajouter/Retirer
Quantity=Quantité
NoMatchFound=Aucun résultat n'a été trouvé
ProductAssociationList=Liste des produits/services associés : nom du produit/service (quantité affectée)
ProductAssociationList=Liste des produits/services composant ce produit: Le nombre entre paraenthèse est la quantité affectée dans cette composition.
ErrorAssociationIsFatherOfThis=L'un des produits sélectionnés est parent du produit en cours
DeleteProduct=Supprimer un produit/service
ConfirmDeleteProduct=Etes-vous sûr de vouloir supprimer ce produit/service ?

View File

@ -1478,7 +1478,7 @@ class Product extends CommonObject
* \brief Lie un produit associe au produit/service
* \param id_pere Id du produit auquel sera lie le produit a lier
* \param id_fils Id du produit a lier
* \return int < 0 si erreur, > 0 si ok
* \return int < 0 if KO, > 0 if OK
*/
function add_sousproduit($id_pere, $id_fils,$qty)
{
@ -1839,15 +1839,16 @@ class Product extends CommonObject
}
/**
* \brief fonction recursive uniquement utilisee par get_arbo_each_prod, recompose l'arborescence des sousproduits
* \brief Fonction recursive uniquement utilisee par get_arbo_each_prod, recompose l'arborescence des sousproduits
* \remarks Define value of this->res
* \param multiply Because each sublevel must be multiplicated by parent nb
* \return void
*/
function fetch_prod_arbo($prod, $compl_path="", $multiply=1, $level=1)
{
global $langs;
global $conf,$langs;
$product = new Product($this->db);
foreach($prod as $nom_pere => $desc_pere)
{
if (is_array($desc_pere)) // If this parent desc is an array, this is an array of childs
@ -1856,8 +1857,6 @@ class Product extends CommonObject
{
//print "XXX ".$desc_pere[1]." multiply=".$multiply;
$img="";
$trueValue=$desc_pere[1]*$multiply;
$product = new Product($this->db);
$this->fetch($desc_pere[0]);
$this->load_stock();
if ($this->stock_entrepot[1] < $this->seuil_stock_alerte)
@ -1865,18 +1864,35 @@ class Product extends CommonObject
$img=img_warning($langs->trans("StockTooLow"));
}
$this->res[]= array(
"<tr><td>&nbsp; &nbsp; &nbsp; ->
/* "<tr><td>&nbsp; &nbsp; &nbsp; ->
<a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$desc_pere[0]."\">".$compl_path.stripslashes($nom_pere)."
</a> (".$desc_pere[1].")</td><td align=\"center\"> ".$trueValue."</td><td>&nbsp</td><td>&nbsp</td>
</a> (".$desc_pere[1].")</td><td align=\"center\"> ".($desc_pere[1]*$multiply)."</td><td>&nbsp</td><td>&nbsp</td>
<td align=\"center\">".$this->stock_entrepot[1]." ".$img."</td></tr>",
$desc_pere[0],
'fullpath' => $compl_path.$nom_pere);
$desc_pere[0], // Id product
*/ 'id'=>$desc_pere[0], // Id product
'nb'=>$desc_pere[1], // Nb of units that compose parent product
'nb_total'=>$desc_pere[1]*$multiply, // Nb of units for all nb of product
'stock'=>$this->stock_entrepot[1], // Stock
'stock_alert'=>$this->seuil_stock_alerte, // Stock alert
'fullpath' => $compl_path.$nom_pere, // Label
'type'=>$desc_pere[2] // Nb of units that compose parent product
);
}
else
{
$this->res[]= array($compl_path.$nom_pere." (".$desc_pere[1].")",
$desc_pere[0],
'fullpath' => $compl_path.$nom_pere);
$this->fetch($desc_pere[0]);
$this->load_stock();
$this->res[]= array(
/* $compl_path.$nom_pere." (".$desc_pere[1].")",
$desc_pere[0], // Id product
*/ 'id'=>$desc_pere[0], // Id product
'nb'=>$desc_pere[1], // Nb of units that compose parent product
'nb_total'=>$desc_pere[1], // Nb of units for all nb of product
'stock'=>$this->stock_entrepot[1], // Stock
'stock_alert'=>$this->seuil_stock_alerte, // Stock alert
'fullpath' => $compl_path.$nom_pere, // Label
'type'=>$desc_pere[2] // Nb of units that compose parent product
);
}
}
else if($nom_pere != "0" && $nom_pere != "1")
@ -1952,15 +1968,15 @@ class Product extends CommonObject
}
/**
* \brief Return all parent products
* \brief Return all parent products fo current product
* \return array prod
*/
function getParent()
{
$sql = "SELECT p.label as label,p.rowid,pa.fk_product_pere as id";
$sql.= " FROM ".MAIN_DB_PREFIX."product_association as pa";
$sql.= ", ".MAIN_DB_PREFIX."product as p";
$sql = "SELECT p.label as label,p.rowid,pa.fk_product_pere as id,p.fk_product_type";
$sql.= " FROM ".MAIN_DB_PREFIX."product_association as pa,";
$sql.= " ".MAIN_DB_PREFIX."product as p";
$sql.= " WHERE p.rowid = pa.fk_product_pere";
$sql.= " AND p.rowid = ".$this->id;
@ -1982,12 +1998,13 @@ class Product extends CommonObject
}
/**
* \brief Return childs
* \return array prod
* \brief Return childs of prodcut with if fk_parent
* \param fk_parent Id of product to search childs of
* \return array Prod
*/
function getChildsArbo($fk_parent)
{
$sql = "SELECT p.rowid, p.label as label, pa.qty as qty, pa.fk_product_fils as id";
$sql = "SELECT p.rowid, p.label as label, pa.qty as qty, pa.fk_product_fils as id, p.fk_product_type";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= ", ".MAIN_DB_PREFIX."product_association as pa";
$sql.= " WHERE p.rowid = pa.fk_product_fils";
@ -1999,10 +2016,15 @@ class Product extends CommonObject
$prods = array();
while ($rec = $this->db->fetch_array($res))
{
//$prods[addslashes($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty'],2=>$rec['fk_product_type']);
$prods[addslashes($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']);
foreach($this->getChildsArbo($rec['id']) as $keyChild => $valueChild)
$prods[addslashes($rec['label'])][$keyChild] = $valueChild;
$listofchilds=$this->getChildsArbo($rec['id']);
foreach($listofchilds as $keyChild => $valueChild)
{
$prods[addslashes($rec['label'])][$keyChild] = $valueChild;
}
}
//var_dump($prods);
return $prods;
}
else
@ -2027,6 +2049,7 @@ class Product extends CommonObject
$parent[$key][$keyChild] = $valueChild;
}
}
//var_dump($parent);
// concatenation
foreach($parent as $key => $value)
{

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
@ -67,7 +67,7 @@ if ($action == 'add_prod' &&
$cancel <> $langs->trans("Cancel") &&
($user->rights->produit->creer || $user->rights->service->creer))
{
$error=0;
for($i=0;$i<$_POST["max_prod"];$i++)
{
// print "<br> : ".$_POST["prod_id_chk".$i];
@ -79,26 +79,33 @@ $cancel <> $langs->trans("Cancel") &&
}
else
{
$error++;
$action = 're-edit';
if($product->error == "isFatherOfThis")
$mesg = $langs->trans("ErrorAssociationIsFatherOfThis");
if ($product->error == "isFatherOfThis") $mesg = $langs->trans("ErrorAssociationIsFatherOfThis");
else $mesg=$product->error;
}
}
else
{
if($product->del_sousproduit($id, $_POST["prod_id_".$i]))
if ($product->del_sousproduit($id, $_POST["prod_id_".$i]) > 0)
{
$action = 'edit';
}
else
{
$error++;
$action = 're-edit';
$mesg=$product->error;
}
}
}
if (! $error)
{
header("Location: ".$_SERVER["PHP_SELF"].'?id='.$product->id);
exit;
}
}
// action recherche des produits par mot-cle et/ou par categorie
if($action == 'search' )
{
@ -180,27 +187,32 @@ if ($id || $ref)
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
print '</tr>';
// Number of subproducts
$product->get_sousproduits_arbo ();
print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>'.sizeof($product->get_arbo_each_prod()).'</td>';
// associations sousproduits
// List of subproducts
$prods_arbo = $product->get_arbo_each_prod();
if(sizeof($prods_arbo) > 0)
{
print '<tr><td colspan="2">';
print '<b>'.$langs->trans("ProductAssociationList").'</b><br>';
foreach($prods_arbo as $key => $value)
print '<table class="nobordernopadding">';
foreach($prods_arbo as $value)
{
$productstatic->id=$value[1];
$productstatic->type=0;
//$productstatic->ref=$value[0];
$productstatic->id=$value['id'];
$productstatic->type=$value['type'];
$productstatic->ref=$value['fullpath'];
//var_dump($value);
//print '<pre>'.$productstatic->ref.'</pre>';
//print $productstatic->getNomUrl(1).'<br>';
print $value[0]; // This contains a tr line.
//print $value[0]; // This contains a tr line.
print '<tr>';
print '<td>'.$productstatic->getNomUrl(1).' ('.$value['nb'].')</td>';
print '<td></td>';
print '</tr>';
}
print '</table>';
print '</td></tr>';
}
@ -225,27 +237,45 @@ if ($id || $ref)
// Reference
print '<td width="25%">'.$langs->trans("Ref").'</td><td>';
print $html->showrefnav($product,'ref','',1,'ref');
print '</td></tr>';
if ($product->is_photo_available($conf->produit->dir_output))
{
// Photo
print '<td valign="middle" align="center" rowspan="'.$nblignes.'">';
$nbphoto=$product->show_photos($conf->produit->dir_output,1,1,0);
print '</td>';
}
print '</tr>';
// Libelle
// Label
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
print '</tr>';
// Nombre de sousproduits associes
// Number of subproducts
$product->get_sousproduits_arbo ();
print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>'.sizeof($product->get_arbo_each_prod()).'</td>';
print '</tr>';
// List of subproducts
$prods_arbo = $product->get_arbo_each_prod();
//var_dump($prods_arbo);
if(sizeof($prods_arbo) > 0)
{
print '<tr><td colspan="2">';
print '<b>'.$langs->trans("ProductAssociationList").'</b><br>';
print '<table class="nobordernopadding">';
foreach($prods_arbo as $value)
{
$productstatic->id=$value['id'];
$productstatic->type=$value['type'];
$productstatic->ref=$value['fullpath'];
//var_dump($value);
//print '<pre>'.$productstatic->ref.'</pre>';
//print $productstatic->getNomUrl(1).'<br>';
//print $value[0]; // This contains a tr line.
print '<tr>';
print '<td>'.$productstatic->getNomUrl(1).' ('.$value['nb'].')</td>';
print '<td></td>';
print '</tr>';
}
print '</table>';
print '</td></tr>';
}
print '</table>';
print '<br>';
@ -253,6 +283,7 @@ if ($id || $ref)
print '<form action="'.DOL_URL_ROOT.'/product/sousproduits/fiche.php?id='.$id.'" method="post">';
print '<table class="nobordernopadding">';
print '<tr><td><b>'.$langs->trans("ProductToAddSearch").'</b></td></tr>';
print '<tr><td>';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print $langs->trans("KeywordFilter");
@ -299,14 +330,16 @@ if ($id || $ref)
if($objp->rowid != $id)
{
// check if a product is not already a parent product of this one
$prod_arbo=new Product($db,$objp->rowid);
$prod_arbo=new Product($db);
$prod_arbo->id=$objp->rowid;
if ($prod_arbo->type==2 || $prod_arbo->type==3)
{
$is_pere=0;
$prod_arbo->get_sousproduits_arbo ();
// associations sousproduits
$prods_arbo = $prod_arbo->get_arbo_each_prod();
if(sizeof($prods_arbo) > 0) {
if (sizeof($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value)
{
if ($value[1]==$id)
@ -354,8 +387,15 @@ if ($id || $ref)
dol_print_error($db);
}
print '<input type="hidden" name="max_prod" value="'.$i.'">';
if($num > 0) print '<tr><td colspan="4" align="center"><br><input type="submit" class="button" value="'.$langs->trans("Add").'/'.$langs->trans("Update").'"></td></tr>';
print '</table>';
if($num > 0)
{
print '<br><center><input type="submit" class="button" value="'.$langs->trans("Add").'/'.$langs->trans("Update").'">';
print ' &nbsp; &nbsp; <input type="submit" class="button" value="'.$langs->trans("Cancel").'">';
print '</center>';
}
print '</form>';
}