2019-04-24 02:22:02 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-04-24 02:22:02 +02:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2020-04-16 10:41:25 +02:00
|
|
|
use App\Events\Quote\QuoteWasUpdated;
|
|
|
|
use App\Jobs\Quote\CreateQuotePdf;
|
2019-12-17 23:40:15 +01:00
|
|
|
use App\Models\Quote;
|
2020-01-20 11:10:33 +01:00
|
|
|
use App\Utils\Traits\Inviteable;
|
2019-04-24 02:22:02 +02:00
|
|
|
use App\Utils\Traits\MakesDates;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2020-03-29 14:22:14 +02:00
|
|
|
use Illuminate\Support\Carbon;
|
2020-04-16 10:41:25 +02:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2019-04-24 02:22:02 +02:00
|
|
|
|
|
|
|
class QuoteInvitation extends BaseModel
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
use MakesDates;
|
2020-01-20 11:10:33 +01:00
|
|
|
use Inviteable;
|
2019-04-24 02:22:02 +02:00
|
|
|
|
2019-12-17 23:40:15 +01:00
|
|
|
protected $fillable = [
|
|
|
|
'id',
|
|
|
|
'client_contact_id',
|
|
|
|
];
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-12-17 23:40:15 +01:00
|
|
|
public function entityType()
|
|
|
|
{
|
|
|
|
return Quote::class;
|
|
|
|
}
|
|
|
|
|
2019-04-24 02:22:02 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function quote()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Quote::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function contact()
|
|
|
|
{
|
2020-02-15 10:01:15 +01:00
|
|
|
return $this->belongsTo(ClientContact::class, 'client_contact_id', 'id')->withTrashed();
|
2019-04-24 02:22:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 signatureDiv()
|
|
|
|
{
|
|
|
|
if (! $this->signature_base64) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf('<img src="data:image/svg+xml;base64,%s"></img><p/>%s: %s', $this->signature_base64, ctrans('texts.signed'), $this->createClientDate($this->signature_date, $this->contact->client->timezone()->name));
|
|
|
|
}
|
2020-03-04 12:09:43 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function markViewed()
|
|
|
|
{
|
2020-03-04 12:09:43 +01:00
|
|
|
$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->quote->client->quote_filepath() . $this->quote->number . '.pdf');
|
|
|
|
|
|
|
|
if (!Storage::exists($this->quote->client->quote_filepath() . $this->quote->number . '.pdf')) {
|
|
|
|
event(new QuoteWasUpdated($this, $this->company));
|
|
|
|
CreateQuotePdf::dispatchNow($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $storage_path;
|
|
|
|
}
|
2019-04-24 02:22:02 +02:00
|
|
|
}
|