okonst/ofxparser

简单的OFX文件解析器 - 基于 asgrim/ofxparser 的分支

维护者

详细信息

github.com/okonst/ofxparser

源代码

安装: 15

依赖: 0

建议: 0

安全: 0

星标: 1

关注者: 0

分支: 100

v1.0.2 2024-05-03 15:52 UTC

This package is auto-updated.

Last update: 2024-09-03 17:01:38 UTC


README

这是一个扩展了交易字段的asgrim/ofxparser分支。

添加了对扩展的OFX交易字段的支持:PAYEEID, REFNUM, EXTDNAME, PAYEE, BANKACCTTO, CCACCTTO。

OFX解析器是一个PHP库,旨在将金融机构下载的OFX文件解析为简单的PHP对象。

它支持多个银行账户、所需的“登录”响应,并识别OFX时间戳。

安装

使用Composer简单要求包

$ composer require asgrim/ofxparser

用法

您可以通过以下方式访问OFX文件中的节点

$ofxParser = new \OfxParser\Parser();
$ofx = $ofxParser->loadFromFile('/path/to/your/bankstatement.ofx');

$bankAccount = reset($ofx->bankAccounts);

// Get the statement start and end dates
$startDate = $bankAccount->statement->startDate;
$endDate = $bankAccount->statement->endDate;

// Get the statement transactions for the account
$transactions = $bankAccount->statement->transactions;

最常用的节点是支持。如果您在OFX文件中遇到无法访问的节点,请提交一个拉取请求!

投资支持

投资看起来与银行/信用卡交易有很大不同。此版本支持OFX 2.0.3规范中的一些节点,以满足作者/的即时需求。如果您选择实现此库,请参考OFX文档。特别是,此版本目前不处理投资位置(INVPOSLIST)或引用的证券定义(SECINFO)。

这不是字面上的字段透传,例如Python中的此实现: csingley/ofxtools。此包包含一些字段,有时会“翻译”以使其对不太熟悉投资OFX规范的用户更友好。

要从Quicken(QFX)文件或MS Money(OFX / XML)文件中加载投资

// You'll probably want to alias the namespace:
use OfxParser\Entities\Investment as InvEntities;

// Load the OFX file
$ofxParser = new \OfxParser\Parsers\Investment();
$ofx = $ofxParser->loadFromFile('/path/to/your/investments_file.ofx');

// Loop over investment accounts (named bankAccounts from base lib)
foreach ($ofx->bankAccounts as $accountData) {
    // Loop over transactions
    foreach ($accountData->statement->transactions as $ofxEntity) {
        // Keep in mind... not all properties are inherited for all transaction types...

        // Maybe you'll want to do something based on the transaction properties:
        $nodeName = $ofxEntity->nodeName;
        if ($nodeName == 'BUYSTOCK') {
            // @see OfxParser\Entities\Investment\Transaction...

            $amount = abs($ofxEntity->total);
            $cusip = $ofxEntity->securityId;

            // ...
        }

        // Maybe you'll want to do something based on the entity:
        if ($ofxEntity instanceof InvEntities\Transaction\BuyStock) {
            // ...
        }

    }
}

Fork & Credits

这是一个grimfor/ofxparser分支,用于使其与框架无关。源代码库是为Symfony 2框架设计的,因此应该给予应有的认可!由Oliver Lowe大量重构,并松散地基于Andrew A. Smith的Ruby ofx-parser