1<?php
2
3/*
4 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
5 * all the essential functionalities required for any enterprise.
6 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
7 *
8 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
9 * the GNU General Public License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with this program;
17 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA  02110-1301, USA
19 */
20
21/**
22 * EmployeeService class file
23 */
24
25/**
26 * Employee Service
27 * @package pim
28 * @todo Remove exceptions that only wraps DAO exceptions [DONE]
29 * @todo Add get/save/delete for all [DONE: Postponed. Will add on request]
30 * @todo Add deleteReportingMethod() function [DONE: Refer ReportingMethodConfigurationService]
31 * @todo Add getEmployeeImmigrationRecords method [DONE]
32 * @todo Add getEmployeeChildren method [DONE: Refer dependents methods]
33 * @todo All methods to return PIMServiceException or DaoException consistantly [DONE]
34 * @todo Don't wrap DAO exceptions. [DONE]
35 * @todo Deside if all methods need to have try catch blocks [DONE]
36 * @todo Show class hierarchy (inheritance) of all the classes in the API
37 */
38class EmployeeService extends BaseService {
39
40    /**
41     * @ignore
42     */
43    private $employeeDao;
44    private $configurationService;
45
46    const EMPLOYEE_COUNT_CHANGE = 10;
47    const EMPLOYEE_ACTIVE_COUNT = 1;
48    const EMPLOYEE_INACTIVE_COUNT = 2;
49    /**
50     * Get Employee Dao
51     * @return EmployeeDao
52     * @ignore
53     */
54    public function getEmployeeDao() {
55        return $this->employeeDao;
56    }
57
58    /**
59     * Set Employee Dao
60     * @param EmployeeDao $employeeDao
61     * @return void
62     * @ignore
63     */
64    public function setEmployeeDao(EmployeeDao $employeeDao) {
65        $this->employeeDao = $employeeDao;
66    }
67
68    /**
69     * Set Configuration Service
70     * @param ConfigService $configurationService
71     * @return void
72     * @ignore
73     */
74    public function setConfigurationService(ConfigService $configurationService) {
75        $this->configurationService = $configurationService;
76    }
77
78    /**
79     * Get Configuration Service
80     * @return ConfigService
81     * @ignore
82     */
83    public function getConfigurationService() {
84        if($this->configurationService) {
85            return $this->configurationService;
86        } else {
87            return new ConfigService();
88        }
89    }
90
91    /**
92     * Construct
93     * @ignore
94     */
95    public function __construct() {
96        $this->employeeDao = new EmployeeDao();
97    }
98
99    /**
100     * Save an employee
101     *
102     * If empNumber is not set, it will be set to next available value and a
103     * new employee will be added.
104     *
105     * If empNumber is set, and it belongs to an existing employee, the employee
106     * is updated.
107     *
108     * If empNumber is set and it does not belong to an existing employee, a
109     * new employee is added. The caller has to update the unique id using
110     * IDGeneratorService.
111     *
112     * @version 2.6.11
113     * @param Employee $employee
114     * @return Employee Saved Employee object
115     * @throws DaoException
116     *
117     * @todo Return Saved Employee [DONE]
118     * @todo Change method name to saveEmployee [DONE]
119     */
120    public function saveEmployee(Employee $employee) {
121        $savedEmployee =$this->getEmployeeDao()->saveEmployee($employee);
122
123        if ($savedEmployee) {
124            $this->checkEmployeeCountChange(self::EMPLOYEE_ACTIVE_COUNT);
125        }
126        return $savedEmployee;
127    }
128
129    /**
130     * Get employee for given empNumber
131     *
132     * @version 2.6.11
133     * @param int $empNumber Employee number
134     * @return Employee Employee instance if found or NULL
135     * @throws DaoException
136     */
137    public function getEmployee($empNumber) {
138        return $this->getEmployeeDao()->getEmployee($empNumber);
139    }
140
141    /**
142     * Get an employee by employee ID
143     *
144     * @version 2.6.12.1
145     * @param string $employeeId Employee ID
146     * @return Employee Employee instance if found or false
147     * @todo return null if not found (instead of returning false) [DONE]
148     */
149    public function getEmployeeByEmployeeId($employeeId) {
150        return $this->getEmployeeDao()->getEmployeeByEmployeeId($employeeId);
151    }
152
153    /**
154     * Get the default employee id to be used for next employee being
155     * added to the system.
156     *
157     * @return employee id based on empNumber
158     *
159     * @ignore
160     */
161    public function getDefaultEmployeeId() {
162        $idGenService = new IDGeneratorService();
163        $idGenService->setEntity(new Employee());
164        return (int)$idGenService->getNextID(false);
165    }
166
167    /**
168     * Retrieve picture for given employee number
169     *
170     * @version 2.6.11
171     * @param int $empNumber
172     * @return EmpPicture EmpPicture or null if no picture found
173     * @throws DaoException
174     *
175     * @todo Rename to getEmployeePicture [DONE]
176     */
177    public function getEmployeePicture($empNumber) {
178        return $this->getEmployeeDao()->getEmployeePicture($empNumber);
179    }
180
181    /**
182     * Save Employee Contact Details of given employee
183     *
184     * @version 2.6.11
185     * @param Employee $employee
186     * @return boolean
187     * @throws DaoException
188     *
189     * @todo Don't return any value (currently returns true always) [DONE: Decided to remove this method and use saveEmployee()]
190     * @todo Exceptions should preserve previous exception [DONE]
191     */
192    /*
193    public function saveContactDetails(Employee $employee) {
194        return $this->getEmployeeDao()->saveContactDetails($employee);
195    }
196    */
197
198    /**
199     * Get Emergency contacts for given employee
200     *
201     * @version 2.6.11
202     * @param int $empNumber Employee Number
203     * @return array EmpEmergencyContact objects as array. Array will be empty
204     *               if no emergency contacts defined fo
205     * r employee.
206     * @throws DaoException
207     *
208     * @todo Rename method as getEmployeeEmergencyContacts [DONE]
209     */
210    public function getEmployeeEmergencyContacts($empNumber) {
211        return $this->getEmployeeDao()->getEmployeeEmergencyContacts($empNumber);
212    }
213
214    /**
215     * Delete the given emergency contacts from the given employee
216     *
217     * If $entriesToDelete is not provided (null), all entries of given employee
218     * will be deleted.
219     *
220     * @version 2.6.11
221     * @param int $empNumber Employee Number
222     * @param array $sequenceNumbers Array of emergency contact sequence numbers. Optional.
223     * @return integer Number of records deleted
224     * @throws DaoException
225     *
226     * @todo return number of contacts deleted (currently returns true always) [DONE]
227     * @todo Exceptions should preserve previous exception [DONE]
228     * @todo rename method as deleteEmployeeEmergencyContacts [DONE]
229     */
230    public function deleteEmployeeEmergencyContacts($empNumber, $sequenceNumbers = null) {
231        return $this->getEmployeeDao()->deleteEmployeeEmergencyContacts($empNumber, $sequenceNumbers);
232    }
233
234    /**
235     * Delete the given immigration entries for the given employee.
236     *
237     * If $entriesToDelete is not provided (null), all entries of given employee
238     * will be deleted.
239     *
240     * @version 2.6.11
241     * @param int $empNumber Employee Number
242     * @param array $recordIds Array of immigration record IDs. Optional.
243     * @return integer Number of records deleted
244     * @throws DaoException
245     *
246     * @todo Rename to deleteEmployeeImmigrationRecords [DONE]
247     * @todo return number of entries deleted (currently returns true always) [DONE]
248     */
249    public function deleteEmployeeImmigrationRecords($empNumber, $recordIds = null) {
250        return $this->getEmployeeDao()->deleteEmployeeImmigrationRecords($empNumber, $recordIds);
251    }
252
253    /**
254     * Get dependents for given employee
255     *
256     * @version 2.6.11
257     * @param int $empNumber Employee Number
258     * @return array EmpDependent Array of EmpDependent objects
259     *
260     * @todo Exceptions should preserve previous exception [DONE]
261     * @todo Rename method as getEmployeeDependents [DONE]
262     */
263    public function getEmployeeDependents($empNumber) {
264        return $this->getEmployeeDao()->getEmployeeDependents($empNumber);
265    }
266
267    /**
268     * Delete the given dependents from the given employee
269     *
270     * If $entriesToDelete is not provided (null), all entries of given employee
271     * will be deleted.
272     *
273     * @version 2.6.11
274     * @param int $empNumber Employee Number
275     * @param array $sequenceNumbers Array of dependent seqno values. Optional.
276     * @return integer Number of records deleted
277     * @throws DaoException
278     *
279     * @todo return number of entries deleted (currently returns true always) [DONE]
280     * @todo Exceptions should preserve previous exception [DONE]
281     * @todo Rename method as deleteEmployeeDependents [DONE]
282     */
283    public function deleteEmployeeDependents($empNumber, $sequenceNumbers = null) {
284        return $this->getEmployeeDao()->deleteEmployeeDependents($empNumber, $sequenceNumbers);
285    }
286
287    /**
288     * Check if employee with given employee number is a supervisor
289     * @ignore
290     * @version 2.6.11
291     * @param int $empNumber Employee Number
292     * @return bool True if given employee is a supervisor, false if not
293     *
294     * @todo Exceptions should preserve previous exception [DONE]
295     */
296    public function isSupervisor($empNumber) {
297        return $this->getEmployeeDao()->isSupervisor($empNumber);
298    }
299
300    /**
301     * Delete picture of the given employee
302     *
303     * @version 2.6.11
304     * @param int $empNumber Employee Number
305     * @return integer Returns 1
306     * @throws DaoException
307     *
308     * @todo Don't return any value (currently returns true always) [DONE: Decided to return query value]
309     * @todo Exceptions should preserve previous exception [DONE]
310     * @todo Rename to deleteEmployeePicture (to match with get method) [DONE]
311     */
312    public function deleteEmployeePicture($empNumber) {
313        return $this->getEmployeeDao()->deleteEmployeePicture($empNumber);
314    }
315
316    /**
317     * Save the given employee picture.
318     *
319     * @version 2.6.11
320     * @param EmpPicture $empPicture EmpPicture object to save
321     * @return EmpPicture Saved EmpPicture object
322     * @throws DaoException
323     *
324     * @todo Return saved EmpPicture [DONE]
325     * @todo Exceptions should preserve previous exception [DONE]
326     * @todo Rename to savePicture (without Employee) to match other methods [DONE: Won't change. Complies with new reules]
327     */
328    public function saveEmployeePicture(EmpPicture $empPicture) {
329        return $this->getEmployeeDao()->saveEmployeePicture($empPicture);
330    }
331
332    /**
333     * Save given employee immigration entry
334     *
335     * @version 2.6.11
336     * @param EmployeeImmigrationRecord $employeeImmigrationRecord EmployeeImmigrationRecord instance
337     * @return EmployeeImmigrationRecord Saved EmployeeImmigrationRecord object
338     *
339     * @todo Rename to saveEmployeeImmigrationEntry (without Employee) and change Passport -> Immigration [DONE: Renamed to saveEmployeeImmigrationRecord]
340     * @todo Rename EmpPassport to EmpImmigrationRecord [DONE]
341     * @todo return saved EmpImmigrationRecord [DONE]
342     */
343    public function saveEmployeeImmigrationRecord(EmployeeImmigrationRecord $employeeImmigrationRecord) {
344        return $this->getEmployeeDao()->saveEmployeeImmigrationRecord($employeeImmigrationRecord);
345    }
346
347    /**
348     * Get Employee Immigration Record(s) for given employee.
349     *
350     * @version 2.6.11
351     * @param int $empNumber Employee Number
352     * @param int $recordId Immigration Record sequence Number (optional)
353     *
354     * @return Doctrine_Collection/EmployeeImmigrationRecord If sequenceNo is given returns matching
355     * Immigration Record or false if not found. If sequenceNo is not given, returns Immigration
356     * Record collection. (Empty collection if no records available)
357     *
358     * @todo rename to getEmployeeImmigrationRecords [DONE]
359     * @todo rename $sequenceNo to a meaningful values. Ex: $recordId [DONE]
360     */
361    public function getEmployeeImmigrationRecords($empNumber, $recordId = null) {
362        return $this->getEmployeeDao()->getEmployeeImmigrationRecords($empNumber, $recordId);
363    }
364
365    /**
366     * Save given Work Experience Record
367     *
368     * @version 2.6.11
369     * @param EmpWorkExperience $empWorkExp Work Experience record to save
370     * @return EmpWorkExperience Saved EmpWorkExperience object
371     * @throws DaoException
372     *
373     * @todo return saved work Experience [DONE]
374     * @todo rename method as saveEmployeeWorkExperience [DONE]
375     */
376    public function saveEmployeeWorkExperience(EmpWorkExperience $empWorkExp) {
377        return $this->getEmployeeDao()->saveEmployeeWorkExperience($empWorkExp);
378    }
379
380    /**
381     * Get Work Experience Record(s) for given employee
382     *
383     * @version 2.6.11
384     * @param int $empNumber Employee number
385     * @param int $recordId Work Experience record sequence number
386     *
387     * @return Doctrine_Collection/WorkExperience  If sequenceNo is given returns matching
388     * EmpWorkExperience or false if not found. If sequenceNo is not given, returns
389     * EmpWorkExperience collection. (Empty collection if no records available)
390     * @throws DaoException
391     *
392     * @todo Rename method as getEmployeeWorkExperienceRecords [DONE]
393     */
394    public function getEmployeeWorkExperienceRecords($empNumber, $recordId = null) {
395        return $this->getEmployeeDao()->getEmployeeWorkExperienceRecords($empNumber, $recordId);
396    }
397
398    /**
399     * Delete given WorkExperience entries from given employee.
400     *
401     * If $entriesToDelete is not provided (null), all entries of given employee
402     * will be deleted.
403     *
404     * @version 2.6.11
405     * @param int $empNumber Employee Number
406     * @param array $entriesToDelete sequenceNos of the work experience
407     *              records to delete. Optional.
408     *
409     * @return integer Number of records deleted
410     * @throws DaoException
411     *
412     * @todo return number of entries deleted [DONE]
413     * @todo rename method as deleteEmployeeWorkExperienceRecords [DONE]
414     */
415    public function deleteEmployeeWorkExperienceRecords($empNumber, $entriesToDelete = null) {
416        return $this->getEmployeeDao()->deleteEmployeeWorkExperienceRecords($empNumber, $entriesToDelete);
417    }
418
419    /**
420     * Get Employee Education with given id
421     *
422     * @ignore
423     *
424     * @version 2.6.11
425     * @param int $id Education Id
426     * @return EmployeeEducation If Id match with records return EmployeeEducation else return false
427     * @throws DaoException
428     *
429     * @todo Rename method as getEmployeeEducation
430     */
431    public function getEducation($id) {
432        return $this->getEmployeeDao()->getEducation($id);
433    }
434
435    /**
436     * Get Education Record(s) for given employee
437     *
438     * @version 2.6.11
439     * @param int $empNumber Employee number
440     * @param int $educationId Education record id
441     *
442     * @return Collection/EmployeeEducation If education id is given returns matching
443     * EmpEducation or false if not found. If educationId is not given, returns
444     * EmpEducation collection. (Empty collection if no records available)
445     *
446     * @todo rename method as getEmployeeEducations [DONE]
447     * @todo If EducationId is given return EmployeeEducation instead of Doctrine_Collection [DONE: Won't change since there is different primary key]
448     */
449    public function getEmployeeEducations($empNumber, $educationId=null) {
450        return $this->getEmployeeDao()->getEmployeeEducations($empNumber, $educationId);
451    }
452
453    /**
454     * Delete given education entries for given employee
455     *
456     * If $entriesToDelete is not provided (null), all entries of given employee
457     * will be deleted.
458     *
459     * @version 2.6.11
460     * @param int $empNumber Employee Number
461     * @param array $ids Array of EmployeeEducation primary keys. Optional.
462     * @return integer Number of records deleted
463     * @throws DaoException
464     *
465     * @todo return number of entries deleted (currently return value is based on $educationToDelete not actual deleted records) [DONE]
466     * @todo rename method as deleteEmployeeEducationRecords [DONE]
467     */
468    public function deleteEmployeeEducationRecords($empNumber, $ids = null) {
469        return $this->getEmployeeDao()->deleteEmployeeEducationRecords($empNumber, $ids);
470    }
471
472    /**
473     * Save the given EmployeeEducation entry.
474     *
475     * @version 2.6.11
476     * @param EmployeeEducation $education EmployeeEducation object to save
477     * @return EmployeeEducation Saved EmployeeEducation object
478     * @throws DaoException
479     *
480     * @todo return saved Employee Education object [DONE]
481     * @todo rename method as saveEmployeeEducation [DONE]
482     */
483    public function saveEmployeeEducation(EmployeeEducation $education) {
484        return $this->getEmployeeDao()->saveEmployeeEducation($education);
485    }
486
487    /**
488     * Get all skills or a single skill with given skill code for given employee.
489     *
490     * If skillCode is null, returns all Doctrine_Collection/EmployeeSkill objects for the employee.
491     * If skillCode is given, returns the Doctrine_Collection/EmployeeSkill object with given skillcode.
492     *
493     * @version 2.6.11
494     * @param int $empNumber Employee Number
495     * @param int $skillCode Skill Code
496     * @return Doctrine_Collection/EmployeeSkill
497     *
498     * @todo rename method as getEmployeeSkills [DONE]
499     *
500     */
501    public function getEmployeeSkills($empNumber, $skillCode = null) {
502        return $this->getEmployeeDao()->getEmployeeSkills($empNumber, $skillCode);
503    }
504
505    /**
506     * Delete given skill entries for given employee
507     *
508     * If $entriesToDelete is not provided (null), all entries of given employee
509     * will be deleted.
510     *
511     * @version 2.6.11
512     * @param int $empNumber Employee Number
513     * @param array $entriesToDelete Ids of the skill entries to delete. Optional.
514     * @return integer Number of records deleted
515     * @throws DaoException
516     *
517     * @todo return number of entries deleted [DONE]
518     * @todo rename method as deleteEmployeeSkills [DONE]
519     */
520    public function deleteEmployeeSkills($empNumber, $entriesToDelete = null) {
521        return $this->getEmployeeDao()->deleteEmployeeSkills($empNumber, $entriesToDelete);
522    }
523
524    /**
525     * Save the given EmployeeSkill entry.
526     *
527     * @version 2.6.11
528     * @param EmployeeSkill $skill EmployeeSkill object to save
529     * @return EmployeeSkill Saved EmployeeSkill object
530     *
531     * @todo reurn saved Employee Skill object [DONE]
532     * @todo rename method as saveEmployeeSkill [DONE]
533     */
534    public function saveEmployeeSkill(EmployeeSkill $skill) {
535        return $this->getEmployeeDao()->saveEmployeeSkill($skill);
536    }
537
538    /**
539     * Retrieve Employee Language for given employee number
540     *
541     * If language code is not set, It returns all languages for Employee
542     *
543     * If Language Type is not set, It returns all languages for Employee
544     *
545     * If Language code and Language type are set, It returns a Language for Employee
546     *
547     * @version 2.6.11
548     * @param int $empNumber Employee Number
549     * @param String $languageCode Language Code
550     * @param String $languageType Language Type
551     * @return Doctrine_Collection/Array Returns Doctrine_Collection of EmployeeLanguage objects  or EmployeeLanguage object
552     *
553     * @todo rename method as getEmployeeLanguages [DONE]
554     *
555     */
556    public function getEmployeeLanguages($empNumber, $languageCode = null, $languageType = null) {
557        return $this->getEmployeeDao()->getEmployeeLanguages($empNumber, $languageCode, $languageType);
558    }
559
560    /**
561     * Deletes languages assigned to an employee
562     *
563     * If $entriesToDelete is not provided (null), all entries of given employee
564     * will be deleted.
565     *
566     * @version 2.6.11
567     * @param int $empNumber Employee Number
568     * @param array $entriesToDelete Associative array of with language IDs as keys and fluency types as values. Optional.
569     * @return integer Number of records deleted
570     *
571     * @todo return number of entries deleted [DONE]
572     * @todo rename method as deleteEmployeeLanguages [DONE]
573     */
574    public function deleteEmployeeLanguages($empNumber, $entriesToDelete = null) {
575        return $this->getEmployeeDao()->deleteEmployeeLanguages($empNumber, $entriesToDelete);
576    }
577
578    /**
579     * Save given Employee Language entry
580     *
581     * @version 2.6.11
582     * @param EmployeeLanguage $language Employee Language
583     * @return EmployeeLanguage Saved EmployeeLanguage object
584     *
585     * @todo return saved Employee Language entry [DONE]
586     * @todo rename method as saveEmployeeLanguage [DONE]
587     *
588     */
589    public function saveEmployeeLanguage(EmployeeLanguage $language) {
590        return $this->getEmployeeDao()->saveEmployeeLanguage($language);
591    }
592
593    /**
594     * Retrieves license(s) of an employee
595     *
596     * If license ID is not set, It returns all licenses of employee
597     *
598     * If licence ID is set, It returns an EmployeeLicense object
599     *
600     * @version 2.6.11
601     * @param int $empNumber Employee number
602     * @param int $licenseId License ID to delete
603     * @return Doctrine_Collection/License Returns Doctrine_Collection of EmployeeLicense objects or single object
604     *
605     * @todo rename method as getEmployeeLicences [DONE]
606     *
607     */
608    public function getEmployeeLicences($empNumber, $licenseId = null) {
609        return $this->getEmployeeDao()->getEmployeeLicences($empNumber, $licenseId);
610    }
611
612    /**
613     * Deletes license of an employee
614     *
615     * If $entriesToDelete is not provided (null), all entries of given employee
616     * will be deleted.
617     *
618     * @version 2.6.11
619     * @param int $empNumber Employee number
620     * @param array $licenseIds Array of license IDs. Optional.
621     * @return integer Number of records deleted
622     *
623     * @todo Return number of items deleted [DONE]
624     * @todo Rename method as deleteEmployeeLicenses [DONE]
625     *
626     */
627    public function deleteEmployeeLicenses($empNumber, $licenseIds = null) {
628        return $this->getEmployeeDao()->deleteEmployeeLicenses($empNumber, $licenseIds);
629    }
630
631
632    /**
633     * Assign a license or update an assigned license of an employee
634     *
635     * @version 2.6.11
636     * @param EmployeeLicense $license Populated EmployeeLicense object
637     * @return EmployeeLicense Saved EmployeeLicense object
638     *
639     * @todo return saved Employee License entry [DONE]
640     * @todo rename method as saveEmployeeLicense [DONE]
641     *
642     */
643    public function saveEmployeeLicense(EmployeeLicense $license) {
644        return $this->getEmployeeDao()->saveEmployeeLicense($license);
645    }
646
647    /**
648     * Get attachments of an employee for given screen
649     *
650     * @version 2.6.11
651     * @param int $empNumber Employee number
652     * @param string $screen Screen name. Allowed values are mentioned in PluginEmployeeAttachment.
653     *
654     * @return Doctrine_Collection Doctrine_Collection of EmployeeAttachment objects
655     *
656     * @todo Define screen name constant in PluginEmployeeAttachment class [DONE]
657     * @todo rename method as getEmployeeAttachments [DONE]
658     * @todo Define the values for $screen as constants use constants names here [DONE]
659     */
660    public function getEmployeeAttachments($empNumber, $screen) {
661        return $this->getEmployeeDao()->getEmployeeAttachments($empNumber, $screen);
662    }
663
664    /**
665     * Deletes attachments of an employee
666     *
667     * If $entriesToDelete is not provided (null), all entries of given employee
668     * will be deleted.
669     *
670     * @version 2.6.11
671     * @param int $empNumber Employee number
672     * @param array $attachmentIds Array of attachement IDs. Optional.
673     * @return integer Number of records deleted
674     *
675     * @todo rename method as deleteEmployeeAttachments [DONE]
676     * @todo return number of items deleted [DONE]
677     */
678    public function deleteEmployeeAttachments($empNumber, $attachmentIds = null) {
679        return $this->getEmployeeDao()->deleteEmployeeAttachments($empNumber, $attachmentIds);
680    }
681
682    /**
683     * Retrieves an attachment of an employee
684     *
685     * @version 2.6.11
686     * @param int $empNumber Employee number
687     * @param int $attachmentId Attachment ID
688     *
689     * @return EmployeeAttachment or null if no attachment is found
690     *
691     * @todo rename method as getEmployeeAttachment [DONE]
692     */
693    public function getEmployeeAttachment($empNumber, $attachmentId) {
694        return $this->getEmployeeDao()->getEmployeeAttachment($empNumber, $attachmentId);
695    }
696
697    /**
698     * Retrieve Employee Picture for an employee
699     *
700     * @ignore
701     *
702     * @version 2.6.11
703     * @param int $empNumber Employee Number
704     * @return EmpPicture Employee Picture object
705     *
706     * @throws DaoException
707     *
708     * @todo remove method and use getEmployeePicture
709     */
710    public function readEmployeePicture($empNumber) {
711        return $this->getEmployeeDao()->readEmployeePicture($empNumber);
712    }
713
714    /**
715     * Retrieve Employee list according to terminated status
716     *
717     * @version 2.6.11
718     * @param String $orderField Order Field, default is empNumber
719     * @param String $orderBy Order By, Default is ASC
720     * @param boolean $includeTerminatedEmployees
721     * @return Doctrine_Collection/Array Returns Doctrine_Collection of Employee objects
722     * @throws DaoException
723     *
724     * @todo Change default $orderField to last name [DONE]
725     */
726    public function getEmployeeList($orderField = 'lastName', $orderBy = 'ASC', $includeTerminatedEmployees = false) {
727        return $this->getEmployeeDao()->getEmployeeList($orderField, $orderBy, $includeTerminatedEmployees);
728    }
729
730    /**
731     * Returns employee IDs of all the employees in the system
732     *
733     * @version 2.7.1
734     * @param Boolean $excludeTerminatedEmployees Exclude Terminated employees or not
735     * @return Array List of employee IDs
736     */
737    public function getEmployeeIdList($excludeTerminatedEmployees = false) {
738        return $this->getEmployeeDao()->getEmployeeIdList($excludeTerminatedEmployees);
739    }
740
741    /**
742     * Returns an array of requested properties of all employees
743     *
744     * <pre>
745     * Ex: $properties = array('empNumber', 'firstName', 'lastName')
746     *
747     * For above $properties parameter there will be an array like below as the response.
748     *
749     * array(
750     *          0 => array('empNumber' => 1, 'firstName' => 'Kayla', 'lastName' => 'Abbey'),
751     *          1 => array('empNumber' => 1, 'firstName' => 'Ashley', 'lastName' => 'Abel')
752     * )
753     * </pre>
754     *
755     * @version 2.7.1
756     * @param $properties An array of strings containing names of required properties. Any property of Employee is allowed.
757     * @param $orderField Field to be used for ordering
758     * @param $orderBy ASC or DESC
759     * @param Boolean $excludeTerminatedEmployees Exclude Terminated employees or not
760     * @return Array Employee Property List
761     */
762    public function getEmployeePropertyList($properties, $orderField, $orderBy, $excludeTerminatedEmployees = false) {
763        return $this->getEmployeeDao()->getEmployeePropertyList($properties, $orderField, $orderBy, $excludeTerminatedEmployees);
764    }
765
766
767    /**
768     * Returns list of supervisors (employees having at least one subordinate)
769     *
770     * @version 2.6.11
771     * @return Doctrine_Collection/Array Returns Doctrine_Collection of Employee objects
772     * @throws DaoException
773     *
774     * @todo add orderField,oraderBy and include Deleted parameters [DONE]
775     */
776    public function getSupervisorList($includeTerminated = false, $orderField = 'lastName', $orderBy = 'ASC') {
777        return $this->getEmployeeDao()->getSupervisorList($includeTerminated, $orderField, $orderBy);
778    }
779
780    /**
781     * Search Employee for given field and value
782     *
783     * @ignore
784     *
785     * @version 2.6.11
786     * @param String $field property name
787     * @param String $value property value
788     * @return Doctrine_Collection/Array Returns Doctrine_Collection of Employee objects
789     * @throws DaoException
790     */
791    public function searchEmployee($field, $value) {
792        return $this->getEmployeeDao()->searchEmployee($field, $value);
793    }
794
795    /**
796     * Returns Employee Count according to terminated status
797     *
798     * @version 2.6.11
799     * @param boolean $includeTerminated
800     * @return int Employee Count
801     *
802     * @throws DaoException
803     *
804     * @todo Change parameter to include terminated and change logic [DONE]
805     */
806    public function getEmployeeCount($includeTerminated = false) {
807        return $this->getEmployeeDao()->getEmployeeCount($includeTerminated);
808    }
809
810    /**
811     * Get Immediate subordinates of the given employee.
812     *
813     * @version 2.6.11
814     * @param int $empNumber Supervisor Id
815     * @return Doctrine_Collection/Array Returns Doctrine_Collection of Employee objects
816     * @throws DaoException
817     *
818     * @todo Rename to getImmediateSubordinates($empNumber) [DONE]
819     * @todo improve DAO method performance , currently it execute few queries [DONE: Decided to remove this method]
820     *
821     */
822    /*
823    public function getImmediateSubordinates($empNumber) {
824        return $this->getEmployeeDao()->getImmediateSubordinates($empNumber);
825    }
826    */
827
828    /**
829     * @ignore
830     *
831     * Returns Employee List as Json string
832     *
833     * if workShift parameter is true json string include employee work shift value
834     *
835     * @version 2.6.11
836     * @param boolean $workShift Work Shift
837     * @return String Json string include employee name and employee id
838     *
839     * @throws DaoException
840     *
841     * @todo Remove WorkShift Parameter , currently it's not used in DAO method
842     * @todo Create Json string in service method instead of DAO method. DAO can
843     * return array of name and id values.
844     * @todo Improve performance of dao method
845     */
846    public function getEmployeeListAsJson($workShift = false) {
847        return $this->getEmployeeDao()->getEmployeeListAsJson($workShift);
848    }
849
850    /**
851     * Return List of Subordinates for given Supervisor
852     *
853     * @version 2.7.1
854     * @param int $supervisorId Supervisor Id
855     * @param boolean $includeTerminated Terminated status
856     * @return Doctrine_Collection of Subordinates
857     *
858     * @todo parameter name $withoutTerminatedEmployees does not give the correct meaning [Done: In 10188]
859     * @todo rename method as getSubordinateChain($empNumber , $includeTerminated ) [Done: In 10188, getSubordinateList is better]
860     * @todo rename second parameter as include Terminated as change DAO method logic [Done: In 10188]
861     */
862    public function getSubordinateList($supervisorId, $includeTerminated = false) {
863        $configService = $this->getConfigurationService();
864        $includeChain = $configService->isSupervisorChainSuported();
865        return $this->getEmployeeDao()->getSubordinateList($supervisorId, $includeTerminated, $includeChain);
866    }
867
868    /**
869     * Returns an array of employee IDs of subordinates for given supervisor ID
870     *
871     * IDs of whole chain under given supervisor are returned.
872     *
873     * @version 2.7.1
874     * @param int $supervisorId Supervisor's ID
875     * @param boolean $includeChain Include Supervisor chain or not
876     * @return Array An array of employee IDs
877     */
878    public function getSubordinateIdListBySupervisorId($supervisorId, $includeChain = null, $maxDepth = NULL) {
879        if (is_null($includeChain)) {
880            $configService = $this->getConfigurationService();
881            $includeChain = $configService->isSupervisorChainSuported();
882        }
883        return $this->getEmployeeDao()->getSubordinateIdListBySupervisorId($supervisorId, $includeChain, array(), $maxDepth);
884    }
885
886    /**
887     * Returns an array of employee IDs of supervisors for given subordinate ID
888     *
889     * IDs of whole chain of supervisors of a subordinate are returned.
890     *
891     * @version 2.7.1
892     * @param int $subordinateId Subordinates ID
893     * @param boolean $includeChain Include Supervisor chain or not
894     * @return Array An array of employee IDs
895     */
896    public function getSupervisorIdListBySubordinateId($subordinateId , $includeChain = null) {
897        if (is_null($includeChain)) {
898            $configService = $this->getConfigurationService();
899            $includeChain = $configService->isSupervisorChainSuported();
900        }
901        return $this->getEmployeeDao()->getSupervisorIdListBySubordinateId($subordinateId, $includeChain);
902    }
903
904    /**
905     * Returns an array of requested properties of subordinates of given supervisor ID
906     *
907     * <pre>
908     * Ex: $properties = array('empNumber', 'firstName', 'lastName')
909     *
910     * For above $properties parameter there will be an array like below as the response.
911     *
912     * array(
913     *          0 => array('empNumber' => 1, 'firstName' => 'Kayla', 'lastName' => 'Abbey'),
914     *          1 => array('empNumber' => 1, 'firstName' => 'Ashley', 'lastName' => 'Abel')
915     * )
916     * </pre>
917     *
918     * @version 2.7.1
919     * @param int $supervisorId Supervisor's ID
920     * @param $properties An array of strings containing names of required properties
921     * @param $orderField Field to be used for ordering
922     * @param $orderBy ASC or DESC
923     * @param Boolean $includeTerminated Include Terminated employees or not
924     * @return Array Employee Property List
925     */
926    public function getSubordinatePropertyListBySupervisorId($supervisorId, $properties, $orderField, $orderBy, $includeTerminated = false, $maxDepth = NULL) {
927        $configService = $this->getConfigurationService();
928        $includeChain = $configService->isSupervisorChainSuported();
929        return $this->getEmployeeDao()->getSubordinatePropertyListBySupervisorId($supervisorId, $properties, $includeChain, $orderField, $orderBy, $includeTerminated, array(), $maxDepth);
930    }
931
932    /**
933     * Filtering Employee by Sub unit
934     * @ignore
935     *
936     * @version 2.6.11
937     * @param Doctrine_Collection/Array $employeeList Employee List Collection
938     * @param String $subUnitId
939     * @return array()
940     * @throws DaoException
941     *
942     */
943    public function filterEmployeeListBySubUnit($employeeList, $subUnitId) {
944
945        if (empty($subUnitId) || $subUnitId == 1) {
946            return $employeeList;
947        }
948
949        if (empty($employeeList)) {
950            $employeeList = $this->getEmployeeList("empNumber", "ASC", true);
951        }
952
953        $filteredList = array();
954        foreach ($employeeList as $employee) {
955            if ($employee->getWorkStation() == $subUnitId) {
956                $filteredList[] = $employee;
957            }
958        }
959
960        return $filteredList;
961
962    }
963
964    /**
965     * Delete Employees for given employee Id List
966     *
967     * @version 2.6.11
968     * @param array $empNumbers
969     * @return integer Number of records deleted
970     *
971     * @throws DaoException
972     *
973     * @todo rename method as deleteEmployees($empNumbers ) [DONE]
974     * @todo return number of deleted items [DONE]
975     *
976     */
977    public function deleteEmployees($empNumbers) {
978        return $this->getEmployeeDao()->deleteEmployees($empNumbers);
979    }
980
981    /**
982     * Checks if the given employee id is in use.
983     *
984     *
985     * @version 2.6.11
986     * @param  $employeeId
987     * @return boolean
988     * @throws DaoException
989     *
990     * @todo rename method as isExistingEmployeeId( $employeeId ) [DONE]
991     */
992    public function isExistingEmployeeId($employeeId) {
993        return $this->getEmployeeDao()->isExistingEmployeeId($employeeId);
994    }
995
996    /**
997     * Checks employee already exists for given first middle and last name
998     *
999     * @ignore
1000     *
1001     * @version 2.6.11
1002     * @param string $firstName First Name of the Employee
1003     * @param string $middle Middle name of the employee
1004     * @param string $lastname Last name of the employee
1005     * @return boolean If Employee exists retrun true else return false
1006     * @throws DaoException
1007     *
1008     */
1009    public function checkForEmployeeWithSameName($first, $middle, $last) {
1010        return $this->getEmployeeDao()->checkForEmployeeWithSameName($first, $middle, $last);
1011    }
1012
1013    /**
1014     * Retrieves the service period of an employee in years
1015     * as on given date
1016     *
1017     * Returns 0 if employee's joined date is not set.
1018     * Calculates based on joined data and given date.
1019     * Does not consider employment terminations happened in between
1020     *
1021     * @version 2.6.11
1022     * @param int $empNumber
1023     * @param string $date Any date format supported by strtotime()
1024     * @return decimal O if joined date is not set or joined date is after $date.
1025     * @throws PIMServiceException If employee with given ID is not found
1026     *
1027     * @todo Improve year duration calculation
1028     */
1029    public function getEmployeeYearsOfService($empNumber, $date) {
1030        $employee = $this->getEmployee($empNumber);
1031        if (!($employee instanceof Employee)) {
1032            throw new PIMServiceException("Employee with employeeId " . $empNumber . " not found!");
1033        }
1034        return $this->getDurationInYears($employee->getJoinedDate(), $date);
1035    }
1036
1037    /**
1038     * Retrieves the duration between two dates in years
1039     *
1040     * If any of the date is empty, it will return 0.
1041     *
1042     * @version 2.6.11
1043     * @param string $fromDate
1044     * @param string $toDate
1045     * @return int
1046     * @ignore
1047     */
1048    public function getDurationInYears($fromDate, $toDate) {
1049        $years = 0;
1050        $secondsOfYear = 60 * 60 * 24 * 365;
1051        $secondsOfMonth = 60 * 60 * 24 * 30;
1052
1053        if (!empty($fromDate) && !empty($toDate)) {
1054            $fromDateTimeStamp = strtotime($fromDate);
1055            $toDateTimeStamp = strtotime($toDate);
1056
1057            $timeStampDiff = 0;
1058            if ($toDateTimeStamp > $fromDateTimeStamp) {
1059                $timeStampDiff = $toDateTimeStamp - $fromDateTimeStamp;
1060
1061                $years = floor($timeStampDiff / $secondsOfYear);
1062
1063                //adjusting the months
1064                $remainingMonthsTimeStamp = ($timeStampDiff - ($years * $secondsOfYear));
1065                $months = round($remainingMonthsTimeStamp / $secondsOfMonth);
1066                $yearByMonth = ($months > 0) ? $months / 12 : 0;
1067
1068                if (floor($years + $yearByMonth) == ($years + $yearByMonth)) {
1069                    $years = $this->getBorderPeriodMonths($fromDate, $toDate);
1070                } else {
1071                    $years = $years + $yearByMonth;
1072                }
1073            }
1074        }
1075        return $years;
1076    }
1077
1078    /**
1079     * @ignore
1080     * @param type $fromDate
1081     * @param type $toDate
1082     * @return type
1083     */
1084    private function getBorderPeriodMonths($fromDate, $toDate) {
1085        $years = 0;
1086        $secondsOfDay = 60 * 60 * 24;
1087        $numberOfDaysInYear = 365;
1088        $secondsOfYear = $secondsOfDay * $numberOfDaysInYear;
1089        $numberOfMonths = 12;
1090
1091        $timeStampDiff = strtotime($toDate) - strtotime($fromDate);
1092        $noOfDays = floor($timeStampDiff / $secondsOfDay);
1093        $fromYear = date("Y", strtotime($fromDate));
1094        $toYear = date("Y", strtotime($toDate));
1095
1096        list($fY, $fM, $fD) = explode("-", $fromDate);
1097        list($tY, $tM, $tD) = explode("-", $toDate);
1098        $years = $tY - $fY;
1099
1100        $temp = $fromYear . "-" . $fM . "-" . $fD;
1101        $newFromMonthDay = date("m-d", strtotime("-1 day", strtotime($temp)));
1102        $toMonthDay = $tM . "-" . $tD;
1103
1104        if ($newFromMonthDay != $toMonthDay) {
1105            if (($tM - $fM) < 0) {
1106                $years--;
1107            } elseif (($tM - $fM) == 0 && ($tD - $fD) < -1) {
1108                $years--;
1109            }
1110        }
1111
1112        return $years;
1113    }
1114
1115    /**
1116     * Retrieves Workshift details of an employee
1117     *
1118     * @version 2.6.11
1119     * @param int $empNumber Employee number
1120     * @return EmployeeWorkShift EmployeeWorkShift instance if found or false
1121     * @throws DaoException
1122     *
1123     * @todo rename method as getEmployeeWorkShift [DONE]
1124     */
1125    public function getEmployeeWorkShift($empNumber) {
1126        return $this->getEmployeeDao()->getEmployeeWorkShift($empNumber);
1127    }
1128
1129    /**
1130     * Retrieves Tax details of an employee
1131     *
1132     * @version 2.6.11
1133     * @param int $empNumber Employee number
1134     * @return EmpUsTaxExemption EmpUsTaxExemption instance if found or NULL
1135     * @throws DaoException
1136     *
1137     */
1138    public function getEmployeeTaxExemptions($empNumber) {
1139        return $this->getEmployeeDao()->getEmployeeTaxExemptions($empNumber);
1140    }
1141
1142    /**
1143     * Saves Tax Exemptions of an employee
1144     *
1145     * @version 2.6.11
1146     * @param EmpUsTaxExemption $empUsTaxExemption
1147     * @return EmpUsTaxExemption Saved EmpUsTaxExemption object
1148     * @throws DaoException
1149     *
1150     * @todo return saved EmpUsTaxExemption entry [DONE]
1151     */
1152    public function saveEmployeeTaxExemptions(EmpUsTaxExemption $empUsTaxExemption) {
1153        return $this->getEmployeeDao()->saveEmployeeTaxExemptions($empUsTaxExemption);
1154    }
1155
1156    /**
1157     * Saves Job details of an employee
1158     *
1159     * @version 2.6.11
1160     * @param Employee $employee Employee instance
1161     * @return boolean true always
1162     * @throws DaoException
1163     *
1164     * @todo Don't return value [DONE: Decided to remove this method and use saveEmployee()]
1165     * @todo Save only job details in corresponding DAO method [DONE: Decided to remove this method and use saveEmployee()]
1166     * @todo rename method as saveEmployeeJobDetails [DONE]
1167     */
1168    /*
1169    public function saveEmployeeJobDetails(Employee $employee) {
1170        return $this->getEmployeeDao()->saveEmployeeJobDetails($employee);
1171    }
1172    */
1173
1174
1175    /**
1176     * Retrieves details of a membership of an employee
1177     *
1178     * @version 2.6.11
1179     * @param int $empNumber Employee number
1180     * @param int $membershipId
1181     * @return Doctrine_Collection A collection of EmployeeMembership
1182     * @throws DaoException
1183     *
1184     * @todo Rename the method as getEmployeeMemberships() [DONE]
1185     * @todo Rename EmployeeMemberDetail Entity as EmployeeMembership [DONE]
1186     * @todo Make $membershipcode parameter as opational parameter and rename parameter as $membershipId [DONE]
1187     */
1188    public function getEmployeeMemberships($empNumber, $membershipUniqueId = null) {
1189        return $this->getEmployeeDao()->getEmployeeMemberships($empNumber, $membershipUniqueId);
1190    }
1191
1192    /**
1193     * Deletes the given Memberships
1194     *
1195     * If $membershipIds is not provided (null), all entries of given employee
1196     * will be deleted.
1197     *
1198     * @version 2.6.11
1199     * @param array $membershipIds Array of membership IDs. Optional.
1200     *
1201     * @return integer Number of records deleted
1202     * @throws DaoException
1203     *
1204     * @todo Add new method as deleteEmployeeMemberships($empNumber, $membershipIds ) [DONE]
1205     * @todo return number of items deleted [DONE]
1206     *
1207     */
1208    public function deleteEmployeeMemberships($membershipIds = null) {
1209
1210        return $this->getEmployeeDao()->deleteEmployeeMemberships($membershipIds);
1211
1212    }
1213
1214    /**
1215     * Retrieve non-assigned Currency List for given employee for the given salary grade
1216     * @ignore
1217     *
1218     * @version 2.6.11
1219     * @param int $empNumber Employee Number
1220     * @param string $salaryGrade Salary Grade
1221     * @param boolean $asArray
1222     * @return Doctrine_Collection/Array Returns Doctrine_Collection of CurrencyType objects
1223     *  if $asArray is false, otherwise returns an array
1224     * @throws DaoException
1225     *
1226     * @todo Remove this method since it's not used anywhere
1227     */
1228    public function getUnAssignedCurrencyList($empNumber, $salaryGrade, $asArray = false) {
1229        return $this->getEmployeeDao()->getUnAssignedCurrencyList($empNumber, $salaryGrade, $asArray);
1230    }
1231
1232    /**
1233     * Retrieve assigned Currency List for the given salary grade
1234     *
1235     * @ignore
1236     *
1237     * @version 2.6.11
1238     * @param string $salaryGrade Salary Grade
1239     * @param boolean $asArray
1240     * @return Doctrine_Collection/Array Returns Doctrine_Collection of CurrencyType objects
1241     *  if $asArray is false, otherwise returns an array
1242     * @throws DaoException
1243     *
1244     * @todo remove this method if it's not used
1245     *
1246     */
1247    public function getAssignedCurrencyList($salaryGrade, $asArray = false) {
1248        return $this->getEmployeeDao()->getAssignedCurrencyList($salaryGrade, $asArray);
1249    }
1250
1251    /**
1252     * Saves salary of an employee
1253     *
1254     * @version 2.6.11
1255     * @param EmployeeSalary $salary
1256     * @return EmployeeSalary Saved EmployeeSalary object
1257     * @throws DaoException
1258     *
1259     * @todo return saved EmpSalary entry [DONE]
1260     * @todo Rename method as saveEmployeeSalary [DONE]
1261     * @todo rename Entity as EmpBasicsalary to EmpSalary [DONE: Renamed as EmployeeSalary]
1262     */
1263    public function saveEmployeeSalary(EmployeeSalary $salary) {
1264        return $this->getEmployeeDao()->saveEmployeeSalary($salary);
1265    }
1266
1267    /**
1268     * Deletes salary components of an employee
1269     *
1270     * If $salaryIds is not provided (null), all entries of given employee
1271     * will be deleted.
1272     *
1273     * @version 2.6.11
1274     * @param int $empNumber Employee number
1275     * @param array $salaryIds Array of salary IDs. Optional.
1276     * @return integer Number of records deleted
1277     * @throws DaoException
1278     *
1279     * @todo return number deleted items [DONE]
1280     * @todo rename method as deleteEmployeeSalaries [DONE]
1281     * @todo Change parameter to $salaryIds [DONE]
1282     * @todo Change EmpBasicSalary ORM to Salary [DONE: Renamed as EmployeeSalary]
1283     */
1284    public function deleteEmployeeSalaryComponents($empNumber, $salaryIds = null) {
1285        return $this->getEmployeeDao()->deleteEmployeeSalaryComponents($empNumber, $salaryIds);
1286    }
1287
1288    /**
1289     * Get Salary Record(s) for given employee
1290     *
1291     * @version 2.6.11
1292     * @param int $empNumber Employee number
1293     * @param int $empSalaryId Employee Basic Salary ID
1294     *
1295     * @return Collection/EmployeeSalary If $empSalaryId is given returns matching
1296     * EmployeeSalary or false if not found. If $empSalaryId is not given, returns
1297     * EmployeeSalary collection. (Empty collection if no records available)
1298     * @throws DaoException
1299     *
1300     * @todo rename method as getEmployeeSalaries [DONE]
1301     */
1302    public function getEmployeeSalaries($empNumber, $empSalaryId = null) {
1303        return $this->getEmployeeDao()->getEmployeeSalaries($empNumber, $empSalaryId);
1304    }
1305
1306    /**
1307     * Retrieves Immediate supervisors of an employee
1308     *
1309     * @version 2.6.11
1310     * @param int $empNumber Employee Number
1311     * @return Doctrine_Collection A collection of ReportTo objects
1312     * @throws DaoException
1313     *
1314     * @todo Rename the method as getImmediateSupervisors [DONE]
1315     * @todo return Employee Entities instead of ReportTo Entities
1316     */
1317    public function getImmediateSupervisors($empNumber) {
1318        return $this->getEmployeeDao()->getImmediateSupervisors($empNumber);
1319    }
1320
1321    /**
1322     * Retrieves subordinates of an employee
1323     * @ignore
1324     *
1325     * @version 2.6.11
1326     * @param int $empNumber Employee Number
1327     * @return Doctrine_Collection A collection of ReportTo objects
1328     * @throws DaoException
1329     *
1330     * @todo Rename the method as getSubordinates
1331     */
1332    public function getSubordinateListForEmployee($empNumber) {
1333        return $this->getEmployeeDao()->getSubordinateListForEmployee($empNumber);
1334    }
1335
1336    /**
1337     * Retrieves report-to details of given supervisor and subordinate IDs
1338     *
1339     * @ignore
1340     * @version 2.6.11
1341     * @param int $supNumber
1342     * @param int $subNumber
1343     * @return ReportTo ReportTo instance if found or NULL
1344     * @throws DaoException
1345     *
1346     * @todo Rename the method as getReportTo()
1347     */
1348    public function getReportToObject($supNumber, $subNumber) {
1349        return $this->getEmployeeDao()->getReportToObject($supNumber, $subNumber);
1350    }
1351
1352    /**
1353     * Deletes report-to details
1354     * @ignore
1355     *
1356     * @version 2.6.11
1357     * @param array $supOrSubListToDelete
1358     * @return boolean true or NULL
1359     * @throws DaoException
1360     *
1361     * @todo Array elements can also be arrays rather than space-separated values
1362     * @todo Currently it returns last deleted record's return value instead return
1363     * an overall value
1364     * @todo Add new deleteEmployeeSubordinates($empNumber , $subordinateIds)  method
1365     * @todo Add new deleteEmployeeSupervisors($empNumber , $supervisorIds)  method
1366     * $todo Add new saveEmployeeReportTo(ReportTo $reportTo)
1367     *
1368     */
1369    public function deleteReportToObject($supOrSubListToDelete) {
1370
1371        foreach ($supOrSubListToDelete as $supOrSubToDelete) {
1372
1373            $tempArray = explode(" ", $supOrSubToDelete);
1374
1375            $supNumber = $tempArray[0];
1376            $subNumber = $tempArray[1];
1377            $reportingMethod = $tempArray[2];
1378
1379            $state = $this->getEmployeeDao()->deleteReportToObject($supNumber, $subNumber, $reportingMethod);
1380        }
1381
1382        return $state;
1383
1384    }
1385
1386    /**
1387     * Remove employee supervisor
1388     *
1389     * @param $supNumber
1390     * @param $subNumber
1391     * @param $reportingMethod
1392     * @return bool
1393     */
1394    public function removeSupervisor($supNumber,$subNumber,$reportingMethod)
1395    {
1396        return  $this->getEmployeeDao()->deleteReportToObject($supNumber, $subNumber, $reportingMethod);
1397    }
1398
1399    /**
1400     * Check if user with given userId is an admin
1401     * @param string $userId
1402     * @return bool - True if given user is an admin, false if not
1403     * @ignore
1404     *
1405     * @todo Move method to Auth Service
1406     */
1407    public function isAdmin($userId) {
1408        return $this->getEmployeeDao()->isAdmin($userId);
1409    }
1410
1411    /**
1412     * Get list of all employees work emails and other emails
1413     *
1414     * Work email index = 'emp_work_email'
1415     * Other email index = 'emp_oth_email'
1416     *
1417     * @return DoctrineCollection work emails and other emails
1418     * @ignore
1419     *
1420     * @todo Look at usages and improve them. (use ajax instead of loading all
1421     *       emails to template)
1422     */
1423    public function getEmailList() {
1424        return $this->getEmployeeDao()->getEmailList();
1425    }
1426
1427    /**
1428     * Get emp numbers of all subordinates in the system
1429     *
1430     * @return Array Array of subordinate employee numbers
1431     * @ignore
1432     *
1433     * @todo Get the result as a PHP array in Doctrine rather than creating the
1434     * array afterwards.
1435     * @todo If not in use, remove method from Service and DAO
1436     */
1437    public function getSubordinateIdList() {
1438        return $this->getEmployeeDao()->getSubordinateIdList();
1439    }
1440
1441    /**
1442     * Terminate employment of given employee
1443     *
1444     * Saves EmployeeTerminationRecord and updates termination_id
1445     * of Employee.
1446     *
1447     * @version 2.6.11
1448     * @param EmployeeTerminationRecord $employeeTerminationRecord EmployeeTerminationRecord object
1449     * @return EmployeeTerminationRecord Saved EmployeeTerminationRecord object
1450     * @throws DaoException
1451     *
1452     * @todo Change to take EmpTermination object. Dao should save
1453     * EmpTermination and update termination id in employee table in one
1454     * transaction. [DONE]
1455     *
1456     * @todo throw an exception if not successfull, no return type [DONE: Returns EmployeeTerminationRecord]
1457     */
1458    public function terminateEmployment(EmployeeTerminationRecord $employeeTerminationRecord) {
1459        $terminatedEmployees = $this->getEmployeeDao()->terminateEmployment($employeeTerminationRecord);
1460        $this->checkEmployeeCountChange(self::EMPLOYEE_INACTIVE_COUNT);
1461        return $terminatedEmployees;
1462    }
1463
1464    /**
1465     * Activates terminated employment for given employee
1466     *
1467     * @version 2.6.11
1468     * @param int $empNumber Employee Number
1469     * @return int 1 if successfull, 0 if empNumber is not available
1470     *
1471     * @todo Rename to activateTerminatedEmployment [DONE]
1472     */
1473    public function activateTerminatedEmployment($empNumber) {
1474        $activatedEmployee = $this->getEmployeeDao()->activateTerminatedEmployment($empNumber);
1475        $this->checkEmployeeCountChange(self::EMPLOYEE_ACTIVE_COUNT);
1476        return $activatedEmployee;
1477    }
1478
1479    /**
1480     * Get EmployeeTerminationRecord object with given Id
1481     *
1482     * @version 2.6.11
1483     * @param int $terminatedId Termination Id
1484     * @return EmployeeTerminationRecord EmployeeTerminationRecord object
1485     *
1486     * @todo raname method as getEmployeeTerminationDetails [DONE: Renamed as getEmployeeTerminationRecord to comply with the entity]
1487     */
1488    public function getEmployeeTerminationRecord($terminatedId) {
1489        return $this->getEmployeeDao()->getEmployeeTerminationRecord($terminatedId);
1490    }
1491
1492    /**
1493     * Get Employees under the given subunits
1494     *
1495     * Only returns the employees in given subunits, not in sub unit hierarchies.
1496     *
1497     * @param string/array $subUnits Sub Unit IDs
1498     * @param boolean $includeTerminatedEmployees if true, includes terminated employees
1499     *
1500     * @return Doctrine_Collection of Employee objects
1501     */
1502    public function getEmployeesBySubUnit($subUnits, $includeTerminatedEmployees = false) {
1503        return $this->getEmployeeDao()->getEmployeesBySubUnit($subUnits, $includeTerminatedEmployees);
1504    }
1505
1506   /**
1507     * Get employee list after sorting and filtering using given parameters.
1508     *
1509     * @param EmployeeSearchParameterHolder $parameterHolder Object containing search parameters
1510     *
1511     * @return Employee array of Employee entities match with filters
1512     *
1513     * @todo Rename to searchEmployees(ParameterHolder $parameterObject) [DONE]
1514     * @todo Use an instance of a parameter holder instead of set of parameters [DONE]
1515     */
1516    public function searchEmployees(EmployeeSearchParameterHolder $parameterHolder) {
1517        return $this->getEmployeeDao()->searchEmployees($parameterHolder);
1518    }
1519
1520    /**
1521     * Get Search Employee Count
1522     *
1523     * @param array $filters
1524     *
1525     * @return int Number of employees matched to the filter criteria mentioned in $filters
1526     * @todo Use a parameter object instead of $filters
1527     */
1528    public function getSearchEmployeeCount(array $filters = null) {
1529        return $this->getEmployeeDao()->getSearchEmployeeCount($filters);
1530    }
1531
1532    /**
1533     * Save employee dependent
1534     *
1535     * @param EmpDependent $employeeDependent
1536     * @return EmpDependent
1537     */
1538    public function saveEmployeeDependent(EmpDependent $employeeDependent){
1539        return $this->getEmployeeDao()->saveEmployeeDependent($employeeDependent);
1540    }
1541
1542    /**
1543     * Update employee dependent
1544     *
1545     * @param EmpDependent $employeeDependent
1546     * @return mixed
1547     */
1548    public function updateEmployeeDependent(EmpDependent $employeeDependent){
1549        return $this->getEmployeeDao()->updateEmployeeDependent($employeeDependent);
1550    }
1551
1552    /**
1553     * Get employee termination reasons list
1554     *
1555     * @param EmpDependent $employeeDependent
1556     * @return mixed
1557     */
1558    public function getTerminationReasonList(){
1559        return $this->getEmployeeDao()->getTerminationReasonList();
1560    }
1561
1562    private function checkEmployeeCountChange($type) {
1563        $registrationProcessorFactory = new RegistrationEventProcessorFactory();
1564        $registrationEventProcessor = $registrationProcessorFactory->getRegistrationEventProcessor($type);
1565        $registrationEventProcessor->saveRegistrationEvent(date("Y-m-d H:i:s"));
1566    }
1567
1568}
1569