From e1b329e80a8c52bd07be5f161d1e6f6ad1c6aaa2 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Wed, 11 Nov 2015 08:16:06 +0100 Subject: [PATCH 1/2] HRM: Update work --- htdocs/hrm/admin/admin_establishment.php | 79 +++++++++++++------- htdocs/hrm/class/employee.class.php | 37 +++++++--- htdocs/hrm/class/establishment.class.php | 74 ++++++++++++++----- htdocs/hrm/employee/list.php | 4 +- htdocs/hrm/establishment/card.php | 91 ++++++++++-------------- htdocs/hrm/establishment/info.php | 1 + 6 files changed, 174 insertions(+), 112 deletions(-) diff --git a/htdocs/hrm/admin/admin_establishment.php b/htdocs/hrm/admin/admin_establishment.php index 771f2e243bc..26e11dd6b94 100644 --- a/htdocs/hrm/admin/admin_establishment.php +++ b/htdocs/hrm/admin/admin_establishment.php @@ -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 ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ""; + 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 "\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 ''; - print ''; - print ''; + + $establishmentstatic->id=$obj->rowid; + $establishmentstatic->name=$obj->name; + + $var=!$var; + print ''; + print ''; print ''; print ''; print ''; - print ''; - print ''; - $var=!$var; + + print ''; + print "\n"; + $i++; } diff --git a/htdocs/hrm/class/employee.class.php b/htdocs/hrm/class/employee.class.php index 4014bb717f2..1a1350b3b63 100644 --- a/htdocs/hrm/class/employee.class.php +++ b/htdocs/hrm/class/employee.class.php @@ -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 { diff --git a/htdocs/hrm/class/establishment.class.php b/htdocs/hrm/class/establishment.class.php index c5ba77fd547..ac1752266c3 100644 --- a/htdocs/hrm/class/establishment.class.php +++ b/htdocs/hrm/class/establishment.class.php @@ -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; @@ -257,23 +267,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 +308,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 +333,28 @@ 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 = ''; + $linkend=''; + + $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; + } } diff --git a/htdocs/hrm/employee/list.php b/htdocs/hrm/employee/list.php index 1635ba41cda..46c59e90937 100644 --- a/htdocs/hrm/employee/list.php +++ b/htdocs/hrm/employee/list.php @@ -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); diff --git a/htdocs/hrm/establishment/card.php b/htdocs/hrm/establishment/card.php index 533ad5117ff..b63e4e09592 100644 --- a/htdocs/hrm/establishment/card.php +++ b/htdocs/hrm/establishment/card.php @@ -81,34 +81,29 @@ 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 = GETPOST('country_id','int')?GETPOST('country_id','int'):$mysoc->country_id; + $object->country_id = $object->country_id?$object->country_id:$mysoc->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 +126,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 +135,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 = GETPOST('country_id', 'int'); $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 +181,11 @@ if ($action == 'create') print '
'.$langs->trans("Ref").''.$langs->trans("Name").''.$langs->trans("Address").''.$langs->trans("Zipcode").''.$langs->trans("Town").''.$langs->trans("Status").'
'.img_object($langs->trans("ShowEstablishment"),"building").' '.$obj->rowid.''.$obj->name.'
'.$establishmentstatic->getNomUrl(1).''.$obj->address.''.$obj->zip.''.$obj->town.''.$establishmentstatic->LibStatut($obj->status,5).'
'; + print $establishmenttmp->getLibStatus(5); + print '
'; // Name - print ''; + print ''; // Address print ''; - print ''; + print ''; print ''; @@ -205,7 +193,7 @@ if ($action == 'create') // Zipcode print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; @@ -273,46 +261,43 @@ else if ($id) // Ref print ""; - print ''; // Name - print ''; // Address - print ''; - print ''; + print ''; print ''; - print ''; + print ''; // Zipcode / Town - print ''; - print ''; // Country - print ''; - print ''; + print ''; print ''; print ''; // Status - print ''; @@ -347,7 +332,7 @@ else if ($id) // Ref print ''; @@ -379,7 +364,7 @@ else if ($id) // Country print ''; print ''; - print ''; + print ''; print ''; // Status diff --git a/htdocs/hrm/establishment/info.php b/htdocs/hrm/establishment/info.php index 2bf014481ac..806bd893fbb 100644 --- a/htdocs/hrm/establishment/info.php +++ b/htdocs/hrm/establishment/info.php @@ -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"); From e157d8b8d20831eb2b1409a2a93f935b43db376a Mon Sep 17 00:00:00 2001 From: aspangaro Date: Wed, 11 Nov 2015 08:52:28 +0100 Subject: [PATCH 2/2] Update for fk_country --- htdocs/hrm/class/establishment.class.php | 30 +++++++++++++++++++++--- htdocs/hrm/establishment/card.php | 15 ++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/htdocs/hrm/class/establishment.class.php b/htdocs/hrm/class/establishment.class.php index ac1752266c3..88b765740ef 100644 --- a/htdocs/hrm/class/establishment.class.php +++ b/htdocs/hrm/class/establishment.class.php @@ -182,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); @@ -199,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 @@ -357,4 +363,22 @@ class Establishment extends CommonObject 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 ''; + } } diff --git a/htdocs/hrm/establishment/card.php b/htdocs/hrm/establishment/card.php index b63e4e09592..10a1b42e961 100644 --- a/htdocs/hrm/establishment/card.php +++ b/htdocs/hrm/establishment/card.php @@ -84,9 +84,7 @@ else if ($action == 'add') $object->address = GETPOST('address', 'alpha'); $object->zip = GETPOST('zipcode', 'alpha'); $object->town = GETPOST('town', 'alpha'); - $object->country_id = GETPOST('country_id','int')?GETPOST('country_id','int'):$mysoc->country_id; - $object->country_id = $object->country_id?$object->country_id:$mysoc->country_id; - $object->country_id = $_POST["country_id"]; + $object->country_id = $_POST["country_id"]; $object->status = GETPOST('status','int'); $object->fk_user_author = $user->id; $object->datec = dol_now(); @@ -135,7 +133,7 @@ else if ($action == 'update') $object->address = GETPOST('address', 'alpha'); $object->zip = GETPOST('zipcode', 'alpha'); $object->town = GETPOST('town', 'alpha'); - $object->country_id = GETPOST('country_id', 'int'); + $object->country_id = $_POST["country_id"]; $object->fk_user_mod = $user->id; $result = $object->update(); @@ -364,7 +362,14 @@ else if ($id) // Country print ''; print ''; - print ''; + print ''; print ''; // Status
'. fieldLabel('Name','name',1).'
'.fieldLabel('Address','address',0).''; print ''; print '
'.fieldLabel('Zip','zipcode',0).''; print $formcompany->select_ziptown(GETPOST('zipcode', 'alpha'), 'zipcode', array ( 'town', @@ -216,7 +204,7 @@ if ($action == 'create') // Town print '
'.fieldLabel('Town','town',0).''; print $formcompany->select_ziptown(GETPOST('town', 'alpha'), 'town', array ( 'zipcode', @@ -227,7 +215,7 @@ if ($action == 'create') // Country print '
'.fieldLabel('Country','selectcountry_id',0).''; print $form->select_country($mysoc->country_id,'country_id'); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); @@ -236,7 +224,7 @@ if ($action == 'create') // Status print '
'.fieldLabel('Status','status',1).''; print $form->selectarray('status',$status2label,GETPOST('status')); print '
'.$langs->trans("Ref").''; - print $object->rowid; + print ''.$langs->trans("Ref").''; + print $object->id; print '
'; + print '
'.fieldLabel('Name','name',1).''; print ''; print '
'.fieldLabel('Address','address',0).''; print ''; - print '
'; + print '
'.fieldLabel('Zip','zipcode',0).''; print $formcompany->select_ziptown($object->zip, 'zipcode', array ( 'town', 'selectcountry_id' ), 6) . '
'; + print '
'.fieldLabel('Town','town',0).''; print $formcompany->select_ziptown($object->town, 'town', array ( 'zipcode', 'selectcountry_id' )) . '
'.fieldLabel('Country','selectcountry_id',0).''; - 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 '
'; + print '
'.fieldLabel('Status','status',1).''; print $form->selectarray('status',$status2label,$object->status); print '
'.$langs->trans("Ref").''; - print $object->rowid; + print $object->id; print ''; print $linkback; print '
'.$langs->trans("Country").''.getCountry($object->fk_pays,1).''.getCountry($object->fk_country,1).'
'.$langs->trans("Country").''.getCountry($object->fk_country,1).''; + if ($object->country_id > 0) + { + $img=picto_from_langcode($object->country_code); + print $img?$img.' ':''; + print getCountry($object->getCountryCode(),0,$db); + } + print '