Browse Source

Update model class docblocs

pull/24/head
Nafies Luthfi 7 years ago
parent
commit
f45021b54d
  1. 50
      app/Entities/Invoices/Invoice.php
  2. 17
      app/Entities/Options/Option.php
  3. 40
      app/Entities/Partners/Customer.php

50
app/Entities/Invoices/Invoice.php

@ -13,26 +13,62 @@ use Illuminate\Database\Eloquent\Model;
*/ */
class Invoice extends Model class Invoice extends Model
{ {
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = ['id', 'created_at', 'updated_at']; protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = ['items' => 'array']; protected $casts = ['items' => 'array'];
/**
* The number of models to return for pagination.
*
* @var int
*/
protected $perPage = 25; protected $perPage = 25;
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName() public function getRouteKeyName()
{ {
return 'number'; return 'number';
} }
/**
* Invoice belongs to project.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function project() public function project()
{ {
return $this->belongsTo(Project::class); return $this->belongsTo(Project::class);
} }
/**
* Invoice belongs to creator (user).
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function creator() public function creator()
{ {
return $this->belongsTo(User::class); return $this->belongsTo(User::class);
} }
/**
* Generate invoice (incrementing) number.
*
* @return string
*/
public function generateNewNumber() public function generateNewNumber()
{ {
$prefix = date('ym'); $prefix = date('ym');
@ -49,13 +85,21 @@ class Invoice extends Model
return $prefix.'001'; return $prefix.'001';
} }
public function getItemsCountAttribute($value)
/**
* Get invoice items count attribute.
*
* @return int
*/
public function getItemsCountAttribute()
{ {
$pcsCount = 0;
return count($this->items); return count($this->items);
} }
/**
* Get invoice number in html link format.
*
* @return \Illuminate\Support\HtmlString
*/
public function numberLink() public function numberLink()
{ {
return link_to_route('invoices.show', $this->number, [$this->number], [ return link_to_route('invoices.show', $this->number, [$this->number], [

17
app/Entities/Options/Option.php

@ -6,7 +6,24 @@ use Illuminate\Database\Eloquent\Model;
class Option extends Model class Option extends Model
{ {
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['key', 'value']; protected $fillable = ['key', 'value'];
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'site_options'; protected $table = 'site_options';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false; public $timestamps = false;
} }

40
app/Entities/Partners/Customer.php

@ -6,28 +6,58 @@ use Illuminate\Database\Eloquent\Model;
class Customer extends Model class Customer extends Model
{ {
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'email', 'phone', 'pic', 'address', 'website', 'notes', 'is_active']; protected $fillable = ['name', 'email', 'phone', 'pic', 'address', 'website', 'notes', 'is_active'];
/**
* Customer has many projects.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function projects() public function projects()
{ {
return $this->hasMany('App\Entities\Projects\Project'); return $this->hasMany('App\Entities\Projects\Project');
} }
/**
* Customer morph many payments.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function payments() public function payments()
{ {
return $this->morphMany('App\Entities\Payments\Payment', 'partner'); return $this->morphMany('App\Entities\Payments\Payment', 'partner');
} }
/**
* Customer has many subscriptions.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function subscriptions() public function subscriptions()
{ {
return $this->hasMany('App\Entities\Subscriptions\Subscription'); return $this->hasMany('App\Entities\Subscriptions\Subscription');
} }
/**
* Customer has many invoices through their projects.
*
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
*/
public function invoices() public function invoices()
{ {
return $this->hasManyThrough('App\Entities\Invoices\Invoice', 'App\Entities\Projects\Project'); return $this->hasManyThrough('App\Entities\Invoices\Invoice', 'App\Entities\Projects\Project');
} }
/**
* Get customer name in html link format.
*
* @return \Illuminate\Support\HtmlString
*/
public function nameLink() public function nameLink()
{ {
return link_to_route('customers.show', $this->name, [$this->id], [ return link_to_route('customers.show', $this->name, [$this->id], [
@ -38,11 +68,21 @@ class Customer extends Model
]); ]);
} }
/**
* Get customr status attribute.
*
* @return string
*/
public function getStatusAttribute() public function getStatusAttribute()
{ {
return $this->is_active == 1 ? trans('app.active') : trans('app.in_active'); return $this->is_active == 1 ? trans('app.active') : trans('app.in_active');
} }
/**
* Get customr status label attribute.
*
* @return string
*/
public function getStatusLabelAttribute() public function getStatusLabelAttribute()
{ {
$color = $this->is_active == 1 ? ' style="background-color: #337ab7"' : ''; $color = $this->is_active == 1 ? ' style="background-color: #337ab7"' : '';

Loading…
Cancel
Save