Fixed: bug #14432 overview: Bug la cration d'une expdition
This commit is contained in:
parent
820dc58e64
commit
18f22d38a4
@ -189,7 +189,7 @@ if ($_GET["id"] > 0)
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0; $total = 0;
|
||||
$i = 0;
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
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 .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
|
||||
$sql .= " WHERE cd.fk_commande = ".$commande->id." AND cd.rowid = ed.fk_commande_ligne AND ed.fk_expedition = e.rowid";
|
||||
$sql .= " ORDER BY e.rowid DESC, cd.fk_product";
|
||||
$sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande";
|
||||
$sql .= " , ed.qty as qty_livre, e.ref, ed.fk_expedition as expedition_id";
|
||||
$sql .= ",".$db->pdate("e.date_expedition")." as date_expedition";
|
||||
$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);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0; $total = 0;
|
||||
$i = 0;
|
||||
|
||||
if ($num)
|
||||
{
|
||||
print '<br><table class="liste" width="100%"><tr>';
|
||||
print '<br><table class="liste" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="54%">'.$langs->trans("Description").'</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";
|
||||
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$var=!$var;
|
||||
$objp = $db->fetch_object($resql);
|
||||
print "<tr $bc[$var]>";
|
||||
if ($objp->fk_product > 0)
|
||||
{
|
||||
print '<td>';
|
||||
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>';
|
||||
$product = new Product($db);
|
||||
$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
|
||||
{
|
||||
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"><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++;
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else {
|
||||
dolibarr_print_error($db);
|
||||
|
||||
@ -28,7 +28,8 @@
|
||||
*/
|
||||
|
||||
|
||||
/** \class Expedition
|
||||
/**
|
||||
\class Expedition
|
||||
\brief Classe de gestion des expeditions
|
||||
*/
|
||||
class Expedition
|
||||
@ -37,6 +38,7 @@ class Expedition
|
||||
var $id ;
|
||||
var $brouillon;
|
||||
var $entrepot_id;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* \return int
|
||||
*/
|
||||
function valid($user)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
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)
|
||||
{
|
||||
$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 .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
||||
|
||||
if ($this->db->query($sql) )
|
||||
{
|
||||
$result = 1;
|
||||
|
||||
// Si module stock géré et que expedition faite depuis un entrepot
|
||||
if ($conf->stock->enabled && $this->entrepot_id)
|
||||
{
|
||||
/*
|
||||
* 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 ";
|
||||
$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 ";
|
||||
|
||||
if ($this->db->query($sql))
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $this->db->num_rows();
|
||||
$num = $this->db->num_rows($resql);
|
||||
$i=0;
|
||||
while($i < $num)
|
||||
{
|
||||
dolibarr_syslog("expedition.class.php::valid movment $i");
|
||||
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$mouvS = new MouvementStock($this->db);
|
||||
$obj = $this->db->fetch_object();
|
||||
$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty, 0);
|
||||
$result=$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->db->rollback();
|
||||
$this->error=$this->db->error()." - sql=$sql";
|
||||
dolibarr_syslog("expedition.class.php::valid ".$this->error);
|
||||
return -3;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
$this->error=$this->db->error()." - sql=$sql";
|
||||
dolibarr_syslog("expedition.class.php::valid ".$this->error);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = -1;
|
||||
$this->error=$this->db->error()." - sql=".$sql;
|
||||
$this->db->rollback();
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -55,6 +55,9 @@ if ($user->societe_id > 0)
|
||||
|
||||
if ($_POST["action"] == 'add')
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
// Creation de l'objet expedition
|
||||
$expedition = new Expedition($db);
|
||||
|
||||
$expedition->date_expedition = time();
|
||||
@ -62,12 +65,11 @@ if ($_POST["action"] == 'add')
|
||||
$expedition->commande_id = $_POST["commande_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->fetch($expedition->commande_id);
|
||||
$commande->fetch_lignes();
|
||||
|
||||
$db->begin();
|
||||
|
||||
for ($i = 0 ; $i < sizeof($commande->lignes) ; $i++)
|
||||
{
|
||||
$qty = "qtyl".$i;
|
||||
@ -177,13 +179,13 @@ if ($_GET["action"] == 'create')
|
||||
print "<tr><td>".$langs->trans("Date")."</td>";
|
||||
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 '<tr><td>'.$langs->trans("Warehouse").'</td>';
|
||||
print '<td>';
|
||||
$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>".$langs->trans("Author")."</td><td>$author->fullname</td>\n";
|
||||
|
||||
@ -232,7 +234,9 @@ if ($_GET["action"] == 'create')
|
||||
$product->fetch($ligne->product_id);
|
||||
|
||||
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
|
||||
{
|
||||
@ -247,36 +251,40 @@ if ($_GET["action"] == 'create')
|
||||
$quantite_livree = $commande->livraisons[$ligne->product_id];
|
||||
print $quantite_livree;;
|
||||
print '</td>';
|
||||
/*
|
||||
*
|
||||
*/
|
||||
print '<td align="center">';
|
||||
print '<input name="idl'.$i.'" type="hidden" value="'.$ligne->id.'">';
|
||||
|
||||
|
||||
$quantite_commandee = $ligne->qty;
|
||||
$quantite_a_livrer = $quantite_commandee - $quantite_livree;
|
||||
|
||||
if ($conf->stock->enabled)
|
||||
{
|
||||
$stock = $product->stock_entrepot[$_POST["entrepot_id"]];
|
||||
if ($conf->stock->enabled)
|
||||
{
|
||||
$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";
|
||||
|
||||
$i++;
|
||||
@ -425,8 +433,13 @@ else
|
||||
print "<tr $bc[$var]>";
|
||||
if ($objp->fk_product > 0)
|
||||
{
|
||||
print '<td>';
|
||||
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>';
|
||||
$product = new Product($db);
|
||||
$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
|
||||
{
|
||||
@ -495,10 +508,9 @@ else
|
||||
|
||||
/*
|
||||
* Déjà livré
|
||||
*
|
||||
*/
|
||||
$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 .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
|
||||
$sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
|
||||
@ -509,47 +521,57 @@ else
|
||||
$sql .= " ORDER BY cd.fk_product";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
if ($num)
|
||||
{
|
||||
print '<br><table class="liste" cellpadding="3" width="100%"><tr>';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="54%">'.$langs->trans("Description").'</td>';
|
||||
print '<td align="center">Quan. livrée</td>';
|
||||
print '<td align="center">Expédition</td>';
|
||||
print '<td align="center">'.$langs->trans("Date").'</td>';
|
||||
|
||||
print "</tr>\n";
|
||||
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
print "<TR $bc[$var]>";
|
||||
if ($objp->fk_product > 0)
|
||||
{
|
||||
print '<td>';
|
||||
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<td>".stripslashes(nl2br($objp->description))."</TD>\n";
|
||||
}
|
||||
print '<td align="center">'.$objp->qty_livre.'</td>';
|
||||
print '<td align="center">'.$objp->ref.'</td>';
|
||||
print '<td align="center">'.dolibarr_print_date($objp->date_expedition).'</td>';
|
||||
$i++;
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
if ($num)
|
||||
{
|
||||
print '<br>';
|
||||
|
||||
print_titre($langs->trans("OtherSendingsForSameOrder"));
|
||||
print '<table class="liste" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="54%">'.$langs->trans("Description").'</td>';
|
||||
print '<td align="center">Quan. livrée</td>';
|
||||
print '<td align="center">'.$langs->trans("Sending").'</td>';
|
||||
print '<td align="center">'.$langs->trans("Date").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
{
|
||||
$var=!$var;
|
||||
$objp = $db->fetch_object($resql);
|
||||
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='.$ligne->product_id.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
|
||||
if ($objp->description) print nl2br($objp->description);
|
||||
print '</td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
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
|
||||
|
||||
@ -15,4 +15,5 @@ CreateASending=Create a sending
|
||||
CreateSending=Create sending
|
||||
QtyOrdered=Qty ordered
|
||||
QtyShipped=Qty shipped
|
||||
KeepToShip=Keep to ship
|
||||
KeepToShip=Keep to ship
|
||||
OtherSendingsForSameOrder=Other sendings already shipped
|
||||
@ -15,4 +15,5 @@ CreateASending=Cr
|
||||
CreateSending=Créer expedition
|
||||
QtyOrdered=Qté commandée
|
||||
QtyShipped=Qté expédiée
|
||||
KeepToShip=Reste à expédier
|
||||
KeepToShip=Reste à expédier
|
||||
OtherSendingsForSameOrder=Autres expéditions déjà envoyés
|
||||
@ -447,17 +447,17 @@ class Product
|
||||
$this->db->free();
|
||||
|
||||
$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) ;
|
||||
if ( $result )
|
||||
if ($result)
|
||||
{
|
||||
$num = $this->db->num_rows();
|
||||
$num = $this->db->num_rows($result);
|
||||
$i=0;
|
||||
if ($num > 0)
|
||||
{
|
||||
while ($i < $num )
|
||||
{
|
||||
$row = $this->db->fetch_row($i);
|
||||
$row = $this->db->fetch_row($result);
|
||||
$this->stock_entrepot[$row[1]] = $row[0];
|
||||
|
||||
$this->stock_reel = $this->stock_reel + $row[0];
|
||||
@ -470,9 +470,14 @@ class Product
|
||||
{
|
||||
$this->no_stock = 1;
|
||||
}
|
||||
$this->db->free();
|
||||
$this->db->free($result);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
return -2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -134,19 +134,19 @@ if ($_GET["action"] == 'create')
|
||||
}
|
||||
|
||||
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="20%" valign="top">'.$langs->trans("Description").'</td><td colspan="3">';
|
||||
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3"><input name="libelle" size="40" value=""></td></tr>';
|
||||
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">';
|
||||
print '<textarea name="desc" rows="4" cols="60">';
|
||||
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 $entrepot->address;
|
||||
print '</textarea></td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans('Zip').'</td><td><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 '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%"><input size="6" type="text" name="cp" value="'.$entrepot->cp.'"></td>';
|
||||
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">';
|
||||
$form->select_pays($entrepot->pays_id,$entrepot->pays_code);
|
||||
@ -198,17 +198,17 @@ else
|
||||
dolibarr_fiche_head($head, $hselected, $langs->trans("Warehouse").': '.$entrepot->libelle);
|
||||
|
||||
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 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 $entrepot->address;
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans('Zip').'</td><td>'.$entrepot->cp.'</td>';
|
||||
print '<td>'.$langs->trans('Town').'</td><td>'.$entrepot->ville.'</td></tr>';
|
||||
print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$entrepot->cp.'</td>';
|
||||
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">';
|
||||
$entrepot->pays;
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
*
|
||||
* $Id$
|
||||
* $Source$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -104,5 +103,5 @@ else
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter("<em>Dernière modification $Date$ révision $Revision$</em>");
|
||||
llxFooter('$Date$ - $Revision$');
|
||||
?>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
/* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -17,10 +18,10 @@
|
||||
*
|
||||
* $Id$
|
||||
* $Source$
|
||||
*
|
||||
*/
|
||||
|
||||
/** \file htdocs/product/stock/mouvementstock.class.php
|
||||
/**
|
||||
\file htdocs/product/stock/mouvementstock.class.php
|
||||
\ingroup stock
|
||||
\brief Fichier de la classe de gestion des mouvements de stocks
|
||||
\version $Revision$
|
||||
@ -34,59 +35,64 @@
|
||||
class MouvementStock
|
||||
{
|
||||
|
||||
function MouvementStock($DB)
|
||||
function MouvementStock($DB)
|
||||
{
|
||||
$this->db = $DB;
|
||||
$this->db = $DB;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
function _create($user, $product_id, $entrepot_id, $qty, $type, $transaction=1)
|
||||
/**
|
||||
* \brief Crée un mouvement en base
|
||||
* \return int <0 si ko, >0 si ok
|
||||
*/
|
||||
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)";
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$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 = "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))
|
||||
{
|
||||
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)
|
||||
{
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + $qty";
|
||||
$sql.= " WHERE fk_entrepot = $entrepot_id AND fk_product = $product_id";
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user