mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix small issue with piggy banks.
This commit is contained in:
parent
ecbc0c1778
commit
04290bf9b6
@ -280,6 +280,7 @@ class PiggyBankController extends Controller
|
|||||||
public function postAdd(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
public function postAdd(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||||
{
|
{
|
||||||
$amount = $request->get('amount');
|
$amount = $request->get('amount');
|
||||||
|
Log::debug(sprintf('Found amount is %s', $amount));
|
||||||
/** @var Carbon $date */
|
/** @var Carbon $date */
|
||||||
$date = session('end', Carbon::now()->endOfMonth());
|
$date = session('end', Carbon::now()->endOfMonth());
|
||||||
$leftOnAccount = $piggyBank->leftOnAccount($date);
|
$leftOnAccount = $piggyBank->leftOnAccount($date);
|
||||||
@ -287,7 +288,7 @@ class PiggyBankController extends Controller
|
|||||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||||
$maxAmount = strval(min(round($leftOnAccount, 12), round($leftToSave, 12)));
|
$maxAmount = strval(min(round($leftOnAccount, 12), round($leftToSave, 12)));
|
||||||
|
|
||||||
if (bccomp($amount, $maxAmount) === -1) {
|
if (bccomp($amount, $maxAmount) <= 0) {
|
||||||
$repetition = $piggyBank->currentRelevantRep();
|
$repetition = $piggyBank->currentRelevantRep();
|
||||||
$currentAmount = $repetition->currentamount ?? '0';
|
$currentAmount = $repetition->currentamount ?? '0';
|
||||||
$repetition->currentamount = bcadd($currentAmount, $amount);
|
$repetition->currentamount = bcadd($currentAmount, $amount);
|
||||||
|
@ -24,7 +24,7 @@ $(function () {
|
|||||||
$('.addMoney').on('click', addMoney);
|
$('.addMoney').on('click', addMoney);
|
||||||
$('.removeMoney').on('click', removeMoney);
|
$('.removeMoney').on('click', removeMoney);
|
||||||
|
|
||||||
$('#sortable tbody').sortable(
|
$('#sortable-piggy tbody').sortable(
|
||||||
{
|
{
|
||||||
helper: fixHelper,
|
helper: fixHelper,
|
||||||
stop: stopSorting,
|
stop: stopSorting,
|
||||||
|
14
public/js/lib/jquery-ui.min.js
vendored
14
public/js/lib/jquery-ui.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
|||||||
<table class="table table-hover table-condensed" id="sortable">
|
<table class="table table-hover table-condensed" id="sortable-piggy">
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for piggyBank in piggyBanks %}
|
{% for piggyBank in piggyBanks %}
|
||||||
<tr data-id="{{ piggyBank.id }}">
|
<tr data-id="{{ piggyBank.id }}">
|
||||||
|
@ -9,12 +9,10 @@
|
|||||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'piggyBanks'|_ }}</h3></div>
|
<h3 class="box-title">{{ 'piggyBanks'|_ }}</h3>
|
||||||
<div class="box-body table-responsive no-padding">
|
|
||||||
{% include 'list/piggy-banks' %}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="box-footer">
|
<div class="box-body">
|
||||||
<a href="{{ route('piggy-banks.create') }}" class="btn btn-success pull-right">{{ 'new_piggy_bank'|_ }}</a>
|
{% include 'list/piggy-banks' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Binary file not shown.
@ -8,6 +8,7 @@
|
|||||||
*
|
*
|
||||||
* See the LICENSE file for details.
|
* See the LICENSE file for details.
|
||||||
*/
|
*/
|
||||||
|
use FireflyIII\Models\PiggyBank;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
|
|
||||||
|
|
||||||
@ -131,6 +132,27 @@ class PiggyBankControllerTest extends TestCase
|
|||||||
$this->assertSessionHas('success');
|
$this->assertSessionHas('success');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the exact amount to fill a piggy bank
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Http\Controllers\PiggyBankController::postAdd
|
||||||
|
*/
|
||||||
|
public function testPostAddExact()
|
||||||
|
{
|
||||||
|
// find a piggy with current amount = 0.
|
||||||
|
$piggy = PiggyBank::leftJoin('piggy_bank_repetitions', 'piggy_bank_repetitions.piggy_bank_id', '=', 'piggy_banks.id')
|
||||||
|
->where('currentamount', 0)
|
||||||
|
->first(['piggy_banks.id', 'targetamount']);
|
||||||
|
|
||||||
|
|
||||||
|
$data = ['amount' => strval($piggy->targetamount)];
|
||||||
|
$this->be($this->user());
|
||||||
|
$this->call('post', route('piggy-banks.add', [$piggy->id]), $data);
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
$this->assertRedirectedToRoute('piggy-banks.index');
|
||||||
|
$this->assertSessionHas('success');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\PiggyBankController::postRemove
|
* @covers \FireflyIII\Http\Controllers\PiggyBankController::postRemove
|
||||||
*/
|
*/
|
||||||
|
@ -17,6 +17,9 @@ use FireflyIII\Models\TransactionType;
|
|||||||
*/
|
*/
|
||||||
class TransactionTypeTest extends TestCase
|
class TransactionTypeTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Models\TransactionType::isDeposit
|
||||||
|
*/
|
||||||
public function testIsDeposit()
|
public function testIsDeposit()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -24,18 +27,27 @@ class TransactionTypeTest extends TestCase
|
|||||||
$this->assertTrue($transactionType->isDeposit());
|
$this->assertTrue($transactionType->isDeposit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Models\TransactionType::isOpeningBalance
|
||||||
|
*/
|
||||||
public function testIsOpeningBalance()
|
public function testIsOpeningBalance()
|
||||||
{
|
{
|
||||||
$transactionType = TransactionType::whereType(TransactionType::OPENING_BALANCE)->first();
|
$transactionType = TransactionType::whereType(TransactionType::OPENING_BALANCE)->first();
|
||||||
$this->assertTrue($transactionType->isOpeningBalance());
|
$this->assertTrue($transactionType->isOpeningBalance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Models\TransactionType::isTransfer
|
||||||
|
*/
|
||||||
public function testIsTransfer()
|
public function testIsTransfer()
|
||||||
{
|
{
|
||||||
$transactionType = TransactionType::whereType(TransactionType::TRANSFER)->first();
|
$transactionType = TransactionType::whereType(TransactionType::TRANSFER)->first();
|
||||||
$this->assertTrue($transactionType->isTransfer());
|
$this->assertTrue($transactionType->isTransfer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Models\TransactionType::isWithdrawal
|
||||||
|
*/
|
||||||
public function testIsWithdrawal()
|
public function testIsWithdrawal()
|
||||||
{
|
{
|
||||||
$transactionType = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
|
$transactionType = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
|
||||||
|
Loading…
Reference in New Issue
Block a user