Some preliminary work on issue #6. Breaks a lot of tests. [skip ci]

This commit is contained in:
James Cole
2014-08-13 20:36:32 +02:00
parent f52cc01a8e
commit 9e77bf51bb
8 changed files with 194 additions and 150 deletions

View File

@@ -34,6 +34,21 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
)->where('piggybanks.id', $piggyBankId)->first(['piggybanks.*']);
}
public function countRepeating()
{
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
'accounts.user_id', \Auth::user()->id
)->where('repeats', 1)->count();
}
public function countNonrepeating()
{
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
'accounts.user_id', \Auth::user()->id
)->where('repeats', 0)->count();
}
/**
* @return mixed
*/
@@ -57,14 +72,8 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
$account = isset($data['account_id']) ? $accounts->find($data['account_id']) : null;
$piggyBank = new \Piggybank;
$piggyBank = new \Piggybank($data);
$piggyBank->account()->associate($account);
$piggyBank->targetdate
= isset($data['targetdate']) && strlen($data['targetdate']) > 0 ? $data['targetdate'] : null;
$piggyBank->name = isset($data['name']) ? $data['name'] : null;
$piggyBank->amount = 0;
$piggyBank->target = floatval($data['target']);
$piggyBank->order = 1;
if ($piggyBank->validate()) {
$piggyBank->save();
}

View File

@@ -23,6 +23,16 @@ interface PiggybankRepositoryInterface
*/
public function count();
/**
* @return mixed
*/
public function countRepeating();
/**
* @return mixed
*/
public function countNonrepeating();
/**
* @param $data
*