Merge pull request #3958 from aspangaro/develop-hrm

HRM: Update work
This commit is contained in:
Laurent Destailleur 2015-11-11 15:28:14 +01:00
commit 47ce8baadc
6 changed files with 206 additions and 115 deletions

View File

@ -33,9 +33,13 @@ if (! $user->admin)
$error=0;
$action = GETPOST('action', 'alpha');
$object = new Establishment($db);
// List of statut
static $tmpstatus2label=array(
'0'=>'OpenEtablishment',
'1'=>'CloseEtablishment'
);
$status2label=array('');
foreach ($tmpstatus2label as $key => $val) $status2label[$key]=$langs->trans($val);
/*
* Actions
@ -44,10 +48,24 @@ $object = new Establishment($db);
/*
* View
*/
$page_name = "Establishments";
llxHeader('', $langs->trans($page_name));
llxHeader('', $langs->trans("Establishments"));
$sortorder = GETPOST("sortorder");
$sortfield = GETPOST("sortfield");
if (!$sortorder) $sortorder="DESC";
if (!$sortfield) $sortfield="e.rowid";
if ($page == -1) {
$page = 0 ;
}
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
$limit = $conf->liste_limit;
$form = new Form($db);
$establishmenttmp=new Establishment($db);
dol_htmloutput_mesg($mesg);
@ -62,43 +80,50 @@ dol_fiche_head($head, 'establishments', $langs->trans("HRM"), 0, "user");
$sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status";
$sql.= " FROM ".MAIN_DB_PREFIX."establishment as e";
$sql.= " WHERE e.entity = ".$conf->entity;
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit+1, $offset);
$result = $db->query($sql);
if ($result)
{
$var=false;
$num = $db->num_rows($result);
$i = 0;
$num = $db->num_rows($result);
$i = 0;
// Load attribute_label
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Ref").'</td>';
print '<td>'.$langs->trans("Name").'</td>';
print '<td>'.$langs->trans("Address").'</td>';
print '<td>'.$langs->trans("Zipcode").'</td>';
print '<td>'.$langs->trans("Town").'</td>';
print '<td align="right">'.$langs->trans("Status").'</td>';
print '</tr>';
print "<tr class=\"liste_titre\">";
print_liste_field_titre($langs->trans("Name"),$_SERVER["PHP_SELF"],"e.name","","","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Address"),$_SERVER["PHP_SELF"],"e.address","","","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Zipcode"),$_SERVER["PHP_SELF"],"e.zip","","","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Town"),$_SERVER["PHP_SELF"],"e.town","","","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"e.status","","",'align="right"',$sortfield,$sortorder);
print "</tr>\n";
if ($num)
$var=true;
if ($num > 0)
{
$establishmentstatic=new Establishment($db);
while ($i < $num && $i < $max)
{
while ($i < min($num,$limit))
{
$obj = $db->fetch_object($result);
$fiscalyearstatic->id=$obj->rowid;
print '<tr '.$bc[$var].'>';
print '<td><a href="admin_establishment_card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowEstablishment"),"building").' '.$obj->rowid.'</a></td>';
print '<td align="left">'.$obj->name.'</td>';
$establishmentstatic->id=$obj->rowid;
$establishmentstatic->name=$obj->name;
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$establishmentstatic->getNomUrl(1).'</td>';
print '<td align="left">'.$obj->address.'</td>';
print '<td align="left">'.$obj->zip.'</td>';
print '<td align="left">'.$obj->town.'</td>';
print '<td align="right">'.$establishmentstatic->LibStatut($obj->status,5).'</td>';
print '</tr>';
$var=!$var;
print '<td align="right">';
print $establishmenttmp->getLibStatus(5);
print '</td>';
print "</tr>\n";
$i++;
}

View File

@ -67,26 +67,41 @@ class Employee extends CommonObject
* @param int $id Id of record to load
* @return int <0 if KO, >0 if OK
*/
function fetch($id)
function fetch($id='')
{
$sql = "SELECT rowid, firstname, lastname, status, fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."user";
global $conf, $user;
$sql = "SELECT e.rowid, e.firstname, e.lastname, e.gender, e.email, e.statut, e.entity, e.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."user as e";
$sql.= " WHERE rowid = ".$id;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql);
if ( $result )
if ($result)
{
$obj = $this->db->fetch_object($result);
if ($obj)
{
$this->id = $obj->rowid;
$this->lastname = $obj->lastname;
$this->firstname = $obj->firstname;
$this->gender = $obj->gender;
$this->address = $obj->address;
$this->zip = $obj->zip;
$this->town = $obj->town;
$this->statut = $obj->statut;
$this->photo = $obj->photo;
$this->id = $obj->rowid;
$this->name = $obj->name;
$this->address = $obj->address;
$this->zip = $obj->zip;
$this->town = $obj->town;
$this->status = $obj->status;
$this->db->free($result);
}
else
{
$this->error="EMPLOYEENOTFOUND";
dol_syslog(get_class($this)."::fetch user not found", LOG_DEBUG);
return 1;
$this->db->free($result);
return 0;
}
}
else
{

View File

@ -34,6 +34,7 @@ class Establishment extends CommonObject
public $fk_element = 'fk_establishment';
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
var $id;
var $rowid;
var $name;
@ -43,6 +44,8 @@ class Establishment extends CommonObject
var $status; // 0=open, 1=closed
var $entity;
var $country_id;
var $statuts=array();
var $statuts_short=array();
@ -69,12 +72,18 @@ class Establishment extends CommonObject
*/
function create($user)
{
global $conf;
global $conf, $langs;
$error = 0;
$ret = 0;
$now=dol_now();
// Clean parameters
$this->address=($this->address>0?$this->address:$this->address);
$this->zip=($this->zip>0?$this->zip:$this->zip);
$this->town=($this->town>0?$this->town:$this->town);
$this->country_id=($this->country_id>0?$this->country_id:$this->country_id);
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."establishment (";
@ -83,22 +92,22 @@ class Establishment extends CommonObject
$sql.= ", zip";
$sql.= ", town";
$sql.= ", status";
$sql.= ", fk_country";
$sql.= ", entity";
$sql.= ", datec";
$sql.= ", fk_user_author";
$sql.= ") VALUES (";
$sql.= " '".$this->name."'";
$sql.= ", '".$this->address."'";
$sql.= ", '".$this->zip."'";
$sql.= ", '".$this->town."'";
$sql.= " '".$this->db->escape($this->name)."'";
$sql.= ", '".$this->db->escape($this->address)."'";
$sql.= ", '".$this->db->escape($this->zip)."'";
$sql.= ", '".$this->db->escape($this->town)."'";
$sql.= ", ".$this->country_id;
$sql.= ", ".$this->status;
$sql.= ", ".$conf->entity;
$sql.= ", '".$this->db->idate($now)."'";
$sql.= ", ". $user->id;
$sql.= ")";
$this->db->begin();
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) {
@ -148,6 +157,7 @@ class Establishment extends CommonObject
$sql .= ", address = '".$this->address."'";
$sql .= ", zip = '".$this->zip."'";
$sql .= ", town = '".$this->town."'";
$sql .= ", status = '".$this->status."'";
$sql .= ", fk_user_mod = " . $user->id;
$sql .= " WHERE rowid = ".$this->id;
@ -172,9 +182,11 @@ class Establishment extends CommonObject
*/
function fetch($id)
{
$sql = "SELECT rowid, name, address, zip, town, status";
$sql.= " FROM ".MAIN_DB_PREFIX."establishment";
$sql.= " WHERE rowid = ".$id;
$sql = "SELECT e.rowid, e.name, e.address, e.zip, e.town, e.status, e.fk_country as country_id,";
$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';
$sql.= " WHERE e.rowid = ".$id;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql);
@ -189,6 +201,10 @@ class Establishment extends CommonObject
$this->town = $obj->town;
$this->status = $obj->status;
$this->country_id = $obj->country_id;
$this->country_code = $obj->country_code;
$this->country = $obj->country;
return 1;
}
else
@ -257,23 +273,23 @@ class Establishment extends CommonObject
}
if ($mode == 2)
{
if ($status==0) return img_picto($langs->trans($this->statuts_short[$status]),'status4').' '.$langs->trans($this->statuts_short[$status]);
if ($status==1) return img_picto($langs->trans($this->statuts_short[$status]),'status8').' '.$langs->trans($this->statuts_short[$status]);
if ($status==0) return img_picto($langs->trans($this->statuts_short[$status]),'statut4').' '.$langs->trans($this->statuts_short[$status]);
if ($status==1) return img_picto($langs->trans($this->statuts_short[$status]),'statut8').' '.$langs->trans($this->statuts_short[$status]);
}
if ($mode == 3)
{
if ($status==0 && ! empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]),'status4');
if ($status==1 && ! empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]),'status8');
if ($status==0 && ! empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]),'statut4');
if ($status==1 && ! empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]),'statut8');
}
if ($mode == 4)
{
if ($status==0 && ! empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]),'status4').' '.$langs->trans($this->statuts[$status]);
if ($status==1 && ! empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]),'status8').' '.$langs->trans($this->statuts[$status]);
if ($status==0 && ! empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]),'statut4').' '.$langs->trans($this->statuts[$status]);
if ($status==1 && ! empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]),'statut8').' '.$langs->trans($this->statuts[$status]);
}
if ($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]),'status4');
if ($status==1 && ! empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'status8');
if ($status==0 && ! empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut4');
if ($status==1 && ! empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]),'statut8');
}
}
@ -298,20 +314,22 @@ class Establishment extends CommonObject
{
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
$this->date_creation = $this->db->jdate($obj->datec);
if ($obj->fk_user_author)
{
$cuser = new User($this->db);
$cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser;
}
if ($obj->fk_user_modif)
if ($obj->fk_user_mod)
{
$muser = new User($this->db);
$muser->fetch($obj->fk_user_mod);
$this->user_modification = $muser;
$this->date_modification = $this->db->jdate($obj->tms);
}
$this->date_creation = $this->db->jdate($obj->datec);
$this->date_modification = $this->db->jdate($obj->tms);
}
$this->db->free($result);
}
@ -321,4 +339,46 @@ class Establishment extends CommonObject
}
}
/**
* Return clicable name (with picto eventually)
*
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
* @return string String with URL
*/
function getNomUrl($withpicto=0)
{
global $langs;
$result='';
$link = '<a href="'.DOL_URL_ROOT.'/hrm/establishment/card.php?id='.$this->id.'">';
$linkend='</a>';
$picto='building';
$label=$langs->trans("Show").': '.$this->name;
if ($withpicto) $result.=($link.img_object($label,$picto).$linkend);
if ($withpicto && $withpicto != 2) $result.=' ';
if ($withpicto != 2) $result.=$link.$this->name.$linkend;
return $result;
}
/**
* Return account country code
*
* @return string country code
*/
function getCountryCode()
{
global $mysoc;
// We return country code of bank account
if (! empty($this->country_code)) return $this->country_code;
// We return country code of managed company
if (! empty($mysoc->country_code)) return $mysoc->country_code;
return '';
}
}

