Fix: Maxi debug on stock decrease

This commit is contained in:
Laurent Destailleur 2008-10-23 21:54:30 +00:00
parent 18f10649c2
commit d1a90768cd
19 changed files with 1027 additions and 889 deletions

View File

@ -22,7 +22,7 @@
\ingroup stock \ingroup stock
\brief Page d'administration/configuration du module gestion de stock \brief Page d'administration/configuration du module gestion de stock
\version $Id$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
@ -30,11 +30,11 @@ $langs->load("admin");
$langs->load("stocks"); $langs->load("stocks");
if (!$user->admin) if (!$user->admin)
accessforbidden(); accessforbidden();
/* /*
* Actions * Actions
*/ */
if ($_POST["action"] == 'stock_userstock') if ($_POST["action"] == 'stock_userstock')
{ {
dolibarr_set_const($db, "STOCK_USERSTOCK", $_POST["stock_userstock"]); dolibarr_set_const($db, "STOCK_USERSTOCK", $_POST["stock_userstock"]);
@ -54,8 +54,8 @@ elseif ($_POST["action"] == 'stock_userstock_autocreate')
} }
// Mode of stock changement // Mode of stock changement
elseif ( $_POST["action"] == 'stock_bill' elseif ( $_POST["action"] == 'stock_bill'
|| $_POST["action"] == 'stock_validateorder' || $_POST["action"] == 'stock_validateorder'
|| $_POST["action"] == 'stock_shipment') || $_POST["action"] == 'stock_shipment')
{ {
$count=0; $count=0;
$db->begin(); $db->begin();
@ -133,8 +133,9 @@ if ($conf->global->STOCK_USERSTOCK == 1)
} }
// Title rule for stock decrease
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print " <td>".$langs->trans("RuleForStockManagement")."</td>\n"; print " <td>".$langs->trans("RuleForStockManagementDecrease")."</td>\n";
print " <td align=\"right\" width=\"160\">".$langs->trans("Value")."</td>\n"; print " <td align=\"right\" width=\"160\">".$langs->trans("Value")."</td>\n";
print '</tr>'."\n"; print '</tr>'."\n";
$var=true; $var=true;
@ -178,6 +179,21 @@ if ($conf->expedition->enabled)
print "</form>\n</td>\n</tr>\n"; print "</form>\n</td>\n</tr>\n";
} }
// Title rule for stock increase
print '<tr class="liste_titre">';
print " <td>".$langs->trans("RuleForStockManagementIncrease")."</td>\n";
print " <td align=\"right\" width=\"160\">".$langs->trans("Value")."</td>\n";
print '</tr>'."\n";
$var=true;
$var=!$var;
print "<tr ".$bc[$var].">";
print '<td colspan="2">'.$langs->trans("FeatureNotYetAvailable").'</td>';
print '</tr>'."\n";
print '</table>'; print '</table>';
$db->close(); $db->close();

View File

