From b5efd38dedfa50b33334097cbf229be3fbd2d781 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 26 Sep 2018 20:34:45 +0200 Subject: [PATCH] New OFX parser reference. --- .../Import/Routine/File/OFXProcessor.php | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 app/Support/Import/Routine/File/OFXProcessor.php diff --git a/app/Support/Import/Routine/File/OFXProcessor.php b/app/Support/Import/Routine/File/OFXProcessor.php new file mode 100644 index 0000000000..a4fd1b4758 --- /dev/null +++ b/app/Support/Import/Routine/File/OFXProcessor.php @@ -0,0 +1,120 @@ +. + */ + +declare(strict_types=1); + +namespace FireflyIII\Support\Import\Routine\File; + + +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; +use FireflyIII\Models\Attachment; +use FireflyIII\Models\ImportJob; +use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; +use Log; +use OfxParser\Entities\BankAccount; +use OfxParser\Entities\Transaction; + +/** + * + * Class OFXProcessor + */ +class OFXProcessor implements FileProcessorInterface +{ + /** @var AttachmentHelperInterface */ + private $attachments; + /** @var ImportJob */ + private $importJob; + /** @var ImportJobRepositoryInterface */ + private $repository; + + /** + * Fires the file processor. + * + * @return array + */ + public function run(): array + { + $collection = $this->repository->getAttachments($this->importJob); + $content = ''; + /** @var Attachment $attachment */ + foreach ($collection as $attachment) { + if ('import_file' === $attachment->filename) { + $content = $this->attachments->getAttachmentContent($attachment); + break; + } + } + $config = $this->repository->getConfiguration($this->importJob); + try { + Log::debug('Now in OFXProcessor() run'); + $ofxParser = new \OfxParser\Parser(); + $ofx = $ofxParser->loadFromString($content); + } catch (\Exception $e) { + echo $e->getMessage(); + exit; + } + reset($ofx->bankAccounts); + /** @var BankAccount $bankAccount */ + foreach ($ofx->bankAccounts as $bankAccount) { + /** @var Transaction $transaction */ + foreach ($bankAccount->statement->transactions as $transaction) { + var_dump($transaction); + } + } + + // + // // Get the statement start and end dates + // $startDate = $bankAccount->statement->startDate; + // $endDate = $bankAccount->statement->endDate; + // var_dump($startDate); + // var_dump($endDate); + // + // // Get the statement transactions for the account + // $transactions = $bankAccount->statement->transactions; + // foreach($transactions as $transaction) { + // var_dump($transaction); + // } + // + // + // die('I am here.'); + + + exit; + + + return []; + } + + /** + * Set values. + * + * @param ImportJob $importJob + */ + public function setImportJob(ImportJob $importJob): void + { + Log::debug('Now in setImportJob()'); + $this->importJob = $importJob; + $this->repository = app(ImportJobRepositoryInterface::class); + $this->attachments = app(AttachmentHelperInterface::class); + + $this->repository->setUser($importJob->user); + + } +} \ No newline at end of file