employee.plugin.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <?php
  2. //Déclaration d'un item de menu dans le menu principal
  3. function employee_menu(&$menuItems){
  4. global $myUser;
  5. if(!$myUser->can('employee','read')) return;
  6. $menuItems[] = array(
  7. 'sort'=>3,
  8. 'url'=>'index.php?module=employee',
  9. 'label'=>'Fiche employé',
  10. 'icon'=> 'fas fa-user-tie',
  11. 'color'=> '#1abc9c'
  12. );
  13. }
  14. //Cette fonction va generer une page quand on clique sur Fiche employé dans menu
  15. function employee_page(){
  16. global $_;
  17. if(!isset($_['module']) || $_['module'] !='employee') return;
  18. $page = !isset($_['page']) ? 'list.employee' : $_['page'];
  19. $page = str_replace('..','',$page);
  20. $file = __DIR__.SLASH.'page.'.$page.'.php';
  21. if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
  22. require_once($file);
  23. }
  24. //Fonction executée lors de l'activation du plugin
  25. function employee_install($id){
  26. if($id != 'fr.core.employee') return;
  27. Entity::install(__DIR__);
  28. $dictionnary = new Dictionnary();
  29. $dictionnary->slug = 'employee_employee_job';
  30. if(Dictionnary::rowCount(array('slug'=>$dictionnary->slug)) ==0){
  31. $dictionnary->label = 'Fiche employé : Poste';
  32. $dictionnary->parent = 0;
  33. $dictionnary->state = Dictionnary::ACTIVE;
  34. $dictionnary->save();
  35. $item = new Dictionnary();
  36. $item->slug = 'employee_employee_job_comercial';
  37. $item->label = 'Commercial';
  38. $item->parent = $dictionnary->id;
  39. $item->state = Dictionnary::ACTIVE;
  40. $item->save();
  41. $item = new Dictionnary();
  42. $item->slug = 'employee_employee_job_devloper';
  43. $item->label = 'Analyste Développeur';
  44. $item->parent = $dictionnary->id;
  45. $item->state = Dictionnary::ACTIVE;
  46. $item->save();
  47. $item = new Dictionnary();
  48. $item->slug = 'employee_employee_job_pdg';
  49. $item->label = 'Président Directeur général';
  50. $item->parent = $dictionnary->id;
  51. $item->state = Dictionnary::ACTIVE;
  52. $item->save();
  53. $item = new Dictionnary();
  54. $item->slug = 'employee_employee_job_dg';
  55. $item->label = 'Directeur général';
  56. $item->parent = $dictionnary->id;
  57. $item->state = Dictionnary::ACTIVE;
  58. $item->save();
  59. $item = new Dictionnary();
  60. $item->slug = 'employee_employee_job_hotline';
  61. $item->label = 'Technicien Support';
  62. $item->parent = $dictionnary->id;
  63. $item->state = Dictionnary::ACTIVE;
  64. $item->save();
  65. $item = new Dictionnary();
  66. $item->slug = 'employee_employee_job_technician';
  67. $item->label = 'Technicien réseau système';
  68. $item->parent = $dictionnary->id;
  69. $item->state = Dictionnary::ACTIVE;
  70. $item->save();
  71. $item = new Dictionnary();
  72. $item->slug = 'employee_employee_job_daf';
  73. $item->label = 'Directeur administratif et financier';
  74. $item->parent = $dictionnary->id;
  75. $item->state = Dictionnary::ACTIVE;
  76. $item->save();
  77. }
  78. $dictionnary = new Dictionnary();
  79. $dictionnary->slug = 'employee_employee_statute';
  80. if(Dictionnary::rowCount(array('slug'=>$dictionnary->slug)) ==0){
  81. $dictionnary->label = 'Fiche employé : Statut';
  82. $dictionnary->parent = 0;
  83. $dictionnary->state = Dictionnary::ACTIVE;
  84. $dictionnary->save();
  85. $item = new Dictionnary();
  86. $item->slug = 'employee_employee_statute_employee';
  87. $item->label = 'Salarié non cadre';
  88. $item->parent = $dictionnary->id;
  89. $item->state = Dictionnary::ACTIVE;
  90. $item->save();
  91. $item = new Dictionnary();
  92. $item->slug = 'employee_employee_statute_cadre';
  93. $item->label = 'Salarié Cadre';
  94. $item->parent = $dictionnary->id;
  95. $item->state = Dictionnary::ACTIVE;
  96. $item->save();
  97. }
  98. $dictionnary = new Dictionnary();
  99. $dictionnary->slug = 'employee_employee_contractType';
  100. if(Dictionnary::rowCount(array('slug'=>$dictionnary->slug)) ==0){
  101. $dictionnary->label = 'Fiche employé : Type de contrat';
  102. $dictionnary->parent = 0;
  103. $dictionnary->state = Dictionnary::ACTIVE;
  104. $dictionnary->save();
  105. $item = new Dictionnary();
  106. $item->slug = 'employee_employee_contractType_cdd';
  107. $item->label = 'CDD';
  108. $item->parent = $dictionnary->id;
  109. $item->state = Dictionnary::ACTIVE;
  110. $item->save();
  111. $item = new Dictionnary();
  112. $item->slug = 'employee_employee_contractType_cdi';
  113. $item->label = 'CDI';
  114. $item->parent = $dictionnary->id;
  115. $item->state = Dictionnary::ACTIVE;
  116. $item->save();
  117. $item = new Dictionnary();
  118. $item->slug = 'employee_employee_contractType_apprentissage';
  119. $item->label = 'Contrat d\'apprentissage (alternance)';
  120. $item->parent = $dictionnary->id;
  121. $item->state = Dictionnary::ACTIVE;
  122. $item->save();
  123. $item = new Dictionnary();
  124. $item->slug = 'employee_employee_contractType_professionalisation';
  125. $item->label = 'Contrat de professionnalisation (alternance)';
  126. $item->parent = $dictionnary->id;
  127. $item->state = Dictionnary::ACTIVE;
  128. $item->save();
  129. }
  130. $dictionnary = new Dictionnary();
  131. $dictionnary->slug = 'employee_employee_hardware';
  132. if(Dictionnary::rowCount(array('slug'=>$dictionnary->slug)) ==0){
  133. $dictionnary->label = 'Fiche employé : Mise a disposition de matériel';
  134. $dictionnary->parent = 0;
  135. $dictionnary->state = Dictionnary::ACTIVE;
  136. $dictionnary->save();
  137. $item = new Dictionnary();
  138. $item->slug = 'employee_employee_hardware_pc';
  139. $item->label = 'Ordinateur portable';
  140. $item->parent = $dictionnary->id;
  141. $item->state = Dictionnary::ACTIVE;
  142. $item->save();
  143. $item = new Dictionnary();
  144. $item->slug = 'employee_employee_hardware_phone';
  145. $item->label = 'Téléphone portable';
  146. $item->parent = $dictionnary->id;
  147. $item->state = Dictionnary::ACTIVE;
  148. $item->save();
  149. $item = new Dictionnary();
  150. $item->slug = 'employee_employee_hardware_car';
  151. $item->label = 'Voiture de fonction';
  152. $item->parent = $dictionnary->id;
  153. $item->state = Dictionnary::ACTIVE;
  154. $item->save();
  155. $item = new Dictionnary();
  156. $item->slug = 'employee_employee_hardware_car_service';
  157. $item->label = 'Voiture de service';
  158. $item->parent = $dictionnary->id;
  159. $item->state = Dictionnary::ACTIVE;
  160. $item->save();
  161. }
  162. }
  163. //Fonction executée lors de la désactivation du plugin
  164. function employee_uninstall($id){
  165. if($id != 'fr.core.employee') return;
  166. Entity::uninstall(__DIR__);
  167. $dictionnary = Dictionnary::bySlug('employee_employee_job');
  168. if($dictionnary!= false && $dictionnary->id!=0){
  169. Dictionnary::delete(array('parent'=>$dictionnary->id));
  170. Dictionnary::delete(array('id'=>$dictionnary->id));
  171. }
  172. $dictionnary = Dictionnary::bySlug('employee_employee_statute');
  173. if($dictionnary!= false && $dictionnary->id!=0){
  174. Dictionnary::delete(array('parent'=>$dictionnary->id));
  175. Dictionnary::delete(array('id'=>$dictionnary->id));
  176. }
  177. $dictionnary = Dictionnary::bySlug('employee_employee_contractType');
  178. if($dictionnary!= false && $dictionnary->id!=0){
  179. Dictionnary::delete(array('parent'=>$dictionnary->id));
  180. Dictionnary::delete(array('id'=>$dictionnary->id));
  181. }
  182. $dictionnary = Dictionnary::bySlug('employee_employee_hardware');
  183. if($dictionnary!= false && $dictionnary->id!=0){
  184. Dictionnary::delete(array('parent'=>$dictionnary->id));
  185. Dictionnary::delete(array('id'=>$dictionnary->id));
  186. }
  187. }
  188. Right::register("employee",array('label'=>"Gestion des droits sur le plugin Fiche employé"));
  189. //cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html
  190. function employee_action(){
  191. require_once(__DIR__.SLASH.'action.php');
  192. }
  193. //Déclaration du menu de réglages
  194. function employee_menu_setting(&$settingMenu){
  195. global $myUser;
  196. if(!$myUser->can('employee','configure')) return;
  197. $settingMenu[]= array(
  198. 'sort' =>1,
  199. 'url' => 'setting.php?section=global.employee',
  200. 'icon' => 'fas fa-angle-right',
  201. 'label' => 'Fiche employé'
  202. );
  203. }
  204. //Déclaration des pages de réglages
  205. function employee_content_setting(){
  206. global $_;
  207. if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
  208. require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
  209. }
  210. require_once(__DIR__.SLASH.'action.php');
  211. //Déclaration des settings de base
  212. //Types possibles : voir FieldType.class.php. Un simple string définit une catégorie.
  213. Configuration::setting('employee',array(
  214. "Général",
  215. 'employee_default_worktime' => array("label"=>"Heures hebdomadaires de travail par défaut","placeholder"=>"ex: 39","type"=>"number"),
  216. 'employee_save_recipients' => array("label"=>"Destinataires des notifications de creation de fiche","placeholder"=>"", "type"=>"user", "attributes"=>
  217. array(
  218. "data-multiple"=>true,
  219. "data-types"=>"user,rank"
  220. )
  221. )
  222. ));
  223. Right::register('employee',array('label'=>'Permissions sur les employés'));
  224. global $myFirm;
  225. if($myFirm->has_plugin('fr.core.export')){
  226. require_once(__ROOT__.PLUGIN_PATH.'export'.SLASH.'ExportModel.class.php');
  227. require_once(__ROOT__.PLUGIN_PATH.'export'.SLASH.'template'.SLASH.'WordExport.class.php');
  228. ExportModel::add('employee','employee-sheet', 'Fiche employé', function($parameters){
  229. global $myUser;
  230. require_once(__DIR__.SLASH.'Employee.class.php');
  231. require_once(__DIR__.SLASH.'EmployeeWorkTime.class.php');
  232. require_once(__DIR__.SLASH.'EmployeeContract.class.php');
  233. $employee = new Employee();
  234. $contract = new EmployeeContract();
  235. $workTime = new EmployeeWorkTime();
  236. if(!empty($parameters['id'])){
  237. $employee = Employee::getById($parameters['id']);
  238. $contracts = EmployeeContract::staticQuery('SELECT main.*,'.EmployeeWorkTime::joinString('wt').' FROM {{table}} main LEFT JOIN '.EmployeeWorkTime::tableName().' wt ON main.worktime = wt.id WHERE (main.`end` IS NULL OR main.`end` = "" OR main.`end` > ?) AND main.employee=? LIMIT 1',array(time(),$employee->id),true,1);
  239. if(isset($contracts[0])) $contract= $contracts[0];
  240. $workTime = $contract->join('worktime');
  241. }
  242. $job = Dictionnary::getById($employee->job);
  243. $statute = Dictionnary::getById($contract->statute);
  244. $contractType = Dictionnary::getById($contract->type);
  245. $job = !$job ? new Dictionnary() : $job ;
  246. $statute = !$statute ? new Dictionnary() : $statute ;
  247. $contractType = !$contractType ? new Dictionnary() : $contractType ;
  248. $workTime = !$workTime ? new EmployeeWorkTime() : $workTime ;
  249. $hardwareTypes = Dictionnary::slugToArray('employee_employee_hardware',true);
  250. $hardwares = array();
  251. $employee->hardware = json_decode($employee->hardware,true);
  252. if(is_array($employee->hardware)){
  253. foreach ($employee->hardware as $value) {
  254. $hardwares[] = $hardwareTypes[$value]->label;
  255. }
  256. }
  257. $manager = $employee->manager !=0 ? Employee::getById($employee->manager) : new Employee();
  258. $employee->jobDescription = strip_tags(str_replace(array('<br>','<br/>','<p>'),PHP_EOL,html_entity_decode($employee->jobDescription)));
  259. $employee->comment = strip_tags(str_replace(array('<br>','<br/>','<p>'),PHP_EOL,html_entity_decode($employee->comment)));
  260. $data['employe'] = array('label'=>'Employé', 'type'=>'object','value' => array());
  261. $data['employe']['value']['nom'] = array('label' => 'Nom de l\'employé','value' => $employee->name);
  262. $data['employe']['value']['nom-naissance'] = array('label' => 'Nom de naissance de l\'employé','value' => $employee->birthName);
  263. $data['employe']['value']['prenom'] = array('label' => 'Prénom l\'employé','value' =>$employee->firstname);
  264. $data['employe']['value']['poste'] = array('label' => 'Poste de l\'employé','value' =>$job->label);
  265. $data['employe']['value']['role'] = array('label' => 'Rôle/Missions','value' => WordExport::convert_text_format(html_entity_decode($employee->jobDescription)) );
  266. $data['employe']['value']['status'] = array('label' => 'Status','value' =>$statute->label);
  267. $data['employe']['value']['manager'] = array('label' => 'Responsable','value' =>$manager->fullName());
  268. $data['employe']['value']['lieu-travail'] = array('label' => 'Lieu de travail','value' =>$employee->workplace);
  269. $data['employe']['value']['debut-contrat'] = array('label' => 'Date de début de contrat','value' =>date('d/m/Y',$contract->start));
  270. $data['employe']['value']['type-contrat'] = array('label' => 'Type de contrat','value' =>$contractType->label);
  271. $data['employe']['value']['motif-cdd'] = array('label' => 'Motif contrat','value' =>$contract->comment);
  272. $data['employe']['value']['fin-contrat'] = array('label' => 'Date de fin CDD','value' =>date('d/m/Y',$contract->end));
  273. $data['employe']['value']['temps-travail'] = array('label' => 'Temps de travail','value' =>$workTime->label);
  274. $data['employe']['value']['heures-semaine'] = array('label' => 'Heures par semaines','value' =>$workTime->hourByWeek);
  275. $data['employe']['value']['jours-an'] = array('label' => 'Jours par an','value' =>$workTime->dayByYear);
  276. $data['employe']['value']['materiel'] = array('label' => 'Matériel alloué','value' => WordExport::convert_text_format(implode(', ',$hardwares)) );
  277. $data['employe']['value']['date'] = array('label' => 'Date','value' => date('d/m/Y',$contract->start));
  278. $path = $employee->picture();
  279. $stream = file_exists($path) ? file_get_contents($path) : '';
  280. $data['employe']['value']['photo'] = array(
  281. 'label'=>'Photo de l\'employé',
  282. 'type'=>'image',
  283. 'value' => $stream
  284. );
  285. return $data;
  286. });
  287. }
  288. function employee_notification_type(&$types){
  289. global $conf;
  290. $types['employee'] = array(
  291. 'category' =>'RH',
  292. 'label' =>'Fiche employé',
  293. 'color' =>'#dc3545',
  294. 'icon' =>'fas fa-user-tie',
  295. 'description' => "Notification lorsqu'une fiche emoployé est créée",
  296. 'default_methods' => array(
  297. 'interface' => !empty($conf->get('employee_interface')) ? $conf->get('employee_interface') : true,
  298. 'mail' => !empty($conf->get('employee_mail')) ? $conf->get('employee_mail') : true
  299. )
  300. );
  301. }
  302. //Déclation des assets
  303. Plugin::addCss("/css/main.css");
  304. Plugin::addJs("/js/main.js");
  305. Plugin::addCss("/css/component.css");
  306. Plugin::addJs("/js/component.js");
  307. //Mapping hook / fonctions
  308. Plugin::addHook("install", "employee_install");
  309. Plugin::addHook("uninstall", "employee_uninstall");
  310. Plugin::addHook("menu_main", "employee_menu");
  311. Plugin::addHook("page", "employee_page");
  312. Plugin::addHook("menu_setting", "employee_menu_setting");
  313. Plugin::addHook("content_setting", "employee_content_setting");
  314. Plugin::addHook("notification_type", "employee_notification_type");
  315. ?>