Fixed: bug #14432 overview: Bug à la création d'une expédition

This commit is contained in:
Laurent Destailleur 2005-09-21 23:43:07 +00:00
parent 820dc58e64
commit 18f22d38a4
9 changed files with 262 additions and 172 deletions

View File

@ -189,7 +189,7 @@ if ($_GET["id"] > 0)
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $total = 0; $i = 0;
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Description").'</td>'; print '<td>'.$langs->trans("Description").'</td>';
@ -371,49 +371,63 @@ if ($_GET["id"] > 0)
} }
/* /*
* Déjà livr * Déjà livré
*/ */
$sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande, ed.qty as qty_livre, e.ref, e.rowid as expedition_id"; $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande";
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; $sql .= " , ed.qty as qty_livre, e.ref, ed.fk_expedition as expedition_id";
$sql .= " WHERE cd.fk_commande = ".$commande->id." AND cd.rowid = ed.fk_commande_ligne AND ed.fk_expedition = e.rowid"; $sql .= ",".$db->pdate("e.date_expedition")." as date_expedition";
$sql .= " ORDER BY e.rowid DESC, cd.fk_product"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
$sql .= " WHERE cd.fk_commande = $commande->id";
$sql .= " AND cd.rowid = ed.fk_commande_ligne";
$sql .= " AND ed.fk_expedition = e.rowid";
$sql .= " ORDER BY cd.fk_product";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $total = 0; $i = 0;
if ($num) if ($num)
{ {
print '<br><table class="liste" width="100%"><tr>'; print '<br><table class="liste" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td width="54%">'.$langs->trans("Description").'</td>'; print '<td width="54%">'.$langs->trans("Description").'</td>';
print '<td align="center">Quan. livrée</td>'; print '<td align="center">Quan. livrée</td>';
print '<td align="center">Expédition</td>'; print '<td align="center">'.$langs->trans("Sending").'</td>';
print '<td align="center">'.$langs->trans("Date").'</td>';
print "</tr>\n"; print "</tr>\n";
$var=True; $var=True;
while ($i < $num) while ($i < $num)
{ {
$objp = $db->fetch_object($resql); $var=!$var;
$objp = $db->fetch_object($resql);
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
if ($objp->fk_product > 0) if ($objp->fk_product > 0)
{ {
print '<td>'; $product = new Product($db);
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>'; $product->fetch($objp->fk_product);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$ligne->product_id.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
if ($objp->description) print nl2br($objp->description);
print '</td>';
} }
else else
{ {
print "<td>".stripslashes(nl2br($objp->description))."</TD>\n"; print "<td>".stripslashes(nl2br($objp->description))."</td>\n";
} }
print '<td align="center">'.$objp->qty_livre.'</td>'; print '<td align="center">'.$objp->qty_livre.'</td>';
print '<td align="center"><a href="fiche.php?id='.$objp->expedition_id.'">'.$objp->ref.'</a></td>'; print '<td align="center"><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="center">'.dolibarr_print_date($objp->date_expedition).'</td>';
$i++; $i++;
} }
print '</table>'; print '</table>';
} }
$db->free($resql);
} }
else { else {
dolibarr_print_error($db); dolibarr_print_error($db);

View File

@ -28,7 +28,8 @@
*/ */
/** \class Expedition /**
\class Expedition
\brief Classe de gestion des expeditions \brief Classe de gestion des expeditions
*/ */
class Expedition class Expedition
@ -37,6 +38,7 @@ class Expedition
var $id ; var $id ;
var $brouillon; var $brouillon;
var $entrepot_id; var $entrepot_id;
/** /**
* Initialisation * Initialisation
* *
@ -222,58 +224,98 @@ class Expedition
} }
/** /**
* \brief Valide l'expedition * \brief Valide l'expedition, et met a jour le stock si stock géré
* \param user Objet de l'utilisateur qui valide * \param user Objet de l'utilisateur qui valide
* \return int * \return int
*/ */
function valid($user) function valid($user)
{ {
global $conf;
require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php"; require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php";
$result = 0; dolibarr_syslog("expedition.class.php::valid");
$this->db->begin();
$error = 0;
if ($user->rights->expedition->valider) if ($user->rights->expedition->valider)
{ {
$this->ref = "EXP".$this->id; $this->ref = "EXP".$this->id;
// \todo Tester si non dejà au statut validé. Si oui, on arrete afin d'éviter
// de décrémenter 2 fois le stock.
$sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET ref='".$this->ref."', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id"; $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET ref='".$this->ref."', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id";
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
$result = 1;
// Si module stock géré et que expedition faite depuis un entrepot // Si module stock géré et que expedition faite depuis un entrepot
if ($conf->stock->enabled && $this->entrepot_id) if ($conf->stock->enabled && $this->entrepot_id)
{ {
/* /*
* Enregistrement d'un mouvement de stock pour chaque produit de l'expedition * Enregistrement d'un mouvement de stock pour chaque produit de l'expedition
*/ */
dolibarr_syslog("expedition.class.php::valid enregistrement des mouvements");
$sql = "SELECT cd.fk_product, ed.qty ";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."expeditiondet as ed";
$sql.= " WHERE ed.fk_expedition = $this->id AND cd.rowid = ed.fk_commande_ligne";
$sql = "SELECT cd.fk_product, ed.qty "; $resql=$this->db->query($sql);
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."expeditiondet as ed"; if ($resql)
$sql .= " WHERE ed.fk_expedition = $this->id AND cd.rowid = ed.fk_commande_ligne ";
if ($this->db->query($sql))
{ {
$num = $this->db->num_rows(); $num = $this->db->num_rows($resql);
$i=0; $i=0;
while($i < $num) while($i < $num)
{ {
dolibarr_syslog("expedition.class.php::valid movment $i");
$obj = $this->db->fetch_object($resql);
$mouvS = new MouvementStock($this->db); $mouvS = new MouvementStock($this->db);
$obj = $this->db->fetch_object(); $result=$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty);
$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty, 0); if ($result < 0)
{
$this->db->rollback();
$this->error=$this->db->error()." - sql=$sql";
dolibarr_syslog("expedition.class.php::valid ".$this->error);
return -3;
}
$i++; $i++;
} }
}
else
{
$this->db->rollback();
$this->error=$this->db->error()." - sql=$sql";
dolibarr_syslog("expedition.class.php::valid ".$this->error);
return -2;
} }
} }
} }
else else
{ {
$result = -1; $this->db->rollback();
$this->error=$this->db->error()." - sql=".$sql; $this->error=$this->db->error()." - sql=$sql";
dolibarr_syslog("expedition.class.php::valid ".$this->error);
return -1;
} }
} }
return $result ; else
{
$this->error="Non autorise";
dolibarr_syslog("expedition.class.php::valid ".$this->error);
return -1;
}
$this->db->commit();
//dolibarr_syslog("expedition.class.php::valid commit");
return 1;
} }

