From 4c8d37ce286c056aa012b8c57fa009eafd04677c Mon Sep 17 00:00:00 2001 From: altairis-noe Date: Wed, 14 Apr 2021 13:45:25 +0200 Subject: [PATCH] warehouse can now be linked to a project with fk_project --- htdocs/product/stock/card.php | 45 ++++++++++++++++--- htdocs/product/stock/class/entrepot.class.php | 14 ++++-- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index 39c4c525696..60690cedeeb 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -105,6 +105,7 @@ if (empty($reshook)) { if ($action == 'add' && $user->rights->stock->creer) { $object->ref = (string) GETPOST("ref", "alpha"); $object->fk_parent = (int) GETPOST("fk_parent", "int"); + $object->fk_project = GETPOST('projectid', 'int'); $object->label = (string) GETPOST("libelle", "alpha"); $object->description = (string) GETPOST("desc", "alpha"); $object->statut = GETPOST("statut"); @@ -168,6 +169,7 @@ if (empty($reshook)) { if ($object->fetch($id)) { $object->label = GETPOST("libelle"); $object->fk_parent = GETPOST("fk_parent"); + $object->fk_project = GETPOST('projectid'); $object->description = GETPOST("desc"); $object->statut = GETPOST("statut"); $object->lieu = GETPOST("lieu"); @@ -221,6 +223,9 @@ if (empty($reshook)) { if ($error) { $action = 'edit_extras'; } + } elseif ($action == 'classin' && $usercancreate) { + // Link to a project + $object->setProject(GETPOST('projectid', 'int')); } if ($cancel == $langs->trans("Cancel")) { @@ -399,12 +404,39 @@ if ($action == 'create') { $morehtmlref = '
'; $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu; - $morehtmlref .= '
'; - if ($object->project) { - $morehtmlref .= '
'; - $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu; - $morehtmlref .= '
'; + + // Project + if (!empty($conf->projet->enabled)) { + $langs->load("projects"); + $morehtmlref .= '
'.img_picto('', 'project').' '.$langs->trans('Project').' '; + if ($usercancreate) { + if ($action != 'classify') { + $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; + } + if ($action == 'classify') { + $projectid = $object->fk_project; + $morehtmlref .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500'); + $morehtmlref .= ''; + $morehtmlref .= '
'; + } else { + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (!empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref .= ''; + $morehtmlref .= $proj->ref; + $morehtmlref .= ''; + } else { + $morehtmlref .= ''; + } + } } + $morehtmlref .= ''; $shownav = 1; if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { @@ -511,7 +543,7 @@ if ($action == 'create') { $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { - if (empty($action)) { + if (empty($action) || $action == 'classin') { if ($user->rights->stock->creer) { print ''.$langs->trans("Modify").''; } else { @@ -732,6 +764,7 @@ if ($action == 'create') { // Project if (!empty($conf->projet->enabled)) { + $projectid = $object->fk_project; $langs->load('projects'); print ''.$langs->trans('Project').''; print img_picto('', 'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500'); diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 214a12ead14..2f3131feba9 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -108,6 +108,11 @@ class Entrepot extends CommonObject */ public $fk_parent; + /** + * @var int ID of project + */ + public $fk_project; + /** * @var array List of short language codes for status */ @@ -124,6 +129,7 @@ class Entrepot extends CommonObject 'description' =>array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-2, 'position'=>35, 'searchall'=>1), 'lieu' =>array('type'=>'varchar(64)', 'label'=>'LocationSummary', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'showoncombobox'=>1, 'searchall'=>1), 'fk_parent' =>array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php:1:statut=1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ParentWarehouse', 'enabled'=>1, 'visible'=>-2, 'position'=>41), + 'fk_project' =>array('type'=>'integer:Project:projet/class/project.class.php:1:fk_statut=1', 'label'=>'Project', 'enabled'=>1, 'visible'=>-1, 'position'=>25), 'address' =>array('type'=>'varchar(255)', 'label'=>'Address', 'enabled'=>1, 'visible'=>-2, 'position'=>45, 'searchall'=>1), 'zip' =>array('type'=>'varchar(10)', 'label'=>'Zip', 'enabled'=>1, 'visible'=>-2, 'position'=>50, 'searchall'=>1), 'town' =>array('type'=>'varchar(50)', 'label'=>'Town', 'enabled'=>1, 'visible'=>-2, 'position'=>55, 'searchall'=>1), @@ -198,8 +204,8 @@ class Entrepot extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (ref, entity, datec, fk_user_author, fk_parent)"; - $sql .= " VALUES ('".$this->db->escape($this->label)."', ".$conf->entity.", '".$this->db->idate($now)."', ".$user->id.", ".($this->fk_parent > 0 ? $this->fk_parent : "NULL").")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)"; + $sql .= " VALUES ('".$this->db->escape($this->label)."', ".$conf->entity.", '".$this->db->idate($now)."', ".$user->id.", ".($this->fk_parent > 0 ? $this->fk_parent : "NULL").", ".($this->fk_project > 0 ? $this->fk_project : "NULL").")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); @@ -290,6 +296,7 @@ class Entrepot extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."entrepot "; $sql .= " SET ref = '".$this->db->escape($this->label)."'"; $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL"); + $sql .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL"); $sql .= ", description = '".$this->db->escape($this->description)."'"; $sql .= ", statut = ".$this->statut; $sql .= ", lieu = '".$this->db->escape($this->lieu)."'"; @@ -432,7 +439,7 @@ class Entrepot extends CommonObject return -1; } - $sql = "SELECT rowid, entity, fk_parent, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,"; + $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,"; $sql .= " model_pdf, import_key"; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; if ($id) { @@ -452,6 +459,7 @@ class Entrepot extends CommonObject $this->id = $obj->rowid; $this->entity = $obj->entity; $this->fk_parent = $obj->fk_parent; + $this->fk_project = $obj->fk_project; $this->ref = $obj->label; $this->label = $obj->label; $this->libelle = $obj->label; // deprecated