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

View File

@ -0,0 +1,399 @@
<?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\Accrual
*/
class AccrualBalanceFactory extends Factory {
protected $table = 'accrual_balance';
protected $pk_sequence_name = 'accrual_balance_id_seq'; //PK Sequence name
var $user_obj = null;
/**
* @param $name
* @param null $parent
* @return array|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
$retval = [
'-1010-first_name' => TTi18n::gettext( 'First Name' ),
'-1020-last_name' => TTi18n::gettext( 'Last Name' ),
'-1030-accrual_policy_account' => TTi18n::gettext( 'Accrual Account' ),
//'-1040-accrual_policy_type' => TTi18n::gettext('Accrual Policy Type'),
'-1050-balance' => TTi18n::gettext( 'Balance' ),
'-1090-title' => TTi18n::gettext( 'Title' ),
'-1099-group' => TTi18n::gettext( 'Group' ),
'-1100-default_branch' => TTi18n::gettext( 'Branch' ),
'-1110-default_department' => TTi18n::gettext( 'Department' ),
];
break;
case 'list_columns':
$retval = Misc::arrayIntersectByKey( [ 'accrual_policy_account', 'balance' ], Misc::trimSortPrefix( $this->getOptions( 'columns' ) ) );
break;
case 'default_display_columns': //Columns that are displayed by default.
$retval = [
'first_name',
'last_name',
'accrual_policy_account',
//'accrual_policy_type',
'balance',
];
break;
}
return $retval;
}
/**
* @param $data
* @return array
*/
function _getVariableToFunctionMap( $data ) {
$variable_function_map = [
'user_id' => 'User',
'first_name' => false,
'last_name' => false,
'accrual_policy_account_id' => 'AccrualPolicyAccount',
'accrual_policy_account' => false,
//'accrual_policy_type_id' => FALSE,
//'accrual_policy_type' => FALSE,
'default_branch' => false,
'default_department' => false,
'group' => false,
'title' => false,
'balance' => 'Balance',
];
return $variable_function_map;
}
/**
* @return bool
*/
function getUserObject() {
return $this->getGenericObject( 'UserListFactory', $this->getUser(), 'user_obj' );
}
/**
* @return bool|mixed
*/
function getUser() {
return $this->getGenericDataValue( 'user_id' );
}
/**
* @param $value
* @return bool
*/
function setUser( $value ) {
$value = TTUUID::castUUID( $value );
return $this->setGenericDataValue( 'user_id', $value );
}
/**
* @return bool|mixed
*/
function getAccrualPolicyAccount() {
return $this->getGenericDataValue( 'accrual_policy_account_id' );
}
/**
* @param $value
* @return bool
*/
function setAccrualPolicyAccount( $value ) {
$value = TTUUID::castUUID( $value );
return $this->setGenericDataValue( 'accrual_policy_account_id', $value );
}
/**
* @return bool|mixed
*/
function getBalance() {
return $this->getGenericDataValue( 'balance' );
}
/**
* @param $value
* @return bool
*/
function setBalance( $value ) {
$value = trim( $value );
if ( empty( $value ) ) {
$value = 0;
}
return $this->setGenericDataValue( 'balance', $value );
}
/**
* @return bool
*/
function getCreatedBy() {
return false;
}
/**
* @param string $id UUID
* @return bool
*/
function setCreatedBy( $id = null ) {
return false;
}
/**
* @return bool
*/
function getUpdatedDate() {
return false;
}
/**
* @param int $epoch EPOCH
* @return bool
*/
function setUpdatedDate( $epoch = null ) {
return false;
}
/**
* @return bool
*/
function getUpdatedBy() {
return false;
}
/**
* @param string $id UUID
* @return bool
*/
function setUpdatedBy( $id = null ) {
return false;
}
/**
* @return bool
*/
function getDeletedDate() {
return false;
}
/**
* @param int $epoch EPOCH
* @return bool
*/
function setDeletedDate( $epoch = null ) {
return false;
}
/**
* @return bool
*/
function getDeletedBy() {
return false;
}
/**
* @param string $id UUID
* @return bool
*/
function setDeletedBy( $id = null ) {
return false;
}
/**
* @param string $user_id UUID
* @param string $accrual_policy_account_id UUID
* @return bool
*/
static function calcBalance( $user_id, $accrual_policy_account_id = null ) {
global $profiler;
$profiler->startTimer( "AccrualBalanceFactory::calcBalance()" );
$retval = false;
$update_balance = true;
$alf = TTnew( 'AccrualListFactory' ); /** @var AccrualListFactory $alf */
$alf->StartTransaction();
//$alf->db->SetTransactionMode( 'SERIALIZABLE' ); //Serialize balance transactions so concurrency issues don't corrupt the balance.
$balance = $alf->getSumByUserIdAndAccrualPolicyAccount( $user_id, $accrual_policy_account_id );
Debug::text( 'Balance for User ID: ' . $user_id . ' Accrual Account ID: ' . $accrual_policy_account_id . ' Balance: ' . $balance, __FILE__, __LINE__, __METHOD__, 10 );
$ablf = TTnew( 'AccrualBalanceListFactory' ); /** @var AccrualBalanceListFactory $ablf */
$ablf->getByUserIdAndAccrualPolicyAccount( $user_id, $accrual_policy_account_id );
Debug::text( 'Found balance records: ' . $ablf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10 );
if ( $ablf->getRecordCount() > 1 ) { //In case multiple records exist, delete them all and re-insert.
foreach ( $ablf as $ab_obj ) {
$ab_obj->Delete( true );
}
$ab_obj = TTnew( 'AccrualBalanceFactory' ); /** @var AccrualBalanceFactory $ab_obj */
} else if ( $ablf->getRecordCount() == 1 ) {
$ab_obj = $ablf->getCurrent();
if ( $balance == $ab_obj->getBalance() ) {
Debug::text( 'Balance has not changed, not updating: ' . $balance, __FILE__, __LINE__, __METHOD__, 10 );
$update_balance = false;
}
} else { //No balance record exists yet.
$ab_obj = TTnew( 'AccrualBalanceFactory' ); /** @var AccrualBalanceFactory $ab_obj */
}
if ( $update_balance == true ) {
Debug::text( 'Setting new balance to: ' . $balance, __FILE__, __LINE__, __METHOD__, 10 );
$ab_obj->setUser( $user_id );
$ab_obj->setAccrualPolicyAccount( $accrual_policy_account_id );
$ab_obj->setBalance( $balance );
if ( $ab_obj->isValid() ) {
$retval = $ab_obj->Save();
} else {
$alf->FailTransaction();
Debug::text( 'Setting new balance failed for User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10 );
}
}
$alf->CommitTransaction();
//$alf->db->SetTransactionMode(''); //Restore default transaction mode.
$profiler->stopTimer( "AccrualBalanceFactory::calcBalance()" );
return $retval;
}
/**
* @param bool $ignore_warning
* @return bool
*/
function Validate( $ignore_warning = true ) {
//
// BELOW: Validation code moved from set*() functions.
//
// User
$ulf = TTnew( 'UserListFactory' ); /** @var UserListFactory $ulf */
$this->Validator->isResultSetWithRows( 'user_id',
$ulf->getByID( $this->getUser() ),
TTi18n::gettext( 'Invalid Employee' )
);
// Accrual Policy Account
if ( $this->getAccrualPolicyAccount() != TTUUID::getZeroID() ) {
$apalf = TTnew( 'AccrualPolicyAccountListFactory' ); /** @var AccrualPolicyAccountListFactory $apalf */
$this->Validator->isResultSetWithRows( 'accrual_policy_account_id',
$apalf->getByID( $this->getAccrualPolicyAccount() ),
TTi18n::gettext( 'Accrual Account is invalid' )
);
}
// Balance
if ( $this->getBalance() != 0 ) {
$this->Validator->isNumeric( 'balance',
$this->getBalance(),
TTi18n::gettext( 'Incorrect Balance' )
);
}
//
// ABOVE: Validation code moved from set*() functions.
//
return true;
}
/**
* @param null $include_columns
* @param bool $permission_children_ids
* @return array
*/
function getObjectAsArray( $include_columns = null, $permission_children_ids = false ) {
$data = [];
$variable_function_map = $this->getVariableToFunctionMap();
if ( is_array( $variable_function_map ) ) {
//$apf = TTnew( 'AccrualPolicyFactory' );
foreach ( $variable_function_map as $variable => $function_stub ) {
if ( $include_columns == null || ( isset( $include_columns[$variable] ) && $include_columns[$variable] == true ) ) {
$function = 'get' . $function_stub;
switch ( $variable ) {
case 'accrual_policy_account':
//case 'accrual_policy_type_id':
case 'first_name':
case 'last_name':
case 'title':
case 'group':
case 'default_branch':
case 'default_department':
$data[$variable] = $this->getColumn( $variable );
break;
//case 'accrual_policy_type':
// $data[$variable] = Option::getByKey( $this->getColumn( 'accrual_policy_type_id' ), $apf->getOptions( 'type' ) );
// break;
default:
if ( method_exists( $this, $function ) ) {
$data[$variable] = $this->$function();
}
break;
}
}
}
$this->getPermissionColumns( $data, $this->getUser(), false, $permission_children_ids, $include_columns );
//Accrual Balances are only created/modified by the system.
//$this->getCreatedAndUpdatedColumns( $data, $include_columns );
}
return $data;
}
}
?>

View File

@ -0,0 +1,440 @@
<?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\Accrual
*/
class AccrualBalanceListFactory extends AccrualBalanceFactory implements IteratorAggregate {
/**
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return $this
*/
function getAll( $limit = null, $page = null, $where = null, $order = null ) {
$query = '
select *
from ' . $this->getTable() . '
WHERE deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, null, $limit, $page );
return $this;
}
/**
* @param string $id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return AccrualBalanceListFactory|bool
*/
function getById( $id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
$ph = [
'id' => TTUUID::castUUID( $id ),
];
$query = '
select *
from ' . $this->getTable() . '
where id = ?
AND deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $company_id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return AccrualBalanceListFactory|bool
*/
function getByCompanyId( $company_id, $where = null, $order = null ) {
if ( $company_id == '' ) {
return false;
}
$uf = new UserFactory();
$ph = [
'company_id' => TTUUID::castUUID( $company_id ),
];
$query = '
select a.*
from ' . $this->getTable() . ' as a,
' . $uf->getTable() . ' as b
where a.user_id = b.id
AND b.company_id = ?
AND ( a.deleted = 0 AND b.deleted = 0 )';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $id UUID
* @param string $company_id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return AccrualBalanceListFactory|bool
*/
function getByIdAndCompanyId( $id, $company_id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
if ( $company_id == '' ) {
return false;
}
$uf = new UserFactory();
$ph = [
'id' => TTUUID::castUUID( $id ),
'company_id' => TTUUID::castUUID( $company_id ),
];
$query = '
select *
from ' . $this->getTable() . ' as a,
' . $uf->getTable() . ' as b
where a.id = ?
AND b.company_id = ?
AND ( a.deleted = 0 AND b.deleted = 0 )';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $user_id UUID
* @param string $company_id UUID
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return AccrualBalanceListFactory|bool
*/
function getByUserIdAndCompanyId( $user_id, $company_id, $limit = null, $page = null, $where = null, $order = null ) {
if ( $user_id == '' ) {
return false;
}
if ( $company_id == '' ) {
return false;
}
$additional_order_fields = [ 'a.balance', 'c.name' ];
if ( $order == null ) {
$order = [ 'c.name' => 'asc' ];
$strict = false;
} else {
$strict = true;
}
$uf = new UserFactory();
$apaf = new AccrualPolicyAccountFactory();
$af = new AccrualFactory();
$ph = [
'company_id' => TTUUID::castUUID( $company_id ),
];
$query = '
select
_ADODB_COUNT
a.*
_ADODB_COUNT
from ' . $this->getTable() . ' as a,
' . $uf->getTable() . ' as b,
' . $apaf->getTable() . ' as c
where a.user_id = b.id
AND a.accrual_policy_account_id = c.id
AND b.company_id = ?
AND a.user_id in (' . $this->getListSQL( $user_id, $ph, 'uuid' ) . ')
AND EXISTS ( select 1 from ' . $af->getTable() . ' as af WHERE af.accrual_policy_account_id = a.accrual_policy_account_id AND a.user_id = af.user_id AND af.deleted = 0 )
AND ( a.deleted = 0 AND b.deleted = 0 AND c.deleted = 0 )';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order, $strict, $additional_order_fields );
$this->rs = $this->ExecuteSQL( $query, $ph, $limit, $page );
return $this;
}
/**
* @param string $user_id UUID
* @param string $company_id UUID
* @param $enable_pay_stub_balance_display
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return AccrualBalanceListFactory|bool
*/
function getByUserIdAndCompanyIdAndEnablePayStubBalanceDisplay( $user_id, $company_id, $enable_pay_stub_balance_display, $limit = null, $page = null, $where = null, $order = null ) {
if ( $user_id == '' ) {
return false;
}
if ( $company_id == '' ) {
return false;
}
$additional_order_fields = [ 'a.balance', 'c.name' ];
if ( $order == null ) {
$order = [ 'c.name' => 'asc' ];
$strict = false;
} else {
$strict = true;
}
$uf = new UserFactory();
$apaf = new AccrualPolicyAccountFactory();
$ph = [
'company_id' => TTUUID::castUUID( $company_id ),
'enable_pay_stub_balance_display' => (int)$enable_pay_stub_balance_display,
];
$query = '
select a.*,
c.name as name
from ' . $this->getTable() . ' as a,
' . $uf->getTable() . ' as b,
' . $apaf->getTable() . ' as c
where a.user_id = b.id
AND a.accrual_policy_account_id = c.id
AND b.company_id = ?
AND c.enable_pay_stub_balance_display = ?
AND a.user_id in (' . $this->getListSQL( $user_id, $ph, 'uuid' ) . ')
AND ( a.deleted = 0 AND b.deleted = 0 AND c.deleted = 0 )';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order, $strict, $additional_order_fields );
$this->rs = $this->ExecuteSQL( $query, $ph, $limit, $page );
return $this;
}
/**
* @param string $user_id UUID
* @param string $accrual_policy_account_id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return AccrualBalanceListFactory|bool
*/
function getByUserIdAndAccrualPolicyAccount( $user_id, $accrual_policy_account_id, $where = null, $order = null ) {
if ( $user_id == '' ) {
return false;
}
if ( $accrual_policy_account_id == '' ) {
return false;
}
$ph = [
'user_id' => TTUUID::castUUID( $user_id ),
'accrual_policy_account_id' => TTUUID::castUUID( $accrual_policy_account_id ),
];
$query = '
select *
from ' . $this->getTable() . '
where user_id = ?
AND accrual_policy_account_id = ?
AND deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $company_id UUID
* @param $filter_data
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return AccrualBalanceListFactory|bool
*/
function getAPISearchByCompanyIdAndArrayCriteria( $company_id, $filter_data, $limit = null, $page = null, $where = null, $order = null ) {
if ( $company_id == '' ) {
return false;
}
if ( !is_array( $order ) ) {
//Use Filter Data ordering if its set.
if ( isset( $filter_data['sort_column'] ) && $filter_data['sort_order'] ) {
$order = [ Misc::trimSortPrefix( $filter_data['sort_column'] ) => $filter_data['sort_order'] ];
}
}
$additional_order_fields = [ 'accrual_policy_account', 'first_name', 'last_name', 'name', 'default_branch', 'default_department', 'title' ];
$sort_column_aliases = [
//'accrual_policy_type' => 'accrual_policy_type_id',
'group' => 'e.name',
];
$order = $this->getColumnsFromAliases( $order, $sort_column_aliases );
if ( $order == null ) {
$order = [ 'last_name' => 'asc', 'first_name' => 'asc', 'accrual_policy_account_id' => 'asc', 'a.created_date' => 'asc' ];
$strict = false;
} else {
//Always sort by last name, first name after other columns
/*
if ( !isset($order['effective_date']) ) {
$order['effective_date'] = 'desc';
}
*/
$strict = true;
}
//Debug::Arr($order, 'Order Data:', __FILE__, __LINE__, __METHOD__, 10);
//Debug::Arr($filter_data, 'Filter Data:', __FILE__, __LINE__, __METHOD__, 10);
$uf = new UserFactory();
$bf = new BranchFactory();
$df = new DepartmentFactory();
$ugf = new UserGroupFactory();
$utf = new UserTitleFactory();
$apaf = new AccrualPolicyAccountFactory();
$af = new AccrualFactory();
$ph = [
'company_id' => TTUUID::castUUID( $company_id ),
];
$query = '
select a.*,
ab.name as accrual_policy_account,
b.first_name as first_name,
b.last_name as last_name,
b.country as country,
b.province as province,
c.id as default_branch_id,
c.name as default_branch,
d.id as default_department_id,
d.name as default_department,
e.id as group_id,
e.name as "group",
f.id as title_id,
f.name as title
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $apaf->getTable() . ' as ab ON ( a.accrual_policy_account_id = ab.id AND ab.deleted = 0 )
LEFT JOIN ' . $uf->getTable() . ' as b ON ( a.user_id = b.id AND b.deleted = 0 )
LEFT JOIN ' . $bf->getTable() . ' as c ON ( b.default_branch_id = c.id AND c.deleted = 0)
LEFT JOIN ' . $df->getTable() . ' as d ON ( b.default_department_id = d.id AND d.deleted = 0)
LEFT JOIN ' . $ugf->getTable() . ' as e ON ( b.group_id = e.id AND e.deleted = 0 )
LEFT JOIN ' . $utf->getTable() . ' as f ON ( b.title_id = f.id AND f.deleted = 0 )
where b.company_id = ?
AND EXISTS ( select 1 from ' . $af->getTable() . ' as af WHERE af.accrual_policy_account_id = a.accrual_policy_account_id AND a.user_id = af.user_id AND af.deleted = 0 )
';
$query .= ( isset( $filter_data['permission_children_ids'] ) ) ? $this->getWhereClauseSQL( 'a.user_id', $filter_data['permission_children_ids'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['user_id'] ) ) ? $this->getWhereClauseSQL( 'a.user_id', $filter_data['user_id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['user_status_id'] ) ) ? $this->getWhereClauseSQL( 'b.status_id', $filter_data['user_status_id'], 'numeric_list', $ph ) : null;
$query .= ( isset( $filter_data['id'] ) ) ? $this->getWhereClauseSQL( 'a.id', $filter_data['id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['exclude_id'] ) ) ? $this->getWhereClauseSQL( 'a.user_id', $filter_data['exclude_id'], 'not_uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['accrual_policy_account_id'] ) ) ? $this->getWhereClauseSQL( 'a.accrual_policy_account_id', $filter_data['accrual_policy_account_id'], 'uuid_list', $ph ) : null;
if ( isset( $filter_data['status'] ) && !is_array( $filter_data['status'] ) && trim( $filter_data['status'] ) != '' && !isset( $filter_data['status_id'] ) ) {
$filter_data['status_id'] = Option::getByFuzzyValue( $filter_data['status'], $this->getOptions( 'status' ) );
}
$query .= ( isset( $filter_data['status_id'] ) ) ? $this->getWhereClauseSQL( 'b.status_id', $filter_data['status_id'], 'numeric_list', $ph ) : null;
$query .= ( isset( $filter_data['group_id'] ) ) ? $this->getWhereClauseSQL( 'b.group_id', $filter_data['group_id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['group'] ) ) ? $this->getWhereClauseSQL( 'e.name', $filter_data['group'], 'text', $ph ) : null;
$query .= ( isset( $filter_data['default_branch_id'] ) ) ? $this->getWhereClauseSQL( 'b.default_branch_id', $filter_data['default_branch_id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['default_branch'] ) ) ? $this->getWhereClauseSQL( 'c.name', $filter_data['default_branch'], 'text', $ph ) : null;
$query .= ( isset( $filter_data['default_department_id'] ) ) ? $this->getWhereClauseSQL( 'b.default_department_id', $filter_data['default_department_id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['default_department'] ) ) ? $this->getWhereClauseSQL( 'd.name', $filter_data['default_department'], 'text', $ph ) : null;
$query .= ( isset( $filter_data['title_id'] ) ) ? $this->getWhereClauseSQL( 'b.title_id', $filter_data['title_id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['title'] ) ) ? $this->getWhereClauseSQL( 'f.name', $filter_data['title'], 'text', $ph ) : null;
$query .= ( isset( $filter_data['first_name'] ) ) ? $this->getWhereClauseSQL( 'b.first_name', $filter_data['first_name'], 'text_metaphone', $ph ) : null;
$query .= ( isset( $filter_data['last_name'] ) ) ? $this->getWhereClauseSQL( 'b.last_name', $filter_data['last_name'], 'text_metaphone', $ph ) : null;
$query .= ( isset( $filter_data['country'] ) ) ? $this->getWhereClauseSQL( 'b.country', $filter_data['country'], 'upper_text_list', $ph ) : null;
$query .= ( isset( $filter_data['province'] ) ) ? $this->getWhereClauseSQL( 'b.province', $filter_data['province'], 'upper_text_list', $ph ) : null;
$query .= '
AND ( a.deleted = 0 AND ab.deleted = 0 )
';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order, $strict, $additional_order_fields );
$this->rs = $this->ExecuteSQL( $query, $ph, $limit, $page );
return $this;
}
}
?>

View File

@ -0,0 +1,744 @@
<?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\Accrual
*/
class AccrualFactory extends Factory {
protected $table = 'accrual';
protected $pk_sequence_name = 'accrual_id_seq'; //PK Sequence name
var $user_obj = null;
protected $system_type_ids = [ 10, 20, 75, 76 ]; //These all special types reserved for system use only.
private $calc_balance;
/**
* @param $name
* @param null $parent
* @return array|bool|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'type':
$retval = [
10 => TTi18n::gettext( 'Banked' ), //System: Can never be deleted/edited/added
20 => TTi18n::gettext( 'Used' ), //System: Can never be deleted/edited/added
30 => TTi18n::gettext( 'Awarded' ),
40 => TTi18n::gettext( 'Un-Awarded' ),
50 => TTi18n::gettext( 'Gift' ),
55 => TTi18n::gettext( 'Paid Out' ),
60 => TTi18n::gettext( 'Rollover Adjustment' ),
65 => TTi18n::gettext( 'Excess Rollover Adjustment' ),
70 => TTi18n::gettext( 'Initial Balance' ),
75 => TTi18n::gettext( 'Calendar-Based Accrual Policy' ), //System: Can never be added or edited.
76 => TTi18n::gettext( 'Hour-Based Accrual Policy' ), //System: Can never be added or edited.
80 => TTi18n::gettext( 'Other' ),
];
break;
case 'system_type':
$retval = array_intersect_key( $this->getOptions( 'type' ), array_flip( $this->system_type_ids ) );
break;
case 'add_type':
case 'edit_type':
case 'user_type':
$retval = array_diff_key( $this->getOptions( 'type' ), array_flip( $this->system_type_ids ) );
break;
case 'delete_type': //Types that can be deleted
$retval = $this->getOptions( 'type' );
unset( $retval[10], $retval[20] ); //Remove just Banked/Used as those can't be deleted.
break;
case 'accrual_policy_type':
$apf = TTNew( 'AccrualPolicyFactory' ); /** @var AccrualPolicyFactory $apf */
$retval = $apf->getOptions( 'type' );
break;
case 'columns':
$retval = [
'-1010-first_name' => TTi18n::gettext( 'First Name' ),
'-1020-last_name' => TTi18n::gettext( 'Last Name' ),
'-1030-accrual_policy_account' => TTi18n::gettext( 'Accrual Account' ),
'-1040-type' => TTi18n::gettext( 'Type' ),
//'-1050-time_stamp' => TTi18n::gettext('Date'),
'-1050-date_stamp' => TTi18n::gettext( 'Date' ), //Date stamp is combination of time_stamp and user_date.date_stamp columns.
'-1060-amount' => TTi18n::gettext( 'Amount' ),
'-1070-note' => TTi18n::gettext( 'Note' ),
'-1090-title' => TTi18n::gettext( 'Title' ),
'-1099-user_group' => TTi18n::gettext( 'Group' ),
'-1100-default_branch' => TTi18n::gettext( 'Branch' ),
'-1110-default_department' => TTi18n::gettext( 'Department' ),
'-2000-created_by' => TTi18n::gettext( 'Created By' ),
'-2010-created_date' => TTi18n::gettext( 'Created Date' ),
'-2020-updated_by' => TTi18n::gettext( 'Updated By' ),
'-2030-updated_date' => TTi18n::gettext( 'Updated Date' ),
];
break;
case 'list_columns':
$retval = Misc::arrayIntersectByKey( [ 'accrual_policy_account', 'type', 'date_stamp', 'amount' ], Misc::trimSortPrefix( $this->getOptions( 'columns' ) ) );
break;
case 'default_display_columns': //Columns that are displayed by default.
$retval = [
'first_name',
'last_name',
'accrual_policy_account',
'type',
'amount',
'date_stamp',
];
break;
}
return $retval;
}
/**
* @param $data
* @return array
*/
function _getVariableToFunctionMap( $data ) {
$variable_function_map = [
'id' => 'ID',
'user_id' => 'User',
'first_name' => false,
'last_name' => false,
'default_branch' => false,
'default_department' => false,
'user_group' => false,
'title' => false,
'accrual_policy_account_id' => 'AccrualPolicyAccount',
'accrual_policy_account' => false,
'accrual_policy_id' => 'AccrualPolicy',
'accrual_policy' => false,
'accrual_policy_type' => false,
'type_id' => 'Type',
'type' => false,
'user_date_total_id' => 'UserDateTotalID',
'date_stamp' => false,
'time_stamp' => 'TimeStamp',
'amount' => 'Amount',
'note' => 'Note',
'deleted' => 'Deleted',
];
return $variable_function_map;
}
/**
* @return bool
*/
function getUserObject() {
return $this->getGenericObject( 'UserListFactory', $this->getUser(), 'user_obj' );
}
/**
* @return bool|mixed
*/
function getUser() {
return $this->getGenericDataValue( 'user_id' );
}
/**
* @param $value
* @return bool
*/
function setUser( $value ) {
$value = TTUUID::castUUID( $value );
return $this->setGenericDataValue( 'user_id', $value );
}
/**
* @return bool|mixed
*/
function getAccrualPolicyAccount() {
return $this->getGenericDataValue( 'accrual_policy_account_id' );
}
/**
* @param $value
* @return bool
*/
function setAccrualPolicyAccount( $value ) {
$value = TTUUID::castUUID( $value );
return $this->setGenericDataValue( 'accrual_policy_account_id', $value );
}
/**
* @return bool|mixed
*/
function getAccrualPolicy() {
return $this->getGenericDataValue( 'accrual_policy_id' );
}
/**
* @param $value
* @return bool
*/
function setAccrualPolicy( $value ) {
$value = TTUUID::castUUID( $value );
return $this->setGenericDataValue( 'accrual_policy_id', $value );
}
/**
* @return int
*/
function getType() {
return (int)$this->getGenericDataValue( 'type_id' );
}
/**
* @param $value
* @return bool
*/
function setType( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'type_id', $value );
}
/**
* @return bool
*/
function isSystemType() {
if ( in_array( $this->getType(), $this->system_type_ids ) ) {
return true;
}
return false;
}
/**
* @return bool|mixed
*/
function getUserDateTotalID() {
return $this->getGenericDataValue( 'user_date_total_id' );
}
/**
* @param $value
* @return bool
*/
function setUserDateTotalID( $value ) {
$value = TTUUID::castUUID( $value );
return $this->setGenericDataValue( 'user_date_total_id', $value );
}
/**
* @param bool $raw
* @return bool|int|mixed
*/
function getTimeStamp( $raw = false ) {
$value = $this->getGenericDataValue( 'time_stamp' );
if ( $value !== false ) {
if ( $raw === true ) {
return $value;
} else {
return TTDate::strtotime( $value );
}
}
return false;
}
/**
* @param $value
* @return bool
*/
function setTimeStamp( $value ) {
$value = ( !is_int( $value ) && $value !== null ) ? trim( $value ) : $value;//Dont trim integer values, as it changes them to strings.
return $this->setGenericDataValue( 'time_stamp', $value );
}
/**
* @param $amount
* @return bool
*/
function isValidAmount( $amount ) {
Debug::text( 'Type: ' . $this->getType() . ' Amount: ' . $amount, __FILE__, __LINE__, __METHOD__, 10 );
//Based on type, set Amount() pos/neg
switch ( $this->getType() ) {
case 10: // Banked
case 30: // Awarded
case 50: // Gifted
if ( $amount >= 0 ) {
return true;
}
break;
case 20: // Used
case 55: // Paid Out
case 40: // Un Awarded
if ( $amount <= 0 ) {
return true;
}
break;
default:
return true;
break;
}
return false;
}
/**
* @return bool|mixed
*/
function getAmount() {
return $this->getGenericDataValue( 'amount' );
}
/**
* @param $value
* @return bool
*/
function setAmount( $value ) {
$value = trim( $value );
if ( empty( $value ) ) {
$value = 0;
}
return $this->setGenericDataValue( 'amount', $value );
}
/**
* @return bool|mixed
*/
function getNote() {
return $this->getGenericDataValue( 'note' );
}
/**
* @param $value
* @return bool
*/
function setNote( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'note', $value );
}
/**
* @return bool
*/
function getEnableCalcBalance() {
if ( isset( $this->calc_balance ) ) {
return $this->calc_balance;
}
return false;
}
/**
* @param $bool
* @return bool
*/
function setEnableCalcBalance( $bool ) {
$this->calc_balance = $bool;
return true;
}
/**
* @param bool $ignore_warning
* @return bool
*/
function Validate( $ignore_warning = true ) {
//
// BELOW: Validation code moved from set*() functions.
//
//User
if ( $this->Validator->getValidateOnly() == false ) {
if ( $this->getUser() == false || $this->getUser() == TTUUID::getZeroID() ) {
$this->Validator->isTrue( 'user_id',
false,
TTi18n::gettext( 'Please specify an employee' ) );
}
}
if ( $this->getUser() != '' && $this->Validator->isError( 'user_id' ) == false ) {
$ulf = TTnew( 'UserListFactory' ); /** @var UserListFactory $ulf */
$this->Validator->isResultSetWithRows( 'user_id',
$ulf->getByID( $this->getUser() ),
TTi18n::gettext( 'Invalid Employee' )
);
}
// Accrual Policy
if ( $this->getAccrualPolicy() != '' && $this->getAccrualPolicy() != TTUUID::getZeroID() ) {
$aplf = TTnew( 'AccrualPolicyListFactory' ); /** @var AccrualPolicyListFactory $aplf */
$this->Validator->isResultSetWithRows( 'accrual_policy_id',
$aplf->getByID( $this->getAccrualPolicy() ),
TTi18n::gettext( 'Accrual Policy is invalid' )
);
}
// Accrual Policy Account
if ( $this->Validator->getValidateOnly() == false ) {
if ( $this->getAccrualPolicyAccount() == false || $this->getAccrualPolicyAccount() == TTUUID::getZeroID() ) {
$this->Validator->isTrue( 'accrual_policy_account_id',
false,
TTi18n::gettext( 'Please select an accrual account' ) );
}
}
if ( $this->getAccrualPolicyAccount() != '' && $this->Validator->isError( 'accrual_policy_account_id' ) == false ) {
$apalf = TTnew( 'AccrualPolicyAccountListFactory' ); /** @var AccrualPolicyAccountListFactory $apalf */
$this->Validator->isResultSetWithRows( 'accrual_policy_account_id',
$apalf->getByID( $this->getAccrualPolicyAccount() ),
TTi18n::gettext( 'Accrual Account is invalid' )
);
}
// Type
if ( $this->Validator->getValidateOnly() == false ) { //Don't do the follow validation checks during Mass Edit.
if ( $this->getType() == false || $this->getType() == 0 ) {
$this->Validator->isTrue( 'type_id',
false,
TTi18n::gettext( 'Please specify accrual type' ) );
}
}
if ( $this->getType() != '' && $this->Validator->isError( 'type_id' ) == false ) {
$this->Validator->inArrayKey( 'type_id',
$this->getType(),
TTi18n::gettext( 'Incorrect Type' ),
$this->getOptions( 'type' )
);
}
// UserDateTotal
if ( $this->getUserDateTotalID() != '' && $this->getUserDateTotalID() != TTUUID::getZeroID() ) {
$udtlf = TTnew( 'UserDateTotalListFactory' ); /** @var UserDateTotalListFactory $udtlf */
$this->Validator->isResultSetWithRows( 'user_date_total',
$udtlf->getByID( $this->getUserDateTotalID() ),
TTi18n::gettext( 'User Date Total ID is invalid' )
);
}
// Time stamp
if ( $this->getTimeStamp() != '' ) {
$this->Validator->isDate( 'times_tamp',
$this->getTimeStamp(),
TTi18n::gettext( 'Incorrect time stamp' )
);
}
// Amount
if ( $this->getAmount() !== false ) {
$this->Validator->isNumeric( 'amount',
$this->getAmount(),
TTi18n::gettext( 'Incorrect Amount' )
);
if ( $this->Validator->isError( 'amount' ) == false ) {
$this->Validator->isTrue( 'amount',
$this->isValidAmount( $this->getAmount() ),
TTi18n::gettext( 'Amounts of type "%1" must be a %2 value instead', [ Option::getByKey( $this->getType(), $this->getOptions( 'type' ) ), ( ( $this->getAmount() < 0 && $this->isValidAmount( $this->getAmount() ) == false ) ? TTi18n::getText( 'positive' ) : TTi18n::getText( 'negative' ) ) ] )
);
}
if ( $this->Validator->isError( 'amount' ) == false ) {
$this->Validator->isGreaterThan( 'amount',
$this->getAmount(),
TTi18n::gettext( 'Amount is too low' ),
-35996400 //9999 hrs
);
$this->Validator->isLessThan( 'amount',
$this->getAmount(),
TTi18n::gettext( 'Amount is too high' ),
35996400 //9999 hrs
);
}
}
// Note
if ( $this->getNote() != '' ) {
$this->Validator->isLength( 'note',
$this->getNote(),
TTi18n::gettext( 'Note is too long' ),
0,
1024
);
}
//
// ABOVE: Validation code moved from set*() functions.
//
if ( $this->getDeleted() == true ) {
$this->Validator->inArrayKey( 'type_id',
$this->getType(),
TTi18n::gettext( 'Unable to delete system accrual records, modify the employees schedule/timesheet instead' ),
$this->getOptions( 'delete_type' )
);
} else if ( $this->isNew( true ) == false ) {
$this->Validator->inArrayKey( 'type_id',
$this->getType(),
TTi18n::gettext( 'Unable to modify system accrual records' ),
$this->getOptions( 'user_type' )
);
}
return true;
}
/**
* @return bool
*/
function preSave() {
if ( $this->getTimeStamp() == false ) {
$this->setTimeStamp( TTDate::getTime() );
}
//Delete duplicates before saving.
//Or orphaned entries on Sum'ing?
//Would have to do it on view as well though.
if ( TTUUID::isUUID( $this->getUserDateTotalID() ) && $this->getUserDateTotalID() != TTUUID::getZeroID() && $this->getUserDateTotalID() != TTUUID::getNotExistID() ) {
$alf = TTnew( 'AccrualListFactory' ); /** @var AccrualListFactory $alf */
$alf->getByUserIdAndAccrualPolicyAccountAndAccrualPolicyAndUserDateTotalID( $this->getUser(), $this->getAccrualPolicyAccount(), $this->getAccrualPolicy(), $this->getUserDateTotalID() );
Debug::text( 'Found Duplicate Records: ' . (int)$alf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10 );
if ( $alf->getRecordCount() > 0 ) {
foreach ( $alf as $a_obj ) {
if ( $a_obj->getId() != $this->getId() ) { //Make sure we don't delete the record we are currently editing.
$a_obj->Delete( true );
}
}
}
}
return true;
}
/**
* @return bool
*/
function postSave() {
//Calculate balance
if ( $this->getEnableCalcBalance() == true ) {
Debug::text( 'Calculating Balance is enabled! ', __FILE__, __LINE__, __METHOD__, 10 );
//If the user and/or the accrual policy account was changed, recalculate the old and new values.
$data_diff = $this->getDataDifferences();
if ( isset( $data_diff['user_id'] ) || isset( $data_diff['accrual_policy_account_id'] ) ) {
AccrualBalanceFactory::calcBalance( ( ( isset( $data_diff['user_id'] ) ) ? $data_diff['user_id'] : $this->getUser() ), ( ( isset( $data_diff['accrual_policy_account_id'] ) ) ? $data_diff['accrual_policy_account_id'] : $this->getAccrualPolicyAccount() ) );
}
AccrualBalanceFactory::calcBalance( $this->getUser(), $this->getAccrualPolicyAccount() );
}
return true;
}
/**
* @param string $user_id UUID
* @param int $date_stamp EPOCH
* @return bool
*/
static function deleteOrphans( $user_id, $date_stamp ) {
Debug::text( 'Attempting to delete Orphaned Records for User ID: ' . $user_id . ' Date: ' . TTDate::getDate( 'DATE', $date_stamp ), __FILE__, __LINE__, __METHOD__, 10 );
//Remove orphaned entries
$alf = TTnew( 'AccrualListFactory' ); /** @var AccrualListFactory $alf */
$alf->getOrphansByUserIdAndDate( $user_id, $date_stamp );
Debug::text( 'Found Orphaned Records: ' . $alf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10 );
if ( $alf->getRecordCount() > 0 ) {
$accrual_policy_ids = [];
foreach ( $alf as $a_obj ) {
Debug::text( 'Orphan Record ID: ' . $a_obj->getID(), __FILE__, __LINE__, __METHOD__, 10 );
$accrual_policy_ids[] = $a_obj->getAccrualPolicyAccount();
$a_obj->Delete( true );
}
//ReCalc balances
if ( empty( $accrual_policy_ids ) === false ) {
foreach ( $accrual_policy_ids as $accrual_policy_id ) {
AccrualBalanceFactory::calcBalance( $user_id, $accrual_policy_id );
}
}
}
return true;
}
/**
* @param string $user_id UUID
* @param string $accrual_policy_account_id UUID
* @return bool|int
*/
function getCurrentAccrualBalance( $user_id = null, $accrual_policy_account_id = null ) {
if ( $user_id == '' ) {
$user_id = $this->getUser();
}
if ( $accrual_policy_account_id == '' ) {
$accrual_policy_account_id = $this->getAccrualPolicyAccount();
}
//Check min/max times of accrual policy.
$ablf = TTnew( 'AccrualBalanceListFactory' ); /** @var AccrualBalanceListFactory $ablf */
$ablf->getByUserIdAndAccrualPolicyAccount( $user_id, $accrual_policy_account_id );
if ( $ablf->getRecordCount() > 0 ) {
$accrual_balance = $ablf->getCurrent()->getBalance();
} else {
$accrual_balance = 0;
}
Debug::Text( ' Current Accrual Balance: ' . $accrual_balance, __FILE__, __LINE__, __METHOD__, 10 );
return $accrual_balance;
}
/**
* @param $data
* @return bool
*/
function setObjectFromArray( $data ) {
if ( is_array( $data ) ) {
$variable_function_map = $this->getVariableToFunctionMap();
foreach ( $variable_function_map as $key => $function ) {
if ( isset( $data[$key] ) ) {
$function = 'set' . $function;
switch ( $key ) {
case 'user_date_total_id': //Skip this, as it should never be set from the API.
break;
case 'time_stamp':
if ( method_exists( $this, $function ) ) {
$this->$function( TTDate::parseDateTime( $data[$key] ) );
}
break;
default:
if ( method_exists( $this, $function ) ) {
$this->$function( $data[$key] );
}
break;
}
}
}
$this->setCreatedAndUpdatedColumns( $data );
return true;
}
return false;
}
/**
* @param null $include_columns
* @param bool $permission_children_ids
* @return array
*/
function getObjectAsArray( $include_columns = null, $permission_children_ids = false ) {
$data = [];
$variable_function_map = $this->getVariableToFunctionMap();
if ( is_array( $variable_function_map ) ) {
foreach ( $variable_function_map as $variable => $function_stub ) {
if ( $include_columns == null || ( isset( $include_columns[$variable] ) && $include_columns[$variable] == true ) ) {
$function = 'get' . $function_stub;
switch ( $variable ) {
case 'accrual_policy_account':
case 'accrual_policy':
case 'first_name':
case 'last_name':
case 'title':
case 'user_group':
case 'default_branch':
case 'default_department':
$data[$variable] = $this->getColumn( $variable );
break;
case 'accrual_policy_type':
$data[$variable] = Option::getByKey( $this->getColumn( 'accrual_policy_type_id' ), $this->getOptions( $variable ) );
break;
case 'type':
$function = 'get' . $variable;
if ( method_exists( $this, $function ) ) {
$data[$variable] = Option::getByKey( $this->$function(), $this->getOptions( $variable ) );
}
break;
case 'time_stamp':
if ( method_exists( $this, $function ) ) {
$data[$variable] = TTDate::getAPIDate( 'DATE', $this->$function() );
}
break;
case 'date_stamp': //This is a combination of the time_stamp and user_date.date_stamp columns.
$data[$variable] = TTDate::getAPIDate( 'DATE', strtotime( $this->getColumn( $variable ) ) );
break;
default:
if ( method_exists( $this, $function ) ) {
$data[$variable] = $this->$function();
}
break;
}
}
}
$this->getPermissionColumns( $data, $this->getUser(), $this->getCreatedBy(), $permission_children_ids, $include_columns );
$this->getCreatedAndUpdatedColumns( $data, $include_columns );
}
//Debug::Arr($data, 'Data Object: ', __FILE__, __LINE__, __METHOD__, 10);
return $data;
}
/**
* @param $log_action
* @return bool
*/
function addLog( $log_action ) {
$u_obj = $this->getUserObject();
if ( is_object( $u_obj ) ) {
return TTLog::addEntry( $this->getId(), $log_action, TTi18n::getText( 'Accrual' ) . ' - ' . TTi18n::getText( 'Employee' ) . ': ' . $u_obj->getFullName( false, true ) . ' ' . TTi18n::getText( 'Type' ) . ': ' . Option::getByKey( $this->getType(), $this->getOptions( 'type' ) ) . ' ' . TTi18n::getText( 'Date' ) . ': ' . TTDate::getDate( 'DATE', $this->getTimeStamp() ) . ' ' . TTi18n::getText( 'Total Time' ) . ': ' . TTDate::getTimeUnit( $this->getAmount() ), null, $this->getTable(), $this );
}
return false;
}
}
?>

File diff suppressed because it is too large Load Diff