Add more units

This commit is contained in:
Laurent Destailleur 2010-08-26 14:49:40 +00:00
parent f038ba869b
commit 76a7e8f424
8 changed files with 116 additions and 55 deletions

View File

@ -713,21 +713,44 @@ else
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
// 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 = ''; $totalWeight = '';
$totalVolume = ''; $totalVolume = '';
$weightUnit=0;
$volumeUnit=0;
for ($i = 0 ; $i < $num_prod ; $i++) for ($i = 0 ; $i < $num_prod ; $i++)
{ {
$weightUnit=0; $weightUnit=0;
$volumeUnit=0; $volumeUnit=0;
if (! empty($lignes[$i]->weight_units)) $weightUnit = $lignes[$i]->weight_units; 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; if (! empty($lignes[$i]->volume_units)) $volumeUnit = $lignes[$i]->volume_units;
$trueVolumeUnit=pow(10,$volumeUnit); // TODO Use a function addvalueunits(val1,unit1,val2,unit2)=>(val,unit)
$totalVolume += $lignes[$i]->volume*$lignes[$i]->qty_shipped*$trueVolumeUnit; 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; $totalVolume=$totalVolume;
//print "totalVolume=".$totalVolume." volumeUnit=".$volumeUnit;
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
@ -831,8 +854,12 @@ else
else else
{ {
// If sending volume not defined we use sum of products // If sending volume not defined we use sum of products
// TODO Show in best unit if ($totalVolume > 0)
if ($totalVolume > 0) print $totalVolume.' '.measuring_units_string(0,"volume"); {
print $totalVolume.' ';
if ($volumeUnit < 50) print measuring_units_string(0,"volume");
else print measuring_units_string($volumeUnit,"volume");
}
else print '&nbsp;'; else print '&nbsp;';
} }
print "</td>\n"; print "</td>\n";

View File

@ -925,22 +925,30 @@ class CommandeFournisseur extends Commande
/** /**
* Add a product into a stock warehouse. * Add a product into a stock warehouse.
* *
* @param $user * @param $user User object making change
* @param $product * @param $product Product object to dispatch
* @param $qty * @param $qty Qty to dispatch
* @param $entrepot Id of warehouse to add product * @param $entrepot Id of warehouse to add product
* @param $price * @param $price Price for PMP value calculation
* @return int <0 if KO, =0 if OK * @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; global $conf;
$error = 0; $error = 0;
require_once DOL_DOCUMENT_ROOT ."/product/stock/class/mouvementstock.class.php"; 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(); $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(); $this->db->begin();
@ -973,7 +981,7 @@ class CommandeFournisseur extends Commande
if ($error == 0) if ($error == 0)
{ {
$this->db->commit(); $this->db->commit();
return 0; return 1;
} }
else else
{ {
@ -983,6 +991,7 @@ class CommandeFournisseur extends Commande
} }
else else
{ {
$this->error='BadStatusForObject';
return -2; return -2;
} }
} }

View File

@ -46,12 +46,18 @@ $id = isset($_GET["id"])?$_GET["id"]:'';
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'commande_fournisseur', $id,''); $result = restrictedArea($user, 'commande_fournisseur', $id,'');
if (empty($conf->stock->enabled))
{
accessforbidden();
}
// Recuperation de l'id de projet // Recuperation de l'id de projet
$projectid = 0; $projectid = 0;
if ($_GET["projectid"]) $projectid = $_GET["projectid"]; if ($_GET["projectid"]) $projectid = $_GET["projectid"];
$mesg=''; $mesg='';
/* /*
* Actions * Actions
*/ */
@ -68,7 +74,14 @@ if ($_POST["action"] == 'dispatch' && $user->rights->fournisseur->commande->rece
$qty = "qty_".$reg[1]; $qty = "qty_".$reg[1];
$ent = "entrepot_".$reg[1]; $ent = "entrepot_".$reg[1];
$pu = "pu_".$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 else
{ {
$mesg=$commande->error; $mesg='<div class="error">'.$langs->trans($commande->error).'</div>';
} }
} }
/* /*
* View * View
*/ */
@ -182,6 +194,9 @@ if ($id > 0 || ! empty($ref))
if ($commande->statut == 3 || $commande->statut == 4 || $commande->statut == 5) if ($commande->statut == 3 || $commande->statut == 4 || $commande->statut == 5)
{ {
$entrepot = new Entrepot($db);
$listwarehouses=$entrepot->list_array(1);
print '<form method="POST" action="dispatch.php?id='.$commande->id.'">'; print '<form method="POST" action="dispatch.php?id='.$commande->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="dispatch">'; print '<input type="hidden" name="action" value="dispatch">';
@ -229,7 +244,6 @@ if ($id > 0 || ! empty($ref))
print "</tr>\n"; print "</tr>\n";
} }
$entrepot = new Entrepot($db);
$nbfreeproduct=0; $nbfreeproduct=0;
$nbproduct=0; $nbproduct=0;
@ -268,8 +282,14 @@ if ($id > 0 || ! empty($ref))
// Warehouse // Warehouse
print '<td align="right">'; print '<td align="right">';
print $html->selectarray("entrepot_".$i, $entrepot->list_array(), '', $disabled, 0, 0, '', 0, 0, $disabled); if (sizeof($listwarehouses))
{
print $html->selectarray("entrepot_".$i, $listwarehouses, '', $disabled, 0, 0, '', 0, 0, $disabled);
}
else
{
print $langs->trans("NoWarehouseDefined");
}
print "</td>\n"; print "</td>\n";
print "</tr>\n"; print "</tr>\n";
} }
@ -287,7 +307,9 @@ if ($id > 0 || ! empty($ref))
if ($nbproduct) if ($nbproduct)
{ {
print '<center><input type="submit" class="button" value="'.$langs->trans("DispatchVerb").'"></center>'; print '<center><input type="submit" class="button" value="'.$langs->trans("DispatchVerb").'"';
if (sizeof($listwarehouses) <= 0) print ' disabled="true"';
print '></center>';
} }
if (! $nbproduct && $nbfreeproduct) if (! $nbproduct && $nbfreeproduct)
{ {

View File

@ -293,7 +293,7 @@ if ($_REQUEST['action'] == 'confirm_valid' && $_REQUEST['confirm'] == 'yes' && $
$commande->fetch($id); $commande->fetch($id);
$commande->date_commande=time(); $commande->date_commande=dol_now();
$result = $commande->valid($user); $result = $commande->valid($user);
if ($result >= 0) if ($result >= 0)
{ {
@ -812,7 +812,7 @@ if ($id > 0 || ! empty($ref))
*/ */
if ($_GET['action'] == 'approve') if ($_GET['action'] == 'approve')
{ {
$ret=$html->form_confirm("fiche.php?id=$commande->id",$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder"),"confirm_approve", '', 1, 1); $ret=$html->form_confirm("fiche.php?id=$commande->id",$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder",$commande->ref),"confirm_approve", '', 1, 1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
/* /*
@ -820,7 +820,7 @@ if ($id > 0 || ! empty($ref))
*/ */
if ($_GET['action'] == 'refuse') if ($_GET['action'] == 'refuse')
{ {
$ret=$html->form_confirm("fiche.php?id=$commande->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder"),"confirm_refuse", '', 0, 1); $ret=$html->form_confirm("fiche.php?id=$commande->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$commande->ref),"confirm_refuse", '', 0, 1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
/* /*
@ -828,7 +828,7 @@ if ($id > 0 || ! empty($ref))
*/ */
if ($_GET['action'] == 'cancel') if ($_GET['action'] == 'cancel')
{ {
$ret=$html->form_confirm("fiche.php?id=$commande->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder"),"confirm_cancel", '', 0, 1); $ret=$html->form_confirm("fiche.php?id=$commande->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder",$commande->ref),"confirm_cancel", '', 0, 1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }

View File

@ -25,10 +25,10 @@ RefSupplierShort=Ref. supplier
ExportDataset_fournisseur_1=Supplier invoices list and invoice's lines ExportDataset_fournisseur_1=Supplier invoices list and invoice's lines
ExportDataset_fournisseur_2=Supplier invoices and payments ExportDataset_fournisseur_2=Supplier invoices and payments
ApproveThisOrder=Approve this order ApproveThisOrder=Approve this order
ConfirmApproveThisOrder=Are you sure you want to approve this order ? ConfirmApproveThisOrder=Are you sure you want to approve order <b>%s</b> ?
DenyingThisOrder=Denying this order DenyingThisOrder=Denying this order
ConfirmDenyingThisOrder=Are you sure you want to deny this order ? ConfirmDenyingThisOrder=Are you sure you want to deny this order <b>%s</b> ?
ConfirmCancelThisOrder=Are you sure you want to cancel this order ? ConfirmCancelThisOrder=Are you sure you want to cancel this order <b>%s</b> ?
AddCustomerOrder=Create customer order AddCustomerOrder=Create customer order
AddCustomerInvoice=Create customer invoice AddCustomerInvoice=Create customer invoice
AddSupplierOrder=Create supplier order AddSupplierOrder=Create supplier order

View File

@ -24,10 +24,10 @@ RefSupplierShort=Réf. fournisseur
ExportDataset_fournisseur_1=Factures fournisseurs et lignes de facture ExportDataset_fournisseur_1=Factures fournisseurs et lignes de facture
ExportDataset_fournisseur_2=Factures fournisseurs et règlements ExportDataset_fournisseur_2=Factures fournisseurs et règlements
ApproveThisOrder=Approuver la commande ApproveThisOrder=Approuver la commande
ConfirmApproveThisOrder=Êtes-vous sûr de vouloir approuver cette commande ? ConfirmApproveThisOrder=Êtes-vous sûr de vouloir approuver la commande fournisseur <b>%</b> ?
DenyingThisOrder=Refuser la commande DenyingThisOrder=Refuser la commande
ConfirmDenyingThisOrder=Êtes-vous sûr de vouloir refuser cette commande ? ConfirmDenyingThisOrder=Êtes-vous sûr de vouloir refuser la commande fournisseur <b>%</b> ?
ConfirmCancelThisOrder=Êtes-vous sûr de vouloir annuler cette commande ? ConfirmCancelThisOrder=Êtes-vous sûr de vouloir annuler la commande fournisseur <b>%</b> ?
AddCustomerOrder=Créer commande client AddCustomerOrder=Créer commande client
AddCustomerInvoice=Créer facture/avoir client AddCustomerInvoice=Créer facture/avoir client
AddSupplierOrder=Créer commande fournisseur AddSupplierOrder=Créer commande fournisseur

View File

@ -319,20 +319,20 @@ class Entrepot extends CommonObject
/** /**
* \brief Renvoie la liste des entrep<EFBFBD>ts ouverts * Return list of all warehouses
* @return array Array list of warehouses
*/ */
function list_array() function list_array($status=1)
{ {
$liste = array(); $liste = array();
$sql = "SELECT rowid, label"; $sql = "SELECT rowid, label";
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot"; $sql.= " FROM ".MAIN_DB_PREFIX."entrepot";
$sql.= " WHERE statut = 1"; $sql.= " WHERE statut = ".$status;
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
$i = 0; $i = 0;
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
if ( $result ) if ( $result )
{ {
while ($i < $num) while ($i < $num)

View File

@ -27,7 +27,7 @@
/** /**
* \class MouvementStock * \class MouvementStock
* \brief Classe permettant la gestion des mouvements de stocks * \brief Class to manage stock movements
*/ */
class MouvementStock class MouvementStock
{ {
@ -47,7 +47,7 @@ class MouvementStock
* 0=input (stock increase after stock transfert), 1=output (stock decrease after stock transfer), * 0=input (stock increase after stock transfert), 1=output (stock decrease after stock transfer),
* 2=output (stock decrease), 3=input (stock increase) * 2=output (stock decrease), 3=input (stock increase)
* \param price Unit price HT of product * \param price Unit price HT of product
* \pamam label Label of stock movement * \param label Label of stock movement
* \return int <0 if KO, >0 if OK * \return int <0 if KO, >0 if OK
*/ */
function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='') function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='')
@ -197,13 +197,13 @@ class MouvementStock
// Add movement for sub products // Add movement for sub products
if (! $error && $conf->global->PRODUIT_SOUSPRODUITS) if (! $error && $conf->global->PRODUIT_SOUSPRODUITS)
{ {
$error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0); // pmp is not change for subproduct $error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label); // pmp is not change for subproduct
} }
// composition module (this is a non official external module) // composition module (this is a non official external module)
if (! $error && $qty < 0 && $conf->global->MAIN_MODULE_COMPOSITION) if (! $error && $qty < 0 && $conf->global->MAIN_MODULE_COMPOSITION)
{ {
$error = $this->_createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, 0); // pmp is not change for subproduct $error = $this->_createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, 0, $label); // pmp is not change for subproduct
} }
if (! $error) if (! $error)
@ -221,10 +221,11 @@ class MouvementStock
/** /**
* \brief Create movement in database for all subproducts * Create movement in database for all subproducts
* \return int <0 si ko, 0 si ok * @param label Label of stock movement
* @return int <0 if KO, 0 if OK
*/ */
function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=0) function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=0, $label='')
{ {
$error = 0; $error = 0;
$pids = array(); $pids = array();
@ -256,7 +257,7 @@ class MouvementStock
// Create movement for each subproduct // Create movement for each subproduct
foreach($pids as $key => $value) foreach($pids as $key => $value)
{ {
$this->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0); $this->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label);
} }
return $error; return $error;
@ -264,12 +265,13 @@ class MouvementStock
/** /**
* \brief Cree un mouvement en base pour toutes les compositions de produits * Cree un mouvement en base pour toutes les compositions de produits
* \return int <0 si ko, 0 si ok * @param label Label of stock movement
* @return int <0 if KO, 0 if OK
*/ */
function _createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, $price=0) function _createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='')
{ {
dol_syslog("MouvementStock::_createProductComposition $user->id, $fk_product, $entrepot_id, $qty, $type, $price"); dol_syslog("MouvementStock::_createProductComposition $user->id, $fk_product, $entrepot_id, $qty, $type, $price, $label");
$products_compo = array(); $products_compo = array();
$sql = "SELECT fk_product_composition, qte, etat_stock"; $sql = "SELECT fk_product_composition, qte, etat_stock";
@ -295,7 +297,7 @@ class MouvementStock
// Create movement for each subproduct // Create movement for each subproduct
foreach($products_compo as $product) foreach($products_compo as $product)
{ {
$this->_create($user, $product->fk_product_composition, $entrepot_id, ($qty*$product->qte), $type, 0); $this->_create($user, $product->fk_product_composition, $entrepot_id, ($qty*$product->qte), $type, 0, $label);
} }
return 0; return 0;
@ -303,12 +305,13 @@ class MouvementStock
/** /**
* \brief Decrease stock for product and subproducts * Decrease stock for product and subproducts
* \return int <0 if KO, >0 if OK * @param label Label of stock movement
* @return int <0 if KO, >0 if OK
*/ */
function livraison($user, $fk_product, $entrepot_id, $qty, $price=0) function livraison($user, $fk_product, $entrepot_id, $qty, $price=0, $label='')
{ {
return $this->_create($user, $fk_product, $entrepot_id, (0 - $qty), 2, $price); return $this->_create($user, $fk_product, $entrepot_id, (0 - $qty), 2, $price, $label);
} }
@ -316,9 +319,9 @@ class MouvementStock
* \brief Increase stock for product and subproducts * \brief Increase stock for product and subproducts
* \return int <0 if KO, >0 if OK * \return int <0 if KO, >0 if OK
*/ */
function reception($user, $fk_product, $entrepot_id, $qty, $price=0) function reception($user, $fk_product, $entrepot_id, $qty, $price=0, $label='')
{ {
return $this->_create($user, $fk_product, $entrepot_id, $qty, 3, $price); return $this->_create($user, $fk_product, $entrepot_id, $qty, 3, $price, $label);
} }