This commit is contained in:
James Cole 2018-04-21 23:48:54 +02:00
parent fb75e2ef02
commit 36329e596e
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
15 changed files with 263 additions and 154 deletions

View File

@ -62,8 +62,8 @@ class PiggyBankEventFactory
$piggyRepos->setUser($journal->user);
// repetition exists?
$repetition = $piggyRepos->getRepetition($piggyBank, $journal->date);
if (null === $repetition->id) {
$repetition = $piggyRepos->getRepetition($piggyBank);
if (null === $repetition) {
Log::error(sprintf('No piggy bank repetition on %s!', $journal->date->format('Y-m-d')));
return null;

View File

@ -25,13 +25,18 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Http\Requests\PiggyBankFormRequest;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Transformers\AccountTransformer;
use FireflyIII\Transformers\PiggyBankTransformer;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Log;
use Preferences;
use Session;
use Steam;
use Symfony\Component\HttpFoundation\ParameterBag;
use View;
/**
@ -39,6 +44,14 @@ use View;
*/
class PiggyBankController extends Controller
{
/** @var AccountRepositoryInterface */
private $accountRepos;
/** @var CurrencyRepositoryInterface */
private $currencyRepos;
/** @var PiggyBankRepositoryInterface */
private $piggyRepos;
/**
*
*/
@ -51,6 +64,10 @@ class PiggyBankController extends Controller
app('view')->share('title', trans('firefly.piggyBanks'));
app('view')->share('mainTitleIcon', 'fa-sort-amount-asc');
$this->piggyRepos = app(PiggyBankRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
$this->accountRepos = app(AccountRepositoryInterface::class);
return $next($request);
}
);
@ -59,43 +76,53 @@ class PiggyBankController extends Controller
/**
* Add money to piggy bank.
*
* @param PiggyBank $piggyBank
*
* @param PiggyBankRepositoryInterface $repository
* @param PiggyBank $piggyBank
*
* @return View
*/
public function add(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository)
public function add(PiggyBank $piggyBank)
{
/** @var Carbon $date */
$date = session('end', Carbon::now()->endOfMonth());
$leftOnAccount = $piggyBank->leftOnAccount($date);
$savedSoFar = $repository->getCurrentAmount($piggyBank);
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, $date);
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
$maxAmount = min($leftOnAccount, $leftToSave);
return view('piggy-banks.add', compact('piggyBank', 'maxAmount'));
// get currency:
$currency = app('amount')->getDefaultCurrency();
$currencyId = (int)$this->accountRepos->getMetaValue($piggyBank->account, 'currency_id');
if ($currencyId > 0) {
$currency = $this->currencyRepos->findNull($currencyId);
}
return view('piggy-banks.add', compact('piggyBank', 'maxAmount', 'currency'));
}
/**
* Add money to piggy bank (for mobile devices).
*
* @param PiggyBank $piggyBank
*
* @param PiggyBankRepositoryInterface $repository
* @param PiggyBank $piggyBank
*
* @return View
*/
public function addMobile(PiggyBank $piggyBank, PiggyBankRepositoryInterface $repository)
public function addMobile(PiggyBank $piggyBank)
{
/** @var Carbon $date */
$date = session('end', Carbon::now()->endOfMonth());
$leftOnAccount = $piggyBank->leftOnAccount($date);
$savedSoFar = $repository->getCurrentAmount($piggyBank);
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, $date);
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
$maxAmount = min($leftOnAccount, $leftToSave);
return view('piggy-banks.add-mobile', compact('piggyBank', 'maxAmount'));
// get currency:
$currency = app('amount')->getDefaultCurrency();
$currencyId = (int)$this->accountRepos->getMetaValue($piggyBank->account, 'currency_id');
if ($currencyId > 0) {
$currency = $this->currencyRepos->findNull($currencyId);
}
return view('piggy-banks.add-mobile', compact('piggyBank', 'maxAmount', 'currency'));
}
/**
@ -131,16 +158,15 @@ class PiggyBankController extends Controller
}
/**
* @param PiggyBankRepositoryInterface $repository
* @param PiggyBank $piggyBank
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
public function destroy(PiggyBank $piggyBank)
{
Session::flash('success', (string)trans('firefly.deleted_piggy_bank', ['name' => $piggyBank->name]));
Preferences::mark();
$repository->destroy($piggyBank);
$this->piggyRepos->destroy($piggyBank);
return redirect($this->getPreviousUri('piggy-banks.delete.uri'));
}
@ -185,53 +211,52 @@ class PiggyBankController extends Controller
/**
* @param Request $request
* @param PiggyBankRepositoryInterface $piggyRepository
*
* @return View
*/
public function index(Request $request, PiggyBankRepositoryInterface $piggyRepository)
public function index(Request $request)
{
$collection = $piggyRepository->getPiggyBanks();
$collection = $this->piggyRepos->getPiggyBanks();
$total = $collection->count();
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
$accounts = [];
/** @var Carbon $end */
$end = session('end', Carbon::now()->endOfMonth());
$accounts = [];
Log::debug('Looping piggues');
/** @var PiggyBank $piggyBank */
foreach ($collection as $piggyBank) {
// transform piggies using the transformer:
$parameters = new ParameterBag;
$parameters->set('end', $end);
$transformed = new Collection;
$transformer = new PiggyBankTransformer(new ParameterBag);
$accountTransformer = new AccountTransformer($parameters);
/** @var PiggyBank $piggy */
foreach ($collection as $piggy) {
$array = $transformer->transform($piggy);
$account = $accountTransformer->transform($piggy->account);
$accountId = $account['id'];
if (!isset($accounts[$accountId])) {
// create new:
$accounts[$accountId] = $account;
$piggyBank->savedSoFar = $piggyRepository->getCurrentAmount($piggyBank);
$piggyBank->percentage = (int)(0 !== bccomp('0', $piggyBank->savedSoFar) ? $piggyBank->savedSoFar / $piggyBank->targetamount * 100 : 0);
$piggyBank->leftToSave = bcsub($piggyBank->targetamount, (string)$piggyBank->savedSoFar);
$piggyBank->percentage = $piggyBank->percentage > 100 ? 100 : $piggyBank->percentage;
// add some interesting details:
$accounts[$accountId]['left'] = $accounts[$accountId]['current_balance'];
$accounts[$accountId]['saved'] = 0;
$accounts[$accountId]['target'] = 0;
$accounts[$accountId]['to_save'] = 0;
}
// Fill account information:
$account = $piggyBank->account;
$new = false;
if (!isset($accounts[$account->id])) {
$new = true;
$accounts[$account->id] = [
'name' => $account->name,
'balance' => Steam::balanceIgnoreVirtual($account, $end),
'leftForPiggyBanks' => $piggyBank->leftOnAccount($end),
'sumOfSaved' => (string)$piggyBank->savedSoFar,
'sumOfTargets' => $piggyBank->targetamount,
'leftToSave' => $piggyBank->leftToSave,
];
}
if (isset($accounts[$account->id]) && false === $new) {
$accounts[$account->id]['sumOfSaved'] = bcadd($accounts[$account->id]['sumOfSaved'], (string)$piggyBank->savedSoFar);
$accounts[$account->id]['sumOfTargets'] = bcadd($accounts[$account->id]['sumOfTargets'], $piggyBank->targetamount);
$accounts[$account->id]['leftToSave'] = bcadd($accounts[$account->id]['leftToSave'], $piggyBank->leftToSave);
}
// calculate new interesting fields:
$accounts[$accountId]['left'] -= $array['current_amount'];
$accounts[$accountId]['saved'] += $array['current_amount'];
$accounts[$accountId]['target'] += $array['target_amount'];
$accounts[$accountId]['to_save'] += ($array['target_amount'] - $array['current_amount']);
$array['account_name'] = $account['name'];
$transformed->push($array);
}
// paginate piggy banks
$collection = $collection->slice(($page - 1) * $pageSize, $pageSize);
$piggyBanks = new LengthAwarePaginator($collection, $total, $pageSize, $page);
$transformed = $transformed->slice(($page - 1) * $pageSize, $pageSize);
$piggyBanks = new LengthAwarePaginator($transformed, $total, $pageSize, $page);
$piggyBanks->setPath(route('piggy-banks.index'));
return view('piggy-banks.index', compact('piggyBanks', 'accounts'));
@ -239,20 +264,19 @@ class PiggyBankController extends Controller
/**
* @param Request $request
* @param PiggyBankRepositoryInterface $repository
*
* @return \Illuminate\Http\JsonResponse
*/
public function order(Request $request, PiggyBankRepositoryInterface $repository)
public function order(Request $request)
{
$data = $request->get('order');
// set all users piggy banks to zero:
$repository->reset();
$this->piggyRepos->reset();
if (is_array($data)) {
foreach ($data as $order => $id) {
$repository->setOrder((int)$id, $order + 1);
$this->piggyRepos->setOrder((int)$id, $order + 1);
}
}
@ -261,17 +285,20 @@ class PiggyBankController extends Controller
/**
* @param Request $request
* @param PiggyBankRepositoryInterface $repository
* @param PiggyBank $piggyBank
*
* @return \Illuminate\Http\RedirectResponse
*/
public function postAdd(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
public function postAdd(Request $request, PiggyBank $piggyBank)
{
$amount = $request->get('amount') ?? '0';
$currency = app('amount')->getDefaultCurrency();
if ($repository->canAddAmount($piggyBank, $amount)) {
$repository->addAmount($piggyBank, $amount);
$currencyId = (int)$this->accountRepos->getMetaValue($piggyBank->account, 'currency_id');
if ($currencyId > 0) {
$currency = $this->currencyRepos->findNull($currencyId);
}
if ($this->piggyRepos->canAddAmount($piggyBank, $amount)) {
$this->piggyRepos->addAmount($piggyBank, $amount);
Session::flash(
'success',
(string)trans(
@ -298,17 +325,20 @@ class PiggyBankController extends Controller
/**
* @param Request $request
* @param PiggyBankRepositoryInterface $repository
* @param PiggyBank $piggyBank
*
* @return \Illuminate\Http\RedirectResponse
*/
public function postRemove(Request $request, PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
public function postRemove(Request $request, PiggyBank $piggyBank)
{
$amount = $request->get('amount') ?? '0';
$currency = app('amount')->getDefaultCurrency();
if ($repository->canRemoveAmount($piggyBank, $amount)) {
$repository->removeAmount($piggyBank, $amount);
$currencyId = (int)$this->accountRepos->getMetaValue($piggyBank->account, 'currency_id');
if ($currencyId > 0) {
$currency = $this->currencyRepos->findNull($currencyId);
}
if ($this->piggyRepos->canRemoveAmount($piggyBank, $amount)) {
$this->piggyRepos->removeAmount($piggyBank, $amount);
Session::flash(
'success',
(string)trans(
@ -341,7 +371,15 @@ class PiggyBankController extends Controller
*/
public function remove(PiggyBank $piggyBank)
{
return view('piggy-banks.remove', compact('piggyBank'));
$repetition = $this->piggyRepos->getRepetition($piggyBank);
// get currency:
$currency = app('amount')->getDefaultCurrency();
$currencyId = (int)$this->accountRepos->getMetaValue($piggyBank->account, 'currency_id');
if ($currencyId > 0) {
$currency = $this->currencyRepos->findNull($currencyId);
}
return view('piggy-banks.remove', compact('piggyBank', 'repetition', 'currency'));
}
/**
@ -353,19 +391,27 @@ class PiggyBankController extends Controller
*/
public function removeMobile(PiggyBank $piggyBank)
{
return view('piggy-banks.remove-mobile', compact('piggyBank'));
$repetition = $this->piggyRepos->getRepetition($piggyBank);
// get currency:
$currency = app('amount')->getDefaultCurrency();
$currencyId = (int)$this->accountRepos->getMetaValue($piggyBank->account, 'currency_id');
if ($currencyId > 0) {
$currency = $this->currencyRepos->findNull($currencyId);
}
return view('piggy-banks.remove-mobile', compact('piggyBank', 'repetition', 'currency'));
}
/**
* @param PiggyBankRepositoryInterface $repository
* @param PiggyBank $piggyBank
*
* @return View
*/
public function show(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank)
public function show(PiggyBank $piggyBank)
{
$note = $piggyBank->notes()->first();
$events = $repository->getEvents($piggyBank);
$events = $this->piggyRepos->getEvents($piggyBank);
$subTitle = $piggyBank->name;
return view('piggy-banks.show', compact('piggyBank', 'events', 'subTitle', 'note'));
@ -373,17 +419,16 @@ class PiggyBankController extends Controller
/**
* @param PiggyBankFormRequest $request
* @param PiggyBankRepositoryInterface $repository
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function store(PiggyBankFormRequest $request, PiggyBankRepositoryInterface $repository)
public function store(PiggyBankFormRequest $request)
{
$data = $request->getPiggyBankData();
if (null === $data['startdate']) {
$data['startdate'] = new Carbon;
}
$piggyBank = $repository->store($data);
$piggyBank = $this->piggyRepos->store($data);
Session::flash('success', (string)trans('firefly.stored_piggy_bank', ['name' => $piggyBank->name]));
Preferences::mark();
@ -400,16 +445,15 @@ class PiggyBankController extends Controller
}
/**
* @param PiggyBankRepositoryInterface $repository
* @param PiggyBankFormRequest $request
* @param PiggyBank $piggyBank
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function update(PiggyBankRepositoryInterface $repository, PiggyBankFormRequest $request, PiggyBank $piggyBank)
public function update(PiggyBankFormRequest $request, PiggyBank $piggyBank)
{
$data = $request->getPiggyBankData();
$piggyBank = $repository->update($piggyBank, $data);
$piggyBank = $this->piggyRepos->update($piggyBank, $data);
Session::flash('success', (string)trans('firefly.updated_piggy_bank', ['name' => $piggyBank->name]));
Preferences::mark();

View File

@ -65,7 +65,6 @@ class PiggyBankFormRequest extends Request
'name' => $nameRule,
'account_id' => 'required|belongsToUser:accounts',
'targetamount' => 'required|numeric|more:0',
'amount_currency_id_targetamount' => 'required|exists:transaction_currencies,id',
'startdate' => 'date',
'targetdate' => 'date|nullable',
'order' => 'integer|min:1',

View File

@ -197,8 +197,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
*/
public function getCurrentAmount(PiggyBank $piggyBank): string
{
/** @var PiggyBankRepetition $rep */
$rep = $piggyBank->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']);
$rep = $this->getRepetition($piggyBank);
if (null === $rep) {
return '0';
}
@ -301,19 +300,40 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
}
/**
* @param PiggyBank $piggyBank
*
* @return PiggyBankRepetition|null
*/
public function getRepetition(PiggyBank $piggyBank): ?PiggyBankRepetition
{
return $piggyBank->piggyBankRepetitions()->first();
}
/**
* Get for piggy account what is left to put in piggies.
*
* @param PiggyBank $piggyBank
* @param Carbon $date
*
* @return PiggyBankRepetition
* @return string
*/
public function getRepetition(PiggyBank $piggyBank, Carbon $date): PiggyBankRepetition
public function leftOnAccount(PiggyBank $piggyBank, Carbon $date): string
{
$repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($date)->first();
if (null === $repetition) {
return new PiggyBankRepetition;
$balance = app('steam')->balanceIgnoreVirtual($piggyBank->account, $date);
/** @var Collection $piggies */
$piggies = $piggyBank->account->piggyBanks;
/** @var PiggyBank $current */
foreach ($piggies as $current) {
$repetition = $this->getRepetition($current);
if(null !== $repetition) {
$balance = bcsub($balance, $repetition->currentamount);
}
}
return $repetition;
return $balance;
}
/**

View File

@ -162,12 +162,21 @@ interface PiggyBankRepositoryInterface
public function getPiggyBanksWithAmount(): Collection;
/**
* @param PiggyBank $piggyBank
*
* @return PiggyBankRepetition|null
*/
public function getRepetition(PiggyBank $piggyBank): ?PiggyBankRepetition;
/**
* Get for piggy account what is left to put in piggies.
*
* @param PiggyBank $piggyBank
* @param Carbon $date
*
* @return PiggyBankRepetition
* @return string
*/
public function getRepetition(PiggyBank $piggyBank, Carbon $date): PiggyBankRepetition;
public function leftOnAccount(PiggyBank $piggyBank, Carbon $date): string;
/**
* @param PiggyBank $piggyBank

View File

@ -151,13 +151,15 @@ class AccountTransformer extends TransformerAbstract
if ($type !== AccountType::ASSET || (string)$role === '') {
$role = null;
}
$currencyId = (int)$this->repository->getMetaValue($account, 'currency_id');
$currencyCode = null;
$decimalPlaces = 2;
$currencyId = (int)$this->repository->getMetaValue($account, 'currency_id');
$currencyCode = null;
$currencySymbol = null;
$decimalPlaces = 2;
if ($currencyId > 0) {
$currency = TransactionCurrency::find($currencyId);
$currencyCode = $currency->code;
$decimalPlaces = $currency->decimal_places;
$currency = TransactionCurrency::find($currencyId);
$currencyCode = $currency->code;
$decimalPlaces = $currency->decimal_places;
$currencySymbol = $currency->symbol;
}
$date = new Carbon;
@ -196,6 +198,8 @@ class AccountTransformer extends TransformerAbstract
'type' => $type,
'currency_id' => $currencyId,
'currency_code' => $currencyCode,
'currency_symbol' => $currencySymbol,
'currency_dp' => $decimalPlaces,
'current_balance' => round(app('steam')->balance($account, $date), $decimalPlaces),
'current_balance_date' => $date->format('Y-m-d'),
'notes' => $this->repository->getNoteText($account),

View File

@ -24,8 +24,10 @@ declare(strict_types=1);
namespace FireflyIII\Transformers;
use FireflyIII\Models\Account;
use FireflyIII\Models\Note;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use League\Fractal\Resource\Collection as FractalCollection;
@ -116,39 +118,60 @@ class PiggyBankTransformer extends TransformerAbstract
*/
public function transform(PiggyBank $piggyBank): array
{
$account = $piggyBank->account;
$currencyId = (int)$account->getMeta('currency_id');
$decimalPlaces = 2;
/** @var Account $account */
$account = $piggyBank->account;
/** @var AccountRepositoryInterface $accountRepos */
$accountRepos = app(AccountRepositoryInterface::class);
$accountRepos->setUser($account->user);
$currencyId = (int)$accountRepos->getMetaValue($account, 'currency_id');
if ($currencyId === 0) {
$currency = app('amount')->getDefaultCurrencyByUser($account->user);
}
if ($currencyId > 0) {
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$repository->setUser($account->user);
$currency = $repository->findNull($currencyId);
$decimalPlaces = $currency->decimal_places;
$currency = $repository->findNull($currencyId);
}
$decimalPlaces = $currency->decimal_places;
// get currently saved amount:
/** @var PiggyBankRepositoryInterface $piggyRepos */
$piggyRepos = app(PiggyBankRepositoryInterface::class);
$piggyRepos->setUser($account->user);
$currentAmount = round($piggyRepos->getCurrentAmount($piggyBank), $decimalPlaces);
// current amount in piggy bank:
$currentAmountStr = $piggyRepos->getCurrentAmount($piggyBank);
$currentAmount = round($currentAmountStr, $decimalPlaces);
// left to save to target:
$leftToSave = bcsub($piggyBank->targetamount, $currentAmountStr);
$startDate = null === $piggyBank->startdate ? null : $piggyBank->startdate->format('Y-m-d');
$targetDate = null === $piggyBank->targetdate ? null : $piggyBank->targetdate->format('Y-m-d');
$targetAmount = round($piggyBank->targetamount, $decimalPlaces);
$percentage = (int)(0 !== bccomp('0', $currentAmountStr) ? $currentAmount / $targetAmount * 100 : 0);
$data = [
'id' => (int)$piggyBank->id,
'updated_at' => $piggyBank->updated_at->toAtomString(),
'created_at' => $piggyBank->created_at->toAtomString(),
'name' => $piggyBank->name,
'target_amount' => $targetAmount,
'current_amount' => $currentAmount,
'startdate' => $startDate,
'targetdate' => $targetDate,
'order' => (int)$piggyBank->order,
'active' => (int)$piggyBank->active === 1,
'notes' => null,
'links' => [
'id' => (int)$piggyBank->id,
'updated_at' => $piggyBank->updated_at->toAtomString(),
'created_at' => $piggyBank->created_at->toAtomString(),
'name' => $piggyBank->name,
'currency_id' => $currency->id,
'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol,
'currency_dp' => $currency->decimal_places,
'target_amount' => $targetAmount,
'percentage' => $percentage,
'current_amount' => $currentAmount,
'left_to_save' => round($leftToSave, $decimalPlaces),
'startdate' => $startDate,
'targetdate' => $targetDate,
'order' => (int)$piggyBank->order,
'active' => (int)$piggyBank->active === 1,
'notes' => null,
'links' => [
[
'rel' => 'self',
'uri' => '/piggy_banks/' . $piggyBank->id,

View File

@ -13,15 +13,15 @@
</tr>
</thead>
<tbody>
{% for piggyBank in piggyBanks %}
<tr data-id="{{ piggyBank.id }}">
{% for piggy in piggyBanks %}
<tr data-id="{{ piggy.id }}">
<td class="visible-xs visible-sm hidden-md hidden-lg">
&nbsp;
</td>
<td class="visible-xs visible-sm hidden-md hidden-lg">
<div class="btn-group btn-group-xs">
<a href="{{ route('piggy-banks.remove-money-mobile', piggyBank.id) }}" class="btn btn-default btn-xs"><i class="fa fa-minus"></i></a>
<a href="{{ route('piggy-banks.add-money-mobile', piggyBank.id) }}" class="btn btn-default btn-xs"><i class="fa fa-plus"></i></a>
<a href="{{ route('piggy-banks.remove-money-mobile', piggy.id) }}" class="btn btn-default btn-xs"><i class="fa fa-minus"></i></a>
<a href="{{ route('piggy-banks.add-money-mobile', piggy.id) }}" class="btn btn-default btn-xs"><i class="fa fa-plus"></i></a>
</div>
</td>
<td style="width:60px;" class="hidden-sm hidden-xs">
@ -30,53 +30,53 @@
</td>
<td style="width:100px;" class="hidden-sm hidden-xs">
<div class="btn-group btn-group-xs">
<a href="{{ route('piggy-banks.edit', piggyBank.id) }}" class="btn btn-default btn-xs"><i class="fa fa-pencil fa-fw"></i></a>
<a href="{{ route('piggy-banks.delete', piggyBank.id) }}" class="btn btn-danger btn-xs"><i class="fa fa-trash fa-fw"></i></a>
<a href="{{ route('piggy-banks.edit', piggy.id) }}" class="btn btn-default btn-xs"><i class="fa fa-pencil fa-fw"></i></a>
<a href="{{ route('piggy-banks.delete', piggy.id) }}" class="btn btn-danger btn-xs"><i class="fa fa-trash fa-fw"></i></a>
</div>
</td>
<td>
<a href="{{ route('piggy-banks.show', piggyBank.id) }}" title="{{ piggyBank.account.name }}">{{ piggyBank.name }}</a>
<a href="{{ route('piggy-banks.show', piggy.id) }}" title="{{ piggy.account_name }}">{{ piggy.name }}</a>
</td>
<td style="text-align: right;" class="piggySaved">
<span title="Saved so far" style="text-align:right;">{{ piggyBank.savedSoFar|formatAmount }}</span>
<span title="Saved so far" style="text-align:right;">{{ formatAmountBySymbol(piggy.current_amount,piggy.currency_symbol,piggy.currency_dp) }}</span>
</td>
<td class="hidden-sm hidden-xs" style="text-align:right;width:40px;">
{% if piggyBank.savedSoFar > 0 %}
<a href="{{ route('piggy-banks.remove-money', piggyBank.id) }}" class="btn btn-default btn-xs removeMoney" data-id="{{ piggyBank.id }}">
<i data-id="{{ piggyBank.id }}" class="fa fa-minus"></i></a>
{% if piggy.current_amount > 0 %}
<a href="{{ route('piggy-banks.remove-money', piggy.id) }}" class="btn btn-default btn-xs removeMoney" data-id="{{ piggy.id }}">
<i data-id="{{ piggy.id }}" class="fa fa-minus"></i></a>
{% endif %}
</td>
<td class="hidden-sm hidden-xs piggyBar">
<div class="progress progress" style="margin-bottom:0;">
<div
{% if piggyBank.percentage == 100 %}
{% if piggy.percentage == 100 %}
class="progress-bar progress-bar-success"
{% elseif piggyBank.percentage == 0 %}
{% elseif piggy.percentage == 0 %}
class="progress-bar progress-bar-warning"
{% else %}
class="progress-bar progress-bar-info"
{% endif %}
role="progressbar" aria-valuenow="{{ piggyBank.percentage }}" aria-valuemin="0" aria-valuemax="100"
style="min-width: 30px;width: {{ piggyBank.percentage }}%;">
{{ piggyBank.percentage }}%
role="progressbar" aria-valuenow="{{ piggy.percentage }}" aria-valuemin="0" aria-valuemax="100"
style="min-width: 30px;width: {{ piggy.percentage }}%;">
{{ piggy.percentage }}%
</div>
</div>
</td>
<td class="hidden-sm hidden-xs" style="width:40px;">
{% if piggyBank.leftToSave > 0 %}
<a href="{{ route('piggy-banks.add-money', piggyBank.id) }}" class="btn btn-default btn-xs addMoney" data-id="{{ piggyBank.id }}">
<i data-id="{{ piggyBank.id }}" class="fa fa-plus"></i></a>
{% if piggy.left_to_save > 0 %}
<a href="{{ route('piggy-banks.add-money', piggy.id) }}" class="btn btn-default btn-xs addMoney" data-id="{{ piggy.id }}">
<i data-id="{{ piggy.id }}" class="fa fa-plus"></i></a>
{% endif %}
</td>
<td class="hidden-sm hidden-xs" style="width:200px;text-align:right;">
<span title="{{ 'target_amount'|_ }}">{{ piggyBank.targetamount|formatAmount }}</span>
<td class="hidden-sm hidden-xs" style="text-align:right;">
<span title="{{ 'target_amount'|_ }}">{{ formatAmountBySymbol(piggy.target_amount,piggy.currency_symbol,piggy.currency_dp) }}</span>
</td>
<td class="hidden-sm hidden-xs" style="width:200px;text-align:right;">
{% if piggyBank.leftToSave > 0 %}
<span title="{{ 'left_to_save'|_ }}">{{ piggyBank.leftToSave|formatAmount }}</span>
<td class="hidden-sm hidden-xs" style="text-align:right;">
{% if piggy.left_to_save > 0 %}
<span title="{{ 'left_to_save'|_ }}">{{ formatAmountBySymbol(piggy.left_to_save,piggy.currency_symbol,piggy.currency_dp) }}</span>
{% endif %}
</td>
</tr>

View File

@ -16,11 +16,11 @@
<div class="box-body">
{% if maxAmount > 0 %}
<p>
{{ 'max_amount_add'|_ }}: {{ maxAmount|formatAmount }}.
{{ 'max_amount_add'|_ }}: {{ formatAmountByCurrency(currency,maxAmount) }}.
</p>
<div class="input-group">
<div class="input-group-addon">{{ getCurrencySymbol()|raw }}</div>
<div class="input-group-addon">{{ currency.symbol|raw }}</div>
<input step="any" class="form-control" id="amount" autocomplete="off" name="amount" max="{{ maxAmount|round(2) }}"
type="number"/>
</div>

View File

@ -11,12 +11,12 @@
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
<p>
{{ 'max_amount_add'|_ }}: {{ maxAmount|formatAmount }}.
{{ 'max_amount_add'|_ }}: {{ formatAmountByCurrency(currency,maxAmount) }}.
</p>
<div class="input-group">
<div class="input-group-addon">{{ getCurrencySymbol()|raw }}</div>
<input step="any" class="form-control" id="amount" autocomplete="off" name="amount" max="{{ maxAmount|round(2) }}" type="number"/>
<div class="input-group-addon">{{ currency.symbol|raw }}</div>
<input step="any" class="form-control" id="amount" autocomplete="off" name="amount" max="{{ maxAmount|round(currency.decimal_places) }}" type="number"/>
</div>
</div>
<div class="modal-footer">

View File

@ -19,7 +19,7 @@
{{ ExpandedForm.text('name') }}
{{ ExpandedForm.assetAccountList('account_id', null, {label: 'saveOnAccount'|_ }) }}
{{ ExpandedForm.amount('targetamount') }}
{{ ExpandedForm.amountNoCurrency('targetamount') }}
</div>
</div>

View File

@ -20,7 +20,7 @@
{{ ExpandedForm.text('name') }}
{{ ExpandedForm.assetAccountList('account_id', null, {label: 'saveOnAccount'|_ }) }}
{{ ExpandedForm.amount('targetamount') }}
{{ ExpandedForm.amountNoCurrency('targetamount') }}
</div>
</div>

View File

@ -5,7 +5,7 @@
{% endblock %}
{% block content %}
{% if piggyBanks.count == 0 %}
{% if piggyBanks|length == 0 %}
{% include 'partials.empty' with {what: 'default', type: 'piggies',route: route('piggy-banks.create')} %}
{% else %}
<div class="row">
@ -49,11 +49,21 @@
{% for id,info in accounts %}
<tr>
<td><a href="{{ route('accounts.show',id) }}" title="{{ info.name }}">{{ info.name }}</a></td>
<td style="text-align:right;" class="hidden-sm hidden-xs">{{ info.balance|formatAmount }}</td>
<td style="text-align:right;">{{ info.leftForPiggyBanks|formatAmount }}</td>
<td style="text-align:right;" class="hidden-sm hidden-xs">{{ info.sumOfTargets|formatAmount }}</td>
<td style="text-align:right;" class="hidden-sm hidden-xs">{{ info.sumOfSaved|formatAmount }}</td>
<td style="text-align:right;" class="hidden-sm hidden-xs">{{ info.leftToSave|formatAmount }}</td>
<td style="text-align:right;" class="hidden-sm hidden-xs">
{{ formatAmountBySymbol(info.current_balance,info.currency_symbol,info.currency_dp) }}
</td>
<td style="text-align:right;">
{{ formatAmountBySymbol(info.left,info.currency_symbol,info.currency_dp) }}
</td>
<td style="text-align:right;" class="hidden-sm hidden-xs">
{{ formatAmountBySymbol(info.target,info.currency_symbol,info.currency_dp) }}
</td>
<td style="text-align:right;" class="hidden-sm hidden-xs">
{{ formatAmountBySymbol(info.saved,info.currency_symbol,info.currency_dp) }}
</td>
<td style="text-align:right;" class="hidden-sm hidden-xs">
{{ formatAmountBySymbol(info.to_save,info.currency_symbol,info.currency_dp) }}
</td>
</tr>
{% endfor %}
</tbody>

View File

@ -15,12 +15,12 @@
<div class="box-body">
<p>
{{ 'max_amount_remove'|_ }}: {{ currentRelevantRepAmount(piggyBank)|formatAmount }}.
{{ 'max_amount_remove'|_ }}: {{ formatAmountByCurrency(currency, repetition.currentamount) }}.
</p>
<div class="input-group">
<div class="input-group-addon">{{ getCurrencySymbol()|raw }}</div>
<input step="any" class="form-control" id="amount" autocomplete="off" name="amount" max="{{ currentRelevantRepAmount(piggyBank) }}"
<div class="input-group-addon">{{ currency.symbol|raw }}</div>
<input step="any" class="form-control" id="amount" autocomplete="off" name="amount" max="{{ repetition.currentamount }}"
type="number"/>
</div>
<p>

View File

@ -11,12 +11,12 @@
<div class="modal-body">
<p>
{{ 'max_amount_remove'|_ }}: {{ currentRelevantRepAmount(piggyBank)|formatAmount }}.
{{ 'max_amount_remove'|_ }}: {{ formatAmountByCurrency(currency, repetition.currentamount) }}.
</p>
<div class="input-group">
<div class="input-group-addon">{{ getCurrencySymbol()|raw }}</div>
<input step="any" class="form-control" id="amount" autocomplete="off" name="amount" max="{{ currentRelevantRepAmount(piggyBank)|round(2) }}"
<div class="input-group-addon">{{ currency.symbol|raw }}</div>
<input step="any" class="form-control" id="amount" autocomplete="off" name="amount" max="{{ repetition.currentamount }}"
type="number">
</div>
</div>