mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-19 20:44:01 +00:00
201 lines
4.8 KiB
PHP
201 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Classes\General\Interfaces\Addressable;
|
|
use App\Classes\General\Interfaces\Contactable;
|
|
use App\Classes\General\Interfaces\ContainerOwner;
|
|
use App\Classes\General\Interfaces\Documentable;
|
|
use App\Classes\General\Interfaces\Packable;
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\BusinessType;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use PhpParser\Node\Expr\AssignOp\Mod;
|
|
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
|
|
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
|
use App\Classes\General\Interfaces\Remarkable;
|
|
|
|
/**
|
|
* Class CompanyModule
|
|
* @package App\Models
|
|
*
|
|
* @property \App\Models\Company company_id
|
|
* @property integer type
|
|
* @property integer status
|
|
*/
|
|
class CompanyModule extends AbstractModel implements Addressable, Documentable, Contactable, ContainerOwner, Packable, Remarkable
|
|
{
|
|
use HasRelationships;
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'company_modules';
|
|
|
|
protected $dates = ['deleted_at'];
|
|
|
|
/**
|
|
* @return BelongsTo
|
|
*/
|
|
public function company(): BelongsTo
|
|
{
|
|
return $this->BelongsTo(Company::class, 'company_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function contacts(): morphMany
|
|
{
|
|
return $this->morphMany(Contact::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function addresses(): morphMany
|
|
{
|
|
return $this->morphMany(Address::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function packingLists(): morphMany
|
|
{
|
|
return $this->morphMany(PackingList::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return hasManyDeep
|
|
*/
|
|
public function orderPackingLists(): hasManyDeep
|
|
{
|
|
return $this->hasManyDeep(PackingList::class, [Order::class], ['company_module_id', ['owner_type', 'owner_id']], ['id', null]);
|
|
}
|
|
|
|
/**
|
|
* @return belongsToMany
|
|
*/
|
|
public function employees(): belongsToMany
|
|
{
|
|
return $this->belongsToMany(User::class, (new CompanyEmployee())->getTable(), 'company_module_id', 'user_id');
|
|
}
|
|
|
|
/**
|
|
* @return belongsToMany
|
|
*/
|
|
public function invites(): belongsToMany
|
|
{
|
|
return $this->belongsToMany(CompanyModule::class, CompanyConnection::class,'inviter_id', 'invitee_id');
|
|
}
|
|
|
|
/**
|
|
* @return belongsToMany
|
|
*/
|
|
public function inviters(): belongsToMany
|
|
{
|
|
return $this->belongsToMany(CompanyModule::class, CompanyConnection::class,'invitee_id', 'inviter_id');
|
|
}
|
|
|
|
|
|
public function connections(): hasMany {
|
|
return $this->hasMany(CompanyConnection::class, 'invitee_id');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany
|
|
*/
|
|
public function orders(): HasMany
|
|
{
|
|
return $this->HasMany(Order::class, 'company_module_id');
|
|
}
|
|
|
|
/**
|
|
* @return belongsToMany
|
|
*/
|
|
public function segments(): belongsToMany
|
|
{
|
|
return $this->belongsToMany(Segment::class, (new SegmentCompany())->getTable(), 'company_id', 'segment_id');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function documents(): morphMany
|
|
{
|
|
return $this->morphMany(Document::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany
|
|
*/
|
|
public function banks(): HasMany
|
|
{
|
|
return $this->HasMany(BankAccount::class, 'company_id');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function containers(): morphMany
|
|
{
|
|
return $this->morphMany(Container::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @param Builder $query
|
|
* @return Builder
|
|
*/
|
|
public function scopeFreightForwarders(Builder $query)
|
|
{
|
|
return $query->where('type', '=', BusinessType::FREIGHT_FORWARDER);
|
|
}
|
|
|
|
/**
|
|
* @param Builder $query
|
|
* @return Builder
|
|
*/
|
|
public function scopeImporters(Builder $query)
|
|
{
|
|
return $query->where('type', '=', BusinessType::IMPORTER);
|
|
}
|
|
|
|
/**
|
|
* @param Builder $query
|
|
* @return Builder
|
|
*/
|
|
public function scopeWarehouses(Builder $query)
|
|
{
|
|
return $query->where('type', '=', BusinessType::WAREHOUSE);
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function remarks(): morphMany
|
|
{
|
|
return $this->morphMany(Remark::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return hasManyDeep
|
|
*/
|
|
public function transactions(): hasManyDeep
|
|
{
|
|
return $this->hasManyDeep(Transaction::class, [Order::class], ['company_module_id', 'owner_id'], ['id', 'id']);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|