From ce191fa6d3885f0ed8d488723f84c3ff165320dc Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 26 Jul 2016 20:26:46 +0200 Subject: [PATCH] Fix split deposit. --- app/Crud/Split/Journal.php | 6 +- app/Http/Requests/SplitJournalFormRequest.php | 12 +- resources/lang/en_US/list.php | 1 + resources/views/split/journals/create.twig | 311 +++++++++--------- resources/views/split/journals/edit.twig | 5 +- 5 files changed, 168 insertions(+), 167 deletions(-) diff --git a/app/Crud/Split/Journal.php b/app/Crud/Split/Journal.php index 8930331d56..cbb4e34c35 100644 --- a/app/Crud/Split/Journal.php +++ b/app/Crud/Split/Journal.php @@ -105,9 +105,6 @@ class Journal implements JournalInterface */ public function updateJournal(TransactionJournal $journal, array $data): TransactionJournal { - echo '
';
-        print_r($data);
-
         $journal->description             = $data['journal_description'];
         $journal->transaction_currency_id = $data['journal_currency_id'];
         $journal->date                    = $data['date'];
@@ -167,7 +164,8 @@ class Journal implements JournalInterface
     {
         $destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first(['accounts.*']);
 
-        if (strlen($data['source_account_name']) > 0) {
+
+        if (isset($data['source_account_name']) && strlen($data['source_account_name']) > 0) {
             $sourceType    = AccountType::where('type', 'Revenue account')->first();
             $sourceAccount = Account::firstOrCreateEncrypted(
                 ['user_id' => $this->user->id, 'account_type_id' => $sourceType->id, 'name' => $data['source_account_name'], 'active' => 1]
diff --git a/app/Http/Requests/SplitJournalFormRequest.php b/app/Http/Requests/SplitJournalFormRequest.php
index 5213fb182e..67ff3b438b 100644
--- a/app/Http/Requests/SplitJournalFormRequest.php
+++ b/app/Http/Requests/SplitJournalFormRequest.php
@@ -59,14 +59,10 @@ class SplitJournalFormRequest extends Request
                 'amount'                   => round($this->get('amount')[$index], 2),
                 'budget_id'                => $this->get('budget_id')[$index] ? intval($this->get('budget_id')[$index]) : 0,
                 'category'                 => $this->get('category')[$index] ?? '',
-                'source_account_id'        => intval($this->get('journal_source_account_id')),
-                'source_account_name'      => $this->get('journal_source_account_name'),
-                'piggy_bank_id'            => isset($this->get('piggy_bank_id')[$index])
-                    ? intval($this->get('piggy_bank_id')[$index])
-                    : 0,
-                'destination_account_id'   => isset($this->get('destination_account_id')[$index])
-                    ? intval($this->get('destination_account_id')[$index])
-                    : intval($this->get('journal_destination_account_id')),
+                'source_account_id'        => isset($this->get('source_account_id')[$index]) ? intval($this->get('source_account_id')[$index]) : intval($this->get('journal_source_account_id')),
+                'source_account_name'      => $this->get('source_account_name')[$index] ?? '',
+                'piggy_bank_id'            => isset($this->get('piggy_bank_id')[$index]) ? intval($this->get('piggy_bank_id')[$index]) : 0,
+                'destination_account_id'   => isset($this->get('destination_account_id')[$index]) ? intval($this->get('destination_account_id')[$index]) : intval($this->get('journal_destination_account_id')),
                 'destination_account_name' => $this->get('destination_account_name')[$index] ?? '',
             ];
             $data['transactions'][] = $transaction;
diff --git a/resources/lang/en_US/list.php b/resources/lang/en_US/list.php
index e66b2afcda..743b67adfa 100644
--- a/resources/lang/en_US/list.php
+++ b/resources/lang/en_US/list.php
@@ -29,6 +29,7 @@ return [
     'lastMatch'             => 'Last match',
     'split_number'          => 'Split #',
     'destination'           => 'Destination',
+    'source'                => 'Source',
     'expectedMatch'         => 'Expected match',
     'automatch'             => 'Auto match?',
     'repeat_freq'           => 'Repeats',
diff --git a/resources/views/split/journals/create.twig b/resources/views/split/journals/create.twig
index 90acdc41f4..cb995a1865 100644
--- a/resources/views/split/journals/create.twig
+++ b/resources/views/split/journals/create.twig
@@ -7,193 +7,196 @@
     
- - - + + + - {% if errors.all()|length > 0 %} + {% if errors.all()|length > 0 %} +
+
+
+
+

{{ 'errors'|_ }}

+
+
+
    + {% for key, err in errors.all() %} +
  • {{ err }}
  • + {% endfor %} +
+
+
+
+
+ {% endif %}
-
-
+
+
-

{{ 'errors'|_ }}

+

{{ 'transaction_meta_data'|_ }}

-
    - {% for key, err in errors.all() %} -
  • {{ err }}
  • - {% endfor %} -
+ {{ ExpandedForm.text('journal_description', journal.description) }} + {{ ExpandedForm.select('journal_currency_id', currencies, journal.transaction_currency_id) }} + {{ ExpandedForm.staticText('journal_amount', preFilled.journal_amount|formatAmount ) }} + + + {% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %} + {{ ExpandedForm.select('journal_source_account_id', assetAccounts, preFilled.journal_source_account_id) }} + {% endif %} + + {% if preFilled.what == 'deposit' %} + {{ ExpandedForm.text('journal_source_account_name', preFilled.journal_source_account_name) }} + {% endif %} + + {% if preFilled.what == 'transfer' %} + {{ ExpandedForm.select('journal_destination_account_id', assetAccounts, preFilled.journal_destination_account_id) }} + {% endif %}
-
- {% endif %} -
-
-
-
-

{{ 'transaction_meta_data'|_ }}

-
-
- {{ ExpandedForm.text('journal_description', journal.description) }} - {{ ExpandedForm.select('journal_currency_id', currencies, journal.transaction_currency_id) }} - {{ ExpandedForm.staticText('journal_amount', preFilled.journal_amount|formatAmount ) }} - - - {% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %} - {{ ExpandedForm.select('journal_source_account_id', assetAccounts, preFilled.journal_source_account_id) }} - {% endif %} - - {% if preFilled.what == 'deposit' %} - {{ ExpandedForm.text('journal_source_account_name', preFilled.journal_source_account_name) }} - {% endif %} - - {% if preFilled.what == 'transfer' %} - {{ ExpandedForm.select('journal_destination_account_id', assetAccounts, preFilled.journal_destination_account_id) }} - {% endif %} +
+
+
+

{{ 'transaction_dates'|_ }}

+
+
+ {{ ExpandedForm.date('date', journal.date) }} + + {{ ExpandedForm.date('interest_date', journal.interest_date) }} + + {{ ExpandedForm.date('book_date', journal.book_date) }} + + {{ ExpandedForm.date('process_date', journal.process_date) }} +
+
-
-
-
-

{{ 'transaction_dates'|_ }}

-
-
- {{ ExpandedForm.date('date', journal.date) }} - - {{ ExpandedForm.date('interest_date', journal.interest_date) }} - - {{ ExpandedForm.date('book_date', journal.book_date) }} - - {{ ExpandedForm.date('process_date', journal.process_date) }} -
-
- -
-
-
-
-
-
-

{{ 'splits'|_ }}

-
-
- - - - - - {% if preFilled.what == 'withdrawal' or preFilled.what == 'deposit' %} - - {% endif %} - - {% if preFilled.what == 'withdrawal' %} - - {% endif %} - - {% if preFilled.what == 'transfer' %} - - {% endif %} - - - - {% for index, descr in preFilled.description %} - - - - - +
+
+
+
+

{{ 'splits'|_ }}

+
+
+
{{ trans('list.split_number') }}{{ trans('list.description') }}{{ trans('list.destination') }}{{ trans('list.amount') }}{{ trans('list.budget') }}{{ trans('list.category') }}{{ trans('list.piggy_bank') }}
#{{ loop.index }} - -
+ + + + {% if preFilled.what == 'withdrawal' %} - + {% endif %} - - {% if preFilled.what == 'deposit' %} - + {% endif %} - - - + {% if preFilled.what == 'withdrawal' %} - + {% endif %} - + {% if preFilled.what == 'transfer' %} - + {% endif %} - {% endfor %} - -
{{ trans('list.split_number') }}{{ trans('list.description') }} - - {{ trans('list.destination') }} - {{ Form.select('destination_account_id[]', assetAccounts, preFilled.destination_account_id[index], {class: 'form-control'}) }} - {{ trans('list.source') }} - - {{ trans('list.amount') }} - - {{ trans('list.budget') }} - - {{ trans('list.category') }} - - {{ Form.select('piggy_bank_id[]',piggyBanks, preFilled.piggy_bank_id[index], {class: 'form-control'}) }} - {{ trans('list.piggy_bank') }}
-

-
- {{ 'add_another_split'|_ }} -

- + {% if preFilled.what == 'withdrawal' %} + + + + {% endif %} + + + {% if preFilled.what == 'deposit' %} + + {{ Form.select('destination_account_id[]', assetAccounts, preFilled.destination_account_id[index], {class: 'form-control'}) }} + + {% endif %} + + + + + + {% if preFilled.what == 'withdrawal' %} + + + + {% endif %} + + + + {% if preFilled.what == 'transfer' %} + + + {{ Form.select('piggy_bank_id[]',piggyBanks, preFilled.piggy_bank_id[index], {class: 'form-control'}) }} + + {% endif %} + + {% endfor %} + + +

+
+ {{ 'add_another_split'|_ }} +

+ +
-
-
-
+
+
-
-
-

{{ 'optionalFields'|_ }}

+
+
+

{{ 'optionalFields'|_ }}

+
+
+ + {{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }} +
-
- - {{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }} +
+
+ +
+
+

{{ 'options'|_ }}

+
+
+ {{ ExpandedForm.optionsList('create','split-transaction') }} +
+
-
- -
-
-

{{ 'options'|_ }}

-
-
- {{ ExpandedForm.optionsList('create','split-transaction') }} -
- -
-
-
{% endblock %} diff --git a/resources/views/split/journals/edit.twig b/resources/views/split/journals/edit.twig index 44deb1c9e1..e7fc9e7105 100644 --- a/resources/views/split/journals/edit.twig +++ b/resources/views/split/journals/edit.twig @@ -94,9 +94,12 @@ {{ trans('list.description') }} - {% if preFilled.what == 'withdrawal' or preFilled.what == 'deposit' %} + {% if preFilled.what == 'withdrawal' %} {{ trans('list.destination') }} {% endif %} + {% if preFilled.what == 'deposit' %} + {{ trans('list.source') }} + {% endif %} {{ trans('list.amount') }}