diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.php new file mode 100644 index 0000000000..4b47b22714 --- /dev/null +++ b/app/Http/Controllers/Transaction/ConvertController.php @@ -0,0 +1,108 @@ +middleware( + function ($request, $next) { + $this->accounts = app(AccountRepositoryInterface::class); + + View::share('title', trans('firefly.transactions')); + View::share('mainTitleIcon', 'fa-exchange'); + + return $next($request); + } + ); + } + + /** + * @param TransactionType $destinationType + * @param TransactionJournal $journal + * + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View + */ + public function convert(TransactionType $destinationType, TransactionJournal $journal) + { + $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'; + + if ($sourceType->type === $destinationType->type) { + Session::flash('info', trans('firefly.convert_is_already_type_' . $destinationType->type)); + + return redirect(route('transactions.show', [$journal->id])); + } + if ($journal->transactions()->count() > 2) { + Session::flash('error', trans('firefly.cannot_convert_split_journl')); + + return redirect(route('transactions.show', [$journal->id])); + } + $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' + + ) + ); + + + // convert withdrawal to deposit requires a new source account () + // or to transfer requires + } + + public function submit(Request $request) + { + echo '
'; + + var_dump($request->all()); + + + exit; + } + +} \ No newline at end of file diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 44c4fc707e..9de3b720ac 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -25,6 +25,7 @@ use FireflyIII\Models\RuleGroup; use FireflyIII\Models\Tag; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Models\TransactionType; use FireflyIII\User; /** @@ -595,13 +596,24 @@ Breadcrumbs::register( Breadcrumbs::register( 'transactions.show', function (BreadCrumbGenerator $breadcrumbs, TransactionJournal $journal) { - $what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type); + $what = strtolower($journal->transactionType->type); $breadcrumbs->parent('transactions.index', $what); $breadcrumbs->push($journal->description, route('transactions.show', [$journal->id])); - } ); +Breadcrumbs::register( + 'transactions.convert', function (BreadCrumbGenerator $breadcrumbs, TransactionType $destinationType, TransactionJournal $journal) { + + $breadcrumbs->parent('transactions.show', $journal); + $breadcrumbs->push( + trans('firefly.convert_to_' . $destinationType->type, ['description' => $journal->description]), + route('transactions.convert', [strtolower($destinationType->type), $journal->id]) + ); +} +); + + /** * SPLIT */ diff --git a/app/Models/TransactionType.php b/app/Models/TransactionType.php index 84a1da7ccf..51a912ca12 100644 --- a/app/Models/TransactionType.php +++ b/app/Models/TransactionType.php @@ -15,6 +15,7 @@ namespace FireflyIII\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * FireflyIII\Models\TransactionType @@ -43,6 +44,25 @@ class TransactionType extends Model protected $dates = ['created_at', 'updated_at', 'deleted_at']; + /** + * @param string $type + * + * @return Model|null|static + */ + public static function routeBinder(string $type) + { + if (!auth()->check()) { + throw new NotFoundHttpException; + } + $transactionType = self::where('type', $type)->first(); + if (!is_null($transactionType)) { + return $transactionType; + } + throw new NotFoundHttpException; + + } + + /** * @return bool */ diff --git a/config/firefly.php b/config/firefly.php index 9d5113793b..69b5e13029 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -137,6 +137,7 @@ return [ 'bill' => 'FireflyIII\Models\Bill', 'budget' => 'FireflyIII\Models\Budget', 'category' => 'FireflyIII\Models\Category', + 'transaction_type' => 'FireflyIII\Models\TransactionType', 'currency' => 'FireflyIII\Models\TransactionCurrency', 'limitrepetition' => 'FireflyIII\Models\LimitRepetition', 'piggyBank' => 'FireflyIII\Models\PiggyBank', diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index cd3074e301..b1d1d18a1a 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -242,6 +242,7 @@ return [ 'rule_action_set_source_account' => 'Set source account to :action_value', 'rule_action_set_destination_account_choice' => 'Set destination account to...', 'rule_action_set_destination_account' => 'Set destination account to :action_value', + // tags 'store_new_tag' => 'Store new tag', 'update_tag' => 'Update tag', @@ -352,6 +353,21 @@ return [ 'title_transfer' => 'Transfers', 'title_transfers' => 'Transfers', + // convert stuff: + 'convert_is_already_type_Withdrawal' => 'This transaction is already a withdrawal', + 'convert_is_already_type_Deposit' => 'This transaction is already a deposit', + 'convert_is_already_type_Transfer' => 'This transaction is already a transfer', + 'convert_to_Withdrawal' => 'Convert ":description" to a withdrawal', + 'convert_to_Deposit' => 'Convert ":description" to a deposit', + 'convert_to_Transfer' => 'Convert ":description" to a transfer', + 'convert_options_WithdrawalDeposit' => 'Convert a withdrawal into a deposit', + 'convert_options_WithdrawalTransfer' => 'Convert a withdrawal into a transfer', + 'convert_options_DepositTransfer' => 'Convert a deposit into a transfer', + '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', + + // create new stuff: 'create_new_withdrawal' => 'Create new withdrawal', 'create_new_deposit' => 'Create new deposit', diff --git a/resources/lang/en_US/form.php b/resources/lang/en_US/form.php index 5cfd1a3688..cb264972d0 100644 --- a/resources/lang/en_US/form.php +++ b/resources/lang/en_US/form.php @@ -31,6 +31,8 @@ return [ 'journal_source_account_id' => 'Asset account (source)', 'account_from_id' => 'From account', 'account_to_id' => 'To account', + 'source_account' => 'Source account', + 'destination_account' => 'Destination account', 'journal_destination_account_id' => 'Asset account (destination)', 'asset_destination_account' => 'Asset account (destination)', 'asset_source_account' => 'Asset account (source)', @@ -58,95 +60,107 @@ return [ 'description' => 'Description', 'expense_account' => 'Expense account', 'revenue_account' => 'Revenue account', - 'amount' => 'Amount', - 'date' => 'Date', - 'interest_date' => 'Interest date', - 'book_date' => 'Book date', - 'process_date' => 'Processing date', - 'category' => 'Category', - 'tags' => 'Tags', - 'deletePermanently' => 'Delete permanently', - 'cancel' => 'Cancel', - 'targetdate' => 'Target date', - 'tag' => 'Tag', - 'under' => 'Under', - 'symbol' => 'Symbol', - 'code' => 'Code', - 'iban' => 'IBAN', - 'accountNumber' => 'Account number', - 'has_headers' => 'Headers', - 'date_format' => 'Date format', - 'specifix' => 'Bank- or file specific fixes', - 'attachments[]' => 'Attachments', - 'store_new_withdrawal' => 'Store new withdrawal', - 'store_new_deposit' => 'Store new deposit', - 'store_new_transfer' => 'Store new transfer', - 'add_new_withdrawal' => 'Add a new withdrawal', - 'add_new_deposit' => 'Add a new deposit', - 'add_new_transfer' => 'Add a new transfer', - 'noPiggybank' => '(no piggy bank)', - 'title' => 'Title', - 'notes' => 'Notes', - 'filename' => 'File name', - 'mime' => 'Mime type', - 'size' => 'Size', - 'trigger' => 'Trigger', - 'stop_processing' => 'Stop processing', - 'start_date' => 'Start of range', - 'end_date' => 'End of range', - 'export_start_range' => 'Start of export range', - 'export_end_range' => 'End of export range', - 'export_format' => 'File format', - 'include_attachments' => 'Include uploaded attachments', - 'include_old_uploads' => 'Include imported data', - 'accounts' => 'Export transactions from these accounts', - 'delete_account' => 'Delete account ":name"', - 'delete_bill' => 'Delete bill ":name"', - 'delete_budget' => 'Delete budget ":name"', - 'delete_category' => 'Delete category ":name"', - 'delete_currency' => 'Delete currency ":name"', - 'delete_journal' => 'Delete transaction with description ":description"', - 'delete_attachment' => 'Delete attachment ":name"', - 'delete_rule' => 'Delete rule ":title"', - 'delete_rule_group' => 'Delete rule group ":title"', - 'attachment_areYouSure' => 'Are you sure you want to delete the attachment named ":name"?', - 'account_areYouSure' => 'Are you sure you want to delete the account named ":name"?', - 'bill_areYouSure' => 'Are you sure you want to delete the bill named ":name"?', - 'rule_areYouSure' => 'Are you sure you want to delete the rule titled ":title"?', - 'ruleGroup_areYouSure' => 'Are you sure you want to delete the rule group titled ":title"?', - 'budget_areYouSure' => 'Are you sure you want to delete the budget named ":name"?', - 'category_areYouSure' => 'Are you sure you want to delete the category named ":name"?', - 'currency_areYouSure' => 'Are you sure you want to delete the currency named ":name"?', - 'piggyBank_areYouSure' => 'Are you sure you want to delete the piggy bank named ":name"?', - 'journal_areYouSure' => 'Are you sure you want to delete the transaction described ":description"?', - 'mass_journal_are_you_sure' => 'Are you sure you want to delete these transactions?', - 'tag_areYouSure' => 'Are you sure you want to delete the tag ":tag"?', - 'permDeleteWarning' => 'Deleting stuff from Firely is permanent and cannot be undone.', - 'mass_make_selection' => 'You can still prevent items from being deleted by removing the checkbox.', - 'delete_all_permanently' => 'Delete selected permanently', - 'update_all_journals' => 'Update these transactions', - 'also_delete_transactions' => 'The only transaction connected to this account will be deleted as well.|All :count transactions connected to this account will be deleted as well.', - 'also_delete_rules' => 'The only rule connected to this rule group will be deleted as well.|All :count rules connected to this rule group will be deleted as well.', - 'also_delete_piggyBanks' => 'The only piggy bank connected to this account will be deleted as well.|All :count piggy bank connected to this account will be deleted as well.', - 'bill_keep_transactions' => 'The only transaction connected to this bill will not be deleted.|All :count transactions connected to this bill will spared deletion.', - 'budget_keep_transactions' => 'The only transaction connected to this budget will not be deleted.|All :count transactions connected to this budget will spared deletion.', - 'category_keep_transactions' => 'The only transaction connected to this category will not be deleted.|All :count transactions connected to this category will spared deletion.', - 'tag_keep_transactions' => 'The only transaction connected to this tag will not be deleted.|All :count transactions connected to this tag will spared deletion.', + + 'revenue_account_source' => 'Revenue account (source)', + 'source_account_asset' => 'Source account (asset account)', + 'destination_account_expense' => 'Destination account (expense account)', + 'destination_account_asset' => 'Destination account (asset account)', + 'source_account_revenue' => 'Source account (revenue account)', + 'type' => 'Type', + 'convert_Withdrawal' => 'Convert withdrawal', + 'convert_Deposit' => 'Convert deposit', + 'convert_Transfer' => 'Convert transfer', + + + 'amount' => 'Amount', + 'date' => 'Date', + 'interest_date' => 'Interest date', + 'book_date' => 'Book date', + 'process_date' => 'Processing date', + 'category' => 'Category', + 'tags' => 'Tags', + 'deletePermanently' => 'Delete permanently', + 'cancel' => 'Cancel', + 'targetdate' => 'Target date', + 'tag' => 'Tag', + 'under' => 'Under', + 'symbol' => 'Symbol', + 'code' => 'Code', + 'iban' => 'IBAN', + 'accountNumber' => 'Account number', + 'has_headers' => 'Headers', + 'date_format' => 'Date format', + 'specifix' => 'Bank- or file specific fixes', + 'attachments[]' => 'Attachments', + 'store_new_withdrawal' => 'Store new withdrawal', + 'store_new_deposit' => 'Store new deposit', + 'store_new_transfer' => 'Store new transfer', + 'add_new_withdrawal' => 'Add a new withdrawal', + 'add_new_deposit' => 'Add a new deposit', + 'add_new_transfer' => 'Add a new transfer', + 'noPiggybank' => '(no piggy bank)', + 'title' => 'Title', + 'notes' => 'Notes', + 'filename' => 'File name', + 'mime' => 'Mime type', + 'size' => 'Size', + 'trigger' => 'Trigger', + 'stop_processing' => 'Stop processing', + 'start_date' => 'Start of range', + 'end_date' => 'End of range', + 'export_start_range' => 'Start of export range', + 'export_end_range' => 'End of export range', + 'export_format' => 'File format', + 'include_attachments' => 'Include uploaded attachments', + 'include_old_uploads' => 'Include imported data', + 'accounts' => 'Export transactions from these accounts', + 'delete_account' => 'Delete account ":name"', + 'delete_bill' => 'Delete bill ":name"', + 'delete_budget' => 'Delete budget ":name"', + 'delete_category' => 'Delete category ":name"', + 'delete_currency' => 'Delete currency ":name"', + 'delete_journal' => 'Delete transaction with description ":description"', + 'delete_attachment' => 'Delete attachment ":name"', + 'delete_rule' => 'Delete rule ":title"', + 'delete_rule_group' => 'Delete rule group ":title"', + 'attachment_areYouSure' => 'Are you sure you want to delete the attachment named ":name"?', + 'account_areYouSure' => 'Are you sure you want to delete the account named ":name"?', + 'bill_areYouSure' => 'Are you sure you want to delete the bill named ":name"?', + 'rule_areYouSure' => 'Are you sure you want to delete the rule titled ":title"?', + 'ruleGroup_areYouSure' => 'Are you sure you want to delete the rule group titled ":title"?', + 'budget_areYouSure' => 'Are you sure you want to delete the budget named ":name"?', + 'category_areYouSure' => 'Are you sure you want to delete the category named ":name"?', + 'currency_areYouSure' => 'Are you sure you want to delete the currency named ":name"?', + 'piggyBank_areYouSure' => 'Are you sure you want to delete the piggy bank named ":name"?', + 'journal_areYouSure' => 'Are you sure you want to delete the transaction described ":description"?', + 'mass_journal_are_you_sure' => 'Are you sure you want to delete these transactions?', + 'tag_areYouSure' => 'Are you sure you want to delete the tag ":tag"?', + 'permDeleteWarning' => 'Deleting stuff from Firely is permanent and cannot be undone.', + 'mass_make_selection' => 'You can still prevent items from being deleted by removing the checkbox.', + 'delete_all_permanently' => 'Delete selected permanently', + 'update_all_journals' => 'Update these transactions', + 'also_delete_transactions' => 'The only transaction connected to this account will be deleted as well.|All :count transactions connected to this account will be deleted as well.', + 'also_delete_rules' => 'The only rule connected to this rule group will be deleted as well.|All :count rules connected to this rule group will be deleted as well.', + 'also_delete_piggyBanks' => 'The only piggy bank connected to this account will be deleted as well.|All :count piggy bank connected to this account will be deleted as well.', + 'bill_keep_transactions' => 'The only transaction connected to this bill will not be deleted.|All :count transactions connected to this bill will spared deletion.', + 'budget_keep_transactions' => 'The only transaction connected to this budget will not be deleted.|All :count transactions connected to this budget will spared deletion.', + 'category_keep_transactions' => 'The only transaction connected to this category will not be deleted.|All :count transactions connected to this category will spared deletion.', + 'tag_keep_transactions' => 'The only transaction connected to this tag will not be deleted.|All :count transactions connected to this tag will spared deletion.', // admin - 'domain' => 'Domain', - 'single_user_mode' => 'Single user mode', + 'domain' => 'Domain', + 'single_user_mode' => 'Single user mode', // import - 'import_file' => 'Import file', - 'configuration_file' => 'Configuration file', - 'import_file_type' => 'Import file type', - 'csv_comma' => 'A comma (,)', - 'csv_semicolon' => 'A semicolon (;)', - 'csv_tab' => 'A tab (invisible)', - 'csv_delimiter' => 'CSV field delimiter', - 'csv_import_account' => 'Default import account', - 'csv_config' => 'CSV import configuration', + 'import_file' => 'Import file', + 'configuration_file' => 'Configuration file', + 'import_file_type' => 'Import file type', + 'csv_comma' => 'A comma (,)', + 'csv_semicolon' => 'A semicolon (;)', + 'csv_tab' => 'A tab (invisible)', + 'csv_delimiter' => 'CSV field delimiter', + 'csv_import_account' => 'Default import account', + 'csv_config' => 'CSV import configuration', 'due_date' => 'Due date', diff --git a/resources/views/transactions/convert.twig b/resources/views/transactions/convert.twig new file mode 100644 index 0000000000..c7617480a6 --- /dev/null +++ b/resources/views/transactions/convert.twig @@ -0,0 +1,176 @@ +{% extends "./layout/default.twig" %} + +{% block breadcrumbs %} + {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, destinationType, journal) }} +{% endblock %} + +{% block content %} ++ +{% endblock %} +{% block scripts %} + + +{% endblock %} + +{% block styles %} + +{% endblock %} diff --git a/resources/views/transactions/show.twig b/resources/views/transactions/show.twig index 5a7e7f42d3..5a146f26be 100644 --- a/resources/views/transactions/show.twig +++ b/resources/views/transactions/show.twig @@ -169,8 +169,6 @@ - - {% if journal.attachments|length > 0 %}
+ + + Convert this {{ journal.transactionType.type }} to a withdrawal. + +
+ {% endif %} + {% if journal.transactionType.type != "Deposit" %} ++ + + Convert this {{ journal.transactionType.type }} to a deposit. + +
+ {% endif %} + + {% if journal.transactionType.type != "Transfer" %} ++ + + Convert this {{ journal.transactionType.type }} to a transfer. + +
+ {% endif %} + +