forked from asgrim/ofxparser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extends base for investments transactions and entities
Tested in php7.4 with phpunit7.5 Supports adding a callback for custom DateTime library. Created helper utils for reused code segments.
- Loading branch information
1 parent
4ac9407
commit 05b8ba7
Showing
34 changed files
with
1,755 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace OfxParser\Entities; | ||
|
||
/** | ||
* Provides entity inspection for a variety of subclasses. | ||
*/ | ||
interface Inspectable | ||
{ | ||
/** | ||
* Get a list of properties defined for this entity. | ||
* @return array array('prop_name' => 'prop_name', ...) | ||
*/ | ||
public function getProperties(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace OfxParser\Entities; | ||
|
||
use SimpleXMLElement; | ||
|
||
abstract class Investment extends AbstractEntity implements Inspectable, OfxLoadable | ||
{ | ||
/** | ||
* Get a list of properties defined for this entity. | ||
* | ||
* Since Traits are being used for multiple inheritance, | ||
* it can be challenging to know which properties exist | ||
* in the entity. | ||
* | ||
* @return array array('prop_name' => 'prop_name', ...) | ||
*/ | ||
public function getProperties() | ||
{ | ||
$props = array_keys(get_object_vars($this)); | ||
|
||
return array_combine($props, $props); | ||
} | ||
|
||
/** | ||
* All Investment entities require a loadOfx method. | ||
* @param SimpleXMLElement $node | ||
* @return $this For chaining | ||
* @throws \Exception | ||
*/ | ||
public function loadOfx(SimpleXMLElement $node) | ||
{ | ||
throw new \Exception('loadOfx method not defined in class "' . get_class() . '"'); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace OfxParser\Entities\Investment; | ||
|
||
use OfxParser\Entities\Investment; | ||
|
||
class Account extends Investment | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $accountNumber; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $brokerId; | ||
|
||
/** | ||
* @var Statement | ||
*/ | ||
public $statement; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $transactionUid; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace OfxParser\Entities\Investment\Transaction; | ||
|
||
use SimpleXMLElement; | ||
use OfxParser\Utils; | ||
use OfxParser\Entities\Inspectable; | ||
use OfxParser\Entities\OfxLoadable; | ||
use OfxParser\Entities\Transaction as BaseTransaction; | ||
|
||
/** | ||
* Per OFX 203 doc, this is a wrapper for a <STMTTRN> node | ||
* (aka "Banking aggregate") with an additional <SUBACCTFUND> node. | ||
* | ||
* Requires Inspectable interface to match API of Invesetment entities | ||
* extending OfxParser\Entities\Investment. | ||
*/ | ||
class Banking extends BaseTransaction implements OfxLoadable, Inspectable | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $nodeName = 'INVBANKTRAN'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $subAccountFund; | ||
|
||
/** | ||
* Get a list of properties defined for this entity. | ||
* @return array array('prop_name' => 'prop_name', ...) | ||
*/ | ||
public function getProperties() | ||
{ | ||
$props = array_keys(get_object_vars($this)); | ||
|
||
return array_combine($props, $props); | ||
} | ||
|
||
/** | ||
* Imports the OFX data for this node. | ||
* @param SimpleXMLElement $node | ||
* @return $this | ||
*/ | ||
public function loadOfx(SimpleXMLElement $node) | ||
{ | ||
// Duplication of code in Ofx::buildTransactions() | ||
$this->type = (string) $node->STMTTRN->TRNTYPE; | ||
$this->date = Utils::createDateTimeFromStr($node->STMTTRN->DTPOSTED); | ||
$this->amount = Utils::createAmountFromStr($node->STMTTRN->TRNAMT); | ||
$this->uniqueId = (string) $node->STMTTRN->FITID; | ||
|
||
// Could put this in another trait. | ||
$this->subAccountFund = (string) $node->SUBACCTFUND; | ||
|
||
return $this; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
lib/OfxParser/Entities/Investment/Transaction/BuyMutualFund.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace OfxParser\Entities\Investment\Transaction; | ||
|
||
use OfxParser\Entities\Investment\Transaction\Traits\BuyType; | ||
|
||
/** | ||
* OFX 203 doc: | ||
* 13.9.2.4.3 Investment Buy/Sell Aggregates <INVBUY>/<INVSELL> | ||
* | ||
* Same as BUYSTOCK, plus <RELFITID> property. | ||
*/ | ||
class BuyMutualFund extends BuyStock | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $nodeName = 'BUYMF'; | ||
|
||
/** | ||
* RELFITID used to relate transactions associated with mutual fund exchanges. | ||
* @var string | ||
*/ | ||
public $relatedUniqueId; | ||
} | ||
|
63 changes: 63 additions & 0 deletions
63
lib/OfxParser/Entities/Investment/Transaction/BuySecurity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace OfxParser\Entities\Investment\Transaction; | ||
|
||
use SimpleXMLElement; | ||
use OfxParser\Entities\AbstractEntity; | ||
use OfxParser\Entities\Investment; | ||
use OfxParser\Entities\Investment\Transaction\Traits\InvTran; | ||
use OfxParser\Entities\Investment\Transaction\Traits\SecId; | ||
use OfxParser\Entities\Investment\Transaction\Traits\Pricing; | ||
|
||
/** | ||
* OFX 203 doc: | ||
* 13.9.2.4.3 Investment Buy/Sell Aggregates <INVBUY>/<INVSELL> | ||
* | ||
* Properties found in the <INVBUY> aggregate. | ||
* Used for "other securities" BUY activities and provides the | ||
* base properties to extend for more specific activities. | ||
* | ||
* Required: | ||
* <INVTRAN> aggregate | ||
* <SECID> aggregate | ||
* <UNITS> | ||
* <UNITPRICE> | ||
* <TOTAL> | ||
* <SUBACCTSEC> | ||
* <SUBACCTFUND> | ||
* | ||
* Optional: | ||
* ...many... | ||
* | ||
* Partial implementation. | ||
*/ | ||
class BuySecurity extends Investment | ||
{ | ||
/** | ||
* Traits used to define properties | ||
*/ | ||
use InvTran; | ||
use SecId; | ||
use Pricing; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $nodeName = 'BUYOTHER'; | ||
|
||
/** | ||
* Imports the OFX data for this node. | ||
* @param SimpleXMLElement $node | ||
* @return $this | ||
*/ | ||
public function loadOfx(SimpleXMLElement $node) | ||
{ | ||
// Transaction data is nested within <INVBUY> child node | ||
$this->loadInvTran($node->INVBUY->INVTRAN) | ||
->loadSecId($node->INVBUY->SECID) | ||
->loadPricing($node->INVBUY); | ||
|
||
return $this; | ||
} | ||
} | ||
|
40 changes: 40 additions & 0 deletions
40
lib/OfxParser/Entities/Investment/Transaction/BuyStock.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace OfxParser\Entities\Investment\Transaction; | ||
|
||
use SimpleXMLElement; | ||
use OfxParser\Entities\Investment\Transaction\Traits\BuyType; | ||
|
||
/** | ||
* OFX 203 doc: | ||
* 13.9.2.4.3 Investment Buy/Sell Aggregates <INVBUY>/<INVSELL> | ||
* | ||
* Properties found in the <INVBUY> aggregate, | ||
* plus <BUYTYPE> property. | ||
*/ | ||
class BuyStock extends BuySecurity | ||
{ | ||
/** | ||
* Traits used to define properties | ||
*/ | ||
use BuyType; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $nodeName = 'BUYSTOCK'; | ||
|
||
/** | ||
* Imports the OFX data for this node. | ||
* @param SimpleXMLElement $node | ||
* @return $this | ||
*/ | ||
public function loadOfx(SimpleXMLElement $node) | ||
{ | ||
parent::loadOfx($node); | ||
$this->loadBuyType($node); | ||
|
||
return $this; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace OfxParser\Entities\Investment\Transaction; | ||
|
||
use SimpleXMLElement; | ||
use OfxParser\Entities\AbstractEntity; | ||
use OfxParser\Entities\Investment; | ||
use OfxParser\Entities\Investment\Transaction\Traits\IncomeType; | ||
use OfxParser\Entities\Investment\Transaction\Traits\InvTran; | ||
use OfxParser\Entities\Investment\Transaction\Traits\Pricing; | ||
use OfxParser\Entities\Investment\Transaction\Traits\SecId; | ||
|
||
/** | ||
* OFX 203 doc: | ||
* 13.9.2.4.3 Investment Buy/Sell Aggregates <INVBUY>/<INVSELL> | ||
* | ||
* Required: | ||
* <INVTRAN> aggregate | ||
* <SECID> aggregate | ||
* <INCOMETYPE> | ||
* <TOTAL> | ||
* <SUBACCTSEC> | ||
* <SUBACCTFUND> | ||
* | ||
* Optional: | ||
* ...many... | ||
* | ||
* Partial implementation. | ||
*/ | ||
class Income extends Investment | ||
{ | ||
/** | ||
* Traits used to define properties | ||
*/ | ||
use IncomeType; | ||
use InvTran; | ||
use Pricing; // Not all of these are required for this node | ||
use SecId; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $nodeName = 'INCOME'; | ||
|
||
/** | ||
* Imports the OFX data for this node. | ||
* @param SimpleXMLElement $node | ||
* @return $this | ||
*/ | ||
public function loadOfx(SimpleXMLElement $node) | ||
{ | ||
// Transaction data is in the root | ||
$this->loadInvTran($node->INVTRAN) | ||
->loadSecId($node->SECID) | ||
->loadPricing($node) | ||
->loadIncomeType($node); | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.