Fix transactions.

This commit is contained in:
James Cole 2018-02-23 16:59:21 +01:00
parent 6591fa9fb4
commit 1a721ac6b5
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
13 changed files with 246 additions and 56 deletions

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\TransactionRequest;
use FireflyIII\Factory\TransactionJournalFactory;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
@ -179,14 +178,11 @@ class TransactionController extends Controller
* @return \Illuminate\Http\JsonResponse
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function store(TransactionRequest $request)
public function store(TransactionRequest $request, JournalRepositoryInterface $repository)
{
$data = $request->getAll();
$data['user'] = auth()->user()->id;
/** @var TransactionJournalFactory $factory */
$factory = app(TransactionJournalFactory::class);
$factory->setUser(auth()->user());
$journal = $factory->create($data);
$journal = $repository->store($data);
$manager = new Manager();
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
@ -196,7 +192,6 @@ class TransactionController extends Controller
$include = $request->get('include') ?? '';
$manager->parseIncludes($include);
// needs a lot of extra data to match the journal collector. Or just expand that one.
// collect transactions using the journal collector
$collector = app(JournalCollectorInterface::class);
$collector->setUser(auth()->user());

View File

@ -424,7 +424,16 @@ class SingleController extends Controller
}
// @codeCoverageIgnoreEnd
$data = $request->getJournalData();
$data = $request->getJournalData();
$data['transactions'][0]['currency_id'] = $journal->transaction_currency_id;
if ($data['currency_id'] !== $journal->transaction_currency_id) {
// currency ID is changed by user. Update transaction:
$data['transactions'][0]['amount'] = $data['native_amount'];
$data['transactions'][0]['foreign_currency_id'] = $data['currency_id'];
$data['transactions'][0]['foreign_amount'] = $data['amount'];
}
$journal = $repository->update($journal, $data);
/** @var array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;

View File

@ -47,36 +47,56 @@ class JournalFormRequest extends Request
public function getJournalData()
{
$data = [
'type' => $this->get('what'), // type. can be 'deposit', 'withdrawal' or 'transfer'
'date' => $this->date('date'),
'tags' => explode(',', $this->string('tags')),
'currency_id' => $this->integer('amount_currency_id_amount'),
'type' => $this->get('what'), // type. can be 'deposit', 'withdrawal' or 'transfer'
'date' => $this->date('date'),
'tags' => explode(',', $this->string('tags')),
// all custom fields:
'interest_date' => $this->date('interest_date'),
'book_date' => $this->date('book_date'),
'process_date' => $this->date('process_date'),
'due_date' => $this->date('due_date'),
'payment_date' => $this->date('payment_date'),
'invoice_date' => $this->date('invoice_date'),
'internal_reference' => $this->string('internal_reference'),
'notes' => $this->string('notes'),
'interest_date' => $this->date('interest_date'),
'book_date' => $this->date('book_date'),
'process_date' => $this->date('process_date'),
'due_date' => $this->date('due_date'),
'payment_date' => $this->date('payment_date'),
'invoice_date' => $this->date('invoice_date'),
'internal_reference' => $this->string('internal_reference'),
'notes' => $this->string('notes'),
// transaction / journal data:
'description' => $this->string('description'),
'amount' => $this->string('amount'),
'budget_id' => $this->integer('budget_id'),
'category' => $this->string('category'),
'source_account_id' => $this->integer('source_account_id'),
'source_account_name' => $this->string('source_account_name'),
'destination_account_id' => $this->string('destination_account_id'),
'destination_account_name' => $this->string('destination_account_name'),
'piggy_bank_id' => $this->integer('piggy_bank_id'),
// journal data:
'description' => $this->string('description'),
'piggy_bank_id' => $this->integer('piggy_bank_id'),
'bill_id' => null,
'bill_name' => null,
// native amount and stuff like that:
'native_amount' => $this->string('native_amount'),
'source_amount' => $this->string('source_amount'),
'destination_amount' => $this->string('destination_amount'),
'currency_id' => $this->integer('amount_currency_id_amount'),
'amount' => $this->string('amount'),
'native_amount' => $this->string('native_amount'),
'source_amount' => $this->string('source_amount'),
'destination_amount' => $this->string('destination_amount'),
// transaction data:
'transactions' => [
[
'currency_id' => null,
'currency_code' => null,
'description' => null,
'amount' => $this->string('amount'),
'budget_id' => $this->integer('budget_id'),
'budget_name' => null,
'category_id' => null,
'category_name' => $this->string('category'),
'source_id' => $this->integer('source_account_id'),
'source_name' => $this->string('source_account_name'),
'destination_id' => $this->integer('destination_account_id'),
'destination_name' => $this->string('destination_account_name'),
'foreign_currency_id' => null,
'foreign_currency_code' => null,
'foreign_amount' => null,
'reconciled' => false,
'identifier' => 0,
],
],
];
return $data;

View File

@ -1,5 +1,26 @@
<?php
/**
* BelongsUser.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Rules;
use FireflyIII\Exceptions\FireflyException;

View File

@ -1,5 +1,26 @@
<?php
/**
* ValidTransactions.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Rules;
use FireflyIII\Models\Transaction;

View File

@ -1,5 +1,26 @@
<?php
/**
* breadcrumbs.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
return [
/*

View File

@ -1,5 +1,26 @@
<?php
/**
* google2fa.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
return [
/*

View File

@ -1,23 +0,0 @@
<?php
return [
/*
* Set the names of files you want to add to generated javascript.
* Otherwise all the files will be included.
*
* 'messages' => [
* 'validation',
* 'forum/thread',
* ],
*/
'messages' => [
'components',
'list',
],
/*
* The default path to use for the generated javascript.
*/
'path' => public_path('messages.js'),
];

View File

@ -1,5 +1,26 @@
<?php
/**
* 2018_01_01_000001_create_oauth_auth_codes_table.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

View File

@ -1,5 +1,26 @@
<?php
/**
* 2018_01_01_000002_create_oauth_access_tokens_table.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

View File

@ -1,5 +1,26 @@
<?php
/**
* 2018_01_01_000003_create_oauth_refresh_tokens_table.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

View File

@ -1,5 +1,26 @@
<?php
/**
* 2018_01_01_000004_create_oauth_clients_table.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

View File

@ -1,5 +1,26 @@
<?php
/**
* 2018_01_01_000005_create_oauth_personal_access_clients_table.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;