1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Models/QuoteInvitation.php

155 lines
4.7 KiB
PHP
Raw Normal View History

2019-04-24 02:22:02 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-05-11 05:32:07 +02:00
*/
2019-04-24 02:22:02 +02:00
namespace App\Models;
2020-10-26 05:06:58 +01:00
use App\Jobs\Entity\CreateEntityPdf;
use App\Utils\Traits\Inviteable;
2019-04-24 02:22:02 +02:00
use App\Utils\Traits\MakesDates;
2020-10-28 11:10:49 +01:00
use Illuminate\Database\Eloquent\Relations\BelongsTo;
2020-07-23 08:13:12 +02:00
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;
2019-04-24 02:22:02 +02:00
2023-03-08 08:33:42 +01: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
2023-08-11 06:18:58 +02:00
* @property \App\Models\Company $company
* @property \App\Models\ClientContact $contact
* @property mixed $hashed_id
* @property \App\Models\Quote $quote
* @property \App\Models\User $user
2023-03-08 08:33:42 +01:00
* @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 withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|QuoteInvitation withoutTrashed()
* @mixin \Eloquent
*/
2019-04-24 02:22:02 +02:00
class QuoteInvitation extends BaseModel
{
use MakesDates;
use Inviteable;
2020-07-23 08:13:12 +02:00
use SoftDeletes;
protected $fillable = [
'id',
'client_contact_id',
];
2020-07-26 07:12:40 +02:00
protected $with = [
'company',
'contact',
];
protected $touches = ['quote'];
public function getEntityType()
{
return self::class;
}
public function entityType()
{
return Quote::class;
}
2019-04-24 02:22:02 +02:00
/**
2023-09-05 02:49:16 +02:00
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
2019-04-24 02:22:02 +02:00
*/
2023-09-05 02:49:16 +02:00
public function quote(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2019-04-24 02:22:02 +02:00
{
return $this->belongsTo(Quote::class)->withTrashed();
}
2023-06-07 05:53:38 +02:00
/**
2023-09-05 02:49:16 +02:00
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
2023-06-07 05:53:38 +02:00
*/
2023-09-05 02:49:16 +02:00
public function entity(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2023-06-07 05:53:38 +02:00
{
return $this->belongsTo(Quote::class)->withTrashed();
}
2019-04-24 02:22:02 +02:00
/**
2023-09-05 02:49:16 +02:00
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
2019-04-24 02:22:02 +02:00
*/
2023-09-05 02:49:16 +02:00
public function contact(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2019-04-24 02:22:02 +02:00
{
return $this->belongsTo(ClientContact::class, 'client_contact_id', 'id')->withTrashed();
2019-04-24 02:22:02 +02:00
}
/**
2023-09-05 02:49:16 +02:00
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
2019-04-24 02:22:02 +02:00
*/
2023-09-05 02:49:16 +02:00
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2019-04-24 02:22:02 +02:00
{
return $this->belongsTo(User::class)->withTrashed();
}
/**
2023-09-05 02:49:16 +02:00
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
2019-04-24 02:22:02 +02:00
*/
2023-09-05 02:49:16 +02:00
public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2019-04-24 02:22:02 +02:00
{
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));
}
public function markViewed()
{
$this->viewed_date = Carbon::now();
$this->save();
}
public function pdf_file_path()
{
2021-06-12 13:50:01 +02:00
$storage_path = Storage::url($this->quote->client->quote_filepath($this).$this->quote->numberFormatter().'.pdf');
2021-06-12 13:50:01 +02:00
if (! Storage::exists($this->quote->client->quote_filepath($this).$this->quote->numberFormatter().'.pdf')) {
(new CreateEntityPdf($this))->handle();
}
return $storage_path;
}
2019-04-24 02:22:02 +02:00
}