New content and tests ensure the coverage of all code.

This commit is contained in:
James Cole 2015-01-01 20:53:36 +01:00
parent 8c439a2852
commit 98c1fcc68f
3 changed files with 100 additions and 86 deletions

View File

@ -132,18 +132,18 @@ class GoogleChartController extends BaseController
/** @var Budget $budget */ /** @var Budget $budget */
foreach ($budgets as $budget) { foreach ($budgets as $budget) {
Log::debug('Now working budget #'.$budget->id.', '.$budget->name); Log::debug('Now working budget #' . $budget->id . ', ' . $budget->name);
/** @var \LimitRepetition $repetition */ /** @var \LimitRepetition $repetition */
$repetition = $bdt->repetitionOnStartingOnDate($budget, $this->_start); $repetition = $bdt->repetitionOnStartingOnDate($budget, $this->_start);
if (is_null($repetition)) { if (is_null($repetition)) {
\Log::debug('Budget #'.$budget->id.' has no repetition on ' . $this->_start->format('Y-m-d')); \Log::debug('Budget #' . $budget->id . ' has no repetition on ' . $this->_start->format('Y-m-d'));
// use the session start and end for our search query // use the session start and end for our search query
$searchStart = $this->_start; $searchStart = $this->_start;
$searchEnd = $this->_end; $searchEnd = $this->_end;
$limit = 0; // the limit is zero: $limit = 0; // the limit is zero:
} else { } else {
\Log::debug('Budget #'.$budget->id.' has a repetition on ' . $this->_start->format('Y-m-d').'!'); \Log::debug('Budget #' . $budget->id . ' has a repetition on ' . $this->_start->format('Y-m-d') . '!');
// use the limit's start and end for our search query // use the limit's start and end for our search query
$searchStart = $repetition->startdate; $searchStart = $repetition->startdate;
$searchEnd = $repetition->enddate; $searchEnd = $repetition->enddate;
@ -151,6 +151,7 @@ class GoogleChartController extends BaseController
} }
$expenses = floatval($budget->transactionjournals()->before($searchEnd)->after($searchStart)->lessThan(0)->sum('amount')) * -1; $expenses = floatval($budget->transactionjournals()->before($searchEnd)->after($searchStart)->lessThan(0)->sum('amount')) * -1;
\Log::debug('Expenses in budget ' . $budget->name . ' before ' . $searchEnd->format('Y-m-d') . ' and after ' . $searchStart . ' are: ' . $expenses);
if ($expenses > 0) { if ($expenses > 0) {
$this->_chart->addRow($budget->name, $limit, $expenses); $this->_chart->addRow($budget->name, $limit, $expenses);
} }
@ -186,6 +187,76 @@ class GoogleChartController extends BaseController
} }
/**
* @param Bill $bill
*
* @return \Illuminate\Http\JsonResponse
*/
public function billOverview(Bill $bill)
{
$this->_chart->addColumn('Date', 'date');
$this->_chart->addColumn('Max amount', 'number');
$this->_chart->addColumn('Min amount', 'number');
$this->_chart->addColumn('Current entry', 'number');
// get first transaction or today for start:
$first = $bill->transactionjournals()->orderBy('date', 'ASC')->first();
if ($first) {
$start = $first->date;
} else {
$start = new Carbon;
}
$end = new Carbon;
while ($start <= $end) {
$result = $bill->transactionjournals()->before($end)->after($start)->first();
if ($result) {
$amount = $result->getAmount();
} else {
$amount = 0;
}
unset($result);
$this->_chart->addRow(clone $start, $bill->amount_max, $bill->amount_min, $amount);
$start = DateKit::addPeriod($start, $bill->repeat_freq, 0);
}
$this->_chart->generate();
return Response::json($this->_chart->getData());
}
/**
* TODO query move to helper.
*
* @return \Illuminate\Http\JsonResponse
* @throws \FireflyIII\Exception\FireflyException
*/
public function billsOverview()
{
$paid = ['items' => [], 'amount' => 0];
$unpaid = ['items' => [], 'amount' => 0];
$this->_chart->addColumn('Name', 'string');
$this->_chart->addColumn('Amount', 'number');
$set = $this->_repository->getBillsSummary($this->_start, $this->_end);
foreach ($set as $entry) {
if (intval($entry->journalId) == 0) {
$unpaid['items'][] = $entry->name;
$unpaid['amount'] += floatval($entry->averageAmount);
} else {
$paid['items'][] = $entry->description;
$paid['amount'] += floatval($entry->actualAmount);
}
}
$this->_chart->addRow('Unpaid: ' . join(', ', $unpaid['items']), $unpaid['amount']);
$this->_chart->addRow('Paid: ' . join(', ', $paid['items']), $paid['amount']);
$this->_chart->generate();
return Response::json($this->_chart->getData());
}
/** /**
* TODO still in use? * TODO still in use?
* *
@ -223,12 +294,12 @@ class GoogleChartController extends BaseController
/** /**
* TODO still in use? * TODO still in use?
* *
* @param Budget $component * @param Budget $budget
* @param $year * @param $year
* *
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function budgetsAndSpending(Budget $component, $year) public function budgetsAndSpending(Budget $budget, $year)
{ {
try { try {
new Carbon('01-01-' . $year); new Carbon('01-01-' . $year);
@ -247,11 +318,14 @@ class GoogleChartController extends BaseController
$end = clone $start; $end = clone $start;
$end->endOfYear(); $end->endOfYear();
while ($start <= $end) { while ($start <= $end) {
$spent = $budgetRepository->spentInMonth($component, $start); $spent = $budgetRepository->spentInMonth($budget, $start);
$repetition = $budgetRepository->repetitionOnStartingOnDate($component, $start); $repetition = $budgetRepository->repetitionOnStartingOnDate($budget, $start);
if ($repetition) { if ($repetition) {
$budgeted = floatval($repetition->amount); $budgeted = floatval($repetition->amount);
\Log::debug('Found a repetition on ' . $start->format('Y-m-d'). ' for budget ' . $budget->name.'!');
} else { } else {
\Log::debug('No repetition on ' . $start->format('Y-m-d'). ' for budget ' . $budget->name);
$budgeted = null; $budgeted = null;
} }
@ -334,76 +408,6 @@ class GoogleChartController extends BaseController
} }
/**
* @param Bill $bill
*
* @return \Illuminate\Http\JsonResponse
*/
public function billOverview(Bill $bill)
{
$this->_chart->addColumn('Date', 'date');
$this->_chart->addColumn('Max amount', 'number');
$this->_chart->addColumn('Min amount', 'number');
$this->_chart->addColumn('Current entry', 'number');
// get first transaction or today for start:
$first = $bill->transactionjournals()->orderBy('date', 'ASC')->first();
if ($first) {
$start = $first->date;
} else {
$start = new Carbon;
}
$end = new Carbon;
while ($start <= $end) {
$result = $bill->transactionjournals()->before($end)->after($start)->first();
if ($result) {
$amount = $result->getAmount();
} else {
$amount = 0;
}
unset($result);
$this->_chart->addRow(clone $start, $bill->amount_max, $bill->amount_min, $amount);
$start = DateKit::addPeriod($start, $bill->repeat_freq, 0);
}
$this->_chart->generate();
return Response::json($this->_chart->getData());
}
/**
* TODO query move to helper.
*
* @return \Illuminate\Http\JsonResponse
* @throws \FireflyIII\Exception\FireflyException
*/
public function billsOverview()
{
$paid = ['items' => [], 'amount' => 0];
$unpaid = ['items' => [], 'amount' => 0];
$this->_chart->addColumn('Name', 'string');
$this->_chart->addColumn('Amount', 'number');
$set = $this->_repository->getBillsSummary($this->_start, $this->_end);
foreach ($set as $entry) {
if (intval($entry->journalId) == 0) {
$unpaid['items'][] = $entry->name;
$unpaid['amount'] += floatval($entry->averageAmount);
} else {
$paid['items'][] = $entry->description;
$paid['amount'] += floatval($entry->actualAmount);
}
}
$this->_chart->addRow('Unpaid: ' . join(', ', $unpaid['items']), $unpaid['amount']);
$this->_chart->addRow('Paid: ' . join(', ', $paid['items']), $paid['amount']);
$this->_chart->generate();
return Response::json($this->_chart->getData());
}
/** /**
* TODO see reports for better way to do this. * TODO see reports for better way to do this.
* *

View File

@ -109,18 +109,24 @@ class TestContentSeeder extends Seeder
$euro = TransactionCurrency::whereCode('EUR')->first(); $euro = TransactionCurrency::whereCode('EUR')->first();
$rentBill = Bill::where('name', 'Rent')->first();
$current = clone $this->_yearAgoStartOfMonth; $current = clone $this->_yearAgoStartOfMonth;
while ($current < $this->_startOfMonth) { while ($current <= $this->_startOfMonth) {
$cur = $current->format('Y-m-d'); $cur = $current->format('Y-m-d');
$formatted = $current->format('F Y'); $formatted = $current->format('F Y');
// create expenses for rent, utilities, TV, phone on the 1st of the month. // create expenses for rent, utilities, TV, phone on the 1st of the month.
$this->createTransaction($checking, $landLord, 800, $withdrawal, 'Rent for ' . $formatted, $cur, $euro, $bills, $house); $this->createTransaction($checking, $landLord, 800, $withdrawal, 'Rent for ' . $formatted, $cur, $euro, $bills, $house, $rentBill);
$this->createTransaction($checking, $utilities, 150, $withdrawal, 'Utilities for ' . $formatted, $cur, $euro, $bills, $house); $this->createTransaction($checking, $utilities, 150, $withdrawal, 'Utilities for ' . $formatted, $cur, $euro, $bills, $house);
$this->createTransaction($checking, $television, 50, $withdrawal, 'TV for ' . $formatted, $cur, $euro, $bills, $house); $this->createTransaction($checking, $television, 50, $withdrawal, 'TV for ' . $formatted, $cur, $euro, $bills, $house);
$this->createTransaction($checking, $phone, 50, $withdrawal, 'Phone bill for ' . $formatted, $cur, $euro, $bills, $house); $this->createTransaction($checking, $phone, 50, $withdrawal, 'Phone bill for ' . $formatted, $cur, $euro, $bills, $house);
// two transactions. One without a budget, one without a category.
$this->createTransaction($checking, $phone, 10, $withdrawal, 'Extra charges on phone bill for ' . $formatted, $cur, $euro, null, $house);
$this->createTransaction($checking, $television, 5, $withdrawal, 'Extra charges on TV bill for ' . $formatted, $cur, $euro, $bills, null);
// income from job: // income from job:
$this->createTransaction($employer, $checking, rand(3500, 4000), $deposit, 'Salary for ' . $formatted, $cur, $euro); $this->createTransaction($employer, $checking, rand(3500, 4000), $deposit, 'Salary for ' . $formatted, $cur, $euro);
$this->createTransaction($checking, $savings, 2000, $transfer, 'Salary to savings account in ' . $formatted, $cur, $euro); $this->createTransaction($checking, $savings, 2000, $transfer, 'Salary to savings account in ' . $formatted, $cur, $euro);
@ -225,9 +231,10 @@ class TestContentSeeder extends Seeder
public function createBudgets(User $user) public function createBudgets(User $user)
{ {
$groceries = Budget::create(['user_id' => $user->id, 'name' => 'Groceries']); $groceries = Budget::create(['user_id' => $user->id, 'name' => 'Groceries']);
$bills = Budget::create(['user_id' => $user->id, 'name' => 'Bills']); $bills = Budget::create(['user_id' => $user->id, 'name' => 'Bills']);
$deleteMe = Budget::create(['user_id' => $user->id, 'name' => 'Delete me']); $deleteMe = Budget::create(['user_id' => $user->id, 'name' => 'Delete me']);
Budget::create(['user_id' => $user->id, 'name' => 'Budget without repetition']);
$groceriesLimit = BudgetLimit::create( $groceriesLimit = BudgetLimit::create(
['startdate' => $this->som, 'amount' => 201, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $groceries->id] ['startdate' => $this->som, 'amount' => 201, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $groceries->id]
); );
@ -405,8 +412,9 @@ class TestContentSeeder extends Seeder
// bill // bill
Bill::create( Bill::create(
[ [
'user_id' => $user->id, 'name' => 'Huur', 'match' => 'huur,portaal', 'amount_min' => 500, 'user_id' => $user->id, 'name' => 'Rent', 'match' => 'rent,landlord',
'amount_max' => 700, 'amount_min' => 700,
'amount_max' => 900,
'date' => $this->som, 'date' => $this->som,
'active' => 1, 'active' => 1,
'automatch' => 1, 'automatch' => 1,

View File

@ -108,8 +108,9 @@ class GoogleChartControllerCest
*/ */
public function budgetsAndSpending(FunctionalTester $I) public function budgetsAndSpending(FunctionalTester $I)
{ {
$year = date('Y');
$I->wantTo('see the chart for a budget in a specific year'); $I->wantTo('see the chart for a budget in a specific year');
$I->amOnPage('/chart/budget/1/spending/2014'); $I->amOnPage('/chart/budget/1/spending/'.$year);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }
@ -129,8 +130,9 @@ class GoogleChartControllerCest
*/ */
public function categoriesAndSpending(FunctionalTester $I) public function categoriesAndSpending(FunctionalTester $I)
{ {
$year = date('Y');
$I->wantTo('see the chart for a category in a specific year'); $I->wantTo('see the chart for a category in a specific year');
$I->amOnPage('/chart/category/1/spending/2014'); $I->amOnPage('/chart/category/1/spending/'.$year);
$I->seeResponseCodeIs(200); $I->seeResponseCodeIs(200);
} }