git push origin developMerge branch 'atm-alexis-develop_NEW_decrease_stock_expedition_classify' into develop

This commit is contained in:
Laurent Destailleur
2016-06-02 11:24:03 +02:00
9 changed files with 213 additions and 32 deletions

View File

@@ -52,14 +52,17 @@ if($action)
// Mode of stock decrease
if ($action == 'STOCK_CALCULATE_ON_BILL'
|| $action == 'STOCK_CALCULATE_ON_VALIDATE_ORDER'
|| $action == 'STOCK_CALCULATE_ON_SHIPMENT')
|| $action == 'STOCK_CALCULATE_ON_SHIPMENT'
|| $action == 'STOCK_CALCULATE_ON_SHIPMENT_CLOSE')
{
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_BILL", '','chaine',0,'',$conf->entity);
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_VALIDATE_ORDER", '','chaine',0,'',$conf->entity);
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SHIPMENT", '','chaine',0,'',$conf->entity);
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SHIPMENT_CLOSE", '','chaine',0,'',$conf->entity);
if ($action == 'STOCK_CALCULATE_ON_BILL') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_BILL", GETPOST('STOCK_CALCULATE_ON_BILL','alpha'),'chaine',0,'',$conf->entity);
if ($action == 'STOCK_CALCULATE_ON_VALIDATE_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_VALIDATE_ORDER", GETPOST('STOCK_CALCULATE_ON_VALIDATE_ORDER','alpha'),'chaine',0,'',$conf->entity);
if ($action == 'STOCK_CALCULATE_ON_SHIPMENT') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SHIPMENT", GETPOST('STOCK_CALCULATE_ON_SHIPMENT','alpha'),'chaine',0,'',$conf->entity);
if ($action == 'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SHIPMENT_CLOSE", GETPOST('STOCK_CALCULATE_ON_SHIPMENT_CLOSE','alpha'),'chaine',0,'',$conf->entity);
}
// Mode of stock increase
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL'
@@ -203,6 +206,26 @@ else
print "</td>\n</tr>\n";
$found++;
$var=!$var;
print "<tr ".$bc[$var].">";
print '<td width="60%">'.$langs->trans("DeStockOnShipmentOnClosing").'</td>';
print '<td width="160" align="right">';
if (! empty($conf->expedition->enabled))
{
print "<form method=\"post\" action=\"stock.php\">";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print "<input type=\"hidden\" name=\"action\" value=\"STOCK_CALCULATE_ON_SHIPMENT_CLOSE\">";
print $form->selectyesno("STOCK_CALCULATE_ON_SHIPMENT_CLOSE",$conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE,1,$disabled);
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"'.$disabled.'>';
print "</form>\n";
}
else
{
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name"));
}
print "</td>\n</tr>\n";
$found++;
/*if (! $found)
{
$var=!$var;

View File

@@ -745,7 +745,7 @@ if ($resql)
// stock order and stock order_supplier
$stock_order=0;
$stock_order_supplier=0;
if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) // What about other options ?
if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) // What about other options ?
{
if (! empty($conf->commande->enabled))
{

View File

@@ -405,6 +405,7 @@ class Conf
$this->global->STOCK_CALCULATE_ON_BILL=0;
$this->global->STOCK_CALCULATE_ON_VALIDATE_ORDER=0;
$this->global->STOCK_CALCULATE_ON_SHIPMENT=1;
$this->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE=0;
$this->global->STOCK_CALCULATE_ON_SUPPLIER_BILL=0;
$this->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER=0;
$this->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER=1;

View File

@@ -1800,6 +1800,7 @@ class Expedition extends CommonObject
*/
function setClosed()
{
global $conf,$langs,$user;
$error=0;
@@ -1813,28 +1814,104 @@ class Expedition extends CommonObject
{
// TODO: Add option/checkbox to set order billed if 100% of order is shipped
$this->statut=2;
// Call trigger
$result=$this->call_trigger('SHIPPING_CLOSED',$user);
if ($result < 0) {
$error++;
// If stock increment is done on closing
if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
{
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
$langs->load("agenda");
// Loop on each product line to add a stock movement
// TODO possibilite d'expedier a partir d'une propale ou autre origine
$sql = "SELECT cd.fk_product, cd.subprice,";
$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
$sql.= " WHERE ed.fk_expedition = ".$this->id;
$sql.= " AND cd.rowid = ed.fk_origin_line";
dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$cpt = $this->db->num_rows($resql);
for ($i = 0; $i < $cpt; $i++)
{
$obj = $this->db->fetch_object($resql);
if (empty($obj->edbrowid))
{
$qty = $obj->qty;
}
else
{
$qty = $obj->edbqty;
}
if ($qty <= 0) continue;
dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
$mouvS = new MouvementStock($this->db);
$mouvS->origin = &$this;
if (empty($obj->edbrowid))
{
// line without batch detail
// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr",$numref));
if ($result < 0) {
$this->error = $mouvS->error;
$this->errors = $mouvS->errors;
$error++; break;
}
}
else
{
// line with batch detail
// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr",$numref), '', $obj->eatby, $obj->sellby, $obj->batch, $obj->fk_origin_stock);
if ($result < 0) {
$this->error = $mouvS->error;
$this->errors = $mouvS->errors;
$error++; break;
}
}
}
}
else
{
$this->error=$this->db->lasterror();
$error++;
}
}
} else {
$error++;
$this->errors[]=$this->db->lasterror;
}
if (empty($error)) {
$this->db->commit();
return 1;
// Call trigger
if (! $error)
{
$result=$this->call_trigger('SHIPPING_CLOSED',$user);
if ($result < 0) {
$error++;
}
}
}
else
{
$this->db->rollback();
dol_print_error($this->db);
return -1;
$error++;
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -1;
}
}
@@ -1876,8 +1953,6 @@ class Expedition extends CommonObject
else
{
$this->db->rollback();
dol_print_error($this->db);
return -1;
}
}
@@ -1889,6 +1964,7 @@ class Expedition extends CommonObject
*/
function reOpen()
{
global $conf,$langs,$user;
$error=0;
@@ -1903,26 +1979,102 @@ class Expedition extends CommonObject
$this->statut=1;
$this->billed=0;
// Call trigger
$result=$this->call_trigger('SHIPPING_REOPEN',$user);
if ($result < 0) {
$error++;
// If stock increment is done on closing
if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
{
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
$langs->load("agenda");
// Loop on each product line to add a stock movement
// TODO possibilite d'expedier a partir d'une propale ou autre origine
$sql = "SELECT cd.fk_product, cd.subprice,";
$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
$sql.= " WHERE ed.fk_expedition = ".$this->id;
$sql.= " AND cd.rowid = ed.fk_origin_line";
dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$cpt = $this->db->num_rows($resql);
for ($i = 0; $i < $cpt; $i++)
{
$obj = $this->db->fetch_object($resql);
if (empty($obj->edbrowid))
{
$qty = $obj->qty;
}
else
{
$qty = $obj->edbqty;
}
if ($qty <= 0) continue;
dol_syslog(get_class($this)."::reopen expedition movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
//var_dump($this->lines[$i]);
$mouvS = new MouvementStock($this->db);
$mouvS->origin = &$this;
if (empty($obj->edbrowid))
{
// line without batch detail
// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr",$numref));
if ($result < 0) {
$this->error = $mouvS->error;
$this->errors = $mouvS->errors;
$error++; break;
}
}
else
{
// line with batch detail
// We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr",$numref), '', $obj->eatby, $obj->sellby, $obj->batch, $obj->fk_origin_stock);
if ($result < 0) {
$this->error = $mouvS->error;
$this->errors = $mouvS->errors;
$error++; break;
}
}
}
}
else
{
$this->error=$this->db->lasterror();
$error++;
}
}
if (! $error)
{
// Call trigger
$result=$this->call_trigger('SHIPPING_REOPEN',$user);
if ($result < 0) {
$error++;
}
}
} else {
$error++;
$this->errors[]=$this->db->lasterror;
$this->errors[]=$this->db->lasterror();
}
if (empty($error)) {
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
dol_print_error($this->db);
return -1;
}
}

View File

@@ -231,6 +231,8 @@ MemberResiliatedInDolibarr=Member %s resiliated
MemberDeletedInDolibarr=Member %s deleted
MemberSubscriptionAddedInDolibarr=Subscription for member %s added
ShipmentValidatedInDolibarr=Shipment %s validated
ShipmentClassifyClosedInDolibarr=Shipment %s classify billed
ShipmentUnClassifyCloseddInDolibarr=Shipment %s classify reopened
ShipmentDeletedInDolibarr=Shipment %s deleted
##### Export #####
Export=Export

View File

@@ -59,6 +59,7 @@ RuleForStockManagementIncrease=Rule for automatic stock management increase (man
DeStockOnBill=Decrease real stocks on customers invoices/credit notes validation
DeStockOnValidateOrder=Decrease real stocks on customers orders validation
DeStockOnShipment=Decrease real stocks on shipping validation
DeStockOnShipmentOnClosing=Decrease real stocks on shipping classification closed
ReStockOnBill=Increase real stocks on suppliers invoices/credit notes validation
ReStockOnValidateOrder=Increase real stocks on suppliers orders approbation
ReStockOnDispatchOrder=Increase real stocks on manual dispatching into warehouses, after supplier order receiving

View File

@@ -3477,7 +3477,7 @@ class Product extends CommonObject
}
// Stock decrease mode
if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) {
if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
$this->stock_theorique=$this->stock_reel-$stock_commande_client+$stock_sending_client;
}
if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)) {

View File

@@ -496,7 +496,7 @@ if ($id > 0 || $ref)
// Real stock
$text_stock_options = '';
$text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)?$langs->trans("DeStockOnShipment").'<br>':'');
$text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)?$langs->trans("DeStockOnShipment").'<br>':'');
$text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)?$langs->trans("DeStockOnValidateOrder").'<br>':'');
$text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_BILL)?$langs->trans("DeStockOnBill").'<br>':'');
$text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)?$langs->trans("ReStockOnBill").'<br>':'');

View File

@@ -71,7 +71,9 @@ if (!$sortorder) {
// Define virtualdiffersfromphysical
$virtualdiffersfromphysical=0;
if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER))
if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
|| ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
|| ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
{
$virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs.
}