Skip to content

Firefly III: a personal finances manager

Update transactions, delete splits.

James Cole140a5b20db18
diff --git a/app/Api/V1/Requests/TransactionRequest.php b/app/Api/V1/Requests/TransactionRequest.php
index 374a15a801..a724caede3 100644
--- a/app/Api/V1/Requests/TransactionRequest.php
+++ b/app/Api/V1/Requests/TransactionRequest.php
@@ -447,6 +447,17 @@ class TransactionRequest extends Request
if ($count < 2) {
return;
}
+
+ if (!isset($data['type'])) {
+ // the journal may exist in the request:
+ /** @var Transaction $transaction */
+ $transaction = $this->route()->parameter('transaction');
+ if (is_null($transaction)) {
+ return;
+ }
+ $data['type'] = strtolower($transaction->transactionJournal->transactionType->type);
+ }
+
// collect all source ID's and destination ID's, if present:
$sources = [];
$destinations = [];
diff --git a/app/Services/Internal/JournalUpdateService.php b/app/Services/Internal/JournalUpdateService.php
index 9254da0af8..76f50c017c 100644
--- a/app/Services/Internal/JournalUpdateService.php
+++ b/app/Services/Internal/JournalUpdateService.php
@@ -57,6 +57,7 @@ class JournalUpdateService
*
* @return TransactionJournal
* @throws \FireflyIII\Exceptions\FireflyException
+ * @throws \Exception
*/
public function update(TransactionJournal $journal, array $data): TransactionJournal
{
@@ -94,6 +95,14 @@ class JournalUpdateService
// otherwise, create!
$factory->createPair($journal, $trData);
}
+ // could be that journal has more transactions than submitted (remove split)
+ $transactions = $journal->transactions()->where('amount', '>', 0)->get();
+ /** @var Transaction $transaction */
+ foreach ($transactions as $transaction) {
+ if (!isset($data['transactions'][$transaction->identifier])) {
+ $journal->transactions()->where('identifier', $transaction->identifier)->delete();
+ }
+ }
// connect bill:
$this->connectBill($journal, $data);