View File

@ -55,6 +55,9 @@ if ($user->societe_id > 0)
if ($_POST["action"] == 'add') if ($_POST["action"] == 'add')
{ {
$db->begin();
// Creation de l'objet expedition
$expedition = new Expedition($db); $expedition = new Expedition($db);
$expedition->date_expedition = time(); $expedition->date_expedition = time();
@ -62,12 +65,11 @@ if ($_POST["action"] == 'add')
$expedition->commande_id = $_POST["commande_id"]; $expedition->commande_id = $_POST["commande_id"];
$expedition->entrepot_id = $_POST["entrepot_id"]; $expedition->entrepot_id = $_POST["entrepot_id"];
// On boucle sur chaque ligne de commande pour compléter objet expedition
// avec qté à livrer
$commande = new Commande($db); $commande = new Commande($db);
$commande->fetch($expedition->commande_id); $commande->fetch($expedition->commande_id);
$commande->fetch_lignes(); $commande->fetch_lignes();
$db->begin();
for ($i = 0 ; $i < sizeof($commande->lignes) ; $i++) for ($i = 0 ; $i < sizeof($commande->lignes) ; $i++)
{ {
$qty = "qtyl".$i; $qty = "qtyl".$i;
@ -177,13 +179,13 @@ if ($_GET["action"] == 'create')
print "<tr><td>".$langs->trans("Date")."</td>"; print "<tr><td>".$langs->trans("Date")."</td>";
print "<td>".strftime("%A %d %B %Y",$commande->date)."</td>\n"; print "<td>".strftime("%A %d %B %Y",$commande->date)."</td>\n";
print '<td colspan="2" width="50%">'.$langs->trans("Order").': ' . $commande->ref; print '<td>'.$langs->trans("Order").'</td><td><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.'</a>';
print "</td></tr>\n"; print "</td></tr>\n";
print '<tr><td>'.$langs->trans("Warehouse").'</td>'; print '<tr><td>'.$langs->trans("Warehouse").'</td>';
print '<td>'; print '<td>';
$ents = $entrepot->list_array(); $ents = $entrepot->list_array();
print $ents[$_GET["entrepot_id"]]; print '<a href="'.DOL_URL_ROOT.'/product/stock/fiche.php?id='.$_GET["entrepot_id"].'">'.img_object($langs->trans("ShowWarehouse"),'stock').' '.$ents[$_GET["entrepot_id"]].'</a>';
print '</td>'; print '</td>';
print "<td>".$langs->trans("Author")."</td><td>$author->fullname</td>\n"; print "<td>".$langs->trans("Author")."</td><td>$author->fullname</td>\n";
@ -232,7 +234,9 @@ if ($_GET["action"] == 'create')
$product->fetch($ligne->product_id); $product->fetch($ligne->product_id);
print '<td>'; print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$ligne->product_id.'">'.nl2br($ligne->description).'</a></td>'; print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$ligne->product_id.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
if ($ligne->description) print nl2br($ligne->description);
print '</td>';
} }
else else
{ {
@ -247,36 +251,40 @@ if ($_GET["action"] == 'create')
$quantite_livree = $commande->livraisons[$ligne->product_id]; $quantite_livree = $commande->livraisons[$ligne->product_id];
print $quantite_livree;; print $quantite_livree;;
print '</td>'; print '</td>';
/*
*
*/
print '<td align="center">';
print '<input name="idl'.$i.'" type="hidden" value="'.$ligne->id.'">';
$quantite_commandee = $ligne->qty; $quantite_commandee = $ligne->qty;
$quantite_a_livrer = $quantite_commandee - $quantite_livree; $quantite_a_livrer = $quantite_commandee - $quantite_livree;
if ($conf->stock->enabled) if ($conf->stock->enabled)
{ {
$stock = $product->stock_entrepot[$_POST["entrepot_id"]]; $stock = $product->stock_entrepot[$_GET["entrepot_id"]];
$stock+=0; // Convertit en numérique
// Quantité à livrer
print '<td align="center">';
print '<input name="idl'.$i.'" type="hidden" value="'.$ligne->id.'">';
print '<input name="qtyl'.$i.'" type="text" size="6" value="'.min($quantite_a_livrer, $stock).'">';
print '</td>';
// Stock
if ($stock < $quantite_a_livrer)
{
print '<td align="center" class="alerte">'.$stock.'</td>';
}
else
{
print '<td align="center">'.$stock.'</td>';
}
}
else
{
// Quantité à livrer
print '<td align="center">';
print '<input name="idl'.$i.'" type="hidden" value="'.$ligne->id.'">';
print '<input name="qtyl'.$i.'" type="text" size="6" value="'.$quantite_a_livrer.'">';
print '</td>';
}
print '<input name="qtyl'.$i.'" type="text" size="6" value="'.min($quantite_a_livrer, $stock).'">';
print '</td>';
if ($stock < $quantite_a_livrer)
{
print '<td align="center" class="alerte">'.$stock.'</td>';
}
else
{
print '<td align="center">'.$stock.'</td>';
}
}
else
{
print '<input name="qtyl'.$i.'" type="text" size="6" value="'.$quantite_a_livrer.'">';
print '</td>';
}
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
@ -425,8 +433,13 @@ else
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
if ($objp->fk_product > 0) if ($objp->fk_product > 0)
{ {
print '<td>'; $product = new Product($db);
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>'; $product->fetch($objp->fk_product);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$ligne->product_id.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
if ($objp->description) print nl2br($objp->description);
print '</td>';
} }
else else
{ {
@ -495,10 +508,9 @@ else
/* /*
* Déjà livré * Déjà livré
*
*/ */
$sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande"; $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande";
$sql .= " , ed.qty as qty_livre, e.ref"; $sql .= " , ed.qty as qty_livre, e.ref, ed.fk_expedition as expedition_id";
$sql .= ",".$db->pdate("e.date_expedition")." as date_expedition"; $sql .= ",".$db->pdate("e.date_expedition")." as date_expedition";
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; $sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
@ -509,47 +521,57 @@ else
$sql .= " ORDER BY cd.fk_product"; $sql .= " ORDER BY cd.fk_product";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
if ($num) if ($num)
{ {
print '<br><table class="liste" cellpadding="3" width="100%"><tr>'; print '<br>';
print '<tr class="liste_titre">';
print '<td width="54%">'.$langs->trans("Description").'</td>'; print_titre($langs->trans("OtherSendingsForSameOrder"));
print '<td align="center">Quan. livrée</td>'; print '<table class="liste" width="100%">';
print '<td align="center">Expédition</td>'; print '<tr class="liste_titre">';
print '<td align="center">'.$langs->trans("Date").'</td>'; print '<td width="54%">'.$langs->trans("Description").'</td>';
print '<td align="center">Quan. livrée</td>';
print "</tr>\n"; print '<td align="center">'.$langs->trans("Sending").'</td>';
print '<td align="center">'.$langs->trans("Date").'</td>';
$var=True; print "</tr>\n";
while ($i < $num)
{ $var=True;
$objp = $db->fetch_object($resql); while ($i < $num)
print "<TR $bc[$var]>"; {
if ($objp->fk_product > 0) $var=!$var;
{ $objp = $db->fetch_object($resql);
print '<td>'; print "<tr $bc[$var]>";
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>'; if ($objp->fk_product > 0)
} {
else $product = new Product($db);
{ $product->fetch($objp->fk_product);
print "<td>".stripslashes(nl2br($objp->description))."</TD>\n";
} print '<td>';
print '<td align="center">'.$objp->qty_livre.'</td>'; print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$ligne->product_id.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
print '<td align="center">'.$objp->ref.'</td>'; if ($objp->description) print nl2br($objp->description);
print '<td align="center">'.dolibarr_print_date($objp->date_expedition).'</td>'; print '</td>';
$i++; }
} else
{
print '</table>'; print "<td>".stripslashes(nl2br($objp->description))."</td>\n";
}
print '<td align="center">'.$objp->qty_livre.'</td>';
print '<td align="center"><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="center">'.dolibarr_print_date($objp->date_expedition).'</td>';
$i++;
}
print '</table>';
}
$db->free($resql);
}
else {
dolibarr_print_error($db);
} }
$db->free($resql);
}
/* /*
* Documents générés * Documents générés

View File

@ -15,4 +15,5 @@ CreateASending=Create a sending
CreateSending=Create sending CreateSending=Create sending
QtyOrdered=Qty ordered QtyOrdered=Qty ordered
QtyShipped=Qty shipped QtyShipped=Qty shipped
KeepToShip=Keep to ship KeepToShip=Keep to ship
OtherSendingsForSameOrder=Other sendings already shipped

View File

@ -15,4 +15,5 @@ CreateASending=Cr
CreateSending=Créer expedition CreateSending=Créer expedition
QtyOrdered=Qté commandée QtyOrdered=Qté commandée
QtyShipped=Qté expédiée QtyShipped=Qté expédiée
KeepToShip=Reste à expédier KeepToShip=Reste à expédier
OtherSendingsForSameOrder=Autres expéditions déjà envoyés

View File

@ -447,17 +447,17 @@ class Product
$this->db->free(); $this->db->free();
$sql = "SELECT reel, fk_entrepot"; $sql = "SELECT reel, fk_entrepot";
$sql .= " FROM ".MAIN_DB_PREFIX."product_stock WHERE fk_product = $id"; $sql .= " FROM ".MAIN_DB_PREFIX."product_stock WHERE fk_product = ".$id;
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
if ( $result ) if ($result)
{ {
$num = $this->db->num_rows(); $num = $this->db->num_rows($result);
$i=0; $i=0;
if ($num > 0) if ($num > 0)
{ {
while ($i < $num ) while ($i < $num )
{ {
$row = $this->db->fetch_row($i); $row = $this->db->fetch_row($result);
$this->stock_entrepot[$row[1]] = $row[0]; $this->stock_entrepot[$row[1]] = $row[0];
$this->stock_reel = $this->stock_reel + $row[0]; $this->stock_reel = $this->stock_reel + $row[0];
@ -470,9 +470,14 @@ class Product
{ {
$this->no_stock = 1; $this->no_stock = 1;
} }
$this->db->free(); $this->db->free($result);
return 1;
}
else
{
$this->error=$this->db->error();
return -2;
} }
return 1;
} }
else else
{ {

View File

@ -134,19 +134,19 @@ if ($_GET["action"] == 'create')
} }
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3"><input name="libelle" size="40" value=""></td></tr>'; print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3"><input name="libelle" size="40" value=""></td></tr>';
print '<tr><td width="20%" valign="top">'.$langs->trans("Description").'</td><td colspan="3">'; print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">';
print '<textarea name="desc" rows="4" cols="60">'; print '<textarea name="desc" rows="4" cols="60">';
print "</textarea></td></tr>"; print "</textarea></td></tr>";
print '<tr><td width="20%">'.$langs->trans("LocationSummary").'</td><td colspan="3"><input name="lieu" size="40" value="'.$entrepot->lieu.'"></td></tr>'; print '<tr><td >'.$langs->trans("LocationSummary").'</td><td colspan="3"><input name="lieu" size="40" value="'.$entrepot->lieu.'"></td></tr>';
print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3"><textarea name="address" cols="60" rows="3" wrap="soft">'; print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3"><textarea name="address" cols="60" rows="3" wrap="soft">';
print $entrepot->address; print $entrepot->address;
print '</textarea></td></tr>'; print '</textarea></td></tr>';
print '<tr><td>'.$langs->trans('Zip').'</td><td><input size="6" type="text" name="cp" value="'.$entrepot->cp.'"></td>'; print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%"><input size="6" type="text" name="cp" value="'.$entrepot->cp.'"></td>';
print '<td>'.$langs->trans('Town').'</td><td><input type="text" name="ville" value="'.$entrepot->ville.'"></td></tr>'; print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%"><input type="text" name="ville" value="'.$entrepot->ville.'"></td></tr>';
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'; print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
$form->select_pays($entrepot->pays_id,$entrepot->pays_code); $form->select_pays($entrepot->pays_id,$entrepot->pays_code);
@ -198,17 +198,17 @@ else
dolibarr_fiche_head($head, $hselected, $langs->trans("Warehouse").': '.$entrepot->libelle); dolibarr_fiche_head($head, $hselected, $langs->trans("Warehouse").': '.$entrepot->libelle);
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">'.$entrepot->libelle.'</td>'; print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">'.$entrepot->libelle.'</td>';
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">'.nl2br($entrepot->description).'</td></tr>'; print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">'.nl2br($entrepot->description).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("LocationSummary").'</td><td colspan="3">'.$entrepot->lieu.'</td></tr>'; print '<tr><td>'.$langs->trans("LocationSummary").'</td><td colspan="3">'.$entrepot->lieu.'</td></tr>';
print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3">'; print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3">';
print $entrepot->address; print $entrepot->address;
print '</td></tr>'; print '</td></tr>';
print '<tr><td>'.$langs->trans('Zip').'</td><td>'.$entrepot->cp.'</td>'; print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$entrepot->cp.'</td>';
print '<td>'.$langs->trans('Town').'</td><td>'.$entrepot->ville.'</td></tr>'; print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$entrepot->ville.'</td></tr>';
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'; print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
$entrepot->pays; $entrepot->pays;

View File

@ -18,7 +18,6 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
/** /**
@ -104,5 +103,5 @@ else
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 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
@ -17,10 +18,10 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
/** \file htdocs/product/stock/mouvementstock.class.php /**
\file htdocs/product/stock/mouvementstock.class.php
\ingroup stock \ingroup stock
\brief Fichier de la classe de gestion des mouvements de stocks \brief Fichier de la classe de gestion des mouvements de stocks
\version $Revision$ \version $Revision$
@ -34,59 +35,64 @@
class MouvementStock class MouvementStock
{ {
function MouvementStock($DB) function MouvementStock($DB)
{ {
$this->db = $DB; $this->db = $DB;
} }
/* /**
* * \brief Crée un mouvement en base
* * \return int <0 si ko, >0 si ok
*/ */
function _create($user, $product_id, $entrepot_id, $qty, $type, $transaction=1) function _create($user, $product_id, $entrepot_id, $qty, $type)
{ {
dolibarr_syslog("mouvementstock.class.php::create $user, $product_id, $entrepot_id, $qty, $type");
$this->db->begin();
if ($this->db->begin($transaction) ) $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)";
{ $sql .= " VALUES (now(), $product_id, $entrepot_id, $qty, $type, $user->id)";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)";
$sql .= " VALUES (now(), $product_id, $entrepot_id, $qty, $type, $user->id)";
if ($this->db->query($sql))
{
$sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + $qty WHERE fk_entrepot = $entrepot_id AND fk_product = $product_id"; if ($this->db->query($sql))
{
if ($this->db->query($sql)) $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + $qty";
{ $sql.= " WHERE fk_entrepot = $entrepot_id AND fk_product = $product_id";
return 1;
}
else
{
print $this->db->error() . "<br>$sql<br>";
return 0;
}
}
else
{
print $this->db->error() . "<br>$sql<br>";
return 0;
}
}
else
{
return 0;
}
}
/*
*
*
*/
function livraison($user, $product_id, $entrepot_id, $qty, $transaction=1)
{
return $this->_create($user, $product_id, $entrepot_id, (0 - $qty), 2, $transaction); if ($this->db->query($sql))
{
$this->db->commit();
//dolibarr_syslog("mouvementstock.class.php::create update ok");
return 1;
}
else
{
$this->db->rollback();
$this->error=$this->db->error() . " - $sql";
dolibarr_syslog("mouvementstock.class.php::create echec update ".$this->error);
return -2;
}
}
else
{
$this->db->rollback();
$this->error=$this->db->error() . " - $sql";
dolibarr_syslog("mouvementstock.class.php::create echec insert ".$this->error);
return -1;
}
} }
/*
*
*
*/
function livraison($user, $product_id, $entrepot_id, $qty)
{
return $this->_create($user, $product_id, $entrepot_id, (0 - $qty), 2);
}
} }
?> ?>