mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-24 23:14:16 +00:00
Merge branch 'development' into 'master'
hide all setting until the set up is complete See merge request CIEFWorldwideSdnBhd/shipping-portal!107
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class OwnerId implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('owner_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Interfaces;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
interface Transactionable
|
||||
{
|
||||
|
||||
public function transactions(): morphMany;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\ResourceConflictException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Accounts\Processors\CreateUserProcessor;
|
||||
use App\Classes\Modules\Accounts\Processors\GenerateEmailVerificationAttemptProcessor;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\EmploymentObject;
|
||||
use App\Classes\Modules\Companies\Processors\AssignEmployeeProcessor;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Http\Resources\UserResource;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AddNewMemberLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
public function notification(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Updated Email',
|
||||
'message' => 'Successfully updated email'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @var AssignEmployeeProcessor
|
||||
*/
|
||||
private $assignEmployeeProcessor;
|
||||
|
||||
/**
|
||||
* @var GenerateEmailVerificationAttemptProcessor
|
||||
*/
|
||||
private $generateEmailVerificationAttemptProcessor;
|
||||
|
||||
/**
|
||||
* AddNewMemberLogic constructor.
|
||||
* @param AssignEmployeeProcessor $assignEmployeeProcessor
|
||||
* @param GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor
|
||||
*/
|
||||
public function __construct(AssignEmployeeProcessor $assignEmployeeProcessor, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor)
|
||||
{
|
||||
$this->assignEmployeeProcessor = $assignEmployeeProcessor;
|
||||
$this->generateEmailVerificationAttemptProcessor = $generateEmailVerificationAttemptProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ResourceConflictException
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$user = Auth::user()->replicate();
|
||||
$user->email = $request->input('email');
|
||||
$user->status = ApprovalStatus::PENDING_VERIFICATION;
|
||||
$user->save();
|
||||
} catch (QueryException $exception){
|
||||
throw new ResourceConflictException('Unable to change your email address as it already exists');
|
||||
}
|
||||
|
||||
if($company = Auth::user()->companyModule()->first()){
|
||||
$Object = new EmploymentObject($company, $user);
|
||||
$this->assignEmployeeProcessor->execute($Object);
|
||||
}
|
||||
|
||||
$this->generateEmailVerificationAttemptProcessor->execute($user);
|
||||
|
||||
return $this->resourceResponse(new UserResource($user));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\Services\ListsAddresses;
|
||||
use App\Classes\Modules\Addresses\Services\ListsStates;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanListAddresses;
|
||||
use App\Http\Resources\AddressResource;
|
||||
use App\Http\Resources\StateResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListStatesLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Addresses',
|
||||
'message' => 'You have successfully retrieved a list of Addresses'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListsStates */
|
||||
private $listStates;
|
||||
|
||||
/**
|
||||
* ListStatesLogic constructor.
|
||||
* @param ListsStates $listStates
|
||||
*/
|
||||
public function __construct(ListsStates $listStates)
|
||||
{
|
||||
$this->listStates = $listStates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->listStates->execute($this->listStates->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(StateResource::collection($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Addresses\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use App\Models\State;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ListsStates extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var State */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsStates constructor.
|
||||
* @param State $repository
|
||||
*/
|
||||
public function __construct(State $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
namespace App\Classes\Modules\Announcements\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class AnnouncementObject implements DataTransferObject
|
||||
{
|
||||
|
||||
@@ -54,20 +52,18 @@ class AnnouncementObject implements DataTransferObject
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
* @return string
|
||||
*/
|
||||
public function getStartingOn(): Carbon
|
||||
public function getStartingOn(): string
|
||||
{
|
||||
// return $this->starting_on;
|
||||
return Carbon::parse($this->starting_on);
|
||||
return $this->starting_on;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
* @return string
|
||||
*/
|
||||
public function getEndingOn(): Carbon
|
||||
public function getEndingOn(): string
|
||||
{
|
||||
// return $this->ending_on;
|
||||
return Carbon::parse($this->ending_on);
|
||||
return $this->ending_on;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Classes\Modules\Companies\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Services\UpdatesCompany;
|
||||
use App\Classes\Modules\Companies\Services\UpdatesCompanyModuleName;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Companies\Standards\Rules\CanUpdateCompany;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
@@ -35,17 +36,22 @@ class UpdateCompanyLogic extends AbstractControllerLogic
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var UpdatesCompanyModuleName */
|
||||
private $updatesCompanyModuleName;
|
||||
|
||||
/**
|
||||
* UpdateCompanyControllersLogic constructor.
|
||||
* @param CanUpdateCompany $canUpdateCompany
|
||||
* @param UpdatesCompany $updatesCompany
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param UpdatesCompanyModuleName $updatesCompanyModuleName
|
||||
*/
|
||||
public function __construct(CanUpdateCompany $canUpdateCompany, UpdatesCompany $updatesCompany, FetchesCompany $fetchesCompany)
|
||||
public function __construct(CanUpdateCompany $canUpdateCompany, UpdatesCompany $updatesCompany, FetchesCompany $fetchesCompany, UpdatesCompanyModuleName $updatesCompanyModuleName)
|
||||
{
|
||||
$this->canUpdateCompany = $canUpdateCompany;
|
||||
$this->updatesCompany = $updatesCompany;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->updatesCompanyModuleName = $updatesCompanyModuleName;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,23 +62,17 @@ class UpdateCompanyLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$object = new CompanyObject($request->input('name'), $request->input('reference'), $request->input('type'));
|
||||
|
||||
$object = new CompanyObject($request->input('reference_no'), $request->input('name'), $request->input('type'));
|
||||
$this->canUpdateCompany->passes($object);
|
||||
|
||||
$this->canUpdateCompany->passes($object);
|
||||
$query = $this->fetchesCompany->execute(['id' => $request->route('id')]);
|
||||
|
||||
$query = $this->fetchesCompany->execute(['id' => $request->route('id')]);
|
||||
$query = $this->updatesCompany->execute($query, $object);
|
||||
|
||||
$query = $this->updatesCompany->execute($query, $object);
|
||||
|
||||
return $this->resourceResponse(new CompanyResource($query));
|
||||
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
$this->updatesCompanyModuleName->execute($query->companyModules()->first(), $object->getName());
|
||||
|
||||
return $this->resourceResponse(new CompanyResource($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
use App\Models\Company;
|
||||
|
||||
class UpdatesCompany extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Company $model
|
||||
* @param CompanyObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Company $model, CompanyObject $object)
|
||||
{
|
||||
$model->name = $object->getName();
|
||||
$model->reference = $object->getReference();
|
||||
$model->type = $object->getType();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyModuleObject;
|
||||
use App\Models\CompanyModule;
|
||||
|
||||
class UpdatesCompanyModuleName extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param CompanyModule $model
|
||||
* @param CompanyModuleObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(CompanyModule $model, string $name)
|
||||
{
|
||||
$model->name = $name;
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
use App\Classes\Modules\Companies\Standards\Validators\CompanyValidation;
|
||||
|
||||
class CanUpdateCompany extends AbstractRule
|
||||
{
|
||||
/** @var CompanyValidation */
|
||||
private $companyValidation;
|
||||
|
||||
|
||||
/**
|
||||
* CanUpdateCompany constructor.
|
||||
* @param CompanyValidation $companyValidation
|
||||
*/
|
||||
public function __construct(CompanyValidation $companyValidation)
|
||||
{
|
||||
$this->companyValidation = $companyValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->companyValidation->validate($object, 'PUT');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,8 @@ class CompanyValidation extends AbstractValidation
|
||||
{
|
||||
return [
|
||||
'company_name' => $object->getName(),
|
||||
'company_reference' => $object->getReference()
|
||||
'company_reference' => $object->getReference(),
|
||||
'type' => $object->getType()
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Documents\ControllersLogic;
|
||||
|
||||
use App\Classes\Modules\Documents\Standards\Rules\CanUpdateDocumentReference;
|
||||
use App\Http\Resources\DocumentResource;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Documents\Services\FetchesDocument;
|
||||
use App\Classes\Modules\Documents\Services\UpdatesDocumentReference;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateDocumentReferenceLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Update Document Reference',
|
||||
'message' => 'You have successfully updated the Document Reference'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdateDocumentReference*/
|
||||
private $canUpdateDocumentReference;
|
||||
|
||||
/** @var UpdatesDocumentReference */
|
||||
private $updatesDocumentReference;
|
||||
|
||||
/** @var FetchesDocument */
|
||||
private $fetchesDocument;
|
||||
|
||||
|
||||
/**
|
||||
* RejectDocumentLogic constructor.
|
||||
* @param CanApproveDocument $canApproveDocument
|
||||
* @param ApprovesDocument $approvesDocument
|
||||
* @param FetchesDocument $fetchesDocument
|
||||
*/
|
||||
public function __construct(CanUpdateDocumentReference $canUpdateDocumentReference, UpdatesDocumentReference $updatesDocumentReference, FetchesDocument $fetchesDocument)
|
||||
{
|
||||
$this->canUpdateDocumentReference = $canUpdateDocumentReference;
|
||||
$this->updatesDocumentReference = $updatesDocumentReference;
|
||||
$this->fetchesDocument = $fetchesDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$document = $this->fetchesDocument->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->canUpdateDocumentReference->passes();
|
||||
|
||||
$document_query = $this->updatesDocumentReference->execute($document, $request->input('identification_number'));
|
||||
|
||||
return $this->resourceResponse(new DocumentResource($document_query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Documents\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\Document;
|
||||
|
||||
class UpdatesDocumentReference extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Document $model
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute(Document $model, string $reference) {
|
||||
$model->reference = $reference;
|
||||
return $this->handler($model);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Documents\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
|
||||
class CanUpdateDocumentReference extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DocumentObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DocumentObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Container;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ExportsContainerPackingList implements FromQuery, WithHeadingRow, WithMapping
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
protected $id;
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Marking',
|
||||
'Refrence',
|
||||
'Quantity',
|
||||
'CBM',
|
||||
'Status',
|
||||
'Delivery Phone',
|
||||
'Delivery Refrence',
|
||||
'Delivery Address',
|
||||
'Remark',
|
||||
'Delivery Date'
|
||||
];
|
||||
}
|
||||
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return Container::find($this->id)->packingLists();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Company $container
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function map($packing_list): array
|
||||
{
|
||||
$order = $packing_list->owner()->first();
|
||||
$address = $order->addresses()->first();
|
||||
$company = $order->companyModule()->first();
|
||||
$connection = $company->inviters()->withPivot('invitee_reference')->first();
|
||||
$marking = $connection ? $connection->pivot->invitee_reference:'';
|
||||
|
||||
$quantity = 0;
|
||||
$cbm = 0;
|
||||
foreach ($packing_list->packages()->get() as $key => $row) {
|
||||
$quantity += $row->quantity;
|
||||
$cbm += (($row->width / 100) * ($row->height / 100) * ($row->length / 100)) * $row->quantity;
|
||||
}
|
||||
|
||||
$status = '';
|
||||
if ($packing_list->transports()->count() > 0) {
|
||||
$status = 'Delivery';
|
||||
}
|
||||
elseif ($packing_list->status == ApprovalStatus::SUSPENDED) {
|
||||
$status = 'On Hold';
|
||||
}
|
||||
elseif ($packing_list->status != ApprovalStatus::SUSPENDED) {
|
||||
$status = 'Release';
|
||||
}
|
||||
|
||||
return [
|
||||
$marking,
|
||||
$order->reference,
|
||||
$quantity,
|
||||
$cbm,
|
||||
$status,
|
||||
$address->contacts()->first() ? $address->contacts()->first()->phone : 'n/a',
|
||||
$address->contacts()->first() ? $address->contacts()->first()->reference : 'n/a',
|
||||
$address->street_one . ' ' . $address->street_two . ' ' . $address->district->name . ' ' . $address->post_code . ' ' . $address->state->name . ' ' . $address->country->name,
|
||||
$address->remarks()->first() ? $address->remarks()->first()->content : 'n/a',
|
||||
$packing_list->transports()->first() ? $packing_list->transports()->current_schedule->eta : 'n/a'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@ use App\Classes\Modules\Addresses\Services\FetchesAddress;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanApproveChangeOrderAddress;
|
||||
use App\Classes\Modules\Orders\Services\UpdatesOrdersAddress;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
|
||||
use App\Classes\Modules\PackingLists\Services\UpdatesPackingListOwner;
|
||||
use App\Classes\Modules\Transports\Services\UpdatesTransportStatus;
|
||||
use App\Classes\Modules\Unity\Services\CreatesContract;
|
||||
use App\Classes\Modules\Unity\Processors\ActivateContractProcessor;
|
||||
use App\Classes\Modules\Unity\Processors\CreateContractEntityProcessor;
|
||||
use App\Classes\Modules\Unity\Processors\AssignContractEntityProcessor;
|
||||
use App\Classes\Modules\PackingLists\Services\UpdatesPackingListContractReference;
|
||||
use App\Classes\Modules\Steps\Services\CreatesStep;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
|
||||
use App\Classes\Modules\Steps\DataTransferObjects\StepsObject;
|
||||
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AssignPackingListOrderLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Assign Packing List Order',
|
||||
'message' => 'You have successfully created a Packing List Order'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesPackingList */
|
||||
private $fetchesPackingList;
|
||||
|
||||
|
||||
/** @var FetchesOrder */
|
||||
private $fetchesOrder;
|
||||
|
||||
/** @var UpdatesPackingListOwner */
|
||||
private $updatesPackingListOwner;
|
||||
|
||||
/** @var UpdatesTransportStatus */
|
||||
private $updatesTransportStatus;
|
||||
|
||||
/** @var CreatesContract */
|
||||
private $unityCreateContract;
|
||||
|
||||
/** @var ActivateContractProcessor */
|
||||
private $unityActivateContract;
|
||||
|
||||
/** @var CreateContractEntityProcessor */
|
||||
private $unityCreateContractEntity;
|
||||
|
||||
/** @var AssignContractEntityProcessor */
|
||||
private $unityAssignContractEntity;
|
||||
|
||||
/** @var UpdatesPackingListContractReference */
|
||||
private $updatesPackingListContractReference;
|
||||
|
||||
/** @var CreatesStep */
|
||||
private $createsStep;
|
||||
|
||||
/**
|
||||
* CreateRemarkLogic constructor.
|
||||
* @param CanCreateRemark $canCreateRemark
|
||||
* @param CreatesPackingListRemark $createsPackingListRemark
|
||||
*/
|
||||
public function __construct(FetchesPackingList $fetchesPackingList, FetchesOrder $fetchesOrder, UpdatesPackingListOwner $updatesPackingListOwner, UpdatesTransportStatus $updatesTransportStatus, CreatesContract $unityCreateContract, ActivateContractProcessor $unityActivateContract, CreateContractEntityProcessor $unityCreateContractEntity, AssignContractEntityProcessor $unityAssignContractEntity, UpdatesPackingListContractReference $updatesPackingListContractReference, CreatesStep $createsStep)
|
||||
{
|
||||
$this->fetchesPackingList = $fetchesPackingList;
|
||||
$this->fetchesOrder = $fetchesOrder;
|
||||
$this->updatesPackingListOwner = $updatesPackingListOwner;
|
||||
$this->updatesTransportStatus = $updatesTransportStatus;
|
||||
|
||||
$this->unityCreateContract = $unityCreateContract;
|
||||
$this->unityActivateContract = $unityActivateContract;
|
||||
$this->unityCreateContractEntity = $unityCreateContractEntity;
|
||||
$this->unityAssignContractEntity = $unityAssignContractEntity;
|
||||
|
||||
$this->updatesPackingListContractReference = $updatesPackingListContractReference;
|
||||
$this->createsStep = $createsStep;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$warehouse_packing_list = $this->fetchesPackingList->execute([
|
||||
'id' => $request->route('id'),
|
||||
'type' => PackingListType::WAREHOUSE_RECEIVE_LIST,
|
||||
'status' => ApprovalStatus::REJECTED
|
||||
]);
|
||||
|
||||
$order = $this->fetchesOrder->execute(['reference' => $request->route('reference')]);
|
||||
|
||||
$warehouse_packing_list = $this->updatesPackingListOwner->execute($warehouse_packing_list, $order);
|
||||
|
||||
|
||||
$transport = $warehouse_packing_list->transports()->first();
|
||||
$transport = $this->updatesTransportStatus->execute($transport, ApprovalStatus::APPROVED);
|
||||
|
||||
$contract = $this->unityCreateContract->execute();
|
||||
$contractReference = $contract->hash_id;
|
||||
$contractObligations = $contract->contract_obligation_list;
|
||||
|
||||
$this->unityActivateContract->execute($contractReference);
|
||||
$supervisorHashId = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->unity_hash_id;
|
||||
|
||||
$supervisorContractEntity = $this->unityCreateContractEntity->execute($contractReference, $supervisorHashId);
|
||||
$order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->update(['entity_hash_id' => $supervisorContractEntity->hash_id, 'entity_signature' => $supervisorContractEntity->entity_signature_hash_id]);
|
||||
|
||||
$importerContractEntity = $this->unityCreateContractEntity->execute($contractReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->appointee->unity_hash_id);
|
||||
$order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->update(['entity_hash_id' => $importerContractEntity->hash_id, 'entity_signature' => $importerContractEntity->entity_signature_hash_id]);
|
||||
|
||||
$this->unityAssignContractEntity->execute($supervisorContractEntity->hash_id, $contractObligations);
|
||||
|
||||
$packing_list = $this->fetchesPackingList->execute([
|
||||
'reference' => $warehouse_packing_list->reference,
|
||||
'type' => PackingListType::SHIPPING_PACKING_LIST,
|
||||
'status' => ApprovalStatus::PENDING_VERIFICATION
|
||||
]);
|
||||
|
||||
$warehouse_packing_list = $this->updatesPackingListOwner->execute($packing_list, $order);
|
||||
|
||||
$this->updatesPackingListContractReference->execute($packing_list, $contractReference);
|
||||
|
||||
foreach($contractObligations as $obligation) {
|
||||
$stepObject = new StepsObject($order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, $obligation->reference, $obligation->sequence, $obligation->hash_id);
|
||||
$this->createsStep->execute($packing_list, $stepObject);
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new PackingListResource($warehouse_packing_list));
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanListPackingLists;
|
||||
use App\Http\Resources\PackingListNullOrderResource;
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -49,18 +50,11 @@ class ListPackingListsLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->canListPackingLists->passes();
|
||||
|
||||
$this->canListPackingLists->passes();
|
||||
|
||||
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(PackingListResource::collection($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(PackingListResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class CreatePackageProcessor
|
||||
if($replica) {
|
||||
$modificationValue = 1;
|
||||
$packageObject = new PackageObject($object->getType(), $object->getDescription(), $object->getWidth() + $modificationValue, $object->getHeight() + $modificationValue, $object->getLength() + $modificationValue, $object->getWeight(), $object->getQuantity(), $object->getStatus());
|
||||
$this->createsPackage->execute($packageObject, $replica);
|
||||
$package = $this->createsPackage->execute($packageObject, $replica);
|
||||
}
|
||||
|
||||
return ;
|
||||
|
||||
@@ -48,11 +48,13 @@ class CreatePackingListProcessor
|
||||
/** @var PackingList $packingList */
|
||||
$packingList = $this->createsPackingList->execute($object, $packable);
|
||||
|
||||
$appointee_id = $packingList->owner_id == 1 ? 2037 : $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id;
|
||||
|
||||
$type = $object->getType() === PackingListType::SHIPPING_PACKING_LIST ? PackingListType::SHIPPING_PACKING_LIST_REPLICA : PackingListType::WAREHOUSE_RECEIVE_LIST_REPLICA;
|
||||
/** create packing list replica */
|
||||
$object = new PackingListObject($object->getReference().'_01', $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id, $type, ApprovalStatus::PENDING_SUBMISSION);
|
||||
$object = new PackingListObject($object->getReference().'_01', $appointee_id, $type, ApprovalStatus::PENDING_SUBMISSION);
|
||||
$this->createsPackingList->execute($object, $packingList);
|
||||
|
||||
|
||||
return $packingList;
|
||||
}
|
||||
|
||||
|
||||
+69
-59
@@ -30,8 +30,8 @@ use App\Classes\ValueObjects\Constants\PackageType;
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use App\Classes\ValueObjects\Constants\TransportType;
|
||||
use App\Models\Container;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Transport;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -134,9 +134,7 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
*/
|
||||
public function execute(?Carbon $start = null, ?Carbon $end = null)
|
||||
{
|
||||
|
||||
try {
|
||||
|
||||
$start = $start ? $start : Carbon::now()->subMonths(2);
|
||||
|
||||
$startLimit = Carbon::parse('01-12-2021');
|
||||
@@ -153,6 +151,7 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
]);
|
||||
|
||||
$rows = $this->fetchesDataFRomYDPortal->getResponseBody($orderRequest);
|
||||
|
||||
foreach($rows->data as $row){
|
||||
|
||||
$containerReference = null;
|
||||
@@ -170,7 +169,7 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
$rows = $this->fetchesDataFRomYDPortal->getResponseBody($trackingRequest);
|
||||
|
||||
foreach (array_reverse($rows->data) as $trackingRow) {
|
||||
if($trackingRow->tracking === '货物已送达仓库准备入库中'){
|
||||
if ($trackingRow->tracking === '货物已送达仓库准备入库中') {
|
||||
$receiveDate = Carbon::parse($trackingRow->trackingtime);
|
||||
}
|
||||
|
||||
@@ -182,29 +181,29 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
$eta = Carbon::parse($tracking[2]);
|
||||
}
|
||||
|
||||
if(strpos($trackingRow->tracking, '预计船时间为') !== false){
|
||||
if (strpos($trackingRow->tracking, '预计船时间为') !== false) {
|
||||
$tracking = explode('预计船时间为', $trackingRow->tracking);
|
||||
$delayDate = Carbon::parse(explode('日', $tracking[1])[0]);
|
||||
}
|
||||
|
||||
if(strpos($trackingRow->tracking, '预计开船为') !== false){
|
||||
if (strpos($trackingRow->tracking, '预计开船为') !== false) {
|
||||
$tracking = explode('预计开船为', $trackingRow->tracking);
|
||||
$delayDate = Carbon::parse(explode('日', $tracking[1])[0]);
|
||||
}
|
||||
|
||||
if($trackingRow->tracking === '货物已进目的港仓库'){
|
||||
if ($trackingRow->tracking === '货物已进目的港仓库') {
|
||||
$unstuffingDate = Carbon::parse($trackingRow->trackingtime);
|
||||
}
|
||||
|
||||
if($trackingRow->tracking === '货物已派送完成'){
|
||||
if ($trackingRow->tracking === '货物已派送完成') {
|
||||
$deliveryDate = Carbon::parse($trackingRow->trackingtime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$customerno = preg_split('(-|\(|\)|\/)', $row->customerno);
|
||||
|
||||
$orderNumber = $customerno[array_key_last($customerno)];
|
||||
$allow_contract = true;
|
||||
|
||||
try {
|
||||
$order = $this->fetchesOrder->execute(['reference' => $orderNumber]);
|
||||
@@ -212,8 +211,10 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
try {
|
||||
$order = $this->fetchesOrder->execute(['reference' => substr($orderNumber, -9)]);
|
||||
} catch (ResourceNotFoundException $exception) {
|
||||
continue;
|
||||
$order = $this->fetchesCompanyModule->execute(['id' => 1]);
|
||||
$allow_contract = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
@@ -232,40 +233,52 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
$replica = $warehouseReceiveList->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST_REPLICA)->first();
|
||||
if($replica) $replica->packages()->delete();
|
||||
|
||||
} catch (ResourceNotFoundException $exception){
|
||||
$warehouseReceiveObject = new PackingListObject($packingListReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id, PackingListType::WAREHOUSE_RECEIVE_LIST, ApprovalStatus::APPROVED);
|
||||
} catch (ResourceNotFoundException $exception) {
|
||||
|
||||
if (!$allow_contract) {
|
||||
$appointee_id = 2037;
|
||||
} else {
|
||||
$appointee_id = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id;
|
||||
}
|
||||
|
||||
$warehouseReceiveObject = new PackingListObject($packingListReference, $appointee_id, PackingListType::WAREHOUSE_RECEIVE_LIST, $allow_contract ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED);
|
||||
|
||||
/** @var PackingList $warehouseReceiveList */
|
||||
$warehouseReceiveList = $this->createPackingListProcessor->execute($warehouseReceiveObject, $order);
|
||||
$transportObject = new TransportObject(TransportType::LAND, null, $row->kuaidilist, Carbon::parse($receiveDate), Carbon::parse($receiveDate), ApprovalStatus::APPROVED);
|
||||
/** @var Transport $warehouseTransport */
|
||||
$warehouseTransport = $this->createsTransport->execute($transportObject, $warehouseReceiveList);
|
||||
$this->createsSchedule->execute($warehouseTransport, new ScheduleObject(Carbon::parse($receiveDate), Carbon::parse($receiveDate), ApprovalStatus::APPROVED));
|
||||
|
||||
$contract = $this->unityCreateContract->execute();
|
||||
$transportObject = new TransportObject(TransportType::LAND, null, $row->kuaidilist, Carbon::parse($receiveDate), Carbon::parse($receiveDate), $allow_contract ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED);
|
||||
$transport = $this->createsTransport->execute($transportObject, $warehouseReceiveList);
|
||||
|
||||
$contractReference = $contract->hash_id;
|
||||
$contractObligations = $contract->contract_obligation_list;
|
||||
if ($allow_contract) {
|
||||
|
||||
$this->unityActivateContract->execute($contractReference);
|
||||
$contract = $this->unityCreateContract->execute();
|
||||
|
||||
$supervisorHashId = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->unity_hash_id;
|
||||
$contractReference = $contract->hash_id;
|
||||
$contractObligations = $contract->contract_obligation_list;
|
||||
|
||||
$supervisorContractEntity = $this->unityCreateContractEntity->execute($contractReference, $supervisorHashId);
|
||||
$order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->update(['entity_hash_id' => $supervisorContractEntity->hash_id, 'entity_signature' => $supervisorContractEntity->entity_signature_hash_id]);
|
||||
$this->unityActivateContract->execute($contractReference);
|
||||
|
||||
$importerContractEntity = $this->unityCreateContractEntity->execute($contractReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->appointee->unity_hash_id);
|
||||
$order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->update(['entity_hash_id' => $importerContractEntity->hash_id, 'entity_signature' => $importerContractEntity->entity_signature_hash_id]);
|
||||
$supervisorHashId = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->unity_hash_id;
|
||||
|
||||
$this->unityAssignContractEntity->execute($supervisorContractEntity->hash_id, $contractObligations);
|
||||
$supervisorContractEntity = $this->unityCreateContractEntity->execute($contractReference, $supervisorHashId);
|
||||
$order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->update(['entity_hash_id' => $supervisorContractEntity->hash_id, 'entity_signature' => $supervisorContractEntity->entity_signature_hash_id]);
|
||||
|
||||
$packingListObject = new PackingListObject($packingListReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_FREIGHT_FORWARDER)->first()->appointee->id, PackingListType::SHIPPING_PACKING_LIST, ApprovalStatus::SUSPENDED , $contractReference);
|
||||
$importerContractEntity = $this->unityCreateContractEntity->execute($contractReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->appointee->unity_hash_id);
|
||||
$order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->update(['entity_hash_id' => $importerContractEntity->hash_id, 'entity_signature' => $importerContractEntity->entity_signature_hash_id]);
|
||||
|
||||
$this->unityAssignContractEntity->execute($supervisorContractEntity->hash_id, $contractObligations);
|
||||
}
|
||||
|
||||
$packingListObject = new PackingListObject($packingListReference, $appointee_id, PackingListType::SHIPPING_PACKING_LIST, ApprovalStatus::PENDING_VERIFICATION, !$allow_contract ? null : $contractReference);
|
||||
|
||||
/** @var PackingList $packingList */
|
||||
$packingList = $this->createPackingListProcessor->execute($packingListObject, $order);
|
||||
|
||||
foreach($contractObligations as $obligation) {
|
||||
$stepObject = new StepsObject($order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, $obligation->reference, $obligation->sequence, $obligation->hash_id);
|
||||
$this->createsStep->execute($packingList, $stepObject);
|
||||
if ($allow_contract) {
|
||||
foreach ($contractObligations as $obligation) {
|
||||
$stepObject = new StepsObject($order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, $obligation->reference, $obligation->sequence, $obligation->hash_id);
|
||||
$this->createsStep->execute($packingList, $stepObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,50 +297,46 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
$this->createPackageProcessor->execute($packageObject, $packingList);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
$marking = $order->companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
|
||||
if(!in_array($marking, ['2192KAA', '2353GFE', '6866DTR', '153DSR', '1291NSC', '8288MIB'])){
|
||||
$this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/confirmsendorder.ashx', 'GET', [
|
||||
'expressno' => $row->expressno
|
||||
]);
|
||||
if($order instanceof Order){
|
||||
$marking = $order->companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
|
||||
if(!in_array($marking, ['2192KAA', '2353GFE', '6866DTR', '153DSR', '1291NSC', '8288MIB'])){
|
||||
$this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/confirmsendorder.ashx', 'GET', [
|
||||
'expressno' => $row->expressno
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($containerReference) {
|
||||
try {
|
||||
$container = $this->fetchesContainer->execute(['reference' => $containerReference]);
|
||||
} catch (ResourceNotFoundException $exception){
|
||||
$originWarehouse = $this->fetchesCompanyModule->execute(['id' => $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->id]);
|
||||
|
||||
if (!$allow_contract) {
|
||||
$appointee_id = 2037;
|
||||
}
|
||||
else {
|
||||
$appointee_id = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->id;
|
||||
}
|
||||
|
||||
$originWarehouse = $this->fetchesCompanyModule->execute(['id' => $appointee_id]);
|
||||
|
||||
$containerObject = new ContainerObject($containerReference, '', '', ContainerTypes::FORTY_FEET_DRY_CONTAINER, $loadingDate, ApprovalStatus::PENDING_VERIFICATION);
|
||||
/** @var Container $container */
|
||||
$container = $this->createContainerProcessor->execute($containerObject, $originWarehouse);
|
||||
}
|
||||
|
||||
$container->packingLists()->detach($packingList);
|
||||
$container->packingLists()->attach($packingList);
|
||||
|
||||
$transport = $container->transports()->first();
|
||||
|
||||
if(!$transport){
|
||||
$transportObject = new TransportObject(TransportType::SEA, null, null, $etd, null, ApprovalStatus::APPROVED);
|
||||
/** @var Transport $transport */
|
||||
$transport = $this->createsTransport->execute($transportObject, $container);
|
||||
$this->createsSchedule->execute($transport, new ScheduleObject($etd, $eta, ApprovalStatus::APPROVED));
|
||||
}
|
||||
|
||||
if($delayDate){
|
||||
$container->packingLists()->attach($packingList);
|
||||
|
||||
$transport = $container->transports()->first();
|
||||
|
||||
if(!$transport->schedules()->where('eta', '=', $delayDate)->first()) {
|
||||
$etd = $transport->schedules()->where('status', '=', ApprovalStatus::APPROVED)->first()->etd;
|
||||
$transport->schedules()->update(['status' => ApprovalStatus::EXPIRED]);
|
||||
$this->createsSchedule->execute($transport, new ScheduleObject($etd, $delayDate, ApprovalStatus::APPROVED));
|
||||
if(!$transport){
|
||||
$transportObject = new TransportObject(TransportType::SEA, null, null, $etd, null, ApprovalStatus::APPROVED);
|
||||
/** @var Transport $transport */
|
||||
$transport = $this->createsTransport->execute($transportObject, $container);
|
||||
$this->createsSchedule->execute($transport, new ScheduleObject($etd, $eta, ApprovalStatus::APPROVED));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if($unstuffingDate && $container->status !== ApprovalStatus::COMPLETED){
|
||||
$container->update(['status' => ApprovalStatus::COMPLETED]);
|
||||
$container->transports()->first()->update(['drop_date' => $unstuffingDate, 'status' => ApprovalStatus::COMPLETED]);
|
||||
@@ -347,7 +356,6 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($deliveryDate){
|
||||
@@ -371,6 +379,8 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
$deliveryStep->update(['status' => ApprovalStatus::COMPLETED]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
Log::debug($exception);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\General\Interfaces\Packable;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Models\PackingList;
|
||||
|
||||
class CreatesNullOrderPackingList extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param PackingListObject $object
|
||||
* @param Packable $packable
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(PackingListObject $object) {
|
||||
$model = new PackingList();
|
||||
|
||||
$model->reference = $object->getReference();
|
||||
$model->claimant_id = $object->getClaimantId();
|
||||
$model->type = $object->getType();
|
||||
$model->status = $object->getStatus();
|
||||
$model->reference_contract = $object->getContractReference();
|
||||
$model->owner_type = 'App\Models\Order';
|
||||
$model->owner_id = 1;
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\PackingList;
|
||||
|
||||
class UpdatesPackingListContractReference extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param PackingList $model
|
||||
* @param int $status
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(PackingList $model, string $reference_contract) {
|
||||
|
||||
$model->reference_contract = $reference_contract;
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Services;
|
||||
|
||||
use App\Classes\General\Interfaces\Packable;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Models\PackingList;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
|
||||
class UpdatesPackingListOwner extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param PackingList $model
|
||||
* @param int $status
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(PackingList $model, Packable $packable) {
|
||||
|
||||
$model->status = ApprovalStatus::APPROVED;
|
||||
|
||||
return $this->handler($packable->packingLists(), $model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\SegmentConstants\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\SegmentConstant;
|
||||
|
||||
class FetchesSegmentConstant extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var SegmentConstant */
|
||||
private $repository;
|
||||
|
||||
|
||||
/**
|
||||
* FetchesSegment constructor.
|
||||
* @param SegmentConstant $repository
|
||||
*/
|
||||
public function __construct(SegmentConstant $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ class CreateSegmentLogic extends AbstractControllerLogic
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var CreateSegmentProcessor */
|
||||
private $createSegmentProcessor;
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ class DeleteSegmentLogic extends AbstractControllerLogic
|
||||
$this->fetchesSegment = $fetchesSegment;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Segments\Services\FetchesConstant;
|
||||
use App\Http\Resources\ConstantResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchConstantLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Fetch Segment Constant',
|
||||
'message' => 'You have successfully retrieved the Segment Constant'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var FetchesConstant */
|
||||
private $fetchesConstant;
|
||||
|
||||
/**
|
||||
* FetchConstantLogic constructor.
|
||||
* @param FetchesConstant $fetchesConstant
|
||||
*/
|
||||
public function __construct(FetchesConstant $fetchesConstant)
|
||||
{
|
||||
$this->fetchesConstant = $fetchesConstant;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$constant = $this->fetchesConstant->execute(['segment_id' => $request->route('id'), 'reference' => $request->route('reference')]);
|
||||
|
||||
return $this->resourceResponse(new ConstantResource($constant));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Segments\Standards\Rules\CanFetchSegment;
|
||||
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
||||
use App\Http\Resources\SegmentResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchSegmentLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Segment',
|
||||
'message' => 'You have successfully retrieved a segment'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchSegment */
|
||||
private $canFetchSegment;
|
||||
|
||||
/** @var FetchesSegment */
|
||||
private $fetchesSegment;
|
||||
|
||||
/**
|
||||
* FetchSegmentLogic constructor.
|
||||
* @param CanFetchSegment $canFetchSegment
|
||||
* @param FetchesSegment $fetchesSegment
|
||||
*/
|
||||
public function __construct(CanFetchSegment $canFetchSegment, FetchesSegment $fetchesSegment)
|
||||
{
|
||||
$this->canFetchSegment = $canFetchSegment;
|
||||
$this->fetchesSegment = $fetchesSegment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canFetchSegment->passes();
|
||||
|
||||
$query = $this->fetchesSegment->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new SegmentResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Segments\Services\ListsSegments;
|
||||
use App\Http\Resources\SegmentResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListSegmentLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Segment',
|
||||
'message' => 'You have successfully retrieved a list of Segment'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var ListsSegments */
|
||||
private $listsSegments;
|
||||
|
||||
/**
|
||||
* ListSegmentLogic constructor.
|
||||
* @param ListsSegments $listsSegments
|
||||
*/
|
||||
public function __construct(ListsSegments $listsSegments)
|
||||
{
|
||||
$this->listsSegments = $listsSegments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$query = $this->listsSegments->execute($this->listsSegments->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(SegmentResource::collection($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
|
||||
use App\Classes\Modules\Segments\Services\CreatesConstant;
|
||||
use App\Classes\Modules\Segments\Services\FetchesConstant;
|
||||
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
||||
use App\Classes\Modules\Segments\Standards\Rules\CanCreateConstant;
|
||||
use App\Classes\Modules\Segments\Standards\Rules\CanUpdateConstant;
|
||||
use App\Classes\Modules\Segments\Services\UpdatesConstant;
|
||||
use App\Http\Resources\ConstantResource;
|
||||
use App\Models\SegmentConstant;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateConstantLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated Segment Constant',
|
||||
'message' => 'You have successfully updated the Segment Constant'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdateConstant */
|
||||
private $canUpdateConstant;
|
||||
|
||||
/** @var UpdatesConstant */
|
||||
private $updatesConstant;
|
||||
|
||||
/** @var FetchesSegment */
|
||||
private $fetchesSegment;
|
||||
|
||||
/** @var FetchesConstant */
|
||||
private $fetchesConstant;
|
||||
|
||||
/** @var CanCreateConstant */
|
||||
private $canCreateConstant;
|
||||
|
||||
/** @var CreatesConstant */
|
||||
private $createsConstant;
|
||||
|
||||
|
||||
/**
|
||||
* UpdateConstantLogic constructor.
|
||||
* @param CanUpdateConstant $canUpdateConstant
|
||||
* @param UpdatesConstant $updatesConstant
|
||||
* @param FetchesSegment $fetchesSegment
|
||||
* @param FetchesConstant $fetchesConstant
|
||||
* @param CanCreateConstant $canCreateConstant
|
||||
* @param CreatesConstant $createsConstant
|
||||
*/
|
||||
public function __construct(CanUpdateConstant $canUpdateConstant, UpdatesConstant $updatesConstant, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant, CanCreateConstant $canCreateConstant, CreatesConstant $createsConstant)
|
||||
{
|
||||
$this->canUpdateConstant = $canUpdateConstant;
|
||||
$this->updatesConstant = $updatesConstant;
|
||||
$this->fetchesSegment = $fetchesSegment;
|
||||
$this->fetchesConstant = $fetchesConstant;
|
||||
$this->canCreateConstant = $canCreateConstant;
|
||||
$this->createsConstant = $createsConstant;
|
||||
}
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$object = new ConstantObject($request->input('name'), $request->input('reference'), $request->input('detail'));
|
||||
|
||||
$segment = $this->fetchesSegment->execute(['id' => $request->route('id')]);
|
||||
|
||||
try {
|
||||
|
||||
$constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'reference' => $object->getReference()]);
|
||||
$this->canUpdateConstant->passes($object);
|
||||
|
||||
/** @var SegmentConstant $constant */
|
||||
$constant = $this->updatesConstant->execute($constant, $object);
|
||||
|
||||
} catch (ResourceNotFoundException $exception){
|
||||
|
||||
$this->canCreateConstant->passes($object);
|
||||
|
||||
/** @var SegmentConstant $constant */
|
||||
$constant = $this->createsConstant->execute($segment, $object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $this->resourceResponse(new ConstantResource($constant));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\SegmentResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
||||
|
||||
use App\Classes\Modules\Segments\Standards\Rules\CanUpdateSegment;
|
||||
use App\Classes\Modules\Segments\Services\UpdatesSegment;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateSegmentLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated Segment',
|
||||
'message' => 'You have successfully updated the Segment'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdateSegment */
|
||||
private $canUpdateSegment;
|
||||
|
||||
/** @var UpdatesSegment */
|
||||
private $updatesSegment;
|
||||
|
||||
/** @var FetchesSegment */
|
||||
private $fetchesSegment;
|
||||
|
||||
|
||||
/**
|
||||
* UpdateSegmentLogic constructor.
|
||||
* @param CanUpdateSegment $canUpdateSegment
|
||||
* @param UpdatesSegment $updatesSegment
|
||||
* @param FetchesSegment $fetchesSegment
|
||||
*/
|
||||
public function __construct(
|
||||
CanUpdateSegment $canUpdateSegment,
|
||||
UpdatesSegment $updatesSegment,
|
||||
FetchesSegment $fetchesSegment
|
||||
)
|
||||
{
|
||||
$this->canUpdateSegment = $canUpdateSegment;
|
||||
$this->updatesSegment = $updatesSegment;
|
||||
$this->fetchesSegment = $fetchesSegment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$segment_query = $this->fetchesSegment->execute(['id' => $request->route('id')]);
|
||||
|
||||
$segment_object = new SegmentObject(
|
||||
$request->input('name', $segment_query->name)
|
||||
);
|
||||
$this->canUpdateSegment->passes($segment_object);
|
||||
$segment_query = $this->updatesSegment->execute($segment_query, $segment_object);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $this->resourceResponse(new SegmentResource($segment_query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Services;
|
||||
|
||||
|
||||
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Http\Resources\ConstantResource;
|
||||
use App\Http\Resources\CurrencyResource;
|
||||
use App\Models\SegmentConstant;
|
||||
|
||||
class ConvertsConstantDetailsToResource
|
||||
{
|
||||
|
||||
/** @var FetchesCurrency */
|
||||
private $fetchesCurrency;
|
||||
|
||||
/**
|
||||
* ConvertsConstantDetailsToResource constructor.
|
||||
* @param FetchesCurrency $fetchesCurrency
|
||||
*/
|
||||
public function __construct(FetchesCurrency $fetchesCurrency)
|
||||
{
|
||||
$this->fetchesCurrency = $fetchesCurrency;
|
||||
}
|
||||
|
||||
|
||||
public function execute(SegmentConstant $constant){
|
||||
|
||||
if($constant->reference === SegmentConstants::SUPPLIER_CURRENCIES) {
|
||||
return property_exists($constant->detail, 'id') ? new CurrencyResource($this->fetchesCurrency->execute(['id' => $constant->detail->id])) : '';
|
||||
}
|
||||
|
||||
return $constant->detail;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,6 @@ use App\Models\Segment;
|
||||
|
||||
class CreatesSegment extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\SegmentConstant;
|
||||
|
||||
class FetchesConstant extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var SegmentConstant */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesConstant constructor.
|
||||
* @param SegmentConstant $repository
|
||||
*/
|
||||
public function __construct(SegmentConstant $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\SegmentConstant;
|
||||
|
||||
class ListsConstants extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var SegmentConstant */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsConstants constructor.
|
||||
* @param SegmentConstant $repository
|
||||
*/
|
||||
public function __construct(SegmentConstant $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Segment;
|
||||
|
||||
class ListsSegments extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var Segment */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsSegments constructor.
|
||||
* @param Segment $repository
|
||||
*/
|
||||
public function __construct(Segment $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
|
||||
use App\Models\SegmentConstant;
|
||||
|
||||
class UpdatesConstant extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param SegmentConstant $model
|
||||
* @param ConstantObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(SegmentConstant $model, ConstantObject $object)
|
||||
{
|
||||
$model->name = $object->getName();
|
||||
$model->reference = $object->getReference();
|
||||
$model->detail = json_encode($object->getDetail());
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
use App\Models\Segment;
|
||||
|
||||
class UpdatesSegment extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Segment $model
|
||||
* @param SegmentObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Segment $model, SegmentObject $object)
|
||||
{
|
||||
$model->name = $object->getName();
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
|
||||
use App\Classes\Modules\Segments\Standards\Validators\ConstantValidation;
|
||||
|
||||
class CanCreateConstant extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var ConstantValidation */
|
||||
private $constantValidation;
|
||||
|
||||
/**
|
||||
* CanCreateConstant constructor.
|
||||
* @param ConstantValidation $constantValidation
|
||||
*/
|
||||
public function __construct(ConstantValidation $constantValidation)
|
||||
{
|
||||
$this->constantValidation = $constantValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConstantObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->constantValidation->validate($object, 'POST');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConstantObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
|
||||
class CanFetchSegment extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
|
||||
class CanListSegments extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
|
||||
use App\Classes\Modules\Segments\Standards\Validators\ConstantValidation;
|
||||
|
||||
class CanUpdateConstant extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var ConstantValidation */
|
||||
private $ConstantValidation;
|
||||
|
||||
/**
|
||||
* CanUpdateConstant constructor.
|
||||
* @param ConstantValidation $ConstantValidation
|
||||
*/
|
||||
public function __construct(ConstantValidation $ConstantValidation)
|
||||
{
|
||||
$this->ConstantValidation = $ConstantValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConstantObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->ConstantValidation->validate($object, 'PUT');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConstantObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
use App\Classes\Modules\Segments\Standards\Validators\SegmentValidation;
|
||||
|
||||
class CanUpdateSegment extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var SegmentValidation */
|
||||
private $segmentValidation;
|
||||
|
||||
|
||||
/**
|
||||
* CanUpdateSegment constructor.
|
||||
* @param SegmentValidation $segmentValidation
|
||||
*/
|
||||
public function __construct(SegmentValidation $segmentValidation)
|
||||
{
|
||||
$this->segmentValidation = $segmentValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
if (!\Auth::user()->can('edit segment')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->segmentValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Standards\Validators;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
|
||||
|
||||
class ConstantValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param ConstantObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array {
|
||||
|
||||
$data = [
|
||||
'name' => $object->getName(),
|
||||
'reference' => $object->getReference(),
|
||||
'detail' => $object->getDetail()
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'name' => 'required',
|
||||
'reference' => 'required',
|
||||
'detail' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
|
||||
use App\Classes\Modules\Segments\Services\CreatesConstant;
|
||||
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceDetailObject;
|
||||
use App\Classes\Modules\ServiceTypes\Services\CreatesServiceType;
|
||||
use App\Classes\Modules\ServiceTypes\Services\CreatesServiceTypeConstantDetails;
|
||||
use App\Classes\Modules\ServiceTypes\Services\UpdatesServiceCurrencyRates;
|
||||
use App\Classes\Modules\ServiceTypes\Standards\Rules\CanCreateServiceType;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Http\Resources\ServiceTypeResource;
|
||||
use App\Models\ServiceType;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateServiceTypeLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Created Service Type',
|
||||
'message' => 'You have successfully created a new Service Type'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanCreateServiceType */
|
||||
private $canCreateServiceType;
|
||||
|
||||
/** @var CreatesServiceType */
|
||||
private $createsServiceType;
|
||||
|
||||
/** @var CreatesServiceTypeConstantDetails */
|
||||
private $createsServiceTypeConstantDetails;
|
||||
|
||||
/** @var UpdatesServiceCurrencyRates */
|
||||
private $updatesServiceCurrencyRates;
|
||||
|
||||
/** @var FetchesSegment */
|
||||
private $fetchesSegment;
|
||||
|
||||
/** @var CreatesConstant */
|
||||
private $createsConstant;
|
||||
|
||||
|
||||
/**
|
||||
* CreateServiceTypeLogic constructor.
|
||||
* @param CanCreateServiceType $canCreateServiceType
|
||||
* @param CreatesServiceType $createsServiceType
|
||||
* @param CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails
|
||||
* @param UpdatesServiceCurrencyRates $updatesServiceCurrencyRates
|
||||
* @param FetchesSegment $fetchesSegment
|
||||
* @param CreatesConstant $createsConstant
|
||||
*/
|
||||
public function __construct(CanCreateServiceType $canCreateServiceType, CreatesServiceType $createsServiceType, CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails, UpdatesServiceCurrencyRates $updatesServiceCurrencyRates, FetchesSegment $fetchesSegment, CreatesConstant $createsConstant)
|
||||
{
|
||||
$this->canCreateServiceType = $canCreateServiceType;
|
||||
$this->createsServiceType = $createsServiceType;
|
||||
$this->createsServiceTypeConstantDetails = $createsServiceTypeConstantDetails;
|
||||
$this->updatesServiceCurrencyRates = $updatesServiceCurrencyRates;
|
||||
$this->fetchesSegment = $fetchesSegment;
|
||||
$this->createsConstant = $createsConstant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$object = new ServiceTypeObject($request->input('name'));
|
||||
|
||||
$this->canCreateServiceType->passes($object);
|
||||
|
||||
/** @var ServiceType $service */
|
||||
$service = $this->createsServiceType->execute($object);
|
||||
|
||||
$object = new ServiceDetailObject($service->id, (int) $request->input('configurations.bank_id'),
|
||||
$request->input('configurations.service_charge'), $request->input('configurations.minimum_charge'), $request->input('configurations.tax'),
|
||||
$request->input('configurations.po_limit'), $request->input('configurations.currencies'), false, $request->input('configurations.billable'));
|
||||
|
||||
$this->updatesServiceCurrencyRates->execute($service, $object->getCurrencies());
|
||||
|
||||
$constantObject = new ConstantObject('Service Type', SegmentConstants::SERVICE_TYPE, $this->createsServiceTypeConstantDetails->execute($object));
|
||||
|
||||
$this->createsConstant->execute($this->fetchesSegment->execute(['type' => SegmentConstants::STANDARD_SEGMENT]), $constantObject);
|
||||
|
||||
|
||||
return $this->resourceResponse(new ServiceTypeResource($service));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\ServiceTypes\Services\DeletesServiceType;
|
||||
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceType;
|
||||
use App\Classes\Modules\ServiceTypes\Standards\Rules\CanDeleteServiceType;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteServiceTypeLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Deleted Service Type',
|
||||
'message' => 'You have successfully deleted a Service Type'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var CanDeleteServiceType */
|
||||
private $canDeleteServiceType;
|
||||
|
||||
/** @var DeletesServiceType */
|
||||
private $deletesServiceType;
|
||||
|
||||
/** @var FetchesServiceType */
|
||||
private $fetchesServiceType;
|
||||
|
||||
/**
|
||||
* DeleteServiceTypeLogic constructor.
|
||||
* @param CanDeleteServiceType $canDeleteServiceType
|
||||
* @param DeletesServiceType $deletesServiceType
|
||||
* @param FetchesServiceType $fetchesServiceType
|
||||
*/
|
||||
public function __construct(CanDeleteServiceType $canDeleteServiceType, DeletesServiceType $deletesServiceType, FetchesServiceType $fetchesServiceType)
|
||||
{
|
||||
$this->canDeleteServiceType = $canDeleteServiceType;
|
||||
$this->deletesServiceType = $deletesServiceType;
|
||||
$this->fetchesServiceType = $fetchesServiceType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$this->canDeleteServiceType->passes();
|
||||
|
||||
$query = $this->fetchesServiceType->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->deletesServiceType->execute($query);
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceType;
|
||||
use App\Classes\Modules\ServiceTypes\Standards\Rules\CanFetchServiceType;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
use App\Http\Resources\ServiceTypeResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchServiceTypeLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Service Type',
|
||||
'message' => 'You have successfully retrieved a Service Type'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchServiceType */
|
||||
private $canFetchServiceType;
|
||||
|
||||
/** @var FetchesServiceType */
|
||||
private $fetchesServiceType;
|
||||
|
||||
/**
|
||||
* FetchServiceTypeLogic constructor.
|
||||
* @param CanFetchServiceType $canFetchServiceType
|
||||
* @param FetchesServiceType $fetchesServiceType
|
||||
*/
|
||||
public function __construct(CanFetchServiceType $canFetchServiceType, FetchesServiceType $fetchesServiceType)
|
||||
{
|
||||
$this->canFetchServiceType = $canFetchServiceType;
|
||||
$this->fetchesServiceType = $fetchesServiceType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canFetchServiceType->passes();
|
||||
|
||||
$query = $this->fetchesServiceType->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new ServiceTypeResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\ServiceTypes\Services\ListsServiceTypes;
|
||||
use App\Classes\Modules\ServiceTypes\Standards\Rules\CanListServiceTypes;
|
||||
use App\Http\Resources\ServiceTypeResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListServiceTypesLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Service Types',
|
||||
'message' => 'You have successfully retrieved a list of Service Types'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListServiceTypes */
|
||||
private $canListServiceTypes;
|
||||
|
||||
/** @var ListsServiceTypes */
|
||||
private $listsServiceTypes;
|
||||
|
||||
/**
|
||||
* ListServiceTypesControllerLogic constructor.
|
||||
* @param CanListServiceTypes $canListServiceTypes
|
||||
* @param ListsServiceTypes $listsServiceTypes
|
||||
*/
|
||||
public function __construct(CanListServiceTypes $canListServiceTypes, ListsServiceTypes $listsServiceTypes)
|
||||
{
|
||||
$this->canListServiceTypes = $canListServiceTypes;
|
||||
$this->listsServiceTypes = $listsServiceTypes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canListServiceTypes->passes();
|
||||
|
||||
$query = $this->listsServiceTypes->execute($this->listsServiceTypes->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(ServiceTypeResource::collection($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
|
||||
use App\Classes\Modules\Segments\Services\CreatesConstant;
|
||||
use App\Classes\Modules\Segments\Services\FetchesConstant;
|
||||
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
||||
use App\Classes\Modules\Segments\Services\UpdatesConstant;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceDetailObject;
|
||||
use App\Classes\Modules\ServiceTypes\Services\CreatesServiceTypeConstantDetails;
|
||||
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceType;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Http\Resources\CustomServiceTypeResource;
|
||||
use App\Models\Segment;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateCustomServiceConstantLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Update Segment Service',
|
||||
'message' => 'You have successfully update a segments service configuration'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesServiceType */
|
||||
private $fetchesServiceType;
|
||||
|
||||
/** @var CreatesServiceTypeConstantDetails */
|
||||
private $createsServiceTypeConstantDetails;
|
||||
|
||||
/** @var FetchesSegment */
|
||||
private $fetchesSegment;
|
||||
|
||||
/** @var FetchesConstant */
|
||||
private $fetchesConstant;
|
||||
|
||||
/** @var UpdatesConstant */
|
||||
private $updatesConstant;
|
||||
|
||||
/** @var CreatesConstant */
|
||||
private $createsConstant;
|
||||
|
||||
/**
|
||||
* UpdateCustomServiceConstantLogic constructor.
|
||||
* @param FetchesServiceType $fetchesServiceType
|
||||
* @param CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails
|
||||
* @param FetchesSegment $fetchesSegment
|
||||
* @param FetchesConstant $fetchesConstant
|
||||
* @param UpdatesConstant $updatesConstant
|
||||
* @param CreatesConstant $createsConstant
|
||||
*/
|
||||
public function __construct(FetchesServiceType $fetchesServiceType, CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant, UpdatesConstant $updatesConstant, CreatesConstant $createsConstant)
|
||||
{
|
||||
$this->fetchesServiceType = $fetchesServiceType;
|
||||
$this->createsServiceTypeConstantDetails = $createsServiceTypeConstantDetails;
|
||||
$this->fetchesSegment = $fetchesSegment;
|
||||
$this->fetchesConstant = $fetchesConstant;
|
||||
$this->updatesConstant = $updatesConstant;
|
||||
$this->createsConstant = $createsConstant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$service = $this->fetchesServiceType->execute(['id' => $request->input('id')]);
|
||||
|
||||
$customFields = $request->input('custom_fields');
|
||||
|
||||
$object = new ServiceDetailObject($service->id, $customFields['bank_id'], $customFields['service_charge'],
|
||||
$customFields['minimum_charge'], $customFields['tax'], $customFields['po_limit'], $request->input('configurations.currencies'),
|
||||
$request->input('configurations.active'), true);
|
||||
|
||||
$constantObject = new ConstantObject('Custom Service Type', SegmentConstants::CUSTOM_SERVICE_TYPE, $this->createsServiceTypeConstantDetails->execute($object, true));
|
||||
|
||||
/** @var Segment $segment */
|
||||
$segment = $this->fetchesSegment->execute(['id' => $request->route('id')]);
|
||||
|
||||
try {
|
||||
|
||||
$constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'custom_service_type' => $object->getId()]);
|
||||
|
||||
$this->updatesConstant->execute($constant, $constantObject);
|
||||
|
||||
} catch (ResourceNotFoundException $exception){
|
||||
|
||||
$constant = $this->createsConstant->execute($segment, $constantObject);
|
||||
}
|
||||
|
||||
|
||||
return $this->resourceResponse(new CustomServiceTypeResource($constant));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
|
||||
use App\Classes\Modules\Segments\Services\FetchesConstant;
|
||||
use App\Classes\Modules\Segments\Services\UpdatesConstant;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceDetailObject;
|
||||
use App\Classes\Modules\ServiceTypes\Services\CreatesServiceTypeConstantDetails;
|
||||
use App\Classes\Modules\ServiceTypes\Services\UpdatesServiceCurrencyRates;
|
||||
use App\Classes\Modules\ServiceTypes\Services\UpdatesServiceType;
|
||||
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceType;
|
||||
use App\Classes\Modules\ServiceTypes\Standards\Rules\CanUpdateServiceType;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Http\Resources\ServiceTypeResource;
|
||||
use App\Models\ServiceType;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateServiceTypeLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated Service Type',
|
||||
'message' => 'You have successfully updated the Service Type'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdateServiceType */
|
||||
private $canUpdateServiceType;
|
||||
|
||||
/** @var UpdatesServiceType */
|
||||
private $updatesServiceType;
|
||||
|
||||
/** @var FetchesServiceType */
|
||||
private $fetchesServiceType;
|
||||
|
||||
/** @var CreatesServiceTypeConstantDetails */
|
||||
private $createsServiceTypeConstantDetails;
|
||||
|
||||
/** @var UpdatesServiceCurrencyRates */
|
||||
private $updatesServiceCurrencyRates;
|
||||
|
||||
/** @var UpdatesConstant */
|
||||
private $updatesConstant;
|
||||
|
||||
/** @var FetchesConstant */
|
||||
private $fetchesConstant;
|
||||
|
||||
|
||||
/**
|
||||
* UpdateServiceTypeLogic constructor.
|
||||
* @param CanUpdateServiceType $canUpdateServiceType
|
||||
* @param UpdatesServiceType $updatesServiceType
|
||||
* @param FetchesServiceType $fetchesServiceType
|
||||
* @param CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails
|
||||
* @param UpdatesServiceCurrencyRates $updatesServiceCurrencyRates
|
||||
* @param UpdatesConstant $updatesConstant
|
||||
* @param FetchesConstant $fetchesConstant
|
||||
*/
|
||||
public function __construct(CanUpdateServiceType $canUpdateServiceType, UpdatesServiceType $updatesServiceType, FetchesServiceType $fetchesServiceType, CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails, UpdatesServiceCurrencyRates $updatesServiceCurrencyRates, UpdatesConstant $updatesConstant, FetchesConstant $fetchesConstant)
|
||||
{
|
||||
$this->canUpdateServiceType = $canUpdateServiceType;
|
||||
$this->updatesServiceType = $updatesServiceType;
|
||||
$this->fetchesServiceType = $fetchesServiceType;
|
||||
$this->createsServiceTypeConstantDetails = $createsServiceTypeConstantDetails;
|
||||
$this->updatesServiceCurrencyRates = $updatesServiceCurrencyRates;
|
||||
$this->updatesConstant = $updatesConstant;
|
||||
$this->fetchesConstant = $fetchesConstant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$object = new ServiceTypeObject($request->input('name'));
|
||||
|
||||
$this->canUpdateServiceType->passes($object);
|
||||
|
||||
$service = $this->fetchesServiceType->execute(['id' => $request->route('id')]);
|
||||
|
||||
/** @var ServiceType $service */
|
||||
$service = $this->updatesServiceType->execute($service, $object);
|
||||
|
||||
$object = new ServiceDetailObject($service->id, (int) $request->input('configurations.bank_id'),
|
||||
$request->input('configurations.service_charge'), $request->input('configurations.minimum_charge'), $request->input('configurations.tax'),
|
||||
$request->input('configurations.po_limit'), $request->input('configurations.currencies'), $request->input('configurations.active'), $request->input('configurations.billable'));
|
||||
|
||||
$this->updatesServiceCurrencyRates->execute($service, $object->getCurrencies());
|
||||
|
||||
$constantObject = new ConstantObject('Service Type', SegmentConstants::SERVICE_TYPE, $this->createsServiceTypeConstantDetails->execute($object));
|
||||
|
||||
$this->updatesConstant->execute($this->fetchesConstant->execute(['service_type' => $service->id]), $constantObject);
|
||||
|
||||
return $this->resourceResponse(new ServiceTypeResource($service));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceType;
|
||||
use App\Classes\Modules\ServiceTypes\Services\UpdatesServiceTypeStatus;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateServiceTypeStatusLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Update Service Type',
|
||||
'message' => 'You have successfully updated a Service Type status'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesServiceType */
|
||||
private $fetchesServiceType;
|
||||
|
||||
/** @var UpdatesServiceTypeStatus */
|
||||
private $updatesServiceTypeStatus;
|
||||
|
||||
/**
|
||||
* UpdateServiceTypeStatusLogic constructor.
|
||||
* @param FetchesServiceType $fetchesServiceType
|
||||
* @param UpdatesServiceTypeStatus $updatesServiceTypeStatus
|
||||
*/
|
||||
public function __construct(FetchesServiceType $fetchesServiceType, UpdatesServiceTypeStatus $updatesServiceTypeStatus)
|
||||
{
|
||||
$this->fetchesServiceType = $fetchesServiceType;
|
||||
$this->updatesServiceTypeStatus = $updatesServiceTypeStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
|
||||
$query = $this->fetchesServiceType->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->updatesServiceTypeStatus->execute($query, $request->route('status') === 'active' ? ApprovalStatus::APPROVED : ApprovalStatus::SUSPENDED);
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\DataTransferObjects;
|
||||
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceCurrenciesConfigurations;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Models\SegmentConstant;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class CustomConfigurationsObject implements DataTransferObject
|
||||
{
|
||||
|
||||
|
||||
/** @var SegmentConstant */
|
||||
private $configurations;
|
||||
|
||||
/** @var SegmentConstant */
|
||||
private $customOptions;
|
||||
|
||||
/**
|
||||
* CustomConfigurationsObject constructor.
|
||||
* @param SegmentConstant $configurations
|
||||
* @param SegmentConstant $customOptions
|
||||
*/
|
||||
public function __construct(SegmentConstant $configurations, SegmentConstant $customOptions)
|
||||
{
|
||||
$this->configurations = $configurations;
|
||||
$this->customOptions = $customOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SegmentConstant
|
||||
*/
|
||||
public function getConfigurations(): SegmentConstant
|
||||
{
|
||||
return $this->configurations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SegmentConstant
|
||||
*/
|
||||
public function getCustomOptions(): SegmentConstant
|
||||
{
|
||||
return $this->customOptions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfigurationValue(string $name) {
|
||||
return property_exists($this->getCustomOptions()->detail, $name) ?
|
||||
$this->getCustomOptions()->detail->$name: $this->configurations->detail->$name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function calculateServiceCharge(){
|
||||
return ($this->getConfigurationValue('service_charge')->value * 0.01) > $this->getConfigurationValue('minimum_charge')->value ?
|
||||
$this->getConfigurationValue('service_charge')->value : $this->getConfigurationValue('minimum_charge')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function calculateTax(){
|
||||
return $this->getConfigurationValue('tax')->value * 0.01;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Classes\Modules\Currencies\DataTransferObjects\RateObject;
|
||||
|
||||
class ServiceCurrenciesObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var int */
|
||||
private $id;
|
||||
|
||||
/** @var boolean */
|
||||
private $isActive;
|
||||
|
||||
/** @var array */
|
||||
private $maxLimit;
|
||||
|
||||
/** @var array */
|
||||
private $minLimit;
|
||||
|
||||
/** @var array */
|
||||
private $rates;
|
||||
|
||||
/**
|
||||
* ServiceCurrenciesObject constructor.
|
||||
* @param int $id
|
||||
* @param bool $isActive
|
||||
* @param array $maxLimit
|
||||
* @param array $minLimit
|
||||
* @param array $rates
|
||||
*/
|
||||
public function __construct(int $id, bool $isActive, array $maxLimit, array $minLimit, array $rates)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->isActive = $isActive;
|
||||
$this->maxLimit = $maxLimit;
|
||||
$this->minLimit = $minLimit;
|
||||
$this->rates = $rates;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->isActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMaxLimit(): array
|
||||
{
|
||||
return $this->maxLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMinLimit(): array
|
||||
{
|
||||
return $this->minLimit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRates(): array
|
||||
{
|
||||
return array_map(function($rate){
|
||||
return new RateObject($rate['selling'], $rate['payment_method']);
|
||||
}, $this->rates);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class ServiceDetailObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var int */
|
||||
private $id;
|
||||
|
||||
/** @var int|null */
|
||||
private $bankId;
|
||||
|
||||
/** @var array|null */
|
||||
private $serviceCharge;
|
||||
|
||||
/** @var array|null */
|
||||
private $minimumCharge;
|
||||
|
||||
/** @var array|null */
|
||||
private $tax;
|
||||
|
||||
/** @var array|null */
|
||||
private $poLimit;
|
||||
|
||||
/** @var array|null */
|
||||
private $currencies;
|
||||
|
||||
/** @var boolean */
|
||||
private $isActive;
|
||||
|
||||
/** @var boolean */
|
||||
private $isBillable;
|
||||
|
||||
/**
|
||||
* ServiceDetailObject constructor.
|
||||
* @param int $id
|
||||
* @param int|null $bankId
|
||||
* @param array|null $serviceCharge
|
||||
* @param array|null $minimumCharge
|
||||
* @param array|null $tax
|
||||
* @param array|null $poLimit
|
||||
* @param array|null $currencies
|
||||
* @param bool $isActive
|
||||
* @param bool $isBillable
|
||||
*/
|
||||
public function __construct(int $id, ?int $bankId, ?array $serviceCharge, ?array $minimumCharge, ?array $tax, ?array $poLimit, ?array $currencies, bool $isActive, bool $isBillable)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->bankId = $bankId;
|
||||
$this->serviceCharge = $serviceCharge;
|
||||
$this->minimumCharge = $minimumCharge;
|
||||
$this->tax = $tax;
|
||||
$this->poLimit = $poLimit;
|
||||
$this->currencies = $currencies;
|
||||
$this->isActive = $isActive;
|
||||
$this->isBillable = $isBillable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getBankId(): ?int
|
||||
{
|
||||
return $this->bankId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getServiceCharge(): ?array
|
||||
{
|
||||
return $this->serviceCharge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getMinimumCharge(): ?array
|
||||
{
|
||||
return $this->minimumCharge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getTax(): ?array
|
||||
{
|
||||
return $this->tax;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getPoLimit(): ?array
|
||||
{
|
||||
return $this->poLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->isActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isBillable(): bool
|
||||
{
|
||||
return $this->isBillable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getCurrencies(): ?array
|
||||
{
|
||||
return array_map(function($currency){
|
||||
return new ServiceCurrenciesObject($currency['id'], $currency['active'], $currency['maximum_limit'], $currency['minimum_limit'], $currency['rates']);
|
||||
}, $this->currencies);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\DataTransferObjects;
|
||||
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class ServiceTypeObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* ServiceTypeObject constructor.
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
use App\Models\ServiceType;
|
||||
|
||||
class CreatesServiceType extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
public function execute(ServiceTypeObject $object) {
|
||||
$model = new ServiceType();
|
||||
$model->name = $object->getName();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Helper;
|
||||
use App\Classes\Modules\Currencies\DataTransferObjects\RateObject;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceCurrenciesObject;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceDetailObject;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreatesServiceTypeConstantDetails
|
||||
{
|
||||
|
||||
/** @var array */
|
||||
private $ConstantDetails;
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceDetailObject $object
|
||||
* @param bool|null $isCustomSegment
|
||||
* @return array
|
||||
*/
|
||||
public function execute(ServiceDetailObject $object, ?bool $isCustomSegment = false) {
|
||||
|
||||
foreach (Helper::getClassMethodsArray(ServiceDetailObject::class) as $methodName){
|
||||
|
||||
if(Helper::getPropertyName($methodName) === 'currencies'){
|
||||
|
||||
$this->mapCurrencies($object->$methodName(), $isCustomSegment);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->addToConstantDetails($methodName, $this->cleanValue($object->$methodName()));
|
||||
|
||||
}
|
||||
|
||||
return $this->ConstantDetails;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $currencies
|
||||
* @param bool $isCustomSegment
|
||||
*/
|
||||
private function mapCurrencies(array $currencies, bool $isCustomSegment){
|
||||
|
||||
$isEmpty = true;
|
||||
foreach ($currencies as $currency){
|
||||
|
||||
if(!$currency->isActive()) { continue; }
|
||||
|
||||
$currencyObject = [];
|
||||
|
||||
|
||||
foreach (Helper::getClassMethodsArray(ServiceCurrenciesObject::class) as $methodName){
|
||||
|
||||
if($methodName === 'isActive') continue;
|
||||
if($methodName === 'getRates') {
|
||||
$currencyObject['rates'] = $this->mapRates($currency->$methodName(), $isCustomSegment);
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $this->cleanValue($currency->$methodName());
|
||||
|
||||
if($this->isAddable($value)) {
|
||||
$isEmpty = false;
|
||||
$currencyObject[Helper::getPropertyName($methodName)] = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->addToCurrencyDetails($currencyObject);
|
||||
|
||||
}
|
||||
|
||||
if($isEmpty) $this->ConstantDetails['currencies'] = [];
|
||||
|
||||
}
|
||||
|
||||
private function mapRates(array $rates, bool $isCustomSegment){
|
||||
|
||||
if(!$isCustomSegment) return [];
|
||||
|
||||
$ratesObject = [];
|
||||
|
||||
/** @var RateObject $rate */
|
||||
foreach ($rates as $rate){
|
||||
|
||||
$selling = $this->cleanValue($rate->getSelling());
|
||||
|
||||
if(!$selling['value']) continue;
|
||||
|
||||
$ratesObject[] = [
|
||||
'payment_type' => $rate->getPaymentMethodType(),
|
||||
'payment_method' => PaymentMethodType::PAYMENT_METHODS_ID[$rate->getPaymentMethodType()],
|
||||
'selling' => $rate->getSelling()
|
||||
];
|
||||
|
||||
}
|
||||
return $ratesObject;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $methodName
|
||||
* @param $value
|
||||
*/
|
||||
private function addToConstantDetails(string $methodName, $value){
|
||||
$this->isAddable($value) ? $this->ConstantDetails[Helper::getPropertyName($methodName)] = $value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
private function isAddable($value){
|
||||
|
||||
return $value !== '' && $value !== null;
|
||||
}
|
||||
|
||||
private function cleanValue($value){
|
||||
|
||||
if(is_array($value)) {
|
||||
if(array_key_exists('value', $value)) $value['value'] = floatval(str_replace(',', '', $value['value']));
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $value
|
||||
*/
|
||||
private function addToCurrencyDetails(array $value){
|
||||
$this->ConstantDetails['currencies'][] = $value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
use App\Models\ServiceType;
|
||||
|
||||
class DeletesServiceType extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
public function execute(ServiceType $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Services;
|
||||
|
||||
use App\Classes\Modules\Banks\Services\FetchesBank;
|
||||
use App\Models\SegmentConstant;
|
||||
|
||||
class FetchesServiceBankConfigurations
|
||||
{
|
||||
|
||||
/** @var FetchesBank */
|
||||
private $fetchesBank;
|
||||
|
||||
/**
|
||||
* FetchesServiceBankConfigurations constructor.
|
||||
* @param FetchesBank $fetchesBank
|
||||
*/
|
||||
public function __construct(FetchesBank $fetchesBank)
|
||||
{
|
||||
$this->fetchesBank = $fetchesBank;
|
||||
}
|
||||
|
||||
public function execute(SegmentConstant $constants)
|
||||
{
|
||||
return $this->fetchesBank->execute(['id' => $constants->detail->bank_id]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Services;
|
||||
|
||||
use App\Classes\Modules\Segments\Services\FetchesConstant;
|
||||
use App\Models\SegmentConstant;
|
||||
|
||||
class FetchesServiceConfigurations
|
||||
{
|
||||
|
||||
/** @var FetchesConstant */
|
||||
private $fetchesConstant;
|
||||
|
||||
/** @var FetchesServiceCurrenciesConfigurations */
|
||||
private $fetchesServiceCurrenciesConfigurations;
|
||||
|
||||
/** @var FetchesServiceBankConfigurations */
|
||||
private $fetchesServiceBankConfigurations;
|
||||
|
||||
/**
|
||||
* FetchesServiceConfigurations constructor.
|
||||
* @param FetchesConstant $fetchesConstant
|
||||
* @param FetchesServiceCurrenciesConfigurations $fetchesServiceCurrenciesConfigurations
|
||||
*/
|
||||
public function __construct(FetchesConstant $fetchesConstant, FetchesServiceCurrenciesConfigurations $fetchesServiceCurrenciesConfigurations, FetchesServiceBankConfigurations $fetchesServiceBankConfigurations)
|
||||
{
|
||||
$this->fetchesConstant = $fetchesConstant;
|
||||
$this->fetchesServiceCurrenciesConfigurations = $fetchesServiceCurrenciesConfigurations;
|
||||
$this->fetchesServiceBankConfigurations = $fetchesServiceBankConfigurations;
|
||||
}
|
||||
|
||||
|
||||
public function execute(SegmentConstant $constant, string $type){
|
||||
|
||||
return array_merge([
|
||||
'active' => (int) $constant->detail->is_active ?? false,
|
||||
'billable' => (int) $constant->detail->is_billable ?? false,
|
||||
'bank_id' => property_exists($constant->detail, 'bank_id') ? $constant->detail->bank_id : '',
|
||||
'bank_info' => property_exists($constant->detail, 'bank_id') ? $this->fetchesServiceBankConfigurations->execute($constant) : '',
|
||||
'currencies' => $this->fetchesServiceCurrenciesConfigurations->execute($constant)
|
||||
], $this->addConfigurations($constant)->toArray());
|
||||
|
||||
}
|
||||
|
||||
private function addConfigurations(SegmentConstant $constant) {
|
||||
|
||||
$configurations = collect(['service_charge', 'minimum_charge', 'tax', 'po_limit']);
|
||||
|
||||
return $configurations->flatMap(function($configuration) use($constant) {
|
||||
if(!property_exists($constant->detail, $configuration)) return [];
|
||||
|
||||
return [$configuration => [
|
||||
'type' => $constant->detail->$configuration->type,
|
||||
'value' => $configuration !== 'po_limit' ? $this->covertToDecimal($constant->detail->$configuration->value) : $constant->detail->$configuration->value
|
||||
]];
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private function covertToDecimal($value){
|
||||
return number_format((float)$value, 2, '.', '');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Services;
|
||||
|
||||
|
||||
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Http\Resources\CurrencyResource;
|
||||
use App\Models\SegmentConstant;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class FetchesServiceCurrenciesConfigurations
|
||||
{
|
||||
|
||||
/** @var FetchesCurrency */
|
||||
private $fetchesCurrency;
|
||||
|
||||
/**
|
||||
* FetchesServiceCurrenciesConfigurations constructor.
|
||||
* @param FetchesCurrency $fetchesCurrency
|
||||
*/
|
||||
public function __construct(FetchesCurrency $fetchesCurrency)
|
||||
{
|
||||
$this->fetchesCurrency = $fetchesCurrency;
|
||||
}
|
||||
|
||||
public function execute(SegmentConstant $constants){
|
||||
|
||||
$currencies = array_map(function($configuration) use($constants){
|
||||
|
||||
$currency = $this->fetchesCurrency->execute(['id' => $configuration->id]);
|
||||
|
||||
if(! $currency->exists()) return [];
|
||||
|
||||
return json_decode(json_encode([
|
||||
'currency_object' => new CurrencyResource($currency),
|
||||
'id' => $configuration->id,
|
||||
'active' => true,
|
||||
'maximum_limit' => [
|
||||
'type' => $configuration->max_limit->type,
|
||||
'value' => number_format((float)$configuration->max_limit->value, 2, '.', ',')
|
||||
],
|
||||
'minimum_limit' => [
|
||||
'type' => $configuration->min_limit->type,
|
||||
'value' => number_format((float)$configuration->min_limit->value, 2, '.', ',')
|
||||
],
|
||||
'rates' => $constants->reference === SegmentConstants::SERVICE_TYPE ? $this->standardRates($currency->rates->where('service_id', $constants->detail->id)) : $configuration->rates
|
||||
]));
|
||||
|
||||
}, $constants->detail->currencies);
|
||||
|
||||
return array_filter($currencies);
|
||||
|
||||
}
|
||||
|
||||
private function standardRates(Collection $rates){
|
||||
return $rates->map(function($rate){
|
||||
return [
|
||||
'payment_method' => PaymentMethodType::PAYMENT_METHODS_ID[$rate->payment_method_type],
|
||||
'selling' => [
|
||||
'type' => 'rate',
|
||||
'value' => $rate->selling
|
||||
]
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\ServiceType;
|
||||
|
||||
class FetchesServiceType extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var ServiceType */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesServiceType constructor.
|
||||
* @param ServiceType $repository
|
||||
*/
|
||||
public function __construct(ServiceType $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\ServiceType;
|
||||
|
||||
class ListsServiceTypes extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var ServiceType */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsServiceTypes constructor.
|
||||
* @param ServiceType $repository
|
||||
*/
|
||||
public function __construct(ServiceType $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Services;
|
||||
|
||||
|
||||
use App\Classes\Modules\Currencies\DataTransferObjects\RateObject;
|
||||
use App\Classes\Modules\Currencies\Services\Rates\CreatesRateLog;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceCurrenciesObject;
|
||||
use App\Models\CurrencyRate;
|
||||
use App\Models\ServiceType;
|
||||
|
||||
class UpdatesServiceCurrencyRates
|
||||
{
|
||||
|
||||
/** @var CreatesRateLog */
|
||||
private $createsRateLog;
|
||||
|
||||
/**
|
||||
* UpdatesServiceCurrencyRates constructor.
|
||||
* @param CreatesRateLog $createsRateLog
|
||||
*/
|
||||
public function __construct(CreatesRateLog $createsRateLog)
|
||||
{
|
||||
$this->createsRateLog = $createsRateLog;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceType $service
|
||||
* @param array $currencies
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(ServiceType $service, array $currencies){
|
||||
|
||||
/** @var ServiceCurrenciesObject $currency */
|
||||
foreach ($currencies as $currency) {
|
||||
|
||||
/** @var RateObject $rate */
|
||||
foreach ($currency->getRates() as $rate){
|
||||
if($rate->getSelling()['value'] > 0){
|
||||
/** @var CurrencyRate $query */
|
||||
$query = $service->rates()->updateOrCreate([
|
||||
'currency_id' => $currency->getId(),
|
||||
'payment_method_type' => $rate->getPaymentMethodType()
|
||||
], ['selling' => $rate->getSelling()['value']]);
|
||||
|
||||
$this->createsRateLog->execute($query);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
use App\Models\ServiceType;
|
||||
|
||||
class UpdatesServiceType extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
public function execute(ServiceType $model, ServiceTypeObject $object) {
|
||||
|
||||
$model->name = $object->getName();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
use App\Models\ServiceType;
|
||||
|
||||
class UpdatesServiceTypeStatus extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
public function execute(ServiceType $model, int $status) {
|
||||
|
||||
$model->status = $status;
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
use App\Classes\Modules\ServiceTypes\Standards\Validators\ServiceTypeValidation;
|
||||
|
||||
class CanCreateServiceType extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var ServiceTypeValidation */
|
||||
private $serviceTypeValidation;
|
||||
|
||||
/**
|
||||
* CanCreateServiceType constructor.
|
||||
* @param ServiceTypeValidation $serviceTypeValidation
|
||||
*/
|
||||
public function __construct(ServiceTypeValidation $serviceTypeValidation)
|
||||
{
|
||||
$this->serviceTypeValidation = $serviceTypeValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServiceTypeObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->serviceTypeValidation->validate($object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceTypeObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
|
||||
class CanDeleteServiceType extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServiceTypeObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceTypeObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
|
||||
class CanFetchServiceType extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServiceTypeObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceTypeObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
|
||||
class CanListServiceTypes extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServiceTypeObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceTypeObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
use App\Classes\Modules\ServiceTypes\Standards\Validators\ServiceTypeValidation;
|
||||
|
||||
class CanUpdateServiceType extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var ServiceTypeValidation */
|
||||
private $serviceTypeValidation;
|
||||
|
||||
/**
|
||||
* CanUpdateServiceType constructor.
|
||||
* @param ServiceTypeValidation $serviceTypeValidation
|
||||
*/
|
||||
public function __construct(ServiceTypeValidation $serviceTypeValidation)
|
||||
{
|
||||
$this->serviceTypeValidation = $serviceTypeValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServiceTypeObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->serviceTypeValidation->validate($object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceTypeObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\Standards\Validators;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\ServiceTypes\DataTransferObjects\ServiceTypeObject;
|
||||
|
||||
class ServiceTypeValidation extends AbstractValidation
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceTypeObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array {
|
||||
return [
|
||||
'name' => $object->getName()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'name' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
|
||||
use App\Classes\Modules\SegmentConstants\Services\FetchesSegmentConstant;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
|
||||
// use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
// use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
// use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
// use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
// use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
// use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
// use App\Models\Document;
|
||||
// use App\Models\Transaction;
|
||||
// use Barryvdh\DomPDF\PDF;
|
||||
// use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
// use Meneses\LaravelLaravelMpdf\Facades\LaravelLaravelMpdf;
|
||||
// use Meneses\LaravelMpdf\Facades\LaravelMpdf;
|
||||
|
||||
class CreateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Create Supplier Transactions',
|
||||
'message' => 'You have successfully created currency supplier transactions'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesPackingList */
|
||||
private $fetchesPackingList;
|
||||
|
||||
/** @var FetchesSegmentConstant */
|
||||
private $fetchesSegmentConstant;
|
||||
|
||||
/** @var GeneratesTransactionBillNumber */
|
||||
private $generatesTransactionBillNumber;
|
||||
|
||||
/** @var CreatesTransaction */
|
||||
private $createsTransaction;
|
||||
|
||||
// /** @var FetchesTransaction */
|
||||
// private $fetchesTransaction;
|
||||
// /** @var UpdatesTransactionStatus */
|
||||
// private $updatesTransactionStatus;
|
||||
// /** @var CreatesDocument */
|
||||
// private $createsDocument;
|
||||
// /** @var CreatesFiles */
|
||||
// private $createsFile;
|
||||
// /** @var PDF */
|
||||
// private $pdf;
|
||||
|
||||
/**
|
||||
* CreateSupplierTransactionLogic constructor.
|
||||
* @param FetchesPackingList $fetchesPackingList
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
* @param CreatesTransaction $createsTransaction
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param PDF $pdf
|
||||
*/
|
||||
public function __construct(
|
||||
FetchesPackingList $fetchesPackingList,
|
||||
FetchesSegmentConstant $fetchesSegmentConstant,
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
CreatesTransaction $createsTransaction
|
||||
|
||||
// UpdatesTransactionStatus $updatesTransactionStatus,
|
||||
// CreatesDocument $createsDocument,
|
||||
// CreatesFiles $createsFile,
|
||||
// PDF $pdf
|
||||
)
|
||||
{
|
||||
|
||||
$this->fetchesPackingList = $fetchesPackingList;
|
||||
$this->fetchesSegmentConstant = $fetchesSegmentConstant;
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsTransaction = $createsTransaction;
|
||||
|
||||
// $this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
// $this->createsDocument = $createsDocument;
|
||||
// $this->createsFile = $createsFile;
|
||||
// $this->pdf = $pdf;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$packing_list = $this->fetchesPackingList->execute(['id' => $request->input('packing_list_id')]);
|
||||
|
||||
$cbm = $packing_list->packages->sum(function($package) {
|
||||
return ($package->width / 100) * ($package->height / 100) *($package->length / 100) * ($package->quantity);
|
||||
});
|
||||
|
||||
$order = $packing_list->owner()->first();
|
||||
$address = $order->addresses()->first();
|
||||
|
||||
$base_price_constant = $this->fetchesSegmentConstant->execute(['id' => 1]);
|
||||
$warehouse_rate_constant = $this->fetchesSegmentConstant->execute(['id' => 2]);
|
||||
$state_rate_constant = $this->fetchesSegmentConstant->execute(['id' => 3]);
|
||||
$center_postcode_constant = $this->fetchesSegmentConstant->execute(['id' => 4]);
|
||||
$outstation_postcode_constant = $this->fetchesSegmentConstant->execute(['id' => 5]);
|
||||
|
||||
$base_price = 0;
|
||||
$warehouse_rate = 0;
|
||||
$state_rate = 0;
|
||||
$state_select = [];
|
||||
$with_out = false;
|
||||
|
||||
if ($base_price_constant) {
|
||||
$base_price = $base_price_constant->value->price;
|
||||
}
|
||||
|
||||
if ($warehouse_rate_constant) {
|
||||
$package_warehouse = $order->OrderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->reference;
|
||||
foreach ($warehouse_rate_constant->value->config as $key_warehouse => $row_warehouse) {
|
||||
if ($row_warehouse->warehouse_name == $package_warehouse) {
|
||||
$warehouse_rate = $row_warehouse->rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($state_rate_constant) {
|
||||
foreach ($state_rate_constant->value->config as $key_state => $row_state) {
|
||||
if ($row_state->status_id == $address->state_id) {
|
||||
$state_select = $row_state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($outstation_postcode_constant) {
|
||||
foreach ($outstation_postcode_constant->value as $key_out => $row_out) {
|
||||
|
||||
if($row_out == $address->postcode) {
|
||||
$with_out = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($state_select)) {
|
||||
$state_rate = $state_select->rate;
|
||||
if ($with_out) {
|
||||
$state_rate = $state_select->rate + $state_select->outstation_rate;
|
||||
}
|
||||
}
|
||||
|
||||
$price_cbm = $base_price + $warehouse_rate + $state_rate;
|
||||
$total_cbm = $price_cbm * $cbm;
|
||||
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('SHIP-');
|
||||
|
||||
$object = new TransactionObject(
|
||||
$billNumber,
|
||||
TransactionType::SHIPPING_INVOICE,
|
||||
1,
|
||||
$order->company_module_id,
|
||||
1,
|
||||
PaymentMethodType::CASH,
|
||||
$total_cbm,
|
||||
$total_cbm,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
ApprovalStatus::PENDING_SUBMISSION
|
||||
);
|
||||
|
||||
$transactions = $this->createsTransaction->execute($packing_list, $object);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,24 @@ class TransactionObject implements DataTransferObject
|
||||
* @param int|null $status
|
||||
* @param array|null $details
|
||||
*/
|
||||
public function __construct(string $billNo, string $transactionType, int $issuer, int $receiver, int $recipientBankAccountId, int $paymentMethod, float $amount, float $originalAmount, int $currencyId, int $originalCurrencyId, float $currencyRate, float $tax, float $serviceCharge, ?Carbon $expiresOn, ?int $status = ApprovalStatus::PENDING_SUBMISSION, ?array $details = [])
|
||||
public function __construct(
|
||||
string $billNo,
|
||||
string $transactionType,
|
||||
int $issuer,
|
||||
int $receiver,
|
||||
int $recipientBankAccountId,
|
||||
int $paymentMethod,
|
||||
float $amount,
|
||||
float $originalAmount,
|
||||
int $currencyId,
|
||||
int $originalCurrencyId,
|
||||
float $currencyRate,
|
||||
float $tax,
|
||||
float $serviceCharge,
|
||||
?Carbon $expiresOn,
|
||||
?int $status = ApprovalStatus::PENDING_SUBMISSION,
|
||||
?array $details = []
|
||||
)
|
||||
{
|
||||
$this->billNo = $billNo;
|
||||
$this->transactionType = $transactionType;
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Classes\Modules\Transactions\Services;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Models\Booking;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\Transaction;
|
||||
|
||||
class CreatesTransaction extends AbstractUpdateRelationshipRecord
|
||||
@@ -15,7 +15,7 @@ class CreatesTransaction extends AbstractUpdateRelationshipRecord
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Booking $booking, TransactionObject $object) {
|
||||
public function execute(PackingList $packing_list, TransactionObject $object) {
|
||||
$model = new Transaction();
|
||||
$model->bill_no = $object->getBillNo();
|
||||
$model->type = $object->getTransactionType();
|
||||
@@ -33,8 +33,6 @@ class CreatesTransaction extends AbstractUpdateRelationshipRecord
|
||||
$model->expires_on = $object->getExpiresOn();
|
||||
$model->status = $object->getStatus();
|
||||
|
||||
|
||||
return $this->handler($booking->transactions(), $model);
|
||||
|
||||
return $this->handler($packing_list->transactions(), $model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transports\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\Transport;
|
||||
|
||||
class updatesTransportStatus extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Transport $model
|
||||
* @param int $status
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Transport $model, int $status) {
|
||||
|
||||
$model->status = $status;
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,19 +5,19 @@ namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
class SegmentConstants
|
||||
{
|
||||
|
||||
public const STANDARD_SEGMENT = 1;
|
||||
|
||||
public const CUSTOM_SEGMENT = 2;
|
||||
|
||||
public const SYSTEM_PRIMARY_CURRENCY = 'SYSTEM_PRIMARY_CURRENCY';
|
||||
public const BASE_PRICE = 'BASE_PRICE';
|
||||
|
||||
public const SUPPLIER_CURRENCIES = 'SUPPLIER_CURRENCIES';
|
||||
public const WAREHOUSE_RATE = 'WAREHOUSE_RATE';
|
||||
|
||||
public const PAYMENT_ATTEMPT_DURATION_LIMIT = 'PAYMENT_ATTEMPT_DURATION_LIMIT';
|
||||
public const STATE_RATE = 'STATE_RATE';
|
||||
|
||||
public const SERVICE_TYPE = 'SERVICE_TYPE';
|
||||
public const CENTER_POSTCODE = 'CENTER_POSTCODE';
|
||||
|
||||
public const CUSTOM_SERVICE_TYPE = 'CUSTOM_SERVICE_TYPE';
|
||||
public const OUTSTATION_POSTCODE = 'OUTSTATION_POSTCODE';
|
||||
|
||||
public const CUSTOMER_RATE = 'CUSTOMER_RATE';
|
||||
}
|
||||
@@ -4,24 +4,26 @@ namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
final class TransactionType {
|
||||
|
||||
public const PAYMENT_ATTEMPT = 0;
|
||||
public const SHIPPING_INVOICE = 1;
|
||||
|
||||
// public const PAYMENT_ATTEMPT = 0;
|
||||
|
||||
public const PAYMENT = 1;
|
||||
// public const PAYMENT = 1;
|
||||
|
||||
public const INVOICE = 2;
|
||||
// public const INVOICE = 2;
|
||||
|
||||
public const BILL = 3;
|
||||
// public const BILL = 3;
|
||||
|
||||
public const PERFORMA = 4;
|
||||
// public const PERFORMA = 4;
|
||||
|
||||
public const TOP_UP = 5;
|
||||
// public const TOP_UP = 5;
|
||||
|
||||
public const REFUND = 6;
|
||||
// public const REFUND = 6;
|
||||
|
||||
public const PURCHASE_ORDER = 7;
|
||||
// public const PURCHASE_ORDER = 7;
|
||||
|
||||
public const SUPPLIER_DELIVER = 8;
|
||||
// public const SUPPLIER_DELIVER = 8;
|
||||
|
||||
public const SHIPPING_COST = 9;
|
||||
// public const SHIPPING_COST = 9;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Addresses;
|
||||
|
||||
use App\Classes\Modules\Addresses\ControllersLogic\ListStatesLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListStatesController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param ListStatesLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function list(Request $request, ListStatesLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,4 +17,4 @@ class ListAnnouncementsController
|
||||
{
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,3 @@ class UpdateAnnouncementController
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Companies;
|
||||
|
||||
use App\Classes\Modules\Accounts\ControllersLogic\AddNewMemberLogic;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AddNewMemberController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param AddNewMemberLogic $execute
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function create(Request $request, AddNewMemberLogic $execute) : JsonResponse
|
||||
{
|
||||
return $execute->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Documents;
|
||||
|
||||
use App\Classes\Modules\Documents\ControllersLogic\UpdateDocumentReferenceLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateDocumentReferenceController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param UpdateDocumentReferenceLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(Request $request, UpdateDocumentReferenceLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Exports;
|
||||
|
||||
use App\Classes\Modules\Exports\Services\ExportsContainerPackingList;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
|
||||
class ExportContainerPackingListController
|
||||
{
|
||||
public function export(ExportsContainerPackingList $exportsContainerPackingList, Request $request) {
|
||||
$token = Auth::fromUser(User::find(1));
|
||||
$request->headers->set('Authorization', 'Bearer '.$token);
|
||||
$exportsContainerPackingList->setId($request->route('id'));
|
||||
return $exportsContainerPackingList->download('customer-container-packing-list.csv', Excel::CSV, ['Content-Type' => 'text/csv']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\PackingLists;
|
||||
|
||||
use App\Classes\Modules\PackingLists\ControllersLogic\AssignPackingListOrderLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AssignPackingListOrderController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param AssignPackingListOrderLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function assign(Request $request, AssignPackingListOrderLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,5 +16,4 @@ class CreateSegmentController
|
||||
public function create(Request $request, CreateSegmentLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Segments;
|
||||
|
||||
use App\Classes\Modules\Segments\ControllersLogic\FetchConstantLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchConstantController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param FetchConstantLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function fetch(Request $request, FetchConstantLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Segments;
|
||||
|
||||
use App\Classes\Modules\Segments\ControllersLogic\FetchSegmentLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchSegmentController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param FetchSegmentLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function fetch(Request $request, FetchSegmentLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Segments;
|
||||
|
||||
use App\Classes\Modules\Segments\ControllersLogic\ListSegmentLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListSegmentsController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param ListSegmentLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function list(Request $request, ListSegmentLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Segments;
|
||||
|
||||
use App\Classes\Modules\Segments\ControllersLogic\UpdateConstantLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateConstantController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param UpdateConstantLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(Request $request, UpdateConstantLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Segments;
|
||||
|
||||
use App\Classes\Modules\ServiceTypes\ControllersLogic\UpdateCustomServiceConstantLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateCustomServiceConstantController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param UpdateCustomServiceConstantLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(Request $request, UpdateCustomServiceConstantLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Segments;
|
||||
|
||||
use App\Classes\Modules\Segments\ControllersLogic\UpdateSegmentLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateSegmentController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param UpdateSegmentLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(Request $request, UpdateSegmentLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Transactions;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Transactions\ControllersLogic\CreateShippingInvoiceTransactionLogic;
|
||||
|
||||
|
||||
class CreateShippingInvoiceTransactionController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param CreateShippingInvoiceTransactionLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function create(Request $request, CreateShippingInvoiceTransactionLogic $logic) : JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\Modules\Segments\Services\ConvertsConstantDetailsToResource;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ConstantResource extends JsonResource
|
||||
{
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'reference' => $this->reference,
|
||||
'detail' => (App()->make(ConvertsConstantDetailsToResource::class))->execute($this->resource)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceConfigurations;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Models\ServiceType;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CustomServiceTypeResource extends JsonResource
|
||||
{
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->detail->id,
|
||||
'name' => ServiceType::where('id', $this->detail->id)->first()->name,
|
||||
'detail' => $this->detail,
|
||||
'configurations' => (App()->make(FetchesServiceConfigurations::class))->execute($this->resource, SegmentConstants::CUSTOM_SERVICE_TYPE)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,8 @@ class DistrictResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'city' => $this->name,
|
||||
'state' => $this->state,
|
||||
'country' => $this->country
|
||||
'country' => $this->country,
|
||||
'postcode' => $this->postcode,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PackageResource extends JsonResource
|
||||
@@ -16,6 +17,8 @@ class PackageResource extends JsonResource
|
||||
public function toArray($request)
|
||||
{
|
||||
|
||||
$originalPackingList = $this->packingList->owner instanceof PackingList ? $this->packingList->owner : $this->packingList;
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'type' => $this->type,
|
||||
@@ -27,9 +30,11 @@ class PackageResource extends JsonResource
|
||||
'quantity' => $this->quantity,
|
||||
'cbm' => (($this->width / 100) * ($this->height / 100) * ($this->length / 100)) * $this->quantity,
|
||||
'status' => $this->status,
|
||||
'order' => New OrderResource($this->packingList->owner instanceof Order ? $this->packingList->owner : $this->packingList->owner->owner),
|
||||
'container' => new ContainerResource($this->packingList->owner instanceof Order ? $this->container : $this->packingList->owner->containers()->first()),
|
||||
'transport' => new TransportResource($this->packingList->owner instanceof Order ? $this->transport : $this->packingList->owner->transports()->first())
|
||||
$this->mergeWhen($originalPackingList->owner instanceof Order, [
|
||||
'order' => New OrderResource($originalPackingList->owner)
|
||||
]),
|
||||
'container' => new ContainerResource($originalPackingList->containers()->first()),
|
||||
'transport' => new TransportResource($originalPackingList->transports()->first())
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PackingListNullOrderResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$replica = $this->packingLists()->first();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'claimant_id' => $this->claimant_id,
|
||||
'reference' => $this->reference,
|
||||
'status' => $this->status,
|
||||
'type' => $this->type,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ScheduleResource extends JsonResource
|
||||
{
|
||||
@@ -18,6 +19,10 @@ class ScheduleResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'etd' => $this->etd ? $this->etd->format('d-m-Y') : 'n/a',
|
||||
'eta' => $this->eta ? $this->eta->format('d-m-Y') : 'n/a',
|
||||
'billing_days_left' => [
|
||||
'value' => (Carbon::parse($this->eta)->subDays(7)->gt(Carbon::now())) ? '+' : '-' ,
|
||||
'duration' => Carbon::parse($this->eta)->subDays(7)->diffInDays(Carbon::now()),
|
||||
],
|
||||
'status' => $this->status,
|
||||
];
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user