Files
firefly-iii/app/lib/FireflyIII/Shared/Toolkit/Steam.php

79 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace FireflyIII\Shared\Toolkit;
use Carbon\Carbon;
/**
*
* Steam is a special class used for those small often occurring things you need your application to do.
*
* Class Steam
*
* @package FireflyIII\Shared\Toolkit
*/
class Steam
{
/**
2015-01-02 05:52:38 +01:00
*
* @param \Account $account
* @param Carbon $date
*
* @return float
*/
public function balance(\Account $account, Carbon $date = null)
{
2015-01-02 09:06:44 +01:00
$date = is_null($date) ? Carbon::now() : $date;
$balance = floatval(
$account->transactions()->leftJoin(
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
)->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount')
);
return $balance;
}
2015-01-02 09:06:44 +01:00
/**
* @param $boolean
*
* @return string
*/
public function boolString($boolean)
{
if ($boolean === true) {
return 'BOOLEAN TRUE';
}
if ($boolean === false) {
return 'BOOLEAN FALSE';
}
return 'NO BOOLEAN: ' . $boolean;
}
/**
* @param \PiggyBank $piggyBank
* @param \PiggyBankRepetition $repetition
*
* @return int
*/
public function percentage(\PiggyBank $piggyBank, \PiggyBankRepetition $repetition)
{
$pct = $repetition->currentamount / $piggyBank->targetamount * 100;
if ($pct > 100) {
return 100;
} else {
return floor($pct);
}
}
2014-12-14 20:40:02 +01:00
public function removeEmptyBudgetLimits()
{
$user = \Auth::user();
if ($user) {
2014-12-20 07:33:59 +01:00
\BudgetLimit::where('amount', 0)->delete();
2014-12-14 20:40:02 +01:00
}
}
2015-01-02 06:16:49 +01:00
}