mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
266 lines
7.9 KiB
PHP
266 lines
7.9 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 Eloquent;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
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 Illuminate\Support\Carbon;
|
|
use PhpParser\Node\Expr\AssignOp\Mod;
|
|
use Spatie\Activitylog\Models\Activity;
|
|
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
|
|
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
|
use App\Classes\General\Interfaces\Remarkable;
|
|
|
|
/**
|
|
* Class CompanyModule
|
|
*
|
|
* @package App\Models
|
|
* @property Company company_id
|
|
* @property integer type
|
|
* @property integer status
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $reference
|
|
* @property string $unity_hash_id
|
|
* @property string $unity_signature
|
|
* @property Carbon|null $deleted_at
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
* @property-read Collection|Activity[] $activities
|
|
* @property-read int|null $activities_count
|
|
* @property-read Collection|Address[] $addresses
|
|
* @property-read int|null $addresses_count
|
|
* @property-read Collection|BankAccount[] $banks
|
|
* @property-read int|null $banks_count
|
|
* @property-read Model|Eloquent $causer
|
|
* @property-read Company $company
|
|
* @property-read Collection|CompanyConnection[] $connections
|
|
* @property-read int|null $connections_count
|
|
* @property-read Collection|Contact[] $contacts
|
|
* @property-read int|null $contacts_count
|
|
* @property-read Collection|Container[] $containers
|
|
* @property-read int|null $containers_count
|
|
* @property-read Collection|Document[] $documents
|
|
* @property-read int|null $documents_count
|
|
* @property-read Collection|User[] $employees
|
|
* @property-read int|null $employees_count
|
|
* @property-read Collection|CompanyModule[] $inviters
|
|
* @property-read int|null $inviters_count
|
|
* @property-read Collection|CompanyModule[] $invites
|
|
* @property-read int|null $invites_count
|
|
* @property-read Collection|Order[] $orders
|
|
* @property-read int|null $orders_count
|
|
* @property-read Collection|PackingList[] $packingLists
|
|
* @property-read int|null $packing_lists_count
|
|
* @property-read Collection|Remark[] $remarks
|
|
* @property-read int|null $remarks_count
|
|
* @property-read Collection|Segment[] $segments
|
|
* @property-read int|null $segments_count
|
|
* @property-read Model|Eloquent $subject
|
|
* @property-read Model|Eloquent $target
|
|
* @method static Builder|CompanyModule freightForwarders()
|
|
* @method static Builder|CompanyModule importers()
|
|
* @method static Builder|CompanyModule newModelQuery()
|
|
* @method static Builder|CompanyModule newQuery()
|
|
* @method static \Illuminate\Database\Query\Builder|CompanyModule onlyTrashed()
|
|
* @method static Builder|CompanyModule query()
|
|
* @method static Builder|CompanyModule warehouses()
|
|
* @method static Builder|CompanyModule whereCompanyId($value)
|
|
* @method static Builder|CompanyModule whereCreatedAt($value)
|
|
* @method static Builder|CompanyModule whereDeletedAt($value)
|
|
* @method static Builder|CompanyModule whereId($value)
|
|
* @method static Builder|CompanyModule whereName($value)
|
|
* @method static Builder|CompanyModule whereReference($value)
|
|
* @method static Builder|CompanyModule whereStatus($value)
|
|
* @method static Builder|CompanyModule whereType($value)
|
|
* @method static Builder|CompanyModule whereUnityHashId($value)
|
|
* @method static Builder|CompanyModule whereUnitySignature($value)
|
|
* @method static Builder|CompanyModule whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Query\Builder|CompanyModule withTrashed()
|
|
* @method static \Illuminate\Database\Query\Builder|CompanyModule withoutTrashed()
|
|
* @mixin Eloquent
|
|
*/
|
|
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']);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|