mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-09 23:15:45 -06:00
Extend transaction model for #351
This commit is contained in:
parent
2017720096
commit
96740aaac4
@ -64,7 +64,7 @@ class Journal implements JournalInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function storeTransaction(TransactionJournal $journal, array $transaction): Collection
|
||||
public function storeTransaction(TransactionJournal $journal, array $transaction, int $identifier): Collection
|
||||
{
|
||||
// store accounts (depends on type)
|
||||
list($sourceAccount, $destinationAccount) = $this->storeAccounts($journal->transactionType->type, $transaction);
|
||||
@ -73,11 +73,11 @@ class Journal implements JournalInterface
|
||||
/** @var Transaction $one */
|
||||
$one = Transaction::create(
|
||||
['account_id' => $sourceAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $transaction['amount'] * -1,
|
||||
'description' => $transaction['description']]
|
||||
'description' => $transaction['description'], 'identifier' => $identifier]
|
||||
);
|
||||
$two = Transaction::create(
|
||||
['account_id' => $destinationAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $transaction['amount'],
|
||||
'description' => $transaction['description']]
|
||||
'description' => $transaction['description'], 'identifier' => $identifier]
|
||||
);
|
||||
|
||||
if (strlen($transaction['category']) > 0) {
|
||||
@ -118,8 +118,10 @@ class Journal implements JournalInterface
|
||||
// delete original transactions, and recreate them.
|
||||
$journal->transactions()->delete();
|
||||
|
||||
$identifier = 0;
|
||||
foreach ($data['transactions'] as $transaction) {
|
||||
$this->storeTransaction($journal, $transaction);
|
||||
$this->storeTransaction($journal, $transaction, $identifier);
|
||||
$identifier++;
|
||||
}
|
||||
|
||||
$journal->completed = true;
|
||||
|
@ -467,7 +467,7 @@ class TestData
|
||||
private function createMultiDeposits()
|
||||
{
|
||||
foreach ($this->data['multi-deposits'] as $deposit) {
|
||||
$journalId = DB::table('transaction_journals')->insertGetId(
|
||||
$journalId = DB::table('transaction_journals')->insertGetId(
|
||||
[
|
||||
'created_at' => $this->time,
|
||||
'updated_at' => $this->time,
|
||||
@ -485,6 +485,7 @@ class TestData
|
||||
'tag_count' => 0,
|
||||
]
|
||||
);
|
||||
$identifier = 0;
|
||||
foreach ($deposit['source_ids'] as $index => $source) {
|
||||
$description = $deposit['description'] . ' (#' . ($index + 1) . ')';
|
||||
$amount = $deposit['amounts'][$index];
|
||||
@ -496,6 +497,7 @@ class TestData
|
||||
'transaction_journal_id' => $journalId,
|
||||
'description' => $description,
|
||||
'amount' => $amount,
|
||||
'identifier' => $identifier,
|
||||
]
|
||||
);
|
||||
$second = DB::table('transactions')->insertGetId(
|
||||
@ -506,8 +508,10 @@ class TestData
|
||||
'transaction_journal_id' => $journalId,
|
||||
'description' => $description,
|
||||
'amount' => $amount * -1,
|
||||
'identifier' => $identifier,
|
||||
]
|
||||
);
|
||||
$identifier++;
|
||||
// link first and second to budget and category, if present.
|
||||
|
||||
if (isset($deposit['category_ids'][$index])) {
|
||||
@ -531,7 +535,7 @@ class TestData
|
||||
private function createMultiTransfers()
|
||||
{
|
||||
foreach ($this->data['multi-transfers'] as $transfer) {
|
||||
$journalId = DB::table('transaction_journals')->insertGetId(
|
||||
$journalId = DB::table('transaction_journals')->insertGetId(
|
||||
[
|
||||
'created_at' => $this->time,
|
||||
'updated_at' => $this->time,
|
||||
@ -549,6 +553,7 @@ class TestData
|
||||
'tag_count' => 0,
|
||||
]
|
||||
);
|
||||
$identifier = 0;
|
||||
foreach ($transfer['destination_ids'] as $index => $destination) {
|
||||
$description = $transfer['description'] . ' (#' . ($index + 1) . ')';
|
||||
$amount = $transfer['amounts'][$index];
|
||||
@ -561,6 +566,7 @@ class TestData
|
||||
'transaction_journal_id' => $journalId,
|
||||
'description' => $description,
|
||||
'amount' => $amount * -1,
|
||||
'identifier' => $identifier,
|
||||
]
|
||||
);
|
||||
$second = DB::table('transactions')->insertGetId(
|
||||
@ -571,9 +577,10 @@ class TestData
|
||||
'transaction_journal_id' => $journalId,
|
||||
'description' => $description,
|
||||
'amount' => $amount,
|
||||
'identifier' => $identifier,
|
||||
]
|
||||
);
|
||||
|
||||
$identifier++;
|
||||
if (isset($transfer['category_ids'][$index])) {
|
||||
DB::table('category_transaction')->insert(
|
||||
[
|
||||
@ -598,7 +605,7 @@ class TestData
|
||||
private function createMultiWithdrawals()
|
||||
{
|
||||
foreach ($this->data['multi-withdrawals'] as $withdrawal) {
|
||||
$journalId = DB::table('transaction_journals')->insertGetId(
|
||||
$journalId = DB::table('transaction_journals')->insertGetId(
|
||||
[
|
||||
'created_at' => $this->time,
|
||||
'updated_at' => $this->time,
|
||||
@ -616,6 +623,7 @@ class TestData
|
||||
'tag_count' => 0,
|
||||
]
|
||||
);
|
||||
$identifier = 0;
|
||||
foreach ($withdrawal['destination_ids'] as $index => $destination) {
|
||||
$description = $withdrawal['description'] . ' (#' . ($index + 1) . ')';
|
||||
$amount = $withdrawal['amounts'][$index];
|
||||
@ -627,6 +635,7 @@ class TestData
|
||||
'transaction_journal_id' => $journalId,
|
||||
'description' => $description,
|
||||
'amount' => $amount * -1,
|
||||
'identifier' => $identifier,
|
||||
]
|
||||
);
|
||||
$second = DB::table('transactions')->insertGetId(
|
||||
@ -637,8 +646,10 @@ class TestData
|
||||
'transaction_journal_id' => $journalId,
|
||||
'description' => $description,
|
||||
'amount' => $amount,
|
||||
'identifier' => $identifier,
|
||||
]
|
||||
);
|
||||
$identifier++;
|
||||
// link first and second to budget and category, if present.
|
||||
if (isset($withdrawal['budget_ids'][$index])) {
|
||||
DB::table('budget_transaction')->insert(
|
||||
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Class ExpandTransactionsTable
|
||||
*/
|
||||
class ExpandTransactionsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table(
|
||||
'transactions', function (Blueprint $table) {
|
||||
$table->smallInteger('identifier', false, false)->default(0);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user