mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
update replica packages logic and over weight price announcement
This commit is contained in:
@@ -16,10 +16,8 @@ class PackingListResource extends JsonResource
|
|||||||
*/
|
*/
|
||||||
public function toArray($request)
|
public function toArray($request)
|
||||||
{
|
{
|
||||||
$replica = $this->packingLists()->first();
|
$exceptionUsers = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]);
|
||||||
$exception = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]);
|
$packages = !$this->packingLists()->exists() || $exceptionUsers ? $this->packages : $this->packingLists->first()->packages;
|
||||||
|
|
||||||
$packages = (!$replica || $exception) ? $this->packages : $replica->packages;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
@@ -29,7 +27,6 @@ class PackingListResource extends JsonResource
|
|||||||
'transport' => new TransportResource($this->transports()->first()),
|
'transport' => new TransportResource($this->transports()->first()),
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'packages' => PackageResource::collection($packages),
|
'packages' => PackageResource::collection($packages),
|
||||||
'packing_list' => new PackingListResource($replica),
|
|
||||||
$this->mergeWhen($this->owner instanceof Order, [
|
$this->mergeWhen($this->owner instanceof Order, [
|
||||||
'order' => New OrderResource($this->owner)
|
'order' => New OrderResource($this->owner)
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -2,24 +2,28 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Classes\General\Interfaces\Packable;
|
|
||||||
use App\Classes\General\Interfaces\Steppable;
|
use App\Classes\General\Interfaces\Steppable;
|
||||||
use App\Classes\General\Interfaces\Transportable;
|
use App\Classes\General\Interfaces\Transportable;
|
||||||
|
use App\Classes\General\Interfaces\Packable;
|
||||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||||
|
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
|
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
|
||||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||||
|
use Staudenmeir\EloquentHasManyDeep\HasTableAlias;
|
||||||
|
|
||||||
class PackingList extends AbstractModel implements Transportable, Steppable, Packable
|
class PackingList extends AbstractModel implements Transportable, Steppable, Packable
|
||||||
{
|
{
|
||||||
use SoftDeletes;
|
use HasTableAlias;
|
||||||
use HasRelationships;
|
use HasRelationships;
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
protected $table = 'packing_lists';
|
protected $table = 'packing_lists';
|
||||||
|
|
||||||
@@ -54,6 +58,15 @@ class PackingList extends AbstractModel implements Transportable, Steppable, Pac
|
|||||||
return $this->hasMany(Package::class, 'packing_list_id');
|
return $this->hasMany(Package::class, 'packing_list_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
* @return morphMany
|
||||||
*/
|
*/
|
||||||
@@ -122,4 +135,5 @@ class PackingList extends AbstractModel implements Transportable, Steppable, Pac
|
|||||||
return $transport->where('transport_arrangements.status', ApprovalStatus::COMPLETED);
|
return $transport->where('transport_arrangements.status', ApprovalStatus::COMPLETED);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user