Update transactions, delete splits.

This commit is contained in:
James Cole
2018-02-21 08:58:06 +01:00
parent e9b6b45fc4
commit 140a5b20db
2 changed files with 20 additions and 0 deletions

View File

@@ -447,6 +447,17 @@ class TransactionRequest extends Request
if ($count < 2) { if ($count < 2) {
return; 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: // collect all source ID's and destination ID's, if present:
$sources = []; $sources = [];
$destinations = []; $destinations = [];

View File

@@ -57,6 +57,7 @@ class JournalUpdateService
* *
* @return TransactionJournal * @return TransactionJournal
* @throws \FireflyIII\Exceptions\FireflyException * @throws \FireflyIII\Exceptions\FireflyException
* @throws \Exception
*/ */
public function update(TransactionJournal $journal, array $data): TransactionJournal public function update(TransactionJournal $journal, array $data): TransactionJournal
{ {
@@ -94,6 +95,14 @@ class JournalUpdateService
// otherwise, create! // otherwise, create!
$factory->createPair($journal, $trData); $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: // connect bill:
$this->connectBill($journal, $data); $this->connectBill($journal, $data);