mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-19 19:01:39 +00:00
Piggies can have no target amount.
This commit is contained in:
@@ -55,7 +55,7 @@ class AmountController extends Controller
|
|||||||
|
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
app('view')->share('title', (string)trans('firefly.piggyBanks'));
|
app('view')->share('title', (string) trans('firefly.piggyBanks'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-bullseye');
|
app('view')->share('mainTitleIcon', 'fa-bullseye');
|
||||||
|
|
||||||
$this->piggyRepos = app(PiggyBankRepositoryInterface::class);
|
$this->piggyRepos = app(PiggyBankRepositoryInterface::class);
|
||||||
@@ -77,8 +77,11 @@ class AmountController extends Controller
|
|||||||
{
|
{
|
||||||
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, today(config('app.timezone')));
|
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, today(config('app.timezone')));
|
||||||
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
|
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
|
||||||
|
$maxAmount = $leftOnAccount;
|
||||||
|
if (0.000 !== (float) $piggyBank->targetamount) {
|
||||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||||
|
}
|
||||||
$currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency();
|
$currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency();
|
||||||
|
|
||||||
return view('piggy-banks.add', compact('piggyBank', 'maxAmount', 'currency'));
|
return view('piggy-banks.add', compact('piggyBank', 'maxAmount', 'currency'));
|
||||||
@@ -97,8 +100,12 @@ class AmountController extends Controller
|
|||||||
$date = session('end', today(config('app.timezone')));
|
$date = session('end', today(config('app.timezone')));
|
||||||
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, $date);
|
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, $date);
|
||||||
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
|
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
|
||||||
|
$maxAmount = $leftOnAccount;
|
||||||
|
|
||||||
|
if (0.000 !== (float) $piggyBank->targetamount) {
|
||||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||||
|
}
|
||||||
$currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency();
|
$currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency();
|
||||||
|
|
||||||
return view('piggy-banks.add-mobile', compact('piggyBank', 'maxAmount', 'currency'));
|
return view('piggy-banks.add-mobile', compact('piggyBank', 'maxAmount', 'currency'));
|
||||||
@@ -125,7 +132,7 @@ class AmountController extends Controller
|
|||||||
$this->piggyRepos->createEvent($piggyBank, $amount);
|
$this->piggyRepos->createEvent($piggyBank, $amount);
|
||||||
session()->flash(
|
session()->flash(
|
||||||
'success',
|
'success',
|
||||||
(string)trans(
|
(string) trans(
|
||||||
'firefly.added_amount_to_piggy',
|
'firefly.added_amount_to_piggy',
|
||||||
['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => $piggyBank->name]
|
['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => $piggyBank->name]
|
||||||
)
|
)
|
||||||
@@ -138,7 +145,7 @@ class AmountController extends Controller
|
|||||||
Log::error('Cannot add ' . $amount . ' because canAddAmount returned false.');
|
Log::error('Cannot add ' . $amount . ' because canAddAmount returned false.');
|
||||||
session()->flash(
|
session()->flash(
|
||||||
'error',
|
'error',
|
||||||
(string)trans(
|
(string) trans(
|
||||||
'firefly.cannot_add_amount_piggy',
|
'firefly.cannot_add_amount_piggy',
|
||||||
['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => e($piggyBank->name)]
|
['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => e($piggyBank->name)]
|
||||||
)
|
)
|
||||||
@@ -167,7 +174,7 @@ class AmountController extends Controller
|
|||||||
$this->piggyRepos->removeAmount($piggyBank, $amount);
|
$this->piggyRepos->removeAmount($piggyBank, $amount);
|
||||||
session()->flash(
|
session()->flash(
|
||||||
'success',
|
'success',
|
||||||
(string)trans(
|
(string) trans(
|
||||||
'firefly.removed_amount_from_piggy',
|
'firefly.removed_amount_from_piggy',
|
||||||
['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => $piggyBank->name]
|
['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => $piggyBank->name]
|
||||||
)
|
)
|
||||||
@@ -176,11 +183,11 @@ class AmountController extends Controller
|
|||||||
|
|
||||||
return redirect(route('piggy-banks.index'));
|
return redirect(route('piggy-banks.index'));
|
||||||
}
|
}
|
||||||
$amount = number_format((float)$request->get('amount'), 12, '.', '');
|
$amount = number_format((float) $request->get('amount'), 12, '.', '');
|
||||||
|
|
||||||
session()->flash(
|
session()->flash(
|
||||||
'error',
|
'error',
|
||||||
(string)trans(
|
(string) trans(
|
||||||
'firefly.cannot_remove_from_piggy',
|
'firefly.cannot_remove_from_piggy',
|
||||||
['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => e($piggyBank->name)]
|
['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => e($piggyBank->name)]
|
||||||
)
|
)
|
||||||
|
@@ -30,6 +30,7 @@ use FireflyIII\Http\Requests\PiggyBankUpdateRequest;
|
|||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
|
use Amount;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Routing\Redirector;
|
use Illuminate\Routing\Redirector;
|
||||||
@@ -55,7 +56,7 @@ class EditController extends Controller
|
|||||||
|
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
app('view')->share('title', (string)trans('firefly.piggyBanks'));
|
app('view')->share('title', (string) trans('firefly.piggyBanks'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-bullseye');
|
app('view')->share('mainTitleIcon', 'fa-bullseye');
|
||||||
|
|
||||||
$this->attachments = app(AttachmentHelperInterface::class);
|
$this->attachments = app(AttachmentHelperInterface::class);
|
||||||
@@ -75,24 +76,28 @@ class EditController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(PiggyBank $piggyBank)
|
public function edit(PiggyBank $piggyBank)
|
||||||
{
|
{
|
||||||
$subTitle = (string)trans('firefly.update_piggy_title', ['name' => $piggyBank->name]);
|
$subTitle = (string) trans('firefly.update_piggy_title', ['name' => $piggyBank->name]);
|
||||||
$subTitleIcon = 'fa-pencil';
|
$subTitleIcon = 'fa-pencil';
|
||||||
$targetDate = null;
|
|
||||||
$startDate = null;
|
|
||||||
$note = $piggyBank->notes()->first();
|
$note = $piggyBank->notes()->first();
|
||||||
// Flash some data to fill the form.
|
// Flash some data to fill the form.
|
||||||
$targetDate = $piggyBank->targetdate?->format('Y-m-d');
|
$targetDate = $piggyBank->targetdate?->format('Y-m-d');
|
||||||
$startDate = $piggyBank->startdate?->format('Y-m-d');
|
$startDate = $piggyBank->startdate?->format('Y-m-d');
|
||||||
$currency = $this->accountRepository->getAccountCurrency($piggyBank->account);
|
$currency = $this->accountRepository->getAccountCurrency($piggyBank->account);
|
||||||
|
if (null === $currency) {
|
||||||
|
$currency = Amount::getDefaultCurrency();
|
||||||
|
}
|
||||||
|
|
||||||
$preFilled = ['name' => $piggyBank->name,
|
$preFilled = ['name' => $piggyBank->name,
|
||||||
'account_id' => $piggyBank->account_id,
|
'account_id' => $piggyBank->account_id,
|
||||||
'targetamount' => number_format((float)$piggyBank->targetamount, $currency->decimal_places,'.',''),
|
'targetamount' => number_format((float) $piggyBank->targetamount, $currency->decimal_places, '.', ''),
|
||||||
'targetdate' => $targetDate,
|
'targetdate' => $targetDate,
|
||||||
'startdate' => $startDate,
|
'startdate' => $startDate,
|
||||||
'object_group' => $piggyBank->objectGroups->first() ? $piggyBank->objectGroups->first()->title : '',
|
'object_group' => $piggyBank->objectGroups->first() ? $piggyBank->objectGroups->first()->title : '',
|
||||||
'notes' => null === $note ? '' : $note->text,
|
'notes' => null === $note ? '' : $note->text,
|
||||||
];
|
];
|
||||||
|
if(0.0 === (float) $piggyBank->targetamount) {
|
||||||
|
$preFilled['targetamount'] = '';
|
||||||
|
}
|
||||||
session()->flash('preFilled', $preFilled);
|
session()->flash('preFilled', $preFilled);
|
||||||
|
|
||||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||||
@@ -117,7 +122,7 @@ class EditController extends Controller
|
|||||||
$data = $request->getPiggyBankData();
|
$data = $request->getPiggyBankData();
|
||||||
$piggyBank = $this->piggyRepos->update($piggyBank, $data);
|
$piggyBank = $this->piggyRepos->update($piggyBank, $data);
|
||||||
|
|
||||||
session()->flash('success', (string)trans('firefly.updated_piggy_bank', ['name' => $piggyBank->name]));
|
session()->flash('success', (string) trans('firefly.updated_piggy_bank', ['name' => $piggyBank->name]));
|
||||||
app('preferences')->mark();
|
app('preferences')->mark();
|
||||||
|
|
||||||
// store new attachment(s):
|
// store new attachment(s):
|
||||||
@@ -127,7 +132,7 @@ class EditController extends Controller
|
|||||||
$this->attachments->saveAttachmentsForModel($piggyBank, $files);
|
$this->attachments->saveAttachmentsForModel($piggyBank, $files);
|
||||||
}
|
}
|
||||||
if (null !== $files && auth()->user()->hasRole('demo')) {
|
if (null !== $files && auth()->user()->hasRole('demo')) {
|
||||||
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
|
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||||
@@ -135,7 +140,7 @@ class EditController extends Controller
|
|||||||
}
|
}
|
||||||
$redirect = redirect($this->getPreviousUri('piggy-banks.edit.uri'));
|
$redirect = redirect($this->getPreviousUri('piggy-banks.edit.uri'));
|
||||||
|
|
||||||
if (1 === (int)$request->get('return_to_edit')) {
|
if (1 === (int) $request->get('return_to_edit')) {
|
||||||
|
|
||||||
session()->put('piggy-banks.edit.fromUpdate', true);
|
session()->put('piggy-banks.edit.fromUpdate', true);
|
||||||
|
|
||||||
|
@@ -61,7 +61,7 @@ class PiggyBankStoreRequest extends FormRequest
|
|||||||
return [
|
return [
|
||||||
'name' => 'required|between:1,255|uniquePiggyBankForUser',
|
'name' => 'required|between:1,255|uniquePiggyBankForUser',
|
||||||
'account_id' => 'required|belongsToUser:accounts',
|
'account_id' => 'required|belongsToUser:accounts',
|
||||||
'targetamount' => 'required|numeric|gte:0.01|max:1000000000',
|
'targetamount' => 'nullable|numeric|max:1000000000',
|
||||||
'startdate' => 'date',
|
'startdate' => 'date',
|
||||||
'targetdate' => 'date|nullable',
|
'targetdate' => 'date|nullable',
|
||||||
'order' => 'integer|min:1',
|
'order' => 'integer|min:1',
|
||||||
|
@@ -65,7 +65,7 @@ class PiggyBankUpdateRequest extends FormRequest
|
|||||||
return [
|
return [
|
||||||
'name' => sprintf('required|between:1,255|uniquePiggyBankForUser:%d', $piggy->id),
|
'name' => sprintf('required|between:1,255|uniquePiggyBankForUser:%d', $piggy->id),
|
||||||
'account_id' => 'required|belongsToUser:accounts',
|
'account_id' => 'required|belongsToUser:accounts',
|
||||||
'targetamount' => 'required|numeric|gte:0.01|max:1000000000',
|
'targetamount' => 'nullable|numeric|max:1000000000',
|
||||||
'startdate' => 'date',
|
'startdate' => 'date',
|
||||||
'targetdate' => 'date|nullable',
|
'targetdate' => 'date|nullable',
|
||||||
'order' => 'integer|min:1',
|
'order' => 'integer|min:1',
|
||||||
|
@@ -77,6 +77,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
* @property string $email
|
* @property string $email
|
||||||
* @property int|null $user_group_id
|
* @property int|null $user_group_id
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Budget whereUserGroupId($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Budget whereUserGroupId($value)
|
||||||
|
* @property-read Collection|\FireflyIII\Models\Note[] $notes
|
||||||
|
* @property-read int|null $notes_count
|
||||||
*/
|
*/
|
||||||
class Budget extends Model
|
class Budget extends Model
|
||||||
{
|
{
|
||||||
|
@@ -90,9 +90,14 @@ trait ModifiesPiggyBanks
|
|||||||
{
|
{
|
||||||
$today = today(config('app.timezone'));
|
$today = today(config('app.timezone'));
|
||||||
$leftOnAccount = $this->leftOnAccount($piggyBank, $today);
|
$leftOnAccount = $this->leftOnAccount($piggyBank, $today);
|
||||||
$savedSoFar = (string)$this->getRepetition($piggyBank)->currentamount;
|
$savedSoFar = (string) $this->getRepetition($piggyBank)->currentamount;
|
||||||
|
$maxAmount = $leftOnAccount;
|
||||||
|
$leftToSave = null;
|
||||||
|
if (0.0 !== (float) $piggyBank->targetamount) {
|
||||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||||
$maxAmount = 1 === bccomp($leftOnAccount, $leftToSave) ? $leftToSave : $leftOnAccount;
|
$maxAmount = 1 === bccomp($leftOnAccount, $leftToSave) ? $leftToSave : $leftOnAccount;
|
||||||
|
}
|
||||||
|
|
||||||
$compare = bccomp($amount, $maxAmount);
|
$compare = bccomp($amount, $maxAmount);
|
||||||
$result = $compare <= 0;
|
$result = $compare <= 0;
|
||||||
|
|
||||||
@@ -208,7 +213,7 @@ trait ModifiesPiggyBanks
|
|||||||
$set = $this->user->piggyBanks()->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*']);
|
$set = $this->user->piggyBanks()->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*']);
|
||||||
$current = 1;
|
$current = 1;
|
||||||
foreach ($set as $piggyBank) {
|
foreach ($set as $piggyBank) {
|
||||||
if ((int)$piggyBank->order !== $current) {
|
if ((int) $piggyBank->order !== $current) {
|
||||||
Log::debug(sprintf('Piggy bank #%d ("%s") was at place %d but should be on %d', $piggyBank->id, $piggyBank->name, $piggyBank->order, $current));
|
Log::debug(sprintf('Piggy bank #%d ("%s") was at place %d but should be on %d', $piggyBank->id, $piggyBank->name, $piggyBank->order, $current));
|
||||||
$piggyBank->order = $current;
|
$piggyBank->order = $current;
|
||||||
$piggyBank->save();
|
$piggyBank->save();
|
||||||
@@ -262,7 +267,7 @@ trait ModifiesPiggyBanks
|
|||||||
*/
|
*/
|
||||||
public function setOrder(PiggyBank $piggyBank, int $newOrder): bool
|
public function setOrder(PiggyBank $piggyBank, int $newOrder): bool
|
||||||
{
|
{
|
||||||
$oldOrder = (int)$piggyBank->order;
|
$oldOrder = (int) $piggyBank->order;
|
||||||
Log::debug(sprintf('Will move piggy bank #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
Log::debug(sprintf('Will move piggy bank #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||||
if ($newOrder > $oldOrder) {
|
if ($newOrder > $oldOrder) {
|
||||||
$this->user->piggyBanks()->where('piggy_banks.order', '<=', $newOrder)->where('piggy_banks.order', '>', $oldOrder)
|
$this->user->piggyBanks()->where('piggy_banks.order', '<=', $newOrder)->where('piggy_banks.order', '>', $oldOrder)
|
||||||
@@ -332,7 +337,7 @@ trait ModifiesPiggyBanks
|
|||||||
|
|
||||||
}
|
}
|
||||||
// try also with ID
|
// try also with ID
|
||||||
$objectGroupId = (int)($data['object_group_id'] ?? 0);
|
$objectGroupId = (int) ($data['object_group_id'] ?? 0);
|
||||||
if (0 !== $objectGroupId) {
|
if (0 !== $objectGroupId) {
|
||||||
$objectGroup = $this->findObjectGroupById($objectGroupId);
|
$objectGroup = $this->findObjectGroupById($objectGroupId);
|
||||||
if (null !== $objectGroup) {
|
if (null !== $objectGroup) {
|
||||||
@@ -354,12 +359,12 @@ trait ModifiesPiggyBanks
|
|||||||
{
|
{
|
||||||
$piggyBank = $this->updateProperties($piggyBank, $data);
|
$piggyBank = $this->updateProperties($piggyBank, $data);
|
||||||
if (array_key_exists('notes', $data)) {
|
if (array_key_exists('notes', $data)) {
|
||||||
$this->updateNote($piggyBank, (string)$data['notes']);
|
$this->updateNote($piggyBank, (string) $data['notes']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the order of the piggy bank:
|
// update the order of the piggy bank:
|
||||||
$oldOrder = (int)$piggyBank->order;
|
$oldOrder = (int) $piggyBank->order;
|
||||||
$newOrder = (int)($data['order'] ?? $oldOrder);
|
$newOrder = (int) ($data['order'] ?? $oldOrder);
|
||||||
if ($oldOrder !== $newOrder) {
|
if ($oldOrder !== $newOrder) {
|
||||||
$this->setOrder($piggyBank, $newOrder);
|
$this->setOrder($piggyBank, $newOrder);
|
||||||
}
|
}
|
||||||
@@ -377,7 +382,7 @@ trait ModifiesPiggyBanks
|
|||||||
|
|
||||||
// update using name:
|
// update using name:
|
||||||
if (array_key_exists('object_group_title', $data)) {
|
if (array_key_exists('object_group_title', $data)) {
|
||||||
$objectGroupTitle = (string)$data['object_group_title'];
|
$objectGroupTitle = (string) $data['object_group_title'];
|
||||||
if ('' !== $objectGroupTitle) {
|
if ('' !== $objectGroupTitle) {
|
||||||
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
|
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
|
||||||
if (null !== $objectGroup) {
|
if (null !== $objectGroup) {
|
||||||
@@ -396,7 +401,7 @@ trait ModifiesPiggyBanks
|
|||||||
|
|
||||||
// try also with ID:
|
// try also with ID:
|
||||||
if (array_key_exists('object_group_id', $data)) {
|
if (array_key_exists('object_group_id', $data)) {
|
||||||
$objectGroupId = (int)($data['object_group_id'] ?? 0);
|
$objectGroupId = (int) ($data['object_group_id'] ?? 0);
|
||||||
if (0 !== $objectGroupId) {
|
if (0 !== $objectGroupId) {
|
||||||
$objectGroup = $this->findObjectGroupById($objectGroupId);
|
$objectGroup = $this->findObjectGroupById($objectGroupId);
|
||||||
if (null !== $objectGroup) {
|
if (null !== $objectGroup) {
|
||||||
@@ -454,7 +459,7 @@ trait ModifiesPiggyBanks
|
|||||||
$piggyBank->name = $data['name'];
|
$piggyBank->name = $data['name'];
|
||||||
}
|
}
|
||||||
if (array_key_exists('account_id', $data) && 0 !== $data['account_id']) {
|
if (array_key_exists('account_id', $data) && 0 !== $data['account_id']) {
|
||||||
$piggyBank->account_id = (int)$data['account_id'];
|
$piggyBank->account_id = (int) $data['account_id'];
|
||||||
}
|
}
|
||||||
if (array_key_exists('targetamount', $data) && '' !== $data['targetamount']) {
|
if (array_key_exists('targetamount', $data) && '' !== $data['targetamount']) {
|
||||||
$piggyBank->targetamount = $data['targetamount'];
|
$piggyBank->targetamount = $data['targetamount'];
|
||||||
|
@@ -79,47 +79,55 @@ class PiggyBankTransformer extends AbstractTransformer
|
|||||||
/** @var ObjectGroup $objectGroup */
|
/** @var ObjectGroup $objectGroup */
|
||||||
$objectGroup = $piggyBank->objectGroups->first();
|
$objectGroup = $piggyBank->objectGroups->first();
|
||||||
if (null !== $objectGroup) {
|
if (null !== $objectGroup) {
|
||||||
$objectGroupId = (int)$objectGroup->id;
|
$objectGroupId = (int) $objectGroup->id;
|
||||||
$objectGroupOrder = (int)$objectGroup->order;
|
$objectGroupOrder = (int) $objectGroup->order;
|
||||||
$objectGroupTitle = $objectGroup->title;
|
$objectGroupTitle = $objectGroup->title;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get currently saved amount:
|
// get currently saved amount:
|
||||||
$currentAmountStr = $this->piggyRepos->getCurrentAmount($piggyBank);
|
$currentAmountStr = $this->piggyRepos->getCurrentAmount($piggyBank);
|
||||||
$currentAmount = number_format((float)$currentAmountStr, $currency->decimal_places, '.', '');
|
$currentAmount = number_format((float) $currentAmountStr, $currency->decimal_places, '.', '');
|
||||||
|
|
||||||
// left to save:
|
// Amounts, depending on 0.0 state of target amount
|
||||||
|
$percentage = null;
|
||||||
|
$targetAmountString = null;
|
||||||
|
$leftToSaveString = null;
|
||||||
|
$savePerMonth = null;
|
||||||
|
if (0.000 !== (float) $piggyBank->targetamount) {
|
||||||
$leftToSave = bcsub($piggyBank->targetamount, $currentAmountStr);
|
$leftToSave = bcsub($piggyBank->targetamount, $currentAmountStr);
|
||||||
|
$targetAmount = (string) $piggyBank->targetamount;
|
||||||
|
$targetAmount = 1 === bccomp('0.01', $targetAmount) ? '0.01' : $targetAmount;
|
||||||
|
$percentage = (int) (0 !== bccomp('0', $currentAmountStr) ? $currentAmountStr / $targetAmount * 100 : 0);
|
||||||
|
$targetAmountString = number_format((float) $targetAmount, $currency->decimal_places, '.', '');
|
||||||
|
$leftToSaveString = number_format((float) $leftToSave, $currency->decimal_places, '.', '');
|
||||||
|
$savePerMonth = number_format((float) $this->piggyRepos->getSuggestedMonthlyAmount($piggyBank), $currency->decimal_places, '.', '');
|
||||||
|
}
|
||||||
$startDate = $piggyBank->startdate?->toAtomString();
|
$startDate = $piggyBank->startdate?->toAtomString();
|
||||||
$targetDate = $piggyBank->targetdate?->toAtomString();
|
$targetDate = $piggyBank->targetdate?->toAtomString();
|
||||||
|
|
||||||
// target and percentage:
|
|
||||||
$targetAmount = $piggyBank->targetamount;
|
|
||||||
$targetAmount = 1 === bccomp('0.01', (string)$targetAmount) ? '0.01' : $targetAmount;
|
|
||||||
$percentage = (int)(0 !== bccomp('0', $currentAmountStr) ? $currentAmountStr / $targetAmount * 100 : 0);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => (string)$piggyBank->id,
|
'id' => (string) $piggyBank->id,
|
||||||
'created_at' => $piggyBank->created_at->toAtomString(),
|
'created_at' => $piggyBank->created_at->toAtomString(),
|
||||||
'updated_at' => $piggyBank->updated_at->toAtomString(),
|
'updated_at' => $piggyBank->updated_at->toAtomString(),
|
||||||
'account_id' => (string)$piggyBank->account_id,
|
'account_id' => (string) $piggyBank->account_id,
|
||||||
'account_name' => $piggyBank->account->name,
|
'account_name' => $piggyBank->account->name,
|
||||||
'name' => $piggyBank->name,
|
'name' => $piggyBank->name,
|
||||||
'currency_id' => (string)$currency->id,
|
'currency_id' => (string) $currency->id,
|
||||||
'currency_code' => $currency->code,
|
'currency_code' => $currency->code,
|
||||||
'currency_symbol' => $currency->symbol,
|
'currency_symbol' => $currency->symbol,
|
||||||
'currency_decimal_places' => (int)$currency->decimal_places,
|
'currency_decimal_places' => (int) $currency->decimal_places,
|
||||||
'target_amount' => number_format((float)$targetAmount, $currency->decimal_places, '.', ''),
|
'target_amount' => $targetAmountString,
|
||||||
'percentage' => $percentage,
|
'percentage' => $percentage,
|
||||||
'current_amount' => $currentAmount,
|
'current_amount' => $currentAmount,
|
||||||
'left_to_save' => number_format((float)$leftToSave, $currency->decimal_places, '.', ''),
|
'left_to_save' => $leftToSaveString,
|
||||||
'save_per_month' => number_format((float)$this->piggyRepos->getSuggestedMonthlyAmount($piggyBank), $currency->decimal_places, '.', ''),
|
'save_per_month' => $savePerMonth,
|
||||||
'start_date' => $startDate,
|
'start_date' => $startDate,
|
||||||
'target_date' => $targetDate,
|
'target_date' => $targetDate,
|
||||||
'order' => (int)$piggyBank->order,
|
'order' => (int) $piggyBank->order,
|
||||||
'active' => true,
|
'active' => true,
|
||||||
'notes' => $notes,
|
'notes' => $notes,
|
||||||
'object_group_id' => $objectGroupId ? (string)$objectGroupId : null,
|
'object_group_id' => $objectGroupId ? (string) $objectGroupId : null,
|
||||||
'object_group_order' => $objectGroupOrder,
|
'object_group_order' => $objectGroupOrder,
|
||||||
'object_group_title' => $objectGroupTitle,
|
'object_group_title' => $objectGroupTitle,
|
||||||
'links' => [
|
'links' => [
|
||||||
|
@@ -57,6 +57,7 @@
|
|||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="hidden-sm hidden-xs piggyBar">
|
<td class="hidden-sm hidden-xs piggyBar">
|
||||||
|
{% if null != piggy.percentage %}
|
||||||
<div class="progress progress" style="margin-bottom:0;">
|
<div class="progress progress" style="margin-bottom:0;">
|
||||||
<div
|
<div
|
||||||
{% if piggy.percentage == 100 %}
|
{% if piggy.percentage == 100 %}
|
||||||
@@ -71,17 +72,20 @@
|
|||||||
{{ piggy.percentage }}%
|
{{ piggy.percentage }}%
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
|
||||||
<td class="hidden-sm hidden-xs" style="width:40px;">
|
<td class="hidden-sm hidden-xs" style="width:40px;">
|
||||||
{% if piggy.left_to_save > 0 %}
|
{% if piggy.left_to_save > 0 or null == piggy.left_to_save %}
|
||||||
<a href="{{ route('piggy-banks.add-money', piggy.id) }}" class="btn btn-default btn-xs addMoney" data-id="{{ piggy.id }}">
|
<a href="{{ route('piggy-banks.add-money', piggy.id) }}" class="btn btn-default btn-xs addMoney" data-id="{{ piggy.id }}">
|
||||||
<span data-id="{{ piggy.id }}" class="fa fa-plus"></span></a>
|
<span data-id="{{ piggy.id }}" class="fa fa-plus"></span></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td class="hidden-sm hidden-xs" style="text-align:right;">
|
<td class="hidden-sm hidden-xs" style="text-align:right;">
|
||||||
|
{% if null != piggy.target_amount %}
|
||||||
<span title="{{ 'target_amount'|_ }}">{{ formatAmountBySymbol(piggy.target_amount,piggy.currency_symbol,piggy.currency_decimal_places) }}</span>
|
<span title="{{ 'target_amount'|_ }}">{{ formatAmountBySymbol(piggy.target_amount,piggy.currency_symbol,piggy.currency_decimal_places) }}</span>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td class="hidden-sm hidden-xs" style="text-align:right;">
|
<td class="hidden-sm hidden-xs" style="text-align:right;">
|
||||||
{% if piggy.left_to_save > 0 %}
|
{% if piggy.left_to_save > 0 %}
|
||||||
|
@@ -42,24 +42,28 @@
|
|||||||
<td>{{ piggy.object_group_title }}</a></td>
|
<td>{{ piggy.object_group_title }}</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if null != piggy.target_amount %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ 'target_amount'|_ }}</td>
|
<td>{{ 'target_amount'|_ }}</td>
|
||||||
<td>
|
<td>
|
||||||
{{ formatAmountBySymbol(piggy.target_amount, piggy.currency_symbol, piggy.currency_decimal_places) }}
|
{{ formatAmountBySymbol(piggy.target_amount, piggy.currency_symbol, piggy.currency_decimal_places) }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ 'saved_so_far'|_ }}</td>
|
<td>{{ 'saved_so_far'|_ }}</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>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% if null != piggy.left_to_save %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ 'left_to_save'|_ }}</td>
|
<td>{{ 'left_to_save'|_ }}</td>
|
||||||
<td>
|
<td>
|
||||||
{{ formatAmountBySymbol(piggy.left_to_save, piggy.currency_symbol, piggy.currency_decimal_places) }}
|
{{ formatAmountBySymbol(piggy.left_to_save, piggy.currency_symbol, piggy.currency_decimal_places) }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ 'start_date'|_ }}</td>
|
<td>{{ 'start_date'|_ }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
Reference in New Issue
Block a user