@ -52,7 +52,7 @@ class Commande extends CommonObject
var $ref_client; var $ref_client;
var $contactid; var $contactid;
var $projet_id; var $projet_id;
var $statut; // -1=Annulee, 0=Brouillon, 1=Validee, 2=Acceptee, 3=Recue (facturee ou non) var $statut; // -1=Annulee, 0=Brouillon, 1=Validee, 2=Acceptee, 3=Envoyee/Recue (facturee ou non)
var $facturee; var $facturee;
var $brouillon; var $brouillon;
var $cond_reglement_id; var $cond_reglement_id;
@ -205,6 +205,7 @@ class Commande extends CommonObject
{ {
global $conf,$langs; global $conf,$langs;
// Protection
if ($this->statut == 1) if ($this->statut == 1)
{ {
return 0; return 0;
@ -212,7 +213,7 @@ class Commande extends CommonObject
if (! $user->rights->commande->valider) if (! $user->rights->commande->valider)
{ {
$this->error='Autorisation insuffisante'; $this->error='Permission denied';
return -1; return -1;
} }
@ -274,31 +275,15 @@ class Commande extends CommonObject
} }
} }
//Si active on decremente le produit principal et ses composants a la validation de command // If stock is incremented on validate order, we must increment it
if($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) if($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
{ {
require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{ {
if ($conf->global->PRODUIT_SOUSPRODUITS == 1)
{
$prod = new Product($this->db, $this->lignes[$i]->fk_product);
$prod -> get_sousproduits_arbo ();
$prods_arbo = $prod->get_each_prod();
if(sizeof($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value)
{
// on decompte le stock de tous les sousproduits
$mouvS = new MouvementStock($this->db);
$entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot
$result=$mouvS->livraison($user, $value[1], $entrepot_id, $value[0]*$this->lignes[$i]->qty);
}
}
}
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// on decompte le stock du produit principal // We decrement stock of product (and sub-products)
$entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot $entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot
$result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty); $result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
} }
@ -325,152 +310,150 @@ class Commande extends CommonObject
/** /**
* \brief Set draft status * \brief Set draft status
* \param user Object user that modify * \param user Object user that modify
* \param int <0 if KO, >0 if OK * \return int <0 if KO, >0 if OK
*/ */
function set_draft($user) function set_draft($user)
{ {
global $conf,$langs; global $conf,$langs;
// Protection
if ($this->statut <= 0)
{
return 0;
}
if (! $user->rights->commande->valider)
{
$this->error='Permission denied';
return -1;
}
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 0"; $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 0";
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
dolibarr_syslog("Commande::set_draft sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
//Si active on incremente le produit principal et ses composants a l'edition de la commande // If stock is decremented on validate order, we must reincrement it
if($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
{ {
require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{ {
if ($conf->global->PRODUIT_SOUSPRODUITS == 1)
{
$prod = new Product($this->db, $this->lignes[$i]->fk_product);
$prod -> get_sousproduits_arbo ();
$prods_arbo = $prod->get_each_prod();
if(sizeof($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value)
{
// on decompte le stock de tous les sousproduits
$mouvS = new MouvementStock($this->db);
$entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot
$result=$mouvS->reception($user, $value[1], $entrepot_id, $value[0]*$this->lignes[$i]->qty);
}
}
}
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// on decompte le stock du produit principal // We increment stock of product (and sub-products)
$entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot $entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot
$result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty); $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
} }
if ($result > 0)
{
$this->statut=0;
$this->db->commit();
return $result;
} }
else
{
$this->error=$mouvP->error;
$this->db->rollback();
return $result;
}
}
$this->statut=0;
$this->db->commit();
return 1; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); $this->error=$this->db->error();
$this->db->rollback();
dolibarr_syslog($this->error, LOG_ERR);
return -1;
} }
} }
/** /**
* \brief Cloture la commande * \brief Cloture la commande
* \param user Objet utilisateur qui cloture * \param user Objet utilisateur qui cloture
* \return int <0 si ko, >0 si ok * \return int <0 if KO, >0 if OK
*/ */
function cloture($user) function cloture($user)
{ {
global $conf; global $conf;
if ($user->rights->commande->valider) if ($user->rights->commande->valider)
{ {
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
$sql.= ' SET fk_statut = 3,'; $sql.= ' SET fk_statut = 3,';
$sql.= ' fk_user_cloture = '.$user->id.','; $sql.= ' fk_user_cloture = '.$user->id.',';
$sql.= " date_cloture = ".$this->db->idate(mktime()); $sql.= ' date_cloture = '.$this->db->idate(mktime());
$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))
{ {
if($conf->stock->enabled && $conf->global->PRODUIT_SOUSPRODUITS == 1 && $conf->global->STOCK_CALCULATE_ON_SHIPMENT == 1)
{
require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{
$prod = new Product($this->db, $this->lignes[$i]->fk_product);
$prod -> get_sousproduits_arbo ();
$prods_arbo = $prod->get_each_prod();
if(sizeof($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value)
{
// on decompte le stock de tous les sousproduits
$mouvS = new MouvementStock($this->db);
$entrepot_id = "1";
$result=$mouvS->livraison($user, $value[1], $entrepot_id, $value[0]*$this->lignes[$i]->qty);
}
}
// on decompte pas le stock du produit principal, ca serait fait manuellement avec l'expedition
// $result=$mouvS->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
}
}
return 1; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); $this->error=$this->db->error();
dolibarr_syslog($this->error, LOG_ERR);
return -1; return -1;
} }
} }
} }
/** /**
* Annule la commande * \brief Cancel an order
* * \return int <0 if KO, >0 if OK
* \remarks If stock is decremented on order validation, we must reincrement it
*/ */
function cancel($user) function cancel($user)
{ {
global $conf; global $conf;
if ($user->rights->commande->valider) if ($user->rights->commande->valider)
{ {
$this->db->begin();
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET fk_statut = -1'; $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET fk_statut = -1';
$sql .= " WHERE rowid = $this->id AND fk_statut = 1 ;"; $sql .= " WHERE rowid = $this->id AND fk_statut = 1 ;";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
//Si active on incremente le produit principal et ses composants a l'edition de la commande // If stock is decremented on validate order, we must reincrement it
if($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) if($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
{ {
require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{
if ($conf->global->PRODUIT_SOUSPRODUITS == 1)
{
$prod = new Product($this->db, $this->lignes[$i]->fk_product);
$prod -> get_sousproduits_arbo ();
$prods_arbo = $prod->get_each_prod();
if(sizeof($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value)
{
// on decompte le stock de tous les sousproduits
$mouvS = new MouvementStock($this->db);
$entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot
$result=$mouvS->reception($user, $value[1], $entrepot_id, $value[0]*$this->lignes[$i]->qty);
}
}
}
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// on decompte le stock du produit principal // We increment stock of product (and sub-products)
$entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot $entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot
$result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty); $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
if ($result > 0)
{
$this->db->commit();
return $result;
}
else
{
$this->error=$mouvP->error;
$this->db->rollback();
return $result;
} }
} }
$this->db->commit();
return 1; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); $this->error=$this->db->error();
$this->db->rollback();
dolibarr_syslog($this->error, LOG_ERR);
return -1;
} }
} }
} }

View File

@ -24,7 +24,7 @@
\ingroup commande \ingroup commande
\brief Page liste des commandes \brief Page liste des commandes
\version $Id$ \version $Id$
*/ */
require('./pre.inc.php'); require('./pre.inc.php');
@ -217,15 +217,18 @@ if ($resql)
print '</td>'; print '</td>';
print '<td><a href="../comm/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>'; print '<td><a href="../comm/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
print '<td>'.$objp->ref_client.'</td>'; print '<td>'.$objp->ref_client.'</td>';
// Date
$y = dolibarr_print_date($objp->date_commande,'%Y');
$m = dolibarr_print_date($objp->date_commande,'%m');
$ml = dolibarr_print_date($objp->date_commande,'%B');
$d = dolibarr_print_date($objp->date_commande,'%d');
print '<td align="right">'; print '<td align="right">';
$y = strftime('%Y',$objp->date_commande); print $d;
$m = strftime('%m',$objp->date_commande); print ' <a href="liste.php?year='.$y.'&amp;month='.$m.'">'.$ml.'</a>';
print strftime('%d',$objp->date_commande); print ' <a href="liste.php?year='.$y.'">'.$y.'</a>';
print ' <a href="liste.php?year='.$y.'&amp;month='.$m.'">';
print strftime('%B',$objp->date_commande).'</a>';
print ' <a href="liste.php?year='.$y.'">';
print strftime('%Y',$objp->date_commande).'</a>';
print '</td>'; print '</td>';
print '<td align="right">'.$generic_commande->LibStatut($objp->fk_statut,$objp->facturee,5).'</td>'; print '<td align="right">'.$generic_commande->LibStatut($objp->fk_statut,$objp->facturee,5).'</td>';
print '</tr>'; print '</tr>';

