Add: ajout du poids et du volume dans la fiche expedition

Fix: fonctionnement de fetch_lines avec fetch dans expedition.class.php
This commit is contained in:
Regis Houssin 2007-05-15 22:47:58 +00:00
parent b0a83fee83
commit ac969457a3
2 changed files with 138 additions and 152 deletions

View File

@ -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;
}
}
/**

View File

@ -1,7 +1,8 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2005-2007 Régis Houssin <regis.houssin@cap-networks.com>
*
* 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 '<br>';
}
/*
* 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 '<form action="fiche.php?id='.$expedition->id.'" method="post">';
print '<input type="hidden" name="action" value="setremise">';
$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 '<table class="border" width="100%">';
@ -519,96 +525,94 @@ else
// Date
print '<tr><td>'.$langs->trans("Date").'</td>';
print '<td colspan="3">'.dolibarr_print_date($expedition->date,"%A %d %B %Y")."</td>\n";
print '</tr>';
print '</tr>';
// Poids Total
print '<tr><td>'.$langs->trans("TotalWeight").'</td>';
print '<td colspan="3">'.$totalWeight.' '.measuring_units_string($weightUnit,"weight")."</td>\n";
print '</tr>';
// Volume Total
print '<tr><td>'.$langs->trans("TotalVolume").'</td>';
print '<td colspan="3">'.$totalVolume.' '.measuring_units_string($volumeUnit,"weight")."</td>\n";
print '</tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td>';
print '<td colspan="3">'.$expedition->getLibStatut(4)."</td>\n";
print '</tr>';
print '</tr>';
print "</table>\n";
/*
* Lignes produits
*/
echo '<br><table class="noborder" width="100%">';
$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 '<br><table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Products").'</td>';
print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
if ($expedition->fk_statut <= 1)
{
$num_prod = $db->num_rows($resql);
$i = 0;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Products").'</td>';
print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
if ($obj->fk_statut <= 1)
{
print '<td align="center">'.$langs->trans("QtyToShip").'</td>';
}
else
{
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
}
if ($conf->stock->enabled)
{
print '<td align="left">'.$langs->trans("WarehouseSource").'</td>';
}
print "</tr>\n";
$var=true;
while ($i < $num_prod)
{
$objp = $db->fetch_object($resql);
$var=!$var;
print "<tr $bc[$var]>";
if ($objp->fk_product > 0)
{
$product = new Product($db);
$product->fetch($objp->fk_product);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
if ($objp->description) print '<br>'.nl2br($objp->description);
print '</td>';
}
else
{
print "<td>".nl2br($objp->description)."</td>\n";
}
// Qte commandé
print '<td align="center">'.$objp->qty_commande.'</td>';
// Qte a expedier ou expedier
print '<td align="center">'.$objp->qty_livre.'</td>';
// Entrepot source
if ($conf->stock->enabled)
{
$entrepot = new Entrepot($db);
$entrepot->fetch($expedition->entrepot_id);
print '<td align="left">'.$entrepot->getNomUrl(1).'</td>';
}
print "</tr>";
$i++;
$var=!$var;
}
$db->free($resql);
print '<td align="center">'.$langs->trans("QtyToShip").'</td>';
}
else
{
dolibarr_print_error($db);
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
}
print '<td align="center">'.$langs->trans("Weight").'</td>';
print '<td align="center">'.$langs->trans("Volume").'</td>';
if ($conf->stock->enabled)
{
print '<td align="left">'.$langs->trans("WarehouseSource").'</td>';
}
print "</tr>\n";
$var=true;
for ($i = 0 ; $i < $num_prod ; $i++)
{
$var=!$var;
print "<tr $bc[$var]>";
if ($lignes[$i]->fk_product > 0)
{
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$lignes[$i]->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$lignes[$i]->ref.'</a> - '.$lignes[$i]->libelle;
if ($lignes[$i]->description) print '<br>'.nl2br($lignes[$i]->description);
print '</td>';
}
else
{
print "<td>".nl2br($lignes[$i]->description)."</td>\n";
}
// Qte commandé
print '<td align="center">'.$lignes[$i]->qty_commande.'</td>';
// Qte a expedier ou expedier
print '<td align="center">'.$lignes[$i]->qty_expedie.'</td>';
// Poids
print '<td align="center">'.$lignes[$i]->weight*$lignes[$i]->qty_expedie.' '.measuring_units_string($lignes[$i]->weight_units,"weight").'</td>';
// Volume
print '<td align="center">'.$lignes[$i]->volume*$lignes[$i]->qty_expedie.' '.measuring_units_string($lignes[$i]->volume_units,"volume").'</td>';
// Entrepot source
if ($conf->stock->enabled)
{
$entrepot = new Entrepot($db);
$entrepot->fetch($expedition->entrepot_id);
print '<td align="left">'.$entrepot->getNomUrl(1).'</td>';
}
print "</tr>";
$i++;
$var=!$var;
}
}
print "</table>\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 '</td></tr></table>';
}
else
{
dolibarr_print_error($db);
}
}
else
{