From b104a849928d209f3be20975ccdc76b5f14d1023 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 5 Apr 2009 19:01:43 +0000 Subject: [PATCH] Fix: Sending page when subproduct feature is enabled --- htdocs/admin/events.php | 12 ++--- htdocs/admin/perms.php | 7 ++- htdocs/admin/security.php | 6 +-- htdocs/admin/security_other.php | 2 +- htdocs/expedition/commande.php | 27 +++++++--- htdocs/lib/sendings.lib.php | 66 ++++++++++++++++------- htdocs/product.class.php | 96 ++++++++++++++++++--------------- 7 files changed, 136 insertions(+), 80 deletions(-) diff --git a/htdocs/admin/events.php b/htdocs/admin/events.php index f5c824fce43..247268177b8 100644 --- a/htdocs/admin/events.php +++ b/htdocs/admin/events.php @@ -71,7 +71,7 @@ $eventstolog=array( array('id'=>'MEMBER_MODIFY', 'test'=>$conf->adherent->enabled), array('id'=>'MEMBER_RESILIATE', 'test'=>$conf->adherent->enabled), array('id'=>'MEMBER_DELETE', 'test'=>$conf->adherent->enabled), -*/ +*/ ); @@ -83,7 +83,7 @@ if ($action == "save") $i=0; $db->begin(); - + foreach ($eventstolog as $key => $arr) { $param='MAIN_LOGEVENTS_'.$arr['id']; @@ -91,18 +91,18 @@ if ($action == "save") if (! empty($_POST[$param])) dolibarr_set_const($db,$param,$_POST[$param],'chaine',0); else dolibarr_del_const($db,$param); } - + $db->commit(); $mesg = "".$langs->trans("SetupSaved").""; } -/** - * Affichage du formulaire de saisie +/* + * View */ -llxHeader(); +llxHeader('',$langs->trans("Audit")); //$linkback=''.$langs->trans("BackToModuleList").''; print_fiche_titre($langs->trans("SecuritySetup"),'','setup'); diff --git a/htdocs/admin/perms.php b/htdocs/admin/perms.php index 37728e7ad90..33190eeaa1f 100644 --- a/htdocs/admin/perms.php +++ b/htdocs/admin/perms.php @@ -48,8 +48,11 @@ if ($_GET["action"] == 'remove') } +/* + * View + */ -llxHeader(); +llxHeader('',$langs->trans("DefaultRights")); print_fiche_titre($langs->trans("SecuritySetup"),'','setup'); @@ -126,7 +129,7 @@ if ($result) foreach($objMod->rights as $key => $val) { } - + // Break found, it's a new module to catch if ($old <> $obj->module) { diff --git a/htdocs/admin/security.php b/htdocs/admin/security.php index 0577f287433..60eabffa57f 100644 --- a/htdocs/admin/security.php +++ b/htdocs/admin/security.php @@ -59,7 +59,7 @@ if ($_GET["action"] == 'setgeneraterule') if ($_GET["action"] == 'activate_encrypt') { $db->begin(); - + dolibarr_set_const($db, "DATABASE_PWD_ENCRYPTED", "1"); $sql = "UPDATE ".MAIN_DB_PREFIX."user as u"; @@ -157,7 +157,7 @@ else if ($_GET["action"] == 'disable_MAIN_SECURITY_DISABLEFORGETPASSLINK') * Affichage onglet */ -llxHeader(); +llxHeader('',$langs->trans("Passwords")); if ($mesg) print "$mesg\n"; @@ -332,7 +332,7 @@ print ''; print ''; // TODO Impossibilité de crypter le mot de passe lorsqu'il y a en a un, il affiche qu'il n'y en a pas !! -if (empty($dolibarr_main_db_pass) && empty($dolibarr_main_db_encrypted_pass)) +if (empty($dolibarr_main_db_pass) && empty($dolibarr_main_db_encrypted_pass)) { $langs->load("errors"); print img_warning($langs->trans("WarningPassIsEmpty")); diff --git a/htdocs/admin/security_other.php b/htdocs/admin/security_other.php index 8f8597c27b7..d49b16068c8 100644 --- a/htdocs/admin/security_other.php +++ b/htdocs/admin/security_other.php @@ -94,7 +94,7 @@ else if ($_GET["action"] == 'disable_avscan') * Affichage onglet */ -llxHeader(); +llxHeader('',$langs->trans("Miscellanous")); print_fiche_titre($langs->trans("SecuritySetup"),'','setup'); diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php index 47fd667f1fc..55a81a48297 100644 --- a/htdocs/expedition/commande.php +++ b/htdocs/expedition/commande.php @@ -472,12 +472,18 @@ if ($id > 0 || ! empty($ref)) print ''; $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 ''; print $reste_a_livrer[$objp->fk_product]; print ''; - 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 ''; print $product->stock_reel; @@ -491,18 +497,25 @@ if ($id > 0 || ! empty($ref)) { print ' '; } - print ""; + print "\n"; - // associations sous produits - if (! empty($conf->global->PRODUIT_SOUSPRODUITS) && $objp->fk_product > 0) + // Show subproducts details + 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); + //var_dump($prods_arbo); if(sizeof($prods_arbo) > 0) { foreach($prods_arbo as $key => $value) { + print ''; print $value[0]; + print ''."\n"; } } } @@ -619,7 +632,7 @@ if ($id > 0 || ! empty($ref)) } else { - /* Commande non trouv�e */ + /* Commande non trouvee */ print "Commande inexistante"; } } diff --git a/htdocs/lib/sendings.lib.php b/htdocs/lib/sendings.lib.php index 8e1060fdd3e..925157d07a4 100644 --- a/htdocs/lib/sendings.lib.php +++ b/htdocs/lib/sendings.lib.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2008-2009 Laurent Destailleur * * 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 @@ -22,6 +22,7 @@ * \brief Library for expedition module * \version $Id$ */ +require_once(DOL_DOCUMENT_ROOT."/product.class.php"); /** @@ -33,16 +34,22 @@ function show_list_sending_receive($origin='commande',$origin_id,$filter='') { global $db, $conf, $langs, $bc; - - $sql = "SELECT obj.rowid, obj.fk_product, obj.description, obj.qty as qty_asked"; + global $html; + + $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.= ", e.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"; + $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,"; + $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.= " ".MAIN_DB_PREFIX.$origin."det as obj,"; $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"; - $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; $sql.= " AND obj.rowid = ed.fk_origin_line"; $sql.= " AND ed.fk_expedition = e.rowid"; @@ -60,8 +67,8 @@ function show_list_sending_receive($origin='commande',$origin_id,$filter='') if ($somethingshown) print '
'; if ($filter) print_titre($langs->trans("OtherSendingsForSameOrder")); - else print_titre($langs->trans("SendingsAndReceivingForSameOrder")); - + else print_titre($langs->trans("SendingsAndReceivingForSameOrder")); + print ''; print ''; print ''; @@ -83,30 +90,51 @@ function show_list_sending_receive($origin='commande',$origin_id,$filter='') $var=!$var; $objp = $db->fetch_object($resql); print ""; - - // Description + if ($objp->fk_product > 0) { - $product = new Product($db); - $product->fetch($objp->fk_product); - print ''; } else { - print "\n"; + print "\n"; } //print ''; - + // Sending id - print ''; + print ''; print ''; - + print ''; if ($conf->livraison_bon->enabled) { diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 4ebe60bb87a..6900f6fc8bc 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -1826,22 +1826,22 @@ class Product extends CommonObject } /** - * \brief fonction recursive uniquement utilisee par get_arbo_each_prod, recompose l'arborescence des sousproduits - * \return void + * \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="") + function fetch_prod_arbo($prod, $compl_path="", $multiply=1, $level=1) { global $langs; - $this->res; - $this->pere_encours; foreach($prod as $nom_pere => $desc_pere) { - // on est dans une sous-categorie - if(is_array($desc_pere)) + if (is_array($desc_pere)) // If this parent desc is an array, this is an array of childs { if($multiply) { + //print "XXX ".$desc_pere[1]." multiply=".$multiply; $img=""; $trueValue=$desc_pere[1]*$multiply; $product = new Product($this->db); @@ -1851,24 +1851,34 @@ class Product extends CommonObject { $img=img_warning($langs->trans("StockTooLow")); } - $this->res[]= array(" - ", - $desc_pere[0]); + (".$desc_pere[1].") + ", + $desc_pere[0], + 'fullpath' => $compl_path.$nom_pere); } 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") - $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 - * \return array $this->res + * \brief reconstruit l'arborescence des categorie sous la forme d'un tableau + * \return array $this->res */ - function get_arbo_each_prod($multiply="") + function get_arbo_each_prod($multiply=1) { $this->res = array(); - if(is_array($this -> sousprods)) + if (is_array($this -> sousprods)) { foreach($this -> sousprods as $nom_pere => $desc_pere) { - if(sizeof($desc_pere) >1) - $this ->fetch_prod_arbo($desc_pere,"",$multiply); + if (is_array($desc_pere)) $this->fetch_prod_arbo($desc_pere,"",$multiply); } - sort($this->res); +// dol_sort($this->res,); } return $this->res; } @@ -1930,8 +1939,8 @@ class Product extends CommonObject } /** - * \brief Retourne les cat�gories p�res - * \return array prod + * \brief Return all parent products + * \return array prod */ function get_pere() { @@ -1940,15 +1949,16 @@ class Product extends CommonObject $sql .= MAIN_DB_PREFIX."product_association as pa,"; $sql .= MAIN_DB_PREFIX."product as p"; $sql .= " where p.rowid=pa.fk_product_pere and p.rowid = '".$this->id."'"; + $res = $this->db->query ($sql); if ($res) { $prods = array (); while ($record = $this->db->fetch_array ($res)) - { - $prods[addslashes($record['label'])] = array(0=>$record['id']); - } - return $prods; + { + $prods[addslashes($record['label'])] = array(0=>$record['id']); + } + return $prods; } else { @@ -1958,26 +1968,26 @@ class Product extends CommonObject } /** - * \brief Retourne les fils de la cat�gorie structur�s pour l'arbo - * \return array prod + * \brief Return childs + * \return array prod */ 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 .= 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."'"; - $res = $this->db->query ($sql); + $res = $this->db->query ($sql); if ($res) { $prods = array(); while ($rec = $this->db->fetch_array ($res)) - { - $prods[addslashes($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']); - foreach($this -> get_fils_arbo($rec['id']) as $kf=>$vf) - $prods[addslashes($rec['label'])][$kf] = $vf; - } - return $prods; + { + $prods[addslashes($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']); + foreach($this -> get_fils_arbo($rec['id']) as $kf=>$vf) + $prods[addslashes($rec['label'])][$kf] = $vf; + } + return $prods; } else { @@ -1985,21 +1995,23 @@ class Product extends CommonObject return -1; } } + /** - * \brief compose l'arborescence des sousproduits, id, nom et quantit� sous la forme d'un tableau associatif - * \return void + * \brief Return tree of all subproducts for product. Tree contains id, name and quantity. + * \remarks Set this->sousprods + * \return void */ - function get_sousproduits_arbo () + function get_sousproduits_arbo() { $peres = $this -> get_pere(); foreach($peres as $k=>$v) { foreach($this -> get_fils_arbo($v[0]) as $kf=>$vf) { - $peres[$k][$kf] = $vf; + $peres[$k][$kf] = $vf; } } - // on concat�ne tout �a + // concatenation foreach($peres as $k=>$v) { $this -> sousprods[$k]=$v;
'.$langs->trans("Description").'
'; - print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.dol_trunc($product->libelle,20); - if ($objp->description) print '
'.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)?'
'.dol_htmlentitiesbr($objp->description):''; + } + print '
".dol_htmlentitiesbr(dol_trunc($objp->description,24)).""; + 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 "'.$objp->qty_asked.''.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.''.img_object($langs->trans("ShowSending"),'sending').' '.$objp->exp_ref.''.$objp->qty_shipped.''.dol_print_date($objp->date_expedition,'dayhour').'
      + $this->res[]= array( + "
      -> ".$compl_path.stripslashes($nom_pere)." - ".$trueValue."  ".$this->stock_entrepot[1]." ".$img."
".$trueValue."  ".$this->stock_entrepot[1]." ".$img."