mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
More code for split and small bug fix in attachment helper.
This commit is contained in:
parent
11ea4b6d47
commit
4ec6bcc8c7
@ -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 JournalInterface
|
||||
list($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();
|
||||
|
@ -251,6 +251,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
$this->processFile($entry, $model);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 Controller
|
||||
throw 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);
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
@ -35,25 +35,28 @@ class SplitJournalFormRequest extends Request
|
||||
public 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',
|
||||
|
@ -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();
|
||||
|
@ -26,6 +26,10 @@ class DatabaseSeeder extends Seeder
|
||||
if (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');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
55
database/seeds/SplitDataSeeder.php
Normal file
55
database/seeds/SplitDataSeeder.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* SplitDataSeeder.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
@ -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',
|
||||
|
||||
];
|
||||
|
@ -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' %}
|
||||
<td>
|
||||
{{ Form.input('text', 'source_account_name[]', data.source_account_name, {class: 'form-control'}) }}
|
||||
</td>
|
||||
{% endif %}
|
||||
|
||||
<!-- withdrawal has several destination names. -->
|
||||
{% if data.what == 'withdrawal' %}
|
||||
<td>
|
||||
{{ Form.input('text', 'destination_account_name[]', data.destination_account_name, {class: 'form-control'}) }}
|
||||
</td>
|
||||
{% endif %}
|
||||
|
||||
<!-- deposit has several destination id's -->
|
||||
{% if data.what == 'deposit' %}
|
||||
<td>
|
||||
{{ 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>
|
||||
|
Loading…
Reference in New Issue
Block a user