Fix: Sending page when subproduct feature is enabled

This commit is contained in:
Laurent Destailleur 2009-04-05 19:01:43 +00:00
parent 5e4f9a3734
commit b104a84992
7 changed files with 136 additions and 80 deletions

View File

@ -98,11 +98,11 @@ if ($action == "save")
/** /*
* Affichage du formulaire de saisie * View
*/ */
llxHeader(); llxHeader('',$langs->trans("Audit"));
//$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>'; //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("SecuritySetup"),'','setup'); print_fiche_titre($langs->trans("SecuritySetup"),'','setup');

View File

@ -48,8 +48,11 @@ if ($_GET["action"] == 'remove')
} }
/*
* View
*/
llxHeader(); llxHeader('',$langs->trans("DefaultRights"));
print_fiche_titre($langs->trans("SecuritySetup"),'','setup'); print_fiche_titre($langs->trans("SecuritySetup"),'','setup');

View File

@ -157,7 +157,7 @@ else if ($_GET["action"] == 'disable_MAIN_SECURITY_DISABLEFORGETPASSLINK')
* Affichage onglet * Affichage onglet
*/ */
llxHeader(); llxHeader('',$langs->trans("Passwords"));
if ($mesg) print "$mesg\n"; if ($mesg) print "$mesg\n";

View File

@ -94,7 +94,7 @@ else if ($_GET["action"] == 'disable_avscan')
* Affichage onglet * Affichage onglet
*/ */
llxHeader(); llxHeader('',$langs->trans("Miscellanous"));
print_fiche_titre($langs->trans("SecuritySetup"),'','setup'); print_fiche_titre($langs->trans("SecuritySetup"),'','setup');

View File

