2015-03-18 00:39:03 +01:00
|
|
|
<?php namespace App\Models;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-03-31 11:38:24 +02:00
|
|
|
use Auth;
|
2015-03-26 04:52:42 +01:00
|
|
|
use Eloquent;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* Class Activity
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
class Activity extends Eloquent
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2015-03-31 19:42:37 +02:00
|
|
|
public $timestamps = true;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $query
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function scopeScope($query)
|
|
|
|
{
|
|
|
|
return $query->whereAccountId(Auth::user()->account_id);
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function account()
|
|
|
|
{
|
2015-03-31 11:38:24 +02:00
|
|
|
return $this->belongsTo('App\Models\Account');
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
public function user()
|
|
|
|
{
|
2015-10-28 20:22:07 +01:00
|
|
|
return $this->belongsTo('App\Models\User')->withTrashed();
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-10-28 20:22:07 +01:00
|
|
|
public function contact()
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2015-10-28 20:22:07 +01:00
|
|
|
return $this->belongsTo('App\Models\Contact')->withTrashed();
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-10-28 20:22:07 +01:00
|
|
|
public function client()
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2015-10-28 20:22:07 +01:00
|
|
|
return $this->belongsTo('App\Models\Client')->withTrashed();
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-10-28 20:22:07 +01:00
|
|
|
public function invoice()
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2015-10-28 20:22:07 +01:00
|
|
|
return $this->belongsTo('App\Models\Invoice')->withTrashed();
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-10-28 20:22:07 +01:00
|
|
|
public function credit()
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2015-10-28 20:22:07 +01:00
|
|
|
return $this->belongsTo('App\Models\Credit')->withTrashed();
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-10-28 20:22:07 +01:00
|
|
|
public function payment()
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2015-10-28 20:22:07 +01:00
|
|
|
return $this->belongsTo('App\Models\Payment')->withTrashed();
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-12-07 14:34:55 +01:00
|
|
|
public function getMessage()
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2015-12-07 14:34:55 +01:00
|
|
|
$activityTypeId = $this->activity_type_id;
|
|
|
|
$account = $this->account;
|
|
|
|
$client = $this->client;
|
|
|
|
$user = $this->user;
|
|
|
|
$invoice = $this->invoice;
|
|
|
|
$contactId = $this->contact_id;
|
|
|
|
$payment = $this->payment;
|
|
|
|
$credit = $this->credit;
|
|
|
|
$isSystem = $this->is_system;
|
|
|
|
|
2015-10-28 20:22:07 +01:00
|
|
|
$data = [
|
|
|
|
'client' => link_to($client->getRoute(), $client->getDisplayName()),
|
|
|
|
'user' => $isSystem ? '<i>' . trans('texts.system') . '</i>' : $user->getDisplayName(),
|
|
|
|
'invoice' => $invoice ? link_to($invoice->getRoute(), $invoice->getDisplayName()) : null,
|
|
|
|
'quote' => $invoice ? link_to($invoice->getRoute(), $invoice->getDisplayName()) : null,
|
|
|
|
'contact' => $contactId ? $client->getDisplayName() : $user->getDisplayName(),
|
|
|
|
'payment' => $payment ? $payment->transaction_reference : null,
|
2016-04-23 22:40:19 +02:00
|
|
|
'payment_amount' => $payment ? $account->formatMoney($payment->amount, $payment) : null,
|
|
|
|
'adjustment' => $this->adjustment ? $account->formatMoney($this->adjustment, $this) : asdf,
|
2015-12-07 14:34:55 +01:00
|
|
|
'credit' => $credit ? $account->formatMoney($credit->amount, $client) : null,
|
2015-10-28 20:22:07 +01:00
|
|
|
];
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-10-28 20:22:07 +01:00
|
|
|
return trans("texts.activity_{$activityTypeId}", $data);
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
}
|