Debug establishment management

This commit is contained in:
Laurent Destailleur 2020-05-29 21:45:50 +02:00
parent 9d2f67bf8c
commit c2a9819daa
6 changed files with 209 additions and 127 deletions

View File

@ -5758,6 +5758,7 @@ class Form
if (!empty($classpath))
{
dol_include_once($classpath);
if ($classname && class_exists($classname))
{
$objecttmp = new $classname($this->db);

View File

@ -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 = '<a href="'.DOL_URL_ROOT.'/hrm/establishment/card.php?id='.$obj->rowid.'">';
$linkend = '</a>';
$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';
}
}

View File

@ -177,13 +177,16 @@ if ($action == 'create')
print '<td><input name="name" id="name" size="32" value="'.GETPOST("name", "alpha").'"></td>';
print '</tr>';
// Parent
print '<tr>';
print '<td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
print '<td class="maxwidthonsmartphone">';
print $form->selectEstablishments(GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity, 'entity', 1);
print '</td>';
print '</tr>';
// Entity
/*
if (! empty($conf->multicompany->enabled)) {
print '<tr>';
print '<td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
print '<td class="maxwidthonsmartphone">';
print $form->selectEstablishments(GETPOST('entity', 'int') > 0 ?GETPOST('entity', 'int') : $conf->entity, 'entity', 1);
print '</td>';
print '</tr>';
} */
// Address
print '<tr>';
@ -279,11 +282,14 @@ if (($id || $ref) && $action == 'edit')
print '<input name="name" id="name" class="flat" size="32" value="'.$object->name.'">';
print '</td></tr>';
// Parent
print '<tr><td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
print '<td class="maxwidthonsmartphone">';
print $form->selectEstablishments($object->entity > 0 ? $object->entity : $conf->entity, 'entity', 1);
print '</td></tr>';
// Entity
/*
if (! empty($conf->multicompany->enabled)) {
print '<tr><td>'.$form->editfieldkey('Parent', 'entity', '', $object, 0, 'string', '', 1).'</td>';
print '<td class="maxwidthonsmartphone">';
print $object->entity > 0 ? $object->entity : $conf->entity;
print '</td></tr>';
}*/
// Address
print '<tr><td>'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
@ -367,11 +373,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<td>'.$object->name.'</td>';
print '</tr>';
// Parent
print '<tr>';
print '<td class="titlefield">'.$langs->trans("Parent").'</td>';
print '<td>'.$object->getNomUrlParent($object->entity).'</td>';
print '</tr>';
// Entity
/*
if ($conf->multicompany->enabled) {
print '<tr>';
print '<td class="titlefield">'.$langs->trans("Entity").'</td>';
print '<td>'.$object->entity.'</td>';
print '</tr>';
}*/
// Address
print '<tr>';

View File

@ -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 '<table width="100%"><tr><td>';
dol_print_object_info($object);
print '</td></tr></table>';
// Object card
// ------------------------------------------------------------
$linkback = '<a href="'.dol_buildpath('/hrm/hrm/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
print '</div>';
$morehtmlref = '<div class="refidno">';
/*
// 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.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
// Project
if (! empty($conf->projet->enabled))
{
$langs->load("projects");
$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
if ($permissiontoadd)
{
if ($action != 'classify')
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$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.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
$morehtmlref.='<input type="hidden" name="action" value="classin">';
$morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
$morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
$morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref.='</form>';
} 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 .= '</div>';
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
$object->info($object->id);
dol_print_object_info($object, 1);
print '</div>';
dol_fiche_end();
}
// End of page
llxFooter();
$db->close();

View File

@ -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);

View File

@ -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),