View File

@ -336,11 +336,12 @@ if ($_GET["id"] > 0)
*/ */
print '<table class="liste" width="100%">'; print '<table class="liste" width="100%">';
$sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.price, cd.qty, cd.tva_tx, cd.subprice"; $sql = "SELECT cd.fk_product, cd.description, cd.price, sum(cd.qty) as qty, cd.rowid, cd.tva_tx, cd.subprice";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
$sql.= " WHERE cd.fk_commande = ".$commande->id; $sql.= " WHERE cd.fk_commande = ".$commande->id;
// $sql.= " AND p.fk_product_type <> 1"; Why this line ? // $sql.= " AND p.fk_product_type <> 1"; Why this line ?
$sql.= " group by (cd.fk_product)";
$sql.= " ORDER BY cd.rowid"; $sql.= " ORDER BY cd.rowid";
dolibarr_syslog("commande.php sql=".$sql, LOG_DEBUG); dolibarr_syslog("commande.php sql=".$sql, LOG_DEBUG);
@ -390,6 +391,7 @@ if ($_GET["id"] > 0)
print '<td align="center">'.$objp->qty.'</td>'; print '<td align="center">'.$objp->qty.'</td>';
$qtyProdCom=$objp->qty;
print '<td align="center">'; print '<td align="center">';
// Nb of sending products for this line of order // Nb of sending products for this line of order
$quantite_livree = $commande->expeditions[$objp->rowid]; $quantite_livree = $commande->expeditions[$objp->rowid];
@ -418,6 +420,17 @@ if ($_GET["id"] > 0)
} }
print "</tr>"; print "</tr>";
// associations sous produits
$product->get_sousproduits_arbo ();
$prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
if(sizeof($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value)
{
print $value[0];
}
}
$i++; $i++;
$var=!$var; $var=!$var;
} }

View File

@ -354,6 +354,7 @@ if ($_GET["action"] == 'create')
} }
print '<td align="center">'.$ligne->qty.'</td>'; print '<td align="center">'.$ligne->qty.'</td>';
$qtyProdCom=$ligne->qty;
print '<td align="center">'; print '<td align="center">';
$quantityDelivered = $object->expeditions[$ligne->id]; $quantityDelivered = $object->expeditions[$ligne->id];
@ -423,6 +424,7 @@ if ($_GET["action"] == 'create')
$html->select_array('entl'.$i,$array,'',1,0,0); $html->select_array('entl'.$i,$array,'',1,0,0);
print '</td>'; print '</td>';
} }
} }
else else
{ {
@ -435,6 +437,17 @@ if ($_GET["action"] == 'create')
print "</tr>\n"; print "</tr>\n";
// associations sous produits
$product->get_sousproduits_arbo ();
$prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
if(sizeof($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value)
{
print $value[0];
}
}
$indiceAsked++; $indiceAsked++;
} }
@ -506,7 +519,7 @@ else
*/ */
if ($_GET["action"] == 'delete') if ($_GET["action"] == 'delete')
{ {
$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('DeleteSending'),'Etes-vous sûr de vouloir supprimer cette expedition ?','confirm_delete'); $html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$expedition->ref),'confirm_delete');
print '<br>'; print '<br>';
} }
@ -516,7 +529,7 @@ else
*/ */
if ($_GET["action"] == 'valid') if ($_GET["action"] == 'valid')
{ {
$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('ValidateSending'),'Etes-vous sûr de vouloir valider cette expédition ?','confirm_valid'); $html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('ValidateSending'),$langs->trans("ConfirmValidateSending",$expedition->ref),'confirm_valid');
print '<br>'; print '<br>';
} }
/* /*
@ -525,7 +538,7 @@ else
*/ */
if ($_GET["action"] == 'annuler') if ($_GET["action"] == 'annuler')
{ {
$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('CancelSending'),'Etes-vous sûr de vouloir annuler cette commande ?','confirm_cancel'); $html->form_confirm($_SERVER['PHP_SELF'].'?id='.$expedition->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$expedition->ref),'confirm_cancel');
print '<br>'; print '<br>';
} }

View File

@ -99,7 +99,7 @@ MultiPriceLevelsName=Price categories
AssociatedProductsAbility=Activate the associated products AssociatedProductsAbility=Activate the associated products
AssociatedProducts=Associated products AssociatedProducts=Associated products
AssociatedProductsNumber=Number of associated products AssociatedProductsNumber=Number of associated products
EditAssociate=Associated EditAssociate=Associate
Translation=Translation Translation=Translation
KeywordFilter=Keyword filter KeywordFilter=Keyword filter
CategoryFilter=Category filter CategoryFilter=Category filter

View File

@ -35,3 +35,6 @@ Carriers=Carriers
Carrier=Carrier Carrier=Carrier
CarriersArea=Carriers area CarriersArea=Carriers area
NewCarrier=New carrier NewCarrier=New carrier
ConfirmDeleteSending=Are you sure you want to delete this sending ?
ConfirmValidateSending=Are you sure you want to valdate this sending ?
ConfirmCancelSending=Are you sure you want to cancel this sending ?

View File

@ -38,7 +38,8 @@ EnhancedValueOfWarehouses=Warehouses value
UserWarehouseAutoCreate=Create a stock automatically when creating a user UserWarehouseAutoCreate=Create a stock automatically when creating a user
QtyDispatched=Quantity dispatched QtyDispatched=Quantity dispatched
OrderDispatch=Order dispatching OrderDispatch=Order dispatching
RuleForStockManagement=Rule for stock management RuleForStockManagementDecrease=Rule for stock management decrease
RuleForStockManagementIncrease=Rule for stock management increase
DeStockReStockOnBill=Decrease/increase real stocks on invoices/credit notes (warning, in this version, it's only in warehouse number 1 that stock is modified) DeStockReStockOnBill=Decrease/increase real stocks on invoices/credit notes (warning, in this version, it's only in warehouse number 1 that stock is modified)
DeStockReStockOnValidateOrder=Decrease/increase real stocks on orders notes (warning, in this version, it's only in warehouse number 1 that stock is modified) DeStockReStockOnValidateOrder=Decrease/increase real stocks on orders notes (warning, in this version, it's only in warehouse number 1 that stock is modified)
DeStockReStockOnShipment=Decrease/increase real stocks on shipment (recommanded) DeStockReStockOnShipment=Decrease/increase real stocks on shipment (recommanded)

