From 4b4dc2e298f2f892157366daa17699d4d6d735c9 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 12 Jun 2018 18:48:15 +0200 Subject: [PATCH] Various code related to the recurring transactions. --- .../Recurring/CreateController.php | 9 +- .../Controllers/Recurring/IndexController.php | 14 + .../2018_06_08_200526_changes_for_v475.php | 1 + public/js/ff/recurring/create.js | 34 ++- resources/lang/en_US/demo.php | 2 + resources/lang/en_US/firefly.php | 4 + resources/lang/en_US/form.php | 3 + resources/views/recurring/create.twig | 260 ++++++++++-------- routes/web.php | 1 + 9 files changed, 213 insertions(+), 115 deletions(-) diff --git a/app/Http/Controllers/Recurring/CreateController.php b/app/Http/Controllers/Recurring/CreateController.php index f7f5d06712..52e12bf7c7 100644 --- a/app/Http/Controllers/Recurring/CreateController.php +++ b/app/Http/Controllers/Recurring/CreateController.php @@ -74,6 +74,13 @@ class CreateController extends Controller $tomorrow = new Carbon; $tomorrow->addDay(); + // types of repetitions: + $typesOfRepetitions = [ + 'forever' => trans('firefly.repeat_forever'), + 'until_date' => trans('firefly.repeat_until_date'), + 'times' => trans('firefly.repeat_times'), + ]; + // flash some data: $preFilled = [ 'first_date' => $tomorrow->format('Y-m-d'), @@ -83,7 +90,7 @@ class CreateController extends Controller ]; $request->session()->flash('preFilled', $preFilled); - return view('recurring.create', compact('tomorrow', 'preFilled', 'defaultCurrency','budgets')); + return view('recurring.create', compact('tomorrow', 'preFilled','typesOfRepetitions', 'defaultCurrency', 'budgets')); } } \ No newline at end of file diff --git a/app/Http/Controllers/Recurring/IndexController.php b/app/Http/Controllers/Recurring/IndexController.php index 8cde8b238f..74f948415c 100644 --- a/app/Http/Controllers/Recurring/IndexController.php +++ b/app/Http/Controllers/Recurring/IndexController.php @@ -63,6 +63,20 @@ class IndexController extends Controller ); } + /** + * @param Request $request + * + * @return string + */ + public function calendar(Request $request) + { + $date = new Carbon; + $daysOfWeek = ['S', 'M', 'T', 'W', 'T', 'F', 'S']; + //$firstDayOfMonth = mktime(0, 0, 0, $month, 1, $year); + + return view('recurring.calendar'); + } + /** * @param Request $request * diff --git a/database/migrations/2018_06_08_200526_changes_for_v475.php b/database/migrations/2018_06_08_200526_changes_for_v475.php index 053a6e676b..db5cfbebe7 100644 --- a/database/migrations/2018_06_08_200526_changes_for_v475.php +++ b/database/migrations/2018_06_08_200526_changes_for_v475.php @@ -44,6 +44,7 @@ class ChangesForV475 extends Migration $table->date('first_date'); $table->date('repeat_until')->nullable(); $table->date('latest_date')->nullable(); + $table->smallInteger('repetitions', false, true); $table->boolean('apply_rules')->default(true); $table->boolean('active')->default(true); diff --git a/public/js/ff/recurring/create.js b/public/js/ff/recurring/create.js index 78ff8264b6..ba79cd4e4e 100644 --- a/public/js/ff/recurring/create.js +++ b/public/js/ff/recurring/create.js @@ -32,12 +32,44 @@ $(document).ready(function () { initializeButtons(); initializeAutoComplete(); respondToFirstDateChange(); + respondToRepetitionEnd(); $('.switch-button').on('click', switchTransactionType); + $('#ffInput_repetition_end').on('change', respondToRepetitionEnd); $('#ffInput_first_date').on('change', respondToFirstDateChange); - + $('#calendar-link').on('click', showRepCalendar); }); +function showRepCalendar() { + + // fill model with calendar: + + + $('#defaultModal').modal({}); + return false; +} + +function respondToRepetitionEnd() { + var obj = $('#ffInput_repetition_end'); + var value = obj.val(); + switch (value) { + case 'forever': + $('#repeat_until_holder').hide(); + $('#repetitions_holder').hide(); + break; + case 'until_date': + $('#repeat_until_holder').show(); + $('#repetitions_holder').hide(); + break; + case 'times': + $('#repeat_until_holder').hide(); + $('#repetitions_holder').show(); + break; + } + + +} + function respondToFirstDateChange() { var obj = $('#ffInput_first_date'); var select = $('#ffInput_repetition_type'); diff --git a/resources/lang/en_US/demo.php b/resources/lang/en_US/demo.php index 640ab10298..e56f6f24c6 100644 --- a/resources/lang/en_US/demo.php +++ b/resources/lang/en_US/demo.php @@ -34,4 +34,6 @@ return [ 'transactions-index' => 'These expenses, deposits and transfers are not particularly imaginative. They have been generated automatically.', 'piggy-banks-index' => 'As you can see, there are three piggy banks. Use the plus and minus buttons to influence the amount of money in each piggy bank. Click the name of the piggy bank to see the administration for each piggy bank.', 'import-index' => 'Any CSV file can be imported into Firefly III. It also supports importing data from bunq and Spectre. Other banks and financial aggregators will be implemented in the future. As a demo-user however, you can only see the "fake"-provider in action. It will generate some random transactions to show you how the process works.', + 'recurring-index' => 'Please note that this feature is under active development and may not work as expected.', + 'recurring-create' => 'Please note that this feature is under active development and may not work as expected.', ]; diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index af9109e153..e839af9f50 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -1235,6 +1235,10 @@ return [ 'optional_for_transaction' => 'Optional transaction information', 'change_date_other_options' => 'Change the "first date" to see more options.', 'mandatory_fields_for_tranaction' => 'The values here will end up in the transaction(s) being created', + 'click_for_calendar' => 'Click here for a calendar that shows you when the transaction would repeat.', + 'repeat_forever' => 'Repeat forever', + 'repeat_until_date' => 'Repeat until date', + 'repeat_times' => 'Repeat a number of times', ]; diff --git a/resources/lang/en_US/form.php b/resources/lang/en_US/form.php index 172fc28ccb..9445534e2a 100644 --- a/resources/lang/en_US/form.php +++ b/resources/lang/en_US/form.php @@ -230,5 +230,8 @@ return [ 'recurring_description' => 'Recurring transaction description', 'repetition_type' => 'Type of repetition', 'foreign_currency_id' => 'Foreign currency', + 'repetition_end' => 'Repetition ends', + 'repetitions' => 'Repetitions', + 'calendar' => 'Calendar', ]; diff --git a/resources/views/recurring/create.twig b/resources/views/recurring/create.twig index 3329ae2208..70b1a034e2 100644 --- a/resources/views/recurring/create.twig +++ b/resources/views/recurring/create.twig @@ -6,129 +6,163 @@
+ {# row with recurrence information #}
-
-
-
-
-

{{ 'mandatory_for_recurring'|_ }}

+ +
+ {# mandatory recurrence stuff #} +
+
+

{{ 'mandatory_for_recurring'|_ }}

+
+
+ {{ ExpandedForm.text('name') }} + {{ ExpandedForm.date('first_date',null, {helpText: trans('firefly.help_first_date')}) }} + {{ ExpandedForm.select('repetition_type', [], null, {helpText: trans('firefly.change_date_other_options')}) }} + {{ ExpandedForm.number('skip', 0) }} + {{ ExpandedForm.select('repetition_end', typesOfRepetitions) }} + {{ ExpandedForm.date('repeat_until',null) }} + {{ ExpandedForm.number('repetitions',null) }} + + {# calendar in popup #} +
+ + +
-
- {{ ExpandedForm.text('name') }} - {{ ExpandedForm.date('first_date',null, {helpText: trans('firefly.help_first_date')}) }} - {{ ExpandedForm.date('repeat_until',null) }} - {{ ExpandedForm.select('repetition_type', [], null, {helpText: trans('firefly.change_date_other_options')}) }} - {{ ExpandedForm.number('skip', 0) }} +
+
+
- {# three buttons to distinguish type of transaction#} -
- +
+ {# optional recurrence stuff #} +
+
+

{{ 'optional_for_recurring'|_ }}

+
+
+ {{ ExpandedForm.textarea('recurring_description') }} -
- + {{ ExpandedForm.checkbox('active',1) }} + + {{ ExpandedForm.checkbox('apply_rules',1) }} +
+
+
+
+ +
+
+ {# mandatory transaction information #} +
+
+

{{ 'mandatory_for_transaction'|_ }}

+
+
+

{{ 'mandatory_fields_for_tranaction'|_ }}

+ {# three buttons to distinguish type of transaction#} +
+ + +
+ {# end of three buttons#} + + {{ ExpandedForm.text('transaction_description') }} + {# transaction information (mandatory) #} + {{ ExpandedForm.currencyList('transaction_currency_id', defaultCurrency.id) }} + {{ ExpandedForm.amountNoCurrency('amount', []) }} + + {# source account if withdrawal, or if transfer: #} + {{ ExpandedForm.assetAccountList('source_account_id', null, {label: trans('form.asset_source_account')}) }} + + {# source account name for deposits: #} + {{ ExpandedForm.text('source_account_name', null, {label: trans('form.revenue_account')}) }} + + {# destination if deposit or transfer: #} + {{ ExpandedForm.assetAccountList('destination_account_id', null, {label: trans('form.asset_destination_account')} ) }} + + {# destination account name for withdrawals #} + {{ ExpandedForm.text('destination_account_name', null, {label: trans('form.expense_account')}) }}
- -
-
-

{{ 'mandatory_for_transaction'|_ }}

-
-
-

{{ 'mandatory_fields_for_tranaction'|_ }}

- {{ ExpandedForm.text('transaction_description') }} - {# transaction information (mandatory) #} - {{ ExpandedForm.currencyList('transaction_currency_id', defaultCurrency.id) }} - {{ ExpandedForm.amountNoCurrency('amount', []) }} - - {# source account if withdrawal, or if transfer: #} - {{ ExpandedForm.assetAccountList('source_account_id', null, {label: trans('form.asset_source_account')}) }} - - {# source account name for deposits: #} - {{ ExpandedForm.text('source_account_name', null, {label: trans('form.revenue_account')}) }} - - {# destination if deposit or transfer: #} - {{ ExpandedForm.assetAccountList('destination_account_id', null, {label: trans('form.asset_destination_account')} ) }} - - {# destination account name for withdrawals #} - {{ ExpandedForm.text('destination_account_name', null, {label: trans('form.expense_account')}) }} -
-
- - -
-
-

{{ 'expected_repetitions'|_ }}

-
-
- Here. -
-
-
- -
-
-
-

{{ 'optional_for_recurring'|_ }}

-
-
- {{ ExpandedForm.textarea('recurring_description') }} - - {{ ExpandedForm.checkbox('active',1) }} - - {{ ExpandedForm.checkbox('apply_rules',1) }} -
-
-
-
-

{{ 'optional_for_transaction'|_ }}

-
-
- {# transaction information (optional) #} - {{ ExpandedForm.currencyList('foreign_currency_id', defaultCurrency.id) }} - {{ ExpandedForm.amountNoCurrency('foreign_amount', []) }} - - {# BUDGET ONLY WHEN CREATING A WITHDRAWAL #} - {% if budgets|length > 1 %} - {{ ExpandedForm.select('budget_id', budgets, null) }} - {% else %} - {{ ExpandedForm.select('budget_id', budgets, null, {helpText: trans('firefly.no_budget_pointer')}) }} - {% endif %} - - {# CATEGORY ALWAYS #} - {{ ExpandedForm.text('category') }} - - {# TAGS #} - {{ ExpandedForm.text('tags') }} - - {# RELATE THIS TRANSFER TO A PIGGY BANK #} - {{ ExpandedForm.select('piggy_bank_id', [], '0') }} -
-
- -
-
-

{{ 'options'|_ }}

-
-
- {{ ExpandedForm.optionsList('create','recurrence') }} -
- -
-
+ +
+ {# optional transaction information #} +
+
+

{{ 'optional_for_transaction'|_ }}

+
+
+ {# transaction information (optional) #} + {{ ExpandedForm.currencyList('foreign_currency_id', defaultCurrency.id) }} + {{ ExpandedForm.amountNoCurrency('foreign_amount', []) }} + + {# BUDGET ONLY WHEN CREATING A WITHDRAWAL #} + {% if budgets|length > 1 %} + {{ ExpandedForm.select('budget_id', budgets, null) }} + {% else %} + {{ ExpandedForm.select('budget_id', budgets, null, {helpText: trans('firefly.no_budget_pointer')}) }} + {% endif %} + + {# CATEGORY ALWAYS #} + {{ ExpandedForm.text('category') }} + + {# TAGS #} + {{ ExpandedForm.text('tags') }} + + {# RELATE THIS TRANSFER TO A PIGGY BANK #} + {{ ExpandedForm.select('piggy_bank_id', [], '0') }} +
+
+
+
+ + {# row with submit stuff. #} +
+
+
+
+

{{ 'options'|_ }}

+
+
+ {{ ExpandedForm.optionsList('create','recurrence') }} +
+ +
+
+
+ {# +
+
+
+

{{ 'expected_repetitions'|_ }}

+
+
+ Here. +
+
+
+
+
+ #} {% endblock %} {% block scripts %} diff --git a/routes/web.php b/routes/web.php index 2fbd1c00d4..fb991d829c 100755 --- a/routes/web.php +++ b/routes/web.php @@ -618,6 +618,7 @@ Route::group( Route::get('', ['uses' => 'IndexController@index', 'as' => 'index']); Route::get('suggest', ['uses' => 'IndexController@suggest', 'as' => 'suggest']); + Route::get('calendar', ['uses' => 'IndexController@calendar', 'as' => 'calendar']); Route::get('show/{recurrence}', ['uses' => 'IndexController@show', 'as' => 'show']); Route::get('create', ['uses' => 'CreateController@create', 'as' => 'create']); Route::get('edit/{recurrence}', ['uses' => 'EditController@edit', 'as' => 'edit']);