Skip to content

Firefly III: a personal finances manager

Simplified export controller.

James Coleb8c787645416
diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php
index 0396c98a63..27e65214af 100644
--- a/app/Http/Controllers/ExportController.php
+++ b/app/Http/Controllers/ExportController.php
@@ -12,6 +12,7 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use Config;
+use ExpandedForm;
use FireflyIII\Export\Processor;
use FireflyIII\Http\Requests;
use FireflyIII\Http\Requests\ExportFormRequest;
@@ -91,12 +92,14 @@ class ExportController extends Controller
// does the user have shared accounts?
$accounts = $repository->getAccounts(['Default account', 'Asset account']);
+ $accountList = ExpandedForm::makeSelectList($accounts);
+ $checked = array_keys($accountList);
$formats = array_keys(Config::get('firefly.export_formats'));
$defaultFormat = Preferences::get('export_format', Config::get('firefly.default_export_format'))->data;
$first = session('first')->format('Y-m-d');
$today = Carbon::create()->format('Y-m-d');
- return view('export.index', compact('accounts', 'job', 'formats', 'defaultFormat', 'first', 'today'));
+ return view('export.index', compact('job', 'checked', 'accountList', 'formats', 'defaultFormat', 'first', 'today'));
}
diff --git a/app/Support/Amount.php b/app/Support/Amount.php
index 84b08b3da7..ceed9f2e06 100644
--- a/app/Support/Amount.php
+++ b/app/Support/Amount.php
@@ -68,7 +68,7 @@ class Amount
*
* @return string
*/
- public function formatJournal(TransactionJournal $journal, bool $coloured = true)
+ public function formatJournal(TransactionJournal $journal, bool $coloured = true): string
{
$cache = new CacheProperties;
$cache->addProperty($journal->id);
diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php
index a67389eb2f..0b3bd7fb55 100644
--- a/app/Support/CacheProperties.php
+++ b/app/Support/CacheProperties.php
@@ -54,7 +54,7 @@ class CacheProperties
/**
* @return string
*/
- public function getMd5()
+ public function getMd5(): string
{
return $this->md5;
}
@@ -62,7 +62,7 @@ class CacheProperties
/**
* @return bool
*/
- public function has()
+ public function has(): bool
{
if (getenv('APP_ENV') == 'testing') {
return false;
diff --git a/app/Support/Domain.php b/app/Support/Domain.php
index c7892278d3..d1df4dc185 100644
--- a/app/Support/Domain.php
+++ b/app/Support/Domain.php
@@ -22,7 +22,7 @@ class Domain
/**
* @return array
*/
- public static function getBindables()
+ public static function getBindables(): array
{
return Config::get('firefly.bindables');
@@ -31,7 +31,7 @@ class Domain
/**
* @return array
*/
- public static function getRuleActions()
+ public static function getRuleActions(): array
{
return Config::get('firefly.rule-actions');
}
@@ -39,7 +39,7 @@ class Domain
/**
* @return array
*/
- public static function getRuleTriggers()
+ public static function getRuleTriggers(): array
{
return Config::get('firefly.rule-triggers');
}
diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php
index 9962c16ac1..f84eaad0d4 100644
--- a/app/Support/Twig/Journal.php
+++ b/app/Support/Twig/Journal.php
@@ -12,8 +12,6 @@ use Twig_SimpleFilter;
use Twig_SimpleFunction;
/**
- * @codeCoverageIgnore
- *
* Class Journal
*
* @package FireflyIII\Support\Twig
@@ -24,7 +22,7 @@ class Journal extends Twig_Extension
/**
* @return array
*/
- public function getFilters()
+ public function getFilters(): array
{
$filters = [$this->typeIcon()];
@@ -34,11 +32,10 @@ class Journal extends Twig_Extension
/**
* @return array
*/
- public function getFunctions()
+ public function getFunctions(): array
{
$functions = [
$this->invalidJournal(),
- $this->relevantTags(),
];
return $functions;
@@ -49,18 +46,34 @@ class Journal extends Twig_Extension
*
* @return string The extension name
*/
- public function getName()
+ public function getName(): string
{
return 'FireflyIII\Support\Twig\Journals';
}
+ /**
+ * @return Twig_SimpleFunction
+ */
+ protected function invalidJournal(): Twig_SimpleFunction
+ {
+ return new Twig_SimpleFunction(
+ 'invalidJournal', function (TransactionJournal $journal): bool {
+ if (!isset($journal->transactions[1]) || !isset($journal->transactions[0])) {
+ return true;
+ }
+
+ return false;
+ }
+ );
+ }
+
/**
* @return Twig_SimpleFilter
*/
- protected function typeIcon()
+ protected function typeIcon(): Twig_SimpleFilter
{
return new Twig_SimpleFilter(
- 'typeIcon', function (TransactionJournal $journal) {
+ 'typeIcon', function (TransactionJournal $journal): string {
$cache = new CacheProperties();
$cache->addProperty($journal->id);
@@ -94,149 +107,4 @@ class Journal extends Twig_Extension
}, ['is_safe' => ['html']]
);
}
-
- /**
- * @return Twig_SimpleFunction
- */
- protected function invalidJournal()
- {
- return new Twig_SimpleFunction(
- 'invalidJournal', function (TransactionJournal $journal) {
- if (!isset($journal->transactions[1]) || !isset($journal->transactions[0])) {
- return true;
- }
-
- return false;
- }
- );
- }
-
- /**
- * @return Twig_SimpleFunction
- */
- protected function relevantTags()
- {
- return new Twig_SimpleFunction(
- 'relevantTags', function (TransactionJournal $journal) {
- $cache = new CacheProperties;
- $cache->addProperty('relevantTags');
- $cache->addProperty($journal->id);
-
- if ($cache->has()) {
- return $cache->get(); // @codeCoverageIgnore
- }
- $count = $journal->tags->count();
- $string = '';
-
- if ($count === 0) {
- $string = $this->relevantTagsNoTags($journal);
- }
-
- if ($count === 1) {
- $string = $this->relevantTagsSingle($journal);
- }
-
- if ($count > 1) {
- $string = $this->relevantTagsMulti($journal);
- }
-
- $cache->store($string);
-
- return $string;
- }
- );
- }
-
- /**
- * @param TransactionJournal $journal
- *
- * @return string
- */
- protected function relevantTagsNoTags(TransactionJournal $journal)
- {
- return app('amount')->formatJournal($journal);
- }
-
- /**
- * @param TransactionJournal $journal
- *
- * @return string
- */
- protected function relevantTagsSingle(TransactionJournal $journal)
- {
- $tag = $journal->tags()->first();
-
- return $this->formatJournalByTag($journal, $tag);
- }
-
- /**
- * @param TransactionJournal $journal
- * @param Tag $tag
- *
- * @return string
- */
- protected function formatJournalByTag(TransactionJournal $journal, Tag $tag)
- {
- if ($tag->tagMode == 'balancingAct') {
- // return tag formatted for a "balancing act", even if other
- // tags are present.
- $amount = app('amount')->format($journal->amount_positive, false);
- $string = '<a href="' . route('tags.show', [$tag->id]) . '" class="label label-success" title="' . $amount
- . '"><i class="fa fa-fw fa-refresh"></i> ' . $tag->tag . '</a>';
-
- return $string;
- }
-
- if ($tag->tagMode == 'advancePayment') {
- if ($journal->isDeposit()) {
- $amount = app('amount')->formatJournal($journal, false);
- $string = '<a href="' . route('tags.show', [$tag->id]) . '" class="label label-success" title="' . $amount
- . '"><i class="fa fa-fw fa-sort-numeric-desc"></i> ' . $tag->tag . '</a>';
-
- return $string;
- }
-
- /*
- * AdvancePayment with a withdrawal will show the amount with a link to
- * the tag. The TransactionJournal should properly calculate the amount.
- */
- if ($journal->isWithdrawal()) {
- $amount = app('amount')->formatJournal($journal);
-
- $string = '<a href="' . route('tags.show', [$tag->id]) . '">' . $amount . '</a>';
-
- return $string;
- }
- }
-
-
- return $this->relevantTagsNoTags($journal);
- }
-
- /**
- * If a transaction journal has multiple tags, we'll have to gamble. FF3
- * does not yet block adding multiple 'special' tags so we must wing it.
- *
- * We grab the first special tag (for advancePayment and for balancingAct
- * and try to format those. If they're not present (it's all normal tags),
- * we can format like any other journal.
- *
- * @param TransactionJournal $journal
- *
- * @return string
- */
- protected function relevantTagsMulti(TransactionJournal $journal)
- {
- $firstBalancingAct = $journal->tags()->where('tagMode', 'balancingAct')->first();
- if ($firstBalancingAct) {
- return $this->formatJournalByTag($journal, $firstBalancingAct);
- }
-
- $firstAdvancePayment = $journal->tags()->where('tagMode', 'advancePayment')->first();
- if ($firstAdvancePayment) {
- return $this->formatJournalByTag($journal, $firstAdvancePayment);
- }
-
- return $this->relevantTagsNoTags($journal);
- }
}