diff --git a/app/Helpers/Collector/Extensions/CollectorProperties.php b/app/Helpers/Collector/Extensions/CollectorProperties.php index ae05ce6338..fd55907012 100644 --- a/app/Helpers/Collector/Extensions/CollectorProperties.php +++ b/app/Helpers/Collector/Extensions/CollectorProperties.php @@ -36,6 +36,8 @@ trait CollectorProperties private $hasAccountInfo; /** @var bool Will be true if query result includes bill information. */ private $hasBillInformation; + /** @var bool */ + private $hasNotesInformation; /** @var bool Will be true if query result contains budget info. */ private $hasBudgetInformation; /** @var bool Will be true if query result contains category info. */ diff --git a/app/Helpers/Collector/Extensions/MetaCollection.php b/app/Helpers/Collector/Extensions/MetaCollection.php index 0f92abbbaf..ea0bea686f 100644 --- a/app/Helpers/Collector/Extensions/MetaCollection.php +++ b/app/Helpers/Collector/Extensions/MetaCollection.php @@ -28,6 +28,7 @@ use FireflyIII\Models\Budget; use FireflyIII\Models\Category; use FireflyIII\Models\Tag; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; +use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection; /** @@ -36,6 +37,27 @@ use Illuminate\Support\Collection; trait MetaCollection { + /** + * @inheritDoc + */ + public function withNotes(): GroupCollectorInterface + { + if (false === $this->hasNotesInformation) { + // join bill table + $this->query->leftJoin( + 'notes', + static function (JoinClause $join) { + $join->on('notes.noteable_id', '=', 'transaction_journals.id'); + $join->where('notes.noteable_type', '=', 'FireflyIII\Models\TransactionJournal'); + } + ); + // add fields + $this->fields[] = 'notes.text as notes'; + $this->hasNotesInformation = true; + } + + return $this; + } /** * Limit the search to a specific bill. diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php index 4540f41a32..bcf955b721 100644 --- a/app/Helpers/Collector/GroupCollector.php +++ b/app/Helpers/Collector/GroupCollector.php @@ -62,6 +62,7 @@ class GroupCollector implements GroupCollectorInterface $this->hasCatInformation = false; $this->hasBudgetInformation = false; $this->hasBillInformation = false; + $this->hasNotesInformation = false; $this->hasJoinedTagTables = false; $this->hasJoinedAttTables = false; $this->integerFields = [ @@ -681,4 +682,5 @@ class GroupCollector implements GroupCollectorInterface ->orderBy('transaction_journals.description', 'DESC') ->orderBy('source.amount', 'DESC'); } + } diff --git a/app/Helpers/Collector/GroupCollectorInterface.php b/app/Helpers/Collector/GroupCollectorInterface.php index 6975ca7b44..17a4e4f0ca 100644 --- a/app/Helpers/Collector/GroupCollectorInterface.php +++ b/app/Helpers/Collector/GroupCollectorInterface.php @@ -398,6 +398,13 @@ interface GroupCollectorInterface */ public function withCategoryInformation(): GroupCollectorInterface; + /** + * Will include notes. + * + * @return GroupCollectorInterface + */ + public function withNotes(): GroupCollectorInterface; + /** * Add tag info. * diff --git a/app/Support/Export/ExportDataGenerator.php b/app/Support/Export/ExportDataGenerator.php index d69e4eea4d..1e49f73d32 100644 --- a/app/Support/Export/ExportDataGenerator.php +++ b/app/Support/Export/ExportDataGenerator.php @@ -656,11 +656,11 @@ class ExportDataGenerator // TODO better place for keys? $header = ['user_id', 'group_id', 'journal_id', 'created_at', 'updated_at', 'group_title', 'type', 'amount', 'foreign_amount', 'currency_code', 'foreign_currency_code', 'description', 'date', 'source_name', 'source_iban', 'source_type', 'destination_name', 'destination_iban', - 'destination_type', 'reconciled', 'category', 'budget', 'bill', 'tags',]; + 'destination_type', 'reconciled', 'category', 'budget', 'bill', 'tags', 'notes']; $collector = app(GroupCollectorInterface::class); $collector->setUser($this->user); $collector->setRange($this->start, $this->end)->withAccountInformation()->withCategoryInformation()->withBillInformation() - ->withBudgetInformation()->withTagInformation(); + ->withBudgetInformation()->withTagInformation()->withNotes(); $journals = $collector->getExtractedJournals(); $records = []; @@ -691,6 +691,7 @@ class ExportDataGenerator $journal['budget_name'], $journal['bill_name'], $this->mergeTags($journal['tags']), + $journal['notes'], ]; } diff --git a/composer.json b/composer.json index 4fce682de7..ed65b7ee94 100644 --- a/composer.json +++ b/composer.json @@ -93,6 +93,7 @@ "laravel/ui": "^2.0", "laravelcollective/html": "6.*", "league/commonmark": "1.*", + "league/csv": "^9.6", "league/fractal": "0.*", "pragmarx/google2fa": "^7.0", "pragmarx/recovery": "^0.1.0", diff --git a/composer.lock b/composer.lock index 01a33730eb..7b06076347 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c87d6fc7dfa25bdd667573fd4f924d0b", + "content-hash": "ff245cbb0236e439d420e96a58327852", "packages": [ { "name": "adldap2/adldap2", @@ -1929,6 +1929,83 @@ ], "time": "2020-05-04T22:15:21+00:00" }, + { + "name": "league/csv", + "version": "9.6.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/csv.git", + "reference": "7351a74625601914409b42b32cabb91a93773b7b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/csv/zipball/7351a74625601914409b42b32cabb91a93773b7b", + "reference": "7351a74625601914409b42b32cabb91a93773b7b", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "php": "^7.2.5" + }, + "require-dev": { + "ext-curl": "*", + "friendsofphp/php-cs-fixer": "^2.16", + "phpstan/phpstan": "^0.12.0", + "phpstan/phpstan-phpunit": "^0.12.0", + "phpstan/phpstan-strict-rules": "^0.12.0", + "phpunit/phpunit": "^8.0" + }, + "suggest": { + "ext-dom": "Required to use the XMLConverter and or the HTMLConverter classes", + "ext-iconv": "Needed to ease transcoding CSV using iconv stream filters" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Csv\\": "src" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://github.com/nyamsprod/", + "role": "Developer" + } + ], + "description": "CSV data manipulation made easy in PHP", + "homepage": "http://csv.thephpleague.com", + "keywords": [ + "convert", + "csv", + "export", + "filter", + "import", + "read", + "transform", + "write" + ], + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2020-03-17T15:15:35+00:00" + }, { "name": "league/event", "version": "2.2.0",