mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 14:58:40 +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');
|
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
|
||||||
$accountList = ExpandedForm::makeSelectList($crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]));
|
$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
|
// put previous url in session
|
||||||
Session::put('transactions.mass-edit.url', URL::previous());
|
Session::put('transactions.mass-edit.url', URL::previous());
|
||||||
Session::flash('gaEventCategory', 'transactions');
|
Session::flash('gaEventCategory', 'transactions');
|
||||||
Session::flash('gaEventAction', 'mass-edit');
|
Session::flash('gaEventAction', 'mass-edit');
|
||||||
|
|
||||||
// set some values to be used in the edit routine:
|
// set some values to be used in the edit routine:
|
||||||
$journals->each(
|
$filtered->each(
|
||||||
function (TransactionJournal $journal) {
|
function (TransactionJournal $journal) {
|
||||||
$journal->amount = TransactionJournal::amountPositive($journal);
|
$journal->amount = TransactionJournal::amountPositive($journal);
|
||||||
$sources = TransactionJournal::sourceAccountList($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'));
|
return view('transactions.mass-edit', compact('journals', 'subTitle', 'accountList'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,32 +185,25 @@ class MassController extends Controller
|
|||||||
if ($journal) {
|
if ($journal) {
|
||||||
// get optional fields:
|
// get optional fields:
|
||||||
$what = strtolower(TransactionJournal::transactionTypeStr($journal));
|
$what = strtolower(TransactionJournal::transactionTypeStr($journal));
|
||||||
|
|
||||||
$sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0;
|
$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;
|
$destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0;
|
||||||
$expenseAccount = $request->get('expense_account')[$journal->id] ?? '';
|
$destAccountName = $request->get('destination_account_name')[$journal->id] ?? '';
|
||||||
$revenueAccount = $request->get('revenue_account')[$journal->id] ?? '';
|
|
||||||
$budgetId = $journal->budgets->first() ? $journal->budgets->first()->id : 0;
|
$budgetId = $journal->budgets->first() ? $journal->budgets->first()->id : 0;
|
||||||
$category = $journal->categories->first() ? $journal->categories->first()->name : '';
|
$category = $journal->categories->first() ? $journal->categories->first()->name : '';
|
||||||
$tags = $journal->tags->pluck('tag')->toArray();
|
$tags = $journal->tags->pluck('tag')->toArray();
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// build data array
|
// build data array
|
||||||
$data = [
|
$data = [
|
||||||
'id' => $journal->id,
|
'id' => $journal->id,
|
||||||
'what' => $what,
|
'what' => $what,
|
||||||
'description' => $request->get('description')[$journal->id],
|
'description' => $request->get('description')[$journal->id],
|
||||||
'account_id' => intval($accountId),
|
'source_account_id' => intval($sourceAccountId),
|
||||||
'account_from_id' => intval($sourceAccountId),
|
'source_account_name' => intval($destAccountId),
|
||||||
'account_to_id' => intval($destAccountId),
|
'destination_account_id' => $sourceAccountName,
|
||||||
'expense_account' => $expenseAccount,
|
'destination_account_name' => $destAccountName,
|
||||||
'revenue_account' => $revenueAccount,
|
|
||||||
'amount' => round($request->get('amount')[$journal->id], 4),
|
'amount' => round($request->get('amount')[$journal->id], 4),
|
||||||
'user' => Auth::user()->id,
|
'user' => Auth::user()->id,
|
||||||
'amount_currency_id_amount' => intval($request->get('amount_currency_id_amount_' . $journal->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_withdrawal' => 'Split this withdrawal',
|
||||||
'split_this_deposit' => 'Split this deposit',
|
'split_this_deposit' => 'Split this deposit',
|
||||||
'split_this_transfer' => 'Split this transfer',
|
'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
|
// 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.',
|
'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>
|
||||||
<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' %}
|
{% 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'}) }}
|
{{ Form.select('source_account_id['~journal.id~']', accountList, journal.source_account_id, {'class': 'form-control'}) }}
|
||||||
{% else %}
|
{% else %}
|
||||||
<!-- if is income -->
|
<!-- SOURCE ACCOUNT NAME FOR DEPOSIT -->
|
||||||
{{ Form.input('text', 'revenue_account['~journal.id~']', journal.source_account_name, {'class': 'form-control', 'placeholder': trans('form.revenue_account')}) }}
|
{{ Form.input('text', 'source_account_name['~journal.id~']', journal.source_account_name, {'class': 'form-control', 'placeholder': trans('form.revenue_account')}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
||||||
{% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == 'Deposit' %}
|
{% 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'}) }}
|
{{ Form.select('destination_account_id['~journal.id~']', accountList, journal.destination_account_id, {'class': 'form-control'}) }}
|
||||||
{% else %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
@@ -83,8 +83,11 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-footer">
|
<div class="box-footer">
|
||||||
|
{% if journals.count > 0 %}
|
||||||
<input type="submit" name="submit" value="{{ trans('form.update_all_journals') }}" class="btn btn-danger pull-right"/>
|
<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>
|
<a href="{{ route('index') }}" class="btn-default btn">{{ trans('form.cancel') }}</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user