Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
More code for split and small bug fix in attachment helper.
James Cole4ec6bcc8c733
diff --git a/app/Crud/Split/Journal.php b/app/Crud/Split/Journal.phpindex 9d742e7ff5..9315ba9193 100644--- a/app/Crud/Split/Journal.php+++ b/app/Crud/Split/Journal.php@@ -85,6 +85,7 @@ class Journal implements JournalInterface'account_id' => $sourceAccount->id,'transaction_journal_id' => $journal->id,'amount' => $transaction['amount'] * -1,+ 'description' => $transaction['description'],]);@@ -94,6 +95,7 @@ class Journal implements JournalInterface'account_id' => $destinationAccount->id,'transaction_journal_id' => $journal->id,'amount' => $transaction['amount'],+ 'description' => $transaction['description'],]);@@ -133,8 +135,8 @@ class Journal implements JournalInterfacelist($sourceAccount, $destinationAccount) = $this->storeDepositAccounts($transaction);break;case TransactionType::TRANSFER:- $sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['account_from_id'])->first();- $destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['account_to_id'])->first();+ $sourceAccount = Account::where('user_id', $this->user->id)->where('id', $transaction['source_account_id'])->first();+ $destinationAccount = Account::where('user_id', $this->user->id)->where('id', $transaction['destination_account_id'])->first();break;default:throw new FireflyException('Cannot handle ' . e($type));@@ -150,7 +152,7 @@ class Journal implements JournalInterface*/private function storeDepositAccounts(array $data): array{- $destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['account_destination_id'])->first(['accounts.*']);+ $destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first(['accounts.*']);if (strlen($data['source_account_name']) > 0) {$fromType = AccountType::where('type', 'Revenue account')->first();diff --git a/app/Helpers/Attachments/AttachmentHelper.php b/app/Helpers/Attachments/AttachmentHelper.phpindex 6fc6e3af0e..3433584545 100644--- a/app/Helpers/Attachments/AttachmentHelper.php+++ b/app/Helpers/Attachments/AttachmentHelper.php@@ -251,6 +251,7 @@ class AttachmentHelper implements AttachmentHelperInterface$this->processFile($entry, $model);}}+ return true;}diff --git a/app/Http/Controllers/Transaction/SplitController.php b/app/Http/Controllers/Transaction/SplitController.phpindex 6a677f5b61..71eabcd273 100644--- a/app/Http/Controllers/Transaction/SplitController.php+++ b/app/Http/Controllers/Transaction/SplitController.php@@ -18,6 +18,7 @@ use FireflyIII\Http\Requests\SplitJournalFormRequest;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;+use Log;use Session;/**@@ -40,8 +41,9 @@ class SplitController extends Controller/** @var BudgetRepositoryInterface $budgetRepository */$budgetRepository = app(BudgetRepositoryInterface::class);+// expect data to be in session or in post?- $journalData = session('temporary_split_data');+ $journalData = session('temporary_split_data');$currencies = ExpandedForm::makeSelectList($currencyRepository->get());$assetAccounts = ExpandedForm::makeSelectList($accountRepository->getAccounts(['Default account', 'Asset account']));$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());@@ -49,6 +51,9 @@ class SplitController extends Controllerthrow new FireflyException('Could not find transaction data in your session. Please go back and try again.'); // translate me.}+ Log::debug('Journal data', $journalData);++return view('split.journals.from-store', compact('currencies', 'assetAccounts', 'budgets'))->with('data', $journalData);diff --git a/app/Http/Requests/JournalFormRequest.php b/app/Http/Requests/JournalFormRequest.phpindex 5b5a7905d7..8b8886b76b 100644--- a/app/Http/Requests/JournalFormRequest.php+++ b/app/Http/Requests/JournalFormRequest.php@@ -39,7 +39,7 @@ class JournalFormRequest extends Request'description' => $this->get('description'),'source_account_id' => intval($this->get('source_account_id')),'source_account_name' => $this->get('source_account_name') ?? '',- 'account_destination_id' => intval($this->get('account_destination_id')),+ 'destination_account_id' => intval($this->get('destination_account_id')),'destination_account_name' => $this->get('destination_account_name') ?? '','amount' => round($this->get('amount'), 2),'user' => Auth::user()->id,diff --git a/app/Http/Requests/SplitJournalFormRequest.php b/app/Http/Requests/SplitJournalFormRequest.phpindex 3cb66f26f8..fc16ae7f87 100644--- a/app/Http/Requests/SplitJournalFormRequest.php+++ b/app/Http/Requests/SplitJournalFormRequest.php@@ -35,25 +35,28 @@ class SplitJournalFormRequest extends Requestpublic function getSplitData(): array{$data = [- 'description' => $this->get('journal_description'),- 'currency_id' => intval($this->get('currency')),- 'source_account_id' => intval($this->get('source_account_id')),- 'date' => new Carbon($this->get('date')),- 'what' => $this->get('what'),- 'interest_date' => $this->get('interest_date') ? new Carbon($this->get('interest_date')) : null,- 'book_date' => $this->get('book_date') ? new Carbon($this->get('book_date')) : null,- 'process_date' => $this->get('process_date') ? new Carbon($this->get('process_date')) : null,- 'transactions' => [],+ 'description' => $this->get('journal_description'),+ 'currency_id' => intval($this->get('currency')),+ 'source_account_id' => intval($this->get('source_account_id')),+ 'source_account_name' => $this->get('source_account_name'),+ 'date' => new Carbon($this->get('date')),+ 'what' => $this->get('what'),+ 'interest_date' => $this->get('interest_date') ? new Carbon($this->get('interest_date')) : null,+ 'book_date' => $this->get('book_date') ? new Carbon($this->get('book_date')) : null,+ 'process_date' => $this->get('process_date') ? new Carbon($this->get('process_date')) : null,+ 'transactions' => [],];// description is leading because it is one of the mandatory fields.foreach ($this->get('description') as $index => $description) {$transaction = ['description' => $description,'amount' => round($this->get('amount')[$index], 2),- 'budget_id' => $this->get('budget')[$index] ? $this->get('budget')[$index] : 0,+ 'budget_id' => $this->get('budget')[$index] ? intval($this->get('budget')[$index]) : 0,'category' => $this->get('category')[$index] ?? '','source_account_id' => intval($this->get('source_account_id')),- 'destination_account_name' => $this->get('destination_account_name')[$index] ?? ''+ 'source_account_name' => $this->get('source_account_name'),+ 'destination_account_id' => $this->get('destination_account_id')[$index] ? intval($this->get('destination_account_id')[$index]) : 0,+ 'destination_account_name' => $this->get('destination_account_name')[$index] ?? '',];$data['transactions'][] = $transaction;}@@ -70,12 +73,14 @@ class SplitJournalFormRequest extends Request'journal_description' => 'required|between:1,255','currency' => 'required|exists:transaction_currencies,id','source_account_id' => 'numeric|belongsToUser:accounts,id',+ 'source_account_name.*' => 'between:1,255','what' => 'required|in:withdrawal,deposit,transfer','date' => 'required|date','interest_date' => 'date','book_date' => 'date','process_date' => 'date','description.*' => 'required|between:1,255',+ 'destination_account_id.*' => 'numeric|belongsToUser:accounts,id','destination_account_name.*' => 'between:1,255','amount.*' => 'required|numeric','budget.*' => 'belongsToUser:budgets,id',diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.phpindex c539eee3bc..7e17636398 100644--- a/app/Repositories/Journal/JournalRepository.php+++ b/app/Repositories/Journal/JournalRepository.php@@ -431,7 +431,7 @@ class JournalRepository implements JournalRepositoryInterface*/protected function storeDepositAccounts(array $data): array{- $destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['account_destination_id'])->first(['accounts.*']);+ $destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first(['accounts.*']);if (strlen($data['source_account_name']) > 0) {$fromType = AccountType::where('type', 'Revenue account')->first();diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.phpindex bf4ec69932..45131e047b 100644--- a/database/seeds/DatabaseSeeder.php+++ b/database/seeds/DatabaseSeeder.php@@ -26,6 +26,10 @@ class DatabaseSeeder extends Seederif (App::environment() == 'testing' || App::environment() == 'local') {$this->call('TestDataSeeder');}+ // set up basic test data (as little as possible):+ if (App::environment() == 'split') {+ $this->call('SplitDataSeeder');+ }}}diff --git a/database/seeds/SplitDataSeeder.php b/database/seeds/SplitDataSeeder.phpnew file mode 100644index 0000000000..623ca15178--- /dev/null+++ b/database/seeds/SplitDataSeeder.php@@ -0,0 +1,55 @@+<?php+/**+ * SplitDataSeeder.php+ * Copyright (C) 2016 [email protected]+ *+ * This software may be modified and distributed under the terms+ * of the MIT license. See the LICENSE file for details.+ */++declare(strict_types = 1);+/**+ * SplitDataSeeder.php+ * Copyright (C) 2016 [email protected]+ *+ * This software may be modified and distributed under the terms+ * of the MIT license. See the LICENSE file for details.+ */++use FireflyIII\Support\Migration\TestData;+use Illuminate\Database\Seeder;++/**+ * Class SplitDataSeeder+ */+class SplitDataSeeder extends Seeder+{+ /**+ * TestDataSeeder constructor.+ */+ public function __construct()+ {+++ }++ /**+ * Run the database seeds.+ *+ * @return void+ */+ public function run()+ {+ // start by creating all users:+ // method will return the first user.+ $user = TestData::createUsers();+++ // create all kinds of static data:+ TestData::createAssetAccounts($user);+ TestData::createBudgets($user);+ TestData::createCategories($user);+ TestData::createExpenseAccounts($user);+ TestData::createRevenueAccounts($user);+ }+}diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex cf87d615bf..71347147b3 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -810,6 +810,14 @@ return ['split_intro_two_withdrawal' => 'It means that the amount of money you\'ve spent is divided between several destination expense accounts, budgets or categories.','split_intro_three_withdrawal' => 'For example: you could split your :total groceries so you pay :split_one from your "daily groceries" budget and :split_two from your "cigarettes" budget.','split_table_intro_withdrawal' => 'Split your withdrawal in as many things as you want. By default the transaction will not split, there is just one entry. Add as many splits as you want to, below. Remember that you should not deviate from your total amount. If you do, Firefly will warn you but not correct you.',- 'add_another_split' => 'Add another split','store_splitted_withdrawal' => 'Store splitted withdrawal',++ 'split_title_deposit' => 'Split your new deposit',+ 'split_intro_one_deposit' => 'Firefly supports the "splitting" of a deposit.',+ 'split_intro_two_deposit' => 'It means that the amount of money you\'ve earned is divided between several source revenue accounts or categories.',+ 'split_intro_three_deposit' => 'For example: you could split your :total salary so you get :split_one as your base salary and :split_two as a reimbursment for expenses made.',+ 'split_table_intro_deposit' => 'Split your deposit in as many things as you want. By default the transaction will not split, there is just one entry. Add as many splits as you want to, below. Remember that you should not deviate from your total amount. If you do, Firefly will warn you but not correct you.',+ 'store_splitted_deposit' => 'Store splitted deposit',+ 'add_another_split' => 'Add another split',+];diff --git a/resources/views/split/journals/from-store.twig b/resources/views/split/journals/from-store.twigindex 8226468056..12cf3aad19 100644--- a/resources/views/split/journals/from-store.twig+++ b/resources/views/split/journals/from-store.twig@@ -24,7 +24,11 @@{{ ('split_intro_two_'~data.what)|_ }}</p><p>- {{ trans(('firefly.split_intro_three_'~data.what), {total: 20|formatAmount, split_one: 15|formatAmount, split_two: 5|formatAmount})|raw }}+ {% if data.what =='deposit' %}+ {{ trans(('firefly.split_intro_three_'~data.what), {total: 500|formatAmount, split_one: 425|formatAmount, split_two: 75|formatAmount})|raw }}+ {% else %}+ {{ trans(('firefly.split_intro_three_'~data.what), {total: 20|formatAmount, split_one: 15|formatAmount, split_two: 5|formatAmount})|raw }}+ {% endif %}</p><!--<p>@@ -64,8 +68,13 @@{{ ExpandedForm.staticText('asset_source_account', assetAccounts[data.source_account_id]) }}<input type="hidden" name="source_account_id" value="{{ data.source_account_id }}"/>{% endif %}- <!-- show static destination if deposit or transfer -->- {% if data.what == 'deposit' or data.what == 'transfer' %}+ <!-- show static source if deposit: -->+ {% if data.what == 'deposit' %}+ {{ ExpandedForm.staticText('revenue_account', data.source_account_name) }}+ <input type="hidden" name="source_account_name" value="{{ data.source_account_name }}"/>+ {% endif %}+ <!-- show static destination if transfer -->+ {% if data.what == 'transfer' %}{{ ExpandedForm.staticText('asset_destination_account', assetAccounts[data.destination_account_id]) }}<input type="hidden" name="destination_account_id" value="{{ data.destination_account_id }}"/>{% endif %}@@ -113,11 +122,14 @@<th>{{ trans('list.split_number') }}</th><th>{{ trans('list.description') }}</th><!-- split the source of a deposit -->+ <!--{% if data.what == 'deposit' %}<th>{{ trans('list.source') }}</th>{% endif %}+ --><!-- split where a withdrawal is going -->- {% if data.what == 'withdrawal' %}+ <!-- split where a deposit is going -->+ {% if data.what == 'withdrawal' or data.what == 'deposit' %}<th>{{ trans('list.destination') }}</th>{% endif %}<th>{{ trans('list.amount') }}</th>@@ -134,16 +146,23 @@<tr class="initial-row"><td class="count">#1</td><td>{{ Form.input('text', 'description[]', data.description, {class: 'form-control'}) }}</td>- {% if data.what == 'deposit' %}++ <!-- withdrawal has several destination names. -->+ {% if data.what == 'withdrawal' %}<td>- {{ Form.input('text', 'source_account_name[]', data.source_account_name, {class: 'form-control'}) }}+ {{ Form.input('text', 'destination_account_name[]', data.destination_account_name, {class: 'form-control'}) }}</td>{% endif %}- {% if data.what == 'withdrawal' %}++ <!-- deposit has several destination id's -->+ {% if data.what == 'deposit' %}<td>- {{ Form.input('text', 'destination_account_name[]', data.destination_account_name, {class: 'form-control'}) }}+ {{ Form.select('destination_account_id[]', assetAccounts, data.destination_account_id, {class: 'form-control'}) }}</td>{% endif %}+++<td style="width:10%;">{{ Form.input('number', 'amount[]', data.amount, {class: 'form-control', autocomplete: 'off', step: 'any', min:'0.01'}) }}</td>