diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.php index 4b47b22714..c66f5421c5 100644 --- a/app/Http/Controllers/Transaction/ConvertController.php +++ b/app/Http/Controllers/Transaction/ConvertController.php @@ -64,30 +64,35 @@ class ConvertController extends Controller $positiveAmount = TransactionJournal::amountPositive($journal); $assetAccounts = ExpandedForm::makeSelectList($this->accounts->getActiveAccountsByType([AccountType::DEFAULT, AccountType::ASSET])); $sourceType = $journal->transactionType; + $subTitle = trans('firefly.convert_to_' . $destinationType->type, ['description' => $journal->description]); + $subTitleIcon = 'fa-exchange'; - $subTitle = trans('firefly.convert_to_' . $destinationType->type, ['description' => $journal->description]); - $subTitleIcon = 'fa-exchange'; - + // cannot convert to its own type. if ($sourceType->type === $destinationType->type) { Session::flash('info', trans('firefly.convert_is_already_type_' . $destinationType->type)); return redirect(route('transactions.show', [$journal->id])); } + + // cannot convert split. if ($journal->transactions()->count() > 2) { Session::flash('error', trans('firefly.cannot_convert_split_journl')); return redirect(route('transactions.show', [$journal->id])); } + + // get source and destination account: $sourceAccount = TransactionJournal::sourceAccountList($journal)->first(); $destinationAccount = TransactionJournal::destinationAccountList($journal)->first(); return view( - 'transactions.convert', compact( - 'sourceType', 'destinationType', 'journal', 'assetAccounts', - 'positiveAmount', 'sourceAccount', 'destinationAccount', 'sourceType', - 'subTitle', 'subTitleIcon' + 'transactions.convert', + compact( + 'sourceType', 'destinationType', 'journal', 'assetAccounts', + 'positiveAmount', 'sourceAccount', 'destinationAccount', 'sourceType', + 'subTitle', 'subTitleIcon' - ) + ) ); @@ -95,8 +100,35 @@ class ConvertController extends Controller // or to transfer requires } - public function submit(Request $request) + /** + * @param Request $request + * @param TransactionType $destinationType + * @param TransactionJournal $journal + */ + public function submit(Request $request, TransactionType $destinationType, TransactionJournal $journal) { + $sourceType = $journal->transactionType; + + // cannot convert to its own type. + if ($sourceType->type === $destinationType->type) { + Session::flash('info', trans('firefly.convert_is_already_type_' . $destinationType->type)); + + return redirect(route('transactions.show', [$journal->id])); + } + + // cannot convert split. + if ($journal->transactions()->count() > 2) { + Session::flash('error', trans('firefly.cannot_convert_split_journl')); + + return redirect(route('transactions.show', [$journal->id])); + } + + // try the conversion with the given data: + + + + + echo '
'; var_dump($request->all()); diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index b1d1d18a1a..1db69759c3 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -366,8 +366,23 @@ return [ 'convert_options_DepositWithdrawal' => 'Convert a deposit into a withdrawal', 'convert_options_TransferWithdrawal' => 'Convert a transfer into a withdrawal', 'convert_options_TransferDeposit' => 'Convert a transfer into a deposit', - - + 'transaction_journal_convert_options' => 'Convert this transaction', + 'convert_Withdrawal_to_deposit' => 'Convert this withdrawal to a deposit', + 'convert_Withdrawal_to_transfer' => 'Convert this withdrawal to a transfer', + 'convert_Deposit_to_withdrawal' => 'Convert this deposit to a withdrawal', + 'convert_Deposit_to_transfer' => 'Convert this deposit to a transfer', + 'convert_Transfer_to_deposit' => 'Convert this transfer to a deposit', + 'convert_Transfer_to_withdrawal' => 'Convert this transfer to a withdrawal', + 'convert_please_set_revenue_source' => 'Please pick the revenue account where the money will come from.', + 'convert_please_set_asset_destination' => 'Please pick the asset account where the money will go to.', + 'convert_please_set_expense_destination' => 'Please pick the expense account where the money will go to.', + 'convert_please_set_asset_source' => 'Please pick the asset account where the money will come from.', + 'convert_explanation_withdrawal_deposit' => 'If you convert this withdrawal into a deposit, :amount will be deposited into :sourceName instead of taken from it.', + 'convert_explanation_withdrawal_transfer' => 'If you convert this withdrawal into a transfer, :amount will be transferred from :sourceName to a new asset account, instead of being paid to :destinationName.', + 'convert_explanation_deposit_withdrawal' => 'If you convert this deposit into a withdrawal, :amount will be removed from :destinationName instead of added to it.', + 'convert_explanation_deposit_transfer' => 'If you convert this deposit into a transfer, :amount will be transferred from an asset account of your choice into :destinationName.', + 'convert_explanation_transfer_withdrawal' => 'If you convert this transfer into a withdrawal, :amount will go from :sourceName to a new destination as an expense, instead of to :destinationName as a transfer.', + 'convert_explanation_transfer_deposit' => 'If you convert this transfer into a deposit, :amount will be deposited into account :destinationName instead of being transferred there.', // create new stuff: 'create_new_withdrawal' => 'Create new withdrawal', 'create_new_deposit' => 'Create new deposit', diff --git a/resources/views/transactions/convert.twig b/resources/views/transactions/convert.twig index c7617480a6..c5c7c95429 100644 --- a/resources/views/transactions/convert.twig +++ b/resources/views/transactions/convert.twig @@ -40,13 +40,19 @@ {# ONE #} {% if sourceType.type == 'Withdrawal' and destinationType.type == 'Deposit' %}- If you convert this withdrawal into a deposit, {{ positiveAmount|formatAmount }} - will be deposited into {{ sourceAccount.name }} - instead of taken from it. + {{ trans('firefly.convert_explanation_withdrawal_deposit', + { + amount: positiveAmount|formatAmount, + sourceRoute: route('accounts.show', [sourceAccount.id]), + sourceName: sourceAccount.name, + destinationRoute: route('accounts.show', [destinationAccount.id]), + destinationName: destinationAccount.name, + })|raw + }}
- Please pick the revenue account where the money will come from. + {{ 'convert_please_set_revenue_source'|_ }}
@@ -56,15 +62,21 @@ {# TWO #} {% if sourceType.type == 'Withdrawal' and destinationType.type == 'Transfer' %}- If you convert this withdrawal into a transfer, {{ positiveAmount|formatAmount }} - will be transferred from {{ sourceAccount.name }} - to a new asset account, instead of being paid to - {{ destinationAccount.name }}. + {{ trans('firefly.convert_explanation_withdrawal_transfer', + { + amount: positiveAmount|formatAmount, + sourceRoute: route('accounts.show', [sourceAccount.id]), + sourceName: sourceAccount.name, + destinationRoute: route('accounts.show', [destinationAccount.id]), + destinationName: destinationAccount.name, + })|raw + }}
- Please pick the asset account where the money will go to. + {{ 'convert_please_set_asset_destination'|_ }} +
{{ ExpandedForm.select('destination_account_asset', assetAccounts) }} @@ -76,14 +88,21 @@ {% if sourceType.type == 'Deposit' and destinationType.type == 'Withdrawal' %}- If you convert this deposit into a withdrawal, {{ positiveAmount|formatAmount }} - will be removed from {{ destinationAccount.name }} - instead of added to it. + {{ trans('firefly.convert_explanation_deposit_withdrawal', + { + amount: positiveAmount|formatAmount, + sourceRoute: route('accounts.show', [sourceAccount.id]), + sourceName: sourceAccount.name, + destinationRoute: route('accounts.show', [destinationAccount.id]), + destinationName: destinationAccount.name, + })|raw + }}
- Please pick the expense account where the money will go to. + {{ 'convert_please_set_expense_destination'|_ }} +
{{ ExpandedForm.text('destination_account_expense', destinationAccount.name) }} @@ -95,14 +114,21 @@- If you convert this deposit into a transfer, {{ positiveAmount|formatAmount }} will be transferred - from an asset account of your choice into - {{ destinationAccount.name }}. + {{ trans('firefly.convert_explanation_deposit_transfer', + { + amount: positiveAmount|formatAmount, + sourceRoute: route('accounts.show', [sourceAccount.id]), + sourceName: sourceAccount.name, + destinationRoute: route('accounts.show', [destinationAccount.id]), + destinationName: destinationAccount.name, + })|raw + }}
- Please pick the asset account where the money will come from. + {{ 'convert_please_set_asset_source'|_ }} +
@@ -114,17 +140,21 @@- If you convert this transfer into a withdrawal, {{ positiveAmount|formatAmount }} - will go from {{ sourceAccount.name }} - to a new destination as an expense, instead of to - {{ destinationAccount.name }} - as a transfer. + {{ trans('firefly.convert_explanation_transfer_withdrawal', + { + amount: positiveAmount|formatAmount, + sourceRoute: route('accounts.show', [sourceAccount.id]), + sourceName: sourceAccount.name, + destinationRoute: route('accounts.show', [destinationAccount.id]), + destinationName: destinationAccount.name, + })|raw + }}
- Please pick the expense account where the money will go to. + {{ 'convert_please_set_expense_destination'|_ }}
@@ -135,17 +165,24 @@ {# SIX #} {% if sourceType.type == 'Transfer' and destinationType.type == 'Deposit' %} +- If you convert this transfer into a deposit, {{ positiveAmount|formatAmount }} - will be deposited into account {{ destinationAccount.name }} - instead of being transferred there. + {{ trans('firefly.convert_explanation_transfer_deposit', + { + amount: positiveAmount|formatAmount, + sourceRoute: route('accounts.show', [sourceAccount.id]), + sourceName: sourceAccount.name, + destinationRoute: route('accounts.show', [destinationAccount.id]), + destinationName: destinationAccount.name, + })|raw + }}
- Please pick the revenue account where the money will come from. + {{ 'convert_please_set_revenue_source'|_ }}
diff --git a/resources/views/transactions/show.twig b/resources/views/transactions/show.twig index 5a146f26be..f4928d89f4 100644 --- a/resources/views/transactions/show.twig +++ b/resources/views/transactions/show.twig @@ -218,7 +218,7 @@ {% endif %} @@ -226,7 +226,7 @@ {% endif %} @@ -235,7 +235,7 @@ {% endif %} @@ -251,7 +251,7 @@-Transactions
+{{ 'transactions'|_ }}