* */ class ems_account_account extends ems_framework_datamodelbase implements ems_account_interface_account { /** * The ID of the account. * * @var integer * @access protected */ protected $id; /** * The ID of the account's parent. * * @var integer * @access protected */ protected $parentID; /** * The parent person of the account. * * @var ems_person_base * @access protected */ protected $parent; /** * The account number. * * @var string * @access protected */ protected $number; /** * The name of the account. * * @var string * @access protected */ protected $name; /** * The description of the account. * * @var mixed * @access protected */ protected $description; /** * The Warning status threshold. * * @var integer * @access protected */ protected $warningThreshold; /** * The Critical status threshold. * * @var mixed * @access protected */ protected $criticalThreshold; /** * The starting date for the account. * * @var ems_util_datetime * @access protected */ protected $startDate; /** * The ending date for the account. * * @var ems_util_datetime * @access protected */ protected $endDate; /** * The hideDisplay property. TODO: Find out what this does. * * @var boolean * @access protected */ protected $hideDisplay; /** * The possible values for a status. * * @var array * @access protected */ protected $statusValues; /** * The project manager for the account. * * @var ems_person_base * @access protected */ protected $projectManager; /** * The ID of the project manager for the account. * * @var integer * @access protected */ protected $projectManagerID; /** * The identifier Quickbooks uses to identify this account * * @var integer * @access protected */ protected $qbIdentifier; /** * A boolean to determine if the qb identifier is the full name or account number * * @var integer * @access protected */ protected $qbIdentifierIsName; /** * The identifier Quickbooks uses to charge this account's time as * * @var integer * @access protected */ protected $qbServiceItem; /** * A boolean to determine if the qb service item is the full name or account number * * @var integer * @access protected */ protected $qbServiceItemIsName; /** * The identifier Quickbooks uses to associate a time entry in this account with the pay roll account * * @var integer * @access protected */ protected $qbPayrollItem; /** * A boolean to determine if the qb payroll item is the full name or account number * * @var integer * @access protected */ protected $qbPayrollItemIsName; /** * A decimal that defines what the default billing rate should be for an account * * @var decimal * @access protected */ protected $defaultRate; /** * An integer that represents the ID of the primary manager. * * @var decimal * @access protected */ protected $primaryManagerID; /** * An integer that represents the ID of the secondar manager. * * @var decimal * @access protected */ protected $secondaryManagerID; /** * An object that represents the primary manager person object. * * @var decimal * @access protected */ protected $primaryManager; /** * An object that represents the secondary manager person object. * * @var decimal * @access protected */ protected $secondaryManager; /** * The costs associated with this account. * * @var mixed * @access protected */ protected $costs; /** * The expenses associated with this account. * * @var mixed * @access protected */ protected $expenses; /** * The time charges associated with this account. * * @var libraries_collection * @access protected */ protected $timeCharges; /** * People associated with this account. * * @var libraries_objectlist * @access public */ public $people; /** * The billing rates associated with this account. * * @var mixed * @access protected */ protected $rates; /** * The time entries associated with this account filtered by a date range * * @var mixed * @access protected */ protected $entries; /** * if thes value true then account is marked as billable * * @var boolen * @access protected */ protected $isBillable; /** * The billing information for account * * @var text * @access protected */ protected $billingInformation; /** * The minimum number of hours per week that should be billed to this account * * @var int * @access protected */ protected $minimumMinutesPerWeek; /** * The maximum number of hours per week that should be billed to this account * * @var int * @access protected */ protected $maximumMinutesPerWeek; /** * Constructor object for the ems_account_account class * * @param ems_framework_registry $param * @access public * @return void */ public function __construct(ems_framework_registry $param) { parent::__construct($param); $this->setDefaultValues(); } /** * Initializes the properties of the class to their defaults. * * @access private * @return void */ private function setDefaultValues() { $this->id = null; $this->number = null; $this->name = null; $this->description = null; $this->parent = null; $this->parentID = null; $this->warningThreshold = 0; $this->criticalThreshold = 0; $this->startDate = $this->param->factory->system->createEmptyDateTime(); $this->endDate = $this->param->factory->system->createEmptyDateTime(); $this->hideDisplay = false; $this->statusValues = array(); $this->projectManagerID = null; $this->projectManager = null; $this->primaryManagerID = null; $this->primaryManager = null; $this->secondaryManagerID = null; $this->secondaryManager = null; $this->qbIdentifier = null; $this->qbIdentifierIsName = true; $this->qbServiceItem = null; $this->qbServiceItemIsName = true; $this->qbPayrollItem = null; $this->qbPayrollItemIsName = true; $this->defaultRate = null; $this->people = $this->param->factory->account->createAssignedPeople(); $this->people->setParent($this); $this->ds = $this->param->factory->ds->createAccount(); $this->costs = null; $this->expenses = null; $this->timeCharges = null; $this->rates = null; $this->entries = null; $this->tableDef = 9; $this->enableGrouperCategory(); $this->isBillable = false; $this->billingInformation = null; $this->minimumMinutesPerWeek = null; $this->maximumMinutesPerWeek = null; } /** * Sets the datasource for the ems_account_account object. * * @param ems_datasource_interface_account $ds * @access public * @return void */ public function setDataSource(ems_datasource_interface_account $ds) { $this->ds = $ds; } /** * Loads the data for the specified account ID into an ems_account_account object. * * @param integer $id * @access public * @return boolean Whether or not the data loading was successful. */ public function getData($id) { $this->checkDS("getData"); $data = $this->ds->getAccount($id); if (is_array($data)) { $this->setID($data['account_id']); $this->setNumber($data['account_number']); $this->setName($data['account_name']); $this->setDescription($data['account_description']); $this->setWarningThreshold($data['account_warning_threshold']); $this->setCriticalThreshold($data['account_critical_threshold']); $this->setStartDate($data['account_start_date']); $this->setEndDate($data['account_end_date']); $this->setHideDisplay($data['account_hide_display']); $this->setProjectManagerID($data['account_project_manager_id']); $this->setPrimaryManagerID($data['account_primary_manager_id']); $this->setSecondaryManagerID($data['account_secondary_manager_id']); $this->setQBIdentifier($data['account_qb_identifier']); $this->setQBIdentifierIsName($data['account_qb_identifier_is_name']); $this->setQBServiceItem($data['account_qb_service_item']); $this->setQBServiceItemIsName($data['account_qb_service_item_is_name']); $this->setQBPayrollItem($data['account_qb_payroll_item']); $this->setQBPayrollItemIsName($data['account_qb_payroll_item_is_name']); $this->setDefaultRate($data['account_default_rate']); $this->setIsBillable($data['account_is_billable']); $this->setBillingInformation($data['account_billing_information']); $this->setMinimumMinutesPerWeek($data['account_minimum_minutes_per_week']); $this->setMaximumMinutesPerWeek($data['account_maximum_minutes_per_week']); $this->getDataRun = true; } return $this->getDataRun; } /** * Gets the time charges for the object, or for a list of people * * @param library_objectlist $personList * @access public * @return libraries_collection A collection of time charges. */ public function getTimeCharges($personList = null) { if (!$this->timeCharges) { $this->timeCharges = $this->param->factory->system->createCollection(); $results = $this->param->factory->ds->createTime()->getPersonTimeTotalsByAccount($this->getID()); if (is_array($results)) { foreach ($results as $row=>$data) { $timeCharge = $this->param->factory->account->createTimeCharge(); if ($personList !== null) { if ($personList->keyExists($data['person_id'])) { $person = $personList->get($data['person_id']); } else { $person = $this->param->factory->person->createPerson(); $person->getData($data['person_id']); } } else { $person = $this->param->factory->person->createPerson(); $person->getData($data['person_id']); } $timeCharge->setPerson($person); $timeCharge->setTime($data['total']); $this->timeCharges->addItem($timeCharge); } } } return $this->timeCharges; } /** * Gets the costs for the account. * * @access public * @return libraries_collection A collection of costs for the account. */ public function getCosts() { if (!$this->costs) { $this->costs = $this->param->factory->system->createCollection(); $results = $this->ds->getAccountCostsByAccount($this->getID()); if (is_array($results)) { foreach ($results as $row=>$data) { $ac = $this->param->factory->account->createAccountCost(); if ($ac->getData($data['account_cost_id'])) { $ac->setAccount($this); $this->costs->addKey($ac->getID(),$ac); } } } if ($this->costs->count() > 0) $this->costs->sort("getOrder"); } return $this->costs; } /** * Returns a collection of expense objects for the parent account * * @access public * @return libraries_collection A collection of expenses for the account. */ public function getExpenses() { if ($this->expenses === null) { $this->expenses = $this->param->factory->system->createCollection(); if ($this->getID()) { $results = $this->ds->getAccountExpensesByAccount($this->getID()); if (is_array($results)) { foreach ($results as $row=>$data) { $ae = $this->param->factory->account->createAccountExpense(); if ($ae->getData($data['account_expense_id'])) { $ae->setAccount($this); $this->expenses->addKey($ae->getID(),$ae); } } } } } return $this->expenses; } /** * Gets the rates for the account. * * @access public * @return libraries_collection A collection of costs for the account. */ public function getRates() { if (!$this->rates) { $this->rates = $this->param->factory->system->createCollection(); $results = $this->ds->getAccountBillingRatesByAccount($this->getID()); if (is_array($results)) { foreach ($results as $row=>$data) { $abr = $this->param->factory->account->createAccountBillingRate(); if ($abr->getData($data['abr_id'])) { $abr->setAccount($this); $this->rates->addKey($abr->getID(),$abr); } } } } return $this->rates; } /** * Returns an accountentries object * * @access public * @return ems_account_accountentires */ public function getAccountEntries() { $ae = $this->param->factory->account->createAccountEntries($this); return $ae; } /** * Gets the time entries for an account, based on a time range * * @access public * @return libraries_collection A collection of entries for the account. */ public function getTimeEntries($startDate,$endDate,$processPeople = true) { if ($this->entries === null) { $this->entries = $this->param->factory->system->createCollection(); if ($processPeople) $people = $this->param->factory->person->createPersonList(); $tcResults = $this->param->factory->ds->createTime()->getTimeCardsByAccount($this->getID(),$startDate,$endDate); $teResults = $this->param->factory->ds->createTime()->getTimeEntriesByAccount($this->getID(),$startDate,$endDate); if (is_array($teResults)) { foreach ($teResults as $index=>$data) { $te = $this->param->factory->time->createEntry(); if ($te->getData($data['te_id'])) { $this->entries->addKey($te->getID(),$te); } } } } return $this->entries; } /** * Gets the ID for the account. * * @access public * @return integer The ID for the account. */ public function getID() { return $this->id; } /** * Gets the account number. This is a number assigned externally, e.g., in Quickbooks. * * @access public * @return string The account number. */ public function getNumber() { return $this->number; } /** * Gets the name that's assigned to the account. * * @access public * @return string The name of the account. */ public function getName() { return $this->name; } /** * Gets the title of the account - composed of the account number, a separator, and the account name. * * @param string $sep The string to separate the account number and the account name. Defaults to "-". * @access public * @return string The title of the account. */ public function getTitle($sep = " - ") { return "{$this->getNumber()}{$sep}{$this->getName()}"; } /** * Gets a description of the account. * * @access public * @return string The description of the account. */ public function getDescription() { return $this->description; } /** * Gets the ID of the parent object. * * @access public * @return integer */ public function getParentID() { return $this->parentID; } /** * Gets the parent of the time charge account. * * @access public * @return ems_person_base The parent person of the time charge account. */ public function getParent() { return $this->parent; } /** * Gets the Warning threshold for the time charge account. * * @access public * @return integer The warning threshold for the account. */ public function getWarningThreshold() { return $this->warningThreshold; } /** * Gets the Critical threshold for the time charge account. * * @access public * @return integer The critical threshold for the account. */ public function getCriticalThreshold() { return $this->criticalThreshold; } /** * Gets the start date for the account. * * @access public * @return ems_util_datetime The start date for the time charge account. */ public function getStartDate() { return $this->startDate; } /** * Gets the end date for the account. * * @access public * @return ems_util_datetime The end date for the account. */ public function getEndDate() { return $this->endDate; } /** * Gets the value of the hideDisplay property. TODO: Find out what this does, change it. * * @access public * @return boolean The value of the hideDisplay property. */ public function getHideDisplay() { return $this->hideDisplay; } /** * Gets the QB account identifier * * @access public * @return string The value of the qbIdentifier property. */ public function getQBIdentifier() { return $this->qbIdentifier; } /** * Gets the QB account identifier id type toggle. * * @access public * @return boolean The value of the qbIdentifierIsName property. */ public function getQBIdentifierIsName() { return $this->qbIdentifierIsName; } /** * Gets the QB account identifier for the service item related this account. * * @access public * @return string The value of the qbServiceItem property. */ public function getQBServiceItem() { return $this->qbServiceItem; } /** * Gets the QB service item id type toggle. * * @access public * @return boolean The value of the qbServiceItemIsName property. */ public function getQBServiceItemIsName() { return $this->qbServiceItemIsName; } /** * Gets the QB account identifier for the payroll item related this account. * * @access public * @return string The value of the qbPayrollItem property. */ public function getQBPayrollItem() { return $this->qbPayrollItem; } /** * Gets the QB payroll item id type toggle. * * @access public * @return boolean The value of the qbPayrollItemIsName property. */ public function getQBPayrollItemIsName() { return $this->qbPayrollItemIsName; } /** * Gets the default rate for the account * * @access public * @return decimal */ public function getDefaultRate() { return $this->defaultRate; } /** * Gets the project manager's ID. * * @access public * @return integer The project manager's ID. */ public function getProjectManagerID() { if (!$this->projectManagerID && $this->projectManager) { $this->setProjectManagerID($this->projectManager->getID()); } return $this->projectManagerID; } /** * Gets the project manager for the account. * * @access public * @return ems_person_base The project manager for the account. */ public function getProjectManager() { if (!$this->projectManager) { $this->projectManager = $this->param->factory->person->createPerson(); if ($this->projectManagerID) $this->projectManager->getData($this->projectManagerID); } return $this->projectManager; } /** * Gets the primary manager's ID. * * @access public * @return integer The project manager's ID. */ public function getPrimaryManagerID() { if (!$this->primaryManagerID && $this->primaryManager) { $this->setPrimaryManagerID($this->primaryManager->getID()); } return $this->primaryManagerID; } /** * Gets the primary manager for the account. * * @access public * @return ems_person_base The primary manager for the account. */ public function getPrimaryManager() { if (!$this->primaryManager) { $this->primaryManager = $this->param->factory->person->createPerson(); if ($this->primaryManagerID) $this->primaryManager->getData($this->primaryManagerID); } return $this->primaryManager; } /** * Gets the secondary manager's ID. * * @access public * @return integer The project manager's ID. */ public function getSecondaryManagerID() { if (!$this->secondaryManagerID && $this->secondaryManager) { $this->setSecondaryManagerID($this->secondaryManager->getID()); } return $this->secondaryManagerID; } /** * Gets the secondary manager for the account. * * @access public * @return ems_person_base The secondary manager for the account. */ public function getSecondaryManager() { if (!$this->secondaryManager) { $this->secondaryManager = $this->param->factory->person->createPerson(); if ($this->secondaryManagerID) $this->secondaryManager->getData($this->secondaryManagerID); } return $this->secondaryManager; } /** * Gets the account is billable or not. * * @access public * @return ems_person_base The is billable value for the account. */ public function getIsBillable() { return $this->isBillable; } /** * Gets the billing information for the account . * * @access public * @return ems_person_base The billing information for the account. */ public function getBillingInformation() { return $this->billingInformation; } public function getMinimumMinutesPerWeek() { return $this->minimumMinutesPerWeek; } public function getMaximumMinutesPerWeek() { return $this->maximumMinutesPerWeek; } /** * Sets the Project Manager for this account. * * @param ems_person_base $value The new person object to be used for the Project Manager. * @access public * @return void */ public function setProjectManager(ems_person_interface_person $value) { $this->projectManager = $value; } /** * Sets the Project Manager ID for the time charge account. * * @param mixed $value The new Project Manager ID. * @access public * @return void */ public function setProjectManagerID($value) { $this->projectManagerID = null; if (is_numeric($value)) $this->projectManagerID = $value; } /** * Sets the Primary Manager ID for the time charge account. * * @param mixed $value The new Primary Manager ID. * @access public * @return void */ public function setPrimaryManagerID($value) { $this->primaryManagerID = null; if (is_numeric($value)) $this->primaryManagerID = $value; } /** * Sets the Primary Manager person for the time charge account. * * @param mixed $value The new Primary Manager object. * @access public * @return void */ public function setPrimaryManager($value) { $this->primaryManager = null; if ($value) $this->primaryManager = $value; } /** * Sets the Secondary Manager ID for the time charge account. * * @param mixed $value The new Secondary Manager ID. * @access public * @return void */ public function setSecondaryManagerID($value) { $this->secondaryManagerID = null; if (is_numeric($value)) $this->secondaryManagerID = $value; } /** * Sets the Secondary Manager person for the time charge account. * * @param mixed $value The new Secondary Manager object. * @access public * @return void */ public function setSecondaryManager($value) { $this->secondaryManager = null; if ($value) $this->secondaryManager = $value; } /** * Sets the ID for the account. * * @param mixed $value The new ID for the account. * @access public * @return void */ public function setID($value) { $this->id = null; if (is_numeric($value)) $this->id = $value; } /** * Sets the account number for the account. * * @param mixed $value The new account number. * @access public * @return void */ public function setNumber($value) { $this->number = null; if ($value) $this->number = $value; } /** * Sets the name for the time charge account. * * @param mixed $value The new name for the account. * @access public * @return void */ public function setName($value) { $this->name = null; if ($value) $this->name = $value; } /** * Sets the parent ID for the time charge account. * * @param mixed $value The new parent ID for the account. * @access public * @return void */ public function setParentID($value) { $this->parentID = null; if (is_numeric($value)) $this->parentID = $value; } /** * Sets the parent object for the time charge account. * * @param ems_account_interface_account $value The parent object for the account. * @access public * @return void */ public function setParent(ems_account_interface_account $value) { $this->parent = $value; } /** * Sets the description for the time charge account. * * @param mixed $value The new description for the time charge account. * @access public * @return void */ public function setDescription($value) { $this->description = null; if ($value) $this->description = $value; } /** * Sets the threshold for determining if the account's status is at the Warning level. * * @param mixed $value The new Warning threshold. * @access public * @return void */ public function setWarningThreshold($value) { $this->warningThreshold = 0; if (is_numeric($value)) $this->warningThreshold = $value; } /** * Sets the threshold for determining if the account is Critical. * * @param mixed $value The new value for the critical threshold. * @access public * @return void */ public function setCriticalThreshold($value) { $this->criticalThreshold = 0; if (is_numeric($value)) $this->criticalThreshold = $value; } /** * Sets the start date for the time charge account. * * @param mixed $value The start date for the time charge account. Optional. * @access public * @return void */ public function setStartDate($value) { $this->startDate = $this->param->factory->system->createEmptyDateTime(); if ($value) $this->startDate = $this->param->factory->system->createDateTime($value); } /** * Sets the end date for the time charge account. * * @param mixed $value The end date for the time charge account. Optional. * @access public * @return void */ public function setEndDate($value) { $this->endDate = $this->param->factory->system->createEmptyDateTime(); if ($value) $this->endDate = $this->param->factory->system->createDateTime($value); } /** * Sets the hideDisplay property. Hide Display controls if the account should show up in the select account screen when customing a dashboard. * * @param boolean $value The boolean if it should be shown or not. * @access public * @return void */ public function setHideDisplay($value) { if ($value) { $this->hideDisplay = true; } else { $this->hideDisplay = false; } } /** * Sets the account identifier that QB uses. * * @param string $value A string that contains the identifier * @access public * @return void */ public function setQBIdentifier($value) { $this->qbIdentifier = null; if ($value) $this->qbIdentifier = $value; } /** * A toggle if the identifier is the Entity Id or Full Name * * @param boolean $value A boolean that toggles the identifier * @access public * @return void */ public function setQBIdentifierIsName($value) { if ($value) { $this->qbIdentifierIsName = true; } else { $this->qbIdentifierIsName = false; } } /** * Sets the identifier of the service item that is used in QB for this account. * * @param string $value A string that contains the identifier * @access public * @return void */ public function setQBServiceItem($value) { $this->qbServiceItem = null; if ($value) $this->qbServiceItem = $value; } /** * A toggle if the service item is the Entity Id or Full Name * * @param boolean $value A boolean that toggles the service item * @access public * @return void */ public function setQBServiceItemIsName($value) { if ($value) { $this->qbServiceItemIsName = true; } else { $this->qbServiceItemIsName = false; } } /** * Sets the identifier of the payroll item that is used in QB for this account. * * @param string $value A string that contains the identifier * @access public * @return void */ public function setQBPayrollItem($value) { $this->qbPayrollItem = null; if ($value) $this->qbPayrollItem = $value; } /** * A toggle if the payroll item is the Entity Id or Full Name * * @param boolean $value A boolean that toggles the payroll item * @access public * @return void */ public function setQBPayrollItemIsName($value) { if ($value) { $this->qbPayrollItemIsName = true; } else { $this->qbPayrollItemIsName = false; } } /** * Sets the default rate for the account. Requires a numeric value. * * @param decimal $value A decimal that defines the default rate. * @access public * @return void */ public function setDefaultRate($value) { $this->defaultRate = null; if (is_numeric($value)) $this->defaultRate = $value; } /** * Sets the account is billable or not. Requires a boolen value. * * @access public * @return void */ public function setIsBillable($value) { if ($value) { $this->isBillable = true; } else { $this->isBillable = false; } } /** * Sets the billing information for the account. * * @access public * @return void */ public function setBillingInformation($value) { $this->billingInformation = null; if ($value) $this->billingInformation = $value; } public function setMinimumMinutesPerWeek($value) { $this->minimumMinutesPerWeek = 0; if (is_numeric($value)) $this->minimumMinutesPerWeek = $value; } public function setMaximumMinutesPerWeek($value) { $this->maximumMinutesPerWeek = 0; if (is_numeric($value)) $this->maximumMinutesPerWeek = $value; } /** * Interval calculates the total number of seconds that have been charged to this account. It returns an interval object. * * @access public * @return ems_time_intervalvalue The interval for the account. */ public function interval() { $results = $this->param->factory->ds->createTime()->getTotalTimeByAccount($this->getID()); if (is_array($results)) { $total = $results['total']; $total = $total * 60; $interval = $this->param->factory->time->createIntervalValue($total); } else { $interval = $this->param->factory->time->createIntervalValue(0); } return $interval; } /** * Gets the amount of employees on the time charge. * * @access public * @return integer The number of employees on the account. */ public function getEmployeeCount() { $people = array(); $it = $this->people->createIterator(); while ($it->hasNext()) { $person = $it->next(); $people[] = $person; } return count(array_unique($people)); } /** * Gets the code for the status of the account. * * @access public * @return integer The code for the status of the account. -1, 0, 1 */ public function getStatusCode() { $statusCodes = array(); $it = $this->getCosts()->createIterator(); while ($it->hasNext()) { $cost = $it->next(); $cost->getMath()->setWarningThreshold($this->getWarningThreshold()); $cost->getMath()->setCriticalThreshold($this->getCriticalThreshold()); $status = $cost->getMath()->getStatus(); $statusCodes[] = $status; } if (in_array(-1,$statusCodes,true)) return -1; if (in_array(0,$statusCodes,true)) return 0; return 1; } /** * Gets the status of the account. * * @access public * @return string The status of the account. */ public function getStatusText() { $code = $this->getStatusCode(); if ($code > 0) { return "Ok"; } else if ($code < 0) { return "Critical"; } else { return "Warning"; } } /** * Saves the account to the database. If it doesn't exist, it creates a new record. If it exists, it updates the information. * * @access public * @return boolean The status of the save operation. */ public function save() { $this->checkDS("save"); $results = array(); $returnResult = false; if ($this->ds->saveAccount($this)) { $results[] = true; if ($this->costs) { $it = $this->costs->createIterator(); while ($it->hasNext()) { $cost = $it->next(); $results[] = $cost->save(); } } if (in_array(false,$results)) { $returnResult = false; } else { $returnResult = true; } } return $returnResult; } /** * Calls the datasource delete method, to set the is_active field to false in the database. * * @access public * @return boolean Whether or not the delete operation succeeded. */ public function delete() { $this->checkDS("delete"); $results = array(); $returnResult = false; if ($this->ds->deleteAccount($this)) { $results[] = true; if ($this->costs) { $it = $this->costs->createIterator(); while ($it->hasNext()) { $cost = $it->next(); $results[] = $cost->delete(); } } if (in_array(false,$results)) { $returnResult = false; } else { $returnResult = true; } } return $returnResult; } } ?>