fix inclusion

This commit is contained in:
Alexis Algoud 2016-04-25 18:54:28 +02:00
parent bf1f805bf6
commit 91bea8b9fe
2 changed files with 87 additions and 4 deletions

View File

@ -1801,7 +1801,7 @@ class Expedition extends CommonObject
*/
function set_billed()
{
global $conf;
global $conf,$langs,$user;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2';
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
@ -1851,7 +1851,6 @@ class Expedition extends CommonObject
if ($qty <= 0) continue;
dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid);
//var_dump($this->lines[$i]);
$mouvS = new MouvementStock($this->db);
$mouvS->origin = &$this;
@ -1860,7 +1859,7 @@ class Expedition extends CommonObject
// 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("ShipmentValidatedInDolibarr",$numref));
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyBilledInDolibarr",$numref));
if ($result < 0) {
$error++; break;
}
@ -1909,7 +1908,7 @@ class Expedition extends CommonObject
*/
function reOpen()
{
global $conf;
global $conf,$langs,$user;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=1';
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0';
@ -1919,6 +1918,88 @@ class Expedition extends CommonObject
{
$this->statut=1;
$this->billed=0;
// If stock increment is done on sending (recommanded choice)
if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLASSIFY_BILLED))
{
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("ShipmentUnClassifyBilledInDolibarr",$numref));
if ($result < 0) {
$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("ShipmentValidatedInDolibarr",$numref), '', $obj->eatby, $obj->sellby, $obj->batch);
if ($result < 0) {
$error++; break;
}
// We update content of table llx_product_batch (will be rename into llx_product_stock_batch inantoher version)
// We can set livraison_batch to deprecated and adapt livraison to handle batch too (mouvS->_create also calls mouvS->_create_batch)
if (! empty($conf->productbatch->enabled))
{
$result=$mouvS->livraison_batch($obj->fk_origin_stock, -$qty); // ->fk_origin_stock = id into table llx_product_batch (will be rename into llx_product_stock_batch in another version)
if ($result < 0) { $error++; $this->errors[]=$mouvS->error; break; }
}
}
}
}
else
{
$this->db->rollback();
$this->error=$this->db->error();
return -2;
}
}
return 1;
}
else

View File

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