TimeTrex Community Edition v16.2.0

This commit is contained in:
2022-12-13 07:10:06 +01:00
commit 472f000c1b
6810 changed files with 2636142 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,218 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\Import
*/
class ImportAccrual extends Import {
public $class_name = 'APIAccrual';
public $accrual_policy_account_options = false;
/**
* @param $name
* @param null $parent
* @return array|bool|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
$apf = TTNew( 'AccrualFactory' ); /** @var AccrualFactory $apf */
$retval = Misc::prependArray( $this->getUserIdentificationColumns(), Misc::arrayIntersectByKey( [ 'accrual_policy_account', 'type', 'amount', 'date_stamp', 'note' ], Misc::trimSortPrefix( $apf->getOptions( 'columns' ) ) ) );
break;
case 'column_aliases':
//Used for converting column names after they have been parsed.
$retval = [
'type' => 'type_id',
'accrual_policy_account' => 'accrual_policy_account_id',
];
break;
case 'import_options':
$retval = [
'-1010-fuzzy_match' => TTi18n::getText( 'Enable smart matching.' ),
];
break;
case 'parse_hint':
$upf = TTnew( 'UserPreferenceFactory' ); /** @var UserPreferenceFactory $upf */
$retval = [
'date_stamp' => $upf->getOptions( 'date_format' ),
'amount' => $upf->getOptions( 'time_unit_format' ),
];
break;
}
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _preParseRow( $row_number, $raw_row ) {
$retval = $this->getObject()->stripReturnHandler( $this->getObject()->getAccrualDefaultData() );
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _postParseRow( $row_number, $raw_row ) {
$raw_row['user_id'] = $this->getUserIdByRowData( $raw_row );
if ( $raw_row['user_id'] == false ) {
unset( $raw_row['user_id'] );
}
if ( isset( $raw_row['date_stamp'] ) ) {
$raw_row['time_stamp'] = $raw_row['date_stamp']; //AcrualFactory wants time_stamp column not date_stamp, so convert that here.
}
return $raw_row;
}
/**
* @param int $validate_only EPOCH
* @return mixed
*/
function _import( $validate_only ) {
return $this->getObject()->setAccrual( $this->getParsedData(), $validate_only );
}
//
// Generic parser functions.
//
/**
* @return bool
*/
function getAccrualPolicyAccountOptions() {
//Get accrual policies
$aplf = TTNew( 'AccrualPolicyAccountListFactory' ); /** @var AccrualPolicyAccountListFactory $aplf */
$aplf->getByCompanyId( $this->company_id );
$this->accrual_policy_account_options = (array)$aplf->getArrayByListFactory( $aplf, false );
unset( $aplf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_accrual_policy_account( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID(); //Default Wage Group
}
if ( !is_array( $this->accrual_policy_account_options ) ) {
$this->getAccrualPolicyAccountOptions();
}
$retval = $this->findClosestMatch( $input, $this->accrual_policy_account_options );
if ( $retval === false ) {
$retval = -1; //Make sure this fails.
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return false|int
*/
function parse_date_stamp( $input, $default_value = null, $parse_hint = null ) {
return $this->parse_date( $input, $default_value, $parse_hint );
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|mixed
*/
function parse_type( $input, $default_value = null, $parse_hint = null ) {
$af = TTnew( 'AccrualFactory' ); /** @var AccrualFactory $af */
$options = $af->getOptions( 'user_type' );
if ( isset( $options[$input] ) ) {
return $input;
} else {
if ( $this->getImportOptions( 'fuzzy_match' ) == true ) {
return $this->findClosestMatch( $input, $options, 50 );
} else {
return array_search( strtolower( $input ), array_map( 'strtolower', $options ) );
}
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|float|int|number|string
*/
function parse_amount( $input, $default_value = null, $parse_hint = null ) {
$val = new Validator();
TTDate::setTimeUnitFormat( $parse_hint );
$retval = TTDate::parseTimeUnit( $val->stripNonTimeUnit( $input ) );
return $retval;
}
}
?>
@@ -0,0 +1,132 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\Import
*/
class ImportBranch extends Import {
public $class_name = 'APIBranch';
/**
* @param $name
* @param null $parent
* @return array|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
global $current_company;
$bf = TTNew( 'BranchFactory' ); /** @var BranchFactory $bf */
$retval = $bf->getOptions( 'columns' );
$retval = Misc::trimSortPrefix( $retval );
Debug::Arr( $retval, 'ImportBranchColumns: ', __FILE__, __LINE__, __METHOD__, 10 );
break;
case 'import_options':
$retval = [
'-1010-fuzzy_match' => TTi18n::getText( 'Enable smart matching.' ),
];
break;
case 'parse_hint':
$upf = TTnew( 'UserPreferenceFactory' ); /** @var UserPreferenceFactory $upf */
$retval = [];
$retval = $upf->getCustomFieldsParseHints( $retval, null, 'branch' );
break;
}
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _preParseRow( $row_number, $raw_row ) {
$retval = $this->getObject()->stripReturnHandler( $this->getObject()->getBranchDefaultData() );
$retval['manual_id'] += $row_number; //Auto increment manual_id automatically.
return $retval;
}
/**
* @param int $validate_only EPOCH
* @return mixed
*/
function _import( $validate_only ) {
return $this->getObject()->setBranch( $this->getParsedData(), $validate_only );
}
//
// Generic parser functions.
//
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return int
*/
function parse_status( $input, $default_value = null, $parse_hint = null ) {
if ( strtolower( $input ) == 'e'
|| strtolower( $input ) == 'enabled' ) {
$retval = 10;
} else if ( strtolower( $input ) == 'd'
|| strtolower( $input ) == 'disabled' ) {
$retval = 20;
} else {
$retval = (int)$input;
}
return $retval;
}
}
?>
@@ -0,0 +1,132 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\Import
*/
class ImportDepartment extends Import {
public $class_name = 'APIDepartment';
/**
* @param $name
* @param null $parent
* @return array|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
global $current_company;
$bf = TTNew( 'DepartmentFactory' ); /** @var DepartmentFactory $bf */
$retval = $bf->getOptions( 'columns' );
$retval = Misc::trimSortPrefix( $retval );
Debug::Arr( $retval, 'ImportDepartmentColumns: ', __FILE__, __LINE__, __METHOD__, 10 );
break;
case 'import_options':
$retval = [
'-1010-fuzzy_match' => TTi18n::getText( 'Enable smart matching.' ),
];
break;
case 'parse_hint':
$upf = TTnew( 'UserPreferenceFactory' ); /** @var UserPreferenceFactory $upf */
$retval = [];
$retval = $upf->getCustomFieldsParseHints( $retval, null, 'department' );
break;
}
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _preParseRow( $row_number, $raw_row ) {
$retval = $this->getObject()->stripReturnHandler( $this->getObject()->getDepartmentDefaultData() );
$retval['manual_id'] += $row_number; //Auto increment manual_id automatically.
return $retval;
}
/**
* @param int $validate_only EPOCH
* @return mixed
*/
function _import( $validate_only ) {
return $this->getObject()->setDepartment( $this->getParsedData(), $validate_only );
}
//
// Generic parser functions.
//
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return int
*/
function parse_status( $input, $default_value = null, $parse_hint = null ) {
if ( strtolower( $input ) == 'e'
|| strtolower( $input ) == 'enabled' ) {
$retval = 10;
} else if ( strtolower( $input ) == 'd'
|| strtolower( $input ) == 'disabled' ) {
$retval = 20;
} else {
$retval = (int)$input;
}
return $retval;
}
}
?>
@@ -0,0 +1,216 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\Import
*/
class ImportPayPeriod extends Import {
public $class_name = 'APIPayPeriod';
public $pay_period_schedule_options = false;
/**
* @param $name
* @param null $parent
* @return array|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
$ppf = TTNew( 'PayPeriodFactory' ); /** @var PayPeriodFactory $ppf */
$retval = Misc::arrayIntersectByKey( [ 'pay_period_schedule', 'start_date', 'end_date', 'transaction_date' ], Misc::trimSortPrefix( $ppf->getOptions( 'columns' ) ) );
break;
case 'column_aliases':
//Used for converting column names after they have been parsed.
$retval = [
'pay_period_schedule' => 'pay_period_schedule_id',
];
break;
case 'import_options':
$retval = [
'-1010-fuzzy_match' => TTi18n::getText( 'Enable smart matching.' ),
];
break;
case 'parse_hint':
$upf = TTnew( 'UserPreferenceFactory' ); /** @var UserPreferenceFactory $upf */
$retval = [
'start_date' => $upf->getOptions( 'date_format' ),
'end_date' => $upf->getOptions( 'date_format' ),
'transaction_date' => $upf->getOptions( 'date_format' ),
];
break;
}
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _preParseRow( $row_number, $raw_row ) {
$retval = $this->getObject()->stripReturnHandler( $this->getObject()->getPayPeriodDefaultData() );
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _postParseRow( $row_number, $raw_row ) {
//$raw_row['user_id'] = $this->getUserIdByRowData( $raw_row );
//if ( $raw_row['user_id'] == FALSE ) {
// unset($raw_row['user_id']);
//}
//If its a salary type, make sure average weekly time is always specified and hourly rate.
return $raw_row;
}
/**
* @param int $validate_only EPOCH
* @return mixed
*/
function _import( $validate_only ) {
return $this->getObject()->setPayPeriod( $this->getParsedData(), $validate_only );
}
//
// Generic parser functions.
//
/**
* @return bool
*/
function getPayPeriodScheduleOptions() {
//Get job titles
$ppslf = TTNew( 'PayPeriodScheduleListFactory' ); /** @var PayPeriodScheduleListFactory $ppslf */
$ppslf->getByCompanyId( $this->company_id );
$this->pay_period_schedule_options = (array)$ppslf->getArrayByListFactory( $ppslf, false );
unset( $ppslf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_pay_period_schedule( $input, $default_value = null, $parse_hint = null ) {
if ( !is_array( $this->pay_period_schedule_options ) ) {
$this->getPayPeriodScheduleOptions();
}
if ( trim( $input ) == '' && count( $this->pay_period_schedule_options ) == 1 ) {
return key( $this->pay_period_schedule_options ); //Use first pay period schedule.
}
$retval = $this->findClosestMatch( $input, $this->pay_period_schedule_options );
if ( $retval === false ) {
$retval = -1; //Make sure this fails.
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|false|int
*/
function parse_start_date( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setDateFormat( $parse_hint );
return TTDate::parseDateTime( $input );
} else {
return TTDate::strtotime( $input );
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|false|int
*/
function parse_end_date( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setDateFormat( $parse_hint );
return TTDate::parseDateTime( $input );
} else {
return TTDate::strtotime( $input );
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|false|int
*/
function parse_transaction_date( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setDateFormat( $parse_hint );
return TTDate::parseDateTime( $input );
} else {
return TTDate::strtotime( $input );
}
}
}
?>
@@ -0,0 +1,274 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\Import
*/
class ImportPayStubAmendment extends Import {
public $class_name = 'APIPayStubAmendment';
public $pay_stub_account_options = false;
/**
* @var array
*/
private $pay_stub_account_short_options;
/**
* @param $name
* @param null $parent
* @return array|bool|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
$psaf = TTNew( 'PayStubAmendmentFactory' ); /** @var PayStubAmendmentFactory $psaf */
$retval = Misc::prependArray( $this->getUserIdentificationColumns(), Misc::arrayIntersectByKey( [ 'status', 'type', 'pay_stub_entry_name', 'effective_date', 'amount', 'rate', 'units', 'description', 'ytd_adjustment' ], Misc::trimSortPrefix( $psaf->getOptions( 'columns' ) ) ) );
break;
case 'column_aliases':
//Used for converting column names after they have been parsed.
$retval = [
'status' => 'status_id',
'type' => 'type_id',
'pay_stub_entry_name' => 'pay_stub_entry_name_id',
];
break;
case 'import_options':
$retval = [
'-1010-fuzzy_match' => TTi18n::getText( 'Enable smart matching.' ),
];
break;
case 'parse_hint':
$upf = TTnew( 'UserPreferenceFactory' ); /** @var UserPreferenceFactory $upf */
$retval = [
'effective_date' => $upf->getOptions( 'date_format' ),
//'amount' => $upf->getOptions('time_unit_format'),
];
break;
}
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _preParseRow( $row_number, $raw_row ) {
$retval = $this->getObject()->stripReturnHandler( $this->getObject()->getPayStubAmendmentDefaultData() );
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _postParseRow( $row_number, $raw_row ) {
$raw_row['user_id'] = $this->getUserIdByRowData( $raw_row );
if ( $raw_row['user_id'] == false ) {
unset( $raw_row['user_id'] );
}
return $raw_row;
}
/**
* @param int $validate_only EPOCH
* @return mixed
*/
function _import( $validate_only ) {
return $this->getObject()->setPayStubAmendment( $this->getParsedData(), $validate_only );
}
//
// Generic parser functions.
//
/**
* @return bool
*/
function getPayStubAccountOptions() {
//Get accrual policies
$psealf = TTNew( 'PayStubEntryAccountListFactory' ); /** @var PayStubEntryAccountListFactory $psealf */
$psealf->getByCompanyIdAndTypeId( $this->company_id, [ 10, 20, 30, 50, 80 ] );
//Get names with types in front, ie: "Earning - Commission"
$this->pay_stub_account_options = (array)$psealf->getArrayByListFactory( $psealf, false, true, true );
//Get names without types in front, ie: "Commission"
$this->pay_stub_account_short_options = (array)$psealf->getArrayByListFactory( $psealf, false, true, false, false );
unset( $psealf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_pay_stub_entry_name( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID(); //Default Wage Group
}
if ( !is_array( $this->pay_stub_account_options ) ) {
$this->getPayStubAccountOptions();
}
$retval = $this->findClosestMatch( $input, $this->pay_stub_account_options );
//Debug::Arr( $this->pay_stub_account_options, 'aAttempting to find PS Account with long name: '. $input, __FILE__, __LINE__, __METHOD__, 10);
if ( $retval === false ) {
$retval = $this->findClosestMatch( $input, $this->pay_stub_account_short_options );
//Debug::Arr( $this->pay_stub_account_short_options, 'bAttempting to find PS Account with short name: '. $input, __FILE__, __LINE__, __METHOD__, 10);
if ( $retval === false ) {
$retval = -1; //Make sure this fails.
}
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return false|int
*/
function parse_effective_date( $input, $default_value = null, $parse_hint = null ) {
return $this->parse_date( $input, $default_value, $parse_hint );
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|mixed
*/
function parse_status( $input, $default_value = null, $parse_hint = null ) {
$psaf = TTnew( 'PayStubAmendmentFactory' ); /** @var PayStubAmendmentFactory $psaf */
$options = Misc::trimSortPrefix( $psaf->getOptions( 'status' ) );
if ( isset( $options[$input] ) ) {
return $input;
} else {
if ( $this->getImportOptions( 'fuzzy_match' ) == true ) {
return $this->findClosestMatch( $input, $options, 50 );
} else {
return array_search( strtolower( $input ), array_map( 'strtolower', $options ) );
}
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|mixed
*/
function parse_type( $input, $default_value = null, $parse_hint = null ) {
$psaf = TTnew( 'PayStubAmendmentFactory' ); /** @var PayStubAmendmentFactory $psaf */
$options = Misc::trimSortPrefix( $psaf->getOptions( 'type' ) );
if ( isset( $options[$input] ) ) {
return $input;
} else {
if ( $this->getImportOptions( 'fuzzy_match' ) == true ) {
return $this->findClosestMatch( $input, $options, 50 );
} else {
return array_search( strtolower( $input ), array_map( 'strtolower', $options ) );
}
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return mixed
*/
function parse_amount( $input, $default_value = null, $parse_hint = null ) {
$val = new Validator();
$retval = $val->stripNonFloat( $input );
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return mixed
*/
function parse_rate( $input, $default_value = null, $parse_hint = null ) {
$val = new Validator();
$retval = $val->stripNonFloat( $input );
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return mixed
*/
function parse_units( $input, $default_value = null, $parse_hint = null ) {
$val = new Validator();
$retval = $val->stripNonFloat( $input );
return $retval;
}
}
?>
@@ -0,0 +1,272 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\Import
*/
class ImportRemittanceDestinationAccount extends Import {
public $class_name = 'APIRemittanceDestinationAccount';
public $wage_group_options = false;
/**
* @param $name
* @param null $parent
* @return array|bool|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
$baf = TTNew( 'RemittanceDestinationAccountFactory' ); /** @var RemittanceDestinationAccountFactory $baf */
$retval = Misc::trimSortPrefix( $baf->getOptions( 'columns' ) );
unset( $retval['display_amount'] ); //For display purposes only.
$retval = Misc::addSortPrefix( Misc::prependArray( $this->getUserIdentificationColumns(), Misc::trimSortPrefix( $retval ) ) );
ksort( $retval );
break;
case 'column_aliases':
//Used for converting column names after they have been parsed.
$retval = [
//'wage_group' => 'wage_group_id',
'amount_type' => 'amount_type_id',
'type' => 'type_id',
];
break;
case 'import_options':
$retval = [
'-1010-fuzzy_match' => TTi18n::getText( 'Enable smart matching.' ),
];
break;
case 'parse_hint':
//$upf = TTnew('UserPreferenceFactory');
$retval = [
//'effective_date' => $upf->getOptions('date_format'),
//'weekly_time' => $upf->getOptions('time_unit_format'),
];
break;
}
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _preParseRow( $row_number, $raw_row ) {
//Try to determine if its a checking or savings account, so we at least have a chance at specifying a default name for the account.
$ach_transaction_type = 22;
if ( isset( $raw_row['ach_transaction_type'] ) ) {
$ach_transaction_type = $this->parse_ach_transaction_type( $raw_row['ach_transaction_type'] );
}
$retval = $this->getObject()->stripReturnHandler( $this->getObject()->getRemittanceDestinationAccountDefaultData( $ach_transaction_type ) );
foreach ( $raw_row as $key => $value ) {
$retval[$key] = $value;
}
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _postParseRow( $row_number, $raw_row ) {
$raw_row['user_id'] = $this->getUserIdByRowData( $raw_row );
if ( $raw_row['user_id'] == false ) {
$raw_row['user_id'] = TTUUID::getNotExistID();
//unset($raw_row['user_id']);
}
if ( ( !isset( $raw_row['type'] ) || $raw_row['type'] == '' ) ) {
if ( isset( $raw_row['value3'] ) && $raw_row['value3'] != '' ) { //Value3=Bank Account.
$raw_row['type'] = 3000; //EFT
} else {
$raw_row['type'] = 2000; //Check
}
}
//If not specified, try to default to some remittance source account.
if ( isset( $raw_row['user_id'] ) && !isset( $raw_row['remittance_source_account_id'] ) ) {
$u_obj = $this->getUserObject( TTUUID::castUUID( $raw_row['user_id'] ) );
if ( is_object( $u_obj ) ) {
$rsalf = TTnew( 'RemittanceSourceAccountListFactory' ); /** @var RemittanceSourceAccountListFactory $rsalf */
$rsalf->getByLegalEntityIdAndStatusIdAndTypeIdAndCompanyId( $u_obj->getLegalEntity(), 10, $raw_row['type'], $this->getCompanyObject()->getId() );
if ( $rsalf->getRecordCount() > 0 ) {
$raw_row['remittance_source_account_id'] = $rsalf->getCurrent()->getId();
unset( $rsalf );
}
}
}
return $raw_row;
}
/**
* @param int $validate_only EPOCH
* @return mixed
*/
function _import( $validate_only ) {
return $this->getObject()->setRemittanceDestinationAccount( $this->getParsedData(), $validate_only );
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return int
*/
function parse_status( $input, $default_value = null, $parse_hint = null ) {
if ( strtolower( $input ) == 'e'
|| strtolower( $input ) == 'enabled' ) {
$retval = 10;
} else if ( strtolower( $input ) == 'd'
|| strtolower( $input ) == 'disabled' ) {
$retval = 20;
} else {
$retval = (int)$input;
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|mixed
*/
function parse_type( $input, $default_value = null, $parse_hint = null ) {
$rsaf = TTnew( 'RemittanceSourceAccountFactory' ); /** @var RemittanceSourceAccountFactory $rsaf */
$options = $rsaf->getOptions( 'type' );
if ( isset( $options[$input] ) ) {
return $input;
} else {
if ( $this->getImportOptions( 'fuzzy_match' ) == true ) {
return $this->findClosestMatch( $input, $options, 50 );
} else {
return array_search( strtolower( $input ), array_map( 'strtolower', $options ) );
}
}
}
/**
* @param $input
* @param string $default_value
* @param null $parse_hint
* @return array|bool|mixed
*/
function parse_amount_type( $input, $default_value = 'Percent', $parse_hint = null ) {
$rsaf = TTnew( 'RemittanceDestinationAccountFactory' ); /** @var RemittanceDestinationAccountFactory $rsaf */
$options = $rsaf->getOptions( 'amount_type' );
if ( isset( $options[$input] ) ) {
return $input;
} else {
if ( $this->getImportOptions( 'fuzzy_match' ) == true ) {
return $this->findClosestMatch( $input, $options, 50 );
} else {
return array_search( strtolower( $input ), array_map( 'strtolower', $options ) );
}
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_remittance_source_account( $input, $default_value = null, $parse_hint = null, $map_data = null, $raw_row = null ) {
$u_obj = $this->getUserObject( TTUUID::castUUID( $this->getUserIdByRowData( $raw_row ) ) ); //Need find user_id based on the raw_row again here, as that is done in postParse otherwise.
if ( is_object( $u_obj ) ) {
$rdalf = TTnew( 'RemittanceSourceAccountListFactory' ); /** @var RemittanceSourceAccountListFactory $rdalf */
$rdalf->getAPISearchByCompanyIdAndArrayCriteria( $this->getCompanyObject()->getId(), [ 'legal_entity_id' => $u_obj->getLegalEntity() ] );
$result = (array)$rdalf->getArrayByListFactory( $rdalf, false );
$retval = $this->findClosestMatch( $input, $result );
if ( $retval === false ) {
$retval = -1; //Make sure this fails.
}
return $retval;
}
return -1; //Make sure this fails.
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|mixed
*/
function parse_ach_transaction_type( $input, $default_value = null, $parse_hint = null ) {
$rdaf = TTnew( 'RemittanceDestinationAccountFactory' ); /** @var RemittanceDestinationAccountFactory $rdaf */
$options = $rdaf->getOptions( 'ach_transaction_type' );
if ( isset( $options[$input] ) ) {
return $input;
} else {
if ( $this->getImportOptions( 'fuzzy_match' ) == true ) {
return $this->findClosestMatch( $input, $options, 50 );
} else {
return array_search( strtolower( $input ), array_map( 'strtolower', (array)$options ) );
}
}
}
}
?>
+830
View File
@@ -0,0 +1,830 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\Import
*/
class ImportUser extends Import {
public $class_name = 'APIUser';
public $user_names = []; //Stored used usernames so we can find duplicates.
public $title_options = false;
public $user_group_options = false;
public $ethnic_group_options = false;
public $permission_control_options = false;
public $policy_group_options = false;
public $pay_period_schedule_options = false;
public $hierarchy_control_options = false;
/**
* @param $name
* @param null $parent
* @return array|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
global $current_company;
$uf = TTNew( 'UserFactory' ); /** @var UserFactory $uf */
$retval = $uf->getOptions( 'columns' );
//Since getOptions() can be called without first setting a company, we don't always know the product edition for the currently logged in employee.
if ( ( is_object( $this->getCompanyObject() ) && $this->getCompanyObject()->getProductEdition() >= TT_PRODUCT_PROFESSIONAL )
|| ( !is_object( $this->getCompanyObject() ) && getTTProductEdition() >= TT_PRODUCT_PROFESSIONAL ) ) {
$retval['-1000-user_default'] = TTi18n::getText( 'New Hire Defaults' ); //Specify name of New Hire Default record to use.
}
$retval['-1025-password'] = TTi18n::getText( 'Password' );
$retval['-1026-phone_password'] = TTi18n::getText( 'Quick Punch Password' );
$retval['-1099-group'] = ( isset( $retval['-1099-user_group'] ) ) ? $retval['-1099-user_group'] : null;
unset( $retval['-1099-user_group'], $retval['-1082-full_name'], $retval['-1401-hierarchy_level_display'], $retval['-1500-last_login_date'], $retval['-1510-max_punch_time_stamp'] );
ksort( $retval );
//Since getOptions() can be called without first setting a company, we don't always know the product edition for the currently logged in employee.
if ( ( is_object( $this->getCompanyObject() ) && $this->getCompanyObject()->getProductEdition() < TT_PRODUCT_CORPORATE )
|| ( !is_object( $this->getCompanyObject() ) && getTTProductEdition() <= TT_PRODUCT_PROFESSIONAL ) ) {
unset( $retval['-1104-default_job'], $retval['-1105-default_job_item'] );
}
$retval = Misc::trimSortPrefix( $retval );
Debug::Arr( $retval, 'ImportUserColumns: ', __FILE__, __LINE__, __METHOD__, 10 );
break;
case 'column_aliases':
//Used for converting column names after they have been parsed.
$retval = [
'status' => 'status_id',
'default_branch' => 'default_branch_id',
'default_department' => 'default_department_id',
'default_job' => 'default_job_id',
'default_job_item' => 'default_job_item_id',
'title' => 'title_id',
'user_group' => 'group_id',
'group' => 'group_id',
'ethnic_group' => 'ethnic_group_id',
'sex' => 'sex_id',
'permission_control' => 'permission_control_id',
'pay_period_schedule' => 'pay_period_schedule_id',
'policy_group' => 'policy_group_id',
'hierarchy_control_display' => 'hierarchy_control',
];
break;
case 'import_options':
$retval = [
'-1010-fuzzy_match' => TTi18n::getText( 'Enable smart matching.' ),
'-1015-update' => TTi18n::getText( 'Update existing records based on UserName, Employee Number, or SIN/SSN.' ), //Need an array to pick the unique column to use as the identifier, or we can just detect this on our own?
//Allow these to be imported separately instead.
//'-1020-create_branch' => TTi18n::getText('Create branches that don\'t exist.'),
//'-1030-create_department' => TTi18n::getText('Create departments that don\'t exist.'),
'-1040-create_group' => TTi18n::getText( 'Create groups that don\'t already exist.' ),
'-1045-create_ethnic_group' => TTi18n::getText( 'Create ethnic groups that don\'t already exist.' ),
'-1050-create_title' => TTi18n::getText( 'Create titles that don\'t already exist.' ),
];
break;
case 'parse_hint':
$upf = TTnew( 'UserPreferenceFactory' ); /** @var UserPreferenceFactory $upf */
$retval = [
'default_branch' => [
'-1010-name' => TTi18n::gettext( 'Name' ),
'-1020-manual_id' => TTi18n::gettext( 'Code' ),
],
'default_department' => [
'-1010-name' => TTi18n::gettext( 'Name' ),
'-1020-manual_id' => TTi18n::gettext( 'Code' ),
],
'default_job' => [
'-1010-name' => TTi18n::gettext( 'Name' ),
'-1020-manual_id' => TTi18n::gettext( 'Code' ),
],
'default_job_item' => [
'-1010-name' => TTi18n::gettext( 'Name' ),
'-1020-manual_id' => TTi18n::gettext( 'Code' ),
],
'first_name' => [
'-1010-first_name' => TTi18n::gettext( 'First Name' ),
'-1020-first_last_name' => TTi18n::gettext( 'FirstName LastName' ),
'-1030-last_first_name' => TTi18n::gettext( 'LastName, FirstName' ),
'-1040-last_first_middle_name' => TTi18n::gettext( 'LastName, FirstName MiddleInitial' ),
],
'last_name' => [
'-1010-last_name' => TTi18n::gettext( 'Last Name' ),
'-1020-first_last_name' => TTi18n::gettext( 'FirstName LastName' ),
'-1030-last_first_name' => TTi18n::gettext( 'LastName, FirstName' ),
'-1040-last_first_middle_name' => TTi18n::gettext( 'LastName, FirstName MiddleInitial' ),
],
'middle_name' => [
'-1010-middle_name' => TTi18n::gettext( 'Middle Name' ),
'-1040-last_first_middle_name' => TTi18n::gettext( 'LastName, FirstName MiddleInitial' ),
],
'hire_date' => $upf->getOptions( 'date_format' ),
'termination_date' => $upf->getOptions( 'date_format' ),
'birth_date' => $upf->getOptions( 'date_format' ),
];
$retval = $upf->getCustomFieldsParseHints( $retval, null, 'users' );
break;
}
return $retval;
}
function _getUserDefaultData( $raw_row ) {
$column_map = $this->getColumnMap();
$user_default_id = null;
if ( isset( $column_map['user_default']['import_column'] ) && isset( $raw_row[$column_map['user_default']['import_column']] ) && $raw_row[$column_map['user_default']['import_column']] != '' ) {
$user_default_id = $raw_row[$column_map['user_default']['import_column']];
}
$default_data = $this->getObject()->stripReturnHandler( $this->getObject()->getUserDefaultData( null, $user_default_id ) );
return $default_data;
}
/**
* @param $row_number
* @param $raw_row
* @return array
*/
function _preParseRow( $row_number, $raw_row ) {
//Only set defaults for columns already specified, or absolutely necessary ones.
//That way if the user wants to just update one or two columns for existing employees, the default values aren't all used too.
$column_map = $this->getColumnMap(); //Include columns that should always be there.
$default_data = $this->_getUserDefaultData( $raw_row );
$retval = [];
foreach ( $column_map as $key => $map_data ) {
if ( isset( $default_data[$key] ) ) {
$retval[$key] = $default_data[$key];
}
}
unset( $map_data ); //code standards
//Debug::Arr($retval, 'preParse Row: ', __FILE__, __LINE__, __METHOD__, 10);
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _postParseRow( $row_number, $raw_row ) {
if ( $this->getImportOptions( 'update' ) == true ) {
Debug::Text( 'Updating existing records, try to find record... ', __FILE__, __LINE__, __METHOD__, 10 );
$raw_row['id'] = $this->getUserIdByRowData( $raw_row );
if ( $raw_row['id'] == false ) {
unset( $raw_row['id'] );
}
} else {
Debug::Text( 'NOT updating existing records... ', __FILE__, __LINE__, __METHOD__, 10 );
}
//Check to see if this particular record is new or modifying an existing one.
if ( !isset( $raw_row['id'] ) || ( isset( $raw_row['id'] ) && $raw_row['id'] == false ) ) {
Debug::Text( 'Unable to find existing employee... Creating a new one...', __FILE__, __LINE__, __METHOD__, 10 );
$default_data = $this->_getUserDefaultData( $raw_row );
//Debug::Arr($default_data, 'Default Data: ', __FILE__, __LINE__, __METHOD__, 10);
$uf = TTnew( 'UserFactory' ); /** @var UserFactory $uf */
if ( !is_array( $default_data ) ) {
$default_data['status_id'] = 10; //Active
$default_data['employee_number'] = 1;
$default_data['currency_id'] = 1;
}
if ( !isset( $raw_row['status'] ) || ( isset( $raw_row['status'] ) && $raw_row['status'] == 0 ) ) {
$raw_row['status'] = $default_data['status_id'];
}
if ( !isset( $raw_row['employee_number'] ) ) {
$raw_row['employee_number'] = ( $default_data['employee_number'] + $row_number ); //Auto increment manual_id automatically.
}
if ( !isset( $raw_row['password'] ) ) {
$raw_row['password'] = TTPassword::generateRandomPassword( 50 ); //Default to a unique password, make it really long so it always passes the password strength checker.
}
if ( !isset( $raw_row['user_name'] ) || ( isset( $raw_row['user_name'] ) && $raw_row['user_name'] == '' ) ) {
if ( isset( $raw_row['first_name'] ) && isset( $raw_row['last_name'] ) ) {
$tmp_first_name = $uf->Validator->stripNonAlphaNumeric( $raw_row['first_name'] );
$tmp_last_name = $uf->Validator->stripNonAlphaNumeric( $raw_row['last_name'] );
$tmp_user_name = strtolower( $tmp_first_name . '.' . $tmp_last_name );
if ( $uf->isUniqueUserName( $tmp_user_name ) == false || in_array( $tmp_user_name, $this->user_names ) ) { //Check against existing users and those in the current import batch.
Debug::Text( 'Autogenerated user name already exists, trying random one: ' . $tmp_user_name, __FILE__, __LINE__, __METHOD__, 10 );
$tmp_user_name = strtolower( $tmp_first_name . '.' . $tmp_last_name . rand( 10, 9999 ) );
}
Debug::Text( 'Autogenerating user name: ' . $tmp_user_name, __FILE__, __LINE__, __METHOD__, 10 );
$raw_row['user_name'] = $tmp_user_name;
} else {
Debug::Text( 'Not autogenerating user name...', __FILE__, __LINE__, __METHOD__, 10 );
}
}
if ( isset( $raw_row['user_name'] ) && $raw_row['user_name'] != '' ) {
$this->user_names[] = $raw_row['user_name']; //Need to store usernames from import batch so we can detect duplicates within it.
}
if ( !isset( $raw_row['currency_id'] ) || ( isset( $raw_row['currency_id'] ) && $raw_row['currency_id'] == '' ) ) {
$raw_row['currency_id'] = $default_data['currency_id'];
}
//Merge the default data with row data.
//This must go at the end so it doesn't overwrite imported data.
$raw_row = array_merge( (array)$default_data, $raw_row );
//Debug::Arr($raw_row, 'Row+Default data: ', __FILE__, __LINE__, __METHOD__, 10);
}
//Debug::Arr($raw_row, 'postParse Row: ', __FILE__, __LINE__, __METHOD__, 10);
return $raw_row;
}
/**
* @param int $validate_only EPOCH
* @return mixed
*/
function _import( $validate_only ) {
return $this->getObject()->setUser( $this->getParsedData(), $validate_only );
}
//
// Generic parser functions.
//
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return int
*/
function parse_status( $input, $default_value = null, $parse_hint = null ) {
$uf = TTnew( 'UserFactory' ); /** @var UserFactory $uf */
$options = Misc::trimSortPrefix( $uf->getOptions( 'status' ) );
if ( isset( $options[$input] ) ) {
$retval = $input;
} else {
if ( $this->getImportOptions( 'fuzzy_match' ) == true ) {
$retval = $this->findClosestMatch( $input, $options, 80 );
} else {
$retval = array_search( strtolower( $input ), array_map( 'strtolower', $options ) );
}
}
if ( $retval === false ) {
if ( strtolower( $input ) == 'a'
|| strtolower( $input ) == 'active' ) {
$retval = 10;
} else if ( strtolower( $input ) == 'disabled'
|| strtolower( $input ) == 'inactive' ) {
$retval = 11;
} else if ( strtolower( $input ) == 't'
|| strtolower( $input ) == 'terminated' ) {
$retval = 20;
} else if ( strtolower( $input ) == 'l'
|| strtolower( $input ) == 'leave' ) {
$retval = 16; //Leave - Other
} else if ( strtolower( $input ) == 'i'
|| strtolower( $input ) == 'injury' || strtolower( $input ) == 'illness' ) {
$retval = 12; //Leave - Injury
} else {
$retval = (int)$input;
}
}
return $retval;
}
/**
* @return bool
*/
function getPermissionControlOptions() {
//Get job titles
$pglf = TTNew( 'PermissionControlListFactory' ); /** @var PermissionControlListFactory $pglf */
$pglf->getByCompanyId( $this->company_id );
$this->permission_control_options = (array)$pglf->getArrayByListFactory( $pglf, false, false ); //Include include in the name level, as it causes problems with exact matching.
unset( $pglf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_permission_control( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID(); //No Permission Group
}
if ( !is_array( $this->permission_control_options ) ) {
$this->getPermissionControlOptions();
}
$retval = $this->findClosestMatch( $input, $this->permission_control_options );
if ( $retval === false ) {
$retval = -1; //Make sure this fails.
}
return $retval;
}
/**
* @return bool
*/
function getPolicyGroupOptions() {
//Get job titles
$pglf = TTNew( 'PolicyGroupListFactory' ); /** @var PolicyGroupListFactory $pglf */
$pglf->getByCompanyId( $this->company_id );
$this->policy_group_options = (array)$pglf->getArrayByListFactory( $pglf, false );
unset( $pglf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_policy_group( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID(); //No Permission Group
}
if ( !is_array( $this->policy_group_options ) ) {
$this->getPolicyGroupOptions();
}
$retval = $this->findClosestMatch( $input, $this->policy_group_options );
if ( $retval === false ) {
$retval = -1; //Make sure this fails.
}
return $retval;
}
/**
* @return bool
*/
function getPayPeriodScheduleOptions() {
//Get job titles
$pglf = TTNew( 'PayPeriodScheduleListFactory' ); /** @var PayPeriodScheduleListFactory $pglf */
$pglf->getByCompanyId( $this->company_id );
$this->pay_period_schedule_options = (array)$pglf->getArrayByListFactory( $pglf, false );
unset( $pglf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_pay_period_schedule( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID(); //No Permission Group
}
if ( !is_array( $this->pay_period_schedule_options ) ) {
$this->getPayPeriodScheduleOptions();
}
$retval = $this->findClosestMatch( $input, $this->pay_period_schedule_options );
if ( $retval === false ) {
$retval = -1; //Make sure this fails.
}
return $retval;
}
/**
* @return bool
*/
function getUserTitleOptions() {
//Get job titles
$utlf = TTNew( 'UserTitleListFactory' ); /** @var UserTitleListFactory $utlf */
$utlf->getByCompanyId( $this->company_id );
$this->title_options = (array)$utlf->getArrayByListFactory( $utlf, false );
unset( $utlf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_title( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID(); //No title
}
if ( !is_array( $this->title_options ) ) {
$this->getUserTitleOptions();
}
$retval = $this->findClosestMatch( $input, $this->title_options );
if ( $retval === false ) {
if ( $this->getImportOptions( 'create_title' ) == true ) {
$utf = TTnew( 'UserTitleFactory' ); /** @var UserTitleFactory $utf */
$utf->setCompany( $this->company_id );
$utf->setName( $input );
if ( $utf->isValid() ) {
$new_title_id = $utf->Save();
$this->getUserTitleOptions(); //Update group records after we've added a new one.
Debug::Text( 'Created new title name: ' . $input . ' ID: ' . $new_title_id, __FILE__, __LINE__, __METHOD__, 10 );
return $new_title_id;
}
unset( $utf, $new_title_id );
}
$retval = -1; //Make sure this fails.
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_default_branch( $input, $default_value = null, $parse_hint = null ) {
return $this->parse_branch( $input, $default_value, $parse_hint );
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_default_department( $input, $default_value = null, $parse_hint = null ) {
return $this->parse_department( $input, $default_value, $parse_hint );
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_default_job( $input, $default_value = null, $parse_hint = null ) {
return $this->parse_job( $input, $default_value, $parse_hint );
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_default_job_item( $input, $default_value = null, $parse_hint = null ) {
return $this->parse_job_item( $input, $default_value, $parse_hint );
}
/**
* @return bool
*/
function getUserGroupOptions() {
//Get groups
$uglf = TTNew( 'UserGroupListFactory' ); /** @var UserGroupListFactory $uglf */
$uglf->getByCompanyId( $this->company_id );
$this->user_group_options = (array)$uglf->getArrayByListFactory( $uglf, false );
unset( $uglf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_group( $input, $default_value = null, $parse_hint = null ) {
return $this->parse_user_group( $input, $default_value, $parse_hint );
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_user_group( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID(); //No group
}
if ( !is_array( $this->user_group_options ) ) {
$this->getUserGroupOptions();
}
$retval = $this->findClosestMatch( $input, $this->user_group_options );
if ( $retval === false ) {
if ( $this->getImportOptions( 'create_group' ) == true ) {
$ugf = TTnew( 'UserGroupFactory' ); /** @var UserGroupFactory $ugf */
$ugf->setCompany( $this->company_id );
$ugf->setParent( TTUUID::getZeroID() );
$ugf->setName( $input );
if ( $ugf->isValid() ) {
$new_group_id = $ugf->Save();
$this->getUserGroupOptions(); //Update group records after we've added a new one.
Debug::Text( 'Created new group name: ' . $input . ' ID: ' . $new_group_id, __FILE__, __LINE__, __METHOD__, 10 );
return $new_group_id;
}
unset( $ugf, $new_group_id );
}
$retval = -1; //Make sure this fails.
}
return $retval;
}
/**
* @return bool
*/
function getEthnicGroupOptions() {
//Get groups
$uglf = TTNew( 'EthnicGroupListFactory' ); /** @var EthnicGroupListFactory $uglf */
$uglf->getByCompanyId( $this->company_id );
$this->ethnic_group_options = (array)$uglf->getArrayByListFactory( $uglf, false );
unset( $uglf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_ethnic_group( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID(); //No group
}
if ( !is_array( $this->user_group_options ) ) {
$this->getEthnicGroupOptions();
}
$retval = $this->findClosestMatch( $input, $this->ethnic_group_options );
if ( $retval === false ) {
if ( $this->getImportOptions( 'create_ethnic_group' ) == true ) {
$egf = TTnew( 'EthnicGroupFactory' ); /** @var EthnicGroupFactory $egf */
$egf->setCompany( $this->company_id );
$egf->setName( $input );
if ( $egf->isValid() ) {
$new_group_id = $egf->Save();
$this->getEthnicGroupOptions(); //Update group records after we've added a new one.
Debug::Text( 'Created new ethnic group name: ' . $input . ' ID: ' . $new_group_id, __FILE__, __LINE__, __METHOD__, 10 );
return $new_group_id;
}
unset( $egf, $new_group_id );
}
$retval = -1; //Make sure this fails.
}
return $retval;
}
/**
* @return bool
*/
function getHierarchyControlOptions() {
//Get job titles
$hclf = TTNew( 'HierarchyControlListFactory' ); /** @var HierarchyControlListFactory $hclf */
$hclf->getObjectTypeAppendedListByCompanyID( $this->company_id );
$this->hierarchy_control_options = (array)$hclf->getArrayByListFactory( $hclf, true, false, true );
unset( $hclf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return int
*/
function parse_hierarchy_control_display( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID(); //No Hierarchy
}
if ( !is_array( $this->hierarchy_control_options ) ) {
$this->getHierarchyControlOptions();
}
Debug::Text( 'Finding hierarchy for: ' . $input, __FILE__, __LINE__, __METHOD__, 10 );
$retval = $this->findClosestMatch( $input, $this->hierarchy_control_options );
if ( $retval === false ) {
$retarr = -1; //Make sure this fails.
} else {
//Use only the permission object_type_id, if the hierarchies use all objects this will work fine as well.
$retarr[100] = $retval;
}
return $retarr;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return string
*/
function parse_phone_id( $input, $default_value = null, $parse_hint = null ) {
if ( strlen( $input ) < 4 ) {
$retval = str_pad( $input, 4, 0, STR_PAD_LEFT );
} else {
$retval = $input;
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return string
*/
function parse_phone_password( $input, $default_value = null, $parse_hint = null ) {
if ( strlen( $input ) < 4 ) {
$retval = str_pad( $input, 4, 0, STR_PAD_LEFT );
} else {
$retval = $input;
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return false|int
*/
function parse_birth_date( $input, $default_value = null, $parse_hint = null ) {
return $this->parse_date( $input, $default_value, $parse_hint );
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return false|int
*/
function parse_hire_date( $input, $default_value = null, $parse_hint = null ) {
return $this->parse_date( $input, $default_value, $parse_hint );
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return false|int
*/
function parse_termination_date( $input, $default_value = null, $parse_hint = null ) {
return $this->parse_date( $input, $default_value, $parse_hint );
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return false|int
*/
function parse_wage_effective_date( $input, $default_value = null, $parse_hint = null ) {
return $this->parse_date( $input, $default_value, $parse_hint );
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return int
*/
function parse_wage_type( $input, $default_value = null, $parse_hint = null ) {
if ( strtolower( $input ) == 'salary' || strtolower( $input ) == 'salaried' || strtolower( $input ) == 's' || strtolower( $input ) == 'annual' ) {
$retval = 20;
} else if ( strtolower( $input ) == 'month' || strtolower( $input ) == 'monthly' ) {
$retval = 15;
} else if ( strtolower( $input ) == 'biweekly' || strtolower( $input ) == 'bi-weekly' ) {
$retval = 13;
} else if ( strtolower( $input ) == 'week' || strtolower( $input ) == 'weekly' ) {
$retval = 12;
} else {
$retval = 10;
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|float|int|number|string
*/
function parse_wage_weekly_time( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setTimeUnitFormat( $parse_hint );
}
$retval = TTDate::parseTimeUnit( $input );
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return mixed
*/
function parse_wage( $input, $default_value = null, $parse_hint = null ) {
$val = new Validator();
$retval = $val->stripNonFloat( $input );
return $retval;
}
}
?>
@@ -0,0 +1,318 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\Import
*/
class ImportUserDeduction extends Import {
public $class_name = 'APIUserDeduction';
/**
* @param $name
* @param null $parent
* @return array|bool|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
$retval = Misc::prependArray( $this->getUserIdentificationColumns(), [ 'company_deduction_id' => TTi18n::getText( 'Tax / Deduction' ) ] );
global $current_user;
//Get a Tax/Deductions that can be imported.
$cdlf = TTNew( 'CompanyDeductionListFactory' );
$cdlf->getByCompanyId( $current_user->getCompany() );
if ( $cdlf->getRecordCount() > 0 ) {
foreach( $cdlf as $cd_obj ) { /** @var CompanyDeductionFactory $cd_obj */
$calculation_type_column_meta_data = $cd_obj->getOptions( 'calculation_type_column_meta_data', [ 'calculation_id' => $cd_obj->getCalculation(), 'country' => $cd_obj->getCountry(), 'province' => $cd_obj->getProvince() ] );
if ( is_array( $calculation_type_column_meta_data ) ) {
foreach ( $calculation_type_column_meta_data as $key => $meta_data ) {
$column_key = $cd_obj->getUniqueKeyPrefix( $key );
$column_name = $cd_obj->getUniqueNamePrefix( $meta_data['name'] );
$retval[$column_key] = $column_name;
}
}
}
}
//Debug::Arr( $retval, 'Import Columns: ', __FILE__, __LINE__, __METHOD__, 10);
break;
case 'column_aliases':
//Used for converting column names after they have been parsed.
$retval = [];
break;
case 'import_options':
$retval = [
'-1010-fuzzy_match' => TTi18n::getText( 'Enable smart matching.' ),
'-1015-update' => TTi18n::getText( 'Update existing records based on Employee and Tax / Deduction' ),
];
break;
case 'parse_hint':
$retval = [];
break;
}
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _preParseRow( $row_number, $raw_row ) {
//$retval = $this->getObject()->stripReturnHandler( $this->getObject()->getUserDeductionDefaultData() );
return $raw_row;
}
function getCompanyDeductionObject( $id ) {
$cdlf = TTnew('CompanyDeductionListFactory');
$cdlf->getByIdAndCompanyId( $id, $this->company_id );
if ( $cdlf->getRecordCount() == 1 ) {
return $cdlf->getCurrent();
}
return false;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _postParseRow( $row_number, $raw_row ) {
$raw_row['user_id'] = $this->getUserIdByRowData( $raw_row );
if ( $raw_row['user_id'] == false ) {
unset( $raw_row['user_id'] );
}
if ( $this->getImportOptions( 'update' ) == true ) {
Debug::Text( 'Updating existing records, try to find record... ', __FILE__, __LINE__, __METHOD__, 10 );
if ( isset( $raw_row['user_id'] ) && isset( $raw_row['company_deduction_id'] ) ) {
$udlf = TTnew( 'UserDeductionListFactory' );
$udlf->getByUserIdAndCompanyDeductionId( $raw_row['user_id'], $raw_row['company_deduction_id'] );
if ( $udlf->getRecordCount() == 1 ) {
$raw_row['id'] = $udlf->getCurrent()->getId();
if ( $raw_row['id'] == false ) {
unset( $raw_row['id'] );
}
}
} else {
Debug::Text( ' NOTICE: UserID/CompanyDeductionID not specified... Unable to find existing record to update.', __FILE__, __LINE__, __METHOD__, 10 );
unset( $raw_row['id'] );
}
} else {
Debug::Text( 'NOT updating existing records... ', __FILE__, __LINE__, __METHOD__, 10 );
}
$cd_obj = $this->getCompanyDeductionObject( TTUUID::castUUID( $raw_row['company_deduction_id'] ) );
if ( is_object( $cd_obj ) ) {
//Strip column prefix so it can be parsed.
foreach( $raw_row as $key => $value ) {
if ( strpos( $key, $cd_obj->getUniqueKeyPrefix() ) !== false ) {
if ( strpos( $key, 'user_value' ) !== false || strpos( $key, 'company_value' ) !== false ) {
preg_match( '/((user_value|company_value)[0-9]{1,2})/i', $key, $matches );
if ( isset( $matches[0] ) ) {
$parsed_value = $this->parse_user_values( $cd_obj, $matches[0], $value );
if ( $parsed_value !== -1 ) { //-1 = Failed.
$raw_row[$matches[0]] = $parsed_value;
}
}
unset( $raw_row[$key] );
} else {
Debug::Text( 'Column is not a CompanyDeduction dynamic field: '. $key .' Tax/Deduction: '. $cd_obj->getName() .'('. $cd_obj->getId() .')', __FILE__, __LINE__, __METHOD__, 10 );
}
} else {
Debug::Text( 'Column is not part of this CompanyDeduction record: '. $key .' Tax/Deduction: '. $cd_obj->getName() .'('. $cd_obj->getId() .')', __FILE__, __LINE__, __METHOD__, 10 );
}
}
}
return $raw_row;
}
/**
* @param int $validate_only EPOCH
* @return mixed
*/
function _import( $validate_only ) {
return $this->getObject()->setUserDeduction( $this->getParsedData(), $validate_only );
}
//
// Generic parser functions.
//
function getUserDeductionByUserIdAndCompanyDeductionId( $user_id, $company_deduction_id ) {
$udlf = TTnew('UserDeductionListFactory');
$udlf->getByUserIdAndCompanyDeductionId( $user_id, $company_deduction_id );
if ( $udlf->getRecordCount() == 1 ) {
return $udlf->getCurrent()->getId();
}
return false;
}
/**
* @return bool
*/
function getCompanyDeductionOptions( $user_id ) {
//Get legal entity of user.
$ulf = TTnew('UserListFactory');
$ulf->getByIdAndCompanyId( $user_id, $this->company_id );
if ( $ulf->getRecordCount() == 1 ) {
$u_obj = $ulf->getCurrent();
//Get Tax/Deduction records assocaited with that legal entity, and any not associated with any legal entity.
$cdlf = TTNew( 'CompanyDeductionListFactory' ); /** @var CompanyDeductionListFactory $cdlf */
$cdlf->getByCompanyIdAndLegalEntityId( $this->company_id, [ $u_obj->getLegalEntity(), TTUUID::getZeroID(), TTUUID::getNotExistID() ] );
$retval = (array)$cdlf->getArrayByListFactory( $cdlf, false, false );
return $retval;
}
return [];
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_company_deduction_id( $input, $default_value = null, $parse_hint = null, $map_data = null, $raw_row = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID();
}
$raw_row['user_id'] = $this->getUserIdByRowData( $raw_row );
if ( $raw_row['user_id'] == false ) {
return -1; //Make sure this fails.
}
$company_deduction_options = $this->getCompanyDeductionOptions( $raw_row['user_id'] ); //Can't really be cached, as its specific to each legal entity, which is linked to the user, and can be different for every row.
$retval = $this->findClosestMatch( $input, $company_deduction_options, 80 ); //Because we could be matching on "CA - State Income Tax" or "CT - State Income Tax", the match percent must be high.
if ( $retval === false ) {
$retval = -1; //Make sure this fails.
}
return $retval;
}
function parse_user_values( $cd_obj, $column, $input ) {
$retval = $input;
$calculation_type_column_meta_data = $cd_obj->getOptions( 'calculation_type_column_meta_data', [ 'calculation_id' => $cd_obj->getCalculation(), 'country' => $cd_obj->getCountry(), 'province' => $cd_obj->getProvince() ] );
if ( isset( $calculation_type_column_meta_data[$column] ) ) {
Debug::Text( 'Parsing Column: '. $column .' Raw Value: '. $input .' Tax/Deduction: '. $cd_obj->getName() .'('. $cd_obj->getId() .')', __FILE__, __LINE__, __METHOD__, 10);
$val = new Validator();
switch ( $calculation_type_column_meta_data[$column]['type_id'] ) {
case 2100:
if ( isset( $calculation_type_column_meta_data[$column]['multi_select_items'][$input] ) ) { //Exact match on the option key.
$retval = $input;
} else {
$retval = $this->findClosestMatch( $input, $calculation_type_column_meta_data[$column]['multi_select_items'] );
if ( $retval === false ) {
$retval = -1; //Make sure this fails.
if ( $cd_obj->getCalculation() == 100 && $cd_obj->getCountry() == 'US' ) { //US - Federal Income Tax
switch ( $column ) {
case 'user_value1': //Filing Status
if ( strtolower( $input ) == 's'
|| strtolower( $input ) == 'single' ) {
$retval = 10;
} else if ( strtolower( $input ) == 'm'
|| strtolower( $input ) == 'married' ) {
$retval = 20;
} else if ( strtolower( $input ) == 'h'
|| strtolower( $input ) == 'h' || strtolower( $input ) == 'hoh' ) {
$retval = 40;
}
break;
case 'user_value3': //Multiple Jobs: Yes/No
if ( strtolower( $input ) == 'y'
|| strtolower( $input ) == 'yes' ) {
$retval = 1;
} else {
$retval = 0;
}
break;
case 'user_value9': //Form W-4 Version
if ( strtolower( $input ) == 'y'
|| strtolower( $input ) == 'yes' ) { //2020 or Later: Yes/No
$retval = 2020;
}
break;
}
}
}
}
break;
case 400: //Integer
$retval = $val->stripNonNumeric( $input );
break;
case 410: //Decimal
$retval = $val->stripNonFloat( $input );
break;
case 420: //Currency
$retval = $val->stripNonFloat( $input );
break;
default:
$retval = $input;
break;
}
}
return $retval;
}
}
?>
@@ -0,0 +1,237 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\Import
*/
class ImportUserEducation extends Import {
public $class_name = 'APIUserEducation';
public $qualification_options = false;
/**
* @param $name
* @param null $parent
* @return array|bool|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
$uef = TTNew( 'UserEducationFactory' ); /** @var UserWageFactory $uef */
$retval = Misc::prependArray( $this->getUserIdentificationColumns(), Misc::arrayIntersectByKey( [ 'qualification', 'institute', 'major', 'minor', 'grade_score', 'start_date', 'end_date', 'graduate_date' ], Misc::trimSortPrefix( $uef->getOptions( 'columns' ) ) ) );
break;
case 'column_aliases':
//Used for converting column names after they have been parsed.
$retval = [
'qualification' => 'qualification_id',
];
break;
case 'import_options':
$retval = [
'-1010-fuzzy_match' => TTi18n::getText( 'Enable smart matching.' ),
'-1050-create_qualification' => TTi18n::getText( 'Create courses that don\'t already exist.' ),
];
break;
case 'parse_hint':
$upf = TTnew( 'UserPreferenceFactory' ); /** @var UserPreferenceFactory $upf */
$retval = [
'start_date' => $upf->getOptions( 'date_format' ),
'end_date' => $upf->getOptions( 'date_format' ),
'graduate_date' => $upf->getOptions( 'date_format' ),
];
break;
}
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _preParseRow( $row_number, $raw_row ) {
$user_education_default_data = $this->getObject()->stripReturnHandler( $this->getObject()->getUserEducationDefaultData() ); //Get default data.
$user_education_default_data['institute'] = ''; //If the user doesn't specify this, it will trigger a friendly validation error stating that it must be.
$user_education_default_data['major'] = ''; //If the user doesn't specify this, it will trigger a friendly validation error stating that it must be.
$user_education_default_data['minor'] = ''; //If the user doesn't specify this, it will trigger a friendly validation error stating that it must be.
$retval = $user_education_default_data;
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _postParseRow( $row_number, $raw_row ) {
$raw_row['user_id'] = $this->getUserIdByRowData( $raw_row );
if ( $raw_row['user_id'] == false ) {
unset( $raw_row['user_id'] );
}
return $raw_row;
}
/**
* @param int $validate_only EPOCH
* @return mixed
*/
function _import( $validate_only ) {
return $this->getObject()->setUserEducation( $this->getParsedData(), $validate_only );
}
//
// Generic parser functions.
//
/**
* @return bool
*/
function getQualificationOptions( $type_id ) {
//Get qualifications
$qlf = TTNew( 'QualificationListFactory' ); /** @var QualificationListFactory $qlf */
$qlf->getByCompanyIdAndTypeId( $this->company_id, $type_id );
$this->qualification_options = (array)$qlf->getArrayByListFactory( $qlf, false );
unset( $qlf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_qualification( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID(); //No qualification
}
$type_id = 20; //20=Education
if ( !is_array( $this->qualification_options ) ) {
$this->getQualificationOptions( $type_id );
}
$retval = $this->findClosestMatch( $input, $this->qualification_options );
if ( $retval === false ) {
if ( $this->getImportOptions( 'create_qualification' ) == true ) {
$qf = TTnew( 'QualificationFactory' ); /** @var QualificationFactory $qf */
$qf->setCompany( $this->company_id );
$qf->setType( $type_id );
$qf->setVisibilityType( 10 ); //Internal Only
$qf->setName( $input );
if ( $qf->isValid() ) {
$new_qualification_id = $qf->Save();
$this->getQualificationOptions( $type_id ); //Update group records after we've added a new one.
Debug::Text( 'Created new qualification name: ' . $input . ' ID: ' . $new_qualification_id, __FILE__, __LINE__, __METHOD__, 10 );
return $new_qualification_id;
}
unset( $qf, $new_qualification_id );
}
$retval = -1; //Make sure this fails.
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|false|int
*/
function parse_start_date( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setDateFormat( $parse_hint );
return TTDate::parseDateTime( $input );
} else {
return TTDate::strtotime( $input );
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|false|int
*/
function parse_end_date( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setDateFormat( $parse_hint );
return TTDate::parseDateTime( $input );
} else {
return TTDate::strtotime( $input );
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|false|int
*/
function parse_graduate_date( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setDateFormat( $parse_hint );
return TTDate::parseDateTime( $input );
} else {
return TTDate::strtotime( $input );
}
}
}
?>
@@ -0,0 +1,290 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\Import
*/
class ImportUserSkill extends Import {
public $class_name = 'APIUserSkill';
public $qualification_options = false;
/**
* @param $name
* @param null $parent
* @return array|bool|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
$usf = TTNew( 'UserSkillFactory' ); /** @var UserWageFactory $usf */
$retval = Misc::prependArray( $this->getUserIdentificationColumns(), Misc::arrayIntersectByKey( [ 'qualification', 'proficiency', 'first_used_date', 'last_used_date', 'expiry_date', 'description' ], Misc::trimSortPrefix( $usf->getOptions( 'columns' ) ) ) );
break;
case 'column_aliases':
//Used for converting column names after they have been parsed.
$retval = [
'proficiency' => 'proficiency_id',
'qualification' => 'qualification_id',
];
break;
case 'import_options':
$retval = [
'-1010-fuzzy_match' => TTi18n::getText( 'Enable smart matching.' ),
'-1050-create_qualification' => TTi18n::getText( 'Create skills that don\'t already exist.' ),
];
break;
case 'parse_hint':
$upf = TTnew( 'UserPreferenceFactory' ); /** @var UserPreferenceFactory $upf */
$retval = [
'first_used_date' => $upf->getOptions( 'date_format' ),
'last_used_date' => $upf->getOptions( 'date_format' ),
'expiry_date' => $upf->getOptions( 'date_format' ),
];
break;
}
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _preParseRow( $row_number, $raw_row ) {
$user_skill_default_data = $this->getObject()->stripReturnHandler( $this->getObject()->getUserSkillDefaultData() ); //Get default data.
$user_skill_default_data['enable_calc_experience'] = true;
$user_skill_default_data['proficiency_id'] = 0; //If the user doesn't specify proficiency this will trigger a friendly validation error stating that it must be.
$retval = $user_skill_default_data;
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _postParseRow( $row_number, $raw_row ) {
$raw_row['user_id'] = $this->getUserIdByRowData( $raw_row );
if ( $raw_row['user_id'] == false ) {
unset( $raw_row['user_id'] );
}
return $raw_row;
}
/**
* @param int $validate_only EPOCH
* @return mixed
*/
function _import( $validate_only ) {
return $this->getObject()->setUserSkill( $this->getParsedData(), $validate_only );
}
//
// Generic parser functions.
//
/**
* @return bool
*/
function getQualificationOptions( $type_id ) {
//Get qualifications
$qlf = TTNew( 'QualificationListFactory' ); /** @var QualificationListFactory $qlf */
$qlf->getByCompanyIdAndTypeId( $this->company_id, $type_id );
$this->qualification_options = (array)$qlf->getArrayByListFactory( $qlf, false );
unset( $qlf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_qualification( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' ) {
return TTUUID::getZeroID(); //No qualification
}
$type_id = 10; //10=Skills
if ( !is_array( $this->qualification_options ) ) {
$this->getQualificationOptions( $type_id );
}
$retval = $this->findClosestMatch( $input, $this->qualification_options );
if ( $retval === false ) {
if ( $this->getImportOptions( 'create_qualification' ) == true ) {
$qf = TTnew( 'QualificationFactory' ); /** @var QualificationFactory $qf */
$qf->setCompany( $this->company_id );
$qf->setType( $type_id );
$qf->setVisibilityType( 10 ); //Internal Only
$qf->setName( $input );
if ( $qf->isValid() ) {
$new_qualification_id = $qf->Save();
$this->getQualificationOptions( $type_id ); //Update group records after we've added a new one.
Debug::Text( 'Created new qualification name: ' . $input . ' ID: ' . $new_qualification_id, __FILE__, __LINE__, __METHOD__, 10 );
return $new_qualification_id;
}
unset( $qf, $new_qualification_id );
}
$retval = -1; //Make sure this fails.
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|false|int
*/
function parse_first_used_date( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setDateFormat( $parse_hint );
return TTDate::parseDateTime( $input );
} else {
return TTDate::strtotime( $input );
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|false|int
*/
function parse_last_used_date( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setDateFormat( $parse_hint );
return TTDate::parseDateTime( $input );
} else {
return TTDate::strtotime( $input );
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|false|int
*/
function parse_expiry_date( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setDateFormat( $parse_hint );
return TTDate::parseDateTime( $input );
} else {
return TTDate::strtotime( $input );
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_proficiency( $input, $default_value = null, $parse_hint = null ) {
$usf = TTnew( 'UserSkillFactory' ); /** @var UserSkillFactory $usf */
$options = Misc::trimSortPrefix( $usf->getOptions( 'proficiency' ) );
if ( isset( $options[$input] ) ) {
$retval = $input;
} else {
if ( $this->getImportOptions( 'fuzzy_match' ) == true ) {
$retval = $this->findClosestMatch( $input, $options, 50 );
} else {
$retval = array_search( strtolower( $input ), array_map( 'strtolower', $options ) );
}
}
if ( $retval === false ) {
$input = (int)$input;
if ( $input == 10 ) {
$retval = 10; //Excellent
} else if ( $input == 9 ) {
$retval = 10; //Excellent
} else if ( $input == 8 ) {
$retval = 20; //Very Good
} else if ( $input == 7 ) {
$retval = 30; //Good
} else if ( $input == 6 ) {
$retval = 40; //Above Average
} else if ( $input == 5 ) {
$retval = 50; // Average
} else if ( $input == 4 ) {
$retval = 60; //Below Average
} else if ( $input == 3 ) {
$retval = 70; //Fair
} else if ( $input == 2 ) {
$retval = 80; //Poor
} else if ( $input == 1 ) {
$retval = 90; //Bad
} else if ( $input == 0 ) {
$retval = 90; //Bad
} else {
$retval = 50; //Average
}
}
return $retval;
}
}
?>
@@ -0,0 +1,255 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\Import
*/
class ImportUserWage extends Import {
public $class_name = 'APIUserWage';
public $wage_group_options = false;
/**
* @param $name
* @param null $parent
* @return array|bool|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
$uwf = TTNew( 'UserWageFactory' ); /** @var UserWageFactory $uwf */
$retval = Misc::prependArray( $this->getUserIdentificationColumns(), Misc::arrayIntersectByKey( [ 'wage_group', 'type', 'wage', 'effective_date', 'hourly_rate', 'labor_burden_percent', 'weekly_time', 'note' ], Misc::trimSortPrefix( $uwf->getOptions( 'columns' ) ) ) );
break;
case 'column_aliases':
//Used for converting column names after they have been parsed.
$retval = [
'type' => 'type_id',
'wage_group' => 'wage_group_id',
];
break;
case 'import_options':
$retval = [
'-1010-fuzzy_match' => TTi18n::getText( 'Enable smart matching.' ),
];
break;
case 'parse_hint':
$upf = TTnew( 'UserPreferenceFactory' ); /** @var UserPreferenceFactory $upf */
$retval = [
'effective_date' => $upf->getOptions( 'date_format' ),
'weekly_time' => $upf->getOptions( 'time_unit_format' ),
];
break;
}
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _preParseRow( $row_number, $raw_row ) {
$user_id = $this->getUserIdByRowData( $raw_row ); //Try to get user_id of row so we set default effective_date to the employees hire_date.
$user_wage_default_data = $this->getObject()->stripReturnHandler( $this->getObject()->getUserWageDefaultData( $user_id ) );
$user_wage_default_data['effective_date'] = TTDate::parseDateTime( $user_wage_default_data['effective_date'] ); //Effective Date is formatted for user to see, so convert it to epoch for importing.
$retval = $user_wage_default_data;
return $retval;
}
/**
* @param $row_number
* @param $raw_row
* @return mixed
*/
function _postParseRow( $row_number, $raw_row ) {
$raw_row['user_id'] = $this->getUserIdByRowData( $raw_row );
if ( $raw_row['user_id'] == false ) {
unset( $raw_row['user_id'] );
}
//If its a salary type, make sure average weekly time is always specified and hourly rate.
return $raw_row;
}
/**
* @param int $validate_only EPOCH
* @return mixed
*/
function _import( $validate_only ) {
return $this->getObject()->setUserWage( $this->getParsedData(), $validate_only );
}
//
// Generic parser functions.
//
/**
* @return bool
*/
function getWageGroupOptions() {
//Get job titles
$wglf = TTNew( 'WageGroupListFactory' ); /** @var WageGroupListFactory $wglf */
$wglf->getByCompanyId( $this->company_id );
$this->wage_group_options = (array)$wglf->getArrayByListFactory( $wglf, false );
unset( $wglf );
return true;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_wage_group( $input, $default_value = null, $parse_hint = null ) {
if ( trim( $input ) == '' || trim( strtolower( $input ) ) == 'default' ) {
return TTUUID::getZeroID(); //Default Wage Group
}
if ( !is_array( $this->wage_group_options ) ) {
$this->getWageGroupOptions();
}
$retval = $this->findClosestMatch( $input, $this->wage_group_options );
if ( $retval === false ) {
$retval = -1; //Make sure this fails.
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|false|int
*/
function parse_effective_date( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setDateFormat( $parse_hint );
return TTDate::parseDateTime( $input );
} else {
return TTDate::strtotime( $input );
}
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return array|bool|int|mixed
*/
function parse_type( $input, $default_value = null, $parse_hint = null ) {
$uwf = TTnew( 'UserWageFactory' ); /** @var UserWageFactory $uwf */
$options = Misc::trimSortPrefix( $uwf->getOptions( 'type' ) );
if ( isset( $options[$input] ) ) {
$retval = $input;
} else {
if ( $this->getImportOptions( 'fuzzy_match' ) == true ) {
$retval = $this->findClosestMatch( $input, $options, 50 );
} else {
$retval = array_search( strtolower( $input ), array_map( 'strtolower', $options ) );
}
}
if ( $retval === false ) {
if ( strtolower( $input ) == 'salary' || strtolower( $input ) == 'salaried' || strtolower( $input ) == 's' || strtolower( $input ) == 'annual' ) {
$retval = 20;
} else if ( strtolower( $input ) == 'month' || strtolower( $input ) == 'monthly' ) {
$retval = 15;
} else if ( strtolower( $input ) == 'biweekly' || strtolower( $input ) == 'bi-weekly' ) {
$retval = 13;
} else if ( strtolower( $input ) == 'week' || strtolower( $input ) == 'weekly' ) {
$retval = 12;
} else {
$retval = 10;
}
}
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return bool|float|int|number|string
*/
function parse_weekly_time( $input, $default_value = null, $parse_hint = null ) {
if ( isset( $parse_hint ) && $parse_hint != '' ) {
TTDate::setTimeUnitFormat( $parse_hint );
}
$retval = TTDate::parseTimeUnit( $input );
return $retval;
}
/**
* @param $input
* @param null $default_value
* @param null $parse_hint
* @return mixed
*/
function parse_wage( $input, $default_value = null, $parse_hint = null ) {
$val = new Validator();
$retval = $val->stripNonFloat( $input );
return $retval;
}
}
?>