Skip to content

Firefly III: a personal finances manager

Fix small errors in bulk and mass controller

James Cole2f17521c06c1
diff --git a/app/Http/Controllers/Transaction/BulkController.php b/app/Http/Controllers/Transaction/BulkController.php
index 3dfc5a1040..10d38d0895 100644
--- a/app/Http/Controllers/Transaction/BulkController.php
+++ b/app/Http/Controllers/Transaction/BulkController.php
@@ -168,7 +168,7 @@ class BulkController extends Controller
}
if ($ignoreTags === false) {
Log::debug(sprintf('Set tags to %s', $request->string('budget_id')));
- $repository->updateTags($journal, explode(',', $request->string('tags')));
+ $repository->updateTags($journal,['tags' => explode(',', $request->string('tags'))]);
}
// update tags if not told to ignore (and is withdrawal)
}
diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php
index 7919344687..c84cde082b 100644
--- a/app/Http/Controllers/Transaction/MassController.php
+++ b/app/Http/Controllers/Transaction/MassController.php
@@ -115,6 +115,8 @@ class MassController extends Controller
}
/**
+ * TODO this code is a mess.
+ *
* @param Collection $journals
*
* @return View
@@ -222,10 +224,11 @@ class MassController extends Controller
if (!is_null($journal)) {
// get optional fields:
$what = strtolower($this->repository->getTransactionType($journal));
- $sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0;
- $sourceAccountName = $request->get('source_account_name')[$journal->id] ?? '';
- $destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0;
- $destAccountName = $request->get('destination_account_name')[$journal->id] ?? '';
+ $sourceAccountId = $request->get('source_account_id')[$journal->id] ?? null;
+ $currencyId = $request->get('transaction_currency_id')[$journal->id] ?? 1;
+ $sourceAccountName = $request->get('source_account_name')[$journal->id] ?? null;
+ $destAccountId = $request->get('destination_account_id')[$journal->id] ?? null;
+ $destAccountName = $request->get('destination_account_name')[$journal->id] ?? null;
$budgetId = $request->get('budget_id')[$journal->id] ?? 0;
$category = $request->get('category')[$journal->id];
$tags = $journal->tags->pluck('tag')->toArray();
@@ -233,29 +236,47 @@ class MassController extends Controller
$foreignAmount = isset($request->get('foreign_amount')[$journal->id]) ? round($request->get('foreign_amount')[$journal->id], 12) : null;
$foreignCurrencyId = isset($request->get('foreign_currency_id')[$journal->id]) ?
intval($request->get('foreign_currency_id')[$journal->id]) : null;
-
+ $notes = $repository->getNoteText($journal);
// build data array
$data = [
- 'id' => $journal->id,
- 'what' => $what,
- 'description' => $request->get('description')[$journal->id],
- 'source_account_id' => intval($sourceAccountId),
- 'source_account_name' => $sourceAccountName,
- 'destination_account_id' => intval($destAccountId),
- 'destination_account_name' => $destAccountName,
- 'amount' => $foreignAmount,
- 'native_amount' => $amount,
- 'source_amount' => $amount,
- 'date' => new Carbon($request->get('date')[$journal->id]),
- 'interest_date' => $journal->interest_date,
- 'book_date' => $journal->book_date,
- 'process_date' => $journal->process_date,
- 'budget_id' => intval($budgetId),
- 'currency_id' => $foreignCurrencyId,
- 'foreign_amount' => $foreignAmount,
- 'destination_amount' => $foreignAmount,
- 'category' => $category,
- 'tags' => $tags,
+ 'id' => $journal->id,
+ 'what' => $what,
+ 'description' => $request->get('description')[$journal->id],
+ 'date' => new Carbon($request->get('date')[$journal->id]),
+ 'bill_id' => null,
+ 'bill_name' => null,
+ 'notes' => $notes,
+ 'transactions' => [[
+
+ 'category_id' => null,
+ 'category_name' => $category,
+ 'budget_id' => intval($budgetId),
+ 'budget_name' => null,
+ 'source_id' => intval($sourceAccountId),
+ 'source_name' => $sourceAccountName,
+ 'destination_id' => intval($destAccountId),
+ 'destination_name' => $destAccountName,
+ 'amount' => $amount,
+ 'identifier' => 0,
+ 'reconciled' => false,
+ 'currency_id' => intval($currencyId),
+ 'currency_code' => null,
+ 'description' => null,
+ 'foreign_amount' => null,
+ 'foreign_currency_id' => $foreignCurrencyId,
+ 'foreign_currency_code' => null,
+ //'native_amount' => $amount,
+ //'source_amount' => $amount,
+ //'foreign_amount' => $foreignAmount,
+ //'destination_amount' => $foreignAmount,
+ //'amount' => $foreignAmount,
+ ]],
+ 'currency_id' => $foreignCurrencyId,
+ 'tags' => $tags,
+ 'interest_date' => $journal->interest_date,
+ 'book_date' => $journal->book_date,
+ 'process_date' => $journal->process_date,
+
];
// call repository update function.
$repository->update($journal, $data);
diff --git a/app/Services/Internal/Support/JournalServiceTrait.php b/app/Services/Internal/Support/JournalServiceTrait.php
index 6ad10999a8..93186c7804 100644
--- a/app/Services/Internal/Support/JournalServiceTrait.php
+++ b/app/Services/Internal/Support/JournalServiceTrait.php
@@ -37,6 +37,28 @@ use FireflyIII\Models\TransactionJournal;
trait JournalServiceTrait
{
+ /**
+ * @param TransactionJournal $journal
+ * @param array $data
+ */
+ public function connectTags(TransactionJournal $journal, array $data): void
+ {
+ /** @var TagFactory $factory */
+ $factory = app(TagFactory::class);
+ $factory->setUser($journal->user);
+ $set = [];
+ if (!is_array($data['tags'])) {
+ return; // @codeCoverageIgnore
+ }
+ foreach ($data['tags'] as $string) {
+ if (strlen($string) > 0) {
+ $tag = $factory->findOrCreate($string);
+ $set[] = $tag->id;
+ }
+ }
+ $journal->tags()->sync($set);
+ }
+
/**
* Connect bill if present.
*
@@ -62,28 +84,6 @@ trait JournalServiceTrait
return;
}
- /**
- * @param TransactionJournal $journal
- * @param array $data
- */
- protected function connectTags(TransactionJournal $journal, array $data): void
- {
- /** @var TagFactory $factory */
- $factory = app(TagFactory::class);
- $factory->setUser($journal->user);
- $set = [];
- if (!is_array($data['tags'])) {
- return; // @codeCoverageIgnore
- }
- foreach ($data['tags'] as $string) {
- if (strlen($string) > 0) {
- $tag = $factory->findOrCreate($string);
- $set[] = $tag->id;
- }
- }
- $journal->tags()->sync($set);
- }
-
/**
* @param TransactionJournal $journal
* @param array $data