diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang
index f46307a21ae..62f028b45e4 100644
--- a/htdocs/langs/en_US/errors.lang
+++ b/htdocs/langs/en_US/errors.lang
@@ -240,6 +240,8 @@ ErrorBatchNoFoundEnoughQuantityForProductInWarehouse=No enough quantity for this
ErrorOnlyOneFieldForGroupByIsPossible=Only 1 field for the 'Group by' is possible (others are discarded)
ErrorTooManyDifferentValueForSelectedGroupBy=Found too many different value (more than %s) for the field '%s', so we can't use it as a 'Group by' for graphics. The field 'Group By' has been removed. May be you wanted to use it as an X-Axis ?
ErrorReplaceStringEmpty=Error, the string to replace into is empty
+ErrorProductNeedBatchNumber=Error, product '%s' need a lot/serial number
+ErrorProductDoesNotNeedBatchNumber=Error, product '%s' does not accept a lot/serial number
# Warnings
WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup.
WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user.
diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang
index 4098024f651..ce128bc5c91 100644
--- a/htdocs/langs/en_US/stocks.lang
+++ b/htdocs/langs/en_US/stocks.lang
@@ -237,4 +237,6 @@ AlwaysShowFullArbo=Display full tree of warehouse on popup of warehouse links (W
StockAtDatePastDesc=You can view here the stock (real stock) at a given date in the past
StockAtDateFutureDesc=You can view here the stock (virtual stock) at a given date in future
CurrentStock=Current stock
-InventoryRealQtyHelp=Set value to 0 to reset qty
Keep field empty, or remove line, to keep unchanged
\ No newline at end of file
+InventoryRealQtyHelp=Set value to 0 to reset qty
Keep field empty, or remove line, to keep unchanged
+UpdateByScaningProductBarcode=Update by scaning product barcode
+UpdateByScaningLot=Update by scaning lot
diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php
index eedafd5497d..5a5435b1b5f 100644
--- a/htdocs/product/inventory/class/inventory.class.php
+++ b/htdocs/product/inventory/class/inventory.class.php
@@ -49,6 +49,11 @@ class Inventory extends CommonObject
*/
public $ismultientitymanaged = 1;
+ /**
+ * @var int Does object support extrafields ? 0=No, 1=Yes
+ */
+ public $isextrafieldmanaged = 1;
+
/**
* @var string String with name of icon for inventory
*/
@@ -246,7 +251,16 @@ class Inventory extends CommonObject
$result = 0;
- if ($result >= 0) {
+ if ($this->status == self::STATUS_DRAFT) {
+ // Delete inventory
+ $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'inventorydet WHERE fk_inventory = '.$this->id;
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $this->error = $this->db->lasterror();
+ $this->db->rollback();
+ return -1;
+ }
+
// Scan existing stock to prefill the inventory
$sql = 'SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,';
$sql .= ' pb.batch, pb.qty';
@@ -256,8 +270,8 @@ class Inventory extends CommonObject
$sql .= ' WHERE p.entity IN ('.getEntity('product').')';
$sql .= ' AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid';
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql .= " AND p.fk_product_type = 0";
- if ($object->fk_product > 0) $sql .= ' AND ps.fk_product = '.$object->fk_product;
- if ($object->fk_warehouse > 0) $sql .= ' AND ps.fk_entrepot = '.$object->fk_warehouse;
+ if ($this->fk_product > 0) $sql .= ' AND ps.fk_product = '.$this->fk_product;
+ if ($this->fk_warehouse > 0) $sql .= ' AND ps.fk_entrepot = '.$this->fk_warehouse;
$inventoryline = new InventoryLine($this->db);
@@ -316,6 +330,15 @@ class Inventory extends CommonObject
{
$this->db->begin();
+ // Delete inventory
+ $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'inventorydet WHERE fk_inventory = '.$this->id;
+ $resql = $this->db->query($sql);
+ if (!$resql) {
+ $this->error = $this->db->lasterror();
+ $this->db->rollback();
+ return -1;
+ }
+
$result = $this->setStatut($this::STATUS_DRAFT, null, '', 'INVENTORY_DRAFT');
if ($result > 0) {
@@ -428,6 +451,25 @@ class Inventory extends CommonObject
return $this->deleteCommon($user, $notrigger);
}
+ /**
+ * Delete a line of object in database
+ *
+ * @param User $user User that delete
+ * @param int $idline Id of line to delete
+ * @param bool $notrigger false=launch triggers after, true=disable triggers
+ * @return int >0 if OK, <0 if KO
+ */
+ public function deleteLine(User $user, $idline, $notrigger = false)
+ {
+ if ($this->status < 0)
+ {
+ $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
+ return -2;
+ }
+
+ return $this->deleteLineCommon($user, $idline, $notrigger);
+ }
+
/**
* Return a link to the object card (with optionaly the picto)
*
@@ -598,6 +640,11 @@ class InventoryLine extends CommonObjectLine
*/
public $ismultientitymanaged = 0;
+ /**
+ * @var int Does object support extrafields ? 0=No, 1=Yes
+ */
+ public $isextrafieldmanaged = 0;
+
/**
* @var string String with name of icon for inventory
*/
diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php
index 0d91546ad56..2105435badf 100644
--- a/htdocs/product/inventory/inventory.php
+++ b/htdocs/product/inventory/inventory.php
@@ -23,11 +23,13 @@
require '../../main.inc.php';
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
+include_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
+include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
include_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
include_once DOL_DOCUMENT_ROOT.'/product/inventory/lib/inventory.lib.php';
// Load translation files required by the page
-$langs->loadLangs(array("stocks", "other"));
+$langs->loadLangs(array("stocks", "other", "productbatch"));
// Get parameters
$id = GETPOST('id', 'int');
@@ -38,6 +40,11 @@ $cancel = GETPOST('cancel', 'aZ09');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
+$fk_warehouse = GETPOST('fk_warehouse', 'int');
+$fk_product = GETPOST('fk_product', 'int');
+$lineid = GETPOST('lineid', 'int');
+$batch = GETPOST('batch', 'alphanohtml');
+
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS))
{
$result = restrictedArea($user, 'stock', $id);
@@ -83,6 +90,8 @@ if (empty($conf->global->MAIN_USE_ADVANCED_PERMS))
$permissiontodelete = $user->rights->stock->inventory_advance->write;
}
+$now = dol_now();
+
/*
* Actions
@@ -113,6 +122,45 @@ if (empty($reshook))
$autocopy='MAIN_MAIL_AUTOCOPY_MYOBJECT_TO';
$trackid='myobject'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';*/
+
+ if (GETPOST('addline', 'alpha')) {
+ if ($fk_warehouse <= 0) {
+ $error++;
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
+ }
+ if ($fk_product <= 0) {
+ $error++;
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
+ }
+ if (! $error) {
+ $tmpproduct = new Product($db);
+ $result = $tmpproduct->fetch($fk_product);
+
+ if (!$error && $tmpproduct->status_batch && !$batch) {
+ $error++;
+ $langs->load("errors");
+ setEventMessages($langs->trans("ErrorProductNeedBatchNumber", $tmpproduct->ref), null, 'errors');
+ }
+ if (!$error && !$tmpproduct->status_batch && $batch) {
+ $error++;
+ $langs->load("errors");
+ setEventMessages($langs->trans("ErrorProductDoesNotNeedBatchNumber", $tmpproduct->ref), null, 'errors');
+ }
+ }
+ if (! $error) {
+ $tmp = new InventoryLine($db);
+ $tmp->fk_inventory = $object->id;
+ $tmp->fk_warehouse = $fk_warehouse;
+ $tmp->fk_product = $fk_product;
+ $tmp->batch = $batch;
+ $tmp->datec = $now;
+
+ $result = $tmp->create($user);
+ if ($result < 0) {
+ dol_print_error($db, $tmp->error, $tmp->errors);
+ }
+ }
+ }
}
@@ -123,6 +171,7 @@ if (empty($reshook))
*/
$form = new Form($db);
+$formproduct = new FormProduct($db);
llxHeader('', $langs->trans('Inventory'), '');
@@ -264,6 +313,7 @@ if ($object->id > 0)
print '';
print '';
print '
';
+ print '';
} else {
print '