2019-04-24 10:22:02 +10:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2023-01-29 09:21:40 +11:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
2021-06-16 16:58:16 +10:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 13:32:07 +10:00
|
|
|
*/
|
2019-04-24 10:22:02 +10:00
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2020-10-26 15:06:58 +11:00
|
|
|
use App\Jobs\Entity\CreateEntityPdf;
|
2020-01-20 21:10:33 +11:00
|
|
|
use App\Utils\Traits\Inviteable;
|
2019-04-24 10:22:02 +10:00
|
|
|
use App\Utils\Traits\MakesDates;
|
2020-10-28 21:10:49 +11:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2020-07-23 16:13:12 +10:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2020-03-29 23:22:14 +11:00
|
|
|
use Illuminate\Support\Carbon;
|
2020-04-16 18:41:25 +10:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2019-04-24 10:22:02 +10:00
|
|
|
|
2023-03-08 18:33:42 +11:00
|
|
|
/**
|
|
|
|
|
* App\Models\QuoteInvitation
|
|
|
|
|
*
|
|
|
|
|
* @property int $id
|
|
|
|
|
* @property int $company_id
|
|
|
|
|
* @property int $user_id
|
|
|
|
|
* @property int $client_contact_id
|
|
|
|
|
* @property int $quote_id
|
|
|
|
|
* @property string $key
|
|
|
|
|
* @property string|null $transaction_reference
|
|
|
|
|
* @property string|null $message_id
|
|
|
|
|
* @property string|null $email_error
|
|
|
|
|
* @property string|null $signature_base64
|
|
|
|
|
* @property string|null $signature_date
|
|
|
|
|
* @property string|null $sent_date
|
|
|
|
|
* @property string|null $viewed_date
|
|
|
|
|
* @property string|null $opened_date
|
|
|
|
|
* @property int|null $created_at
|
|
|
|
|
* @property int|null $updated_at
|
|
|
|
|
* @property int|null $deleted_at
|
|
|
|
|
* @property string|null $signature_ip
|
|
|
|
|
* @property string|null $email_status
|
|
|
|
|
* @property-read \App\Models\Company $company
|
|
|
|
|
* @property-read \App\Models\ClientContact $contact
|
|
|
|
|
* @property-read mixed $hashed_id
|
|
|
|
|
* @property-read \App\Models\Quote $quote
|
|
|
|
|
* @property-read \App\Models\User $user
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel company()
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns)
|
|
|
|
|
* @method static \Database\Factories\QuoteInvitationFactory factory($count = null, $state = [])
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation newModelQuery()
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation newQuery()
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation onlyTrashed()
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation query()
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel scope()
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereClientContactId($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereCompanyId($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereCreatedAt($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereDeletedAt($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereEmailError($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereEmailStatus($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereId($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereKey($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereMessageId($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereOpenedDate($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereQuoteId($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereSentDate($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereSignatureBase64($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereSignatureDate($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereSignatureIp($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereTransactionReference($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereUpdatedAt($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereUserId($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation whereViewedDate($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation withTrashed()
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation withoutTrashed()
|
|
|
|
|
* @mixin \Eloquent
|
|
|
|
|
*/
|
2019-04-24 10:22:02 +10:00
|
|
|
class QuoteInvitation extends BaseModel
|
|
|
|
|
{
|
2019-12-31 08:59:12 +11:00
|
|
|
use MakesDates;
|
2020-01-20 21:10:33 +11:00
|
|
|
use Inviteable;
|
2020-07-23 16:13:12 +10:00
|
|
|
use SoftDeletes;
|
2020-09-06 19:38:10 +10:00
|
|
|
|
2019-12-18 09:40:15 +11:00
|
|
|
protected $fillable = [
|
|
|
|
|
'id',
|
|
|
|
|
'client_contact_id',
|
|
|
|
|
];
|
|
|
|
|
|
2020-07-26 15:12:40 +10:00
|
|
|
protected $with = [
|
|
|
|
|
'company',
|
|
|
|
|
'contact',
|
|
|
|
|
];
|
2020-09-06 19:38:10 +10:00
|
|
|
|
2020-07-16 21:01:39 +10:00
|
|
|
protected $touches = ['quote'];
|
|
|
|
|
|
2020-05-06 21:49:42 +10:00
|
|
|
public function getEntityType()
|
|
|
|
|
{
|
2020-09-06 19:38:10 +10:00
|
|
|
return self::class;
|
2020-05-06 21:49:42 +10:00
|
|
|
}
|
|
|
|
|
|
2019-12-18 09:40:15 +11:00
|
|
|
public function entityType()
|
|
|
|
|
{
|
|
|
|
|
return Quote::class;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-24 10:22:02 +10:00
|
|
|
/**
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function quote()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Quote::class)->withTrashed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function contact()
|
|
|
|
|
{
|
2020-02-15 09:01:15 +00:00
|
|
|
return $this->belongsTo(ClientContact::class, 'client_contact_id', 'id')->withTrashed();
|
2019-04-24 10:22:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function user()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-10-28 21:10:49 +11:00
|
|
|
* @return BelongsTo
|
2019-04-24 10:22:02 +10:00
|
|
|
*/
|
|
|
|
|
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 22:09:43 +11:00
|
|
|
|
2020-03-21 16:37:30 +11:00
|
|
|
public function markViewed()
|
|
|
|
|
{
|
2020-03-04 22:09:43 +11:00
|
|
|
$this->viewed_date = Carbon::now();
|
|
|
|
|
$this->save();
|
|
|
|
|
}
|
2020-04-16 18:41:25 +10:00
|
|
|
|
|
|
|
|
public function pdf_file_path()
|
|
|
|
|
{
|
2021-06-12 21:50:01 +10:00
|
|
|
$storage_path = Storage::url($this->quote->client->quote_filepath($this).$this->quote->numberFormatter().'.pdf');
|
2020-04-16 18:41:25 +10:00
|
|
|
|
2021-06-12 21:50:01 +10:00
|
|
|
if (! Storage::exists($this->quote->client->quote_filepath($this).$this->quote->numberFormatter().'.pdf')) {
|
2022-08-01 07:30:04 +10:00
|
|
|
(new CreateEntityPdf($this))->handle();
|
2020-04-16 18:41:25 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $storage_path;
|
|
|
|
|
}
|
2019-04-24 10:22:02 +10:00
|
|
|
}
|