1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OfxParser\Ofx; |
4
|
|
|
|
5
|
|
|
use SimpleXMLElement; |
6
|
|
|
use OfxParser\Ofx; |
7
|
|
|
use OfxParser\Utils; |
8
|
|
|
use OfxParser\Entities\Statement; |
9
|
|
|
use OfxParser\Entities\Investment\Account as InvestmentAccount; |
10
|
|
|
use OfxParser\Entities\Investment\Transaction\Banking; |
11
|
|
|
use OfxParser\Entities\Investment\Transaction\BuyMutualFund; |
12
|
|
|
use OfxParser\Entities\Investment\Transaction\BuySecurity; |
13
|
|
|
use OfxParser\Entities\Investment\Transaction\BuyStock; |
14
|
|
|
use OfxParser\Entities\Investment\Transaction\Income; |
15
|
|
|
use OfxParser\Entities\Investment\Transaction\Reinvest; |
16
|
|
|
use OfxParser\Entities\Investment\Transaction\SellMutualFund; |
17
|
|
|
|
18
|
|
|
class Investment extends Ofx |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param SimpleXMLElement $xml |
22
|
|
|
* @throws \Exception |
23
|
|
|
*/ |
24
|
|
|
public function __construct(SimpleXMLElement $xml) |
25
|
|
|
{ |
26
|
|
|
$this->signOn = $this->buildSignOn($xml->SIGNONMSGSRSV1->SONRS); |
27
|
|
|
|
28
|
|
|
if (isset($xml->INVSTMTMSGSRSV1)) { |
29
|
|
|
$this->bankAccounts = $this->buildAccounts($xml); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// Set a helper if only one bank account |
33
|
|
|
if (count($this->bankAccounts) === 1) { |
34
|
|
|
$this->bankAccount = $this->bankAccounts[0]; |
|
|
|
|
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param SimpleXMLElement $xml |
40
|
|
|
* @return array Array of InvestmentAccount enities |
41
|
|
|
* @throws \Exception |
42
|
|
|
*/ |
43
|
|
|
protected function buildAccounts(SimpleXMLElement $xml) |
44
|
|
|
{ |
45
|
|
|
// Loop through the bank accounts |
46
|
|
|
$accounts = []; |
47
|
|
|
foreach ($xml->INVSTMTMSGSRSV1->INVSTMTTRNRS as $accountStatement) { |
48
|
|
|
foreach ($accountStatement->INVSTMTRS as $statementResponse) { |
49
|
|
|
$accounts[] = $this->buildAccount($accountStatement->TRNUID, $statementResponse); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
return $accounts; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $transactionUid |
57
|
|
|
* @param SimpleXMLElement $statementResponse |
58
|
|
|
* @return InvestmentAccount |
59
|
|
|
* @throws \Exception |
60
|
|
|
*/ |
61
|
|
|
protected function buildAccount($transactionUid, SimpleXMLElement $statementResponse) |
62
|
|
|
{ |
63
|
|
|
$account = new InvestmentAccount(); |
64
|
|
|
$account->transactionUid = (string) $transactionUid; |
65
|
|
|
$account->brokerId = (string) $statementResponse->INVACCTFROM->BROKERID; |
66
|
|
|
$account->accountNumber = (string) $statementResponse->INVACCTFROM->ACCTID; |
67
|
|
|
|
68
|
|
|
$account->statement = new Statement(); |
|
|
|
|
69
|
|
|
$account->statement->currency = (string) $statementResponse->CURDEF; |
70
|
|
|
|
71
|
|
|
$account->statement->startDate = Utils::createDateTimeFromStr( |
72
|
|
|
$statementResponse->INVTRANLIST->DTSTART |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$account->statement->endDate = Utils::createDateTimeFromStr( |
76
|
|
|
$statementResponse->INVTRANLIST->DTEND |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$account->statement->transactions = $this->buildTransactions( |
80
|
|
|
$statementResponse->INVTRANLIST->children() |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
return $account; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Processes multiple types of investment transactions, ignoring many |
88
|
|
|
* others. |
89
|
|
|
* |
90
|
|
|
* @param SimpleXMLElement $transactions |
91
|
|
|
* @return array |
92
|
|
|
* @throws \Exception |
93
|
|
|
*/ |
94
|
|
|
protected function buildTransactions(SimpleXMLElement $transactions) |
95
|
|
|
{ |
96
|
|
|
$activity = []; |
97
|
|
|
|
98
|
|
|
foreach ($transactions as $t) { |
99
|
|
|
$item = null; |
100
|
|
|
|
101
|
|
|
switch ($t->getName()) { |
|
|
|
|
102
|
|
|
case 'BUYMF': |
103
|
|
|
$item = new BuyMutualFund(); |
104
|
|
|
break; |
105
|
|
|
case 'BUYOTHER': |
106
|
|
|
$item = new BuySecurity(); |
107
|
|
|
break; |
108
|
|
|
case 'BUYSTOCK': |
109
|
|
|
$item = new BuyStock(); |
110
|
|
|
break; |
111
|
|
|
case 'INCOME': |
112
|
|
|
$item = new Income(); |
113
|
|
|
break; |
114
|
|
|
case 'INVBANKTRAN': |
115
|
|
|
$item = new Banking(); |
116
|
|
|
break; |
117
|
|
|
case 'REINVEST': |
118
|
|
|
$item = new Reinvest(); |
119
|
|
|
break; |
120
|
|
|
case 'SELLMF': |
121
|
|
|
$item = new SellMutualFund(); |
122
|
|
|
break; |
123
|
|
|
case 'DTSTART': |
124
|
|
|
// already processed |
125
|
|
|
break; |
126
|
|
|
case 'DTEND': |
127
|
|
|
// already processed |
128
|
|
|
break; |
129
|
|
|
default: |
130
|
|
|
// Log: ignored node.... |
131
|
|
|
break; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if (!is_null($item)) { |
135
|
|
|
$item->loadOfx($t); |
|
|
|
|
136
|
|
|
$activity[] = $item; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return $activity; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.