2019-04-24 02:22:02 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @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;
|
2020-10-26 05:06:58 +01:00
|
|
|
use App\Jobs\Entity\CreateEntityPdf;
|
2019-12-17 23:40:15 +01:00
|
|
|
use App\Models\Quote;
|
2020-07-08 14:02:16 +02:00
|
|
|
use App\Utils\Ninja;
|
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-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;
|
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;
|
2020-07-23 08:13:12 +02:00
|
|
|
use SoftDeletes;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-17 23:40:15 +01:00
|
|
|
protected $fillable = [
|
|
|
|
'id',
|
|
|
|
'client_contact_id',
|
|
|
|
];
|
|
|
|
|
2020-07-26 07:12:40 +02:00
|
|
|
protected $with = [
|
|
|
|
'company',
|
|
|
|
'contact',
|
|
|
|
];
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-07-16 13:01:39 +02:00
|
|
|
protected $touches = ['quote'];
|
|
|
|
|
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
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return BelongsTo
|
2019-04-24 02:22:02 +02: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 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()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
$storage_path = Storage::url($this->quote->client->quote_filepath().$this->quote->number.'.pdf');
|
2020-04-16 10:41:25 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! Storage::exists($this->quote->client->quote_filepath().$this->quote->number.'.pdf')) {
|
2020-07-14 12:35:41 +02:00
|
|
|
event(new QuoteWasUpdated($this->quote, $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;
|
|
|
|
}
|
2019-04-24 02:22:02 +02:00
|
|
|
}
|