New movement stock can be linked to project

This commit is contained in:
atm-ph 2017-01-29 13:04:06 +01:00
parent 10bacda820
commit 56d75c552d
5 changed files with 91 additions and 8 deletions

View File

@ -3518,20 +3518,26 @@ class Product extends CommonObject
* @param string $label Label of stock movement
* @param double $price Unit price HT of product, used to calculate average weighted price (PMP in french). If 0, average weighted price is not changed.
* @param string $inventorycode Inventory code
* @param string $origin_element Origin element type
* @param int $origin_id Origin id of element
* @return int <0 if KO, >0 if OK
*/
function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $inventorycode='')
function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $inventorycode='', $origin_element='', $origin_id=null)
{
if ($id_entrepot)
{
$this->db->begin();
require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
// If remove stock then save it the actual PMP as price (the new calculation of PMP is triggered only with $movement = 0 || 3 )
if ($movement == 1) $price = $this->pmp;
$op[0] = "+".trim($nbpiece);
$op[1] = "-".trim($nbpiece);
$movementstock=new MouvementStock($this->db);
$movementstock->setOrigin($origin_element, $origin_id);
$result=$movementstock->_create($user,$this->id,$id_entrepot,$op[$movement],$movement,$price,$label,$inventorycode);
if ($result >= 0)
@ -3563,9 +3569,11 @@ class Product extends CommonObject
* @param date $dluo sell-by date
* @param string $lot Lot number
* @param string $inventorycode Inventory code
* @param string $origin_element Origin element type
* @param int $origin_id Origin id of element
* @return int <0 if KO, >0 if OK
*/
function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $dlc='', $dluo='',$lot='', $inventorycode='')
function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $dlc='', $dluo='',$lot='', $inventorycode='', $origin_element='', $origin_id=null)
{
if ($id_entrepot)
{
@ -3573,10 +3581,14 @@ class Product extends CommonObject
require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
// If remove stock then save it the actual PMP as price (the new calculation of PMP is triggered only with $movement = 0 || 3 )
if ($movement == 1) $price = $this->pmp;
$op[0] = "+".trim($nbpiece);
$op[1] = "-".trim($nbpiece);
$movementstock=new MouvementStock($this->db);
$movementstock->setOrigin($origin_element, $origin_id);
$result=$movementstock->_create($user,$this->id,$id_entrepot,$op[$movement],$movement,$price,$label,$inventorycode,'',$dlc,$dluo,$lot);
if ($result >= 0)

View File

@ -893,6 +893,33 @@ class MouvementStock extends CommonObject
return '';
}
/**
* Set attribute origin to object
*
* @param string $origin_element
* @param int $origin_id
*
* @return void
*/
function setOrigin($origin_element, $origin_id)
{
if (!empty($origin_element) && $origin_id > 0)
{
$origin='';
if ($origin_element == 'project')
{
if (!class_exists('Project')) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
$origin = new Project($this->db);
}
if (!empty($origin))
{
$this->origin = $origin;
$this->origin->id = $origin_id;
}
}
}
/**

View File

@ -34,6 +34,11 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
if (! empty($conf->projet->enabled))
{
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
}
$langs->load("products");
$langs->load("stocks");
@ -156,6 +161,15 @@ if ($action == "correct_stock")
if (! $error)
{
$origin_element = '';
$origin_id = null;
if (GETPOST('projectid', 'int'))
{
$origin_element = 'project';
$origin_id = GETPOST('projectid', 'int');
}
if ($product->hasbatch())
{
$batch=GETPOST('batch_number');
@ -173,7 +187,9 @@ if ($action == "correct_stock")
GETPOST("label",'san_alpha'),
GETPOST('unitprice'),
$eatby,$sellby,$batch,
GETPOST('inventorycode')
GETPOST('inventorycode'),
$origin_element,
$origin_id
); // We do not change value of stock for a correction
}
else
@ -185,7 +201,9 @@ if ($action == "correct_stock")
GETPOST("mouvement"),
GETPOST("label",'san_alpha'),
GETPOST('unitprice'),
GETPOST('inventorycode')
GETPOST('inventorycode'),
$origin_element,
$origin_id
); // We do not change value of stock for a correction
}
@ -392,6 +410,7 @@ $userstatic=new User($db);
$form=new Form($db);
$formother=new FormOther($db);
$formproduct=new FormProduct($db);
if (!empty($conf->projet->enabled)) $formproject=new FormProjets($db);
$sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.fk_product_type as type, p.entity,";
$sql.= " e.label as stock, e.rowid as entrepot_id, e.lieu,";

View File

@ -37,6 +37,11 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productstockentrepot.class.php';
if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
if (! empty($conf->projet->enabled))
{
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
}
$langs->load("products");
$langs->load("orders");
@ -220,6 +225,15 @@ if ($action == "correct_stock" && ! $cancel)
$priceunit=price2num(GETPOST("unitprice"));
if (is_numeric(GETPOST("nbpiece")) && $id)
{
$origin_element = '';
$origin_id = null;
if (GETPOST('projectid', 'int'))
{
$origin_element = 'project';
$origin_id = GETPOST('projectid', 'int');
}
if (empty($object)) {
$object = new Product($db);
$result=$object->fetch($id);
@ -236,7 +250,9 @@ if ($action == "correct_stock" && ! $cancel)
$d_eatby,
$d_sellby,
$batchnumber,
GETPOST('inventorycode')
GETPOST('inventorycode'),
$origin_element,
$origin_id
); // We do not change value of stock for a correction
}
else
@ -248,7 +264,9 @@ if ($action == "correct_stock" && ! $cancel)
GETPOST("mouvement"),
GETPOST("label"),
$priceunit,
GETPOST('inventorycode')
GETPOST('inventorycode'),
$origin_element,
$origin_id
); // We do not change value of stock for a correction
}
@ -490,7 +508,7 @@ if ($action == 'updateline' && GETPOST('save') == $langs->trans('Save'))
$form = new Form($db);
$formproduct=new FormProduct($db);
if (! empty($conf->projet->enabled)) $formproject=new FormProjets($db);
if ($id > 0 || $ref)
{

View File

@ -77,7 +77,14 @@
// Purchase price
print '<tr>';
print '<td width="20%" colspan="2">'.$langs->trans("UnitPurchaseValue").'</td>';
print '<td colspan="4"><input class="flat" name="unitprice" id="unitprice" size="10" value="'.GETPOST("unitprice").'"></td>';
print '<td colspan="'.(!empty($conf->projet->enabled) ? '2' : '4').'"><input class="flat" name="unitprice" id="unitprice" size="10" value="'.GETPOST("unitprice").'"></td>';
if (! empty($conf->projet->enabled))
{
print '<td>'.$langs->trans('Project').'</td>';
print '<td>';
$formproject->select_projects();
print '</td>';
}
print '</tr>';
// Serial / Eat-by date