Merge pull request #10617 from wdammak/patch-29

NEW Add Default Warehouse to user record (if module stock is on)
This commit is contained in:
Laurent Destailleur 2019-02-27 13:38:55 +01:00 committed by GitHub
commit 727c4b787b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 3 deletions

View File

@ -48,6 +48,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
if (! empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; if (! empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
@ -91,7 +92,7 @@ $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
if ($user->id <> $id && ! $canreaduser) accessforbidden(); if ($user->id <> $id && ! $canreaduser) accessforbidden();
// Load translation files required by page // Load translation files required by page
$langs->loadLangs(array('users', 'companies', 'ldap', 'admin', 'hrm')); $langs->loadLangs(array('users', 'companies', 'ldap', 'admin', 'hrm', 'stocks'));
$object = new User($db); $object = new User($db);
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
@ -238,6 +239,8 @@ if (empty($reshook)) {
$dateemploymentend = dol_mktime(0, 0, 0, GETPOST('dateemploymentendmonth'), GETPOST('dateemploymentendday'), GETPOST('dateemploymentendyear')); $dateemploymentend = dol_mktime(0, 0, 0, GETPOST('dateemploymentendmonth'), GETPOST('dateemploymentendday'), GETPOST('dateemploymentendyear'));
$object->dateemploymentend = $dateemploymentend; $object->dateemploymentend = $dateemploymentend;
$object->fk_warehouse = GETPOST('fk_warehouse', 'int');
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object); $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
if ($ret < 0) { if ($ret < 0) {
@ -386,6 +389,11 @@ if (empty($reshook)) {
$dateemploymentend = dol_mktime(0, 0, 0, GETPOST('dateemploymentendmonth', 'int'), GETPOST('dateemploymentendday', 'int'), GETPOST('dateemploymentendyear', 'int')); $dateemploymentend = dol_mktime(0, 0, 0, GETPOST('dateemploymentendmonth', 'int'), GETPOST('dateemploymentendday', 'int'), GETPOST('dateemploymentendyear', 'int'));
$object->dateemploymentend = $dateemploymentend; $object->dateemploymentend = $dateemploymentend;
if (! empty($conf->stock->enabled))
{
$object->fk_warehouse = GETPOST('fk_warehouse', 'int');
}
if (! empty($conf->multicompany->enabled)) if (! empty($conf->multicompany->enabled))
{ {
if (! empty($_POST["superadmin"])) if (! empty($_POST["superadmin"]))
@ -642,6 +650,7 @@ $form = new Form($db);
$formother=new FormOther($db); $formother=new FormOther($db);
$formcompany = new FormCompany($db); $formcompany = new FormCompany($db);
$formfile = new FormFile($db); $formfile = new FormFile($db);
if (! empty($conf->stock->enabled)) $formproduct = new FormProduct($db);
llxHeader('', $langs->trans("UserCard")); llxHeader('', $langs->trans("UserCard"));
@ -1185,6 +1194,13 @@ if ($action == 'create' || $action == 'adduserldap')
print '<input class="maxwidth200" type="text" name="job" value="'.GETPOST('job').'">'; print '<input class="maxwidth200" type="text" name="job" value="'.GETPOST('job').'">';
print '</td></tr>'; print '</td></tr>';
// Default warehouse
if (! empty($conf->stock->enabled))
{
print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1);
print '</td></tr>';
}
if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read))
|| (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read))) || (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read)))
@ -1538,6 +1554,17 @@ else
print '<td>'.$object->job.'</td>'; print '<td>'.$object->job.'</td>';
print '</tr>'."\n"; print '</tr>'."\n";
// Default warehouse
if (! empty($conf->stock->enabled))
{
require_once DOL_DOCUMENT_ROOT .'/product/stock/class/entrepot.class.php';
$warehousestatic=new Entrepot($db);
$warehousestatic->fetch($object->fk_warehouse);
print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
print $warehousestatic->getNomUrl();
print '</td></tr>';
}
//$childids = $user->getAllChildIds(1); //$childids = $user->getAllChildIds(1);
if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read))
@ -2556,6 +2583,15 @@ else
} }
print '</td></tr>'; print '</td></tr>';
// Default warehouse
if (! empty($conf->stock->enabled))
{
print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1);
print ' <a href="'.DOL_URL_ROOT.'/product/stock/card.php?action=create&amp;backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit').'">'.$langs->trans("AddWarehouse").'</a>';
print '</td></tr>';
}
if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read))
|| (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read))) || (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read)))
{ {

View File

@ -175,6 +175,8 @@ class User extends CommonObject
public $default_c_exp_tax_cat; public $default_c_exp_tax_cat;
public $default_range; public $default_range;
public $fk_warehouse;
public $fields = array( public $fields = array(
'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), 'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
'lastname'=>array('type'=>'varchar(50)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>20, 'searchall'=>1, 'comment'=>'Reference of object'), 'lastname'=>array('type'=>'varchar(50)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>20, 'searchall'=>1, 'comment'=>'Reference of object'),
@ -249,6 +251,7 @@ class User extends CommonObject
$sql.= " u.weeklyhours,"; $sql.= " u.weeklyhours,";
$sql.= " u.color,"; $sql.= " u.color,";
$sql.= " u.dateemployment, u.dateemploymentend,"; $sql.= " u.dateemployment, u.dateemploymentend,";
$sql.= " u.fk_warehouse,";
$sql.= " u.ref_int, u.ref_ext,"; $sql.= " u.ref_int, u.ref_ext,";
$sql.= " u.default_range, u.default_c_exp_tax_cat,"; // Expense report default mode $sql.= " u.default_range, u.default_c_exp_tax_cat,"; // Expense report default mode
$sql.= " c.code as country_code, c.label as country,"; $sql.= " c.code as country_code, c.label as country,";
@ -370,6 +373,7 @@ class User extends CommonObject
$this->default_range = $obj->default_range; $this->default_range = $obj->default_range;
$this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat; $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
$this->fk_warehouse = $obj->fk_warehouse;
// Protection when module multicompany was set, admin was set to first entity and then, the module was disabled, // Protection when module multicompany was set, admin was set to first entity and then, the module was disabled,
// in such case, this admin user must be admin for ALL entities. // in such case, this admin user must be admin for ALL entities.
@ -1486,6 +1490,7 @@ class User extends CommonObject
$this->color = empty($this->color)?'':$this->color; $this->color = empty($this->color)?'':$this->color;
$this->dateemployment = empty($this->dateemployment)?'':$this->dateemployment; $this->dateemployment = empty($this->dateemployment)?'':$this->dateemployment;
$this->dateemploymentend = empty($this->dateemploymentend)?'':$this->dateemploymentend; $this->dateemploymentend = empty($this->dateemploymentend)?'':$this->dateemploymentend;
$this->fk_warehouse = trim(empty($this->fk_warehouse)?'':$this->fk_warehouse);
// Check parameters // Check parameters
if (! empty($conf->global->USER_MAIL_REQUIRED) && ! isValidEMail($this->email)) if (! empty($conf->global->USER_MAIL_REQUIRED) && ! isValidEMail($this->email))
@ -1544,6 +1549,7 @@ class User extends CommonObject
$sql.= ", entity = '".$this->db->escape($this->entity)."'"; $sql.= ", entity = '".$this->db->escape($this->entity)."'";
$sql.= ", default_range = ".($this->default_range > 0 ? $this->default_range : 'null'); $sql.= ", default_range = ".($this->default_range > 0 ? $this->default_range : 'null');
$sql.= ", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat : 'null'); $sql.= ", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat : 'null');
$sql.= ", fk_warehouse = ".($this->fk_warehouse?"'".$this->db->escape($this->fk_warehouse)."'":"null");
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
@ -1984,7 +1990,7 @@ class User extends CommonObject
dol_syslog(get_class($this)."::send_password changelater is on, url=".$url); dol_syslog(get_class($this)."::send_password changelater is on, url=".$url);
} }
$mailfile = new CMailFile( $mailfile = new CMailFile(
$subject, $subject,
$this->email, $this->email,
$conf->global->MAIN_MAIL_EMAIL_FROM, $conf->global->MAIN_MAIL_EMAIL_FROM,