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

203 lines
7.2 KiB
PHP
Raw Normal View History

<?php
2022-06-10 10:00:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @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)
2022-06-10 10:00:07 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Models;
2022-06-06 05:28:10 +02:00
use App\Utils\Ninja;
use App\Utils\Traits\Inviteable;
use App\Utils\Traits\MakesDates;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\SoftDeletes;
2022-06-10 10:00:07 +02:00
use Illuminate\Support\Str;
2023-03-08 08:33:42 +01:00
/**
* App\Models\PurchaseOrderInvitation
*
* @property int $id
* @property int $company_id
* @property int $user_id
* @property int $vendor_contact_id
* @property int $purchase_order_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 $email_status
2023-08-11 06:18:58 +02:00
* @property \App\Models\Company $company
* @property \App\Models\VendorContact $contact
* @property string $hashed_id
* @property \App\Models\PurchaseOrder $purchase_order
* @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\PurchaseOrderInvitationFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation query()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel scope()
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereCompanyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereEmailError($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereEmailStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereKey($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereMessageId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereOpenedDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation wherePurchaseOrderId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereSentDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereSignatureBase64($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereSignatureDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereTransactionReference($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereVendorContactId($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation whereViewedDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrderInvitation withoutTrashed()
* @mixin \Eloquent
*/
class PurchaseOrderInvitation extends BaseModel
{
use MakesDates;
use SoftDeletes;
use Inviteable;
protected $fillable = [
'id',
'vendor_contact_id',
];
protected $with = [
'company',
'contact',
];
protected $touches = ['purchase_order'];
public function getEntityType()
{
return self::class;
}
2024-01-19 03:45:24 +01:00
public function getEntityString(): string
{
return 'purchase_order';
}
public function entityType()
{
return PurchaseOrder::class;
}
2023-08-04 10:13:26 +02:00
public function purchase_order(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(PurchaseOrder::class)->withTrashed();
}
2023-08-04 10:13:26 +02:00
public function entity(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2023-06-07 05:53:38 +02:00
{
return $this->belongsTo(PurchaseOrder::class)->withTrashed();
}
2023-08-04 10:13:26 +02:00
public function contact(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(VendorContact::class, 'vendor_contact_id', 'id')->withTrashed();
}
2023-08-04 10:13:26 +02:00
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
}
2023-08-04 10:13:26 +02:00
public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Company::class);
}
2023-08-04 10:13:26 +02:00
public function getName(): string
{
return $this->key;
}
2023-08-04 10:13:26 +02:00
public function markViewed(): void
{
$this->viewed_date = Carbon::now();
$this->save();
}
2024-01-14 05:05:00 +01:00
public function getPortalLink(): string
2022-06-06 05:28:10 +02:00
{
if (Ninja::isHosted()) {
2022-06-06 05:28:10 +02:00
$domain = $this->company->domain();
} else {
2022-06-06 05:28:10 +02:00
$domain = config('ninja.app_url');
}
2022-06-06 05:28:10 +02:00
switch ($this->company->portal_mode) {
case 'subdomain':
return $domain.'/vendor/';
case 'iframe':
return $domain.'/vendor/';
case 'domain':
return $domain.'/vendor/';
default:
return '';
}
}
2024-01-14 05:05:00 +01:00
public function getLink(): string
2022-06-10 10:00:07 +02:00
{
$entity_type = Str::snake(class_basename($this->entityType()));
if (Ninja::isHosted()) {
2022-06-10 10:00:07 +02:00
$domain = $this->company->domain();
} else {
2022-06-10 10:00:07 +02:00
$domain = config('ninja.app_url');
}
2022-06-10 10:00:07 +02:00
switch ($this->company->portal_mode) {
case 'subdomain':
return $domain.'/vendor/'.$entity_type.'/'.$this->key;
case 'iframe':
return $domain.'/vendor/'.$entity_type.'/'.$this->key;
case 'domain':
return $domain.'/vendor/'.$entity_type.'/'.$this->key;
default:
return '';
}
}
2024-01-14 05:05:00 +01:00
public function getAdminLink($use_react_link = false): string
2022-06-10 10:00:07 +02:00
{
2023-06-07 06:29:06 +02:00
return $use_react_link ? $this->getReactLink() : $this->getLink().'?silent=true';
2022-06-10 10:00:07 +02:00
}
2023-06-07 06:29:06 +02:00
private function getReactLink(): string
{
$entity_type = Str::snake(class_basename($this->entityType()));
2023-06-11 08:09:16 +02:00
return config('ninja.react_url')."/#/{$entity_type}s/{$this->{$entity_type}->hashed_id}/edit";
2023-06-07 06:29:06 +02:00
}
2023-10-26 04:57:44 +02:00
}