invoiceninja/app/Models/Payment.php

82 lines
1.7 KiB
PHP
Raw Normal View History

2015-03-18 09:39:03 +10:00
<?php namespace App\Models;
2015-03-17 07:45:25 +10:00
2015-03-31 12:38:24 +03:00
use Illuminate\Database\Eloquent\SoftDeletes;
2015-10-28 21:22:07 +02:00
use App\Events\PaymentWasCreated;
2015-11-12 22:36:28 +02:00
use Laracasts\Presenter\PresentableTrait;
2015-03-31 12:38:24 +03:00
2015-03-17 07:45:25 +10:00
class Payment extends EntityModel
{
2015-11-12 22:36:28 +02:00
use PresentableTrait;
2015-03-31 12:38:24 +03:00
use SoftDeletes;
2015-11-12 22:36:28 +02:00
2015-03-31 12:38:24 +03:00
protected $dates = ['deleted_at'];
2015-11-12 22:36:28 +02:00
protected $presenter = 'App\Ninja\Presenters\PaymentPresenter';
2015-03-31 12:38:24 +03:00
2015-03-17 07:45:25 +10:00
public function invoice()
{
2015-03-31 12:38:24 +03:00
return $this->belongsTo('App\Models\Invoice')->withTrashed();
2015-03-17 07:45:25 +10:00
}
public function invitation()
{
2015-03-31 12:38:24 +03:00
return $this->belongsTo('App\Models\Invitation');
2015-03-17 07:45:25 +10:00
}
public function client()
{
2015-03-31 12:38:24 +03:00
return $this->belongsTo('App\Models\Client')->withTrashed();
2015-03-17 07:45:25 +10:00
}
public function user()
{
return $this->belongsTo('App\Models\User')->withTrashed();
}
2015-03-17 07:45:25 +10:00
public function account()
{
2015-03-31 12:38:24 +03:00
return $this->belongsTo('App\Models\Account');
2015-03-17 07:45:25 +10:00
}
public function contact()
{
2015-03-31 12:38:24 +03:00
return $this->belongsTo('App\Models\Contact');
2015-03-17 07:45:25 +10:00
}
2015-11-12 22:36:28 +02:00
public function account_gateway()
{
return $this->belongsTo('App\Models\AccountGateway');
}
public function payment_type()
{
return $this->belongsTo('App\Models\PaymentType');
}
2015-10-28 21:22:07 +02:00
public function getRoute()
{
return "/payments/{$this->public_id}/edit";
}
2015-03-17 07:45:25 +10:00
public function getAmount()
{
2015-06-10 11:34:20 +03:00
return Utils::formatMoney($this->amount, $this->client->getCurrencyId());
2015-03-17 07:45:25 +10:00
}
public function getName()
{
return trim("payment {$this->transaction_reference}");
}
public function getEntityType()
{
return ENTITY_PAYMENT;
}
}
2015-10-28 21:22:07 +02:00
Payment::creating(function ($payment) {
2015-03-17 07:45:25 +10:00
});
2015-10-28 21:22:07 +02:00
Payment::created(function ($payment) {
event(new PaymentWasCreated($payment));
});