Some general cleaning up.

This commit is contained in:
James Cole 2014-11-17 20:45:55 +01:00
parent 36cbb3d71f
commit 696e9a6fde
16 changed files with 103 additions and 168 deletions

View File

@ -7,25 +7,25 @@ use LaravelBook\Ardent\Builder;
/**
* Account
*
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property integer $user_id
* @property integer $account_type_id
* @property string $name
* @property boolean $active
* @property-read \AccountType $accountType
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property integer $user_id
* @property integer $account_type_id
* @property string $name
* @property boolean $active
* @property-read \AccountType $accountType
* @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions
* @property-read \Illuminate\Database\Eloquent\Collection|\Piggybank[] $piggybanks
* @property-read \User $user
* @method static \Illuminate\Database\Query\Builder|\Account whereId($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereAccountTypeId($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereName($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereActive($value)
* @method static \Account accountTypeIn($types)
* @property-read \Illuminate\Database\Eloquent\Collection|\Piggybank[] $piggybanks
* @property-read \User $user
* @method static \Illuminate\Database\Query\Builder|\Account whereId($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereAccountTypeId($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereName($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereActive($value)
* @method static \Account accountTypeIn($types)
*/
class Account extends Ardent
{
@ -36,8 +36,11 @@ class Account extends Ardent
* @var array
*/
public static $rules
= ['name' => ['required', 'between:1,100', 'alphabasic'], 'user_id' => 'required|exists:users,id',
'account_type_id' => 'required|exists:account_types,id', 'active' => 'required|boolean'
= [
'name' => ['required', 'between:1,100', 'alphabasic'],
'user_id' => 'required|exists:users,id',
'account_type_id' => 'required|exists:account_types,id',
'active' => 'required|boolean'
];
@ -56,6 +59,8 @@ class Account extends Ardent
/**
* Get an accounts current balance.
*
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* @param \Carbon\Carbon $date
*
* @return float
@ -82,6 +87,9 @@ class Account extends Ardent
}
/**
*
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* @param TransactionJournal $journal
*
* @return float
@ -98,6 +106,8 @@ class Account extends Ardent
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* @return Carbon
*/
public function lastActionDate()
@ -119,6 +129,8 @@ class Account extends Ardent
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* @param \Carbon\Carbon $date
*
* @return null

View File

@ -13,7 +13,10 @@ class AccountMeta extends Ardent
* @var array
*/
public static $rules
= ['account_id' => 'numeric|required|exists:accounts,id', 'name' => 'required|between:1,250', 'data' => 'required'];
= [
'account_id' => 'numeric|required|exists:accounts,id',
'name' => 'required|between:1,250',
'data' => 'required'];
/**
* @var array

View File

@ -32,12 +32,5 @@ class Budget extends Component
return $this->hasMany('Limit', 'component_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany|\TransactionJournal
*/
public function transactionjournals()
{
return $this->belongsToMany('TransactionJournal', 'component_transaction_journal', 'component_id');
}
}

View File

@ -25,24 +25,5 @@ class Category extends Component
{
protected $isSubclass = true;
/**
* @return Carbon
*/
public function lastActionDate()
{
$transaction = $this->transactionjournals()->orderBy('updated_at', 'DESC')->first();
if (is_null($transaction)) {
return null;
}
return $transaction->date;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function transactionjournals()
{
return $this->belongsToMany('TransactionJournal', 'component_transaction_journal', 'component_id');
}
}
}

View File

@ -5,22 +5,22 @@ use FireflyIII\Shared\SingleTableInheritanceEntity;
/**
* Component
*
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $name
* @property integer $user_id
* @property string $class
* @property-read \Illuminate\Database\Eloquent\Collection|\Limit[] $limits
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $name
* @property integer $user_id
* @property string $class
* @property-read \Illuminate\Database\Eloquent\Collection|\Limit[] $limits
* @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionjournals
* @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions
* @property-read \User $user
* @method static \Illuminate\Database\Query\Builder|\Component whereId($value)
* @method static \Illuminate\Database\Query\Builder|\Component whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Component whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Component whereName($value)
* @method static \Illuminate\Database\Query\Builder|\Component whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|\Component whereClass($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions
* @property-read \User $user
* @method static \Illuminate\Database\Query\Builder|\Component whereId($value)
* @method static \Illuminate\Database\Query\Builder|\Component whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Component whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Component whereName($value)
* @method static \Illuminate\Database\Query\Builder|\Component whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|\Component whereClass($value)
*/
class Component extends SingleTableInheritanceEntity
{
@ -33,11 +33,17 @@ class Component extends SingleTableInheritanceEntity
protected $table = 'components';
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
* TODO remove this method in favour of something in the FireflyIII libraries.
* @return Carbon
*/
public function limits()
public function lastActionDate()
{
return $this->hasMany('Limit');
$transaction = $this->transactionjournals()->orderBy('updated_at', 'DESC')->first();
if (is_null($transaction)) {
return null;
}
return $transaction->date;
}
/**
@ -45,9 +51,10 @@ class Component extends SingleTableInheritanceEntity
*/
public function transactionjournals()
{
return $this->belongsToMany('TransactionJournal');
return $this->belongsToMany('TransactionJournal','component_transaction_journal','component_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/

View File

@ -1,30 +0,0 @@
<?php
use Illuminate\Database\Eloquent\Model as Eloquent;
/**
* Importentry
*
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $class
* @property integer $importmap_id
* @property integer $old
* @property integer $new
* @property-read \Importmap $importmap
* @method static \Illuminate\Database\Query\Builder|\Importentry whereId($value)
* @method static \Illuminate\Database\Query\Builder|\Importentry whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Importentry whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Importentry whereClass($value)
* @method static \Illuminate\Database\Query\Builder|\Importentry whereImportmapId($value)
* @method static \Illuminate\Database\Query\Builder|\Importentry whereOld($value)
* @method static \Illuminate\Database\Query\Builder|\Importentry whereNew($value)
*/
class Importentry extends Eloquent
{
public function importmap()
{
return $this->belongsTo('Importmap');
}
}

View File

@ -1,49 +0,0 @@
<?php
use LaravelBook\Ardent\Ardent as Ardent;
/**
* Importmap
*
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property integer $user_id
* @property string $file
* @property integer $totaljobs
* @property integer $jobsdone
* @property-read \User $user
* @method static \Illuminate\Database\Query\Builder|\Importmap whereId($value)
* @method static \Illuminate\Database\Query\Builder|\Importmap whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Importmap whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Importmap whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|\Importmap whereFile($value)
* @method static \Illuminate\Database\Query\Builder|\Importmap whereTotaljobs($value)
* @method static \Illuminate\Database\Query\Builder|\Importmap whereJobsdone($value)
*/
class Importmap extends Ardent
{
public static $rules
= ['user_id' => 'required|exists:users,id', 'file' => 'required', 'totaljobs' => 'numeric|required|min:0', 'jobsdone' => 'numeric|required|min:0',
];
public function pct()
{
if ($this->jobsdone == 0 || $this->totaljobs == 0) {
return 0;
} else {
return round((($this->jobsdone / $this->totaljobs) * 100), 1);
}
}
/**
* User
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo('User');
}
}

View File

@ -46,14 +46,6 @@ class Limit extends Ardent
return $this->belongsTo('Budget', 'component_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function component()
{
return $this->belongsTo('Component', 'component_id');
}
/**
* Create a new repetition for this limit, starting on
* the given date.

View File

@ -45,6 +45,10 @@ class LimitRepetition extends Ardent
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
* @return float
*/
public function spentInRepetition()
{
$sum = \DB::table('transactions')->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->leftJoin(
@ -69,6 +73,8 @@ class LimitRepetition extends Ardent
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* Returns a string used to sort this particular repetition
* based on the date and period it falls into. Ie. the limit
* repeats monthly and the start date is 12 dec 2012, this will
@ -105,6 +111,8 @@ class LimitRepetition extends Ardent
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* Same as above, just with a more natural view. So "March 2012".
*/
public function periodShow()

View File

@ -71,16 +71,34 @@ class Piggybank extends Ardent
return $this->belongsTo('Account');
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* @return int
*/
public function amountPerReminder() {
return 0;
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* @return int
*/
public function countFutureReminders()
{
return 0;
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* @param Carbon $start
* @param Carbon $target
*
* @return PiggybankRepetition
*/
public function createRepetition(Carbon $start = null, Carbon $target = null)
{
$rep = new \PiggybankRepetition;
@ -94,6 +112,8 @@ class Piggybank extends Ardent
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* Grabs the PiggyBankRepetition that's currently relevant / active
*
* @returns \PiggybankRepetition
@ -167,6 +187,8 @@ class Piggybank extends Ardent
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* Same but for specific date.
*
* @param Carbon $date

View File

@ -34,6 +34,11 @@ class PiggybankRepetition extends Ardent
return ['created_at', 'updated_at', 'targetdate', 'startdate'];
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* @return float|int
*/
public function pct()
{
$total = $this->piggybank->targetamount;

View File

@ -72,6 +72,8 @@ class RecurringTransaction extends Ardent
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
* Find the next expected match based on the set journals and the date stuff from the recurring
* transaction.
*/

View File

@ -50,19 +50,6 @@ class Reminder extends Ardent
return $this->belongsTo('User');
}
/**
* Expected data in this value:
*
* type: Piggybank, Test
* action_uri: where to go when the user wants to do this?
* text: full text to present to user
* amount: any relevant amount.
* model: id of relevant model.
*
* @param $value
*
* @return mixed
*/
public function getDataAttribute($value)
{
return json_decode($value);

View File

@ -86,6 +86,7 @@ class TransactionJournal extends Ardent
}
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
* @return float
*/
public function getAmount()

View File

@ -221,7 +221,7 @@ Route::group(
// user controller
Route::get('/logout', ['uses' => 'UserController@logout', 'as' => 'logout']);
//Route::post('budgets/amount/{budget}', ['uses' => 'BudgetController@amount']);
Route::post('budgets/amount/{budget}', ['uses' => 'BudgetController@amount']);
}

View File

@ -102,4 +102,5 @@ Event::subscribe('FireflyIII\Event\Piggybank');
// although this not changes the amount in the piggy bank).
// TODO check if recurring transactions are being updated when journals are updated (aka no longer fitting, thus removed).
// TODO think about reminders.
// TODO an event that triggers and creates a limit + limit repetition when a budget is created, or something?
return $app;