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 '
| '.$langs->trans("Ref").' | '; - print ''.$langs->trans("Name").' | '; - print ''.$langs->trans("Address").' | '; - print ''.$langs->trans("Zipcode").' | '; - print ''.$langs->trans("Town").' | '; - print ''.$langs->trans("Status").' | '; - print '
| '.img_object($langs->trans("ShowEstablishment"),"building").' '.$obj->rowid.' | '; - print ''.$obj->name.' | '; + + $establishmentstatic->id=$obj->rowid; + $establishmentstatic->name=$obj->name; + + $var=!$var; + print '||||
| '.$establishmentstatic->getNomUrl(1).' | '; print ''.$obj->address.' | '; print ''.$obj->zip.' | '; print ''.$obj->town.' | '; - print ''.$establishmentstatic->LibStatut($obj->status,5).' | '; - print ''; + print $establishmenttmp->getLibStatus(5); + 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..88b765740ef 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; @@ -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 = ''; + $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; + } + + /** + * 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/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..10a1b42e961 100644 --- a/htdocs/hrm/establishment/card.php +++ b/htdocs/hrm/establishment/card.php @@ -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 '
| '. fieldLabel('Name','name',1).' | ||||
| '; + print ' | '.fieldLabel('Address','address',0).' | '; print ''; print ''; print ' | '; @@ -205,7 +191,7 @@ if ($action == 'create') // Zipcode print '||
| '; + print ' | '.fieldLabel('Zip','zipcode',0).' | '; print ''; print $formcompany->select_ziptown(GETPOST('zipcode', 'alpha'), 'zipcode', array ( 'town', @@ -216,7 +202,7 @@ if ($action == 'create') // Town print ' | ||
| '; + print ' | '.fieldLabel('Town','town',0).' | '; print ''; print $formcompany->select_ziptown(GETPOST('town', 'alpha'), 'town', array ( 'zipcode', @@ -227,7 +213,7 @@ if ($action == 'create') // Country print ' | ||
| '; + print ' | '.fieldLabel('Country','selectcountry_id',0).' | '; print ''; 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 ' | ||
| '; + print ' | '.fieldLabel('Status','status',1).' | '; print ''; 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 ' | |||
| '; + print ' | ||||
| '.fieldLabel('Address','address',0).' | '; print ''; print ''; - 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' )) . ' | |||
| '; + print ' | ||||
| '.fieldLabel('Country','selectcountry_id',0).' | '; print ''; - 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 '|||
| '; + 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").' | '; - print ''.getCountry($object->fk_pays,1).' | '; + print ''; + if ($object->country_id > 0) + { + $img=picto_from_langcode($object->country_code); + print $img?$img.' ':''; + print getCountry($object->getCountryCode(),0,$db); + } + print ' | '; print '||