mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Moved leftOnAccount()
This commit is contained in:
parent
ade1cf9c19
commit
fcb5e4eabc
@ -19,7 +19,6 @@ use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||
use FireflyIII\Http\Requests\PiggyBankFormRequest;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Input;
|
||||
@ -53,16 +52,15 @@ class PiggyBankController extends Controller
|
||||
/**
|
||||
* Add money to piggy bank
|
||||
*
|
||||
* @param ARI $repository
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function add(ARI $repository, PiggyBank $piggyBank)
|
||||
public function add(PiggyBank $piggyBank)
|
||||
{
|
||||
/** @var Carbon $date */
|
||||
$date = session('end', Carbon::now()->endOfMonth());
|
||||
$leftOnAccount = $repository->leftOnAccount($piggyBank->account, $date);
|
||||
$leftOnAccount = $piggyBank->leftOnAccount($date);
|
||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount ?? '0';
|
||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||
@ -73,16 +71,15 @@ class PiggyBankController extends Controller
|
||||
/**
|
||||
* Add money to piggy bank (for mobile devices)
|
||||
*
|
||||
* @param ARI $repository
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function addMobile(ARI $repository, PiggyBank $piggyBank)
|
||||
public function addMobile(PiggyBank $piggyBank)
|
||||
{
|
||||
/** @var Carbon $date */
|
||||
$date = session('end', Carbon::now()->endOfMonth());
|
||||
$leftOnAccount = $repository->leftOnAccount($piggyBank->account, $date);
|
||||
$leftOnAccount = $piggyBank->leftOnAccount($date);
|
||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount?? '0';
|
||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||
@ -185,12 +182,11 @@ class PiggyBankController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ARI $repository
|
||||
* @param PiggyBankRepositoryInterface $piggyRepository
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function index(ARI $repository, PiggyBankRepositoryInterface $piggyRepository)
|
||||
public function index(PiggyBankRepositoryInterface $piggyRepository)
|
||||
{
|
||||
/** @var Collection $piggyBanks */
|
||||
$piggyBanks = $piggyRepository->getPiggyBanks();
|
||||
@ -213,7 +209,7 @@ class PiggyBankController extends Controller
|
||||
$accounts[$account->id] = [
|
||||
'name' => $account->name,
|
||||
'balance' => Steam::balanceIgnoreVirtual($account, $end),
|
||||
'leftForPiggyBanks' => $repository->leftOnAccount($account, $end),
|
||||
'leftForPiggyBanks' => $piggyBank->leftOnAccount($end),
|
||||
'sumOfSaved' => strval($piggyBank->savedSoFar),
|
||||
'sumOfTargets' => strval(round($piggyBank->targetamount, 2)),
|
||||
'leftToSave' => $piggyBank->leftToSave,
|
||||
@ -248,17 +244,16 @@ class PiggyBankController extends Controller
|
||||
|
||||
/**
|
||||
* @param PiggyBankRepositoryInterface $repository
|
||||
* @param ARI $accounts
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postAdd(PiggyBankRepositoryInterface $repository, ARI $accounts, PiggyBank $piggyBank)
|
||||
public function postAdd(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
|
||||
{
|
||||
$amount = strval(round(Input::get('amount'), 2));
|
||||
/** @var Carbon $date */
|
||||
$date = session('end', Carbon::now()->endOfMonth());
|
||||
$leftOnAccount = $accounts->leftOnAccount($piggyBank->account, $date);
|
||||
$leftOnAccount = $piggyBank->leftOnAccount($date);
|
||||
$savedSoFar = strval($piggyBank->currentRelevantRep()->currentamount);
|
||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||
$maxAmount = round(min($leftOnAccount, $leftToSave), 2);
|
||||
|
@ -13,9 +13,11 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Crypt;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Steam;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
@ -105,8 +107,6 @@ class PiggyBank extends Model
|
||||
$this->currentRep = $rep;
|
||||
|
||||
return $rep;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,6 +125,27 @@ class PiggyBank extends Model
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function leftOnAccount(Carbon $date): string
|
||||
{
|
||||
|
||||
$balance = Steam::balanceIgnoreVirtual($this->account, $date);
|
||||
/** @var PiggyBank $p */
|
||||
foreach ($this->account->piggyBanks as $piggyBank) {
|
||||
$currentAmount = $piggyBank->currentRelevantRep()->currentamount ?? '0';
|
||||
|
||||
$balance = bcsub($balance, $currentAmount);
|
||||
}
|
||||
|
||||
return $balance;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
|
@ -111,28 +111,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function leftOnAccount(Account $account, Carbon $date): string
|
||||
{
|
||||
|
||||
$balance = Steam::balanceIgnoreVirtual($account, $date);
|
||||
/** @var PiggyBank $p */
|
||||
foreach ($account->piggyBanks()->get() as $p) {
|
||||
$currentAmount = $p->currentRelevantRep()->currentamount ?? '0';
|
||||
|
||||
$balance = bcsub($balance, $currentAmount);
|
||||
}
|
||||
|
||||
return $balance;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date of the very last transaction in this account.
|
||||
*
|
||||
|
@ -60,15 +60,6 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function getFirstTransaction(TransactionJournal $journal, Account $account): Transaction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function leftOnAccount(Account $account, Carbon $date): string;
|
||||
|
||||
/**
|
||||
* Returns the date of the very last transaction in this account.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user