View File

@ -169,8 +169,8 @@ if ($result)
$employeestatic->email=$obj->email;
$employeestatic->gender=$obj->gender;
$employeestatic->societe_id=$obj->fk_soc;
$employeestatic->firstname='';
$employeestatic->lastname=$obj->login;
$userstatic->firstname=$obj->firstname;
$userstatic->lastname=$obj->lastname;
$li=$employeestatic->getNomUrl(1,'',0,0,24,1);

View File

@ -81,34 +81,27 @@ else if ($action == 'add')
if (empty($error))
{
$tmparray=getCountry(GETPOST('country_id','int'),'all',$db,$langs,0);
if (! empty($tmparray['id']))
{
$object->country_id =$tmparray['id'];
$object->country_code =$tmparray['code'];
$object->country_label=$tmparray['label'];
}
$object->address = GETPOST('address', 'alpha');
$object->zip = GETPOST('zipcode', 'alpha');
$object->town = GETPOST('town', 'alpha');
$object->fk_pays = $object->country_id;
$object->country_id = $_POST["country_id"];
$object->status = GETPOST('status','int');
$object->fk_user_author = $user->id;
$object->datec = dol_now();
$id = $object->create($user);
if ($id > 0)
{
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
exit;
}
else
{
setEventMessage($object->error, 'errors');
$action='create';
}
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
}
}
else
{
@ -131,12 +124,7 @@ else if ($action == 'update')
$name = GETPOST('name', 'alpha');
if (empty($name)) {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->trans('NameProperty')), 'errors');
$error ++;
}
$typeid = GETPOST('typeid', 'int');
if (empty($typeid)) {
setEventMessage($langs->trans('ErrorFieldRequired', $langs->trans('TypeProperty')), 'errors');
setEventMessage($langs->trans('ErrorFieldRequired', $langs->trans('Name')), 'errors');
$error ++;
}
@ -145,25 +133,23 @@ else if ($action == 'update')
$object->address = GETPOST('address', 'alpha');
$object->zip = GETPOST('zipcode', 'alpha');
$object->town = GETPOST('town', 'alpha');
$object->fk_pays = GETPOST('country_id', 'int');
$object->rowid = GETPOST('id');
$object->country_id = $_POST["country_id"];
$object->fk_user_mod = $user->id;
$id = $object->update();
$result = $object->update();
if ($id > 0)
if ($result > 0)
{
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $_POST['id']);
exit;
}
else
{
setEventMessage($object->error, 'errors');
$action='create';
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
}
}
} else {
header("Location: card.php?id=" . $id);
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $_POST['id']);
exit;
}
}
@ -193,11 +179,11 @@ if ($action == 'create')
print '<table class="border" width="100%">';
// Name
print '<tr><td class="fieldrequired"><label for="name">'.$langs->trans("Name").'</label></td><td><input name="name" id="name" size="32" value="' . GETPOST("name") . '"></td></tr>';
print '<tr><td>'. fieldLabel('Name','name',1).'</td><td><input name="name" id="name" size="32" value="' . GETPOST("name") . '"></td></tr>';
// Address
print '<tr>';
print '<td><label for="address">' . $langs->trans("Address") . '</label></td>';
print '<td>'.fieldLabel('Address','address',0).'</td>';
print '<td>';
print '<input name="address" id="address" size="32" value="' . $object->address . '">';
print '</td>';
@ -205,7 +191,7 @@ if ($action == 'create')
// Zipcode
print '<tr>';
print '<td><label for="zipcode">' . $langs->trans('Zip') . '</label></td>';
print '<td>'.fieldLabel('Zip','zipcode',0).'</td>';
print '<td>';
print $formcompany->select_ziptown(GETPOST('zipcode', 'alpha'), 'zipcode', array (
'town',
@ -216,7 +202,7 @@ if ($action == 'create')
// Town
print '<tr>';
print '<td><label for="town">' . $langs->trans('Town') . '</label></td>';
print '<td>'.fieldLabel('Town','town',0).'</td>';
print '<td>';
print $formcompany->select_ziptown(GETPOST('town', 'alpha'), 'town', array (
'zipcode',
@ -227,7 +213,7 @@ if ($action == 'create')
// Country
print '<tr>';
print '<td><label for="selectcountry_id">' . $langs->trans("Country") . '</label></td>';
print '<td>'.fieldLabel('Country','selectcountry_id',0).'</td>';
print '<td class="maxwidthonsmartphone">';
print $form->select_country($mysoc->country_id,'country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
@ -236,7 +222,7 @@ if ($action == 'create')
// Status
print '<tr>';
print '<td class="fieldrequired"><label for="status">'.$langs->trans("Status").'</label></td>';
print '<td>'.fieldLabel('Status','status',1).'</td>';
print '<td>';
print $form->selectarray('status',$status2label,GETPOST('status'));
print '</td></tr>';
@ -273,46 +259,43 @@ else if ($id)
// Ref
print "<tr>";
print '<td width="20%">'.$langs->trans("Ref").'</td><td>';
print $object->rowid;
print '<td width="25%">'.$langs->trans("Ref").'</td><td>';
print $object->id;
print '</td></tr>';
// Name
print '<tr><td class="fieldrequired"><label for="name">'.$langs->trans("Name").'</label></td><td>';
print '<tr><td>'.fieldLabel('Name','name',1).'</td><td>';
print '<input name="name" id="name" class="flat" size="32" value="'.$object->name.'">';
print '</td></tr>';
// Address
print '<tr>';
print '<td><label for="address">' . $langs->trans("Address") . '</label></td>';
print '<tr><td>'.fieldLabel('Address','address',0).'</td>';
print '<td>';
print '<input name="address" id="address" size="32" value="' . $object->address . '">';
print '</td>';
print '</tr>';
print '</td></tr>';
// Zipcode / Town
print '<tr><td><label for="zipcode">' . $langs->trans('Zip') . '</label></td><td>';
print '<tr><td>'.fieldLabel('Zip','zipcode',0).'</td><td>';
print $formcompany->select_ziptown($object->zip, 'zipcode', array (
'town',
'selectcountry_id'
), 6) . '</tr>';
print '<tr><td><label for="town">' . $langs->trans('Town') . '</label></td><td>';
print '<tr><td>'.fieldLabel('Town','town',0).'</td><td>';
print $formcompany->select_ziptown($object->town, 'town', array (
'zipcode',
'selectcountry_id'
)) . '</td></tr>';
// Country
print '<tr>';
print '<td><label for="selectcountry_id">' . $langs->trans("Country") . '</label></td>';
print '<tr><td>'.fieldLabel('Country','selectcountry_id',0).'</td>';
print '<td class="maxwidthonsmartphone">';
print $form->select_country($object->fk_pays,'country_id');
print $form->select_country($object->fk_country,'country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
print '</td>';
print '</tr>';
// Status
print '<tr><td><label for="status">'.$langs->trans("Status").'</label></td><td>';
print '<tr><td>'.fieldLabel('Status','status',1).'</td><td>';
print $form->selectarray('status',$status2label,$object->status);
print '</td></tr>';
@ -347,7 +330,7 @@ else if ($id)
// Ref
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td width="50%">';
print $object->rowid;
print $object->id;
print '</td><td width="25%">';
print $linkback;
print '</td></tr>';
@ -379,7 +362,14 @@ else if ($id)
// Country
print '<tr>';
print '<td>'.$langs->trans("Country").'</td>';
print '<td colspan="2">'.getCountry($object->fk_pays,1).'</td>';
print '<td colspan="2">';
if ($object->country_id > 0)
{
$img=picto_from_langcode($object->country_code);
print $img?$img.' ':'';
print getCountry($object->getCountryCode(),0,$db);
}
print '</td>';
print '</tr>';
// Status

View File

@ -22,6 +22,7 @@
require('../../main.inc.php');
require_once DOL_DOCUMENT_ROOT.'/core/lib/hrm.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
$langs->load("admin");