Lots of new tests.

This commit is contained in:
James Cole
2015-04-07 10:14:10 +02:00
parent b2674971f1
commit 701efb943d
9 changed files with 355 additions and 86 deletions

View File

@@ -19,6 +19,31 @@ use Navigation;
*/
class BillRepository implements BillRepositoryInterface
{
/**
* Create a fake bill to help the chart controller.
*
* @param string $description
* @param Carbon $date
* @param float $amount
*
* @return Bill
*/
public function createFakeBill($description, Carbon $date, $amount)
{
$bill = new Bill;
$bill->name = $description;
$bill->match = $description;
$bill->amount_min = $amount;
$bill->amount_max = $amount;
$bill->date = $date;
$bill->repeat_freq = 'monthly';
$bill->skip = 0;
$bill->automatch = false;
$bill->active = false;
return $bill;
}
/**
* @param Bill $bill
*
@@ -29,6 +54,22 @@ class BillRepository implements BillRepositoryInterface
return $bill->delete();
}
/**
* @return Collection
*/
public function getActiveBills()
{
/** @var Collection $set */
$set = Auth::user()->bills()->orderBy('name', 'ASC')->where('active', 1)->get();
$set->sort(
function (Bill $bill) {
return $bill->name;
}
);
return $set;
}
/**
* @return Collection
*/
@@ -65,6 +106,20 @@ class BillRepository implements BillRepositoryInterface
->get(['transaction_journals.*', 'transactions.amount']);
}
/**
* Get all journals that were recorded on this bill between these dates.
*
* @param Bill $bill
* @param Carbon $start
* @param Carbon $end
*
* @return Collection
*/
public function getJournalsInRange(Bill $bill, Carbon $start, Carbon $end)
{
return $bill->transactionjournals()->before($end)->after($start)->get();
}
/**
* @param Bill $bill
*
@@ -322,20 +377,4 @@ class BillRepository implements BillRepositoryInterface
return $bill;
}
/**
* @return Collection
*/
public function getActiveBills()
{
/** @var Collection $set */
$set = Auth::user()->bills()->orderBy('name', 'ASC')->where('active', 1)->get();
$set->sort(
function (Bill $bill) {
return $bill->name;
}
);
return $set;
}
}