2020-01-07 01:13:47 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2020-04-16 10:41:25 +02:00
|
|
|
use App\Events\Credit\CreditWasUpdated;
|
|
|
|
use App\Jobs\Credit\CreateCreditPdf;
|
2020-01-07 01:13:47 +01:00
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Utils\Traits\Inviteable;
|
|
|
|
use App\Utils\Traits\MakesDates;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
use Illuminate\Support\Carbon;
|
2020-04-16 10:41:25 +02:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2020-01-07 01:13:47 +01:00
|
|
|
|
|
|
|
class CreditInvitation extends BaseModel
|
|
|
|
{
|
|
|
|
use MakesDates;
|
|
|
|
use SoftDeletes;
|
|
|
|
use Inviteable;
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'id',
|
|
|
|
'client_contact_id',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $with = [
|
2020-02-06 10:35:51 +01:00
|
|
|
// 'company',
|
2020-01-07 01:13:47 +01:00
|
|
|
];
|
|
|
|
|
2020-05-06 13:49:42 +02:00
|
|
|
public function getEntityType()
|
|
|
|
{
|
|
|
|
return CreditInvitation::class;
|
|
|
|
}
|
|
|
|
|
2020-04-04 12:32:42 +02:00
|
|
|
public function getSignatureDateAttribute($value)
|
|
|
|
{
|
2020-03-29 14:22:14 +02:00
|
|
|
if (!$value) {
|
2020-04-04 12:32:42 +02:00
|
|
|
return (new Carbon($value))->format('Y-m-d');
|
2020-03-29 14:22:14 +02:00
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2020-04-04 12:32:42 +02:00
|
|
|
public function getSentDateAttribute($value)
|
|
|
|
{
|
2020-03-29 14:22:14 +02:00
|
|
|
if (!$value) {
|
2020-04-04 12:32:42 +02:00
|
|
|
return (new Carbon($value))->format('Y-m-d');
|
2020-03-29 14:22:14 +02:00
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2020-04-04 12:32:42 +02:00
|
|
|
public function getViewedDateAttribute($value)
|
|
|
|
{
|
2020-03-29 14:22:14 +02:00
|
|
|
if (!$value) {
|
2020-04-04 12:32:42 +02:00
|
|
|
return (new Carbon($value))->format('Y-m-d');
|
2020-03-29 14:22:14 +02:00
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2020-04-04 12:32:42 +02:00
|
|
|
public function getOpenedDateAttribute($value)
|
|
|
|
{
|
2020-03-29 14:22:14 +02:00
|
|
|
if (!$value) {
|
2020-04-04 12:32:42 +02:00
|
|
|
return (new Carbon($value))->format('Y-m-d');
|
2020-03-29 14:22:14 +02:00
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2020-01-07 01:13:47 +01:00
|
|
|
public function entityType()
|
|
|
|
{
|
|
|
|
return Credit::class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function credit()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Credit::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function contact()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(ClientContact::class, 'client_contact_id', 'id')->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function company()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->key;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function markViewed()
|
|
|
|
{
|
|
|
|
$this->viewed_date = Carbon::now();
|
|
|
|
$this->save();
|
|
|
|
}
|
2020-04-16 10:41:25 +02:00
|
|
|
|
|
|
|
public function pdf_file_path()
|
|
|
|
{
|
|
|
|
$storage_path = Storage::url($this->credit->client->quote_filepath() . $this->credit->number . '.pdf');
|
|
|
|
|
|
|
|
if (!Storage::exists($this->credit->client->credit_filepath() . $this->credit->number . '.pdf')) {
|
|
|
|
event(new CreditWasUpdated($this, $this->company));
|
|
|
|
CreateCreditPdf::dispatchNow($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $storage_path;
|
|
|
|
}
|
2020-01-07 01:13:47 +01:00
|
|
|
}
|