mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 10:47:00 +00:00 
			
		
		
		
	Fine tuning split edit screens.
This commit is contained in:
		| @@ -126,7 +126,6 @@ class SplitController extends Controller | ||||
|      */ | ||||
|     public function update(Request $request, JournalRepositoryInterface $repository, TransactionJournal $journal) | ||||
|     { | ||||
|  | ||||
|         $data    = $this->arrayFromInput($request, $journal); | ||||
|         $journal = $repository->updateSplitJournal($journal, $data); | ||||
|  | ||||
| @@ -170,7 +169,7 @@ class SplitController extends Controller | ||||
|             'journal_source_account_id'      => $request->get('journal_source_account_id'), | ||||
|             'journal_source_account_name'    => $request->get('journal_source_account_name'), | ||||
|             'journal_destination_account_id' => $request->get('journal_destination_account_id'), | ||||
|             'transaction_currency_id'        => $request->get('transaction_currency_id'), | ||||
|             'currency_id'        => $request->get('currency_id'), | ||||
|             'what'                           => $request->get('what'), | ||||
|             'date'                           => $request->get('date'), | ||||
|             // all custom fields: | ||||
| @@ -208,7 +207,7 @@ class SplitController extends Controller | ||||
|             'journal_source_account_id'      => $request->old('journal_source_account_id', $sourceAccounts->first()->id), | ||||
|             'journal_source_account_name'    => $request->old('journal_source_account_name', $sourceAccounts->first()->name), | ||||
|             'journal_destination_account_id' => $request->old('journal_destination_account_id', $destinationAccounts->first()->id), | ||||
|             'transaction_currency_id'        => $request->old('transaction_currency_id', $journal->transaction_currency_id), | ||||
|             'currency_id'                    => $request->old('currency_id', $journal->transaction_currency_id), | ||||
|             'destinationAccounts'            => $destinationAccounts, | ||||
|             'what'                           => strtolower(TransactionJournal::transactionTypeStr($journal)), | ||||
|             'date'                           => $request->old('date', $journal->date), | ||||
| @@ -277,7 +276,6 @@ class SplitController extends Controller | ||||
|                 'budget_id'                => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : 0, | ||||
|                 'category'                 => $transaction['category'] ?? '', | ||||
|                 'user'                     => auth()->user()->id, // needed for accounts. | ||||
|                 'piggy_bank_id'            => $transaction['piggy_bank_id'] ?? 0, | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -264,9 +264,10 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|     public function updateSplitJournal(TransactionJournal $journal, array $data): TransactionJournal | ||||
|     { | ||||
|         // update actual journal: | ||||
|         $journal->transaction_currency_id = $data['transaction_currency_id']; | ||||
|         $journal->transaction_currency_id = $data['currency_id']; | ||||
|         $journal->description             = $data['journal_description']; | ||||
|         $journal->date                    = $data['date']; | ||||
|         $journal->save(); | ||||
|          | ||||
|         // unlink all categories: | ||||
|         $journal->categories()->detach(); | ||||
| @@ -330,6 +331,9 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|             case strtolower(TransactionType::WITHDRAWAL): | ||||
|                 $transaction['source_account_id'] = intval($data['journal_source_account_id']); | ||||
|                 break; | ||||
|         } | ||||
|  | ||||
|         switch ($data['what']) { | ||||
|             case strtolower(TransactionType::TRANSFER): | ||||
|             case strtolower(TransactionType::DEPOSIT): | ||||
|                 $transaction['destination_account_id'] = intval($data['journal_destination_account_id']); | ||||
| @@ -379,6 +383,7 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|             'source'      => null, | ||||
|             'destination' => null, | ||||
|         ]; | ||||
|  | ||||
|         Log::debug(sprintf('Going to store accounts for type %s', $type->type)); | ||||
|         switch ($type->type) { | ||||
|             case TransactionType::WITHDRAWAL: | ||||
| @@ -390,7 +395,6 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|  | ||||
|                 break; | ||||
|             case TransactionType::TRANSFER: | ||||
|  | ||||
|                 $accounts['source']      = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first(); | ||||
|                 $accounts['destination'] = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first(); | ||||
|                 break; | ||||
| @@ -536,11 +540,6 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|         $this->storeCategoryWithTransaction($two, $transaction['category']); | ||||
|         $this->storeBudgetWithTransaction($two, $transaction['budget_id']); | ||||
|  | ||||
|         if ($transaction['piggy_bank_id'] > 0) { | ||||
|             $transaction['date'] = $journal->date->format('Y-m-d'); | ||||
|             event(new TransactionStored($transaction)); | ||||
|         } | ||||
|  | ||||
|         return new Collection([$one, $two]); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -14,6 +14,7 @@ var categories = {}; | ||||
| $(function () { | ||||
|     "use strict"; | ||||
|     $('.btn-do-split').click(cloneRow); | ||||
|     $('.remove-current-split').click(removeRow); | ||||
|  | ||||
|     $.getJSON('json/expense-accounts').done(function (data) { | ||||
|         destAccounts = data; | ||||
| @@ -38,24 +39,42 @@ $(function () { | ||||
|     // add auto complete: | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| }); | ||||
|  | ||||
| function removeRow(e) { | ||||
|     "use strict"; | ||||
|     var rows = $('table.split-table tbody tr'); | ||||
|     if (rows.length === 1) { | ||||
|         console.log('Will not remove last split'); | ||||
|         return false; | ||||
|     } | ||||
|     var row = $(e.target); | ||||
|     var index = row.data('split'); | ||||
|     console.log('Trying to remove row with split ' + index); | ||||
|     $('table.split-table tbody tr[data-split="' + index + '"]').remove(); | ||||
|  | ||||
|  | ||||
|  | ||||
|     resetSplits(); | ||||
|  | ||||
|     return false; | ||||
|  | ||||
| } | ||||
|  | ||||
| function cloneRow() { | ||||
|     "use strict"; | ||||
|     var source = $('.initial-row').clone(); | ||||
|     var source = $('.table.split-table tbody tr').last().clone(); | ||||
|     var count = $('.split-table tbody tr').length + 1; | ||||
|     var index = count - 1; | ||||
|     source.removeClass('initial-row'); | ||||
|     source.find('.count').text('#' + count); | ||||
|  | ||||
|     // get each input, change the name? | ||||
|     $.each(source.find('input, select'), function (i, v) { | ||||
|         var obj = $(v); | ||||
|         var name = obj.attr('name').replace('[0]', '[' + index + ']'); | ||||
|         obj.attr('name', name); | ||||
|     }); | ||||
|     // // get each input, change the name? | ||||
|     // $.each(source.find('input, select'), function (i, v) { | ||||
|     //     var obj = $(v); | ||||
|     //     var name = obj.attr('name').replace('[0]', '[' + index + ']'); | ||||
|     //     obj.attr('name', name); | ||||
|     // }); | ||||
|  | ||||
|     source.find('input[name$="][amount]"]').val("").on('input', calculateSum); | ||||
|     if (destAccounts.length > 0) { | ||||
| @@ -74,11 +93,84 @@ function cloneRow() { | ||||
|  | ||||
|     $('.split-table tbody').append(source); | ||||
|  | ||||
|     // remove original click things, add them again: | ||||
|     $('.remove-current-split').unbind('click').click(removeRow); | ||||
|  | ||||
|  | ||||
|     calculateSum(); | ||||
|     resetSplits(); | ||||
|  | ||||
|     return false; | ||||
| } | ||||
|  | ||||
| function resetSplits() { | ||||
|     "use strict"; | ||||
|     // loop rows, reset numbers: | ||||
|  | ||||
|     // update the row split number: | ||||
|     $.each($('table.split-table tbody tr'), function (i, v) { | ||||
|         var row = $(v); | ||||
|         row.attr('data-split', i); | ||||
|         console.log('Row is now ' + row.data('split')); | ||||
|     }); | ||||
|  | ||||
|     // loop each remove button, update the index | ||||
|     $.each($('.remove-current-split'), function (i, v) { | ||||
|         var button = $(v); | ||||
|         button.attr('data-split', i); | ||||
|         button.find('i').attr('data-split', i); | ||||
|         console.log('Remove button index is now ' + button.data('split')); | ||||
|  | ||||
|     }); | ||||
|  | ||||
|     // loop each indicator (#) and update it: | ||||
|     $.each($('td.count'), function (i, v) { | ||||
|         var cell = $(v); | ||||
|         var index = i + 1; | ||||
|         cell.text('#' + index); | ||||
|         console.log('Cell is now ' + cell.text()); | ||||
|     }); | ||||
|  | ||||
|     // loop each possible field. | ||||
|  | ||||
|     // ends with ][description] | ||||
|     $.each($('input[name$="][description]"]'), function (i, v) { | ||||
|         var input = $(v); | ||||
|         input.attr('name', 'transaction[' + i + '][description]'); | ||||
|         console.log('description is now ' + input.attr('name')); | ||||
|     }); | ||||
|     // ends with ][destination_account_name] | ||||
|     $.each($('input[name$="][destination_account_name]"]'), function (i, v) { | ||||
|         var input = $(v); | ||||
|         input.attr('name', 'transaction[' + i + '][destination_account_name]'); | ||||
|         console.log('destination_account_name is now ' + input.attr('name')); | ||||
|     }); | ||||
|     // ends with ][source_account_name] | ||||
|     $.each($('input[name$="][source_account_name]"]'), function (i, v) { | ||||
|         var input = $(v); | ||||
|         input.attr('name', 'transaction[' + i + '][source_account_name]'); | ||||
|         console.log('source_account_name is now ' + input.attr('name')); | ||||
|     }); | ||||
|     // ends with ][amount] | ||||
|     $.each($('input[name$="][amount]"]'), function (i, v) { | ||||
|         var input = $(v); | ||||
|         input.attr('name', 'transaction[' + i + '][amount]'); | ||||
|         console.log('amount is now ' + input.attr('name')); | ||||
|     }); | ||||
|     // ends with ][budget_id] | ||||
|     $.each($('input[name$="][budget_id]"]'), function (i, v) { | ||||
|         var input = $(v); | ||||
|         input.attr('name', 'transaction[' + i + '][budget_id]'); | ||||
|         console.log('budget_id is now ' + input.attr('name')); | ||||
|     }); | ||||
|     // ends with ][category] | ||||
|     $.each($('input[name$="][category]"]'), function (i, v) { | ||||
|         var input = $(v); | ||||
|         input.attr('name', 'transaction[' + i + '][category]'); | ||||
|         console.log('category is now ' + input.attr('name')); | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function calculateSum() { | ||||
|     "use strict"; | ||||
|     var sum = 0; | ||||
|   | ||||
| @@ -41,7 +41,7 @@ | ||||
|                         {{ ExpandedForm.text('journal_description', journal.description) }} | ||||
|  | ||||
|                         {# CURRENCY IS NEW FOR SPLIT JOURNALS #} | ||||
|                         {{ ExpandedForm.select('journal_currency_id', currencies, preFilled.transaction_currency_id) }} | ||||
|                         {{ ExpandedForm.select('currency_id', currencies, preFilled.currency_id) }} | ||||
|  | ||||
|                         {# show source if withdrawal or transfer #} | ||||
|                         {% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %} | ||||
| @@ -218,8 +218,9 @@ | ||||
|                             </thead> | ||||
|                             <tbody> | ||||
|                             {% for index, transaction in preFilled.transactions %} | ||||
|                                 <tr class="{% if loop.index == 1 %}initial-row{% else %}not-initial-row{% endif %}"> | ||||
|                                     <td><a href="#" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></a></td> | ||||
|                                 <tr data-split="{{ loop.index0 }}"> | ||||
|                                     <td><a href="#" class="btn btn-xs btn-danger remove-current-split" data-split="{{ loop.index0 }}"><i | ||||
|                                                     class="fa fa-trash" data-split="{{ loop.index0 }}"></i></a></td> | ||||
|                                     <td class="count">#{{ loop.index }}</td> | ||||
|                                     <td> | ||||
|                                         <input type="text" name="transactions[{{ loop.index0 }}][description]" value="{{ transaction.description }}" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user