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

139 lines
3.1 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Models;
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;
use App\Utils\Traits\Inviteable;
use App\Utils\Traits\MakesDates;
2020-10-28 11:10:49 +01:00
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;
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',
];
protected $touches = ['credit'];
public function getEntityType()
{
return self::class;
}
// public function getSignatureDateAttribute($value)
// {
// if (!$value) {
// return (new Carbon($value))->format('Y-m-d');
// }
// return $value;
// }
// public function getSentDateAttribute($value)
// {
// if (!$value) {
// return (new Carbon($value))->format('Y-m-d');
// }
// return $value;
// }
// public function getViewedDateAttribute($value)
// {
// if (!$value) {
// return (new Carbon($value))->format('Y-m-d');
// }
// return $value;
// }
// public function getOpenedDateAttribute($value)
// {
// if (!$value) {
// return (new Carbon($value))->format('Y-m-d');
// }
// return $value;
// }
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
*/
public function company()
{
return $this->belongsTo(Company::class);
}
public function getName()
{
return $this->key;
}
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->credit->client->quote_filepath($this).$this->credit->numberFormatter().'.pdf');
2021-06-12 13:50:01 +02:00
if (! Storage::exists($this->credit->client->credit_filepath($this).$this->credit->numberFormatter().'.pdf')) {
event(new CreditWasUpdated($this->credit, $this->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
(new CreateEntityPdf($this))->handle();
}
return $storage_path;
}
}