View File

@ -100,7 +100,7 @@ MultiPriceLevelsName=Categor
AssociatedProductsAbility=Activar productos asociados AssociatedProductsAbility=Activar productos asociados
AssociatedProducts=Productos asociados AssociatedProducts=Productos asociados
AssociatedProductsNumber=Nº de productos asociados AssociatedProductsNumber=Nº de productos asociados
EditAssociate=Asociar a EditAssociate=Asociar
Translation=Traducción Translation=Traducción
KeywordFilter=Filtro por clave KeywordFilter=Filtro por clave
CategoryFilter=Filtro por categoría CategoryFilter=Filtro por categoría

View File

@ -89,7 +89,7 @@ MultiPriceLevelsName=Cat
AssociatedProductsAbility=Activer les produits associés AssociatedProductsAbility=Activer les produits associés
AssociatedProducts=Produits associés AssociatedProducts=Produits associés
AssociatedProductsNumber=Nombre de produits associés AssociatedProductsNumber=Nombre de produits associés
EditAssociate=Associé EditAssociate=Associer
Translation=Traduction Translation=Traduction
KeywordFilter=Filtre par mot-clé KeywordFilter=Filtre par mot-clé
CategoryFilter=Filtre par catégorie CategoryFilter=Filtre par catégorie

View File

@ -74,7 +74,7 @@ NumberOfOrdersByMonth=Nombre de commandes par mois
AmountOfOrdersByMonthHT=Montant total de commandes par mois (HT) AmountOfOrdersByMonthHT=Montant total de commandes par mois (HT)
ListOfOrders=Liste des commandes ListOfOrders=Liste des commandes
CloseOrder=Cloturer commande CloseOrder=Cloturer commande
ConfirmCloseOrder=Êtes-vous sur de vouloir cloturer cette commande ? Une fois une commande cloturée, elle doit être facturée. ConfirmCloseOrder=Êtes-vous sur de vouloir cloturer cette commande ? Une fois une commande cloturée, elle peut être facturée.
ConfirmCloseOrderIfSending=Êtes-vous sur de vouloir cloturer cette commande ? Vous ne devez cloturer une commande qu'une fois les produits expédiés. ConfirmCloseOrderIfSending=Êtes-vous sur de vouloir cloturer cette commande ? Vous ne devez cloturer une commande qu'une fois les produits expédiés.
ConfirmDeleteOrder=Êtes-vous sur de vouloir effacer cette commande ? ConfirmDeleteOrder=Êtes-vous sur de vouloir effacer cette commande ?
ConfirmValidateOrder=Êtes-vous sur de vouloir valider cette commande sous la référence <b>%s</b> ? ConfirmValidateOrder=Êtes-vous sur de vouloir valider cette commande sous la référence <b>%s</b> ?

View File

@ -103,7 +103,7 @@ MultiPriceLevelsName=Cat
AssociatedProductsAbility=Prise en charges des produits associés AssociatedProductsAbility=Prise en charges des produits associés
AssociatedProducts=Produits associés AssociatedProducts=Produits associés
AssociatedProductsNumber=Nbre de produits associés AssociatedProductsNumber=Nbre de produits associés
EditAssociate=Associer au EditAssociate=Associer
Translation=Traduction Translation=Traduction
KeywordFilter=Filtre par mot-clé KeywordFilter=Filtre par mot-clé
CategoryFilter=Filtre par catégorie CategoryFilter=Filtre par catégorie

View File

@ -35,3 +35,6 @@ Carriers=Transporteurs
Carrier=Transporteur Carrier=Transporteur
CarriersArea=Espace transporteurs CarriersArea=Espace transporteurs
NewCarrier=Nouveau transporteur NewCarrier=Nouveau transporteur
ConfirmDeleteSending=Etes-vous sûr de vouloir supprimer cette expedition ?
ConfirmValidateSending=Etes-vous sûr de vouloir valider cette expédition ?
ConfirmCancelSending=Etes-vous sûr de vouloir annuler cette expédition ?

View File

@ -38,7 +38,8 @@ EnhancedValueOfWarehouses=Valorisation des stocks
UserWarehouseAutoCreate=Créer un stock automatiquement à la création d'un utilisateur UserWarehouseAutoCreate=Créer un stock automatiquement à la création d'un utilisateur
QtyDispatched=Quantité ventilée QtyDispatched=Quantité ventilée
OrderDispatch=Ventilation commande OrderDispatch=Ventilation commande
RuleForStockManagement=Règle de gestion de stock RuleForStockManagementDecrease=Règle de gestion des décrémentations de stock
RuleForStockManagementIncrease=Règle de gestion des incrémentations de stock
DeStockReStockOnBill=Décrémente/Incrémente les stocks physiques sur les factures/avoirs (attention, dans cette version, c'est toujours dans le premier entrepot numero 1 que se fait l'ajustement) DeStockReStockOnBill=Décrémente/Incrémente les stocks physiques sur les factures/avoirs (attention, dans cette version, c'est toujours dans le premier entrepot numero 1 que se fait l'ajustement)
DeStockReStockOnValidateOrder=Décrémente/Incrémente les stocks physiques sur les commandes (attention, dans cette version, c'est toujours dans le premier entrepot numero 1 que se fait l'ajustement) DeStockReStockOnValidateOrder=Décrémente/Incrémente les stocks physiques sur les commandes (attention, dans cette version, c'est toujours dans le premier entrepot numero 1 que se fait l'ajustement)
DeStockReStockOnShipment=Décrémente/Incrémente les stocks physiques sur les expéditions (recommandé) DeStockReStockOnShipment=Décrémente/Incrémente les stocks physiques sur les expéditions (recommandé)

