/** * creates missing accounts * * @param Zend_Console_Getopt $_opts * @return integer */ public function create_missing_accounts($_opts) { $args = $this->_parseArgs($_opts, array()); $year = isset($args['year']) || array_key_exists('year', $args) ? intval($args['year']) : 0; if ($year !== 0 && $year < 2010 || $year > 2100) { echo 'Please use a valid year with 4 digits!' . PHP_EOL; return; } HumanResources_Controller_Account::getInstance()->createMissingAccounts($year); }
/** * test adding a contract with manually setting the end_date of the contract before */ public function testAddContract() { $sdate = new Tinebase_DateTime('2013-01-01 00:00:00'); $sdate->setTimezone(Tinebase_Core::getUserTimezone()); $employee = $this->_getEmployee('rwright'); $contractController = HumanResources_Controller_Contract::getInstance(); $employeeController = HumanResources_Controller_Employee::getInstance(); $employee = $employeeController->create($employee); $contract = $this->_getContract($sdate); $contract->workingtime_json = '{"days": [8,8,8,8,8,0,0]}'; $contract->employee_id = $employee->getId(); $feastCalendar = $this->_getFeastCalendar(); $contract->feast_calendar_id = $feastCalendar->getId(); $contract->start_date = $sdate; $contractController->create($contract); $employeeJson = $this->_json->getEmployee($employee->getId()); $accountController = HumanResources_Controller_Account::getInstance(); // should not be created, exist already $accountController->createMissingAccounts(2013, $employee); $account = $accountController->getAll()->getFirstRecord(); $employeeJson['vacation'] = array(array('account_id' => $account->getId(), 'type' => 'vacation', 'status' => 'ACCEPTED', 'freedays' => array(array('duration' => '1', 'date' => '2013-01-11 00:00:00')))); $employeeJson = $this->_json->saveEmployee($employeeJson); $this->assertEquals(1, count($employeeJson['vacation'])); // manually set the end date and add a new contract $employeeJson['contracts'][0]['end_date'] = '2013-05-31 00:00:00'; $employeeJson['contracts'][1] = array('start_date' => '2013-06-01 00:00:00', 'workingtime_json' => '{"days": [8,8,8,8,8,0,0]}', 'vacation_days' => 27, 'feast_calendar_id' => $feastCalendar->getId()); // no exception should be thrown $employeeJson = $this->_json->saveEmployee($employeeJson); $this->assertEquals(2, count($employeeJson['contracts'])); // an exception should be thrown $employeeJson['contracts'][0]['vacation_days'] = 31; $this->setExpectedException('HumanResources_Exception_ContractNotEditable'); $employeeJson = $this->_json->saveEmployee($employeeJson); }
/** * delete linked objects (notes, relations, ...) of record * * @param Tinebase_Record_Interface $_record */ protected function _deleteLinkedObjects(Tinebase_Record_Interface $_record) { // use textfilter for employee_id $eFilter = new Tinebase_Model_Filter_Text(array('field' => 'employee_id', 'operator' => 'equals', 'value' => $_record->getId())); // delete free times $filter = new HumanResources_Model_FreeTimeFilter(array(), 'AND'); $filter->addFilter($eFilter); HumanResources_Controller_FreeTime::getInstance()->deleteByFilter($filter); // delete contracts $filter = new HumanResources_Model_ContractFilter(array(), 'AND'); $filter->addFilter($eFilter); HumanResources_Controller_Contract::getInstance()->deleteByFilter($filter); // delete costcenters if ($_record->has('costcenters')) { $filter = new HumanResources_Model_CostCenterFilter(array(), 'AND'); $filter->addFilter($eFilter); HumanResources_Controller_CostCenter::getInstance()->deleteByFilter($filter); } // delete accounts $filter = new HumanResources_Model_AccountFilter(array()); $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'employee_id', 'operator' => 'equals', 'value' => $_record->getId()))); HumanResources_Controller_Account::getInstance()->deleteByFilter($filter); parent::_deleteLinkedObjects($_record); }
/** * creates for each account an employee */ protected function _createSharedEmployees() { $controller = HumanResources_Controller_Employee::getInstance(); $this->_feastCalendar = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array('name' => 'Feast Calendar', 'type' => Tinebase_Model_Container::TYPE_SHARED, 'owner_id' => Tinebase_Core::getUser(), 'backend' => 'SQL', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'color' => '#00FF00'), TRUE)); $controller->transferUserAccounts(FALSE, $this->_feastCalendar->getId(), NULL, 27, TRUE); $employees = $controller->search(new HumanResources_Model_EmployeeFilter(array())); // get pwulf as supervisor $pwulf = $employees->filter('n_family', 'Wulf')->getFirstRecord(); $sdate = new Tinebase_DateTime(); $sdate->subMonth(6); $defaultData = array('supervisor_id' => $pwulf->getId(), 'countryname' => 'GB', 'region' => 'East Sussex', 'locality' => 'Brighton', 'employment_begin' => $sdate); foreach ($employees as $employee) { if (!$employee->account_id) { echo '=== SKIPPING ===' . PHP_EOL; echo 'There is no account_id for this employee: ' . PHP_EOL; echo print_r($employee->toArray(), 1); echo 'This employee won\'t have costcenters, contracts, etc.' . PHP_EOL; echo '=== SKIPPING ===' . PHP_EOL; } $user = Tinebase_User::getInstance()->getUserByProperty('accountId', $employee->account_id, 'Tinebase_Model_FullUser'); foreach (array_merge($defaultData, $this->_dataMapping[$user->accountLoginName]) as $key => $data) { $employee->{$key} = $data; $employee->employment_begin = $this->_startDate; } // add costcenter $scs = $this->_costCenters->getByIndex(0); $hrc = array('cost_center_id' => $scs->getId(), 'start_date' => $this->_startDate); $employee->costcenters = array($hrc); // add contract $contract = $this->_getContract($sdate); $employee->contracts = array($contract->toArray()); // add division $division = $this->_divisions->getByIndex(0); $employee->division_id = $division->getId(); // update and increment counter $controller->update($employee); } HumanResources_Controller_Account::getInstance()->createMissingAccounts(); }
/** * * @param integer $year */ public function createMissingAccounts($year = NULL) { $year = intval($year); if ($year < 2006 || $year >= 2106 || !is_int($year)) { throw new HumanResources_Exception_NeedsYear(); } $results = HumanResources_Controller_Account::getInstance()->createMissingAccounts($year); return array('success' => TRUE, 'year' => $year, 'totalcount' => $results->count(), 'results' => $results->toArray()); }
/** * update 7.12 -> 7.13 * * - create accounts for this and next year */ public function update_12() { $date = Tinebase_DateTime::now(); HumanResources_Controller_Account::getInstance()->createMissingAccounts((int) $date->format('Y'), NULL, TRUE); $date->addYear(1); HumanResources_Controller_Account::getInstance()->createMissingAccounts((int) $date->format('Y'), NULL, TRUE); $this->setApplicationVersion('HumanResources', '7.13'); }
/** * some contract tests (more in jsontests) */ public function testContract() { $sdate = new Tinebase_DateTime('2013-01-01 00:00:00'); $employee = $this->_getEmployee('rwright'); $contractController = HumanResources_Controller_Contract::getInstance(); $employeeController = HumanResources_Controller_Employee::getInstance(); $employee = $employeeController->create($employee); $contract = $this->_getContract($sdate); $contract->workingtime_json = '{"days": [8,8,8,8,8,0,0]}'; // create feast days $feastDays2013 = array(array('2013-12-25', '2013-12-26'), array('2013-04-01'), '2013-05-01', '2013-05-09', '2013-05-20', '2013-10-03', '2013-01-01', '2013-03-29', '2013-12-31', '2009-12-31'); $feastCalendar = $this->_getFeastCalendar(); $contract->feast_calendar_id = $feastCalendar->getId(); foreach ($feastDays2013 as $day) { if (is_array($day)) { $date = array(); foreach ($day as $dayQ) { $date[] = new Tinebase_DateTime($dayQ . ' 06:00:00'); } } else { $date = new Tinebase_DateTime($day . ' 06:00:00'); } $this->_createFeastDay($date); } // test "calculateVacationDays" $start = new Tinebase_DateTime('2013-01-01'); $stop = new Tinebase_DateTime('2013-12-31'); $contract->start_date = $start; $contract->end_date = $stop; $this->assertEquals(30, $contractController->calculateVacationDays($contract, $start, $stop)); $newStartDate = new Tinebase_DateTime('2013-07-01'); $contract->start_date = $newStartDate; $contract->employee_id = $employee->getId(); $contractController->create($contract); $this->assertEquals(15, round($contractController->calculateVacationDays($contract, $start, $stop), 0)); // test "getDatesToWorkOn" $contract->start_date = $start; // 2013 has 365 days, 52 Saturdays and 52 Sundays, all of the 10 feast days are at working days (a good year for an employee!) // so we expect 365-52-52-10 = 251 days $workingDates = $contractController->getDatesToWorkOn($contract, $start, $stop); $this->assertEquals(251, count($workingDates['results'])); // test $respectTakenVacationDays parameter of getDatesToWorkOn $accountController = HumanResources_Controller_Account::getInstance(); $accounts = $accountController->createMissingAccounts(2013, $contract->employee_id); $account = $accounts->getFirstRecord(); $refDate = clone $newStartDate; // get a monday $refDate->addWeek(1)->addDay(1); // now add 3 vacation days $freetime = array('account_id' => $account->getId(), 'employee_id' => $contract->employee_id, 'type' => 'vacation', 'status' => 'ACCEPTED', 'firstday_date' => $refDate->toString()); $freetime['freedays'] = array(array('duration' => '1', 'date' => $refDate->toString()), array('duration' => '1', 'date' => $refDate->addDay(1)->toString()), array('duration' => '1', 'date' => $refDate->addDay(1)->toString())); $json = new HumanResources_Frontend_Json(); $freetime = $json->saveFreeTime($freetime); $workingDates = $contractController->getDatesToWorkOn($contract, $start, $stop, TRUE); $this->assertEquals(248, count($workingDates['results'])); // test "getFeastDays" $feastDays = $contractController->getFeastDays($contract, $start, $stop); // we expect 10 here $this->assertEquals(10, count($feastDays), '10 feast days should have been found!'); }