2020-01-20 02:31:58 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-01-20 02:31:58 +01: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)
|
2020-01-20 02:31:58 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-01-20 02:31:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2022-06-06 14:27:17 +02:00
|
|
|
use App\Models\Presenters\VendorContactPresenter;
|
2020-10-01 12:49:47 +02:00
|
|
|
use App\Notifications\ClientContactResetPassword;
|
2020-01-20 02:31:58 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Contracts\Translation\HasLocalePreference;
|
2020-10-01 12:49:47 +02:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2020-01-20 02:31:58 +01:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Laracasts\Presenter\PresentableTrait;
|
|
|
|
|
2023-03-08 08:33:42 +01:00
|
|
|
/**
|
|
|
|
* App\Models\VendorContact
|
|
|
|
*
|
|
|
|
* @property int $id
|
|
|
|
* @property int $company_id
|
|
|
|
* @property int $user_id
|
|
|
|
* @property int $vendor_id
|
|
|
|
* @property int|null $created_at
|
|
|
|
* @property int|null $updated_at
|
|
|
|
* @property int|null $deleted_at
|
|
|
|
* @property int $is_primary
|
|
|
|
* @property string|null $first_name
|
|
|
|
* @property string|null $last_name
|
|
|
|
* @property string|null $email
|
|
|
|
* @property string|null $phone
|
|
|
|
* @property string|null $custom_value1
|
|
|
|
* @property string|null $custom_value2
|
|
|
|
* @property string|null $custom_value3
|
|
|
|
* @property string|null $custom_value4
|
|
|
|
* @property int $send_email
|
|
|
|
* @property string|null $email_verified_at
|
|
|
|
* @property string|null $confirmation_code
|
|
|
|
* @property int $confirmed
|
|
|
|
* @property string|null $last_login
|
|
|
|
* @property int|null $failed_logins
|
|
|
|
* @property string|null $oauth_user_id
|
|
|
|
* @property int|null $oauth_provider_id
|
|
|
|
* @property string|null $google_2fa_secret
|
|
|
|
* @property string|null $accepted_terms_version
|
|
|
|
* @property string|null $avatar
|
|
|
|
* @property string|null $avatar_type
|
|
|
|
* @property string|null $avatar_size
|
|
|
|
* @property string $password
|
|
|
|
* @property string|null $token
|
|
|
|
* @property int $is_locked
|
|
|
|
* @property string|null $contact_key
|
|
|
|
* @property string|null $remember_token
|
|
|
|
* @property-read \App\Models\Company $company
|
|
|
|
* @property-read mixed $contact_id
|
|
|
|
* @property-read mixed $hashed_id
|
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
|
|
|
* @property-read int|null $notifications_count
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
|
|
|
* @property-read int|null $purchase_order_invitations_count
|
|
|
|
* @property-read \App\Models\User $user
|
|
|
|
* @property-read \App\Models\Vendor $vendor
|
|
|
|
* @method static \Database\Factories\VendorContactFactory factory($count = null, $state = [])
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact newModelQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact newQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact onlyTrashed()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact query()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereAcceptedTermsVersion($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereAvatar($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereAvatarSize($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereAvatarType($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereCompanyId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereConfirmationCode($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereConfirmed($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereContactKey($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereCreatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereCustomValue1($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereCustomValue2($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereCustomValue3($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereCustomValue4($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereDeletedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereEmail($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereEmailVerifiedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereFailedLogins($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereFirstName($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereGoogle2faSecret($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereIsLocked($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereIsPrimary($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereLastLogin($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereLastName($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereOauthProviderId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereOauthUserId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact wherePassword($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact wherePhone($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereRememberToken($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereSendEmail($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereToken($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereUpdatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereUserId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact whereVendorId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact withTrashed()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|VendorContact withoutTrashed()
|
2023-03-16 05:20:38 +01:00
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
2023-04-26 08:55:49 +02:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
2023-03-29 05:23:06 +02:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
2023-04-10 09:37:40 +02:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
2023-04-13 07:39:12 +02:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
2023-04-26 00:43:54 +02:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
2023-03-16 05:20:38 +01:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
2023-03-27 05:47:01 +02:00
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
2023-03-27 22:47:07 +02:00
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
2023-03-29 04:13:50 +02:00
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
2023-03-21 12:37:06 +01:00
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
2023-03-24 02:12:12 +01:00
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
2023-03-24 08:02:34 +01:00
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PurchaseOrderInvitation> $purchase_order_invitations
|
2023-03-08 08:33:42 +01:00
|
|
|
* @mixin \Eloquent
|
|
|
|
*/
|
2020-01-20 02:31:58 +01:00
|
|
|
class VendorContact extends Authenticatable implements HasLocalePreference
|
|
|
|
{
|
|
|
|
use Notifiable;
|
|
|
|
use MakesHash;
|
|
|
|
use PresentableTrait;
|
|
|
|
use SoftDeletes;
|
2020-10-01 12:49:47 +02:00
|
|
|
use HasFactory;
|
2020-01-20 02:31:58 +01:00
|
|
|
|
|
|
|
/* Used to authenticate a vendor */
|
|
|
|
protected $guard = 'vendor';
|
|
|
|
|
2020-07-16 13:01:39 +02:00
|
|
|
protected $touches = ['vendor'];
|
|
|
|
|
2022-06-06 14:27:17 +02:00
|
|
|
protected $presenter = VendorContactPresenter::class;
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
/* Allow microtime timestamps */
|
|
|
|
protected $dateFormat = 'Y-m-d H:i:s.u';
|
2022-06-21 12:03:51 +02:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
protected $appends = [
|
2020-09-06 11:38:10 +02:00
|
|
|
'hashed_id',
|
2020-01-20 02:31:58 +01:00
|
|
|
];
|
|
|
|
|
2022-09-09 03:07:14 +02:00
|
|
|
protected $with = [];
|
2020-01-20 02:31:58 +01:00
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'first_name',
|
|
|
|
'last_name',
|
|
|
|
'phone',
|
|
|
|
'custom_value1',
|
|
|
|
'custom_value2',
|
|
|
|
'custom_value3',
|
|
|
|
'custom_value4',
|
|
|
|
'email',
|
|
|
|
'is_primary',
|
2020-10-31 06:35:05 +01:00
|
|
|
'vendor_id',
|
2022-11-24 01:38:57 +01:00
|
|
|
'send_email',
|
2020-01-20 02:31:58 +01:00
|
|
|
];
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2022-06-13 11:59:24 +02:00
|
|
|
public function avatar()
|
|
|
|
{
|
|
|
|
if ($this->avatar) {
|
|
|
|
return $this->avatar;
|
|
|
|
}
|
|
|
|
|
|
|
|
return asset('images/svg/user.svg');
|
|
|
|
}
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-06-13 11:59:24 +02:00
|
|
|
public function setAvatarAttribute($value)
|
|
|
|
{
|
|
|
|
if (! filter_var($value, FILTER_VALIDATE_URL) && $value) {
|
|
|
|
$this->attributes['avatar'] = url('/').$value;
|
|
|
|
} else {
|
|
|
|
$this->attributes['avatar'] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-20 02:31:58 +01:00
|
|
|
public function getHashedIdAttribute()
|
|
|
|
{
|
|
|
|
return $this->encodePrimaryKey($this->id);
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
public function getContactIdAttribute()
|
|
|
|
{
|
|
|
|
return $this->encodePrimaryKey($this->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function vendor()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Vendor::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function primary_contact()
|
|
|
|
{
|
|
|
|
return $this->where('is_primary', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function company()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function sendPasswordResetNotification($token)
|
|
|
|
{
|
2022-06-10 09:04:16 +02:00
|
|
|
// $this->notify(new ClientContactResetPassword($token));
|
2020-01-20 02:31:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function preferredLocale()
|
|
|
|
{
|
|
|
|
$languages = Cache::get('languages');
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
return $languages->filter(function ($item) {
|
2022-06-10 09:04:16 +02:00
|
|
|
return $item->id == $this->company->getSetting('language_id');
|
2020-01-20 02:31:58 +01:00
|
|
|
})->first()->locale;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the model for a bound value.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param mixed $value
|
|
|
|
* @param null $field
|
|
|
|
* @return Model|null
|
2020-01-20 02:31:58 +01:00
|
|
|
*/
|
2020-11-25 15:19:52 +01:00
|
|
|
public function resolveRouteBinding($value, $field = null)
|
2020-01-20 02:31:58 +01:00
|
|
|
{
|
|
|
|
return $this
|
|
|
|
->withTrashed()
|
2023-02-03 21:41:25 +01:00
|
|
|
// ->company()
|
2023-01-22 06:34:47 +01:00
|
|
|
->where('id', $this->decodePrimaryKey($value))
|
|
|
|
->firstOrFail();
|
2020-01-20 02:31:58 +01:00
|
|
|
}
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-06-05 04:40:48 +02:00
|
|
|
public function purchase_order_invitations(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(PurchaseOrderInvitation::class);
|
|
|
|
}
|
2022-08-04 08:22:48 +02:00
|
|
|
|
|
|
|
public function getLoginLink()
|
|
|
|
{
|
|
|
|
$domain = isset($this->company->portal_domain) ? $this->company->portal_domain : $this->company->domain();
|
|
|
|
|
2022-08-04 08:30:11 +02:00
|
|
|
return $domain.'/vendor/key_login/'.$this->contact_key;
|
2022-08-04 08:22:48 +02:00
|
|
|
}
|
2020-01-20 02:31:58 +01:00
|
|
|
}
|