View File

@ -38,7 +38,7 @@ EnhancedValueOfWarehouses =Valore magazzini
UserWarehouseAutoCreate =Creare uno stock automaticamente durante la creazione di un utente UserWarehouseAutoCreate =Creare uno stock automaticamente durante la creazione di un utente
QtyDispatched =Quantità spedita QtyDispatched =Quantità spedita
OrderDispatch =Spedizione dell'ordine OrderDispatch =Spedizione dell'ordine
RuleForStockManagement =Regola per gestione delle scorte RuleForStockManagementDecrease =Regola per gestione delle scorte
DeStockReStockOnBill =Diminuzione / aumento reale delle scorte sulle fatture / note di credito (attenzione, in questa versione, è solo nel magazzino numero 1 che viene modificata) DeStockReStockOnBill =Diminuzione / aumento reale delle scorte sulle fatture / note di credito (attenzione, in questa versione, è solo nel magazzino numero 1 che viene modificata)
DeStockReStockOnValidateOrder =Diminuzione / aumento reale delle scorte per ordini note (avviso, in questa versione, è solo nel magazzino numero 1 che viene modificata) DeStockReStockOnValidateOrder =Diminuzione / aumento reale delle scorte per ordini note (avviso, in questa versione, è solo nel magazzino numero 1 che viene modificata)
DeStockReStockOnShipment =Diminuzione / aumento reale delle scorte sulla spedizione (Raccomandato) DeStockReStockOnShipment =Diminuzione / aumento reale delle scorte sulla spedizione (Raccomandato)

View File

