mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-22 05:54:08 +00:00
WIP - Order steps & remaining APIs
This commit is contained in:
@@ -35,12 +35,6 @@ class CreateOrderLogic extends AbstractControllerLogic
|
||||
|
||||
$order = $this->createOrderProcessor->execute($request);
|
||||
|
||||
//$order_object = new OrderObject($request->get('company_module_id'), '', '', OrderType::SHARED_CONTAINER, OrderStatus::PROCESSING, OrderSteps::PROCESSING);
|
||||
|
||||
//$this->canCreateOrder->passes($order_object);
|
||||
|
||||
//$order = $this->createsOrder->execute($order_object);
|
||||
|
||||
return $this->resourceResponse(new OrderResource($order));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ class CreateOrderProcessor
|
||||
//Pre-approved order, no need Admin to process it
|
||||
$this->confirmOrderProcessor->execute($order->id);
|
||||
|
||||
//TODO: Add order roles - Allow multiple entity to process this order
|
||||
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanFetchPackingList;
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchContainerPackingList extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved PackingList',
|
||||
'message' => 'You have successfully retrieved a PackingList'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchPackingList */
|
||||
private $canFetchPackingList;
|
||||
|
||||
/** @var FetchesPackingList */
|
||||
private $fetchesPackingList;
|
||||
|
||||
/**
|
||||
* FetchPackingListControllersLogic constructor.
|
||||
* @param CanFetchPackingList $canFetchPackingList
|
||||
* @param FetchesPackingList $fetchesPackingList
|
||||
*/
|
||||
public function __construct(CanFetchPackingList $canFetchPackingList, FetchesPackingList $fetchesPackingList)
|
||||
{
|
||||
$this->canFetchPackingList = $canFetchPackingList;
|
||||
$this->fetchesPackingList = $fetchesPackingList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canFetchPackingList->passes();
|
||||
|
||||
$query = $this->fetchesPackingList->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new PackingListResource($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -54,20 +54,13 @@ class DeleteRemarkLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->canDeleteRemark->passes();
|
||||
|
||||
$this->canDeleteRemark->passes();
|
||||
$query = $this->fetchesRemark->execute(['id' => $request->route('id')]);
|
||||
|
||||
$query = $this->fetchesRemark->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->deletesRemark->execute($query);
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
$this->deletesRemark->execute($query);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,18 +49,11 @@ class FetchRemarkLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->canFetchRemark->passes();
|
||||
|
||||
$this->canFetchRemark->passes();
|
||||
|
||||
$query = $this->fetchesRemark->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new RemarkResource($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
$query = $this->fetchesRemark->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new RemarkResource($query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,18 +49,11 @@ class ListRemarksLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->canListRemarks->passes();
|
||||
|
||||
$this->canListRemarks->passes();
|
||||
|
||||
$query = $this->listsRemarks->execute($this->listsRemarks->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(RemarkResource::collection($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
$query = $this->listsRemarks->execute($this->listsRemarks->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(RemarkResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ class UpdateRemarkLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$object = new RemarkObject($request->input('comment'), $request->input('commenter_id'));
|
||||
|
||||
$this->canUpdateRemark->passes($object);
|
||||
@@ -72,7 +71,6 @@ class UpdateRemarkLogic extends AbstractControllerLogic
|
||||
$query = $this->updatesRemark->execute($query, $object);
|
||||
|
||||
return $this->resourceResponse(new RemarkResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class ScheduleObject implements DataTransferObject
|
||||
*/
|
||||
public function getETD(): Carbon
|
||||
{
|
||||
return $this->completed_date ? Carbon::parse($this->etd);
|
||||
return Carbon::parse($this->etd);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ class ScheduleObject implements DataTransferObject
|
||||
*/
|
||||
public function getETA(): Carbon
|
||||
{
|
||||
return $this->completed_date ? Carbon::parse($this->eta);
|
||||
return Carbon::parse($this->eta);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,18 +6,18 @@ use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\Modules\Schedules\DataTransferObjects\ScheduleObject;
|
||||
use App\Models\Schedule;
|
||||
use App\Models\TransportArrangement;
|
||||
use App\Models\Transport;
|
||||
|
||||
class CreatesSchedule extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param TransportArrangement $transport
|
||||
* @param Transport $transport
|
||||
* @param ScheduleObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(TransportArrangement $transport, ScheduleObject $object) {
|
||||
public function execute(Transport $transport, ScheduleObject $object) {
|
||||
$model = new Schedule();
|
||||
$model->etd = $object->getETD();
|
||||
$model->eta = $object->getETA();
|
||||
|
||||
@@ -8,7 +8,7 @@ use App\Classes\Modules\Transports\Services\CreatesTransport;
|
||||
use App\Classes\Modules\Transports\Services\FetchesDistrict;
|
||||
use App\Classes\Modules\Transports\Standards\Rules\CanCreateTransport;
|
||||
use App\Classes\Modules\Transports\DataTransferObjects\TransportObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\PackingLists\Services\FetchesContainerPackingList;
|
||||
use App\Http\Resources\TransportResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -30,11 +30,8 @@ class CreateTransportLogic extends AbstractControllerLogic
|
||||
/** @var CanCreateTransport */
|
||||
private $canCreateTransport;
|
||||
|
||||
/** @var FetchesDistrict */
|
||||
private $fetchesDistrict;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
/** @var FetchesContainerPackingList */
|
||||
private $fetchesContainerPackingList;
|
||||
|
||||
/** @var CreatesTransport */
|
||||
private $createsTransport;
|
||||
@@ -42,15 +39,13 @@ class CreateTransportLogic extends AbstractControllerLogic
|
||||
/**
|
||||
* CreateTransportLogic constructor.
|
||||
* @param CanCreateTransport $canCreateTransport
|
||||
* @param FetchesDistrict $fetchesDistrict
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param FetchesContainerPackingList $fetchesContainerPackingList
|
||||
* @param CreatesTransport $createsTransport
|
||||
*/
|
||||
public function __construct(CanCreateTransport $canCreateTransport, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesTransport $createsTransport)
|
||||
public function __construct(CanCreateTransport $canCreateTransport, FetchesContainerPackingList $fetchesContainerPackingList, CreatesTransport $createsTransport)
|
||||
{
|
||||
$this->canCreateTransport = $canCreateTransport;
|
||||
$this->fetchesDistrict = $fetchesDistrict;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->fetchesContainerPackingList = $fetchesContainerPackingList;
|
||||
$this->createsTransport = $createsTransport;
|
||||
}
|
||||
|
||||
@@ -64,13 +59,11 @@ class CreateTransportLogic extends AbstractControllerLogic
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]);
|
||||
|
||||
$object = new TransportObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'));
|
||||
$object = new TransportObject($request->input('type'), $request->input('courier'), $request->input('tracking_number'), null, null, 0);
|
||||
|
||||
$this->canCreateTransport->passes($object);
|
||||
|
||||
$query = $this->createsTransport->execute($this->fetchesCompany->execute(['id' => $request->input('company_id')]), $object);
|
||||
$query = $this->createsTransport->execute($this->fetchesContainerPackingList->execute(['id' => $request->input('container_id')]), $object);
|
||||
|
||||
return $this->resourceResponse(new TransportResource($query));
|
||||
|
||||
|
||||
@@ -54,20 +54,13 @@ class DeleteTransportLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->canDeleteTransport->passes();
|
||||
|
||||
$this->canDeleteTransport->passes();
|
||||
$query = $this->fetchesTransport->execute(['id' => $request->route('id')]);
|
||||
|
||||
$query = $this->fetchesTransport->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->deletesTransport->execute($query);
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
$this->deletesTransport->execute($query);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,18 +49,11 @@ class FetchTransportLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->canFetchTransport->passes();
|
||||
|
||||
$this->canFetchTransport->passes();
|
||||
|
||||
$query = $this->fetchesTransport->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new TransportResource($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
$query = $this->fetchesTransport->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new TransportResource($query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,18 +49,11 @@ class ListTransportsLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->canListTransports->passes();
|
||||
|
||||
$this->canListTransports->passes();
|
||||
|
||||
$query = $this->listsTransports->execute($this->listsTransports->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(TransportResource::collection($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
$query = $this->listsTransports->execute($this->listsTransports->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(TransportResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -62,25 +62,15 @@ class UpdateTransportLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$object = new TransportObject($request->input('type'), $request->input('courier'), $request->input('tracking_number'), $request->input('dispact_date'), $request->input('drop_date'), $request->input('status'));
|
||||
|
||||
$district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]);
|
||||
$object = new TransportObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'));
|
||||
//$object = new TransportObject($request->input('company_id'), $request->input('street_one'), $request->input('street_two'), $request->input('city'), $request->input('state'), $request->input('post_code'), $request->input('country'), $request->input('default'), $request->input('billing'));
|
||||
$this->canUpdateTransport->passes($object);
|
||||
|
||||
$this->canUpdateTransport->passes($object);
|
||||
$query = $this->fetchesTransport->execute(['id' => $request->route('id')]);
|
||||
|
||||
$query = $this->fetchesTransport->execute(['id' => $request->route('id')]);
|
||||
|
||||
$query = $this->updatesTransport->execute($query, $object);
|
||||
|
||||
return $this->resourceResponse(new TransportResource($query));
|
||||
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
$query = $this->updatesTransport->execute($query, $object);
|
||||
|
||||
return $this->resourceResponse(new TransportResource($query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,51 +3,52 @@
|
||||
namespace App\Classes\Modules\Transports\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class TransportObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var string */
|
||||
private $streetOne;
|
||||
private $type;
|
||||
|
||||
/** @var string|null */
|
||||
private $streetTwo;
|
||||
private $courier;
|
||||
|
||||
/** @var int */
|
||||
private $countryId;
|
||||
private $tracking_number;
|
||||
|
||||
/** @var int */
|
||||
private $stateId;
|
||||
private $dispacth_date;
|
||||
|
||||
/** @var int */
|
||||
private $districtId;
|
||||
private $drop_date;
|
||||
|
||||
/** @var int */
|
||||
private $postCode;
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* TransportObject constructor.
|
||||
* @param string $streetOne
|
||||
* @param null|string $streetTwo
|
||||
* @param int $countryId
|
||||
* @param int $stateId
|
||||
* @param int $districtId
|
||||
* @param int $postCode
|
||||
* @param string $type
|
||||
* @param null|string $courier
|
||||
* @param int $tracking_number
|
||||
* @param int $dispatch_date
|
||||
* @param int $drop_date
|
||||
* @param int $status
|
||||
*/
|
||||
public function __construct(string $streetOne, ?string $streetTwo, int $countryId, int $stateId, int $districtId, int $postCode)
|
||||
public function __construct(string $type, string $courier, int $tracking_number, ?string $dispatch_date, ?string $drop_date, int $status)
|
||||
{
|
||||
$this->streetOne = $streetOne;
|
||||
$this->streetTwo = $streetTwo;
|
||||
$this->countryId = $countryId;
|
||||
$this->stateId = $stateId;
|
||||
$this->districtId = $districtId;
|
||||
$this->postCode = $postCode;
|
||||
$this->type = $type;
|
||||
$this->courier = $courier;
|
||||
$this->tracking_number = $tracking_number;
|
||||
$this->dispatch_date = $dispatch_date;
|
||||
$this->drop_date = $drop_date;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStreetOne(): string
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->streetOne;
|
||||
}
|
||||
@@ -55,7 +56,7 @@ class TransportObject implements DataTransferObject
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getStreetTwo(): ?string
|
||||
public function getCourier(): ?string
|
||||
{
|
||||
return $this->streetTwo;
|
||||
}
|
||||
@@ -63,7 +64,7 @@ class TransportObject implements DataTransferObject
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCountryId(): int
|
||||
public function getTrackingNumber(): int
|
||||
{
|
||||
return $this->countryId;
|
||||
}
|
||||
@@ -71,25 +72,25 @@ class TransportObject implements DataTransferObject
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStateId(): int
|
||||
public function getDispatchDate(): Carbon
|
||||
{
|
||||
return $this->stateId;
|
||||
return $this->dispatch_date ? Carbon::parse($this->dispatch_date) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getDistrictId(): int
|
||||
public function getDropDate(): Carbon
|
||||
{
|
||||
return $this->districtId;
|
||||
return $this->drop_date ? Carbon::parse($this->drop_date) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPostCode(): int
|
||||
public function getStatus(): int
|
||||
{
|
||||
return $this->postCode;
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,9 +16,12 @@ class TransportValidation extends AbstractValidation
|
||||
*/
|
||||
protected function data($object): array {
|
||||
return [
|
||||
'street_one' => $object->getStreetOne(),
|
||||
'street_two' => $object->getStreetTwo(),
|
||||
'district_id' => $object->getDistrictId()
|
||||
'type' => $object->getType(),
|
||||
'courier' => $object->getCourier(),
|
||||
'tracking_number' => $object->getTrackingNumber()
|
||||
'dispacth_date' => $object->getDispatchDate()
|
||||
'drop_date' => $object->getDropDate()
|
||||
'status' => $object->getStatus()
|
||||
];
|
||||
}
|
||||
|
||||
@@ -27,8 +30,12 @@ class TransportValidation extends AbstractValidation
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'street_one' => 'required',
|
||||
'district_id' => 'required',
|
||||
'type' => 'required',
|
||||
'courier' => 'required',
|
||||
'tracking_number' => 'required',
|
||||
'dispacth_date' => '',
|
||||
'drop_date' => '',
|
||||
'status' => '',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,12 @@ class ContainerPackingList extends AbstractModel
|
||||
{
|
||||
return $this->hasMany(PackingList::class, 'packing_list_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function transports(): morphMany
|
||||
{
|
||||
return $this->morphMany(Transport::class, 'owner');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,20 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class TransportArrangement extends Model
|
||||
class Transport extends AbstractModel
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'schedules';
|
||||
|
||||
/**
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function schedule(): morphMany
|
||||
{
|
||||
return $this->morphMany(Schdule::class, 'owner');
|
||||
}
|
||||
}
|
||||
|
||||
+2744
-942
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user