From c2a9819daabdc5523f1c7095abc0451d6715da39 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 29 May 2020 21:45:50 +0200 Subject: [PATCH] Debug establishment management --- htdocs/core/class/html.form.class.php | 1 + htdocs/hrm/class/establishment.class.php | 131 ++++----------- htdocs/hrm/establishment/card.php | 43 +++-- htdocs/hrm/establishment/info.php | 152 ++++++++++++++++-- .../install/mysql/migration/12.0.0-13.0.0.sql | 6 + .../mysql/tables/llx_establishment.sql | 3 +- 6 files changed, 209 insertions(+), 127 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 092ef6795cb..0dd3c31bdc6 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5758,6 +5758,7 @@ class Form if (!empty($classpath)) { dol_include_once($classpath); + if ($classname && class_exists($classname)) { $objecttmp = new $classname($this->db); diff --git a/htdocs/hrm/class/establishment.class.php b/htdocs/hrm/class/establishment.class.php index 37ae050cd9b..2bbe374d1d0 100644 --- a/htdocs/hrm/class/establishment.class.php +++ b/htdocs/hrm/class/establishment.class.php @@ -100,6 +100,10 @@ class Establishment extends CommonObject public $statuts = array(); public $statuts_short = array(); + const STATUS_OPEN = 0; + const STATUS_CLOSED = 1; + + /** * Constructor * @@ -109,8 +113,8 @@ class Establishment extends CommonObject { $this->db = $db; - $this->statuts_short = array(0 => 'Closed', 1 => 'Opened'); - $this->statuts = array(0 => 'Closed', 1 => 'Opened'); + $this->statuts_short = array(0 => 'Closed', 1 => 'Open'); + $this->statuts = array(0 => 'Closed', 1 => 'Open'); } /** @@ -136,7 +140,8 @@ class Establishment extends CommonObject $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."establishment ("; - $sql .= "name"; + $sql .= "ref"; + $sql .= ", name"; $sql .= ", address"; $sql .= ", zip"; $sql .= ", town"; @@ -204,7 +209,7 @@ class Establishment extends CommonObject $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."establishment"; - $sql .= " SET name = '".$this->db->escape($this->name)."'"; + $sql .= " SET ref = '".$this->db->escape($this->ref)."', name = '".$this->db->escape($this->name)."'"; $sql .= ", address = '".$this->db->escape($this->address)."'"; $sql .= ", zip = '".$this->db->escape($this->zip)."'"; $sql .= ", town = '".$this->db->escape($this->town)."'"; @@ -234,7 +239,7 @@ class Establishment extends CommonObject */ public function fetch($id) { - $sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status, e.fk_country as country_id, e.entity,"; + $sql = "SELECT e.rowid, e.ref, e.name, e.address, e.zip, e.town, e.status, e.fk_country as country_id, e.entity,"; $sql .= ' c.code as country_code, c.label as country'; $sql .= " FROM ".MAIN_DB_PREFIX."establishment as e"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON e.fk_country = c.rowid'; @@ -247,7 +252,7 @@ class Establishment extends CommonObject $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; - $this->ref = $obj->rowid; + $this->ref = $obj->ref; $this->name = $obj->name; $this->address = $obj->address; $this->zip = $obj->zip; @@ -294,52 +299,43 @@ class Establishment extends CommonObject /** * Give a label from a status * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto - * @return string Label + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @return string Label of status */ public function getLibStatut($mode = 0) { return $this->LibStatut($this->status, $mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Give a label from a status + * Return the status * - * @param int $status Id status - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto - * @return string Label + * @param int $status Id status + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @return string Label of status */ public function LibStatut($status, $mode = 0) { - // phpcs:enable - global $langs; - - if ($mode == 0) + // phpcs:enable + if (empty($this->labelStatus) || empty($this->labelStatusShort)) { - return $langs->trans($this->statuts[$status]); - } elseif ($mode == 1) - { - return $langs->trans($this->statuts_short[$status]); - } elseif ($mode == 2) - { - if ($status == 0) return img_picto($langs->trans($this->statuts_short[$status]), 'statut5').' '.$langs->trans($this->statuts_short[$status]); - elseif ($status == 1) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts_short[$status]); - } elseif ($mode == 3) - { - if ($status == 0 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut5'); - elseif ($status == 1 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4'); - } elseif ($mode == 4) - { - if ($status == 0 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut5').' '.$langs->trans($this->statuts[$status]); - elseif ($status == 1 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]); - } elseif ($mode == 5) - { - if ($status == 0 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut5'); - elseif ($status == 1 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut4'); + global $langs; + //$langs->load("mymodule"); + $this->labelStatus[self::STATUS_OPEN] = $langs->trans('Open'); + $this->labelStatus[self::STATUS_CLOSED] = $langs->trans('Closed'); + $this->labelStatusShort[self::STATUS_OPEN] = $langs->trans('Open'); + $this->labelStatusShort[self::STATUS_CLOSED] = $langs->trans('Closed'); } + + $statusType = 'status'.$status; + //if ($status == self::STATUS_VALIDATED) $statusType = 'status1'; + if ($status == self::STATUS_CLOSED) $statusType = 'status6'; + + return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); } + /** * Information on record * @@ -348,7 +344,7 @@ class Establishment extends CommonObject */ public function info($id) { - $sql = 'SELECT e.rowid, e.datec, e.fk_user_author, e.tms, e.fk_user_mod, e.entity'; + $sql = 'SELECT e.rowid, e.ref, e.datec, e.fk_user_author, e.tms, e.fk_user_mod, e.entity'; $sql .= ' FROM '.MAIN_DB_PREFIX.'establishment as e'; $sql .= ' WHERE e.rowid = '.$id; @@ -384,35 +380,6 @@ class Establishment extends CommonObject } } - /** - * Get on record Establishment - * - * @param int $id Id of record - * @return Object - */ - public function getEstablishment($id) - { - $sql = 'SELECT e.rowid, e.name, e.datec, e.fk_user_author, e.tms, e.fk_user_mod, e.entity'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'establishment as e'; - $sql .= ' WHERE e.rowid = '.$id; - - dol_syslog(get_class($this)."::fetch info", LOG_DEBUG); - $result = $this->db->query($sql); - - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); - } - $this->db->free($result); - } else { - dol_print_error($this->db); - } - - return $obj; - } - /** * Return clicable name (with picto eventually) * @@ -438,34 +405,6 @@ class Establishment extends CommonObject return $result; } - /** - * Return clicable name (with picto eventually) - * - * @param int $id Id of record - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @return string String with URL - */ - public function getNomUrlParent($id = 0, $withpicto = 0) - { - global $langs, $conf; - - $result = ''; - - $obj = $this->getEstablishment(($id > 0) ? $id : $conf->entity); - - $link = ''; - $linkend = ''; - - $picto = 'building'; - - $label = $langs->trans("Show").': '.$obj->name; - - if ($withpicto) $result .= ($link.img_object($label, $picto).$linkend); - if ($withpicto && $withpicto != 2) $result .= ' '; - if ($withpicto != 2) $result .= $link.$obj->name.$linkend; - return $result; - } - /** * Return account country code * @@ -493,6 +432,6 @@ class Establishment extends CommonObject public function initAsSpecimen() { $this->id = 0; - $this->ref = 'DEAAA'; + $this->ref = 'DEP-AAA'; } } diff --git a/htdocs/hrm/establishment/card.php b/htdocs/hrm/establishment/card.php index aa1ac36a9f1..c7784d42fb2 100644 --- a/htdocs/hrm/establishment/card.php +++ b/htdocs/hrm/establishment/card.php @@ -177,13 +177,16 @@ if ($action == 'create') print ''; print ''; - // Parent - print ''; - print ''.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).''; - print ''; - print $form->selectEstablishments(GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity, 'entity', 1); - print ''; - print ''; + // Entity + /* + if (! empty($conf->multicompany->enabled)) { + print ''; + print ''.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).''; + print ''; + print $form->selectEstablishments(GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity, 'entity', 1); + print ''; + print ''; + } */ // Address print ''; @@ -279,11 +282,14 @@ if (($id || $ref) && $action == 'edit') print ''; print ''; - // Parent - print ''.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).''; - print ''; - print $form->selectEstablishments($object->entity > 0 ? $object->entity : $conf->entity, 'entity', 1); - print ''; + // Entity + /* + if (! empty($conf->multicompany->enabled)) { + print ''.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).''; + print ''; + print $object->entity > 0 ? $object->entity : $conf->entity; + print ''; + }*/ // Address print ''.$form->editfieldkey('Address', 'address', '', $object, 0).''; @@ -367,11 +373,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''.$object->name.''; print ''; - // Parent - print ''; - print ''.$langs->trans("Parent").''; - print ''.$object->getNomUrlParent($object->entity).''; - print ''; + // Entity + /* + if ($conf->multicompany->enabled) { + print ''; + print ''.$langs->trans("Entity").''; + print ''.$object->entity.''; + print ''; + }*/ // Address print ''; diff --git a/htdocs/hrm/establishment/info.php b/htdocs/hrm/establishment/info.php index a9825ac7b3a..c26f7db4fc1 100644 --- a/htdocs/hrm/establishment/info.php +++ b/htdocs/hrm/establishment/info.php @@ -28,31 +28,157 @@ require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php'; // Load translation files required by the page $langs->loadLangs(array('admin', 'hrm')); -// Security check -if (!$user->admin) accessforbidden(); - +// Get parameters $id = GETPOST('id', 'int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action', 'alpha'); +$cancel = GETPOST('cancel', 'aZ09'); +$backtopage = GETPOST('backtopage', 'alpha'); -// View -llxHeader(); +if (GETPOST('actioncode', 'array')) { + $actioncode = GETPOST('actioncode', 'array', 3); + if (!count($actioncode)) $actioncode = '0'; +} else { + $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); +} +$search_agenda_label = GETPOST('search_agenda_label'); -if ($id) +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (!$sortfield) $sortfield = 'a.datep,a.id'; +if (!$sortorder) $sortorder = 'DESC,DESC'; + +// Initialize technical objects +$object = new Establishment($db); +$extrafields = new ExtraFields($db); +$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id; +$hookmanager->initHooks(array('hrmagenda', 'globalcard')); // Note that conf->hooks_modules contains array +// Fetch optionals attributes and labels +$extrafields->fetch_name_optionals_label($object->table_element); + +// Load object +include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals +if ($id > 0 || !empty($ref)) $upload_dir = $conf->hrm->multidir_output[$object->entity]."/".$object->id; + +// Security check - Protection if external user +//if ($user->socid > 0) accessforbidden(); +//if ($user->socid > 0) $socid = $user->socid; +//$result = restrictedArea($user, 'mymodule', $object->id); + +$permissiontoadd = $user->rights->hrm->write; // Used by the include of actions_addupdatedelete.inc.php + + +/* + * Actions + */ + +$parameters = array('id'=>$id); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if (empty($reshook)) { - $object = new Establishment($db); - $object->fetch($id); - $object->info($id); + // Cancel + if (GETPOST('cancel', 'alpha') && !empty($backtopage)) + { + header("Location: ".$backtopage); + exit; + } + // Purge search criteria + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers + { + $actioncode = ''; + $search_agenda_label = ''; + } +} + + + +/* + * View + */ + +$form = new Form($db); + +if ($object->id > 0) +{ + $title = $langs->trans("Agenda"); + //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title; + $help_url = ''; + llxHeader('', $title, $help_url); + + if (!empty($conf->notification->enabled)) $langs->load("mails"); $head = establishment_prepare_head($object); + dol_fiche_head($head, 'info', $langs->trans("Establishment"), -1, 'building'); - print '
'; - dol_print_object_info($object); - print '
'; + // Object card + // ------------------------------------------------------------ + $linkback = ''.$langs->trans("BackToList").''; - print ''; + $morehtmlref = '
'; + /* + // Ref customer + $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); + $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : ''); + // Project + if (! empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($permissiontoadd) + { + if ($action != 'classify') + //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + $morehtmlref.=' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.='
'; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $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 .= ': '.$proj->getNomUrl(); + } else { + $morehtmlref .= ''; + } + } + }*/ + $morehtmlref .= '
'; + + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + + print '
'; + print '
'; + + $object->info($object->id); + dol_print_object_info($object, 1); + + print '
'; + + dol_fiche_end(); } + // End of page llxFooter(); $db->close(); diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index a6a1870e807..58d28dcd6a3 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -37,3 +37,9 @@ ALTER TABLE llx_commande MODIFY COLUMN date_livraison DATETIME; ALTER TABLE llx_website ADD COLUMN position integer DEFAULT 0; +ALTER TABLE llx_establishment ADD COLUMN ref varchar(30); +ALTER TABLE llx_establishment ADD COLUMN name varchar(128); +UPDATE llx_establishment SET ref = rowid WHERE ref IS NULL; +ALTER TABLE llx_establishment MODIFY COLUMN ref varchar(30) NOT NULL; +ALTER TABLE llx_establishment MODIFY COLUMN name varchar(128); + diff --git a/htdocs/install/mysql/tables/llx_establishment.sql b/htdocs/install/mysql/tables/llx_establishment.sql index 89fec8f54e2..f47d7b4aeae 100644 --- a/htdocs/install/mysql/tables/llx_establishment.sql +++ b/htdocs/install/mysql/tables/llx_establishment.sql @@ -22,7 +22,8 @@ CREATE TABLE llx_establishment ( rowid integer NOT NULL auto_increment PRIMARY KEY, entity integer NOT NULL DEFAULT 1, - name varchar(50), + ref varchar(30), + name varchar(128), address varchar(255), zip varchar(25), town varchar(50),