Quelques améliorations diverses sur gestion des éxpéditions

This commit is contained in:
Laurent Destailleur 2006-07-14 11:31:57 +00:00
parent 4db870e577
commit 7facc82362
11 changed files with 478 additions and 391 deletions

View File

@ -1035,7 +1035,7 @@ class Commande extends CommonObject
*/ */
function expedition_array($filtre_statut=-1) function expedition_array($filtre_statut=-1)
{ {
$this->livraisons = array(); $this->expeditions = array();
$sql = 'SELECT fk_product, sum(ed.qty)'; $sql = 'SELECT fk_product, sum(ed.qty)';
$sql.=' FROM '.MAIN_DB_PREFIX.'expeditiondet as ed, '.MAIN_DB_PREFIX.'expedition as e, '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'commandedet as cd'; $sql.=' FROM '.MAIN_DB_PREFIX.'expeditiondet as ed, '.MAIN_DB_PREFIX.'expedition as e, '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'commandedet as cd';
$sql.=' WHERE ed.fk_expedition = e.rowid AND ed.fk_commande_ligne = cd .rowid AND cd.fk_commande = c.rowid'; $sql.=' WHERE ed.fk_expedition = e.rowid AND ed.fk_commande_ligne = cd .rowid AND cd.fk_commande = c.rowid';
@ -1059,14 +1059,14 @@ class Commande extends CommonObject
return 0; return 0;
} }
/** /**
* Renvoie un tableau avec les expeditions par ligne * Renvoie un tableau avec nombre de lignes d'expeditions
* *
*/ */
function nb_expedition() function nb_expedition()
{ {
$sql = 'SELECT count(*) FROM '.MAIN_DB_PREFIX.'expedition as e'; $sql = 'SELECT count(*) FROM '.MAIN_DB_PREFIX.'expedition as e';
$sql .=" WHERE e.fk_commande = $this->id"; $sql .=" WHERE e.fk_commande = ".$this->id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
@ -1076,7 +1076,7 @@ class Commande extends CommonObject
} }
} }
/** /**
* \brief Renvoie un tableau avec les livraisons par ligne * \brief Renvoie un tableau avec les livraisons par ligne
* \param filtre_statut Filtre sur statut * \param filtre_statut Filtre sur statut
* \return int 0 si OK, <0 si KO * \return int 0 si OK, <0 si KO
@ -1107,11 +1107,48 @@ class Commande extends CommonObject
return 0; return 0;
} }
/** /**
* \brief Supprime une ligne de la commande * \brief Renvoie un tableau avec les stocks restant par produit
* \param idligne Id de la ligne à supprimer * \param filtre_statut Filtre sur statut
* \return int >0 si ok, <0 si ko * \return int 0 si OK, <0 si KO
*/ * \todo FONCTION NON FINIE A FINIR
*/
function stock_array($filtre_statut=-1)
{
$this->stocks = array();
// Tableau des id de produit de la commande
// Recherche total en stock pour chaque produit
if (sizeof($array_of_product))
{
$sql = "SELECT fk_product, sum(ps.reel)";
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
$sql.= " WHERE ps.fk_product in (".join(',',$array_of_product).")";
$sql.= ' GROUP BY fk_product ';
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row( $i);
$this->stocks[$row[0]] = $row[1];
$i++;
}
$this->db->free();
}
}
return 0;
}
/**
* \brief Supprime une ligne de la commande
* \param idligne Id de la ligne à supprimer
* \return int >0 si ok, <0 si ko
*/
function delete_line($idligne) function delete_line($idligne)
{ {
if ($this->statut == 0) if ($this->statut == 0)

View File

@ -41,6 +41,7 @@ $langs->load("companies");
$langs->load("bills"); $langs->load("bills");
$langs->load('propal'); $langs->load('propal');
$langs->load('deliveries'); $langs->load('deliveries');
$langs->load('stocks');
$user->getrights('commande'); $user->getrights('commande');
$user->getrights('expedition'); $user->getrights('expedition');
@ -300,7 +301,7 @@ if ($_GET["id"] > 0)
/** /**
* Lignes de commandes avec quantité livrées et reste à livrer * Lignes de commandes avec quantité livrées et reste à livrer
* * Les quantités livrées sont stockées dans $commande->expeditions[fk_product]
*/ */
echo '<table class="liste" width="100%">'; echo '<table class="liste" width="100%">';
@ -352,7 +353,7 @@ if ($_GET["id"] > 0)
} }
else else
{ {
print "<td>".stripslashes(nl2br($objp->description))."</td>\n"; print "<td>".nl2br($objp->description)."</td>\n";
} }
print '<td align="center">'.$objp->qty.'</td>'; print '<td align="center">'.$objp->qty.'</td>';
@ -363,22 +364,20 @@ if ($_GET["id"] > 0)
print '</td>'; print '</td>';
$reste_a_livrer[$objp->fk_product] = $objp->qty - $quantite_livree; $reste_a_livrer[$objp->fk_product] = $objp->qty - $quantite_livree;
$reste_a_livrer_x = $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_total + $reste_a_livrer_x;
print '<td align="center">'; print '<td align="center">';
print $reste_a_livrer[$objp->fk_product]; print $reste_a_livrer[$objp->fk_product];
print '</td>'; print '</td>';
if ($conf->stock->enabled) if ($conf->stock->enabled)
{ {
if ($product->stock_reel < $reste_a_livrer_x) print '<td align="center">';
print $product->stock_reel;
if ($product->stock_reel < $reste_a_livrer[$objp->fk_product])
{ {
print '<td align="center" class="alerte">'.$product->stock_reel.'</td>'; print ' '.img_warning($langs->trans("StockTooLow"));
}
else
{
print '<td align="center">'.$product->stock_reel.'</td>';
} }
print '</td>';
} }
else else
{ {
@ -459,51 +458,6 @@ if ($_GET["id"] > 0)
print "</form>\n"; print "</form>\n";
} }
/*
* Alerte de seuil
*/
if ($reste_a_livrer_total > 0 && $conf->stock->enabled)
{
print '<br><table class="liste" width="100%">';
foreach ($reste_a_livrer as $key => $value)
{
if ($value > 0)
{
$sql = "SELECT e.rowid as entrepot_id, e.label as entrepot, ps.reel, p.label, p.ref, p.rowid as fk_product";
$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e, ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p";
$sql .= " WHERE e.rowid = ps.fk_entrepot AND ps.fk_product = p.rowid AND ps.fk_product = $key";
$sql .= " AND e.statut = 1 AND reel < $value";
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
$var=True;
while ($i < $num)
{
$obja = $db->fetch_object($resql);
print "<tr $bc[$var]>";
print '<td width="30%">';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$obja->ref.'</a> - '.$obja->label;
print '<td><a href="'.DOL_URL_ROOT.'/product/stock/fiche.php?id='.$obja->entrepot_id.'">'.$obja->entrepot.'</td>';
print '<td><b>Stock : '.$obja->reel.'</b>' .img_warning($langs->trans("Alert")).'</td>';
print "</tr>\n";
$i++;
}
$db->free($resql);
}
else {
dolibarr_print_error($db);
}
}
}
print "</table>";
}
/* /*
* Déjà livré * Déjà livré
*/ */
@ -534,13 +488,13 @@ if ($_GET["id"] > 0)
print '<table class="liste" width="100%">'; print '<table class="liste" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td align="left">'.$langs->trans("Sending").'</td>'; print '<td align="left">'.$langs->trans("Sending").'</td>';
print '<td>'.$langs->trans("Product").'</td>';
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
print '<td align="center">'.$langs->trans("Date").'</td>';
if ($conf->livraison->enabled) if ($conf->livraison->enabled)
{ {
print '<td>'.$langs->trans("DeliveryOrder").'</td>'; print '<td>'.$langs->trans("DeliveryOrder").'</td>';
} }
print '<td>'.$langs->trans("Description").'</td>';
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
print '<td align="center">'.$langs->trans("Date").'</td>';
print "</tr>\n"; print "</tr>\n";
$var=True; $var=True;
@ -551,18 +505,6 @@ if ($_GET["id"] > 0)
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td align="left"><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="left"><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.'<a></td>';
if ($conf->livraison->enabled)
{
if ($objp->livraison_id)
{
print '<td><a href="'.DOL_URL_ROOT.'/livraison/fiche.php?id='.$objp->livraison_id.'">'.img_object($langs->trans("ShowSending"),'generic').' '.$objp->livraison_ref.'<a></td>';
}
else
{
print '<td><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'&amp;action=create_delivery">'.$langs->trans("CreateDeliveryOrder").'<a></td>';
}
}
if ($objp->fk_product > 0) if ($objp->fk_product > 0)
{ {
$product = new Product($db); $product = new Product($db);
@ -579,6 +521,19 @@ if ($_GET["id"] > 0)
} }
print '<td align="center">'.$objp->qty_livre.'</td>'; print '<td align="center">'.$objp->qty_livre.'</td>';
print '<td align="center">'.dolibarr_print_date($objp->date_expedition).'</td>'; print '<td align="center">'.dolibarr_print_date($objp->date_expedition).'</td>';
if ($conf->livraison->enabled)
{
if ($objp->livraison_id)
{
print '<td><a href="'.DOL_URL_ROOT.'/livraison/fiche.php?id='.$objp->livraison_id.'">'.img_object($langs->trans("ShowSending"),'generic').' '.$objp->livraison_ref.'<a></td>';
}
else
{
print '<td><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'&amp;action=create_delivery">'.$langs->trans("CreateDeliveryOrder").'<a></td>';
}
}
print '</tr>';
$i++; $i++;
} }

