diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php
index 77657e28c49..f9a8d612c00 100644
--- a/htdocs/expedition/fiche.php
+++ b/htdocs/expedition/fiche.php
@@ -713,21 +713,44 @@ else
if ($ret == 'html') print '
';
}
- // Calcul du poids total et du volume total des produits
+ // Calculate ture totalVeight and totalVolume for all products
+ // by adding weight and volume of each line.
$totalWeight = '';
$totalVolume = '';
+ $weightUnit=0;
+ $volumeUnit=0;
for ($i = 0 ; $i < $num_prod ; $i++)
{
$weightUnit=0;
$volumeUnit=0;
if (! empty($lignes[$i]->weight_units)) $weightUnit = $lignes[$i]->weight_units;
- $trueWeightUnit=pow(10,$weightUnit);
- $totalWeight += $lignes[$i]->weight*$lignes[$i]->qty_shipped*$trueWeightUnit;
if (! empty($lignes[$i]->volume_units)) $volumeUnit = $lignes[$i]->volume_units;
- $trueVolumeUnit=pow(10,$volumeUnit);
- $totalVolume += $lignes[$i]->volume*$lignes[$i]->qty_shipped*$trueVolumeUnit;
+ // TODO Use a function addvalueunits(val1,unit1,val2,unit2)=>(val,unit)
+ if ($lignes[$i]->weight_units < 50)
+ {
+ $trueWeightUnit=pow(10,$weightUnit);
+ $totalWeight += $lignes[$i]->weight*$lignes[$i]->qty_shipped*$trueWeightUnit;
+ }
+ else
+ {
+ $trueWeightUnit=$weightUnit;
+ $totalWeight += $lignes[$i]->weight*$lignes[$i]->qty_shipped;
+ }
+ if ($lignes[$i]->volume_units < 50)
+ {
+ //print $lignes[$i]->volume."x".$lignes[$i]->volume_units."x".($lignes[$i]->volume_units < 50)."x".$volumeUnit;
+ $trueVolumeUnit=pow(10,$volumeUnit);
+ //print $lignes[$i]->volume;
+ $totalVolume += $lignes[$i]->volume*$lignes[$i]->qty_shipped*$trueVolumeUnit;
+ }
+ else
+ {
+ $trueVolumeUnit=$volumeUnit;
+ $totalVolume += $lignes[$i]->volume*$lignes[$i]->qty_shipped;
+ }
}
$totalVolume=$totalVolume;
+ //print "totalVolume=".$totalVolume." volumeUnit=".$volumeUnit;
print '
';
@@ -831,8 +854,12 @@ else
else
{
// If sending volume not defined we use sum of products
- // TODO Show in best unit
- if ($totalVolume > 0) print $totalVolume.' '.measuring_units_string(0,"volume");
+ if ($totalVolume > 0)
+ {
+ print $totalVolume.' ';
+ if ($volumeUnit < 50) print measuring_units_string(0,"volume");
+ else print measuring_units_string($volumeUnit,"volume");
+ }
else print ' ';
}
print "\n";
diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index 1cdf4d23f3a..c4025559c44 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -925,22 +925,30 @@ class CommandeFournisseur extends Commande
/**
* Add a product into a stock warehouse.
*
- * @param $user
- * @param $product
- * @param $qty
+ * @param $user User object making change
+ * @param $product Product object to dispatch
+ * @param $qty Qty to dispatch
* @param $entrepot Id of warehouse to add product
- * @param $price
- * @return int <0 if KO, =0 if OK
+ * @param $price Price for PMP value calculation
+ * @param $comment Comment for stock movement
+ * @return int <0 if KO, >0 if OK
*/
- function DispatchProduct($user, $product, $qty, $entrepot, $price=0)
+ function DispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='')
{
global $conf;
$error = 0;
require_once DOL_DOCUMENT_ROOT ."/product/stock/class/mouvementstock.class.php";
+ // Check parameters
+ if ($entrepot <= 0 || $qty <= 0)
+ {
+ $this->error='BadValueForParameter';
+ return -1;
+ }
+
$now=dol_now();
- if ( ($this->statut == 3 || $this->statut == 4 || $this->statut == 5) && $qty > 0)
+ if (($this->statut == 3 || $this->statut == 4 || $this->statut == 5))
{
$this->db->begin();
@@ -973,7 +981,7 @@ class CommandeFournisseur extends Commande
if ($error == 0)
{
$this->db->commit();
- return 0;
+ return 1;
}
else
{
@@ -983,6 +991,7 @@ class CommandeFournisseur extends Commande
}
else
{
+ $this->error='BadStatusForObject';
return -2;
}
}
diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php
index 7280d17b4ae..def7060b5c0 100644
--- a/htdocs/fourn/commande/dispatch.php
+++ b/htdocs/fourn/commande/dispatch.php
@@ -46,12 +46,18 @@ $id = isset($_GET["id"])?$_GET["id"]:'';
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'commande_fournisseur', $id,'');
+if (empty($conf->stock->enabled))
+{
+ accessforbidden();
+}
+
// Recuperation de l'id de projet
$projectid = 0;
if ($_GET["projectid"]) $projectid = $_GET["projectid"];
$mesg='';
+
/*
* Actions
*/
@@ -68,7 +74,14 @@ if ($_POST["action"] == 'dispatch' && $user->rights->fournisseur->commande->rece
$qty = "qty_".$reg[1];
$ent = "entrepot_".$reg[1];
$pu = "pu_".$reg[1];
- $result = $commande->DispatchProduct($user, $_POST[$prod], $_POST[$qty], $_POST[$ent], $_POST[$pu]);
+ if ($_POST[$ent] > 0)
+ {
+ $result = $commande->DispatchProduct($user, $_POST[$prod], $_POST[$qty], $_POST[$ent], $_POST[$pu], $_POST["label"]);
+ }
+ else
+ {
+ dol_syslog('No dispatch for line '.$key.' as no warehouse choosed');
+ }
}
}
@@ -79,12 +92,11 @@ if ($_POST["action"] == 'dispatch' && $user->rights->fournisseur->commande->rece
}
else
{
- $mesg=$commande->error;
+ $mesg=''.$langs->trans($commande->error).'
';
}
}
-
/*
* View
*/
@@ -182,6 +194,9 @@ if ($id > 0 || ! empty($ref))
if ($commande->statut == 3 || $commande->statut == 4 || $commande->statut == 5)
{
+ $entrepot = new Entrepot($db);
+ $listwarehouses=$entrepot->list_array(1);
+
print '