mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-03 19:16:51 +00:00
Fix #10413
This commit is contained in:
@@ -63,6 +63,12 @@ class EditController extends Controller
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function resetHistory(PiggyBank $piggyBank): RedirectResponse {
|
||||||
|
$this->piggyRepos->resetHistory($piggyBank);
|
||||||
|
session()->flash('success', (string) trans('firefly.piggy_history_reset'));
|
||||||
|
return redirect(route('piggy-banks.show', [$piggyBank->id]));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit a piggy bank.
|
* Edit a piggy bank.
|
||||||
*
|
*
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Repositories\PiggyBank;
|
namespace FireflyIII\Repositories\PiggyBank;
|
||||||
|
|
||||||
|
use FireflyIII\Events\Model\PiggyBank\ChangedAmount;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
@@ -438,4 +439,14 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
|
|||||||
|
|
||||||
return $search->take($limit)->get(['piggy_banks.*']);
|
return $search->take($limit)->get(['piggy_banks.*']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function resetHistory(PiggyBank $piggyBank): void
|
||||||
|
{
|
||||||
|
$piggyBank->piggyBankEvents()->delete();
|
||||||
|
foreach($piggyBank->accounts as $account) {
|
||||||
|
if(0 !== bccomp('0',$account->pivot->current_amount)) {
|
||||||
|
event(new ChangedAmount($piggyBank, $account->pivot->current_amount, null, null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,7 @@ use FireflyIII\Models\TransactionJournal;
|
|||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Contracts\Auth\Authenticatable;
|
use Illuminate\Contracts\Auth\Authenticatable;
|
||||||
|
use Illuminate\Routing\Redirector;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,6 +48,8 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
interface PiggyBankRepositoryInterface
|
interface PiggyBankRepositoryInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public function resetHistory(PiggyBank $piggyBank): void;
|
||||||
public function addAmount(PiggyBank $piggyBank, Account $account, string $amount, ?TransactionJournal $journal = null): bool;
|
public function addAmount(PiggyBank $piggyBank, Account $account, string $amount, ?TransactionJournal $journal = null): bool;
|
||||||
|
|
||||||
public function addAmountToPiggyBank(PiggyBank $piggyBank, string $amount, TransactionJournal $journal): void;
|
public function addAmountToPiggyBank(PiggyBank $piggyBank, string $amount, TransactionJournal $journal): void;
|
||||||
|
@@ -24,4 +24,12 @@ $(function () {
|
|||||||
if (typeof(lineChart) === 'function' && typeof(piggyBankID) !== 'undefined') {
|
if (typeof(lineChart) === 'function' && typeof(piggyBankID) !== 'undefined') {
|
||||||
lineChart('chart/piggy-bank/' + piggyBankID, 'piggy-bank-history');
|
lineChart('chart/piggy-bank/' + piggyBankID, 'piggy-bank-history');
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
// on submit of logout button:
|
||||||
|
$('.reset-link').click(function(e) {
|
||||||
|
console.log('here we are');
|
||||||
|
e.preventDefault();
|
||||||
|
document.getElementById('reset-form').submit();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@@ -2486,6 +2486,10 @@ return [
|
|||||||
'left_for_piggy_banks' => 'Left for piggy banks',
|
'left_for_piggy_banks' => 'Left for piggy banks',
|
||||||
'sum_of_piggy_banks' => 'Sum of piggy banks',
|
'sum_of_piggy_banks' => 'Sum of piggy banks',
|
||||||
'saved_so_far' => 'Saved so far',
|
'saved_so_far' => 'Saved so far',
|
||||||
|
'saved_so_far_total' => 'Saved so far in total',
|
||||||
|
'reset_history' => 'reset history',
|
||||||
|
'reset_history_confirm' => 'Are you sure you want to reset the history of this piggy bank? This will make the chart match the piggy bank\'s amount again.',
|
||||||
|
'piggy_history_reset' => 'The piggy bank history has been reset',
|
||||||
'left_to_save' => 'Left to save',
|
'left_to_save' => 'Left to save',
|
||||||
'suggested_amount' => 'Suggested monthly amount to save',
|
'suggested_amount' => 'Suggested monthly amount to save',
|
||||||
'add_money_to_piggy_title' => 'Add money to piggy bank ":name"',
|
'add_money_to_piggy_title' => 'Add money to piggy bank ":name"',
|
||||||
|
@@ -54,8 +54,20 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% for account in piggy.accounts %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
{{ 'saved_so_far'|_ }}
|
||||||
|
(<a href="{{ route('accounts.show', account.id) }}">{{ account.name }}</a>)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ formatAmountBySymbol(account.current_amount, piggy.currency_symbol, piggy.currency_decimal_places) }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ 'saved_so_far'|_ }}</td>
|
<td>{{ 'saved_so_far_total'|_ }}</td>
|
||||||
<td>
|
<td>
|
||||||
{{ formatAmountBySymbol(piggy.current_amount, piggy.currency_symbol, piggy.currency_decimal_places) }}
|
{{ formatAmountBySymbol(piggy.current_amount, piggy.currency_symbol, piggy.currency_decimal_places) }}
|
||||||
</td>
|
</td>
|
||||||
@@ -102,7 +114,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'event_history'|_ }}</h3>
|
<h3 class="box-title">{{ 'event_history'|_ }} (<a onclick="return confirm('{{ 'reset_history_confirm'|_|escape('js') }}');" class="reset-link" href="#">{{ 'reset_history'|_ }}</a>)</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body no-padding" id="piggyEvents">
|
<div class="box-body no-padding" id="piggyEvents">
|
||||||
{% include 'list/piggy-bank-events' %}
|
{% include 'list/piggy-bank-events' %}
|
||||||
@@ -140,6 +152,9 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
<form id="reset-form" action="{{ route('piggy-banks.reset', [piggyBank.id]) }}" method="POST" style="display: none;">
|
||||||
|
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
|
||||||
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
|
@@ -803,6 +803,7 @@ Route::group(
|
|||||||
Route::post('store', ['uses' => 'PiggyBank\CreateController@store', 'as' => 'store']);
|
Route::post('store', ['uses' => 'PiggyBank\CreateController@store', 'as' => 'store']);
|
||||||
Route::post('update/{piggyBank}', ['uses' => 'PiggyBank\EditController@update', 'as' => 'update']);
|
Route::post('update/{piggyBank}', ['uses' => 'PiggyBank\EditController@update', 'as' => 'update']);
|
||||||
Route::post('destroy/{piggyBank}', ['uses' => 'PiggyBank\DeleteController@destroy', 'as' => 'destroy']);
|
Route::post('destroy/{piggyBank}', ['uses' => 'PiggyBank\DeleteController@destroy', 'as' => 'destroy']);
|
||||||
|
Route::post('reset-history/{piggyBank}', ['uses' => 'PiggyBank\EditController@resetHistory', 'as' => 'reset']);
|
||||||
Route::post('add/{piggyBank}', ['uses' => 'PiggyBank\AmountController@postAdd', 'as' => 'add']);
|
Route::post('add/{piggyBank}', ['uses' => 'PiggyBank\AmountController@postAdd', 'as' => 'add']);
|
||||||
Route::post('remove/{piggyBank}', ['uses' => 'PiggyBank\AmountController@postRemove', 'as' => 'remove']);
|
Route::post('remove/{piggyBank}', ['uses' => 'PiggyBank\AmountController@postRemove', 'as' => 'remove']);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user