@ -472,12 +472,18 @@ if ($id > 0 || ! empty($ref))
print '</td>'; print '</td>';
$reste_a_livrer[$objp->fk_product] = $objp->qty - $quantite_livree; $reste_a_livrer[$objp->fk_product] = $objp->qty - $quantite_livree;
$reste_a_livrer_total = $reste_a_livrer_total + $reste_a_livrer[$objp->fk_product]; $reste_a_livrer_total += $reste_a_livrer[$objp->fk_product];
print '<td align="center">'; print '<td align="center">';
print $reste_a_livrer[$objp->fk_product]; print $reste_a_livrer[$objp->fk_product];
print '</td>'; print '</td>';
if ($conf->stock->enabled) if ($objp->fk_product > 0)
{
$product = new Product($db);
$product->fetch($objp->fk_product);
}
if ($objp->fk_product > 0 && $conf->stock->enabled)
{ {
print '<td align="center">'; print '<td align="center">';
print $product->stock_reel; print $product->stock_reel;
@ -491,18 +497,25 @@ if ($id > 0 || ! empty($ref))
{ {
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
} }
print "</tr>"; print "</tr>\n";
// associations sous produits // Show subproducts details
if (! empty($conf->global->PRODUIT_SOUSPRODUITS) && $objp->fk_product > 0) if ($objp->fk_product > 0 && ! empty($conf->global->PRODUIT_SOUSPRODUITS))
{ {
$product->get_sousproduits_arbo (); // Set tree of subproducts in product->sousprods
$product->get_sousproduits_arbo();
//var_dump($product->sousprods);exit;
// Define a new tree with quantiies recalculated
$prods_arbo = $product->get_arbo_each_prod($qtyProdCom); $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
//var_dump($prods_arbo);
if(sizeof($prods_arbo) > 0) if(sizeof($prods_arbo) > 0)
{ {
foreach($prods_arbo as $key => $value) foreach($prods_arbo as $key => $value)
{ {
print '<tr><td colspan="4">';
print $value[0]; print $value[0];
print '</td></tr>'."\n";
} }
} }
} }
@ -619,7 +632,7 @@ if ($id > 0 || ! empty($ref))
} }
else else
{ {
/* Commande non trouv<EFBFBD>e */ /* Commande non trouvee */
print "Commande inexistante"; print "Commande inexistante";
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -22,6 +22,7 @@
* \brief Library for expedition module * \brief Library for expedition module
* \version $Id$ * \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
/** /**
@ -33,16 +34,22 @@
function show_list_sending_receive($origin='commande',$origin_id,$filter='') function show_list_sending_receive($origin='commande',$origin_id,$filter='')
{ {
global $db, $conf, $langs, $bc; global $db, $conf, $langs, $bc;
global $html;
$sql = "SELECT obj.rowid, obj.fk_product, obj.description, obj.qty as qty_asked"; $product_static=new Product($db);
$sql = "SELECT obj.rowid, obj.fk_product, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked";
$sql.= ", ed.qty as qty_shipped, ed.fk_expedition as expedition_id"; $sql.= ", ed.qty as qty_shipped, ed.fk_expedition as expedition_id";
$sql.= ", e.ref, ".$db->pdate("e.date_expedition")." as date_expedition"; $sql.= ", e.ref as exp_ref, ".$db->pdate("e.date_expedition")." as date_expedition,";
if ($conf->livraison_bon->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, ".$db->pdate("l.date_livraison")." as date_delivery, ld.qty as qty_received"; if ($conf->livraison_bon->enabled) $sql .= " l.rowid as livraison_id, l.ref as livraison_ref, ".$db->pdate("l.date_livraison")." as date_delivery, ld.qty as qty_received,";
$sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,';
$sql.= ' p.description as product_desc';
$sql.= " FROM (".MAIN_DB_PREFIX."expeditiondet as ed,"; $sql.= " FROM (".MAIN_DB_PREFIX."expeditiondet as ed,";
$sql.= " ".MAIN_DB_PREFIX.$origin."det as obj,"; $sql.= " ".MAIN_DB_PREFIX.$origin."det as obj,";
$sql.= " ".MAIN_DB_PREFIX."expedition as e)"; $sql.= " ".MAIN_DB_PREFIX."expedition as e)";
if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line"; if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line";
$sql.= " WHERE obj.fk_".$origin." = ".$origin_id; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
$sql.= " WHERE obj.fk_".$origin." = ".$origin_id;
if ($filter) $sql.=$filter; if ($filter) $sql.=$filter;
$sql.= " AND obj.rowid = ed.fk_origin_line"; $sql.= " AND obj.rowid = ed.fk_origin_line";
$sql.= " AND ed.fk_expedition = e.rowid"; $sql.= " AND ed.fk_expedition = e.rowid";
@ -84,26 +91,47 @@ function show_list_sending_receive($origin='commande',$origin_id,$filter='')
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
// Description
if ($objp->fk_product > 0) if ($objp->fk_product > 0)
{ {
$product = new Product($db);
$product->fetch($objp->fk_product);
print '<td>'; print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.dol_trunc($product->libelle,20);
if ($objp->description) print '<br>'.dol_htmlentitiesbr(dol_trunc($objp->description,24)); // Show product and description
$product_static->type=$objp->fk_product_type;
$product_static->id=$objp->fk_product;
$product_static->ref=$objp->ref;
$product_static->libelle=$objp->product;
$text=$product_static->getNomUrl(1);
$text.= ' - '.$objp->product;
$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description));
print $html->textwithtooltip($text,$description,3,'','',$i);
// Show range
print_date_range($objp->date_start,$objp->date_end);
// Add description in form
if ($conf->global->PRODUIT_DESC_IN_FORM)
{
print ($objp->description && $objp->description!=$objp->product)?'<br>'.dol_htmlentitiesbr($objp->description):'';
}
print '</td>'; print '</td>';
} }
else else
{ {
print "<td>".dol_htmlentitiesbr(dol_trunc($objp->description,24))."</td>\n"; print "<td>";
if ($type==1) $text = img_object($langs->trans('Service'),'service');
else $text = img_object($langs->trans('Product'),'product');
print $text.' '.nl2br($objp->description);
// Show range
print_date_range($objp->date_start,$objp->date_end);
print "</td>\n";
} }
//print '<td align="center">'.$objp->qty_asked.'</td>'; //print '<td align="center">'.$objp->qty_asked.'</td>';
// Sending id // Sending id
print '<td align="left" nowrap="nowrap"><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.'<a></td>'; print '<td align="left" nowrap="nowrap"><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->exp_ref.'<a></td>';
print '<td align="center">'.$objp->qty_shipped.'</td>'; print '<td align="center">'.$objp->qty_shipped.'</td>';

View File

@ -1826,22 +1826,22 @@ 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
* \return void * \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="") function fetch_prod_arbo($prod, $compl_path="", $multiply=1, $level=1)
{ {
global $langs; global $langs;
$this->res;
$this->pere_encours;
foreach($prod as $nom_pere => $desc_pere) foreach($prod as $nom_pere => $desc_pere)
{ {
// on est dans une sous-categorie if (is_array($desc_pere)) // If this parent desc is an array, this is an array of childs
if(is_array($desc_pere))
{ {
if($multiply) if($multiply)
{ {
//print "XXX ".$desc_pere[1]." multiply=".$multiply;
$img=""; $img="";
$trueValue=$desc_pere[1]*$multiply; $trueValue=$desc_pere[1]*$multiply;
$product = new Product($this->db); $product = new Product($this->db);
@ -1851,24 +1851,34 @@ class Product extends CommonObject
{ {
$img=img_warning($langs->trans("StockTooLow")); $img=img_warning($langs->trans("StockTooLow"));
} }
$this->res[]= array("<tr><td>&nbsp; &nbsp; &nbsp; $this->res[]= array(
"<tr><td>&nbsp; &nbsp; &nbsp; ->
<a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$desc_pere[0]."\">".$compl_path.stripslashes($nom_pere)." <a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$desc_pere[0]."\">".$compl_path.stripslashes($nom_pere)."
</a></td><td align=\"center\"> ".$trueValue."</td><td>&nbsp</td></td><td>&nbsp</td> </a> (".$desc_pere[1].")</td><td align=\"center\"> ".$trueValue."</td><td>&nbsp</td><td>&nbsp</td>
</td><td align=\"center\">".$this->stock_entrepot[1]." ".$img."</td></tr>", <td align=\"center\">".$this->stock_entrepot[1]." ".$img."</td></tr>",
$desc_pere[0]); $desc_pere[0],
'fullpath' => $compl_path.$nom_pere);
} }
else else
{ {
$this->res[]= array($compl_path.$nom_pere." (".$desc_pere[1].")",$desc_pere[0]); $this->res[]= array($compl_path.$nom_pere." (".$desc_pere[1].")",
$desc_pere[0],
'fullpath' => $compl_path.$nom_pere);
} }
} }
else if($nom_pere != "0" && $nom_pere != "1") else if($nom_pere != "0" && $nom_pere != "1")
$this->res[]= array($compl_path.$nom_pere,$desc_pere);
if(sizeof($desc_pere) >1)
{ {
$this ->fetch_prod_arbo($desc_pere,$nom_pere." -> "); $this->res[]= array($compl_path.$nom_pere,$desc_pere);
}
// Recursive call
if (is_array($desc_pere))
{
$this ->fetch_prod_arbo($desc_pere, $nom_pere." -> ", $desc_pere[1]*$multiply, $level+1);
} }
} }
//if ($level == 1) var_dump($this->res);
} }
/** /**
@ -1891,20 +1901,19 @@ class Product extends CommonObject
} }
/** /**
* \brief reconstruit l'arborescence des categorie sous la forme d'un tableau * \brief reconstruit l'arborescence des categorie sous la forme d'un tableau
* \return array $this->res * \return array $this->res
*/ */
function get_arbo_each_prod($multiply="") function get_arbo_each_prod($multiply=1)
{ {
$this->res = array(); $this->res = array();
if(is_array($this -> sousprods)) if (is_array($this -> sousprods))
{ {
foreach($this -> sousprods as $nom_pere => $desc_pere) foreach($this -> sousprods as $nom_pere => $desc_pere)
{ {
if(sizeof($desc_pere) >1) if (is_array($desc_pere)) $this->fetch_prod_arbo($desc_pere,"",$multiply);
$this ->fetch_prod_arbo($desc_pere,"",$multiply);
} }
sort($this->res); // dol_sort($this->res,);
} }
return $this->res; return $this->res;
} }
@ -1930,8 +1939,8 @@ class Product extends CommonObject
} }
/** /**
* \brief Retourne les cat<EFBFBD>gories p<EFBFBD>res * \brief Return all parent products
* \return array prod * \return array prod
*/ */
function get_pere() function get_pere()
{ {
@ -1940,15 +1949,16 @@ class Product extends CommonObject
$sql .= MAIN_DB_PREFIX."product_association as pa,"; $sql .= MAIN_DB_PREFIX."product_association as pa,";
$sql .= MAIN_DB_PREFIX."product as p"; $sql .= MAIN_DB_PREFIX."product as p";
$sql .= " where p.rowid=pa.fk_product_pere and p.rowid = '".$this->id."'"; $sql .= " where p.rowid=pa.fk_product_pere and p.rowid = '".$this->id."'";
$res = $this->db->query ($sql); $res = $this->db->query ($sql);
if ($res) if ($res)
{ {
$prods = array (); $prods = array ();
while ($record = $this->db->fetch_array ($res)) while ($record = $this->db->fetch_array ($res))
{ {
$prods[addslashes($record['label'])] = array(0=>$record['id']); $prods[addslashes($record['label'])] = array(0=>$record['id']);
} }
return $prods; return $prods;
} }
else else
{ {
@ -1958,26 +1968,26 @@ class Product extends CommonObject
} }
/** /**
* \brief Retourne les fils de la cat<EFBFBD>gorie structur<EFBFBD>s pour l'arbo * \brief Return childs
* \return array prod * \return array prod
*/ */
function get_fils_arbo ($id_pere) function get_fils_arbo ($id_pere)
{ {
$sql = "SELECT p.rowid, p.label as label,pa.qty as qty,pa.fk_product_fils as id FROM "; $sql = "SELECT p.rowid, p.label as label,pa.qty as qty,pa.fk_product_fils as id FROM ";
$sql .= MAIN_DB_PREFIX."product as p,".MAIN_DB_PREFIX."product_association as pa"; $sql .= MAIN_DB_PREFIX."product as p,".MAIN_DB_PREFIX."product_association as pa";
$sql .= " WHERE p.rowid = pa.fk_product_fils and pa.fk_product_pere = '".$id_pere."'"; $sql .= " WHERE p.rowid = pa.fk_product_fils and pa.fk_product_pere = '".$id_pere."'";
$res = $this->db->query ($sql);
$res = $this->db->query ($sql);
if ($res) if ($res)
{ {
$prods = array(); $prods = array();
while ($rec = $this->db->fetch_array ($res)) while ($rec = $this->db->fetch_array ($res))
{ {
$prods[addslashes($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']); $prods[addslashes($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']);
foreach($this -> get_fils_arbo($rec['id']) as $kf=>$vf) foreach($this -> get_fils_arbo($rec['id']) as $kf=>$vf)
$prods[addslashes($rec['label'])][$kf] = $vf; $prods[addslashes($rec['label'])][$kf] = $vf;
} }
return $prods; return $prods;
} }
else else
{ {
@ -1985,21 +1995,23 @@ class Product extends CommonObject
return -1; return -1;
} }
} }
/** /**
* \brief compose l'arborescence des sousproduits, id, nom et quantit<69> sous la forme d'un tableau associatif * \brief Return tree of all subproducts for product. Tree contains id, name and quantity.
* \return void * \remarks Set this->sousprods
* \return void
*/ */
function get_sousproduits_arbo () function get_sousproduits_arbo()
{ {
$peres = $this -> get_pere(); $peres = $this -> get_pere();
foreach($peres as $k=>$v) foreach($peres as $k=>$v)
{ {
foreach($this -> get_fils_arbo($v[0]) as $kf=>$vf) foreach($this -> get_fils_arbo($v[0]) as $kf=>$vf)
{ {
$peres[$k][$kf] = $vf; $peres[$k][$kf] = $vf;
} }
} }
// on concat<61>ne tout <20>a // concatenation
foreach($peres as $k=>$v) foreach($peres as $k=>$v)
{ {
$this -> sousprods[$k]=$v; $this -> sousprods[$k]=$v;