@ -1099,7 +1099,7 @@ class Product extends CommonObject
/** /**
* \brief Charge tableau des stats commande client pour le produit/service * \brief Charge tableau des stats commande client pour le produit/service
* \param socid Id societe pour filtrer sur une soci<EFBFBD>t<EFBFBD> * \param socid Id societe pour filtrer sur une societe
* \param filtrestatut Id statut pour filtrer sur un statut * \param filtrestatut Id statut pour filtrer sur un statut
* \return array Tableau des stats * \return array Tableau des stats
*/ */
@ -1184,6 +1184,50 @@ class Product extends CommonObject
} }
} }
/**
* \brief Charge tableau des stats expedition client pour le produit/service
* \param socid Id societe pour filtrer sur une societe
* \param filtrestatut Id statut pour filtrer sur un statut
* \return array Tableau des stats
*/
function load_stats_sending($socid=0,$filtrestatut='')
{
global $conf,$user;
$sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
$sql.= " COUNT(ed.rowid) as nb_rows, SUM(ed.qty) as qty";
$sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd,";
$sql.= " ".MAIN_DB_PREFIX."expedition as c";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.rowid = ed.fk_expedition AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ".$this->id;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid > 0)
{
$sql.= " AND c.fk_soc = ".$socid;
}
if ($filtrestatut <> '')
{
$sql.= " AND c.fk_statut in (".$filtrestatut.")";
}
$result = $this->db->query($sql) ;
if ( $result )
{
$obj=$this->db->fetch_object($result);
$this->stats_expedition['customers']=$obj->nb_customers;
$this->stats_expedition['nb']=$obj->nb;
$this->stats_expedition['rows']=$obj->nb_rows;
$this->stats_expedition['qty']=$obj->qty?$obj->qty:0;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/** /**
* \brief Charge tableau des stats contrat pour le produit/service * \brief Charge tableau des stats contrat pour le produit/service
* \param socid Id societe * \param socid Id societe
@ -1810,29 +1854,55 @@ class Product extends CommonObject
$db->commit(); $db->commit();
return 1; return 1;
} }
/** /**
* \brief fonction r<EFBFBD>cursive uniquement utilis<EFBFBD>e par get_arbo_each_prod, recompose l'arborescence des sousproduits * \brief fonction recursive uniquement utilisee par get_arbo_each_prod, recompose l'arborescence des sousproduits
* \return void * \return void
*/ */
function fetch_prod_arbo($prod,$compl_path="") function fetch_prod_arbo($prod,$compl_path="",$multiply="")
{ {
global $langs;
$this->res; $this->res;
$this->pere_encours; $this->pere_encours;
foreach($prod as $nom_pere => $desc_pere) foreach($prod as $nom_pere => $desc_pere)
{ {
// on est dans une sous-cat<EFBFBD>gorie // on est dans une sous-categorie
if(is_array($desc_pere)) if(is_array($desc_pere))
$this->res[]= array($compl_path.stripslashes($nom_pere)." (".$desc_pere[1].")",$desc_pere[0]); {
if($multiply)
{
$img="";
$trueValue=$desc_pere[1]*$multiply;
$product = new Product($this->db);
$this->fetch($desc_pere[0]);
$this->load_stock();
if ($this->stock_entrepot[1] < $this->seuil_stock_alerte)
{
$img=img_warning($langs->trans("StockTooLow"));
}
$this->res[]= array("<tr><td>&nbsp; &nbsp; &nbsp;
<a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$desc_pere[0]."\">".$compl_path.stripslashes($nom_pere)."
</a></td><td align=\"center\"> ".$trueValue."</td><td>&nbsp</td></td><td>&nbsp</td>
</td><td align=\"center\">".$this->stock_entrepot[1]." ".$img."</td></tr>",
$desc_pere[0]);
}
else
{
$this->res[]= array($compl_path.$nom_pere." (".$desc_pere[1].")",$desc_pere[0]);
}
}
else if($nom_pere != "0" && $nom_pere != "1") else if($nom_pere != "0" && $nom_pere != "1")
$this->res[]= array($compl_path.stripslashes($nom_pere),$desc_pere); $this->res[]= array($compl_path.$nom_pere,$desc_pere);
if(sizeof($desc_pere) >1) if(sizeof($desc_pere) >1)
{ {
$this ->fetch_prod_arbo($desc_pere,stripslashes($nom_pere)." -> "); $this ->fetch_prod_arbo($desc_pere,$nom_pere." -> ");
} }
} }
} }
/** /**
* \brief fonction r<EFBFBD>cursive uniquement utilis<EFBFBD>e par get_each_prod, ajoute chaque sousproduits dans le tableau res * \brief fonction recursive uniquement utilisee par get_each_prod, ajoute chaque sousproduits dans le tableau res
* \return void * \return void
*/ */
function fetch_prods($prod) function fetch_prods($prod)
@ -1840,7 +1910,7 @@ class Product extends CommonObject
$this->res; $this->res;
foreach($prod as $nom_pere => $desc_pere) foreach($prod as $nom_pere => $desc_pere)
{ {
// on est dans une sous-cat<EFBFBD>gorie // on est dans une sous-categorie
if(is_array($desc_pere)) if(is_array($desc_pere))
$this->res[]= array($desc_pere[1],$desc_pere[0]); $this->res[]= array($desc_pere[1],$desc_pere[0]);
if(sizeof($desc_pere) >1) if(sizeof($desc_pere) >1)
@ -1849,11 +1919,12 @@ class Product extends CommonObject
} }
} }
} }
/** /**
* \brief reconstruit l'arborescence des cat<EFBFBD>gorie sous la forme d'un tableau * \brief reconstruit l'arborescence des categorie sous la forme d'un tableau
* \return array $this->res * \return array $this->res
*/ */
function get_arbo_each_prod() function get_arbo_each_prod($multiply="")
{ {
$this->res = array(); $this->res = array();
if(is_array($this -> sousprods)) if(is_array($this -> sousprods))
@ -1861,13 +1932,13 @@ class Product extends CommonObject
foreach($this -> sousprods as $nom_pere => $desc_pere) foreach($this -> sousprods as $nom_pere => $desc_pere)
{ {
if(sizeof($desc_pere) >1) if(sizeof($desc_pere) >1)
$this ->fetch_prod_arbo($desc_pere); $this ->fetch_prod_arbo($desc_pere,"",$multiply);
} }
sort($this->res); sort($this->res);
} }
return $this->res; return $this->res;
} }
/** /**
* \brief renvoie tous les sousproduits dans le tableau res, chaque ligne de res contient : id -> qty * \brief renvoie tous les sousproduits dans le tableau res, chaque ligne de res contient : id -> qty
* \return array $this->res * \return array $this->res

View File

@ -44,13 +44,13 @@ $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
$cancel=isset($_GET["cancel"])?$_GET["cancel"]:$_POST["cancel"]; $cancel=isset($_GET["cancel"])?$_GET["cancel"]:$_POST["cancel"];
if ($action <> 're-edit') if ($action <> 're-edit')
{ {
$product = new Product($db); $product = new Product($db);
if ($id) $result = $product->fetch($id); if ($id) $result = $product->fetch($id);
if ($ref) $result = $product->fetch($ref); if ($ref) $result = $product->fetch($ref);
if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]);
if ($_GET["id"]) $result = $product->fetch($_GET["id"]); if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
} }
if (!$user->rights->produit->lire) accessforbidden(); if (!$user->rights->produit->lire) accessforbidden();
@ -59,8 +59,8 @@ $html = new Form($db);
// Action association d'un sousproduit // Action association d'un sousproduit
if ($action == 'add_prod' && if ($action == 'add_prod' &&
$cancel <> $langs->trans("Cancel") && $cancel <> $langs->trans("Cancel") &&
$user->rights->produit->creer) $user->rights->produit->creer)
{ {
for($i=0;$i<$_POST["max_prod"];$i++) for($i=0;$i<$_POST["max_prod"];$i++)
@ -131,6 +131,12 @@ if ($cancel == $langs->trans("Cancel"))
llxHeader("","",$langs->trans("CardProduct".$product->type)); llxHeader("","",$langs->trans("CardProduct".$product->type));
$html = new Form($db); $html = new Form($db);
$productstatic = new Product($db);
if ($mesg) {
print '<br><div class="error">'.$mesg.'</div><br>';
}
$head=product_prepare_head($product, $user); $head=product_prepare_head($product, $user);
$titre=$langs->trans("CardProduct".$product->type); $titre=$langs->trans("CardProduct".$product->type);
dolibarr_fiche_head($head, 'subproduct', $titre); dolibarr_fiche_head($head, 'subproduct', $titre);
@ -141,6 +147,7 @@ dolibarr_fiche_head($head, 'subproduct', $titre);
if ($id || $ref) if ($id || $ref)
{ {
if ( $result ) if ( $result )
{ {
@ -150,8 +157,6 @@ if ($id || $ref)
* En mode visu * En mode visu
*/ */
print($mesg);
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print "<tr>"; print "<tr>";
@ -161,7 +166,7 @@ if ($id || $ref)
if ($product->isservice()) $nblignes++; if ($product->isservice()) $nblignes++;
// Reference // Reference
print '<td width="15%">'.$langs->trans("Ref").'</td><td>'; print '<td width="25%">'.$langs->trans("Ref").'</td><td>';
print $html->showrefnav($product,'ref','',1,'ref'); print $html->showrefnav($product,'ref','',1,'ref');
print '</td></tr>'; print '</td></tr>';
@ -180,7 +185,10 @@ if ($id || $ref)
print '<b>'.$langs->trans("ProductAssociationList").'</b><br>'; print '<b>'.$langs->trans("ProductAssociationList").'</b><br>';
foreach($prods_arbo as $key => $value) foreach($prods_arbo as $key => $value)
{ {
print '- <a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$value[1].'">'.$value[0].'</a><br>'; $productstatic->id=$value[1];
$productstatic->type=0;
$productstatic->ref=$value[0];
print $productstatic->getNomUrl(1).'<br>';
} }
@ -198,17 +206,6 @@ if ($id || $ref)
*/ */
if (($action == 'edit' || $action == 'search' || $action == 're-edit') && $user->rights->produit->creer) if (($action == 'edit' || $action == 'search' || $action == 're-edit') && $user->rights->produit->creer)
{ {
if ($product->isservice()) {
print_fiche_titre($langs->trans('EditAssociate').' '.$langs->trans('Service').' : '.$product->ref, "");
} else {
print_fiche_titre($langs->trans('EditAssociate').' '.$langs->trans('Product').' : '.$product->ref, "");
}
if ($mesg) {
print '<br><div class="error">'.$mesg.'</div><br>';
}
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print "<tr>"; print "<tr>";
@ -218,9 +215,9 @@ if ($id || $ref)
if ($product->isservice()) $nblignes++; if ($product->isservice()) $nblignes++;
// Reference // Reference
print '<td width="15%">'.$langs->trans("Ref").'</td><td>'; print '<td width="25%">'.$langs->trans("Ref").'</td><td>';
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'">'.$product->ref.'</a>'; print $html->showrefnav($product,'ref','',1,'ref');
print '</td>'; print '</td></tr>';
if ($product->is_photo_available($conf->produit->dir_output)) if ($product->is_photo_available($conf->produit->dir_output))
{ {
@ -235,7 +232,7 @@ if ($id || $ref)
// Libelle // Libelle
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>'; print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
print '</tr>'; print '</tr>';
// Nombre de sousproduits associ<63>s // Nombre de sousproduits associes
$product->get_sousproduits_arbo (); $product->get_sousproduits_arbo ();
print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>'.sizeof($product->get_arbo_each_prod()).'</td>'; print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>'.sizeof($product->get_arbo_each_prod()).'</td>';
print '</tr>'; print '</tr>';
@ -279,7 +276,8 @@ if ($id || $ref)
{ {
// check if a product is not already a parent product of this one // check if a product is not already a parent product of this one
$prod_arbo=new Product($db,$objp->rowid); $prod_arbo=new Product($db,$objp->rowid);
if ($prod_arbo->type==2 || $prod_arbo->type==3) { if ($prod_arbo->type==2 || $prod_arbo->type==3)
{
$is_pere=0; $is_pere=0;
$prod_arbo->get_sousproduits_arbo (); $prod_arbo->get_sousproduits_arbo ();
// associations sousproduits // associations sousproduits
@ -349,7 +347,7 @@ if ($action == '')
if ( $user->rights->produit->creer) if ( $user->rights->produit->creer)
{ {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/sousproduits/fiche.php?action=edit&amp;id='.$product->id.'">'.$langs->trans("Modify").'</a>'; print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/sousproduits/fiche.php?action=edit&amp;id='.$product->id.'">'.$langs->trans("EditAssociate").'</a>';
} }

View File

@ -25,13 +25,13 @@
\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$
*/ */
/** /**
\class MouvementStock \class MouvementStock
\brief Classe permettant la gestion des mouvements de stocks \brief Classe permettant la gestion des mouvements de stocks
*/ */
class MouvementStock class MouvementStock
{ {
@ -42,8 +42,9 @@ class MouvementStock
} }
/** /**
* \brief Crée un mouvement en base * \brief Add a mouvement in stock (in one direction only)
* \return int <0 si ko, >0 si ok * \param type Direction of movement: 2=output (stock decrease), 3=input (stock increase)
* \return int <0 if KO, >0 if OK
*/ */
function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0) function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0)
{ {
@ -52,11 +53,16 @@ class MouvementStock
$this->db->begin(); $this->db->begin();
// $nbOfSubproduct=$this->nbOfSubProdcuts();
if (1 == 1) // Always change stock for current product
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement";
$sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, price)"; $sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, price)";
$sql.= " VALUES (".$this->db->idate(mktime()).", ".$fk_product.", ".$entrepot_id.", ".$qty.", ".$type.", ".$user->id; $sql.= " VALUES (".$this->db->idate(mktime()).", ".$fk_product.", ".$entrepot_id.", ".$qty.", ".$type.", ".$user->id;
$sql.= ",'".price2num($price)."')"; $sql.= ",'".price2num($price)."')";
dolibarr_syslog("MouvementStock::_create sql=".$sql, LOG_DEBUG);
if ($resql = $this->db->query($sql)) if ($resql = $this->db->query($sql))
{ {
$mvid = $this->db->last_insert_id($resql); $mvid = $this->db->last_insert_id($resql);
@ -67,9 +73,9 @@ class MouvementStock
$error = -1; $error = -1;
} }
// Get current value of stock
$num = 0; $num = 0;
if ($error == 0)
if ($error === 0)
{ {
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_stock"; $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_stock";
$sql.= " WHERE fk_entrepot = ".$entrepot_id." AND fk_product = ".$fk_product; $sql.= " WHERE fk_entrepot = ".$entrepot_id." AND fk_product = ".$fk_product;
@ -86,7 +92,8 @@ class MouvementStock
} }
} }
if ($error === 0) // Update value
if ($error == 0)
{ {
if ($num > 0) if ($num > 0)
{ {
@ -100,6 +107,7 @@ class MouvementStock
$sql.= " (".$qty.",".$entrepot_id.",".$fk_product.")"; $sql.= " (".$qty.",".$entrepot_id.",".$fk_product.")";
} }
dolibarr_syslog("MouvementStock::_create sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
@ -111,23 +119,22 @@ class MouvementStock
} }
} }
if ($error === 0) if ($error == 0)
{ {
$valo_mouvement = 0; $valo_mouvement = 0;
$error = $this->CalculateValoPmp($mvid, $fk_product, $qty, $price, $valo_mouvement); $error = $this->CalculateValoPmp($mvid, $fk_product, $qty, $price, $valo_mouvement);
} }
if ($error === 0) if ($error == 0)
{ {
$error = $this->CalculateEntrepotValoPmp($user, $entrepot_id, $valo_mouvement); $error = $this->CalculateEntrepotValoPmp($user, $entrepot_id, $valo_mouvement);
} }
if ($error === 0)
{
$error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, $price=0);
} }
if ($error === 0) // Add movement for sub products
$error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, $price=0);
if ($error == 0)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
@ -146,32 +153,35 @@ class MouvementStock
* \brief Crée un mouvement en base pour tous les sous-produits * \brief Crée un mouvement en base pour tous les sous-produits
* \return int <0 si ko, 0 si ok * \return int <0 si ko, 0 si ok
*/ */
function _createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, $price=0) function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=0)
{ {
$error = 0; $error = 0;
dolibarr_syslog("MouvementStock::_CreateSubProduct $user->id, $fk_product, $entrepot_id, $qty, $type, $price");
$pids = array(); $pids = array();
$sql = "SELECT fk_product_subproduct FROM ".MAIN_DB_PREFIX."product_subproduct"; $sql = "SELECT fk_product_pere, fk_product_fils, qty";
$sql.= " WHERE fk_product = $fk_product;"; $sql.= " FROM ".MAIN_DB_PREFIX."product_association";
$sql.= " WHERE fk_product_pere = ".$idProduct;
if ($this->db->query($sql)) dolibarr_syslog("MouvementStock::_createSubProduct sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{ {
while ($row = $this->db->fetch_row($resql) ) while ($obj=$this->db->fetch_object($resql))
{ {
array_push($row[0]); $pids[]=$obj->fk_product_fils;
} }
$this->db->free($resql); $this->db->free($resql);
} }
else else
{ {
dolibarr_syslog("MouvementStock::_Create echec update ".$this->error); dolibarr_syslog("MouvementStock::_createSubProduct echec update ".$this->error, LOG_ERROR);
$error = -2; $error = -2;
} }
// Create movement for each subproduct
foreach($pids as $pid) foreach($pids as $pid)
{ {
$this->_create($user, $pid, $entrepot_id, $qty, $type, $price=0); $this->_create($user, $pid, $entrepot_id, $qty, $type, $price);
} }
return $error; return $error;
@ -387,8 +397,8 @@ class MouvementStock
} }
/* /**
* * \brief Decrease stock for product and subproducts
* *
*/ */
function livraison($user, $fk_product, $entrepot_id, $qty) function livraison($user, $fk_product, $entrepot_id, $qty)
@ -397,8 +407,8 @@ class MouvementStock
} }
/* /**
* * \brief Increase stock for product and subproducts
* *
*/ */
function reception($user, $fk_product, $entrepot_id, $qty, $price=0) function reception($user, $fk_product, $entrepot_id, $qty, $price=0)
@ -406,5 +416,27 @@ class MouvementStock
return $this->_create($user, $fk_product, $entrepot_id, $qty, 3, $price); return $this->_create($user, $fk_product, $entrepot_id, $qty, 3, $price);
} }
/**
* Return nb of subproducts for a product
*
* @param unknown_type $id
* @return unknown
*/
function nbOfSubProdcuts($id)
{
$nbSP=0;
$resql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."product_association";
$resql.= " WHERE fk_product_pere = ".$id;
if ($this->db->query($resql))
{
$obj=$this->db->fetch_object($resql);
$nbSP=$obj->nb;
}
$this->db->free($resql);
return $nbSP;
}
} }
?> ?>

