From ac969457a36efafecc956fa900ae6742a82eda6b Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 15 May 2007 22:47:58 +0000 Subject: [PATCH] Add: ajout du poids et du volume dans la fiche expedition Fix: fonctionnement de fetch_lines avec fetch dans expedition.class.php --- htdocs/expedition/expedition.class.php | 108 +++++++-------- htdocs/expedition/fiche.php | 182 ++++++++++++------------- 2 files changed, 138 insertions(+), 152 deletions(-) diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index 19b703e8e52..f91adc5937a 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -205,6 +205,8 @@ class Expedition extends CommonObject if ($result) { + if ($this->db->num_rows($result)) + { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; @@ -219,66 +221,39 @@ class Expedition extends CommonObject $this->date = $obj->date_expedition; $this->entrepot_id = $obj->fk_entrepot; $this->adresse_livraison_id = $obj->fk_adresse_livraison; - $this->modelpdf = $obj->model_pdf; + $this->modelpdf = $obj->model_pdf; $this->db->free($result); if ($this->statut == 0) $this->brouillon = 1; - $this->lignes = array(); - // TODO Supprimer cette partie. L'appelant qui fetch doit - // en fait appeler fetch_lignes pour charges ceci. - $sql = "SELECT c.description, c.qty as qtycom, c.fk_product, p.label, "; - $sql.= " e.qty as qtyexp, e.fk_commande_ligne,"; - $sql.= " p.ref"; - $sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as e"; - $sql.= " , ".MAIN_DB_PREFIX."commandedet as c"; - $sql.= " , ".MAIN_DB_PREFIX."product as p"; - $sql.= " WHERE e.fk_expedition = ".$this->id; - $sql.= " AND e.fk_commande_ligne = c.rowid"; - $sql.= " AND c.fk_product = p.rowid"; - - $resultp = $this->db->query($sql); - - if ($resultp) - { - $num = $this->db->num_rows($resultp); - $i = 0; - - while ($i < $num) - { - $objp = $this->db->fetch_object($resultp); - - $ligne = new ExpeditionLigne($this->db); - - $ligne->commande_ligne_id = $objp->fk_commande_ligne; - $ligne->product_desc = $objp->description; // Description ligne - $ligne->qty_expedition = $objp->qtyexp; - $ligne->qty_commande = $objp->qtycom; - $ligne->fk_product = $objp->fk_product; - - $ligne->libelle = $objp->label; // Label produit - $ligne->ref = $objp->ref; - - $this->lignes[$i] = $ligne; - $i++; - } - $this->db->free($resultp); - } - else - { - dolibarr_syslog("Propal::Fetch Erreur lecture des produits"); - return -1; - } + $this->lignes = array(); $file = $conf->expedition->dir_output . "/" .get_exdir($expedition->id,2) . "/" . $this->id.".pdf"; $this->pdf_filename = $file; + + /* + * Lignes + */ + $result=$this->fetch_lines(); + if ($result < 0) + { + return -3; + } return 1; + } + else + { + dolibarr_syslog('Expedition::Fetch Error rowid='.$rowid.' numrows=0 sql='.$sql); + $this->error='Delivery with id '.$rowid.' not found sql='.$sql; + return -2; + } } else { - $this->error=$this->db->error(); - return -2; + dolibarr_syslog('Facture::Fetch Error rowid='.$rowid.' Erreur dans fetch de la facture'); + $this->error=$this->db->error(); + return -1; } } @@ -591,17 +566,16 @@ class Expedition extends CommonObject } - function fetch_lignes() + function fetch_lines() { - $this->lignes = array(); - - $sql = "SELECT c.description, c.qty as qtycom, e.qty as qtyexp"; - $sql .= ", c.fk_product"; - $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as e"; - $sql .= " , ".MAIN_DB_PREFIX."commandedet as c"; - - $sql .= " WHERE e.fk_expedition = ".$this->id; - $sql .= " AND e.fk_commande_ligne = c.rowid"; + $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.qty as qty_commande"; + $sql.= ", ed.qty as qty_expedie, ed.fk_commande_ligne"; + $sql.= ", p.ref, p.label, p.weight, p.weight_units, p.volume, p.volume_units"; + $sql.= " FROM (".MAIN_DB_PREFIX."commandedet as cd"; + $sql.= ", ".MAIN_DB_PREFIX."expeditiondet as ed)"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON (p.rowid = cd.fk_product)"; + $sql.= " WHERE ed.fk_expedition = ".$this->id; + $sql.= " AND ed.fk_commande_ligne = cd.rowid"; $resql = $this->db->query($sql); @@ -615,16 +589,28 @@ class Expedition extends CommonObject $obj = $this->db->fetch_object($resql); $ligne->fk_product = $obj->fk_product; - $ligne->qty_commande = $obj->qtycom; - $ligne->qty_expedition = $obj->qtyexp; + $ligne->ref = $obj->ref; + $ligne->libelle = $obj->label; $ligne->description = $obj->description; + $ligne->qty_commande = $obj->qty_commande; + $ligne->qty_expedie = $obj->qty_expedie; + $ligne->weight = $obj->weight; + $ligne->weight_units = $obj->weight_units; + $ligne->volume = $obj->volume; + $ligne->volume_units = $obj->volume_units; $this->lignes[$i] = $ligne; $i++; } $this->db->free($resql); + return 1; } - return $this->lignes; + else + { + $this->error=$this->db->error(); + dolibarr_syslog('Expedition::fetch_lines: Error '.$this->error); + return -3; + } } /** diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 6bb48853e4b..f4ae4a1fec9 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -1,7 +1,8 @@ * Copyright (C) 2005-2006 Laurent Destailleur - * Copyright (C) 2005 Simon TOSSER + * Copyright (C) 2005 Simon TOSSER + * Copyright (C) 2005-2007 Régis Houssin * * 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 @@ -429,6 +430,8 @@ else { $expedition = New Expedition($db); $result = $expedition->fetch($_GET["id"]); + $lignes = $expedition->lignes; + $num_prod = sizeof($lignes); if ($expedition->id > 0) { @@ -485,14 +488,17 @@ else $html->form_confirm("fiche.php?id=$expedition->id",$langs->trans("CancelSending"),"Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel"); print '
'; } - - /* - * Commande - */ - if ($commande->brouillon && $user->rights->commande->creer) + + // calcul du poids total et du volume total des produits + //TODO: ajouter conversion pour le poids et le volume et selection de l'unité de mesure la plus utilisée + $totalWeight = ''; + $totalVolume = ''; + for ($i = 0 ; $i < $num_prod ; $i++) { - print '
'; - print ''; + $totalWeight += $lignes[$i]->weight*$lignes[$i]->qty_expedie; + $weightUnit = $lignes[$i]->weight_units; + $totalVolume += $lignes[$i]->volume*$lignes[$i]->qty_expedie; + $volumeUnit = $lignes[$i]->volume_units; } print ''; @@ -519,96 +525,94 @@ else // Date print ''; print '\n"; - print ''; + print ''; + + // Poids Total + print ''; + print '\n"; + print ''; + + // Volume Total + print ''; + print '\n"; + print ''; // Statut print ''; print '\n"; - print ''; + print ''; print "
'.$langs->trans("Date").''.dolibarr_print_date($expedition->date,"%A %d %B %Y")."
'.$langs->trans("TotalWeight").''.$totalWeight.' '.measuring_units_string($weightUnit,"weight")."
'.$langs->trans("TotalVolume").''.$totalVolume.' '.measuring_units_string($volumeUnit,"weight")."
'.$langs->trans("Status").''.$expedition->getLibStatut(4)."
\n"; /* * Lignes produits */ - echo '
'; - - $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande,"; - $sql .= " e.fk_statut, ed.qty as qty_livre"; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; - $sql .= " WHERE e.rowid = ".$expedition->id." AND e.rowid = ed.fk_expedition AND cd.rowid = ed.fk_commande_ligne"; - - $resql = $db->query($sql); - - if ($resql) + print '
'; + print ''; + print ''; + print ''; + if ($expedition->fk_statut <= 1) { - $num_prod = $db->num_rows($resql); - $i = 0; - - print ''; - print ''; - print ''; - if ($obj->fk_statut <= 1) - { - print ''; - } - else - { - print ''; - } - if ($conf->stock->enabled) - { - print ''; - } - print "\n"; - - $var=true; - while ($i < $num_prod) - { - $objp = $db->fetch_object($resql); - - $var=!$var; - print ""; - if ($objp->fk_product > 0) - { - $product = new Product($db); - $product->fetch($objp->fk_product); - - print ''; - } - else - { - print "\n"; - } - - // Qte commandé - print ''; - - // Qte a expedier ou expedier - print ''; - - // Entrepot source - if ($conf->stock->enabled) - { - $entrepot = new Entrepot($db); - $entrepot->fetch($expedition->entrepot_id); - print ''; - } - - - print ""; - - $i++; - $var=!$var; - } - $db->free($resql); + print ''; } else { - dolibarr_print_error($db); + print ''; + } + + print ''; + print ''; + + if ($conf->stock->enabled) + { + print ''; + } + print "\n"; + + $var=true; + + for ($i = 0 ; $i < $num_prod ; $i++) + { + $var=!$var; + print ""; + if ($lignes[$i]->fk_product > 0) + { + print ''; + } + else + { + print "\n"; + } + + // Qte commandé + print ''; + + // Qte a expedier ou expedier + print ''; + + // Poids + print ''; + + // Volume + print ''; + + // Entrepot source + if ($conf->stock->enabled) + { + $entrepot = new Entrepot($db); + $entrepot->fetch($expedition->entrepot_id); + print ''; + } + + + print ""; + + $i++; + $var=!$var; + } } print "
'.$langs->trans("Products").''.$langs->trans("QtyOrdered").'
'.$langs->trans("Products").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyToShip").''.$langs->trans("QtyShipped").''.$langs->trans("WarehouseSource").'
'; - print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; - if ($objp->description) print '
'.nl2br($objp->description); - print '
".nl2br($objp->description)."'.$objp->qty_commande.''.$objp->qty_livre.''.$entrepot->getNomUrl(1).'
'.$langs->trans("QtyToShip").''.$langs->trans("QtyShipped").''.$langs->trans("Weight").''.$langs->trans("Volume").''.$langs->trans("WarehouseSource").'
'; + print ''.img_object($langs->trans("ShowProduct"),"product").' '.$lignes[$i]->ref.' - '.$lignes[$i]->libelle; + if ($lignes[$i]->description) print '
'.nl2br($lignes[$i]->description); + print '
".nl2br($lignes[$i]->description)."'.$lignes[$i]->qty_commande.''.$lignes[$i]->qty_expedie.''.$lignes[$i]->weight*$lignes[$i]->qty_expedie.' '.measuring_units_string($lignes[$i]->weight_units,"weight").''.$lignes[$i]->volume*$lignes[$i]->qty_expedie.' '.measuring_units_string($lignes[$i]->volume_units,"volume").''.$entrepot->getNomUrl(1).'
\n"; @@ -734,8 +738,9 @@ else } $db->free($resql); } - else { - dolibarr_print_error($db); + else + { + dolibarr_print_error($db); } @@ -745,11 +750,6 @@ else print ''; - } - else - { - dolibarr_print_error($db); - } } else {