2020-01-07 01:13:47 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-01-07 01:13:47 +01:00
|
|
|
*
|
|
|
|
* @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;
|
2020-10-26 05:06:58 +01:00
|
|
|
use App\Jobs\Entity\CreateEntityPdf;
|
2020-07-08 14:02:16 +02:00
|
|
|
use App\Utils\Ninja;
|
2020-01-07 01:13:47 +01:00
|
|
|
use App\Utils\Traits\Inviteable;
|
|
|
|
use App\Utils\Traits\MakesDates;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2020-01-07 01:13:47 +01:00
|
|
|
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-07-26 07:12:40 +02:00
|
|
|
'company',
|
|
|
|
'contact',
|
2020-01-07 01:13:47 +01:00
|
|
|
];
|
|
|
|
|
2020-07-16 13:01:39 +02:00
|
|
|
protected $touches = ['credit'];
|
|
|
|
|
2020-05-06 13:49:42 +02:00
|
|
|
public function getEntityType()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
return self::class;
|
2020-05-06 13:49:42 +02:00
|
|
|
}
|
|
|
|
|
2020-07-14 07:37:49 +02:00
|
|
|
// public function getSignatureDateAttribute($value)
|
|
|
|
// {
|
|
|
|
// if (!$value) {
|
|
|
|
// return (new Carbon($value))->format('Y-m-d');
|
|
|
|
// }
|
|
|
|
// return $value;
|
|
|
|
// }
|
2020-03-29 14:22:14 +02:00
|
|
|
|
2020-07-14 07:37:49 +02:00
|
|
|
// public function getSentDateAttribute($value)
|
|
|
|
// {
|
|
|
|
// if (!$value) {
|
|
|
|
// return (new Carbon($value))->format('Y-m-d');
|
|
|
|
// }
|
|
|
|
// return $value;
|
|
|
|
// }
|
2020-03-29 14:22:14 +02:00
|
|
|
|
2020-07-14 07:37:49 +02:00
|
|
|
// public function getViewedDateAttribute($value)
|
|
|
|
// {
|
|
|
|
// if (!$value) {
|
|
|
|
// return (new Carbon($value))->format('Y-m-d');
|
|
|
|
// }
|
|
|
|
// return $value;
|
|
|
|
// }
|
2020-03-29 14:22:14 +02:00
|
|
|
|
2020-07-14 07:37:49 +02:00
|
|
|
// public function getOpenedDateAttribute($value)
|
|
|
|
// {
|
|
|
|
// if (!$value) {
|
|
|
|
// return (new Carbon($value))->format('Y-m-d');
|
|
|
|
// }
|
|
|
|
// return $value;
|
|
|
|
// }
|
2020-09-06 11:38:10 +02:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return BelongsTo
|
2020-01-07 01:13:47 +01:00
|
|
|
*/
|
|
|
|
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()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
$storage_path = Storage::url($this->credit->client->quote_filepath().$this->credit->number.'.pdf');
|
2020-04-16 10:41:25 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! Storage::exists($this->credit->client->credit_filepath().$this->credit->number.'.pdf')) {
|
2020-07-08 14:02:16 +02:00
|
|
|
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars()));
|
2020-10-26 05:06:58 +01:00
|
|
|
CreateEntityPdf::dispatchNow($this);
|
2020-04-16 10:41:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $storage_path;
|
|
|
|
}
|
2020-01-07 01:13:47 +01:00
|
|
|
}
|