View File

@ -147,15 +147,14 @@ if ($_GET["id"] || $_GET["ref"])
print '<td>'.$product->stock_reel.'</td>'; print '<td>'.$product->stock_reel.'</td>';
print '</tr>'; print '</tr>';
// Calculating a theorical value of stock if stock increment is done on real sending
// Calculating a theorical value of stock if stock increment is done on order if ($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
if ($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)
{ {
$stock_commande_client=$stock_commande_fournisseur=0; $stock_commande_client=$stock_commande_fournisseur=0;
if ($conf->commande->enabled) if ($conf->commande->enabled)
{ {
$result=$product->load_stats_commande(0,'2'); $result=$product->load_stats_commande(0,'1,2');
if ($result < 0) dolibarr_print_error($db,$product->error); if ($result < 0) dolibarr_print_error($db,$product->error);
$stock_commande_client=$product->stats_commande['qty']; $stock_commande_client=$product->stats_commande['qty'];
} }
@ -166,7 +165,7 @@ if ($_GET["id"] || $_GET["ref"])
$stock_commande_fournisseur=$product->stats_commande_fournisseur['qty']; $stock_commande_fournisseur=$product->stats_commande_fournisseur['qty'];
} }
$product->stock_theorique=$product->stock_reel-$stock_commande_client+$stock_commande_fournisseur; $product->stock_theorique=$product->stock_reel-($stock_commande_client+$stock_sending_client)+$stock_commande_fournisseur;
// Stock theorique // Stock theorique
print '<tr><td>'.$langs->trans("VirtualStock").'</td>'; print '<tr><td>'.$langs->trans("VirtualStock").'</td>';
@ -190,10 +189,12 @@ if ($_GET["id"] || $_GET["ref"])
if ($conf->commande->enabled) if ($conf->commande->enabled)
{ {
if ($found) print '<br>'; else $found=1; if ($found) print '<br>'; else $found=1;
print $langs->trans("CustomersOrdersRunning").': '.$stock_commande_client; print $langs->trans("CustomersOrdersRunning").': '.($stock_commande_client+$stock_sending_client);
$result=$product->load_stats_commande(0,'0,1'); $result=$product->load_stats_commande(0,'0');
if ($result < 0) dolibarr_print_error($db,$product->error); if ($result < 0) dolibarr_print_error($db,$product->error);
print ' ('.$langs->trans("DraftOrWaitingShipped").': '.$product->stats_commande['qty'].')'; print ' ('.$langs->trans("Draft").': '.$product->stats_commande['qty'].')';
//print '<br>';
//print $langs->trans("CustomersSendingRunning").': '.$stock_sending_client;
} }
// Nbre de commande fournisseurs en cours // Nbre de commande fournisseurs en cours