Merge pull request #20144 from atm-adrien/NEW_include_sub_warehouse_in_inventory
NEW : Include sub warehouse in inventory
This commit is contained in:
commit
3b69bbb0b6
6 changed files with 76 additions and 6 deletions
|
|
@ -444,7 +444,13 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissionto
|
|||
|
||||
// Action validate object
|
||||
if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) {
|
||||
$result = $object->validate($user);
|
||||
if ($object->element == 'inventory' && !empty($include_sub_warehouse)) {
|
||||
//Case of the conf INVENTORY_INCLUDE_SUB_WAREHOUSE
|
||||
$result = $object->validate($user, false, $include_sub_warehouse);
|
||||
} else {
|
||||
$result = $object->validate($user);
|
||||
}
|
||||
|
||||
if ($result >= 0) {
|
||||
// Define output language
|
||||
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
|
||||
|
|
|
|||
|
|
@ -321,5 +321,8 @@ BatchNotFound=Lot / serial not found for this product
|
|||
StockMovementWillBeRecorded=Stock movement will be recorded
|
||||
StockMovementNotYetRecorded=Stock movement will not be affected by this step
|
||||
WarningThisWIllAlsoDeleteStock=Warning, this will also destroy all quantities in stock in the warehouse
|
||||
ValidateInventory=Inventory validation
|
||||
IncludeSubWarehouse=Include sub-warehouse ?
|
||||
IncludeSubWarehouseExplanation=Check this box if you want to include all sub-warehouses of the associated warehouse in the inventory
|
||||
DeleteBatch=Delete lot/serial
|
||||
ConfirmDeleteBatch=Are you sure you want to delete lot/serial ?
|
||||
ConfirmDeleteBatch=Are you sure you want to delete lot/serial ?
|
||||
|
|
|
|||
|
|
@ -318,6 +318,7 @@ StockTransferRightRead=Lire les transferts de stocks
|
|||
StockTransferRightCreateUpdate=Créer/Mettre à jour les transferts de stocks
|
||||
StockTransferRightDelete=Supprimer les transferts de stocks
|
||||
BatchNotFound=Lot/série introuvable pour ce produit
|
||||
IncludeSubWarehouse=Inclure les sous-entrepôts ?
|
||||
StockMovementWillBeRecorded=Les mouvements de stock seront enregistrés
|
||||
StockMovementNotYetRecorded=Le mouvement des stocks ne sera pas affecté par cette étape
|
||||
WarningThisWIllAlsoDeleteStock=Attention, cela détruira également toutes les quantités en stock dans l'entrepôt
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ $confirm = GETPOST('confirm', 'alpha');
|
|||
$cancel = GETPOST('cancel', 'aZ09');
|
||||
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'inventorycard'; // To manage different context of search
|
||||
$backtopage = GETPOST('backtopage', 'alpha');
|
||||
$include_sub_warehouse = !empty(GETPOST('include_sub_warehouse')) ? GETPOST('include_sub_warehouse') : 0;
|
||||
|
||||
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
|
||||
$result = restrictedArea($user, 'stock', $id);
|
||||
|
|
@ -289,6 +290,18 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
|
||||
}
|
||||
|
||||
|
||||
if ($action == 'validate') {
|
||||
$form = new Form($db);
|
||||
$formquestion = '';
|
||||
if ($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)) {
|
||||
$formquestion = array(
|
||||
array('type' => 'checkbox', 'name' => 'include_sub_warehouse', 'label' => $langs->trans("IncludeSubWarehouse"), 'value' => 1, 'size' => '10'),
|
||||
);
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateInventory'), $langs->trans('IncludeSubWarehouseExplanation'), 'confirm_validate', $formquestion, '', 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Call Hook formConfirm
|
||||
$parameters = array('formConfirm' => $formconfirm);
|
||||
$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||
|
|
@ -412,7 +425,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||
// Validate
|
||||
if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_CANCELED) {
|
||||
if ($permissiontoadd) {
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken().'">'.$langs->trans("Validate").' ('.$langs->trans("ToStart").')</a>';
|
||||
if ($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)) {
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate&token='.newToken().'">'.$langs->trans("Validate").' ('.$langs->trans("Start").')</a>';
|
||||
} else {
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken().'">'.$langs->trans("Validate").' ('.$langs->trans("Start").')</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ class Inventory extends CommonObject
|
|||
* @param bool $notrigger false=launch triggers after, true=disable triggers
|
||||
* @return int <0 if KO, Id of created object if OK
|
||||
*/
|
||||
public function validate(User $user, $notrigger = false)
|
||||
public function validate(User $user, $notrigger = false, $include_sub_warehouse = 0)
|
||||
{
|
||||
global $conf;
|
||||
$this->db->begin();
|
||||
|
|
@ -292,7 +292,12 @@ class Inventory extends CommonObject
|
|||
$sql .= " AND ps.fk_product = ".((int) $this->fk_product);
|
||||
}
|
||||
if ($this->fk_warehouse > 0) {
|
||||
$sql .= " AND ps.fk_entrepot = ".((int) $this->fk_warehouse);
|
||||
$sql .= " AND (ps.fk_entrepot = ".((int) $this->fk_warehouse);
|
||||
if (!empty($include_sub_warehouse) && $conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE) {
|
||||
$this->getchildWarehouse($this->fk_warehouse, $TChildWarehouses);
|
||||
$sql .= " OR ps.fk_entrepot IN (".filter_var(implode(',', $TChildWarehouses), FILTER_SANITIZE_STRING).")";
|
||||
}
|
||||
$sql .= ')';
|
||||
}
|
||||
if (!empty($this->categories_product)) {
|
||||
$sql .= " AND EXISTS (";
|
||||
|
|
@ -745,6 +750,29 @@ class Inventory extends CommonObject
|
|||
$this->initAsSpecimenCommon();
|
||||
$this->title = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the child warehouse of the current one
|
||||
* @param int $id Id of warehouse
|
||||
* @param $TChildWarehouse child warehouses
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function getchildWarehouse($id, &$TChildWarehouse)
|
||||
{
|
||||
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'entrepot';
|
||||
$sql.= ' WHERE fk_parent='.(int) $id;
|
||||
$sql.= ' ORDER BY rowid';
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql && $this->db->num_rows($resql)>0) {
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
$TChildWarehouse[] = $obj->rowid;
|
||||
$this->getchildWarehouse($obj->rowid, $TChildWarehouse);
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -468,6 +468,17 @@ if ($action == 'confirm_cancel') {
|
|||
$action = 'view';
|
||||
}
|
||||
|
||||
if ($action == 'validate') {
|
||||
$form = new Form($db);
|
||||
$formquestion = '';
|
||||
if ($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)) {
|
||||
$formquestion = array(
|
||||
array('type' => 'checkbox', 'name' => 'include_sub_warehouse', 'label' => $langs->trans("IncludeSubWarehouse"), 'value' => 1, 'size' => '10'),
|
||||
);
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateInventory'), $langs->trans('IncludeSubWarehouseExplanation'), 'confirm_validate', $formquestion, '', 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Call Hook formConfirm
|
||||
$parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
|
||||
$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||
|
|
@ -573,7 +584,11 @@ if ($action != 'record') {
|
|||
if (empty($reshook)) {
|
||||
if ($object->status == Inventory::STATUS_DRAFT) {
|
||||
if ($permissiontoadd) {
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken().'">'.$langs->trans("Validate").' ('.$langs->trans("Start").')</a>'."\n";
|
||||
if ($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)) {
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate&token='.newToken().'">'.$langs->trans("Validate").' ('.$langs->trans("Start").')</a>';
|
||||
} else {
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken().'">'.$langs->trans("Validate").' ('.$langs->trans("Start").')</a>';
|
||||
}
|
||||
} else {
|
||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Validate').' ('.$langs->trans("Start").')</a>'."\n";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue