mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 20:44:19 +00:00
220 lines
7.5 KiB
PHP
220 lines
7.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Classes\General\Interfaces\Steppable;
|
|
use App\Classes\General\Interfaces\Transportable;
|
|
use App\Classes\General\Interfaces\Packable;
|
|
use App\Classes\General\Interfaces\Transactionable;
|
|
|
|
use App\Classes\General\Traits\LogData;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use Carbon\Carbon;
|
|
use Eloquent;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Database\Query\Builder;
|
|
use Spatie\Activitylog\Models\Activity;
|
|
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
|
|
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
|
use Staudenmeir\EloquentHasManyDeep\HasTableAlias;
|
|
|
|
/**
|
|
* App\Models\PackingList
|
|
*
|
|
* @property int $id
|
|
* @property string $owner_type
|
|
* @property int $owner_id
|
|
* @property int|null $claimant_id
|
|
* @property string|null $reference_contract
|
|
* @property string $reference
|
|
* @property int $type
|
|
* @property int $status
|
|
* @property \Illuminate\Support\Carbon|null $deleted_at
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read Collection|Activity[] $activities
|
|
* @property-read int|null $activities_count
|
|
* @property-read Collection|Addon[] $addons
|
|
* @property-read int|null $addons_count
|
|
* @property-read Model|Eloquent $causer
|
|
* @property-read Collection|Container[] $containers
|
|
* @property-read int|null $containers_count
|
|
* @property-read Model|Eloquent $owner
|
|
* @property-read Collection|Package[] $packages
|
|
* @property-read int|null $packages_count
|
|
* @property-read Collection|PackingList[] $packingLists
|
|
* @property-read int|null $packing_lists_count
|
|
* @property-read Collection|PackingList[] $packing_list_owner
|
|
* @property-read int|null $packing_list_owner_count
|
|
* @property-read Collection|Remark[] $remarks
|
|
* @property-read int|null $remarks_count
|
|
* @property-read Collection|Step[] $steps
|
|
* @property-read int|null $steps_count
|
|
* @property-read Model|Eloquent $subject
|
|
* @property-read Model|Eloquent $target
|
|
* @property-read Collection|Transaction[] $transactions
|
|
* @property-read int|null $transactions_count
|
|
* @property-read Collection|Transport[] $transports
|
|
* @property-read int|null $transports_count
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList newQuery()
|
|
* @method static Builder|PackingList onlyTrashed()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList shipping()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList whereClaimantId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList whereDeletedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList whereOwnerId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList whereOwnerType($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList whereReference($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList whereReferenceContract($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList whereStatus($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList whereType($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|PackingList whereUpdatedAt($value)
|
|
* @method static Builder|PackingList withTrashed()
|
|
* @method static Builder|PackingList withoutTrashed()
|
|
* @mixin Eloquent
|
|
*/
|
|
class PackingList extends AbstractModel implements Transportable, Steppable, Packable, Transactionable
|
|
{
|
|
use HasTableAlias;
|
|
use HasRelationships;
|
|
use SoftDeletes;
|
|
use LogData;
|
|
|
|
protected $table = 'packing_lists';
|
|
|
|
protected $fillable = ['status'];
|
|
|
|
/**
|
|
* @return MorphTo
|
|
*/
|
|
public function owner(): morphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function addons(): morphMany
|
|
{
|
|
return $this->morphMany(Addon::class, 'owner');
|
|
}
|
|
|
|
public function containers(): BelongsToMany
|
|
{
|
|
return $this->BelongsToMany(Container::class, ContainerPackingList::class);
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function steps(): morphMany
|
|
{
|
|
return $this->morphMany(Step::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany
|
|
*/
|
|
public function packages(): hasMany
|
|
{
|
|
return $this->hasMany(Package::class, 'packing_list_id');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function transactions(): MorphMany
|
|
{
|
|
return $this->MorphMany(Transaction::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return HasManyDeep
|
|
*/
|
|
public function replicatedPackages(): HasManyDeep
|
|
{
|
|
// return $this->hasManyDeep(Package::class, [PackingList::class.' as replica', PackingList::class], [['owner_type', 'owner_id'], ['owner_type', 'owner_id'], 'packing_list_id'], [null, null, 'id']);
|
|
return $this->hasManyDeepFromRelations($this->packingLists(), (new PackingList)->setAlias('replica')->packages());
|
|
}
|
|
|
|
/**
|
|
* @return morphMany
|
|
*/
|
|
public function transports(): morphMany
|
|
{
|
|
return $this->morphMany(Transport::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function remarks(): morphMany
|
|
{
|
|
return $this->morphMany(Remark::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return belongsToMany
|
|
*/
|
|
public function packing_list_owner()
|
|
{
|
|
return $this->BelongsToMany(PackingList::class, 'packing_list_owner', 'owner_packing_list_id', 'packing_list_id');
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany
|
|
*/
|
|
public function packingLists(): morphMany
|
|
{
|
|
return $this->morphMany(PackingList::class, 'owner');
|
|
}
|
|
|
|
/**
|
|
* @return hasManyDeep
|
|
*/
|
|
public function shippingTransports(): hasManyDeep
|
|
{
|
|
return $this->hasManyDeep(Transport::class, [ContainerPackingList::class, Container::class], ['packing_list_id', 'id', ['owner_type', 'owner_id']], ['id', 'container_id', null]);
|
|
}
|
|
|
|
/**
|
|
* @return hasManyDeep
|
|
*/
|
|
public function shippingSchedules(): hasManyDeep
|
|
{
|
|
return $this->hasManyDeep(Schedule::class, [ContainerPackingList::class, Container::class, Transport::class], ['packing_list_id', 'id', ['owner_type', 'owner_id'], ['owner_type', 'owner_id']], ['id', 'container_id', null, null]);
|
|
}
|
|
|
|
|
|
/**
|
|
* @return hasManyDeep
|
|
*/
|
|
public function deliverySchedules(): hasManyDeep
|
|
{
|
|
return $this->hasManyDeep(Schedule::class, [Transport::class], [['owner_type', 'owner_id'], ['owner_type', 'owner_id']], [null, null]);
|
|
}
|
|
|
|
/**
|
|
* @param $query
|
|
* @return mixed
|
|
*/
|
|
public function scopeShipping($query){
|
|
return $query->whereHas('shippingSchedules', function($schedule){
|
|
return $schedule->where('etd', '<', Carbon::now())->where('schedules.status', ApprovalStatus::APPROVED);
|
|
})->whereDoesntHave('shippingTransports', function($transport){
|
|
return $transport->where('transport_arrangements.status', ApprovalStatus::COMPLETED);
|
|
});
|
|
}
|
|
|
|
}
|