Expand budget box and clear some languages.

This commit is contained in:
James Cole
2017-09-29 14:22:40 +02:00
parent 76ed261441
commit aa4682af6a
5 changed files with 32 additions and 18 deletions

View File

@@ -290,7 +290,19 @@ class BudgetController extends Controller
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($begin, $subDay)->setTypes([TransactionType::DEPOSIT])->withOpposingAccount();
$result['earned'] = bcdiv(strval($collector->getJournals()->sum('transaction_amount')),strval($count));
$result['earned'] = bcdiv(strval($collector->getJournals()->sum('transaction_amount')), strval($count));
// amount spent in period
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($begin, $subDay)->setTypes([TransactionType::WITHDRAWAL])->withOpposingAccount();
$result['spent'] = bcdiv(strval($collector->getJournals()->sum('transaction_amount')), strval($count));
// suggestion starts with the amount spent
$result['suggested'] = bcmul($result['spent'], '-1');
$result['suggested'] = bccomp($result['suggested'], $result['earned']) === 1 ? $result['earned'] : $result['suggested'];
// unless it's more than you earned. So min() of suggested/earned
$cache->store($result);
}

View File

@@ -32,7 +32,9 @@ use Response;
class BoxController extends Controller
{
/**
* @param BudgetRepositoryInterface $repository
*
* @return \Illuminate\Http\JsonResponse
*/
public function available(BudgetRepositoryInterface $repository)
{
@@ -61,7 +63,7 @@ class BoxController extends Controller
if (bccomp($left, '0') === -1) {
$left = '0';
}
$days = $today->diffInDays($end);
$days = $today->diffInDays($end) + 1;
$perDay = '0';
if ($days !== 0) {
$perDay = bcdiv($left, strval($days));