mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 22:48:18 +00:00
This should fix #280
This commit is contained in:
@@ -110,13 +110,40 @@ class MassController extends Controller
|
||||
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
|
||||
$accountList = ExpandedForm::makeSelectList($crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]));
|
||||
|
||||
// skip transactions that have multiple destinations
|
||||
// or multiple sources:
|
||||
$filtered = new Collection;
|
||||
$messages = [];
|
||||
/**
|
||||
* @var int $index
|
||||
* @var TransactionJournal $journal
|
||||
*/
|
||||
foreach ($journals as $index => $journal) {
|
||||
$sources = TransactionJournal::sourceAccountList($journal);
|
||||
$destinations = TransactionJournal::destinationAccountList($journal);
|
||||
if ($sources->count() > 1) {
|
||||
$messages[] = trans('firefly.cannot_edit_multiple_source', ['description' => $journal->description, 'id' => $journal->id]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($destinations->count() > 1) {
|
||||
$messages[] = trans('firefly.cannot_edit_multiple_dest', ['description' => $journal->description, 'id' => $journal->id]);
|
||||
continue;
|
||||
}
|
||||
$filtered->push($journal);
|
||||
}
|
||||
|
||||
if (count($messages)) {
|
||||
Session::flash('info', $messages);
|
||||
}
|
||||
|
||||
// put previous url in session
|
||||
Session::put('transactions.mass-edit.url', URL::previous());
|
||||
Session::flash('gaEventCategory', 'transactions');
|
||||
Session::flash('gaEventAction', 'mass-edit');
|
||||
|
||||
// set some values to be used in the edit routine:
|
||||
$journals->each(
|
||||
$filtered->each(
|
||||
function (TransactionJournal $journal) {
|
||||
$journal->amount = TransactionJournal::amountPositive($journal);
|
||||
$sources = TransactionJournal::sourceAccountList($journal);
|
||||
@@ -133,6 +160,12 @@ class MassController extends Controller
|
||||
}
|
||||
);
|
||||
|
||||
if ($filtered->count() === 0) {
|
||||
Session::flash('error', trans('firefly.no_edit_multiple_left'));
|
||||
}
|
||||
|
||||
$journals = $filtered;
|
||||
|
||||
return view('transactions.mass-edit', compact('journals', 'subTitle', 'accountList'));
|
||||
}
|
||||
|
||||
@@ -151,33 +184,26 @@ class MassController extends Controller
|
||||
$journal = $repository->find(intval($journalId));
|
||||
if ($journal) {
|
||||
// get optional fields:
|
||||
$what = strtolower(TransactionJournal::transactionTypeStr($journal));
|
||||
$sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0;
|
||||
$destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0;
|
||||
$expenseAccount = $request->get('expense_account')[$journal->id] ?? '';
|
||||
$revenueAccount = $request->get('revenue_account')[$journal->id] ?? '';
|
||||
$budgetId = $journal->budgets->first() ? $journal->budgets->first()->id : 0;
|
||||
$category = $journal->categories->first() ? $journal->categories->first()->name : '';
|
||||
$tags = $journal->tags->pluck('tag')->toArray();
|
||||
$what = strtolower(TransactionJournal::transactionTypeStr($journal));
|
||||
|
||||
// for a deposit, the 'account_id' is the account the money is deposited on.
|
||||
// needs a better way of handling.
|
||||
// more uniform source/destination field names
|
||||
$accountId = $sourceAccountId;
|
||||
if ($what == 'deposit') {
|
||||
$accountId = $destAccountId;
|
||||
}
|
||||
$sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0;
|
||||
$sourceAccountName = $request->get('source_account_name')[$journal->id] ?? '';
|
||||
$destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0;
|
||||
$destAccountName = $request->get('destination_account_name')[$journal->id] ?? '';
|
||||
|
||||
$budgetId = $journal->budgets->first() ? $journal->budgets->first()->id : 0;
|
||||
$category = $journal->categories->first() ? $journal->categories->first()->name : '';
|
||||
$tags = $journal->tags->pluck('tag')->toArray();
|
||||
|
||||
// build data array
|
||||
$data = [
|
||||
'id' => $journal->id,
|
||||
'what' => $what,
|
||||
'description' => $request->get('description')[$journal->id],
|
||||
'account_id' => intval($accountId),
|
||||
'account_from_id' => intval($sourceAccountId),
|
||||
'account_to_id' => intval($destAccountId),
|
||||
'expense_account' => $expenseAccount,
|
||||
'revenue_account' => $revenueAccount,
|
||||
'source_account_id' => intval($sourceAccountId),
|
||||
'source_account_name' => intval($destAccountId),
|
||||
'destination_account_id' => $sourceAccountName,
|
||||
'destination_account_name' => $destAccountName,
|
||||
'amount' => round($request->get('amount')[$journal->id], 4),
|
||||
'user' => Auth::user()->id,
|
||||
'amount_currency_id_amount' => intval($request->get('amount_currency_id_amount_' . $journal->id)),
|
||||
|
@@ -749,6 +749,9 @@ return [
|
||||
'split_this_withdrawal' => 'Split this withdrawal',
|
||||
'split_this_deposit' => 'Split this deposit',
|
||||
'split_this_transfer' => 'Split this transfer',
|
||||
'cannot_edit_multiple_source' => 'You cannot edit splitted transaction #:id with description ":description" because it contains multiple source accounts.',
|
||||
'cannot_edit_multiple_dest' => 'You cannot edit splitted transaction #:id with description ":description" because it contains multiple destination accounts.',
|
||||
'no_edit_multiple_left' => 'You have selected no valid transactions to edit.',
|
||||
|
||||
// import
|
||||
'configuration_file_help' => 'If you have previously imported data into Firefly III, you may have a configuration file, which will pre-set configuration values for you.',
|
||||
|
@@ -56,24 +56,24 @@
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<!-- SOURCE ACCOUNT FOR TRANSFER OR WITHDRAWAL -->
|
||||
<!-- SOURCE ACCOUNT ID FOR TRANSFER OR WITHDRAWAL -->
|
||||
{% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == 'Withdrawal' %}
|
||||
{{ Form.select('source_account_id['~journal.id~']', accountList, journal.source_account_id, {'class': 'form-control'}) }}
|
||||
{% else %}
|
||||
<!-- if is income -->
|
||||
{{ Form.input('text', 'revenue_account['~journal.id~']', journal.source_account_name, {'class': 'form-control', 'placeholder': trans('form.revenue_account')}) }}
|
||||
<!-- SOURCE ACCOUNT NAME FOR DEPOSIT -->
|
||||
{{ Form.input('text', 'source_account_name['~journal.id~']', journal.source_account_name, {'class': 'form-control', 'placeholder': trans('form.revenue_account')}) }}
|
||||
{% endif %}
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
{% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == 'Deposit' %}
|
||||
<!-- is is transfer or income -->
|
||||
<!-- DESTINATION ACCOUNT NAME FOR TRANSFER AND DEPOSIT -->
|
||||
{{ Form.select('destination_account_id['~journal.id~']', accountList, journal.destination_account_id, {'class': 'form-control'}) }}
|
||||
{% else %}
|
||||
<!-- if is expense -->
|
||||
<!-- DESTINATION ACCOUNT NAME FOR EXPENSE-->
|
||||
|
||||
{{ Form.input('text', 'expense_account['~journal.id~']', journal.destination_account_name, {'class': 'form-control', 'placeholder': trans('form.expense_account')}) }}
|
||||
{{ Form.input('text', 'destination_account_name['~journal.id~']', journal.destination_account_name, {'class': 'form-control', 'placeholder': trans('form.expense_account')}) }}
|
||||
{% endif %}
|
||||
|
||||
</td>
|
||||
@@ -83,8 +83,11 @@
|
||||
</table>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<input type="submit" name="submit" value="{{ trans('form.update_all_journals') }}" class="btn btn-danger pull-right"/>
|
||||
{% if journals.count > 0 %}
|
||||
<input type="submit" name="submit" value="{{ trans('form.update_all_journals') }}" class="btn btn-danger pull-right"/>
|
||||
{% endif %}
|
||||
<a href="{{ route('index') }}" class="btn-default btn">{{ trans('form.cancel') }}</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user