View File

@ -586,6 +586,26 @@ class Expedition extends CommonObject
} }
return $this->lignes; return $this->lignes;
} }
/**
* \brief Retourne le libellé du statut d'un entrepot (ouvert, fermé)
* \return string Libellé
*/
function getLibStatut()
{
return $this->LibStatut($this->statut);
}
/**
* \brief Renvoi le libellé d'un statut donné
* \param statut id statut
* \return string Libellé
*/
function LibStatut($statut)
{
return $this->statuts[$statut];
}
} }

View File

@ -40,6 +40,7 @@ $langs->load("companies");
$langs->load("bills"); $langs->load("bills");
$langs->load('deliveries'); $langs->load('deliveries');
$langs->load('orders'); $langs->load('orders');
$langs->load('stocks');
$user->getrights('expedition'); $user->getrights('expedition');
if (!$user->rights->expedition->lire) if (!$user->rights->expedition->lire)
@ -60,6 +61,8 @@ if ($user->societe_id > 0)
if ($_POST["action"] == 'add') if ($_POST["action"] == 'add')
{ {
// \todo Mettre id entrepot sur ligne detail expedition et non sur fiche expedition
$db->begin(); $db->begin();
// Creation de l'objet expedition // Creation de l'objet expedition
@ -125,7 +128,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes')
if ($user->rights->expedition->supprimer ) if ($user->rights->expedition->supprimer )
{ {
$expedition = new Expedition($db); $expedition = new Expedition($db);
$expedition->fectch($_GET["id"]); $expedition->fetch($_GET["id"]);
$expedition->delete(); $expedition->delete();
Header("Location: liste.php"); Header("Location: liste.php");
} }
@ -166,48 +169,51 @@ $html = new Form($db);
if ($_GET["action"] == 'create') if ($_GET["action"] == 'create')
{ {
print_titre($langs->trans("CreateASending")); print_titre($langs->trans("CreateASending"));
if ($mesg) if ($mesg)
{ {
print $mesg.'<br>'; print $mesg.'<br>';
} }
$commande = new Commande($db); $commande = new Commande($db);
$commande->expedition_array(); $commande->expedition_array();
if ( $commande->fetch($_GET["commande_id"])) if ( $commande->fetch($_GET["commande_id"]))
{ {
$soc = new Societe($db); $soc = new Societe($db);
$soc->fetch($commande->socidp); $soc->fetch($commande->socidp);
$author = new User($db); $author = new User($db);
$author->id = $commande->user_author_id; $author->id = $commande->user_author_id;
$author->fetch(); $author->fetch();
$entrepot = new Entrepot($db); $entrepot = new Entrepot($db);
/* /*
* Commande * Commande
*/ */
print '<form action="fiche.php" method="post">'; print '<form action="fiche.php" method="post">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="commande_id" value="'.$commande->id.'">'; print '<input type="hidden" name="commande_id" value="'.$commande->id.'">';
print '<input type="hidden" name="entrepot_id" value="'.$_GET["entrepot_id"].'">'; if ($_GET["entrepot_id"])
{
print '<input type="hidden" name="entrepot_id" value="'.$_GET["entrepot_id"].'">';
}
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Ref commande // Ref commande
print '<tr><td>'.$langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.'</a></td>'; print '<tr><td>'.$langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.'</a></td>';
print "</tr>\n"; print "</tr>\n";
// Ref commande client // Ref commande client
print '<tr><td>'; print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td nowrap>'; print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
print $langs->trans('RefCustomerOrderShort').'</td><td align="left">'; print $langs->trans('RefCustomerOrderShort').'</td><td align="left">';
print '</td>'; print '</td>';
if ($_GET['action'] != 'refcdeclient' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=refcdeclient&amp;id='.$commande->id.'">'.img_edit($langs->trans('Edit')).'</a></td>'; if ($_GET['action'] != 'refcdeclient' && $commande->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=refcdeclient&amp;id='.$commande->id.'">'.img_edit($langs->trans('Edit')).'</a></td>';
print '</tr></table>'; print '</tr></table>';
print '</td><td colspan="3">'; print '</td><td colspan="3">';
if ($user->rights->commande->creer && $_GET['action'] == 'refcdeclient') if ($user->rights->commande->creer && $_GET['action'] == 'refcdeclient')
{ {
print '<form action="fiche.php?id='.$id.'" method="post">'; print '<form action="fiche.php?id='.$id.'" method="post">';
@ -223,7 +229,7 @@ if ($_GET["action"] == 'create')
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Société // Sociét
print '<tr><td>'.$langs->trans('Company').'</td>'; print '<tr><td>'.$langs->trans('Company').'</td>';
print '<td colspan="3">'.$soc->getNomUrl(1).'</td>'; print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
print '</tr>'; print '</tr>';
@ -232,10 +238,9 @@ if ($_GET["action"] == 'create')
print "<tr><td>".$langs->trans("Date")."</td>"; print "<tr><td>".$langs->trans("Date")."</td>";
print '<td colspan="3">'.dolibarr_print_date($commande->date,"%A %d %B %Y")."</td></tr>\n"; print '<td colspan="3">'.dolibarr_print_date($commande->date,"%A %d %B %Y")."</td></tr>\n";
// Entrepot (si forcé)
if ($conf->stock->enabled && $_GET["entrepot_id"])
if ($conf->stock->enabled) {
{
print '<tr><td>'.$langs->trans("Warehouse").'</td>'; print '<tr><td>'.$langs->trans("Warehouse").'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
$ents = $entrepot->list_array(); $ents = $entrepot->list_array();
@ -245,119 +250,163 @@ if ($_GET["action"] == 'create')
if ($commande->note) if ($commande->note)
{ {
print '<tr><td colspan="3">Note : '.nl2br($commande->note)."</td></tr>"; print '<tr><td colspan="3">'.$langs->trans("NotePrivate").': '.nl2br($commande->note)."</td></tr>";
} }
print "</table>"; print "</table>";
/* /*
* Lignes de commandes * Lignes de commandes
* *
*/ */
echo '<br><table class="noborder" width="100%">'; echo '<br><table class="noborder" width="100%">';
$lignes = $commande->fetch_lignes(1); $lignes = $commande->fetch_lignes(1);
/* Lecture des expeditions déjà effectuées */ /* Lecture des expeditions déjà effectuées */
$commande->expedition_array(); $commande->expedition_array();
$num = sizeof($commande->lignes); $num = sizeof($commande->lignes);
$i = 0; $i = 0;
if ($num) if ($num)
{ {
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td width="54%">'.$langs->trans("Description").'</td>'; print '<td>'.$langs->trans("Description").'</td>';
print '<td align="center">Quan. commandée</td>'; print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
print '<td align="center">Quan. livrée</td>'; print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
print '<td align="center">Quan. à livrer</td>'; print '<td align="center">'.$langs->trans("QtyToShip").'</td>';
if ($conf->stock->enabled) if ($conf->stock->enabled)
{ {
print '<td width="12%" align="center">'.$langs->trans("Stock").'</td>'; if ($_GET["entrepot_id"])
} {
print "</tr>\n"; print '<td align="right">'.$langs->trans("Stock").'</td>';
}
else
{
print '<td align="left">'.$langs->trans("Warehouse").'</td>';
}
}
print "</tr>\n";
}
$var=true;
while ($i < $num)
{
$ligne = $commande->lignes[$i];
$var=!$var;
print "<tr $bc[$var]>\n";
if ($ligne->fk_product > 0)
{
$product = new Product($db);
$product->fetch($ligne->fk_product);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$ligne->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
if ($ligne->description) print nl2br($ligne->description);
print '</td>';
}
else
{
print "<td>".nl2br($ligne->description)."</td>\n";
}
print '<td align="center">'.$ligne->qty.'</td>';
print '<td align="center">';
$quantite_livree = $commande->expeditions[$ligne->fk_product];
print $quantite_livree;;
print '</td>';
$quantite_commandee = $ligne->qty;
$quantite_a_livrer = $quantite_commandee - $quantite_livree;
if ($conf->stock->enabled)
{
$defaultqty=0;
if ($_GET["entrepot_id"])
{
$stock = $product->stock_entrepot[$_GET["entrepot_id"]];
$stock+=0; // Convertit en numérique
$defaultqty=min($quantite_a_livrer, $stock);
}
// Quantité à livrer
print '<td align="center">';
print '<input name="idl'.$i.'" type="hidden" value="'.$ligne->id.'">';
print '<input name="qtyl'.$i.'" type="text" size="4" value="'.$defaultqty.'">';
print '</td>';
// Stock
if ($_GET["entrepot_id"])
{
print '<td align="right">'.$stock;
if ($stock < $quantite_a_livrer)
{
print ' '.img_warning($langs->trans("StockTooLow"));
}
print '</td>';
}
else
{
$array=array();
$sql = "SELECT e.rowid, e.label, ps.reel";
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."entrepot as e";
$sql.= " WHERE ps.fk_entrepot = e.rowid AND fk_product = '".$product->id."'";
$result = $db->query($sql) ;
if ($result)
{
$num = $db->num_rows($result);
$i=0;
if ($num > 0)
{
while ($i < $num)
{
$obj = $db->fetch_object($result);
$array[$obj->rowid] = $obj->label.' ('.$obj->reel.')';
$i++;
}
}
$db->free($result);
}
else
{
$this->error=$db->error();
return -1;
}
print '<td align="left">';
$html->select_array('warehouse'.$i,$array,'',1,0,0);
print '</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 "</tr>\n";
$i++;
$var=!$var;
}
/*
*
*/
print '<tr><td align="center" colspan="5"><br><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>';
print "</table>";
print '</form>';
} }
$var=true; else
while ($i < $num)
{ {
$ligne = $commande->lignes[$i]; dolibarr_print_error($db);
$var=!$var;
print "<tr $bc[$var]>\n";
if ($ligne->fk_product > 0)
{
$product = new Product($db);
$product->fetch($ligne->fk_product);
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$ligne->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
if ($ligne->description) print nl2br($ligne->description);
print '</td>';
}
else
{
print "<td>".nl2br($ligne->description)."</td>\n";
}
print '<td align="center">'.$ligne->qty.'</td>';
/*
*
*/
print '<td align="center">';
$quantite_livree = $commande->expeditions[$ligne->fk_product];
print $quantite_livree;;
print '</td>';
$quantite_commandee = $ligne->qty;
$quantite_a_livrer = $quantite_commandee - $quantite_livree;
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 "</tr>\n";
$i++;
$var=!$var;
} }
/*
*
*/
print '<tr><td align="center" colspan="4"><br><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>';
print "</table>";
print '</form>';
}
else
{
dolibarr_print_error($db);
}
} }
else else
/* *************************************************************************** */ /* *************************************************************************** */
@ -430,7 +479,7 @@ else
/* /*
* Commande * Commande
*/ */
if ($commande->brouillon == 1 && $user->rights->commande->creer) if ($commande->brouillon && $user->rights->commande->creer)
{ {
print '<form action="fiche.php?id='.$expedition->id.'" method="post">'; print '<form action="fiche.php?id='.$expedition->id.'" method="post">';
print '<input type="hidden" name="action" value="setremise">'; print '<input type="hidden" name="action" value="setremise">';
@ -462,6 +511,11 @@ else
print '<td colspan="3">'.dolibarr_print_date($expedition->date,"%A %d %B %Y")."</td>\n"; print '<td colspan="3">'.dolibarr_print_date($expedition->date,"%A %d %B %Y")."</td>\n";
print '</tr>'; print '</tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td>';
print '<td colspan="3">'.$expedition->getLibStatut()."</td>\n";
print '</tr>';
if (!$conf->expedition->enabled && $conf->stock->enabled) if (!$conf->expedition->enabled && $conf->stock->enabled)
{ {
// Entrepot // Entrepot
@ -480,9 +534,9 @@ else
echo '<br><table class="noborder" width="100%">'; echo '<br><table class="noborder" width="100%">';
$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"; $sql .= " e.fk_statut, ed.qty as qty_livre";
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."expeditiondet as ed"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
$sql .= " WHERE ed.fk_expedition = ".$expedition->id." AND cd.rowid = ed.fk_commande_ligne "; $sql .= " WHERE e.rowid = ".$expedition->id." AND e.rowid = ed.fk_expedition AND cd.rowid = ed.fk_commande_ligne";
$resql = $db->query($sql); $resql = $db->query($sql);
@ -494,7 +548,14 @@ else
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Products").'</td>'; print '<td>'.$langs->trans("Products").'</td>';
print '<td align="center">'.$langs->trans("QtyOrdered").'</td>'; print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
print '<td align="center">'.$langs->trans("QtyShipped").'</td>'; if ($obj->fk_statut <= 1)
{
print '<td align="center">'.$langs->trans("QtyToShip").'</td>';
}
else
{
print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
}
print "</tr>\n"; print "</tr>\n";
$var=true; $var=true;
@ -578,12 +639,13 @@ else
$urlsource = $_SERVER["PHP_SELF"]."?id=".$expedition->id; $urlsource = $_SERVER["PHP_SELF"]."?id=".$expedition->id;
$genallowed=$user->rights->expedition->creer; $genallowed=$user->rights->expedition->creer && ($expedition->statut > 0);
$delallowed=$user->rights->expedition->supprimer; $delallowed=$user->rights->expedition->supprimer;
//$genallowed=1; //$genallowed=1;
//$delallowed=0; //$delallowed=0;
$somethingshown=$html->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf); $somethingshown=$html->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf);
if ($genallowed && ! $somethingshown) $somethingshown=1;
/* /*
* Déjà livre * Déjà livre
@ -608,14 +670,14 @@ else
if ($num) if ($num)
{ {
print '<br>'; if ($somethingshown) print '<br>';
print_titre($langs->trans("OtherSendingsForSameOrder")); print_titre($langs->trans("OtherSendingsForSameOrder"));
print '<table class="liste" width="100%">'; print '<table class="liste" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td align="left">'.$langs->trans("Ref").'</td>'; print '<td align="left">'.$langs->trans("Ref").'</td>';
print '<td>'.$langs->trans("Description").'</td>'; print '<td>'.$langs->trans("Description").'</td>';
print '<td align="center">'.$langs->trans("QtyShipped").'</td>'; print '<td align="center">'.$langs->trans("Qty").'</td>';
print '<td align="center">'.$langs->trans("Date").'</td>'; print '<td align="center">'.$langs->trans("Date").'</td>';
print "</tr>\n"; print "</tr>\n";
@ -632,13 +694,13 @@ else
$product->fetch($objp->fk_product); $product->fetch($objp->fk_product);
print '<td>'; 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; print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.dolibarr_trunc($product->libelle,20);
if ($objp->description) print nl2br($objp->description); if ($objp->description) print nl2br(dolibarr_trunc($objp->description,24));
print '</td>'; print '</td>';
} }
else else
{ {
print "<td>".stripslashes(nl2br($objp->description))."</td>\n"; print "<td>".nl2br(dolibarr_trunc($objp->description,24))."</td>\n";
} }
print '<td align="center">'.$objp->qty_livre.'</td>'; print '<td align="center">'.$objp->qty_livre.'</td>';
print '<td align="center" nowrap="nowrap">'.dolibarr_print_date($objp->date_expedition).'</td>'; print '<td align="center" nowrap="nowrap">'.dolibarr_print_date($objp->date_expedition).'</td>';
@ -682,11 +744,12 @@ else
print '</td><td valign="top" width="50%">'; print '</td><td valign="top" width="50%">';
print_titre("Actions");
/* /*
* Liste des actions * Liste des actions
* *
*/ */
print_titre("Actions");
$sql = "SELECT ".$db->pdate("a.datea")." as da, a.note"; $sql = "SELECT ".$db->pdate("a.datea")." as da, a.note";
$sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
$sql .= " WHERE a.fk_soc = ".$commande->socidp." AND a.fk_action in (9,10)"; $sql .= " WHERE a.fk_soc = ".$commande->socidp." AND a.fk_action in (9,10)";

View File

@ -2162,7 +2162,7 @@ class Form
\param htmlname Nom de la zone select \param htmlname Nom de la zone select
\param array Tableau de key+valeur \param array Tableau de key+valeur
\param id Key pré-sélectionnée \param id Key pré-sélectionnée
\param show_empty 1 si il faut ajouter une valeur " " dans la liste, 0 sinon \param show_empty 1 si il faut ajouter une valeur vide dans la liste, 0 sinon
\param key_in_label 1 pour afficher la key dans la valeur "[key] value" \param key_in_label 1 pour afficher la key dans la valeur "[key] value"
\param value_as_key 1 pour utiliser la valeur comme clé \param value_as_key 1 pour utiliser la valeur comme clé
*/ */

View File

@ -16,6 +16,7 @@ CreateSending=Create sending
QtyOrdered=Qty ordered QtyOrdered=Qty ordered
QtyShipped=Qty shipped QtyShipped=Qty shipped
QtyReceived=Qty received QtyReceived=Qty received
QtyToShip=Qty to ship
KeepToShip=Keep to ship KeepToShip=Keep to ship
OtherSendingsForSameOrder=Other sendings already shipped OtherSendingsForSameOrder=Other sendings already shipped
SendingsToValidate=Sending to validate SendingsToValidate=Sending to validate

View File

@ -25,3 +25,4 @@ StockCorrection=Stock correction
StockMovement=Transfer StockMovement=Transfer
NumberOfUnit=Number of units NumberOfUnit=Number of units
TotalStock=Total in stock TotalStock=Total in stock
StockTooLow=Stock too low

View File

@ -15,6 +15,7 @@ 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
QtyToShip=Qté à expédier
QtyReceived=Qté reçue QtyReceived=Qté reçue
KeepToShip=Reste à expédier KeepToShip=Reste à expédier
OtherSendingsForSameOrder=Autres expéditions déjà envoyés OtherSendingsForSameOrder=Autres expéditions déjà envoyés

View File

@ -25,3 +25,4 @@ StockCorrection=Correction stock
StockMovement=Transfert StockMovement=Transfert
NumberOfUnit=Nombre de pièces NumberOfUnit=Nombre de pièces
TotalStock=Total en stock TotalStock=Total en stock
StockTooLow=Stock insuffisant

View File

@ -769,61 +769,61 @@ class Product
* \param ref Ref du produit/service à charger * \param ref Ref du produit/service à charger
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
*/ */
function fetch($id='',$ref='') function fetch($id='',$ref='')
{ {
global $langs; global $langs;
global $conf; global $conf;
dolibarr_syslog("Product::fetch id=$id ref=$ref"); dolibarr_syslog("Product::fetch id=$id ref=$ref");
// Verification parametres // Verification parametres
if (! $id && ! $ref) if (! $id && ! $ref)
{ {
$this->error=$langs->trans('ErrorWrongParameters'); $this->error=$langs->trans('ErrorWrongParameters');
dolibarr_print_error("Product::fetch ".$this->error); dolibarr_print_error("Product::fetch ".$this->error);
return -1; return -1;
} }
$sql = "SELECT rowid, ref, label, description, note, price, tva_tx, envente,"; $sql = "SELECT rowid, ref, label, description, note, price, tva_tx, envente,";
$sql.= " nbvente, fk_product_type, duration, seuil_stock_alerte"; $sql.= " nbvente, fk_product_type, duration, seuil_stock_alerte";
$sql.= " FROM ".MAIN_DB_PREFIX."product"; $sql.= " FROM ".MAIN_DB_PREFIX."product";
if ($id) $sql.= " WHERE rowid = '".$id."'"; if ($id) $sql.= " WHERE rowid = '".$id."'";
if ($ref) $sql.= " WHERE ref = '".addslashes($ref)."'"; if ($ref) $sql.= " WHERE ref = '".addslashes($ref)."'";
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
if ( $result ) if ( $result )
{ {
$result = $this->db->fetch_array(); $result = $this->db->fetch_array();
$this->id = $result["rowid"]; $this->id = $result["rowid"];
$this->ref = $result["ref"]; $this->ref = $result["ref"];
$this->libelle = stripslashes($result["label"]); $this->libelle = stripslashes($result["label"]);
$this->description = stripslashes($result["description"]); $this->description = stripslashes($result["description"]);
$this->note = stripslashes($result["note"]); $this->note = stripslashes($result["note"]);
$this->price = $result["price"]; $this->price = $result["price"];
$this->tva_tx = $result["tva_tx"]; $this->tva_tx = $result["tva_tx"];
$this->type = $result["fk_product_type"]; $this->type = $result["fk_product_type"];
$this->nbvente = $result["nbvente"]; $this->nbvente = $result["nbvente"];
$this->status = $result["envente"]; $this->status = $result["envente"];
$this->duration = $result["duration"]; $this->duration = $result["duration"];
$this->duration_value = substr($result["duration"],0,strlen($result["duration"])-1); $this->duration_value = substr($result["duration"],0,strlen($result["duration"])-1);
$this->duration_unit = substr($result["duration"],-1); $this->duration_unit = substr($result["duration"],-1);
$this->seuil_stock_alerte = $result["seuil_stock_alerte"]; $this->seuil_stock_alerte = $result["seuil_stock_alerte"];
$this->label_url = '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$this->id.'">'.$this->libelle.'</a>'; $this->label_url = '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$this->id.'">'.$this->libelle.'</a>';
if ($this->type == 0) if ($this->type == 0)
{ {
$this->isproduct = 1; $this->isproduct = 1;
$this->isservice = 0; $this->isservice = 0;
} }
else else
{ {
$this->isproduct = 0; $this->isproduct = 0;
$this->isservice = 1; $this->isservice = 1;
} }
$this->db->free(); $this->db->free();
// multilangs // multilangs
if( $conf->global->MAIN_MULTILANGS) $this->getMultiLangs(); if( $conf->global->MAIN_MULTILANGS) $this->getMultiLangs();
@ -831,88 +831,59 @@ class Product
// multiprix // multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1) if($conf->global->PRODUIT_MULTIPRICES == 1)
{ {
if ($ref) if ($ref)
{
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product ";
$sql.= "WHERE ref = '".addslashes($ref)."'";
$result = $this->db->query($sql) ;
if ($result)
{ {
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product "; $result = $this->db->fetch_array();
$sql.= "WHERE ref = '".addslashes($ref)."'"; $prodid = $result["rowid"];
$result = $this->db->query($sql) ;
if ($result)
{
$result = $this->db->fetch_array();
$prodid = $result["rowid"];
}
else
{
dolibarr_print_error($this->db);
return -1;
}
} }
$this -> multiprices[1] = $this->price; else
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{ {
$sql= "SELECT price, tva_tx, envente "; dolibarr_print_error($this->db);
$sql.= "FROM ".MAIN_DB_PREFIX."product_price "; return -1;
$sql.= "where price_level=".$i." and ";
if ($id) $sql.= "fk_product = '".$id."' ";
if ($ref) $sql.= "fk_product = '".$prodid."' ";
$sql.= "order by date_price DESC limit 1";
$result = $this->db->query($sql) ;
if ( $result )
{
$result = $this->db->fetch_array();
if($result["price"] != "" && $result["price"] != "0.00")
$this -> multiprices[$i]=$result["price"];
else
$this -> multiprices[$i]=$this->price;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
} }
}
$this -> multiprices[1] = $this->price;
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
$sql= "SELECT price, tva_tx, envente ";
$sql.= "FROM ".MAIN_DB_PREFIX."product_price ";
$sql.= "where price_level=".$i." and ";
if ($id) $sql.= "fk_product = '".$id."' ";
if ($ref) $sql.= "fk_product = '".$prodid."' ";
$sql.= "order by date_price DESC limit 1";
$result = $this->db->query($sql) ;
if ( $result )
{
$result = $this->db->fetch_array();
if($result["price"] != "" && $result["price"] != "0.00")
$this -> multiprices[$i]=$result["price"];
else
$this -> multiprices[$i]=$this->price;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
} }
$sql = "SELECT reel, fk_entrepot"; $res=$this->load_stock();
$sql .= " FROM ".MAIN_DB_PREFIX."product_stock WHERE fk_product = '".$this->id."'";
$result = $this->db->query($sql) ;
if ($result)
{
$num = $this->db->num_rows($result);
$i=0;
if ($num > 0)
{
while ($i < $num )
{
$row = $this->db->fetch_row($result);
$this->stock_entrepot[$row[1]] = $row[0];
$this->stock_reel = $this->stock_reel + $row[0]; return $res;
$i++; }
} else
{
$this->no_stock = 0; dolibarr_print_error($this->db);
} return -1;
else }
{ }
$this->no_stock = 1;
}
$this->db->free($result);
return 1;
}
else
{
$this->error=$this->db->error();
return -2;
}
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
/** /**
@ -1825,7 +1796,6 @@ function get_each_prod()
* \param nbpiece nombre de pieces * \param nbpiece nombre de pieces
* \param mouvement 0 = ajout, 1 = suppression * \param mouvement 0 = ajout, 1 = suppression
*/ */
function ajust_stock($user, $id_entrepot, $nbpiece, $mouvement) function ajust_stock($user, $id_entrepot, $nbpiece, $mouvement)
{ {
$op[0] = "+" . trim($nbpiece); $op[0] = "+" . trim($nbpiece);
@ -1877,13 +1847,52 @@ function get_each_prod()
} }
} }
/**
* \brief Charge les informations en stock du produit
* \return int < 0 si erreur, > 0 si ok
*/
function load_stock()
{
$sql = "SELECT reel, fk_entrepot";
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock";
$sql.= " WHERE fk_product = '".$this->id."'";
$result = $this->db->query($sql) ;
if ($result)
{
$num = $this->db->num_rows($result);
$i=0;
if ($num > 0)
{
while ($i < $num )
{
$row = $this->db->fetch_row($result);
$this->stock_entrepot[$row[1]] = $row[0];
$this->stock_reel = $this->stock_reel + $row[0];
$i++;
}
/** $this->no_stock = 0;
* \brief Charge les informations relatives à un fournisseur }
* \param fournid id du fournisseur else
* \return int < 0 si erreur, > 0 si ok {
*/ $this->no_stock = 1;
function fetch_fourn_data($fournid) }
$this->db->free($result);
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Charge les informations relatives à un fournisseur
* \param fournid id du fournisseur
* \return int < 0 si erreur, > 0 si ok
*/
function fetch_fourn_data($fournid)
{ {
$sql = "SELECT rowid, ref_fourn"; $sql = "SELECT rowid, ref_fourn";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur "; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur ";

View File

@ -18,7 +18,6 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
/** /**