Work on inventory

This commit is contained in:
Laurent Destailleur 2020-08-17 16:04:12 +02:00
parent c3e3baaca0
commit bdcb945dda
4 changed files with 152 additions and 13 deletions

View File

@ -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 <b>%s</b>) for the field '<b>%s</b>', 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 '<b>%s</b>' need a lot/serial number
ErrorProductDoesNotNeedBatchNumber=Error, product '<b>%s</b>' 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.

View File

@ -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<br>Keep field empty, or remove line, to keep unchanged
InventoryRealQtyHelp=Set value to 0 to reset qty<br>Keep field empty, or remove line, to keep unchanged
UpdateByScaningProductBarcode=Update by scaning product barcode
UpdateByScaningLot=Update by scaning lot

View File

@ -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
*/

View File

@ -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 '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>';
print '<br>';
print '</form>';
} else {
print '<div class="tabsAction">'."\n";
$parameters = array();
@ -286,8 +336,10 @@ if ($object->id > 0)
{
if ($permissiontoadd)
{
//print '<a href="'.DOL_URL_ROOT.'/product/inventory/inventory.php?id='.$object->id.'&action=addline" class="butAction">'.$langs->trans("AddLine").'</a>';
if ($conf->barcode->enabled) {
print '<a href="#" class="butAction">'.$langs->trans("UpdateByScanningProductBarcode").'</a>';
print '<a href="#" class="butAction">'.$langs->trans("UpdateByScaningProductBarcode").'</a>';
}
if ($conf->productbatch->enabled) {
print '<a href="#" class="butAction">'.$langs->trans('UpdateByScaningLot').'</a>';
@ -324,6 +376,11 @@ if ($object->id > 0)
print '</div>'."\n";
}
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="updateinventorylines">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
if ($backtopage) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
print '<div class="fichecenter">';
//print '<div class="fichehalfleft">';
@ -351,6 +408,32 @@ if ($object->id > 0)
print '</td>';
print '</tr>';
// Line to add a new line in inventory
//if ($action == 'addline') {
if ($object->status == $object::STATUS_VALIDATED) {
print '<tr>';
print '<td>';
print $formproduct->selectWarehouses((GETPOSTISSET('fk_warehouse') ? GETPOST('fk_warehouse', 'int') : $object->fk_warehouse), 'fk_warehouse', 'warehouseopen', 1, 0, 0, '', 0, 0, array(), 'maxwidth300');
print '</td>';
print '<td>';
print $form->select_produits((GETPOSTISSET('fk_product') ? GETPOST('fk_product', 'int') : $object->fk_product), 'fk_product', '', 0, 0, 1, 2, '', 0, null, 0, '1', 0, 'maxwidth300');
print '</td>';
if ($conf->productbatch->enabled) {
print '<td>';
print '<input type="text" name="batch" class="maxwidth100" value="'.(GETPOSTISSET('batch') ? GETPOST('batch') : '').'">';
print '</td>';
}
print '<td class="right"></td>';
print '<td class="center">';
print '<input type="submit" class="button paddingrightonly" name="addline" value="'.$langs->trans("Add").'">';
//print '<input type="submit" class="button paddingrightonly" name="canceladdline" value="'.$langs->trans("Cancel").'">';
print '</td>';
// Actions
print '<td class="center">';
print '</td>';
print '</tr>';
}
// Request to show lines of inventory (prefilled during creation)
$sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,';
$sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated';
@ -415,7 +498,7 @@ if ($object->id > 0)
print '<input type="text" class="maxwidth75" name="id_'.$obj->rowid.' value="'.GETPOST("id_".$obj->rowid).'">';
print '</td>';
print '<td class="right">';
print img_delete();
print '<a class="reposition" href="'.DOL_URL_ROOT.'/product/inventory/inventory.php?id='.$object->id.'&lineid='.$obj->rowid.'&action=deleteline">'.img_delete().'</a>';
print '</td>';
print '</tr>';
@ -427,14 +510,19 @@ if ($object->id > 0)
}
print '</table>';
print '</div>';
//print '</div>';
print '</div>';
if ($action == 'edit') {
print '</form>';
// Save
if ($object->status == $object::STATUS_VALIDATED) {
print '<div class="center">';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print '</div>';
}
print '</div>';
print '</div>';
print '</form>';
}
// End of page