diff --git a/.env.example b/.env.example index 5ac21009..b26bfbf8 100644 --- a/.env.example +++ b/.env.example @@ -45,4 +45,7 @@ PUSHER_APP_CLUSTER=mt1 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" -JWT_SECRET= \ No newline at end of file +FILESYSTEM_DRIVER="documents" + +JWT_SECRET= +JWT_TTL=1440 \ No newline at end of file diff --git a/app/Classes/Exceptions/ErrorException.php b/app/Classes/Exceptions/ErrorException.php index 34cfdbb5..a1a71069 100644 --- a/app/Classes/Exceptions/ErrorException.php +++ b/app/Classes/Exceptions/ErrorException.php @@ -3,7 +3,6 @@ namespace App\Classes\Exceptions; use Exception; -use Illuminate\Support\Facades\Log; class ErrorException extends Exception { diff --git a/app/Classes/General/Abstracts/AbstractControllerLogic.php b/app/Classes/General/Abstracts/AbstractControllerLogic.php index c07da1ce..2fdd0dab 100644 --- a/app/Classes/General/Abstracts/AbstractControllerLogic.php +++ b/app/Classes/General/Abstracts/AbstractControllerLogic.php @@ -3,16 +3,19 @@ namespace App\Classes\General\Abstracts; +use App\Classes\Exceptions\ErrorException; +use App\Classes\Exceptions\InternalServerErrorException; use App\Classes\ValueObjects\Constants\Notifications; use App\Classes\ValueObjects\Constants\HttpStatus; use App\Classes\ValueObjects\Response\ApiResponseObject; -use ErrorException; +use ErrorException as GeneralExceptions; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\Json\ResourceCollection; +use Illuminate\Support\Facades\DB; -abstract class AbstractControllersLogic +abstract class AbstractControllerLogic { /** @@ -49,10 +52,17 @@ abstract class AbstractControllersLogic try { - return $this->logic($request); + DB::beginTransaction(); - } catch (ErrorException $exception){ - return (new ApiResponseObject($this->getNotificationTitle().' failed', $exception->getMessage(), $exception->getCode()))->handler(); + $response = $this->logic($request); + + DB::commit(); + + return $response; + + } catch (ErrorException|GeneralExceptions $exception){ + return (new ApiResponseObject($this->getNotificationTitle().' failed', $exception->getMessage(), + $exception->getCode() ? $exception->getCode() : HttpStatus::SERVER_ERROR))->handler(); } } diff --git a/app/Classes/General/Abstracts/AbstractRule.php b/app/Classes/General/Abstracts/AbstractRule.php index a4506ba2..d2e0568b 100644 --- a/app/Classes/General/Abstracts/AbstractRule.php +++ b/app/Classes/General/Abstracts/AbstractRule.php @@ -5,7 +5,7 @@ namespace App\Classes\General\Abstracts; use App\Classes\Exceptions\AccessForbiddenException; use App\Classes\Exceptions\RequestValidationException; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; abstract class AbstractRule { diff --git a/app/Classes/General/Abstracts/AbstractService.php b/app/Classes/General/Abstracts/AbstractService.php index 03a2e8cc..7c7b6ddb 100644 --- a/app/Classes/General/Abstracts/AbstractService.php +++ b/app/Classes/General/Abstracts/AbstractService.php @@ -3,7 +3,7 @@ namespace App\Classes\General\Abstracts; use App\Classes\Exceptions\MalformedRequestException; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\QueryException; @@ -16,7 +16,7 @@ abstract class AbstractService * @return mixed * @throws MalformedRequestException */ - public function execute(Model $model, DataTransferObject $object){ + public function execute(Model $model){ try{ diff --git a/app/Classes/General/Abstracts/AbstractValidation.php b/app/Classes/General/Abstracts/AbstractValidation.php index 27f51272..fae27298 100644 --- a/app/Classes/General/Abstracts/AbstractValidation.php +++ b/app/Classes/General/Abstracts/AbstractValidation.php @@ -4,7 +4,7 @@ namespace App\Classes\General\Abstracts; use App\Classes\Exceptions\RequestValidationException; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; use Illuminate\Support\Facades\Validator; abstract class AbstractValidation @@ -31,6 +31,7 @@ abstract class AbstractValidation /** * @param DataTransferObject $object + * @param null|string $type * @return bool * @throws RequestValidationException */ diff --git a/app/Classes/General/DummyDataTransferObject.php b/app/Classes/General/DummyDataTransferObject.php new file mode 100644 index 00000000..98f2a056 --- /dev/null +++ b/app/Classes/General/DummyDataTransferObject.php @@ -0,0 +1,10 @@ +getMessage()); throw new MalformedRequestException('Unable to update the record due to unexpected error'); } } diff --git a/app/Classes/General/Eloquent/AbstractUpdateRecord.php b/app/Classes/General/Eloquent/AbstractUpdateRecord.php index 63d22180..44129c92 100644 --- a/app/Classes/General/Eloquent/AbstractUpdateRecord.php +++ b/app/Classes/General/Eloquent/AbstractUpdateRecord.php @@ -18,13 +18,10 @@ abstract class AbstractUpdateRecord public function handler(Model $model){ try{ - if($model->save()){ - return $model; - } + if($model->save()){ return $model; } } catch (QueryException $exception){ throw new MalformedRequestException($exception); - // throw new MalformedRequestException('Unable to update the record due to unexpected error'); } } diff --git a/app/Classes/General/Eloquent/AbstractUpdateRelationshipRecord.php b/app/Classes/General/Eloquent/AbstractUpdateRelationshipRecord.php new file mode 100644 index 00000000..00894f11 --- /dev/null +++ b/app/Classes/General/Eloquent/AbstractUpdateRelationshipRecord.php @@ -0,0 +1,33 @@ +save($model)){ + return $model; + } + + } catch (QueryException $exception){ + throw new MalformedRequestException($exception->getMessage()); + } + } + + + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/ApplyFiltersToQuery.php b/app/Classes/General/Eloquent/ApplyFiltersToQuery.php index 7531a2cf..afa2adb8 100644 --- a/app/Classes/General/Eloquent/ApplyFiltersToQuery.php +++ b/app/Classes/General/Eloquent/ApplyFiltersToQuery.php @@ -4,7 +4,6 @@ namespace App\Classes\General\Eloquent; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; class ApplyFiltersToQuery diff --git a/app/Classes/General/Eloquent/Filters/UserName.php b/app/Classes/General/Eloquent/Filters/BusinessType.php similarity index 54% rename from app/Classes/General/Eloquent/Filters/UserName.php rename to app/Classes/General/Eloquent/Filters/BusinessType.php index 6cf60e7f..a654c9ac 100644 --- a/app/Classes/General/Eloquent/Filters/UserName.php +++ b/app/Classes/General/Eloquent/Filters/BusinessType.php @@ -4,7 +4,7 @@ namespace App\Classes\General\Eloquent\Filters; use Illuminate\Database\Eloquent\Builder; -class UserName implements Filter +class BusinessType implements Filter { /** @@ -14,9 +14,7 @@ class UserName implements Filter */ public static function apply(Builder $builder, $value) { - return $builder->where(function($query) use ($value) { - $query->where('first_name', 'LIKE', '%' . $value . '%')->orWhere('last_name', 'LIKE', '%' . $value . '%'); - }); + return $builder->where('business_type', $value); } } \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/CountryId.php b/app/Classes/General/Eloquent/Filters/CountryId.php new file mode 100644 index 00000000..eb1a8b8e --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/CountryId.php @@ -0,0 +1,20 @@ +where('country_id', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/CustomServiceType.php b/app/Classes/General/Eloquent/Filters/CustomServiceType.php new file mode 100644 index 00000000..e894a5e0 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/CustomServiceType.php @@ -0,0 +1,21 @@ +where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->where('detail->id', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/DocumentTypeIn.php b/app/Classes/General/Eloquent/Filters/DocumentTypeIn.php new file mode 100644 index 00000000..c6382c10 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/DocumentTypeIn.php @@ -0,0 +1,20 @@ +whereIn('document_type', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/Email.php b/app/Classes/General/Eloquent/Filters/Email.php index c02c97f7..cc403255 100644 --- a/app/Classes/General/Eloquent/Filters/Email.php +++ b/app/Classes/General/Eloquent/Filters/Email.php @@ -14,7 +14,7 @@ class Email implements Filter */ public static function apply(Builder $builder, $value) { - return $builder->where('email', 'LIKE', '%' . $value . '%'); + return $builder->where('email', '=', $value); } } \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/NotId.php b/app/Classes/General/Eloquent/Filters/IdNot.php similarity index 91% rename from app/Classes/General/Eloquent/Filters/NotId.php rename to app/Classes/General/Eloquent/Filters/IdNot.php index ea73b39c..8ed35044 100644 --- a/app/Classes/General/Eloquent/Filters/NotId.php +++ b/app/Classes/General/Eloquent/Filters/IdNot.php @@ -4,7 +4,7 @@ namespace App\Classes\General\Eloquent\Filters; use Illuminate\Database\Eloquent\Builder; -class NotId implements Filter +class IdNot implements Filter { /** diff --git a/app/Classes/General/Eloquent/Filters/IdNotIn.php b/app/Classes/General/Eloquent/Filters/IdNotIn.php new file mode 100644 index 00000000..12dd733d --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/IdNotIn.php @@ -0,0 +1,20 @@ +whereNotIn('id', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/Marking.php b/app/Classes/General/Eloquent/Filters/Marking.php new file mode 100644 index 00000000..77a4dae2 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/Marking.php @@ -0,0 +1,20 @@ +where('marking', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/NotExpired.php b/app/Classes/General/Eloquent/Filters/NotExpired.php new file mode 100644 index 00000000..c61a2fe8 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/NotExpired.php @@ -0,0 +1,21 @@ +whereDate('expires_on', '>=', Carbon::now()); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/OriginalCurrencyIdIn.php b/app/Classes/General/Eloquent/Filters/OriginalCurrencyIdIn.php new file mode 100644 index 00000000..628a27fa --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/OriginalCurrencyIdIn.php @@ -0,0 +1,20 @@ +whereIn('original_currency_id', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/Reference.php b/app/Classes/General/Eloquent/Filters/Reference.php new file mode 100644 index 00000000..fe2cbf03 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/Reference.php @@ -0,0 +1,20 @@ +where('Reference', '=', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/ServiceId.php b/app/Classes/General/Eloquent/Filters/ServiceId.php new file mode 100644 index 00000000..b5a55286 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/ServiceId.php @@ -0,0 +1,20 @@ +where('service_id', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/ServiceType.php b/app/Classes/General/Eloquent/Filters/ServiceType.php new file mode 100644 index 00000000..d3d8a2f1 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/ServiceType.php @@ -0,0 +1,21 @@ +where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->id', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/ShortCode.php b/app/Classes/General/Eloquent/Filters/ShortCode.php new file mode 100644 index 00000000..a5030343 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/ShortCode.php @@ -0,0 +1,20 @@ +where('short_code', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/StatusIn.php b/app/Classes/General/Eloquent/Filters/StatusIn.php new file mode 100644 index 00000000..cbfdfbd0 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/StatusIn.php @@ -0,0 +1,20 @@ +whereIn('status', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/SupplierCurrencies.php b/app/Classes/General/Eloquent/Filters/SupplierCurrencies.php new file mode 100644 index 00000000..1461dbae --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/SupplierCurrencies.php @@ -0,0 +1,21 @@ +where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/Type.php b/app/Classes/General/Eloquent/Filters/Type.php new file mode 100644 index 00000000..60555260 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/Type.php @@ -0,0 +1,20 @@ +where('type', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/WithBookings.php b/app/Classes/General/Eloquent/Filters/WithBookings.php new file mode 100644 index 00000000..8728e119 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/WithBookings.php @@ -0,0 +1,20 @@ +with('bookings'); + } +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/WithCompany.php b/app/Classes/General/Eloquent/Filters/WithCompany.php new file mode 100644 index 00000000..7c19bd29 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/WithCompany.php @@ -0,0 +1,20 @@ +with('owner'); + } +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/WithTransactions.php b/app/Classes/General/Eloquent/Filters/WithTransactions.php new file mode 100644 index 00000000..15cbd88e --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/WithTransactions.php @@ -0,0 +1,20 @@ +with('transactions'); + } +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/DefaultType.php b/app/Classes/General/Eloquent/Filters/isDefault.php similarity index 89% rename from app/Classes/General/Eloquent/Filters/DefaultType.php rename to app/Classes/General/Eloquent/Filters/isDefault.php index c23ceaaf..da62e1f6 100644 --- a/app/Classes/General/Eloquent/Filters/DefaultType.php +++ b/app/Classes/General/Eloquent/Filters/isDefault.php @@ -4,7 +4,7 @@ namespace App\Classes\General\Eloquent\Filters; use Illuminate\Database\Eloquent\Builder; -class DefaultType implements Filter +class isDefault implements Filter { /** diff --git a/app/Classes/General/Helper.php b/app/Classes/General/Helper.php new file mode 100644 index 00000000..cad68208 --- /dev/null +++ b/app/Classes/General/Helper.php @@ -0,0 +1,27 @@ +attempt = $attempt; + } + + + /** + * @throws MalformedRequestException + */ + public function handle() + { + (new ExpiresEmailVerificationAttempt())->execute($this->attempt); + + } +} diff --git a/app/Classes/Jobs/PasswordResetTokenExpiration.php b/app/Classes/Jobs/PasswordResetTokenExpiration.php new file mode 100644 index 00000000..d5010964 --- /dev/null +++ b/app/Classes/Jobs/PasswordResetTokenExpiration.php @@ -0,0 +1,39 @@ +attempt = $attempt; + } + + + /** + * @throws MalformedRequestException + */ + public function handle() + { + (new ExpiresPasswordReset())->execute($this->attempt); + } +} diff --git a/app/Classes/Jobs/SendResetPasswordEmail.php b/app/Classes/Jobs/SendResetPasswordEmail.php new file mode 100644 index 00000000..1a8d2488 --- /dev/null +++ b/app/Classes/Jobs/SendResetPasswordEmail.php @@ -0,0 +1,42 @@ +user = $user; + $this->attempt = $attempt; + } + + + public function handle() + { + $this->user->notify(new ResetPasswordEmail($this->user, $this->attempt)); + + } +} diff --git a/app/Classes/Jobs/SendUserVerificationEmail.php b/app/Classes/Jobs/SendUserVerificationEmail.php new file mode 100644 index 00000000..2bb54f47 --- /dev/null +++ b/app/Classes/Jobs/SendUserVerificationEmail.php @@ -0,0 +1,41 @@ +user = $user; + $this->attempt = $attempt; + } + + + public function handle() + { + $this->user->notify(new UserVerificationEmail($this->user, $this->attempt)); + } +} diff --git a/app/Classes/Modules/Accounts/ControllersLogic/AuthenticateUserLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/AuthenticateUserLogic.php index 198ee6df..f3353622 100644 --- a/app/Classes/Modules/Accounts/ControllersLogic/AuthenticateUserLogic.php +++ b/app/Classes/Modules/Accounts/ControllersLogic/AuthenticateUserLogic.php @@ -2,17 +2,12 @@ namespace App\Classes\Modules\Accounts\ControllersLogic; -use App\Classes\Modules\Accounts\DataTransferObjects\AuthenticationCredentialsObject; -use App\Classes\Modules\Accounts\Services\AuthenticatesUser; -use App\Classes\Modules\Accounts\Services\AuthenticationRedirect; -use App\Classes\Modules\Accounts\Standards\Rules\CanAuthenticateUser; -use App\Classes\General\Abstracts\AbstractControllersLogic; -use App\Classes\ValueObjects\Constants\Notifications; -use ErrorException; +use App\Classes\Modules\Accounts\Processors\AuthenticationProcessor; +use App\Classes\General\Abstracts\AbstractControllerLogic; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class AuthenticateUserLogic extends AbstractControllersLogic +class AuthenticateUserLogic extends AbstractControllerLogic { protected function notification():array { @@ -22,51 +17,30 @@ class AuthenticateUserLogic extends AbstractControllersLogic ]; } - /** @var CanAuthenticateUser */ - private $canAuthenticateUser; + /** @var AuthenticationProcessor */ + private $authenticationProcessor; - /** @var AuthenticatesUser */ - private $authenticatesUser; - - /** @var AuthenticationRedirect */ - private $authenticationRedirect; /** * AuthenticateUserLogic constructor. - * @param CanAuthenticateUser $canAuthenticateUser - * @param AuthenticatesUser $authenticatesUser - * @param AuthenticationRedirect $authenticationRedirect + * @param AuthenticationProcessor $authenticationProcessor */ - public function __construct(CanAuthenticateUser $canAuthenticateUser, AuthenticatesUser $authenticatesUser, AuthenticationRedirect $authenticationRedirect) + public function __construct(AuthenticationProcessor $authenticationProcessor) { - $this->canAuthenticateUser = $canAuthenticateUser; - $this->authenticatesUser = $authenticatesUser; - $this->authenticationRedirect = $authenticationRedirect; + $this->authenticationProcessor = $authenticationProcessor; } - /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\AccessUnauthorisedException + * @throws \App\Classes\Exceptions\InternalServerErrorException + * @throws \App\Classes\Exceptions\RequestValidationException */ protected function logic(Request $request): JsonResponse { - try { - $object = new AuthenticationCredentialsObject($request->input('email'), - $request->input('password'), $request->input('remember_me')); - - $this->canAuthenticateUser->passes($object); - - $token = $this->authenticatesUser->execute($object); - - return $this->response(['access_token' => $token, 'redirect_url' => $this->authenticationRedirect->url()]); - - } catch (\Exception $exception){ - dd($exception); - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - + return $this->response($this->authenticationProcessor->execute($request)); } } \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/CheckEmailLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/CheckEmailLogic.php index 76cdc888..b73b150a 100644 --- a/app/Classes/Modules/Accounts/ControllersLogic/CheckEmailLogic.php +++ b/app/Classes/Modules/Accounts/ControllersLogic/CheckEmailLogic.php @@ -2,18 +2,13 @@ namespace App\Classes\Modules\Accounts\ControllersLogic; -use App\Classes\Modules\Accounts\DataTransferObjects\AuthenticationCredentialsObject; -use App\Classes\Modules\Accounts\Services\AuthenticatesUser; -use App\Classes\Modules\Accounts\Services\AuthenticationRedirect; use App\Classes\Modules\Accounts\Services\FetchesUser; -use App\Classes\Modules\Accounts\Standards\Rules\CanAuthenticateUser; -use App\Classes\General\Abstracts\AbstractControllersLogic; -use App\Classes\ValueObjects\Constants\Notifications; +use App\Classes\General\Abstracts\AbstractControllerLogic; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class CheckEmailLogic extends AbstractControllersLogic +class CheckEmailLogic extends AbstractControllerLogic { protected function notification():array { diff --git a/app/Classes/Modules/Accounts/ControllersLogic/CreateCustomerLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/CreateCustomerLogic.php new file mode 100644 index 00000000..b1fc4285 --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllersLogic/CreateCustomerLogic.php @@ -0,0 +1,108 @@ + 'Created User', + 'message' => 'You have successfully created a new User' + ]; + } + + /** @var CreateUserProcessor */ + private $createUserProcessor; + + /** @var CreateCompanyProcessor */ + private $createCompanyProcessor; + + /** @var CreateContactProcessor */ + private $createContactProcessor; + + /** @var AssignEmployeeProcessor */ + private $assignEmployeeProcessor; + + /** @var AssignSegmentProcessor */ + private $assignSegmentProcessor; + + /** @var AuthenticationProcessor */ + private $authenticationProcessor; + + /** @var GenerateEmailVerificationAttemptProcessor */ + private $generateEmailVerificationAttemptProcessor; + + /** + * CreateCustomerLogic constructor. + * @param CreateUserProcessor $createUserProcessor + * @param CreateCompanyProcessor $createCompanyProcessor + * @param CreateContactProcessor $createContactProcessor + * @param AssignEmployeeProcessor $assignEmployeeProcessor + * @param AssignSegmentProcessor $assignSegmentProcessor + * @param AuthenticationProcessor $authenticationProcessor + * @param GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor + */ + public function __construct(CreateUserProcessor $createUserProcessor, CreateCompanyProcessor $createCompanyProcessor, CreateContactProcessor $createContactProcessor, AssignEmployeeProcessor $assignEmployeeProcessor, AssignSegmentProcessor $assignSegmentProcessor, AuthenticationProcessor $authenticationProcessor, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor) + { + $this->createUserProcessor = $createUserProcessor; + $this->createCompanyProcessor = $createCompanyProcessor; + $this->createContactProcessor = $createContactProcessor; + $this->assignEmployeeProcessor = $assignEmployeeProcessor; + $this->assignSegmentProcessor = $assignSegmentProcessor; + $this->authenticationProcessor = $authenticationProcessor; + $this->generateEmailVerificationAttemptProcessor = $generateEmailVerificationAttemptProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\AccessUnauthorisedException + * @throws \App\Classes\Exceptions\InternalServerErrorException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + /** @var User $user */ + $user = $this->createUserProcessor->execute($request, RoleTypes::USER, App::environment(['local', 'staging']) ? ApprovalStatus::APPROVED : ApprovalStatus::PENDING_VERIFICATION); + + /** @var Company $company */ + $company = $this->createCompanyProcessor->execute($request, BusinessType::IMPORTER, $request->input('type'), ApprovalStatus::PENDING_SUBMISSION); + + $this->createContactProcessor->execute($request, $company); + + $Object = new EmploymentObject($company, $user); + $this->assignEmployeeProcessor->execute($Object); + + $this->assignSegmentProcessor->execute($company); + + $this->generateEmailVerificationAttemptProcessor->execute($user); + + return $this->response($this->authenticationProcessor->execute($request)); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/CreateUserLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/CreateUserLogic.php deleted file mode 100644 index 55b5152c..00000000 --- a/app/Classes/Modules/Accounts/ControllersLogic/CreateUserLogic.php +++ /dev/null @@ -1,184 +0,0 @@ - 'Created User', - 'message' => 'You have successfully created a new User' - ]; - } - - /** @var CanCreateUser */ - private $canCreateUser; - - /** @var CreatesUser */ - private $createsUser; - - /** @var CanCreateCompany */ - private $canCreateCompany; - - /** @var CreatesCompany */ - private $createsCompany; - - /** @var CanCreateContact */ - private $canCreateContact; - - /** @var CreatesContact */ - private $createsContact; - - /** @var CanCreateCompanyEmployee */ - private $canCreateCompanyEmployee; - - /** @var CreatesCompanyEmployee */ - private $createsCompanyEmployee; - - /** @var CanCreateSegmentCompany */ - private $canCreateSegmentCompany; - - /** @var CreatesSegmentCompany */ - private $createsSegmentCompany; - - - /** - * CreateUserLogic constructor. - * @param CanCreateUser $canCreateUser - * @param CreatesUser $createsUser - * @param CanCreateCompany $canCreateCompany - * @param CreatesCompany $createsCompany - * @param CanCreateContact $canCreateContact - * @param CreatesContact $createsContact - * @param CanCreateCompanyEmployee $canCreateCompanyEmployee - * @param CreatesCompanyEmployee $createsCompanyEmployee - * @param CanCreateSegmentCompany $canCreateSegmentCompany - * @param CreatesSegmentCompany $createsSegmentCompany - */ - public function __construct( - CanCreateUser $canCreateUser, - CreatesUser $createsUser, - CanCreateCompany $canCreateCompany, - CreatesCompany $createsCompany, - CanCreateContact $canCreateContact, - CreatesContact $createsContact, - CanCreateCompanyEmployee $canCreateCompanyEmployee, - CreatesCompanyEmployee $createsCompanyEmployee, - CanCreateSegmentCompany $canCreateSegmentCompany, - CreatesSegmentCompany $createsSegmentCompany - ) - { - $this->canCreateUser = $canCreateUser; - $this->createsUser = $createsUser; - $this->canCreateCompany = $canCreateCompany; - $this->createsCompany = $createsCompany; - $this->canCreateContact = $canCreateContact; - $this->createsContact = $createsContact; - $this->canCreateCompanyEmployee = $canCreateCompanyEmployee; - $this->createsCompanyEmployee = $createsCompanyEmployee; - $this->canCreateSegmentCompany = $canCreateSegmentCompany; - $this->createsSegmentCompany = $createsSegmentCompany; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $user_object = new UserObject( - $request->input('name'), - $request->input('email'), - $request->input('password'), - $request->input('password_confirmation'), - 2, - 9 - ); - - $this->canCreateUser->passes($user_object); - $user_query = $this->createsUser->execute($user_object); - - $company_object = new CompanyObject( - $request->input('company_name'), - $request->input('company_reference'), - null - ); - - $this->canCreateCompany->passes($company_object); - $company_query = $this->createsCompany->execute($company_object); - - $contact_object = new ContactObject( - 1, - $company_query->id, - $request->input('contact_reference'), - $request->input('phone'), - $request->input('contact_email'), - $request->input('wechat_id') - ); - - $this->canCreateContact->passes($contact_object); - $contact_query = $this->createsContact->execute($contact_object); - - $company_employee_object = new CompanyEmployeeObject( - $company_query->id, - $user_query->id - ); - - $this->canCreateCompanyEmployee->passes($company_employee_object); - $company_employee_query = $this->createsCompanyEmployee->execute($user_query, $company_employee_object); - - - $segment_company_object = new SegmentCompanyObject( - 1, - $company_query->id - ); - - $this->canCreateSegmentCompany->passes($segment_company_object); - $segment_company_query = $this->createsSegmentCompany->execute($company_query, $segment_company_object); - - DB::commit(); - - return $this->resourceResponse(new UserResource($user_query)); - - } catch (\Exception $exception) { - dd($exception); - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - - } -} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/FetchUserLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/FetchUserLogic.php new file mode 100644 index 00000000..eafd55a3 --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllersLogic/FetchUserLogic.php @@ -0,0 +1,64 @@ + 'Fetch Users', + 'message' => 'You have successfully retrieved the user' + ]; + } + + /** @var CanFetchUser */ + private $canFetchUser; + + /** @var FetchesUser */ + private $fetchessUser; + + /** + * FetchUserLogic constructor. + * @param CanFetchUser $canFetchUser + * @param FetchesUser $fetchessUser + */ + public function __construct(CanFetchUser $canFetchUser, FetchesUser $fetchessUser) + { + $this->canFetchUser = $canFetchUser; + $this->fetchessUser = $fetchessUser; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + $this->canFetchUser->passes(); + + $query = $this->fetchessUser->execute(['id' => $request->input('user_id')]); + + return $this->collectionResponse(UserResource::collection($query)); + + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/GeneratePasswordResetLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/GeneratePasswordResetLogic.php new file mode 100644 index 00000000..36b560a6 --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllersLogic/GeneratePasswordResetLogic.php @@ -0,0 +1,86 @@ + 'Reset Password', + 'message' => 'You have successfully sent you an email to reset your password' + ]; + } + + + /** @var CanGeneratePasswordReset */ + private $canGeneratePasswordReset; + + /** @var FetchesUser */ + private $fetchesUser; + + /** @var GeneratesPasswordReset */ + private $generatesPasswordReset; + + /** @var PasswordResetTokenExpiration */ + private $passwordResetTokenExpiration; + + /** @var SendResetPasswordEmail */ + private $sendResetPasswordEmail; + + /** + * GeneratePasswordResetLogic constructor. + * @param CanGeneratePasswordReset $canGeneratePasswordReset + * @param FetchesUser $fetchesUser + * @param GeneratesPasswordReset $generatesPasswordReset + * @param PasswordResetTokenExpiration $passwordResetTokenExpiration + * @param SendResetPasswordEmail $sendResetPasswordEmail + */ + public function __construct(CanGeneratePasswordReset $canGeneratePasswordReset, FetchesUser $fetchesUser, GeneratesPasswordReset $generatesPasswordReset, PasswordResetTokenExpiration $passwordResetTokenExpiration, SendResetPasswordEmail $sendResetPasswordEmail) + { + $this->canGeneratePasswordReset = $canGeneratePasswordReset; + $this->fetchesUser = $fetchesUser; + $this->generatesPasswordReset = $generatesPasswordReset; + $this->passwordResetTokenExpiration = $passwordResetTokenExpiration; + $this->sendResetPasswordEmail = $sendResetPasswordEmail; + } + + + /** + * @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 GeneratePasswordResetObject($request->input('email')); + + if($this->canGeneratePasswordReset->passes($object)) { + $user = $this->fetchesUser->execute(['email' => $object->getEmail()]); + + $attempt = $this->generatesPasswordReset->execute($user); + + $this->passwordResetTokenExpiration::dispatch($attempt)->delay(now()->addHours(24)); + $this->sendResetPasswordEmail::dispatch($user, $attempt); + + return $this->response(['email' => $object->getEmail()]); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/ListUsersLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/ListUsersLogic.php index 8796765f..626876bc 100644 --- a/app/Classes/Modules/Accounts/ControllersLogic/ListUsersLogic.php +++ b/app/Classes/Modules/Accounts/ControllersLogic/ListUsersLogic.php @@ -4,13 +4,13 @@ namespace App\Classes\Modules\Accounts\ControllersLogic; use App\Classes\Modules\Accounts\Services\ListsUsers; use App\Classes\Modules\Accounts\Standards\Rules\CanListUsers; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Http\Resources\UserResource; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class ListUsersLogic extends AbstractControllersLogic +class ListUsersLogic extends AbstractControllerLogic { /** @@ -24,19 +24,19 @@ class ListUsersLogic extends AbstractControllersLogic } /** @var CanListUsers */ - private $canListUser; + private $canListUsers; /** @var ListsUsers */ private $listsUsers; /** - * ListUsersControllersLogic constructor. - * @param CanListUsers $canListUser + * ListUsersLogic constructor. + * @param CanListUsers $canListUsers * @param ListsUsers $listsUsers */ - public function __construct(CanListUsers $canListUser, ListsUsers $listsUsers) + public function __construct(CanListUsers $canListUsers, ListsUsers $listsUsers) { - $this->canListUser = $canListUser; + $this->canListUsers = $canListUsers; $this->listsUsers = $listsUsers; } @@ -44,22 +44,17 @@ class ListUsersLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { + $this->canListUsers->passes(); - $this->canListUser->passes(); + $query = $this->listsUsers->execute($this->listsUsers->deserializeFilters($request->input('filters'))); - $query = $this->listsUsers->execute($this->listsUsers->deserializeFilters($request->input('filters'))); - - return $this->collectionResponse(UserResource::collection($query)); - - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->collectionResponse(UserResource::collection($query)); } } \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/LogoutUserLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/LogoutUserLogic.php new file mode 100644 index 00000000..fed6e182 --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllersLogic/LogoutUserLogic.php @@ -0,0 +1,44 @@ + 'Logout', + 'message' => 'You have successfully logged out of your account' + ]; + } + + /** @var InvalidatesAuthenticationToken */ + private $invalidatesAuthenticationToken; + + /** + * LogoutUserLogic constructor. + * @param InvalidatesAuthenticationToken $invalidatesAuthenticationToken + */ + public function __construct(InvalidatesAuthenticationToken $invalidatesAuthenticationToken) + { + $this->invalidatesAuthenticationToken = $invalidatesAuthenticationToken; + } + + /** + * @param Request $request + * @return JsonResponse + */ + protected function logic(Request $request): JsonResponse { + + $this->invalidatesAuthenticationToken->execute(); + + return $this->response(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/RefreshAuthenticationTokenLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/RefreshAuthenticationTokenLogic.php new file mode 100644 index 00000000..9e4c5519 --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllersLogic/RefreshAuthenticationTokenLogic.php @@ -0,0 +1,47 @@ + 'Refresh Authentication', + 'message' => 'You have successfully your account authentication' + ]; + } + + /** @var RefreshAuthenticationTokenProcessor */ + private $refreshAuthenticationTokenProcessor; + + /** + * RefreshAuthenticationTokenLogic constructor. + * @param RefreshAuthenticationTokenProcessor $refreshAuthenticationTokenProcessor + */ + public function __construct(RefreshAuthenticationTokenProcessor $refreshAuthenticationTokenProcessor) + { + $this->refreshAuthenticationTokenProcessor = $refreshAuthenticationTokenProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\InternalServerErrorException + */ + protected function logic(Request $request): JsonResponse { + + /** @var User $user */ + $user = Auth()->user(); + + return $this->response($this->refreshAuthenticationTokenProcessor->execute($user)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/RegistrationStep2Logic.php b/app/Classes/Modules/Accounts/ControllersLogic/RegistrationStep2Logic.php deleted file mode 100644 index 3bd510c7..00000000 --- a/app/Classes/Modules/Accounts/ControllersLogic/RegistrationStep2Logic.php +++ /dev/null @@ -1,159 +0,0 @@ - 'Registration Step 2', - 'message' => 'You have completed registration step 2' - ]; - } - - /** @var FetchesUser */ - private $fetchesUser; - - /** @var CanUpdateCompany */ - private $canUpdateCompany; - - /** @var UpdatesCompany */ - private $updatesCompany; - - /** @var CanCreateDocument */ - private $canCreateDocument; - - /** @var CreatesDocument */ - private $createsDocument; - - /** @var CanCreateFile */ - private $canCreateFIle; - - /** @var CreatesFile */ - private $createsFile; - - /** @var Convert64ToFile */ - private $convert64ToFile; - - - /** - * RegistrationStep2Logic constructor. - * @param FetchesUser $fetchesUser - * @param CanUpdateCompany $canUpdateCompany - * @param UpdatesCompany $updatesCompany - * @param CanCreateDocument $canCreateDocument - * @param CreatesDocument $createsDocument - * @param CanCreateFile $canCreateFile - * @param CreatesFile $createsFile - * @param Convert64ToFile $convert64ToFile - */ - public function __construct( - FetchesUser $fetchesUser, - CanUpdateCompany $canUpdateCompany, - UpdatesCompany $updatesCompany, - CanCreateDocument $canCreateDocument, - CreatesDocument $createsDocument, - CanCreateFile $canCreateFile, - CreatesFile $createsFile, - Convert64ToFile $convert64ToFile - ) - { - $this->fetchesUser = $fetchesUser; - $this->canUpdateCompany = $canUpdateCompany; - $this->updatesCompany = $updatesCompany; - $this->canCreateDocument = $canCreateDocument; - $this->createsDocument = $createsDocument; - $this->canCreateFile = $canCreateFile; - $this->createsFile = $createsFile; - $this->convert64ToFile = $convert64ToFile; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $user_query = $this->fetchesUser->execute(['id' => \Auth::user()->id]); - $company_query = $user_query->company()->first(); - - $company_object = new CompanyObject( - $request->input('company_name', $company_query->name), - $request->input('company_reference', $company_query->refence), - $request->input('type', $company_query->type) - ); - $this->canUpdateCompany->passes($company_object); - $company_query = $this->updatesCompany->execute($company_query, $company_object); - - $document_type = $company_query->type == 1 ? DocumentType::COMPANY_PUBLIC_SMS_REGISTER : DocumentType::COMPANY_PERSONAL_IC; - $document_object = new DocumentObject( - $user_query->id, - OwnerType::COMPANY, - $document_type, - $request->input('document_reference'), - ObjectStatus::PENDING, - null, - null, - null, - null - ); - $this->canCreateDocument->passes($document_object); - $document_query = $this->createsDocument->execute($document_object); - - $file = $this->convert64ToFile->convert($request->input('file')); - $file_type = $company_query->type == 1 ? FileType::COMPANY_PUBLIC_SMS_REGISTER : FileType::COMPANY_PERSONAL_IC; - - $file_object = new FileObject( - $document_query->id, - !empty($file[0]) ? json_encode($file[0]) : null, - $file_type - ); - $this->canCreateFile->passes($file_object); - $file_query = $this->createsFile->execute($file_object); - - DB::commit(); - - return $this->resourceResponse(new UserResource(\Auth::user())); - - } catch (\Exception $exception) { - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - - } -} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/ResendEmailVerificationLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/ResendEmailVerificationLogic.php new file mode 100644 index 00000000..1723b370 --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllersLogic/ResendEmailVerificationLogic.php @@ -0,0 +1,51 @@ + 'Resend Verification Email', + 'message' => 'Successfully resent a new verification email' + ]; + } + + /** @var FetchesUser */ + private $fetchesUser; + + /** @var GenerateEmailVerificationAttemptProcessor */ + private $generateEmailVerificationAttemptProcessor; + + /** + * ResendEmailVerificationLogic constructor. + * @param FetchesUser $fetchesUser + * @param GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor + */ + public function __construct(FetchesUser $fetchesUser, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor) + { + $this->fetchesUser = $fetchesUser; + $this->generateEmailVerificationAttemptProcessor = $generateEmailVerificationAttemptProcessor; + } + + public function logic(Request $request) : JsonResponse { + + /** @var User $user */ + $user = $this->fetchesUser->execute(['id' => $request->input('user_id')]); + + $this->generateEmailVerificationAttemptProcessor->execute($user); + + return $this->response([]); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/ResetPasswordLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/ResetPasswordLogic.php new file mode 100644 index 00000000..1058286c --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllersLogic/ResetPasswordLogic.php @@ -0,0 +1,80 @@ + 'Password Change', + 'message' => 'You have successfully changed your account\'t password' + ]; + } + + /** @var CanResetPassword */ + private $canResetPassword; + + /** @var FetchesPasswordReset */ + private $fetchesPasswordReset; + + /** @var ChangesPassword */ + private $changePassword; + + /** @var CompletesPasswordReset */ + private $completesPasswordResetToken; + + /** + * ResetPasswordLogic constructor. + * @param CanResetPassword $canResetPassword + * @param FetchesPasswordReset $fetchesPasswordReset + * @param ChangesPassword $changePassword + * @param CompletesPasswordReset $completesPasswordResetToken + */ + public function __construct(CanResetPassword $canResetPassword, FetchesPasswordReset $fetchesPasswordReset, ChangesPassword $changePassword, CompletesPasswordReset $completesPasswordResetToken) + { + $this->canResetPassword = $canResetPassword; + $this->fetchesPasswordReset = $fetchesPasswordReset; + $this->changePassword = $changePassword; + $this->completesPasswordResetToken = $completesPasswordResetToken; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\InternalServerErrorException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request): JsonResponse { + + $object = new PasswordResetObject($request->input('token'), + new NewPasswordObject($request->input('password'), $request->input('confirmPassword'))); + + $this->canResetPassword->passes($object); + + /** @var PasswordReset $passwordReset */ + $passwordReset = $this->fetchesPasswordReset->execute(['token' => $object->getToken(), 'with_user']); + $this->changePassword->execute($passwordReset->user, $object->getNewPassword()); + $this->completesPasswordResetToken->execute($passwordReset); + + return $this->response(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/UpdateUserLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/UpdateUserLogic.php deleted file mode 100644 index 368f34ce..00000000 --- a/app/Classes/Modules/Accounts/ControllersLogic/UpdateUserLogic.php +++ /dev/null @@ -1,159 +0,0 @@ - 'Update User', - 'message' => 'You have successfully update a user' - ]; - } - - /** @var FetchesUser */ - private $fetchesUser; - - /** @var CanUpdateCompany */ - private $canUpdateCompany; - - /** @var UpdatesCompany */ - private $updatesCompany; - - /** @var CanCreateDocument */ - private $canCreateDocument; - - /** @var CreatesDocument */ - private $createsDocument; - - /** @var CanCreateFile */ - private $canCreateFIle; - - /** @var CreatesFile */ - private $createsFile; - - /** @var Convert64ToFile */ - private $convert64ToFile; - - - /** - * UpdateUserLogic constructor. - * @param FetchesUser $fetchesUser - * @param CanUpdateCompany $canUpdateCompany - * @param UpdatesCompany $updatesCompany - * @param CanCreateDocument $canCreateDocument - * @param CreatesDocument $createsDocument - * @param CanCreateFile $canCreateFile - * @param CreatesFile $createsFile - * @param Convert64ToFile $convert64ToFile - */ - public function __construct( - FetchesUser $fetchesUser, - CanUpdateCompany $canUpdateCompany, - UpdatesCompany $updatesCompany, - CanCreateDocument $canCreateDocument, - CreatesDocument $createsDocument, - CanCreateFile $canCreateFile, - CreatesFile $createsFile, - Convert64ToFile $convert64ToFile - ) - { - $this->fetchesUser = $fetchesUser; - $this->canUpdateCompany = $canUpdateCompany; - $this->updatesCompany = $updatesCompany; - $this->canCreateDocument = $canCreateDocument; - $this->createsDocument = $createsDocument; - $this->canCreateFile = $canCreateFile; - $this->createsFile = $createsFile; - $this->convert64ToFile = $convert64ToFile; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $user_query = $this->fetchesUser->execute(['id' => \Auth::user()->id]); - $company_query = $user_query->company()->first(); - - $company_object = new CompanyObject( - $request->input('company_name', $company_query->name), - $request->input('company_reference', $company_query->refence), - $request->input('type', $company_query->type) - ); - $this->canUpdateCompany->passes($company_object); - $company_query = $this->updatesCompany->execute($company_query, $company_object); - - $document_type = $company_query->type == 1 ? DocumentType::COMPANY_PUBLIC_SMS_REGISTER : DocumentType::COMPANY_PERSONAL_IC; - $document_object = new DocumentObject( - $user_query->id, - OwnerType::COMPANY, - $document_type, - $request->input('document_reference'), - ObjectStatus::PENDING, - null, - null, - null, - null - ); - $this->canCreateDocument->passes($document_object); - $document_query = $this->createsDocument->execute($document_object); - - $file = $this->convert64ToFile->convert($request->input('file')); - $file_type = $company_query->type == 1 ? FileType::COMPANY_PUBLIC_SMS_REGISTER : FileType::COMPANY_PERSONAL_IC; - - $file_object = new FileObject( - $document_query->id, - !empty($file[0]) ? json_encode($file[0]) : null, - $file_type - ); - $this->canCreateFile->passes($file_object); - $file_query = $this->createsFile->execute($file_object); - - DB::commit(); - - return $this->resourceResponse(new UserResource(\Auth::user())); - - } catch (\Exception $exception) { - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - - } -} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllersLogic/UserEmailVerificationLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/UserEmailVerificationLogic.php new file mode 100644 index 00000000..bae6f5eb --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllersLogic/UserEmailVerificationLogic.php @@ -0,0 +1,76 @@ + 'Email Verification', + 'message' => 'You have successfully verified your email address' + ]; + } + + /** @var emailVerificationActiveAttemptExists */ + private $emailVerificationActiveAttemptExists; + + /** @var CompletesEmailVerificationAttempt */ + private $completesEmailVerificationAttempt; + + /** @var FetchesEmailVerificationAttempt */ + private $fetchesEmailVerificationAttempt; + + /** @var VerifiesUser */ + private $verifiesUser; + + /** + * UserEmailVerificationLogic constructor. + * @param EmailVerificationActiveAttemptExists $emailVerificationActiveAttemptExists + * @param CompletesEmailVerificationAttempt $completesEmailVerificationAttempt + * @param FetchesEmailVerificationAttempt $fetchesEmailVerificationAttempt + * @param VerifiesUser $verifiesUser + */ + public function __construct(EmailVerificationActiveAttemptExists $emailVerificationActiveAttemptExists, CompletesEmailVerificationAttempt $completesEmailVerificationAttempt, FetchesEmailVerificationAttempt $fetchesEmailVerificationAttempt, VerifiesUser $verifiesUser) + { + $this->emailVerificationActiveAttemptExists = $emailVerificationActiveAttemptExists; + $this->completesEmailVerificationAttempt = $completesEmailVerificationAttempt; + $this->fetchesEmailVerificationAttempt = $fetchesEmailVerificationAttempt; + $this->verifiesUser = $verifiesUser; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws MalformedRequestException + * @throws ResourceNotFoundException + */ + public function logic(Request $request) : JsonResponse { + + $token = $request->input('token'); + + $this->emailVerificationActiveAttemptExists->execute($token); + + /** @var UserEmailVerification $attempt */ + $attempt = $this->fetchesEmailVerificationAttempt->execute(['token' => $token]); + + $this->completesEmailVerificationAttempt->execute($attempt); + + $this->verifiesUser->execute($attempt->user); + + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/DataTransferObjects/AuthenticationCredentialsObject.php b/app/Classes/Modules/Accounts/DataTransferObjects/AuthenticationCredentialsObject.php index 7db93777..528ea709 100644 --- a/app/Classes/Modules/Accounts/DataTransferObjects/AuthenticationCredentialsObject.php +++ b/app/Classes/Modules/Accounts/DataTransferObjects/AuthenticationCredentialsObject.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Accounts\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; class AuthenticationCredentialsObject implements DataTransferObject { diff --git a/app/Classes/Modules/Accounts/DataTransferObjects/GeneratePasswordResetObject.php b/app/Classes/Modules/Accounts/DataTransferObjects/GeneratePasswordResetObject.php new file mode 100644 index 00000000..0051577e --- /dev/null +++ b/app/Classes/Modules/Accounts/DataTransferObjects/GeneratePasswordResetObject.php @@ -0,0 +1,34 @@ +email = $email; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/DataTransferObjects/NewPasswordObject.php b/app/Classes/Modules/Accounts/DataTransferObjects/NewPasswordObject.php new file mode 100644 index 00000000..cc3c83e1 --- /dev/null +++ b/app/Classes/Modules/Accounts/DataTransferObjects/NewPasswordObject.php @@ -0,0 +1,45 @@ +password = $password; + $this->ConfirmPassword = $ConfirmPassword; + } + + /** + * @return String + */ + public function getPassword(): String + { + return $this->password; + } + + /** + * @return String + */ + public function getConfirmPassword(): String + { + return $this->ConfirmPassword; + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/DataTransferObjects/PasswordResetObject.php b/app/Classes/Modules/Accounts/DataTransferObjects/PasswordResetObject.php new file mode 100644 index 00000000..93b6b559 --- /dev/null +++ b/app/Classes/Modules/Accounts/DataTransferObjects/PasswordResetObject.php @@ -0,0 +1,44 @@ +token = $token; + $this->newPassword = $newPassword; + } + + /** + * @return String + */ + public function getToken(): String + { + return $this->token; + } + + /** + * @return NewPasswordObject + */ + public function getNewPassword(): NewPasswordObject + { + return $this->newPassword; + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/DataTransferObjects/RegistrationObject.php b/app/Classes/Modules/Accounts/DataTransferObjects/RegistrationObject.php new file mode 100644 index 00000000..533979b0 --- /dev/null +++ b/app/Classes/Modules/Accounts/DataTransferObjects/RegistrationObject.php @@ -0,0 +1,99 @@ +name = $name; + $this->email = $email; + $this->password = $password; + $this->passwordConfirmation = $passwordConfirmation; + $this->type = $type; + $this->status = $status; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @return string + */ + public function getPassword(): string + { + return $this->password; + } + + /** + * @return string + */ + public function getPasswordConfirmation(): string + { + return $this->passwordConfirmation; + } + + /** + * @return int + */ + public function getType(): int + { + return $this->type; + } + + /** + * @return int + */ + public function getStatus(): int + { + return $this->status; + } + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/DataTransferObjects/UserObject.php b/app/Classes/Modules/Accounts/DataTransferObjects/UserObject.php deleted file mode 100644 index 36a6d40a..00000000 --- a/app/Classes/Modules/Accounts/DataTransferObjects/UserObject.php +++ /dev/null @@ -1,100 +0,0 @@ -name = $name; - $this->email = $email; - $this->password = $password; - $this->password_confirmation = $password_confirmation; - $this->type = $type; - $this->status = $status; - } - - /** - * @return string - */ - public function getName(): ?string - { - return $this->name; - } - - /** - * @return string - */ - public function getEmail(): ?string - { - return $this->email; - } - - /** - * @return string - */ - public function getPassword(): ?string - { - return $this->password; - } - - /** - * @return string - */ - public function getPasswordConfirmation(): ?string - { - return $this->password_confirmation; - } - - /** - * @return int - */ - public function getType(): int - { - return $this->type; - } - - /** - * @return int - */ - public function getStatus(): int - { - return $this->status; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Processors/AuthenticationProcessor.php b/app/Classes/Modules/Accounts/Processors/AuthenticationProcessor.php new file mode 100644 index 00000000..7b55a39f --- /dev/null +++ b/app/Classes/Modules/Accounts/Processors/AuthenticationProcessor.php @@ -0,0 +1,71 @@ +canAuthenticateUser = $canAuthenticateUser; + $this->authenticatesUser = $authenticatesUser; + $this->generatesAuthenticationToken = $generatesAuthenticationToken; + $this->fetchesUser = $fetchesUser; + $this->authenticationRedirect = $authenticationRedirect; + } + + + /** + * @param Request $request + * @return array + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\AccessUnauthorisedException + * @throws \App\Classes\Exceptions\InternalServerErrorException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function execute(Request $request): array { + + $object = new AuthenticationCredentialsObject($request->input('email'), $request->input('password')); + + $this->canAuthenticateUser->passes($object); + + $this->authenticatesUser->execute($object); + + $user = $this->fetchesUser->execute(['email' => $object->getEmail()]); + + return ['access_token' => $this->generatesAuthenticationToken->execute($user), 'redirect_url' => $this->authenticationRedirect->url($user)]; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Processors/CreateUserProcessor.php b/app/Classes/Modules/Accounts/Processors/CreateUserProcessor.php new file mode 100644 index 00000000..1b4d2b64 --- /dev/null +++ b/app/Classes/Modules/Accounts/Processors/CreateUserProcessor.php @@ -0,0 +1,55 @@ +canRegisterUser = $canRegisterUser; + $this->createsUser = $createsUser; + } + + + /** + * @param Request $request + * @param $roleType + * @param $status + * @return Model + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function execute(Request $request, $roleType, $status): Model { + + $userObject = new RegistrationObject($request->input('name'), $request->input('email'), + $request->input('password'), $request->input('password_confirmation'), + $roleType, $status); + + $this->canRegisterUser->passes($userObject); + + /** @var User $user_query */ + return $this->createsUser->execute($userObject); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php b/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php new file mode 100644 index 00000000..23853f27 --- /dev/null +++ b/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php @@ -0,0 +1,59 @@ +invalidatesActiveEmailVerificationAttempts = $invalidatesActiveEmailVerificationAttempts; + $this->generatesEmailVerificationAttempt = $generatesEmailVerificationAttempt; + $this->emailVerificationAttemptExpiration = $emailVerificationAttemptExpiration; + $this->sendUserVerificationEmail = $sendUserVerificationEmail; + } + + + /** + * @param User $user + * @return void + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(User $user) { + + $this->invalidatesActiveEmailVerificationAttempts->execute($user); + + $attempt = $this->generatesEmailVerificationAttempt->execute($user); + + $this->emailVerificationAttemptExpiration::dispatch($attempt)->delay(now()->addHours(48)); + + $this->sendUserVerificationEmail::dispatch($user, $attempt); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Processors/RefreshAuthenticationTokenProcessor.php b/app/Classes/Modules/Accounts/Processors/RefreshAuthenticationTokenProcessor.php new file mode 100644 index 00000000..288fcb1c --- /dev/null +++ b/app/Classes/Modules/Accounts/Processors/RefreshAuthenticationTokenProcessor.php @@ -0,0 +1,43 @@ +invalidatesAuthenticationToken = $invalidatesAuthenticationToken; + $this->generatesAuthenticationToken = $generatesAuthenticationToken; + } + + + /** + * @param User $user + * @return array + * @throws \App\Classes\Exceptions\InternalServerErrorException + */ + public function execute(User $user): array { + + $this->invalidatesAuthenticationToken->execute(); + + return ['refresh_token' => $this->generatesAuthenticationToken->execute($user)]; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/AuthenticatesUser.php b/app/Classes/Modules/Accounts/Services/AuthenticatesUser.php index 40a89cce..3f4e69cd 100644 --- a/app/Classes/Modules/Accounts/Services/AuthenticatesUser.php +++ b/app/Classes/Modules/Accounts/Services/AuthenticatesUser.php @@ -5,8 +5,6 @@ namespace App\Classes\Modules\Accounts\Services; use App\Classes\Exceptions\AccessUnauthorisedException; use App\Classes\Modules\Accounts\DataTransferObjects\AuthenticationCredentialsObject; -use Tymon\JWTAuth\Facades\JWTAuth; - class AuthenticatesUser { @@ -17,11 +15,12 @@ class AuthenticatesUser */ public function execute(AuthenticationCredentialsObject $object){ - if (! $token = JWTAuth::attempt(['email' => $object->getEmail(), 'password' => $object->getPassword()])) { + if (! auth()->validate(['email' => $object->getEmail(), 'password' => $object->getPassword()])) { throw new AccessUnauthorisedException('These credentials do not match our records.'); } - return $token; + return true; + } } \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/AuthenticationRedirect.php b/app/Classes/Modules/Accounts/Services/AuthenticationRedirect.php index 5b7e964f..b359108d 100644 --- a/app/Classes/Modules/Accounts/Services/AuthenticationRedirect.php +++ b/app/Classes/Modules/Accounts/Services/AuthenticationRedirect.php @@ -2,18 +2,19 @@ namespace App\Classes\Modules\Accounts\Services; -use App\Classes\ValueObjects\Constants\Roles; +use App\Classes\ValueObjects\Constants\RoleTypes; +use App\Models\User; class AuthenticationRedirect { - public function url(){ + public function url(User $user){ - if(\Auth::user()->hasRole('Shadow Admin') || \Auth::user()->hasRole('Ultimate Admin')){ - return route('dashboard.forwarder'); + if($user->type === RoleTypes::USER){ + return route('dashboard'); } - // return route('dashboard.importer', ['id' => Auth()->user()->employers->first()->company->id]); + return route('dashboard'); } } \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/ChangesPassword.php b/app/Classes/Modules/Accounts/Services/ChangesPassword.php new file mode 100644 index 00000000..f22334ca --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/ChangesPassword.php @@ -0,0 +1,32 @@ +password = Hash::make($object->getPassword()); + return $user->save(); + + } catch (QueryException $exception){ + throw new InternalServerErrorException($exception->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/CompletesEmailVerificationAttempt.php b/app/Classes/Modules/Accounts/Services/CompletesEmailVerificationAttempt.php new file mode 100644 index 00000000..bba1705f --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/CompletesEmailVerificationAttempt.php @@ -0,0 +1,24 @@ +is_complete = true; + return $this->handler($model); + } + +} diff --git a/app/Classes/Modules/Accounts/Services/CompletesPasswordReset.php b/app/Classes/Modules/Accounts/Services/CompletesPasswordReset.php new file mode 100644 index 00000000..b733fe81 --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/CompletesPasswordReset.php @@ -0,0 +1,26 @@ +is_complete = true; + return $this->handler($model); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/CreatesUser.php b/app/Classes/Modules/Accounts/Services/CreatesUser.php index c14ac186..2dba3898 100644 --- a/app/Classes/Modules/Accounts/Services/CreatesUser.php +++ b/app/Classes/Modules/Accounts/Services/CreatesUser.php @@ -3,17 +3,18 @@ namespace App\Classes\Modules\Accounts\Services; use App\Classes\General\Eloquent\AbstractUpdateRecord; +use App\Classes\Modules\Accounts\DataTransferObjects\RegistrationObject; use App\Classes\Modules\Accounts\DataTransferObjects\UserObject; use App\Models\User; class CreatesUser extends AbstractUpdateRecord { /** - * @param UserObject $object + * @param RegistrationObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(UserObject $object) { + public function execute(RegistrationObject $object) { $model = new User(); $model->name = $object->getName(); $model->email = $object->getEmail(); diff --git a/app/Classes/Modules/Accounts/Services/ExpiresEmailVerificationAttempt.php b/app/Classes/Modules/Accounts/Services/ExpiresEmailVerificationAttempt.php new file mode 100644 index 00000000..ebce5271 --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/ExpiresEmailVerificationAttempt.php @@ -0,0 +1,29 @@ +is_active = false; + return $this->handler($model); + + + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/ExpiresPasswordReset.php b/app/Classes/Modules/Accounts/Services/ExpiresPasswordReset.php new file mode 100644 index 00000000..b8b27692 --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/ExpiresPasswordReset.php @@ -0,0 +1,28 @@ +is_expired = true; + return $this->handler($model); + + + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/FetchesEmailVerificationAttempt.php b/app/Classes/Modules/Accounts/Services/FetchesEmailVerificationAttempt.php new file mode 100644 index 00000000..ed835693 --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/FetchesEmailVerificationAttempt.php @@ -0,0 +1,35 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/FetchesPasswordReset.php b/app/Classes/Modules/Accounts/Services/FetchesPasswordReset.php new file mode 100644 index 00000000..2f0a18bc --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/FetchesPasswordReset.php @@ -0,0 +1,34 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/GeneratesAuthenticationToken.php b/app/Classes/Modules/Accounts/Services/GeneratesAuthenticationToken.php new file mode 100644 index 00000000..72296b97 --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/GeneratesAuthenticationToken.php @@ -0,0 +1,79 @@ +builder = $builder; + } + + + /** + * @param User $user + * @param bool $rememberUser + * @return string + */ + public function execute(User $user, bool $rememberUser = false): string { + + $this->builder->manager()->setBlacklistEnabled(false); + + // generate token for the customer + $this->builder->factory()->setTTL(Carbon::now()->addDay()->timestamp); + + if ($rememberUser === true) { + $this->builder->factory()->setTTL(Carbon::now()->addWeek()->timestamp); + } + + // set the claim based on the object + $this->setTokenClaims($user); + + return $this->builder->fromUser($user); + } + + + /** + * @param User $user + */ + private function setTokenClaims(User $user): void { + + /** @var Company $company */ + $company = $user->company()->first(); + + $claims = [ + 'id' => $user->id, + 'name' => $user->name, + 'email' => $user->email, + 'type' => $user->type, + 'status' => $user->status + ]; + + if($user->type === RoleTypes::USER) { + $claims = array_merge($claims, [ + 'company_id' => $company->id + ]); + } + + $this->builder->factory()->customClaims(['user' => $claims]); + + + $this->builder->factory()->buildClaimsCollection(); + + } +} diff --git a/app/Classes/Modules/Accounts/Services/GeneratesEmailVerificationAttempt.php b/app/Classes/Modules/Accounts/Services/GeneratesEmailVerificationAttempt.php new file mode 100644 index 00000000..215bc7ac --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/GeneratesEmailVerificationAttempt.php @@ -0,0 +1,32 @@ +token = Str::random(25); + $model->is_complete = false; + $model->is_active = true; + $model->is_sent = true; + + return $this->handler($user->emailVerification(), $model); + } + +} diff --git a/app/Classes/Modules/Accounts/Services/GeneratesPasswordReset.php b/app/Classes/Modules/Accounts/Services/GeneratesPasswordReset.php new file mode 100644 index 00000000..d57bd66a --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/GeneratesPasswordReset.php @@ -0,0 +1,30 @@ +token = Str::random(60); + $model->is_expired = false; + $model->is_complete = false; + + return $this->handler($user->passwordReset(), $model); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/InvalidatesActiveEmailVerificationAttempts.php b/app/Classes/Modules/Accounts/Services/InvalidatesActiveEmailVerificationAttempts.php new file mode 100644 index 00000000..21605bb9 --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/InvalidatesActiveEmailVerificationAttempts.php @@ -0,0 +1,22 @@ +emailVerification()->active()->update([ + 'is_active' => false + ]); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/InvalidatesAuthenticationToken.php b/app/Classes/Modules/Accounts/Services/InvalidatesAuthenticationToken.php new file mode 100644 index 00000000..e243e5d4 --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/InvalidatesAuthenticationToken.php @@ -0,0 +1,15 @@ +logout(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/VerifiesUser.php b/app/Classes/Modules/Accounts/Services/VerifiesUser.php new file mode 100644 index 00000000..6d9e296c --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/VerifiesUser.php @@ -0,0 +1,29 @@ +status = ApprovalStatus::APPROVED; + + return $this->handler($model); + + } + +} diff --git a/app/Classes/Modules/Accounts/Standards/Criteria/EmailVerificationActiveAttemptExists.php b/app/Classes/Modules/Accounts/Standards/Criteria/EmailVerificationActiveAttemptExists.php new file mode 100644 index 00000000..5df54812 --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Criteria/EmailVerificationActiveAttemptExists.php @@ -0,0 +1,40 @@ +repository = $repository; + } + + + /** + * @param string $token + * @return bool + * @throws ResourceNotFoundException + */ + public function execute(string $token){ + + if(!$this->repository->active()->where('token', $token)->first()){ + throw new ResourceNotFoundException('The email verification token has expired or doesn\'t exist'); + } + + return true; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Criteria/PasswordResetTokenExists.php b/app/Classes/Modules/Accounts/Standards/Criteria/PasswordResetTokenExists.php new file mode 100644 index 00000000..2ba48718 --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Criteria/PasswordResetTokenExists.php @@ -0,0 +1,39 @@ +repository = $repository; + } + + + /** + * @param string $token + * @return bool + * @throws ResourceNotFoundException + */ + public function execute(string $token){ + + if(!$this->repository->active()->where('token', $token)->first()){ + throw new ResourceNotFoundException('The reset password token has expired or doesn\'t exist'); + } + return true; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Criteria/UnverifiedUserEmail.php b/app/Classes/Modules/Accounts/Standards/Criteria/UnverifiedUserEmail.php new file mode 100644 index 00000000..d23b2041 --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Criteria/UnverifiedUserEmail.php @@ -0,0 +1,43 @@ +repository = $repository; + } + + + /** + * @param string $token + * @return bool + * @throws MalformedRequestException + */ + public function execute(string $user){ + + if(!$this->repository->status === ApprovalStatus::PENDING_VERIFICATION){ + throw new MalformedRequestException('The user email address has been verified already'); + } + + return true; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Criteria/UserEmailExists.php b/app/Classes/Modules/Accounts/Standards/Criteria/UserEmailExists.php new file mode 100644 index 00000000..9b65263d --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Criteria/UserEmailExists.php @@ -0,0 +1,40 @@ +repository = $repository; + } + + + /** + * @param string $email + * @return bool + * @throws ResourceNotFoundException + */ + public function execute(string $email){ + + if(!$this->repository->where('email', $email)->first()){ + throw new ResourceNotFoundException('Unable to find any record that matches the email address provided'); + } + + return true; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Rules/CanFetchUser.php b/app/Classes/Modules/Accounts/Standards/Rules/CanFetchUser.php new file mode 100644 index 00000000..740e231c --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Rules/CanFetchUser.php @@ -0,0 +1,42 @@ +generatePasswordResetValidation = $generatePasswordResetValidation; + $this->userEmailExists = $userEmailExists; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + return true; + + } + + + /** + * @param GeneratePasswordResetObject $object + * @return bool + * @throws RequestValidationException + */ + protected function validators($object): bool + { + return $this->generatePasswordResetValidation->validate($object); + } + + + /** + * @param GeneratePasswordResetObject $object + * @return bool + * @throws ResourceNotFoundException + */ + protected function criteria($object): bool + { + return $this->userEmailExists->execute($object->getEmail()); + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Rules/CanListUsers.php b/app/Classes/Modules/Accounts/Standards/Rules/CanListUsers.php index 0039de25..d1ba2ea0 100644 --- a/app/Classes/Modules/Accounts/Standards/Rules/CanListUsers.php +++ b/app/Classes/Modules/Accounts/Standards/Rules/CanListUsers.php @@ -4,11 +4,7 @@ namespace App\Classes\Modules\Accounts\Standards\Rules; use App\Classes\General\Abstracts\AbstractRule; -use App\Classes\Exceptions\RequestValidationException; -use App\Classes\Exceptions\ResourceNotFoundException; -use App\Classes\Modules\Accounts\DataTransferObjects\PasswordResetObject; -use App\Classes\Modules\Accounts\Standards\Criteria\PasswordResetTokenExists; -use App\Classes\Modules\Accounts\Standards\Validators\ResetPasswordValidation; +use App\Classes\Modules\Accounts\DataTransferObjects\UserObject; class CanListUsers extends AbstractRule { @@ -24,7 +20,7 @@ class CanListUsers extends AbstractRule } /** - * @param PasswordResetObject $object + * @param UserObject $object * @return bool */ protected function validators($object): bool @@ -35,7 +31,7 @@ class CanListUsers extends AbstractRule /** - * @param PasswordResetObject $object + * @param UserObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/Accounts/Standards/Rules/CanCreateUser.php b/app/Classes/Modules/Accounts/Standards/Rules/CanRegisterUser.php similarity index 62% rename from app/Classes/Modules/Accounts/Standards/Rules/CanCreateUser.php rename to app/Classes/Modules/Accounts/Standards/Rules/CanRegisterUser.php index dfb328ce..d0720d1c 100644 --- a/app/Classes/Modules/Accounts/Standards/Rules/CanCreateUser.php +++ b/app/Classes/Modules/Accounts/Standards/Rules/CanRegisterUser.php @@ -3,20 +3,20 @@ namespace App\Classes\Modules\Accounts\Standards\Rules; use App\Classes\General\Abstracts\AbstractRule; -use App\Classes\Modules\Accounts\DataTransferObjects\UserObject; -use App\Classes\Modules\Accounts\Standards\Validators\UserValidation; +use App\Classes\Modules\Accounts\DataTransferObjects\RegistrationObject; +use App\Classes\Modules\Accounts\Standards\Validators\UserRegistrationValidation; -class CanCreateUser extends AbstractRule +class CanRegisterUser extends AbstractRule { - /** @var UserValidation */ + /** @var UserRegistrationValidation */ private $userValidation; /** * CanCreateUser constructor. - * @param UserValidation $userValidation + * @param UserRegistrationValidation $userValidation */ - public function __construct(UserValidation $userValidation) + public function __construct(UserRegistrationValidation $userValidation) { $this->userValidation = $userValidation; } @@ -31,7 +31,7 @@ class CanCreateUser extends AbstractRule } /** - * @param UserObject $object + * @param RegistrationObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -41,7 +41,7 @@ class CanCreateUser extends AbstractRule } /** - * @param UserObject $object + * @param RegistrationObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/Accounts/Standards/Rules/CanResendEmailVerification.php b/app/Classes/Modules/Accounts/Standards/Rules/CanResendEmailVerification.php new file mode 100644 index 00000000..4a9f016c --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Rules/CanResendEmailVerification.php @@ -0,0 +1,42 @@ +passwordResetTokenExists->execute($object->getToken()); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Rules/CanResetPassword.php b/app/Classes/Modules/Accounts/Standards/Rules/CanResetPassword.php new file mode 100644 index 00000000..cf620414 --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Rules/CanResetPassword.php @@ -0,0 +1,65 @@ +resetPasswordValidation = $resetPasswordValidation; + $this->passwordResetTokenExists = $passwordResetTokenExists; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + return true; + + } + + /** + * @param PasswordResetObject $object + * @return bool + * @throws RequestValidationException + */ + protected function validators($object): bool + { + return $this->resetPasswordValidation->validate($object); + + } + + + /** + * @param PasswordResetObject $object + * @return bool + * @throws ResourceNotFoundException + */ + protected function criteria($object): bool + { + return $this->passwordResetTokenExists->execute($object->getToken()); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Validators/GeneratePasswordResetValidation.php b/app/Classes/Modules/Accounts/Standards/Validators/GeneratePasswordResetValidation.php new file mode 100644 index 00000000..e4deb0ea --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Validators/GeneratePasswordResetValidation.php @@ -0,0 +1,42 @@ + $object->getEmail() + ]; + } + + /** + * @return array + */ + protected function rules(): array { + return [ + 'email' => 'required|email' + ]; + } + + /** + * @return array + */ + protected function messages(): array { + return []; + } + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Validators/ResetPasswordValidation.php b/app/Classes/Modules/Accounts/Standards/Validators/ResetPasswordValidation.php new file mode 100644 index 00000000..7963dc10 --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Validators/ResetPasswordValidation.php @@ -0,0 +1,50 @@ + $object->getToken(), + 'password' => $object->getNewPassword()->getPassword(), + 'confirm_password' => $object->getNewPassword()->getConfirmPassword() + ]; + } + + /** + * @return array + */ + protected function rules(): array { + return [ + 'token' => 'required', + 'password' => 'required|min:6', + 'confirm_password' => 'same:password' + + ]; + } + + /** + * @return array + */ + protected function messages(): array { + return [ + 'confirm_password' => [ + 'same' => 'The :attribute and :other must match.' + ] + ]; + } + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Validators/UserValidation.php b/app/Classes/Modules/Accounts/Standards/Validators/UserRegistrationValidation.php similarity index 74% rename from app/Classes/Modules/Accounts/Standards/Validators/UserValidation.php rename to app/Classes/Modules/Accounts/Standards/Validators/UserRegistrationValidation.php index 2fea6460..673b7961 100644 --- a/app/Classes/Modules/Accounts/Standards/Validators/UserValidation.php +++ b/app/Classes/Modules/Accounts/Standards/Validators/UserRegistrationValidation.php @@ -3,15 +3,17 @@ namespace App\Classes\Modules\Accounts\Standards\Validators; use App\Classes\General\Abstracts\AbstractValidation; -use App\Classes\Modules\Accounts\DataTransferObjects\UserObject; +use App\Classes\Modules\Accounts\DataTransferObjects\RegistrationObject; -class UserValidation extends AbstractValidation +class UserRegistrationValidation extends AbstractValidation { + + /** - * @param UserObject $object + * @param RegistrationObject $object * @return array */ - protected function data($object): array + protected function data($object): array { return [ 'name' => $object->getName(), @@ -26,7 +28,7 @@ class UserValidation extends AbstractValidation /** * @return array */ - protected function rules(): array + protected function rules(): array { return [ 'name' => 'required', @@ -40,7 +42,7 @@ class UserValidation extends AbstractValidation /** * @return array */ - protected function messages(): array + protected function messages(): array { return []; } diff --git a/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php index 81531ca4..8fd6fe7f 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php @@ -3,16 +3,18 @@ namespace App\Classes\Modules\Addresses\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Addresses\Services\CreatesAddress; +use App\Classes\Modules\Addresses\Services\FetchesDistrict; use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress; use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject; +use App\Classes\Modules\Companies\Services\FetchesCompany; use App\Http\Resources\AddressResource; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class CreateAddressLogic extends AbstractControllersLogic +class CreateAddressLogic extends AbstractControllerLogic { /** @@ -28,41 +30,49 @@ class CreateAddressLogic extends AbstractControllersLogic /** @var CanCreateAddress */ private $canCreateAddress; + /** @var FetchesDistrict */ + private $fetchesDistrict; + + /** @var FetchesCompany */ + private $fetchesCompany; + /** @var CreatesAddress */ private $createsAddress; /** - * CreateAddressControllersLogic constructor. + * CreateAddressLogic constructor. * @param CanCreateAddress $canCreateAddress + * @param FetchesDistrict $fetchesDistrict + * @param FetchesCompany $fetchesCompany * @param CreatesAddress $createsAddress */ - public function __construct(CanCreateAddress $canCreateAddress, CreatesAddress $createsAddress) + public function __construct(CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesAddress $createsAddress) { $this->canCreateAddress = $canCreateAddress; + $this->fetchesDistrict = $fetchesDistrict; + $this->fetchesCompany = $fetchesCompany; $this->createsAddress = $createsAddress; } - /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { - $object = new AddressObject($request->input('company_id'), $request->input('street_one'), $request->input('street_two'), $request->input('city'), $request->input('state'), $request->input('post_code'), $request->input('country'), $request->input('default'), $request->input('billing')); + $district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]); - $this->canCreateAddress->passes($object); + $object = new AddressObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code')); - $query = $this->createsAddress->execute($object); + $this->canCreateAddress->passes($object); - return $this->resourceResponse(new AddressResource($query)); + $query = $this->createsAddress->execute($this->fetchesCompany->execute(['id' => $request->input('company_id')]), $object); - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->resourceResponse(new AddressResource($query)); } diff --git a/app/Classes/Modules/Addresses/ControllersLogic/DeleteAddressLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/DeleteAddressLogic.php index b5f6753b..3a3593aa 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/DeleteAddressLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/DeleteAddressLogic.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Addresses\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Addresses\Services\DeletesAddress; use App\Classes\Modules\Addresses\Services\FetchesAddress; use App\Classes\Modules\Addresses\Standards\Rules\CanDeleteAddress; @@ -11,7 +11,7 @@ use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class DeleteAddressLogic extends AbstractControllersLogic +class DeleteAddressLogic extends AbstractControllerLogic { /** * @return array diff --git a/app/Classes/Modules/Addresses/ControllersLogic/FetchAddressLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/FetchAddressLogic.php index 84b4b1a3..12320e0f 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/FetchAddressLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/FetchAddressLogic.php @@ -3,16 +3,15 @@ namespace App\Classes\Modules\Addresses\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Addresses\Services\FetchesAddress; use App\Classes\Modules\Addresses\Standards\Rules\CanFetchAddress; -use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject; use App\Http\Resources\AddressResource; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class FetchAddressLogic extends AbstractControllersLogic +class FetchAddressLogic extends AbstractControllerLogic { /** diff --git a/app/Classes/Modules/Addresses/ControllersLogic/ListAddressesLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/ListAddressesLogic.php index 24a7b932..57e3a2f0 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/ListAddressesLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/ListAddressesLogic.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Addresses\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Addresses\Services\ListsAddresses; use App\Classes\Modules\Addresses\Standards\Rules\CanListAddresses; use App\Http\Resources\AddressResource; @@ -11,7 +11,7 @@ use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class ListAddressesLogic extends AbstractControllersLogic +class ListAddressesLogic extends AbstractControllerLogic { /** diff --git a/app/Classes/Modules/Addresses/ControllersLogic/ListDistrictsLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/ListDistrictsLogic.php new file mode 100644 index 00000000..b9a97fb3 --- /dev/null +++ b/app/Classes/Modules/Addresses/ControllersLogic/ListDistrictsLogic.php @@ -0,0 +1,54 @@ + 'Retrieved Addresses', + 'message' => 'You have successfully retrieved a list of Addresses' + ]; + } + + /** @var ListsDistricts */ + private $listDistricts; + + /** + * ListDistrictsLogic constructor. + * @param ListsDistricts $listDistricts + */ + public function __construct(ListsDistricts $listDistricts) + { + $this->listDistricts = $listDistricts; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $query = $this->listDistricts->execute($this->listDistricts->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(DistrictResource::collection($query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php index 3b4937d5..aa7b4434 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Addresses\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Addresses\Services\UpdatesAddress; use App\Classes\Modules\Addresses\Services\FetchesAddress; use App\Classes\Modules\Addresses\Standards\Rules\CanUpdateAddress; @@ -13,7 +13,7 @@ use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class UpdateAddressLogic extends AbstractControllersLogic +class UpdateAddressLogic extends AbstractControllerLogic { /** diff --git a/app/Classes/Modules/Addresses/DataTransferObjects/AddressObject.php b/app/Classes/Modules/Addresses/DataTransferObjects/AddressObject.php index abacaa67..8c164317 100644 --- a/app/Classes/Modules/Addresses/DataTransferObjects/AddressObject.php +++ b/app/Classes/Modules/Addresses/DataTransferObjects/AddressObject.php @@ -2,69 +2,46 @@ namespace App\Classes\Modules\Addresses\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; class AddressObject implements DataTransferObject { - /** @var int */ - private $companyId; - /** @var string */ private $streetOne; /** @var string|null */ private $streetTwo; - /** @var string */ - private $city; + /** @var int */ + private $countryId; - /** @var string */ - private $state; + /** @var int */ + private $stateId; - /** @var string */ + /** @var int */ + private $districtId; + + /** @var int */ private $postCode; - /** @var string */ - private $country; - - /** @var int */ - private $default; - - /** @var int */ - private $billing; - /** * AddressObject constructor. - * @param int $companyId * @param string $streetOne * @param null|string $streetTwo - * @param string $city - * @param string $state - * @param string $postCode - * @param string $country - * @param int $default - * @param int $billing + * @param int $countryId + * @param int $stateId + * @param int $districtId + * @param int $postCode */ - public function __construct(int $companyId, string $streetOne, ?string $streetTwo, string $city, string $state, string $postCode, string $country, int $default, int $billing) + public function __construct(string $streetOne, ?string $streetTwo, int $countryId, int $stateId, int $districtId, int $postCode) { - $this->companyId = $companyId; $this->streetOne = $streetOne; $this->streetTwo = $streetTwo; - $this->city = $city; - $this->state = $state; + $this->countryId = $countryId; + $this->stateId = $stateId; + $this->districtId = $districtId; $this->postCode = $postCode; - $this->country = $country; - $this->default = $default; - $this->billing = $billing; - } - - /** - * @return int - */ - public function getCompanyId(): int - { - return $this->companyId; } /** @@ -84,52 +61,36 @@ class AddressObject implements DataTransferObject } /** - * @return string + * @return int */ - public function getCity(): string + public function getCountryId(): int { - return $this->city; + return $this->countryId; } /** - * @return string + * @return int */ - public function getState(): string + public function getStateId(): int { - return $this->state; + return $this->stateId; } /** - * @return string + * @return int */ - public function getPostCode(): string + public function getDistrictId(): int + { + return $this->districtId; + } + + /** + * @return int + */ + public function getPostCode(): int { return $this->postCode; } - /** - * @return string - */ - public function getCountry(): string - { - return $this->country; - } - - /** - * @return int - */ - public function getDefault(): int - { - return $this->default; - } - - /** - * @return int - */ - public function getBilling(): int - { - return $this->billing; - } - } \ No newline at end of file diff --git a/app/Classes/Modules/Addresses/Services/CreatesAddress.php b/app/Classes/Modules/Addresses/Services/CreatesAddress.php index b5e5b0df..e6a7b8b3 100644 --- a/app/Classes/Modules/Addresses/Services/CreatesAddress.php +++ b/app/Classes/Modules/Addresses/Services/CreatesAddress.php @@ -3,30 +3,30 @@ namespace App\Classes\Modules\Addresses\Services; use App\Classes\General\Eloquent\AbstractUpdateRecord; +use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord; use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject; use App\Models\Address; +use App\Models\Company; -class CreatesAddress extends AbstractUpdateRecord +class CreatesAddress extends AbstractUpdateRelationshipRecord { /** + * @param Company $company * @param AddressObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(AddressObject $object) { + public function execute(Company $company, AddressObject $object) { $model = new Address(); - $model->company_id = $object->getCompanyId(); $model->street_one = $object->getStreetOne(); $model->street_two = $object->getStreetTwo(); - $model->city = $object->getCity(); - $model->state = $object->getState(); - $model->post_code = $object->getPostCode(); - $model->country = $object->getCountry(); - $model->default = $object->getDefault(); - $model->billing = $object->getBilling(); + $model->country_id = $object->getCountryId(); + $model->state_id = $object->getStateId(); + $model->district_id = $object->getDistrictId(); + $model->postcode = $object->getPostCode(); - return $this->handler($model); + return $this->handler($company->addresses(), $model); } } \ No newline at end of file diff --git a/app/Classes/Modules/Addresses/Services/DeletesAddress.php b/app/Classes/Modules/Addresses/Services/DeletesAddress.php index 75cbbca8..a36ab903 100644 --- a/app/Classes/Modules/Addresses/Services/DeletesAddress.php +++ b/app/Classes/Modules/Addresses/Services/DeletesAddress.php @@ -3,12 +3,16 @@ namespace App\Classes\Modules\Addresses\Services; use App\Classes\General\Eloquent\AbstractDeleteRecord; -use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject; use App\Models\Address; class DeletesAddress extends AbstractDeleteRecord { + /** + * @param Address $model + * @return mixed + * @throws \App\Classes\Exceptions\MalformedRequestException + */ public function execute(Address $model) { return $this->handler($model); } diff --git a/app/Classes/Modules/Addresses/Services/FetchesDistrict.php b/app/Classes/Modules/Addresses/Services/FetchesDistrict.php new file mode 100644 index 00000000..f2fcd371 --- /dev/null +++ b/app/Classes/Modules/Addresses/Services/FetchesDistrict.php @@ -0,0 +1,34 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/Services/ListsCompanyBank.php b/app/Classes/Modules/Addresses/Services/ListsDistricts.php similarity index 54% rename from app/Classes/Modules/CompanyBanks/Services/ListsCompanyBank.php rename to app/Classes/Modules/Addresses/Services/ListsDistricts.php index e9420517..b5b65341 100644 --- a/app/Classes/Modules/CompanyBanks/Services/ListsCompanyBank.php +++ b/app/Classes/Modules/Addresses/Services/ListsDistricts.php @@ -1,23 +1,23 @@ repository = $repository; } diff --git a/app/Classes/Modules/Addresses/Standards/Validators/AddressValidation.php b/app/Classes/Modules/Addresses/Standards/Validators/AddressValidation.php index 6d4e873c..5d8b0ee6 100644 --- a/app/Classes/Modules/Addresses/Standards/Validators/AddressValidation.php +++ b/app/Classes/Modules/Addresses/Standards/Validators/AddressValidation.php @@ -16,15 +16,9 @@ class AddressValidation extends AbstractValidation */ protected function data($object): array { return [ - 'company_id' => $object->getCompanyId(), 'street_one' => $object->getStreetOne(), 'street_two' => $object->getStreetTwo(), - 'city' => $object->getCity(), - 'state' => $object->getState(), - 'post_code' => $object->getPostCode(), - 'country' => $object->getCountry(), - 'default' => $object->getDefault(), - 'billing' => $object->getBilling() + 'district_id' => $object->getDistrictId() ]; } @@ -33,14 +27,8 @@ class AddressValidation extends AbstractValidation */ protected function rules(): array { return [ - 'company_id' => 'required', 'street_one' => 'required', - 'city' => 'required', - 'state' => 'required', - 'post_code' => 'required', - 'country' => 'required', - 'default' => 'required', - 'billing' => 'required' + 'district_id' => 'required', ]; } diff --git a/app/Classes/Modules/Banks/ControllersLogic/CreateBankLogic.php b/app/Classes/Modules/Banks/ControllersLogic/CreateBankLogic.php new file mode 100644 index 00000000..41684344 --- /dev/null +++ b/app/Classes/Modules/Banks/ControllersLogic/CreateBankLogic.php @@ -0,0 +1,71 @@ + 'Created Bank', + 'message' => 'You have successfully created a new Bank' + ]; + } + + /** @var CanCreateBank */ + private $canCreateBank; + + /** @var CreatesBank */ + private $createsBank; + + + /** + * CreateBankLogic constructor. + * @param CanCreateBank $canCreateBank + * @param CreatesBank $createsBank + */ + public function __construct( + CanCreateBank $canCreateBank, + CreatesBank $createsBank + ) + { + $this->canCreateBank = $canCreateBank; + $this->createsBank = $createsBank; + } + + /** + * @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 + { + + $bank_object = new BankObject($request->input('company_id'), $request->input('account_type'), + $request->input('bank_name'), $request->input('holder_name'), $request->input('account_no'), + $request->input('country_id'), $request->input('reference')); + + $this->canCreateBank->passes($bank_object); + + $bank = $this->createsBank->execute($bank_object); + + return $this->resourceResponse(new BankResource($bank)); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Banks/ControllersLogic/DeleteBankLogic.php b/app/Classes/Modules/Banks/ControllersLogic/DeleteBankLogic.php new file mode 100644 index 00000000..24975379 --- /dev/null +++ b/app/Classes/Modules/Banks/ControllersLogic/DeleteBankLogic.php @@ -0,0 +1,77 @@ + 'Delete Bank', + 'message' => 'You have successfully deleted the Bank' + ]; + } + + /** @var CanDeleteBank */ + private $canDeleteBank; + + /** @var DeletesBank */ + private $deletesBank; + + /** @var FetchesBank */ + private $fetchesBank; + + + /** + * DeleteBankLogic constructor. + * @param CanDeleteBank $canDeleteBank + * @param DeletesBank $deletesBank + * @param FetchesBank $fetchesBank + */ + public function __construct( + CanDeleteBank $canDeleteBank, + DeletesBank $deletesBank, + FetchesBank $fetchesBank + ) + { + $this->canDeleteBank = $canDeleteBank; + $this->deletesBank = $deletesBank; + $this->fetchesBank = $fetchesBank; + } + + /** + * @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->canDeleteBank->passes(); + + $bank = $this->fetchesBank->execute(['id' => $request->route('id')]); + + if($bank->default){ + throw new RequestValidationException('You can\'t delete bank account when it set to default'); + } + + $this->deletesBank->execute($bank); + + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Banks/ControllersLogic/ListBanksLogic.php b/app/Classes/Modules/Banks/ControllersLogic/ListBanksLogic.php new file mode 100644 index 00000000..94396d61 --- /dev/null +++ b/app/Classes/Modules/Banks/ControllersLogic/ListBanksLogic.php @@ -0,0 +1,62 @@ + 'Retrieve Banks', + 'message' => 'You have successfully retrieved a list of Banks' + ]; + } + + /** @var CanListBanks */ + private $canListBanks; + + /** @var ListsBanks */ + private $listsBanks; + + /** + * ListBanksLogic constructor. + * @param CanListBanks $canListBanks + * @param ListsBanks $listsBanks + */ + public function __construct(CanListBanks $canListBanks, ListsBanks $listsBanks) + { + $this->canListBanks = $canListBanks; + $this->listsBanks = $listsBanks; + } + + + /** + * @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->canListBanks->passes(); + + $banks = $this->listsBanks->execute($this->listsBanks->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(BankResource::collection($banks)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Banks/ControllersLogic/SetBankToDefaultLogic.php b/app/Classes/Modules/Banks/ControllersLogic/SetBankToDefaultLogic.php new file mode 100644 index 00000000..0e9885ae --- /dev/null +++ b/app/Classes/Modules/Banks/ControllersLogic/SetBankToDefaultLogic.php @@ -0,0 +1,78 @@ + 'Updated Bank', + 'message' => 'You have successfully updated the Bank' + ]; + } + + /** @var ResetsBanksDefault */ + private $resetsBanksDefault; + + /** @var FetchesBank */ + private $fetchesBank; + + /** @var SetsBankToDefault*/ + private $setsBankToDefault ; + + /** + * SetBankToDefaultLogic constructor. + * @param ResetsBanksDefault $resetsBanksDefault + * @param FetchesBank $fetchesBank + * @param SetsBankToDefault $setsBankToDefault + */ + public function __construct(ResetsBanksDefault $resetsBanksDefault, FetchesBank $fetchesBank, SetsBankToDefault $setsBankToDefault) + { + $this->resetsBanksDefault = $resetsBanksDefault; + $this->fetchesBank = $fetchesBank; + $this->setsBankToDefault = $setsBankToDefault; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + /** @var Bank $bank */ + $bank = $this->fetchesBank->execute(['id' => $request->route('id')]); + + $this->resetsBanksDefault->execute($bank); + + $this->setsBankToDefault->execute($bank); + + return $this->resourceResponse(new BankResource($this->setsBankToDefault->execute($bank))); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php new file mode 100644 index 00000000..85e3449c --- /dev/null +++ b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php @@ -0,0 +1,85 @@ + 'Update Bank Account', + 'message' => 'You have successfully updated the Bank Account' + ]; + } + + /** @var CanUpdateBank */ + private $canUpdateBank; + + /** @var UpdatesBank */ + private $updatesBank; + + /** @var FetchesBank */ + private $fetchesBank; + + + /** + * UpdateBankLogic constructor. + * @param CanUpdateBank $canUpdateBank + * @param UpdatesBank $updatesBank + * @param FetchesBank $fetchesBank + */ + public function __construct( + CanUpdateBank $canUpdateBank, + UpdatesBank $updatesBank, + FetchesBank $fetchesBank + ) + { + $this->canUpdateBank = $canUpdateBank; + $this->updatesBank = $updatesBank; + $this->fetchesBank = $fetchesBank; + } + + /** + * @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 + { + + $bankObject = new BankObject($request->input('company_id'), $request->input('country_id'), + $request->input('reference'), $request->input('bank_name'), $request->input('holder_name'), + $request->input('account_no')); + + + $bank = $this->fetchesBank->execute(['id' => $request->route('id')]); + + $this->canUpdateBank->passes($bankObject); + + $bank_query = $this->updatesBank->execute($bank, $bankObject); + + return $this->resourceResponse(new BankResource($bank_query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Banks/DataTransferObjects/BankObject.php b/app/Classes/Modules/Banks/DataTransferObjects/BankObject.php new file mode 100644 index 00000000..08ef54f7 --- /dev/null +++ b/app/Classes/Modules/Banks/DataTransferObjects/BankObject.php @@ -0,0 +1,109 @@ +company_id = $company_id; + $this->type = $type; + $this->bank_name = $bank_name; + $this->holder_name = $holder_name; + $this->account_no = $account_no; + $this->country_id = $country_id; + $this->reference = $reference; + } + + /** + * @return int + */ + public function getCompanyId(): int + { + return $this->company_id; + } + + /** + * @return int + */ + public function getType(): int + { + return $this->type; + } + + /** + * @return string + */ + public function getBankName(): string + { + return $this->bank_name; + } + + /** + * @return string + */ + public function getHolderName(): string + { + return $this->holder_name; + } + + /** + * @return string + */ + public function getAccountNo(): string + { + return $this->account_no; + } + + /** + * @return int + */ + public function getCountryId(): int + { + return $this->country_id; + } + + /** + * @return null|string + */ + public function getReference(): ?string + { + return $this->reference; + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/Services/CreatesCompanyBank.php b/app/Classes/Modules/Banks/Services/CreatesBank.php similarity index 58% rename from app/Classes/Modules/CompanyBanks/Services/CreatesCompanyBank.php rename to app/Classes/Modules/Banks/Services/CreatesBank.php index 06223f49..3aea73e3 100644 --- a/app/Classes/Modules/CompanyBanks/Services/CreatesCompanyBank.php +++ b/app/Classes/Modules/Banks/Services/CreatesBank.php @@ -1,27 +1,29 @@ country_id = $object->getCountryId(); + public function execute(BankObject $object) { + + $model = new Bank(); $model->company_id = $object->getCompanyId(); + $model->reference = $object->getReference(); $model->bank_name = $object->getBankName(); $model->holder_name = $object->getHolderName(); $model->account_no = $object->getAccountNo(); $model->type = $object->getType(); - $model->default = $object->getDefault(); + $model->country_id = $object->getCountryId(); + return $this->handler($model); } diff --git a/app/Classes/Modules/Banks/Services/DeletesBank.php b/app/Classes/Modules/Banks/Services/DeletesBank.php new file mode 100644 index 00000000..2aeb8ea7 --- /dev/null +++ b/app/Classes/Modules/Banks/Services/DeletesBank.php @@ -0,0 +1,19 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/Services/FetchesCompanyBank.php b/app/Classes/Modules/Banks/Services/FetchesBank.php similarity index 54% rename from app/Classes/Modules/CompanyBanks/Services/FetchesCompanyBank.php rename to app/Classes/Modules/Banks/Services/FetchesBank.php index 669075d2..dd075da6 100644 --- a/app/Classes/Modules/CompanyBanks/Services/FetchesCompanyBank.php +++ b/app/Classes/Modules/Banks/Services/FetchesBank.php @@ -1,24 +1,24 @@ repository = $repository; } diff --git a/app/Classes/Modules/Banks/Services/ListsBanks.php b/app/Classes/Modules/Banks/Services/ListsBanks.php new file mode 100644 index 00000000..f1470ca4 --- /dev/null +++ b/app/Classes/Modules/Banks/Services/ListsBanks.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Banks/Services/ResetsBanksDefault.php b/app/Classes/Modules/Banks/Services/ResetsBanksDefault.php new file mode 100644 index 00000000..29e010a5 --- /dev/null +++ b/app/Classes/Modules/Banks/Services/ResetsBanksDefault.php @@ -0,0 +1,21 @@ +company->banks()->where('type', $bank->type)->update(['default' => false]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Banks/Services/SetsBankToDefault.php b/app/Classes/Modules/Banks/Services/SetsBankToDefault.php new file mode 100644 index 00000000..eab9b709 --- /dev/null +++ b/app/Classes/Modules/Banks/Services/SetsBankToDefault.php @@ -0,0 +1,22 @@ +default = true; + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/Services/UpdatesCompanyBank.php b/app/Classes/Modules/Banks/Services/UpdatesBank.php similarity index 58% rename from app/Classes/Modules/CompanyBanks/Services/UpdatesCompanyBank.php rename to app/Classes/Modules/Banks/Services/UpdatesBank.php index 3116b3c3..85249fb9 100644 --- a/app/Classes/Modules/CompanyBanks/Services/UpdatesCompanyBank.php +++ b/app/Classes/Modules/Banks/Services/UpdatesBank.php @@ -1,20 +1,21 @@ bank_name = $object->getBankName(); $model->holder_name = $object->getHolderName(); diff --git a/app/Classes/Modules/Banks/Standards/Rules/CanCreateBank.php b/app/Classes/Modules/Banks/Standards/Rules/CanCreateBank.php new file mode 100644 index 00000000..8cef85d8 --- /dev/null +++ b/app/Classes/Modules/Banks/Standards/Rules/CanCreateBank.php @@ -0,0 +1,50 @@ +BankValidation = $BankValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + return true; + } + + /** + * @param CompanyObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->BankValidation->validate($object); + } + + /** + * @param CompanyObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Banks/Standards/Rules/CanDeleteBank.php b/app/Classes/Modules/Banks/Standards/Rules/CanDeleteBank.php new file mode 100644 index 00000000..074550e5 --- /dev/null +++ b/app/Classes/Modules/Banks/Standards/Rules/CanDeleteBank.php @@ -0,0 +1,40 @@ +BankValidation = $BankValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param BankObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->BankValidation->validate($object); + } + + /** + * @param BankObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/Standards/Validators/CompanyBankValidation.php b/app/Classes/Modules/Banks/Standards/Validators/BankValidation.php similarity index 61% rename from app/Classes/Modules/CompanyBanks/Standards/Validators/CompanyBankValidation.php rename to app/Classes/Modules/Banks/Standards/Validators/BankValidation.php index e8614e78..896f70bc 100644 --- a/app/Classes/Modules/CompanyBanks/Standards/Validators/CompanyBankValidation.php +++ b/app/Classes/Modules/Banks/Standards/Validators/BankValidation.php @@ -1,14 +1,14 @@ $object->getCompanyId(), 'bank_name' => $object->getBankName(), 'holder_name' => $object->getHolderName(), - 'account_no' => $object->getAccountNo(), - 'type' => $object->getType(), - 'default' => $object->getDefault(), + 'account_no' => $object->getAccountNo() ]; } @@ -34,9 +32,7 @@ class CompanyBankValidation extends AbstractValidation 'company_id' => 'required', 'bank_name' => 'required', 'holder_name' => 'required', - 'account_no' => 'required', - 'type' => 'required', - 'default' => 'required', + 'account_no' => 'required' ]; } diff --git a/app/Classes/Modules/Bookings/ControllersLogic/ApprovePaymentLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/ApprovePaymentLogic.php new file mode 100644 index 00000000..0a4ef334 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/ApprovePaymentLogic.php @@ -0,0 +1,60 @@ + 'Payment Proof Approved', + 'message' => 'You have successfully approve the payment' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var ApprovesDocument */ + private $approvesDocument; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('payment_id')]); + + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::PENDING_VERIFICATION); + + + + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/ApprovePaymentVerificationLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/ApprovePaymentVerificationLogic.php new file mode 100644 index 00000000..1f814831 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/ApprovePaymentVerificationLogic.php @@ -0,0 +1,81 @@ +fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->approvesDocument = $approvesDocument; + $this->rejectsDocument = $rejectsDocument; + $this->fetchesDocument = $fetchesDocument; + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Payment Status', + 'message' => 'You have successfully updated the payment status' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var ApprovesDocument */ + private $approvesDocument; + + /** @var RejectsDocument */ + private $rejectsDocument; + + /** @var FetchesDocument */ + private $fetchesDocument; + + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $status = $request->route('status'); + + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('payment_id')]); + + $status === 'approve' ? $this->approvesDocument->execute($transaction->documents()->first()) : $this->rejectsDocument->execute($transaction->documents()->first()); + + $this->updatesTransactionStatus->execute($transaction, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); + + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/ApprovePurchaseOrderLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/ApprovePurchaseOrderLogic.php new file mode 100644 index 00000000..3f394557 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/ApprovePurchaseOrderLogic.php @@ -0,0 +1,63 @@ + 'Purchase Order Approval', + 'message' => 'You have successfully updated the Purchase order status' + ]; + } + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** + * ApprovePurchaseOrderLogic constructor. + * @param FetchesBooking $fetchesBooking + * @param UpdatesTransactionStatus $updatesTransactionStatus + */ + public function __construct(FetchesBooking $fetchesBooking, UpdatesTransactionStatus $updatesTransactionStatus) + { + $this->fetchesBooking = $fetchesBooking; + $this->updatesTransactionStatus = $updatesTransactionStatus; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); + + $this->updatesTransactionStatus->execute($booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(), ApprovalStatus::APPROVED); + + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingLogic.php index 88f82349..e4fa3666 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingLogic.php @@ -2,10 +2,10 @@ namespace App\Classes\Modules\Bookings\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Companies\Services\FetchesCompany; -use App\Classes\Modules\CompanyBanks\Services\FetchesCompanyBank; +use App\Classes\Modules\Banks\Services\FetchesBank; use App\Classes\Modules\Currencies\Services\FetchesCurrency; use App\Classes\Modules\Bookings\Standards\Rules\CanCreateBooking; @@ -18,10 +18,10 @@ use App\Http\Resources\BookingResource; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; -class CreateBookingLogic extends AbstractControllersLogic +class CreateBookingLogic extends AbstractControllerLogic { + /** * @return array */ @@ -44,75 +44,40 @@ class CreateBookingLogic extends AbstractControllersLogic /** @var FetchesCompany */ private $fetchesCompany; - /** @var FetchesCompanyBank */ - private $fetchesCompanyBank; - - /** @var FetchesCurrency */ - private $fetchesCurrency; - - /** * CreateBookingLogic constructor. * @param CanCreateBooking $canCreateBooking * @param CreatesBooking $createsBooking * @param GeneratesBookingMarking $generatesBookingMarking * @param FetchesCompany $fetchesCompany - * @param FetchesCompanyBank $fetchesCompanyBank - * @param FetchesCurrency $fetchesCurrency */ - public function __construct( - CanCreateBooking $canCreateBooking, - CreatesBooking $createsBooking, - GeneratesBookingMarking $generatesBookingMarking, - FetchesCompany $fetchesCompany, - FetchesCompanyBank $fetchesCompanyBank, - FetchesCurrency $fetchesCurrency - ) + public function __construct(CanCreateBooking $canCreateBooking, CreatesBooking $createsBooking, GeneratesBookingMarking $generatesBookingMarking, FetchesCompany $fetchesCompany) { $this->canCreateBooking = $canCreateBooking; $this->createsBooking = $createsBooking; $this->generatesBookingMarking = $generatesBookingMarking; $this->fetchesCompany = $fetchesCompany; - $this->fetchesCompanyBank = $fetchesCompanyBank; - $this->fetchesCurrency = $fetchesCurrency; } + /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { - DB::beginTransaction(); - $booking_object = new BookingObject( - $request->input('company_id'), - $request->input('transferable_bank_id'), - $this->generatesBookingMarking->execute(), - $request->input('reference'), - number_format( (float) $request->input('fix_amount'), 5, '.', ''), - $request->input('fix_currency_id'), - $request->input('convertible_currency_id'), - $request->input('conversion_currency_id') - ); - $this->canCreateBooking->passes($booking_object); + $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); - $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); - $transferable_bank = $this->fetchesCompanyBank->execute(['id' => $request->input('transferable_bank_id')]); - $fix_currency = $this->fetchesCurrency->execute(['id' => $request->input('fix_currency_id')]); - $convertible_currency = $this->fetchesCurrency->execute(['id' => $request->input('convertible_currency_id')]); - $conversion_currency = $this->fetchesCurrency->execute(['id' => $request->input('conversion_currency_id')]); + $object = new BookingObject($request->input('service_id'), $request->input('transferable_bank_id'), $this->generatesBookingMarking->execute(), number_format( floatval(str_replace(',', '', $request->input('fix_amount'))), 5, '.', ''), $request->input('type') === 1 ? $request->input('convertible_currency_id') : 1, $request->input('convertible_currency_id'), 1); - $booking = $this->createsBooking->execute($booking_object); + $this->canCreateBooking->passes($object); - DB::commit(); + $booking = $this->createsBooking->execute($company, $object); - return $this->resourceResponse(new BookingResource($booking)); - - } catch (\Exception $exception) { - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->resourceResponse(new BookingResource($booking)); } } \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingPaymentLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingPaymentLogic.php new file mode 100644 index 00000000..ab741b6b --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingPaymentLogic.php @@ -0,0 +1,103 @@ + 'Create Payment Attempt', + 'message' => 'You have successfully created a payment attempt' + ]; + } + + /** @var FetchesBookingQuotation */ + private $fetchBookingQuotation; + + /** @var FetchesCompanyPaymentAttemptLimit */ + private $fetchesCompanyPaymentAttemptLimit; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var CalculatesBookingOutstanding */ + private $calculatesBookingOutstanding; + + /** + * CreateBookingPaymentLogic constructor. + * @param FetchesBookingQuotation $fetchBookingQuotation + * @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesTransaction $createsTransaction + * @param CalculatesBookingOutstanding $calculatesBookingOutstanding + */ + public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CalculatesBookingOutstanding $calculatesBookingOutstanding) + { + $this->fetchBookingQuotation = $fetchBookingQuotation; + $this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->calculatesBookingOutstanding = $calculatesBookingOutstanding; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $booking = Booking::find($request->route('id')); + + $conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $request->input('amount'))), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')]); + + $outstanding = $this->calculatesBookingOutstanding->execute($booking); + + if($conversionObject->getAmount() > $outstanding) throw new MalformedRequestException('Your payment must not be greater than '. $outstanding .'.'); + + $configurations = $this->fetchBookingQuotation->execute($booking->company, $conversionObject); + + $paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company); + + $billNumber = $this->generatesTransactionBillNumber->execute('PYMT-'); + + $object = new TransactionObject($billNumber, TransactionType::PAYMENT, 1, $booking->company->id, + $configurations->getConfigurations()->getBankId(), $configurations->getConversionObject()->getPaymentMethod(), + $configurations->getTotal(), $configurations->getForeignTotal(), 1, + $configurations->getConversionObject()->getCurrencyId(), $configurations->getConfigurations()->getRate(), + $configurations->getTax(), $configurations->getServiceCharge(), Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_SUBMISSION); + + $transaction = $this->createsTransaction->execute($booking, $object); + + return $this->resourceResponse(new TransactionResource($transaction)); + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreatePaymentVerificationDocumentLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreatePaymentVerificationDocumentLogic.php new file mode 100644 index 00000000..bfd0229d --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreatePaymentVerificationDocumentLogic.php @@ -0,0 +1,83 @@ + 'Payment Proof Document', + 'message' => 'You have successfully submitted your payment proof document' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFile; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** + * CreatePaymentVerificationDocumentLogic constructor. + * @param FetchesTransaction $fetchesTransaction + * @param CreatesDocument $createsDocument + * @param CreatesFiles $createsFile + * @param UpdatesTransactionStatus $updatesTransactionStatus + */ + public function __construct(FetchesTransaction $fetchesTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesTransactionStatus $updatesTransactionStatus) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + $this->updatesTransactionStatus = $updatesTransactionStatus; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('payment_id')]); + + $object = new DocumentObject(DocumentType::CUSTOMER_PAYMENT_PROOF, $request->input('files'), '', ApprovalStatus::PENDING_VERIFICATION, 'payments'); + + /** @var Document $document */ + $document = $this->createsDocument->execute($transaction, $object); + + $this->createsFile->execute($document, $object); + + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::PENDING_VERIFICATION); + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/DeleteBookingLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/DeleteBookingLogic.php index fc4b447b..bb653d21 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/DeleteBookingLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/DeleteBookingLogic.php @@ -2,24 +2,21 @@ namespace App\Classes\Modules\Bookings\ControllersLogic; -use App\Classes\Modules\Segments\Services\UpdatesSegment; -use App\Classes\Modules\Segments\Standards\Rules\CanUpdateSegment; use App\Http\Resources\BookingResource; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Bookings\Services\FetchesBooking; use App\Classes\Modules\Bookings\Standards\Rules\CanDeleteBooking; use App\Classes\Modules\Bookings\Services\DeletesBooking; -use App\Classes\Modules\Bookings\DataTransferObjects\SegmentObject; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class DeleteBookingLogic extends AbstractControllersLogic +class DeleteBookingLogic extends AbstractControllerLogic { /** diff --git a/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingLogic.php new file mode 100644 index 00000000..d9857548 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingLogic.php @@ -0,0 +1,61 @@ + 'Retrieved Address', + 'message' => 'You have successfully retrieved a Address' + ]; + } + + /** @var CanFetchBooking */ + private $canFetchBooking; + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** + * FetchBookingLogic constructor. + * @param CanFetchBooking $canFetchBooking + * @param FetchesBooking $fetchesBooking + */ + public function __construct(CanFetchBooking $canFetchBooking, FetchesBooking $fetchesBooking) + { + $this->canFetchBooking = $canFetchBooking; + $this->fetchesBooking = $fetchesBooking; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $this->canFetchBooking->passes(); + + $query = $this->fetchesBooking->execute(['marking' => $request->route('marking'), 'with_transactions' => true]); + + return $this->resourceResponse(new BookingResource($query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingPaymentQuotationLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingPaymentQuotationLogic.php new file mode 100644 index 00000000..c20450d8 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingPaymentQuotationLogic.php @@ -0,0 +1,81 @@ + 'Fetch Currency Conversion', + 'message' => 'You have successfully retrieved a currency conversion' + ]; + } + + /** @var FetchesBookingQuotation */ + private $fetchBookingQuotation; + + /** @var GeneratesBookingQuotation */ + private $generatesBookingQuotation; + + /** @var FetchesCompanyPaymentAttemptLimit */ + private $fetchesCompanyPaymentAttemptLimit; + + /** @var CalculatesBookingOutstanding */ + private $calculatesBookingOutstanding; + + /** + * FetchBookingPaymentQuotationLogic constructor. + * @param FetchesBookingQuotation $fetchBookingQuotation + * @param GeneratesBookingQuotation $generatesBookingQuotation + * @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit + * @param CalculatesBookingOutstanding $calculatesBookingOutstanding + */ + public function __construct(FetchesBookingQuotation $fetchBookingQuotation, GeneratesBookingQuotation $generatesBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, CalculatesBookingOutstanding $calculatesBookingOutstanding) + { + $this->fetchBookingQuotation = $fetchBookingQuotation; + $this->generatesBookingQuotation = $generatesBookingQuotation; + $this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit; + $this->calculatesBookingOutstanding = $calculatesBookingOutstanding; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $booking = Booking::find($request->route('id')); + + $conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $request->input('amount'))), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')]); + + $outstanding = $this->calculatesBookingOutstanding->execute($booking); + if($conversionObject->getAmount() > $outstanding) throw new MalformedRequestException('Your payment must not be greater than '.$booking->fixedCurrency->short_code.' '. number_format((float)$outstanding, 2, '.', ',')); + + return $this->response(['data' => $this->generatesBookingQuotation->execute( + $this->fetchBookingQuotation->execute($booking->company, $conversionObject), + $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company) + )]); + + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/ListBookingsLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/ListBookingsLogic.php index 21ea2a37..23a21700 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/ListBookingsLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/ListBookingsLogic.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Bookings\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Bookings\Services\ListsBookings; use App\Classes\Modules\Bookings\Standards\Rules\CanListBookings; use App\Http\Resources\BookingResource; @@ -11,7 +11,7 @@ use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class ListBookingsLogic extends AbstractControllersLogic +class ListBookingsLogic extends AbstractControllerLogic { /** * @return array @@ -42,16 +42,11 @@ class ListBookingsLogic extends AbstractControllersLogic public function logic(Request $request) : JsonResponse { - try { - $this->canListBookings->passes(); + $this->canListBookings->passes(); - $query = $this->listsBookings->execute($this->listsBookings->deserializeFilters($request->input('filters'))); + $query = $this->listsBookings->execute($this->listsBookings->deserializeFilters($request->input('filters'))); - return $this->collectionResponse(BookingResource::collection($query)); - - } catch (\Exception $exception) { - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->collectionResponse(BookingResource::collection($query)); } diff --git a/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingLogic.php index f38788bb..5db55b0d 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingLogic.php @@ -4,7 +4,7 @@ namespace App\Classes\Modules\Bookings\ControllersLogic; use App\Http\Resources\BookingResource; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Bookings\Services\FetchesBooking; @@ -17,7 +17,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class UpdateBookingLogic extends AbstractControllersLogic +class UpdateBookingLogic extends AbstractControllerLogic { /** diff --git a/app/Classes/Modules/Bookings/DataTransferObjects/BookingObject.php b/app/Classes/Modules/Bookings/DataTransferObjects/BookingObject.php index cb6239c5..21b248b6 100644 --- a/app/Classes/Modules/Bookings/DataTransferObjects/BookingObject.php +++ b/app/Classes/Modules/Bookings/DataTransferObjects/BookingObject.php @@ -2,112 +2,108 @@ namespace App\Classes\Modules\Bookings\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; class BookingObject implements DataTransferObject { - private $company_id; - private $transferable_bank_id; + + /** @var int */ + private $serviceId; + + /** @var int */ + private $transferableBankId; + + /** @var string */ private $marking; - private $reference; - private $fix_amount; - private $fix_currency_id; - private $convertible_currency_id; - private $conversion_currency_id; + + /** @var float */ + private $fixAmount; + + /** @var int */ + private $fixCurrencyId; + + /** @var int */ + private $convertibleCurrencyId; + + /** @var int */ + private $conversionCurrencyId; /** * BookingObject constructor. - * @param int|null $company_id - * @param int|null $transferable_bank_id - * @param string|null $marking - * @param string|null $reference - * @param float|null $fix_amount - * @param int|null $fix_currency_id - * @param int|null $convertible_currency_id - * @param int|null $conversion_currency_id + * @param int $serviceId + * @param int $transferableBankId + * @param string $marking + * @param float $fixAmount + * @param int $fixCurrencyId + * @param int $convertibleCurrencyId + * @param int $conversionCurrencyId */ - public function __construct( - ?int $company_id, - ?int $transferable_bank_id, - ?string $marking, - ?string $reference, - ?float $fix_amount, - ?int $fix_currency_id, - ?int $convertible_currency_id, - ?int $conversion_currency_id - ) + public function __construct(int $serviceId, int $transferableBankId, string $marking, float $fixAmount, int $fixCurrencyId, int $convertibleCurrencyId, int $conversionCurrencyId) { - $this->company_id = $company_id; - $this->transferable_bank_id = $transferable_bank_id; + $this->serviceId = $serviceId; + $this->transferableBankId = $transferableBankId; $this->marking = $marking; - $this->reference = $reference; - $this->fix_amount = $fix_amount; - $this->fix_currency_id = $fix_currency_id; - $this->convertible_currency_id = $convertible_currency_id; - $this->conversion_currency_id = $conversion_currency_id; + $this->fixAmount = $fixAmount; + $this->fixCurrencyId = $fixCurrencyId; + $this->convertibleCurrencyId = $convertibleCurrencyId; + $this->conversionCurrencyId = $conversionCurrencyId; } /** * @return int */ - public function getCompanyId(): ?int + public function getServiceId(): int { - return $this->company_id; + return $this->serviceId; } /** * @return int */ - public function getTransferableBankId(): ?int + public function getTransferableBankId(): int { - return $this->transferable_bank_id; + return $this->transferableBankId; } /** * @return string */ - public function getMarking(): ?string + public function getMarking(): string { return $this->marking; } - /** - * @return string - */ - public function getReference(): ?string - { - return $this->reference; - } - /** * @return float */ - public function getFixAmount(): ?float + public function getFixAmount(): float { - return $this->fix_amount; + return $this->fixAmount; } /** * @return int */ - public function getFixCurrencyId(): ?int + public function getFixCurrencyId(): int { - return $this->fix_currency_id; + return $this->fixCurrencyId; } /** * @return int */ - public function getConvertibleCurrencyId(): ?int + public function getConvertibleCurrencyId(): int { - return $this->convertible_currency_id; + return $this->convertibleCurrencyId; } /** * @return int */ - public function getConversionCurrencyId(): ?int + public function getConversionCurrencyId(): int { - return $this->conversion_currency_id; + return $this->conversionCurrencyId; } + + } \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/DataTransferObjects/CalculationObject.php b/app/Classes/Modules/Bookings/DataTransferObjects/CalculationObject.php new file mode 100644 index 00000000..aeeba8f7 --- /dev/null +++ b/app/Classes/Modules/Bookings/DataTransferObjects/CalculationObject.php @@ -0,0 +1,95 @@ +conversionObject = $conversionObject; + $this->configurations = $configurations; + } + + /** + * @return CurrencyConversionObject + */ + public function getConversionObject(): CurrencyConversionObject + { + return $this->conversionObject; + } + + + /** + * @return CompanyServiceConfigurationsObject + */ + public function getConfigurations(): CompanyServiceConfigurationsObject + { + return $this->configurations; + } + + public function getConvertibleTotal(){ + return $this->getConversionObject()->getType() === 1 ? $this->getConversionObject()->getAmount() : $this->getConversionTotal(); + } + + /** + * @return float + */ + public function getConversionTotal(): float { + $rate = $this->getConversionObject()->getType() === 1 ? (1/$this->getConfigurations()->getRate()) : $this->getConfigurations()->getRate(); + return $this->getConversionObject()->getAmount() * $rate; + } + + /** + * @return float + */ + public function getLocalTotal(){ + return $this->getConversionObject()->getType() === 1 ? $this->getConversionTotal() : $this->getConversionObject()->getAmount(); + } + + /** + * @return float + */ + public function getForeignTotal(){ + return $this->getConversionObject()->getType() === 1 ? $this->getConversionObject()->getAmount() : $this->getConversionTotal(); + } + + /** + * @return float + */ + public function getServiceCharge(): float { + return ($this->getLocalTotal()/100) * $this->getConfigurations()->getServiceCharge() < $this->getConfigurations()->getMinimumCharge() ? $this->getConfigurations()->getMinimumCharge() : ($this->getLocalTotal()/100) * $this->getConfigurations()->getServiceCharge(); + } + + public function getSubTotal(): float { + return $this->getLocalTotal() + $this->getServiceCharge(); + } + + /** + * @return float + */ + public function getTax(): float { + return ($this->getSubTotal()/100) * $this->getConfigurations()->getTax(); + } + + public function getTotal(): float { + return $this->getSubTotal() + $this->getTax(); + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingFloatingAmount.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingFloatingAmount.php new file mode 100644 index 00000000..cc5acc1d --- /dev/null +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingFloatingAmount.php @@ -0,0 +1,25 @@ +transactions()->selectRaw('sum(amount - service_charge - tax) as sub_total') + ->where('type', TransactionType::PAYMENT) + ->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION]) + ->whereDate('expires_on', '>', Carbon::now())->get()->sum('sub_total') : + $booking->transactions()->where('type', TransactionType::PAYMENT) + ->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION]) + ->whereDate('expires_on', '>', Carbon::now())->sum('original_amount'); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingOutstanding.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingOutstanding.php new file mode 100644 index 00000000..b1aae605 --- /dev/null +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingOutstanding.php @@ -0,0 +1,33 @@ +calculatesBookingPaidAmount = $calculatesBookingPaidAmount; + $this->calculatesBookingFloatingAmount = $calculatesBookingFloatingAmount; + } + + + public function execute(Booking $booking){ + return $booking->fix_amount - $this->calculatesBookingFloatingAmount->execute($booking, $booking->fix_currency_id) - $this->calculatesBookingPaidAmount->execute($booking, $booking->fix_currency_id); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingPaidAmount.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingPaidAmount.php new file mode 100644 index 00000000..1dd5a847 --- /dev/null +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingPaidAmount.php @@ -0,0 +1,23 @@ +transactions()->selectRaw('sum(amount - service_charge - tax) as sub_total') + ->where('type', TransactionType::PAYMENT) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get()->sum('sub_total') : + $booking->transactions()->where('type', TransactionType::PAYMENT) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('original_amount'); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/CreatesBooking.php b/app/Classes/Modules/Bookings/Services/CreatesBooking.php index 676451fd..51c6da78 100644 --- a/app/Classes/Modules/Bookings/Services/CreatesBooking.php +++ b/app/Classes/Modules/Bookings/Services/CreatesBooking.php @@ -3,26 +3,30 @@ namespace App\Classes\Modules\Bookings\Services; use App\Classes\General\Eloquent\AbstractUpdateRecord; +use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord; use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject; use App\Models\Booking; +use App\Models\Company; -class CreatesBooking extends AbstractUpdateRecord +class CreatesBooking extends AbstractUpdateRelationshipRecord { /** + * @param Company $company * @param BookingObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(BookingObject $object) { + public function execute(Company $company, BookingObject $object) { + $model = new Booking(); - $model->company_id = $object->getCompanyId(); - $model->transferable_bank_id = $object->getTransferableBankId(); + $model->service_id = $object->getServiceId(); + $model->bank_id = $object->getTransferableBankId(); $model->marking = $object->getMarking(); - $model->reference = $object->getReference(); $model->fix_amount = $object->getFixAmount(); $model->fix_currency_id = $object->getFixCurrencyId(); $model->convertible_currency_id = $object->getConvertibleCurrencyId(); $model->conversion_currency_id = $object->getConversionCurrencyId(); - return $this->handler($model); + + return $this->handler($company->bookings(), $model); } } \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/DeletesBooking.php b/app/Classes/Modules/Bookings/Services/DeletesBooking.php index b189c382..7e4d4842 100644 --- a/app/Classes/Modules/Bookings/Services/DeletesBooking.php +++ b/app/Classes/Modules/Bookings/Services/DeletesBooking.php @@ -8,6 +8,11 @@ use App\Models\Booking; class DeletesBooking extends AbstractDeleteRecord { + /** + * @param Booking $model + * @return mixed + * @throws \App\Classes\Exceptions\MalformedRequestException + */ public function execute(Booking $model) { return $this->handler($model); } diff --git a/app/Classes/Modules/Bookings/Services/FetchesBookingQuotation.php b/app/Classes/Modules/Bookings/Services/FetchesBookingQuotation.php new file mode 100644 index 00000000..17d776fd --- /dev/null +++ b/app/Classes/Modules/Bookings/Services/FetchesBookingQuotation.php @@ -0,0 +1,55 @@ +fetchesCompanyServiceSettings = $fetchesCompanyServiceSettings; + $this->fetchesCurrency = $fetchesCurrency; + } + + + /** + * @param Company $company + * @param CurrencyConversionObject $conversionObject + * @return CalculationObject + * @throws MalformedRequestException + */ + public function execute(Company $company, CurrencyConversionObject $conversionObject){ + if($conversionObject->getAmount() <= 0) throw new MalformedRequestException('Your transfer must be greater than zero.'); + + $configurations = $this->fetchesCompanyServiceSettings->execute($company, $conversionObject); + + /** @var Currency $currency */ + $currency = $this->fetchesCurrency->execute(['id' => $conversionObject->getCurrencyId()]); + if($conversionObject->getAmount() > $configurations->getMaxLimit()) throw new MalformedRequestException('Your transfer can\'t be greater than '.number_format( floatval(str_replace(',', '', $configurations->getMaxLimit())), 2, '.', ',').' '.$currency->short_code); + + $calculationObject = new CalculationObject($conversionObject, $configurations); + + return $calculationObject; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/GeneratesBookingMarking.php b/app/Classes/Modules/Bookings/Services/GeneratesBookingMarking.php index 0e920ab8..3e58e945 100644 --- a/app/Classes/Modules/Bookings/Services/GeneratesBookingMarking.php +++ b/app/Classes/Modules/Bookings/Services/GeneratesBookingMarking.php @@ -24,7 +24,7 @@ class GeneratesBookingMarking */ public function execute(): int { - $marking = mt_rand(100000001, 999999999); + $marking = mt_rand(20000, 99999); return !$this->bookingMarkingExists->execute($marking) ? $marking : self::execute(); } diff --git a/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php b/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php new file mode 100644 index 00000000..0b631b54 --- /dev/null +++ b/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php @@ -0,0 +1,30 @@ + new BankResource(Bank::find($calculationObject->getConfigurations()->getBankId())), + 'rate' => $calculationObject->getConfigurations()->getRate(), + 'local_total' => $calculationObject->getLocalTotal(), + 'foreign_total' => $calculationObject->getForeignTotal(), + 'conversion_amount' => $calculationObject->getConversionTotal(), + 'service_charge' => $calculationObject->getServiceCharge(), + 'tax_total' => $calculationObject->getTax(), + 'tax' => $calculationObject->getConfigurations()->getTax(), + 'sub_total' => $calculationObject->getSubTotal(), + 'total' => $calculationObject->getTotal(), + 'date' => Carbon::now()->timezone('Asia/Singapore')->format('h:i a, jS M, Y \G\M\T T'), + 'payment_attempt_limit' => $paymentAttemptLimit + ]; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/ListsBookings.php b/app/Classes/Modules/Bookings/Services/ListsBookings.php index f2aa1f1c..fb1ef526 100644 --- a/app/Classes/Modules/Bookings/Services/ListsBookings.php +++ b/app/Classes/Modules/Bookings/Services/ListsBookings.php @@ -22,10 +22,10 @@ class ListsBookings extends AbstractListRecord } /** - * @return Booking + * @return Builder */ public function getRepository(): Builder { - return $this->repository; + return $this->repository->newQuery(); } } diff --git a/app/Classes/Modules/Bookings/Services/UpdatesBooking.php b/app/Classes/Modules/Bookings/Services/UpdatesBooking.php index b5350aa3..37ca5b7c 100644 --- a/app/Classes/Modules/Bookings/Services/UpdatesBooking.php +++ b/app/Classes/Modules/Bookings/Services/UpdatesBooking.php @@ -10,6 +10,7 @@ class UpdatesBooking extends AbstractUpdateRecord { /** + * @param Booking $model * @param BookingObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException diff --git a/app/Classes/Modules/Bookings/Standards/Rules/CanCreateBooking.php b/app/Classes/Modules/Bookings/Standards/Rules/CanCreateBooking.php index 22dadccf..7871acfe 100644 --- a/app/Classes/Modules/Bookings/Standards/Rules/CanCreateBooking.php +++ b/app/Classes/Modules/Bookings/Standards/Rules/CanCreateBooking.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Bookings\Standards\Rules; use App\Classes\General\Abstracts\AbstractRule; -use App\Classes\Modules\Bookings\DataTransferObjects\SegmentObject; +use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject; use App\Classes\Modules\Bookings\Standards\Validators\BookingValidation; class CanCreateBooking extends AbstractRule @@ -27,16 +27,11 @@ class CanCreateBooking extends AbstractRule */ protected function authorized(): bool { - // TODO Set Authorization rules - if (!\Auth::user()->can('add booking')) { - return false; - } - return true; } /** - * @param SegmentObject $object + * @param BookingObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -46,7 +41,7 @@ class CanCreateBooking extends AbstractRule } /** - * @param SegmentObject $object + * @param BookingObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/CurrencyRates/Standards/Rules/CanFetchCurrencyRate.php b/app/Classes/Modules/Bookings/Standards/Rules/CanFetchBooking.php similarity index 62% rename from app/Classes/Modules/CurrencyRates/Standards/Rules/CanFetchCurrencyRate.php rename to app/Classes/Modules/Bookings/Standards/Rules/CanFetchBooking.php index db751d2f..c6f17684 100644 --- a/app/Classes/Modules/CurrencyRates/Standards/Rules/CanFetchCurrencyRate.php +++ b/app/Classes/Modules/Bookings/Standards/Rules/CanFetchBooking.php @@ -1,12 +1,12 @@ $object->getCompanyId(), + 'service_id' => $object->getServiceId(), 'transferable_bank_id' => $object->getTransferableBankId(), 'marking' => $object->getMarking(), - 'reference' => $object->getReference(), 'fix_amount' => $object->getFixAmount(), 'fix_currency_id' => $object->getFixCurrencyId(), 'convertible_currency_id' => $object->getConvertibleCurrencyId(), @@ -31,10 +30,9 @@ class BookingValidation extends AbstractValidation protected function rules(): array { return [ - 'company_id' => 'required', + 'service_id' => 'required', 'transferable_bank_id' => 'required', 'marking' => 'required', - 'reference' => 'required', 'fix_amount' => 'required', 'fix_currency_id' => 'required', 'convertible_currency_id' => 'required', diff --git a/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php new file mode 100644 index 00000000..d5e052a9 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php @@ -0,0 +1,91 @@ + 'Approve Document', + 'message' => 'You have successfully approved the Document' + ]; + } + + /** @var CanApproveDocument*/ + private $canApproveDocument; + + /** @var ApprovesDocument */ + private $approvesDocument; + + /** @var RejectsDocument */ + private $rejectsDocument; + + /** @var FetchesDocument */ + private $fetchesDocument; + + /** @var UpdatesCompanyStatus */ + private $updatesCompanyStatus; + + /** + * ApproveIdentificationDocumentLogic constructor. + * @param CanApproveDocument $canApproveDocument + * @param ApprovesDocument $approvesDocument + * @param RejectsDocument $rejectsDocument + * @param FetchesDocument $fetchesDocument + * @param UpdatesCompanyStatus $updatesCompanyStatus + */ + public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus) + { + $this->canApproveDocument = $canApproveDocument; + $this->approvesDocument = $approvesDocument; + $this->rejectsDocument = $rejectsDocument; + $this->fetchesDocument = $fetchesDocument; + $this->updatesCompanyStatus = $updatesCompanyStatus; + } + + /** + * @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 + { + + $status = $request->route('status'); + + /** @var Document $document */ + $document = $this->fetchesDocument->execute(['id' => $request->route('document_id')]); + + $this->canApproveDocument->passes(); + + $document = $status === 'approve' ? $this->approvesDocument->execute($document) : $this->rejectsDocument->execute($document); + + $this->updatesCompanyStatus->execute($document->owner, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); + + return $this->resourceResponse(new DocumentResource($document)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php new file mode 100644 index 00000000..17a6c900 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php @@ -0,0 +1,59 @@ + 'Assign Company To Segment', + 'message' => 'You have successfully assigned Company to segment' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var AssignSegmentProcessor */ + private $assignCompanyToSegmentProcessor; + + /** + * AssignCompanyToSegmentLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param AssignSegmentProcessor $assignCompanyToSegmentProcessor + */ + public function __construct(FetchesCompany $fetchesCompany, AssignSegmentProcessor $assignCompanyToSegmentProcessor) + { + $this->fetchesCompany = $fetchesCompany; + $this->assignCompanyToSegmentProcessor = $assignCompanyToSegmentProcessor; + } + + /** + * @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 + { + + $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $this->assignCompanyToSegmentProcessor->execute($company, $request->input('segment_id')); + + return $this->resourceResponse(new CompanyResource($company)); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/CreateCompanyLogic.php b/app/Classes/Modules/Companies/ControllersLogic/CreateCompanyLogic.php index 62292083..019fe833 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/CreateCompanyLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/CreateCompanyLogic.php @@ -3,15 +3,25 @@ namespace App\Classes\Modules\Companies\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Companies\Processors\CreateCompanyProcessor; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\ValueObjects\Constants\BusinessType; +use App\Classes\ValueObjects\Constants\CompanyType; use App\Http\Resources\CompanyResource; -use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class CreateCompanyLogic extends AbstractControllersLogic +class CreateCompanyLogic extends AbstractControllerLogic { + /** + * CreateCompanyLogic constructor. + * @param CreateCompanyProcessor $createCompanyProcessor + */ + public function __construct(CreateCompanyProcessor $createCompanyProcessor) + { + $this->createCompanyProcessor = $createCompanyProcessor; + } /** * @return array @@ -26,30 +36,18 @@ class CreateCompanyLogic extends AbstractControllersLogic /** @var CreateCompanyProcessor */ private $createCompanyProcessor; - /** - * CreateCompanyLogic constructor. - * @param CreateCompanyProcessor $createCompanyProcessor - */ - public function __construct(CreateCompanyProcessor $createCompanyProcessor) - { - $this->createCompanyProcessor = $createCompanyProcessor; - } /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { - - return $this->resourceResponse(new CompanyResource($this->createCompanyProcessor->execute($request))); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - + $company = $this->createCompanyProcessor->execute($request, BusinessType::CURRENCY_VENDOR, CompanyType::COMPANY_BUSINESS, ApprovalStatus::APPROVED); + return $this->resourceResponse(new CompanyResource($company)); } } \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/CreateIdentificationDocumentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/CreateIdentificationDocumentLogic.php new file mode 100644 index 00000000..bbf91ea7 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/CreateIdentificationDocumentLogic.php @@ -0,0 +1,84 @@ + 'Created Identification Document', + 'message' => 'You have successfully created a new identification document' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFile; + + /** @var UpdatesCompanyStatus */ + private $updatesCompanyStatus; + + + /** + * CreateIdentificationDocumentLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param CreatesDocument $createsDocument + * @param CreatesFiles $createsFile + * @param UpdatesCompanyStatus $updatesCompanyStatus + */ + public function __construct(FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesCompanyStatus $updatesCompanyStatus) + { + $this->fetchesCompany = $fetchesCompany; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + $this->updatesCompanyStatus = $updatesCompanyStatus; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + /** @var Company $company */ + $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); + $object = new DocumentObject($company->type === CompanyType::COMPANY_BUSINESS ? + DocumentType::SSM_REGISTRATION : DocumentType::IDENTITY_CARD, $request->input('files'), + $request->input('identification_no'), ApprovalStatus::PENDING_VERIFICATION, 'identifications'); + + /** @var Document $document */ + $document = $this->createsDocument->execute($company, $object); + $this->createsFile->execute($document, $object); + + $this->updatesCompanyStatus->execute($company, ApprovalStatus::PENDING_VERIFICATION); + + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/DeleteCompanyLogic.php b/app/Classes/Modules/Companies/ControllersLogic/DeleteCompanyLogic.php index aa4ea625..ac5dabb0 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/DeleteCompanyLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/DeleteCompanyLogic.php @@ -3,15 +3,14 @@ namespace App\Classes\Modules\Companies\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Companies\Services\DeletesCompany; use App\Classes\Modules\Companies\Services\FetchesCompany; use App\Classes\Modules\Companies\Standards\Rules\CanDeleteCompany; -use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class DeleteCompanyLogic extends AbstractControllersLogic +class DeleteCompanyLogic extends AbstractControllerLogic { /** * @return array @@ -31,7 +30,7 @@ class DeleteCompanyLogic extends AbstractControllersLogic private $deletesCompany; /** @var FetchesCompany */ - private $fetchesCompany; + private $fetchesCompany; /** * DeleteCompanyLogic constructor. @@ -50,23 +49,20 @@ class DeleteCompanyLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { - $this->canDeleteCompany->passes(); + $this->canDeleteCompany->passes(); - $query = $this->fetchesCompany->execute(['id' => $request->route('id')]); + $query = $this->fetchesCompany->execute(['id' => $request->route('id')]); - $this->deletesCompany->execute($query); + $this->deletesCompany->execute($query); - return $this->response([]); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->response([]); } diff --git a/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyBookingQuotationLogic.php b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyBookingQuotationLogic.php new file mode 100644 index 00000000..37225631 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyBookingQuotationLogic.php @@ -0,0 +1,79 @@ + 'Fetch Currency Conversion', + 'message' => 'You have successfully retrieved a currency conversion' + ]; + } + + + /** @var FetchesBookingQuotation */ + private $fetchBookingQuotation; + + /** @var GeneratesBookingQuotation */ + private $generatesBookingQuotation; + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + /** + * FetchCompanyBookingQuotationLogic constructor. + * @param FetchesBookingQuotation $fetchBookingQuotation + * @param GeneratesBookingQuotation $generatesBookingQuotation + * @param FetchesCurrency $fetchesCurrency + */ + public function __construct(FetchesBookingQuotation $fetchBookingQuotation, GeneratesBookingQuotation $generatesBookingQuotation, FetchesCurrency $fetchesCurrency) + { + $this->fetchBookingQuotation = $fetchBookingQuotation; + $this->generatesBookingQuotation = $generatesBookingQuotation; + $this->fetchesCurrency = $fetchesCurrency; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws MalformedRequestException + * @throws RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + /** @var Company $company */ + $company = Company::find($request->route('id')); + + $conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $request->input('amount'))), $request->input('currency_id'), $request->input('service_id'), $request->input('type')); + + $calculationObject = $this->fetchBookingQuotation->execute($company, $conversionObject); + + /** @var Currency $currency */ + $currency = $this->fetchesCurrency->execute(['id' => $conversionObject->getCurrencyId()]); + if($calculationObject->getConvertibleTotal() < $calculationObject->getConfigurations()->getMinLimit()) throw new RequestValidationException('Your transfer is below the minimum amount allowed of '.$calculationObject->getConfigurations()->getMinLimit().' '.$currency->short_code); + + //TODO add po limit validation + return $this->response(['data' => $this->generatesBookingQuotation->execute($calculationObject)]); + + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyLogic.php b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyLogic.php index b64ac700..5406d682 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyLogic.php @@ -3,16 +3,15 @@ namespace App\Classes\Modules\Companies\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Companies\Services\FetchesCompany; use App\Classes\Modules\Companies\Standards\Rules\CanFetchCompany; -use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject; use App\Http\Resources\CompanyResource; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class FetchCompanyLogic extends AbstractControllersLogic +class FetchCompanyLogic extends AbstractControllerLogic { /** @@ -46,21 +45,16 @@ class FetchCompanyLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { + $this->canFetchCompany->passes(); - $this->canFetchCompany->passes(); + $query = $this->fetchesCompany->execute(['id' => $request->route('id'), 'with_bookings' => true]); - $query = $this->fetchesCompany->execute(['id' => $request->route('id')]); - - return $this->resourceResponse(new CompanyResource($query)); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->resourceResponse(new CompanyResource($query)); } diff --git a/app/Classes/Modules/Companies/ControllersLogic/ListCompaniesLogic.php b/app/Classes/Modules/Companies/ControllersLogic/ListCompaniesLogic.php index dbfd108c..80b15c1c 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/ListCompaniesLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/ListCompaniesLogic.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Companies\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Companies\Services\ListsCompanies; use App\Classes\Modules\Companies\Standards\Rules\CanListCompanies; use App\Http\Resources\CompanyResource; @@ -11,7 +11,7 @@ use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class ListCompaniesLogic extends AbstractControllersLogic +class ListCompaniesLogic extends AbstractControllerLogic { /** @@ -45,19 +45,16 @@ class ListCompaniesLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { - $this->canListCompanies->passes(); - - $query = $this->listsCompanies->execute($this->listsCompanies->deserializeFilters($request->input('filters'))); - return $this->collectionResponse(CompanyResource::collection($query)); + $this->canListCompanies->passes(); - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + $query = $this->listsCompanies->execute($this->listsCompanies->deserializeFilters($request->input('filters'))); + return $this->collectionResponse(CompanyResource::collection($query)); } diff --git a/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php new file mode 100644 index 00000000..10623311 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php @@ -0,0 +1,65 @@ + 'Detach Company From Segment', + 'message' => 'You have successfully detached Company from segment' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** @var RemovesCompanyFromSegment */ + private $removesCompanyFromSegment; + + /** + * RemoveCompanyFromSegmentLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param FetchesSegment $fetchesSegment + * @param RemovesCompanyFromSegment $removesCompanyFromSegment + */ + public function __construct(FetchesCompany $fetchesCompany, FetchesSegment $fetchesSegment, RemovesCompanyFromSegment $removesCompanyFromSegment) + { + $this->fetchesCompany = $fetchesCompany; + $this->fetchesSegment = $fetchesSegment; + $this->removesCompanyFromSegment = $removesCompanyFromSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $segment = $this->fetchesSegment->execute(['id' => $request->route('segment_id')]); + + $this->removesCompanyFromSegment->execute($company, $segment); + + return $this->resourceResponse(new CompanyResource($company)); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyLogic.php index 597d2ede..c435dab4 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyLogic.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Companies\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Companies\Services\UpdatesCompany; use App\Classes\Modules\Companies\Services\FetchesCompany; use App\Classes\Modules\Companies\Standards\Rules\CanUpdateCompany; @@ -13,7 +13,7 @@ use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class UpdateCompanyLogic extends AbstractControllersLogic +class UpdateCompanyLogic extends AbstractControllerLogic { /** diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateSupplierCurrenciesLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateSupplierCurrenciesLogic.php new file mode 100644 index 00000000..1f7f6853 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateSupplierCurrenciesLogic.php @@ -0,0 +1,104 @@ + 'Updated Supplier', + 'message' => 'You have successfully updated the Supplier' + ]; + } + + /** @var CanCreateConstant */ + private $canCreateConstant; + + /** @var CanUpdateConstant */ + private $canUpdateConstant; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** @var FetchesConstant */ + private $fetchesConstant; + + /** @var UpdatesConstant */ + private $updatesConstant; + + /** @var CreatesConstant */ + private $createsConstant; + + + /** + * UpdateSupplierCurrenciesLogic constructor. + * @param CanCreateConstant $canCreateConstant + * @param CanUpdateConstant $canUpdateConstant + * @param FetchesSegment $fetchesSegment + * @param FetchesConstant $fetchesConstant + * @param UpdatesConstant $updatesConstant + * @param CreatesConstant $createsConstant + */ + public function __construct(CanCreateConstant $canCreateConstant, CanUpdateConstant $canUpdateConstant, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant, UpdatesConstant $updatesConstant, CreatesConstant $createsConstant) + { + $this->canCreateConstant = $canCreateConstant; + $this->canUpdateConstant = $canUpdateConstant; + $this->fetchesSegment = $fetchesSegment; + $this->fetchesConstant = $fetchesConstant; + $this->updatesConstant = $updatesConstant; + $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 + { + + $supplierId = $request->route('id'); + + $object = new ConstantObject('Supplier\'s Currencies',SegmentConstants::SUPPLIER_CURRENCIES, + [ + 'id' => $supplierId, 'currencies' => $request->input('currencies') + ] + ); + + try { + $constant = $this->fetchesConstant->execute(['supplier_currencies' => $supplierId]); + $this->canUpdateConstant->passes($object); + $this->updatesConstant->execute($constant, $object); + + } catch (\Exception $exception) { + $this->canCreateConstant->passes($object); + $segment = $this->fetchesSegment->execute(['type' => SegmentConstants::STANDARD_SEGMENT]); + $constant = $this->createsConstant->execute($segment, $object); + } + + return $this->resourceResponse(new ConstantResource($constant)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php b/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php index da9905e9..09b0e153 100644 --- a/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php +++ b/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php @@ -2,40 +2,48 @@ namespace App\Classes\Modules\Companies\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\ValueObjects\Constants\BusinessType; class CompanyObject implements DataTransferObject { - /** @var string|null */ + /** @var string */ private $name; - /** @var string|null */ + /** @var string */ private $reference; - /** @var int */ + /** @var int|null */ + private $businessType; + + /** @var int|null */ private $type; + /** @var int|null */ + private $status; + /** * CompanyObject constructor. - * @param string|null $name - * @param string|null $reference - * @param string|null $type + * @param string $name + * @param string $reference + * @param int|null $businessType + * @param int|null $type + * @param int|null $status */ - public function __construct( - ?string $name, - ?string $reference, - ?string $type - ) + public function __construct(string $name, string $reference, ?int $businessType = BusinessType::IMPORTER, ?int $type = BusinessType::IMPORTER, ?int $status = ApprovalStatus::PENDING_SUBMISSION) { $this->name = $name; $this->reference = $reference; + $this->businessType = $businessType; $this->type = $type; + $this->status = $status; } /** * @return string */ - public function getName(): ?string + public function getName(): string { return $this->name; } @@ -43,7 +51,7 @@ class CompanyObject implements DataTransferObject /** * @return string */ - public function getReference(): ?string + public function getReference(): string { return $this->reference; } @@ -51,8 +59,28 @@ class CompanyObject implements DataTransferObject /** * @return int */ - public function getType(): ?int + public function getBusinessType(): int + { + return $this->businessType; + } + + /** + * @return int + */ + public function getType(): int { return $this->type; } + + /** + * @return int + */ + public function getStatus(): int + { + return $this->status; + } + + + + } \ No newline at end of file diff --git a/app/Classes/Modules/Companies/DataTransferObjects/CompanyServiceConfigurationsObject.php b/app/Classes/Modules/Companies/DataTransferObjects/CompanyServiceConfigurationsObject.php new file mode 100644 index 00000000..ab47b73d --- /dev/null +++ b/app/Classes/Modules/Companies/DataTransferObjects/CompanyServiceConfigurationsObject.php @@ -0,0 +1,203 @@ +isBillable = $isBillable; + $this->bankId = $bankId; + $this->poLimit = $poLimit; + $this->tax = $tax; + $this->serviceCharge = $serviceCharge; + $this->minimumCharge = $minimumCharge; + $this->maxLimit = $maxLimit; + $this->minLimit = $minLimit; + $this->rate = $rate; + } + + + /** + * @param int $poLimit + */ + public function setPoLimit(int $poLimit): void + { + $this->poLimit = $poLimit; + } + + /** + * @param int $bankId + */ + public function setBankId(int $bankId): void + { + $this->bankId = $bankId; + } + + + + /** + * @param float $tax + */ + public function setTax(float $tax): void + { + $this->tax = $tax; + } + + /** + * @param float $serviceCharge + */ + public function setServiceCharge(float $serviceCharge): void + { + $this->serviceCharge = $serviceCharge; + } + + /** + * @param float $minimumCharge + */ + public function setMinimumCharge(float $minimumCharge): void + { + $this->minimumCharge = $minimumCharge; + } + + /** + * @param float $maxLimit + */ + public function setMaxLimit(float $maxLimit): void + { + $this->maxLimit = $maxLimit; + } + + /** + * @param float $minLimit + */ + public function setMinLimit(float $minLimit): void + { + $this->minLimit = $minLimit; + } + + /** + * @param float $rate + */ + public function setRate(float $rate): void + { + $this->rate = $rate; + } + + /** + * @return bool + */ + public function isBillable(): bool + { + return $this->isBillable; + } + + /** + * @return int + */ + public function getBankId(): int + { + return $this->bankId; + } + + /** + * @return int + */ + public function getPoLimit(): int + { + return $this->poLimit; + } + + /** + * @return float + */ + public function getTax(): float + { + return $this->tax; + } + + /** + * @return float + */ + public function getServiceCharge(): float + { + return $this->serviceCharge; + } + + /** + * @return float + */ + public function getMinimumCharge(): float + { + return $this->minimumCharge; + } + + /** + * @return float + */ + public function getMaxLimit(): float + { + return $this->maxLimit; + } + + /** + * @return float + */ + public function getMinLimit(): float + { + return $this->minLimit; + } + + /** + * @return float + */ + public function getRate(): float + { + return $this->rate; + } + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/DataTransferObjects/ConnectionObject.php b/app/Classes/Modules/Companies/DataTransferObjects/ConnectionObject.php deleted file mode 100644 index 078378b4..00000000 --- a/app/Classes/Modules/Companies/DataTransferObjects/ConnectionObject.php +++ /dev/null @@ -1,45 +0,0 @@ -inviter = $inviter; - $this->invitee = $invitee; - } - - /** - * @return CompanyModule - */ - public function getInviter(): CompanyModule - { - return $this->inviter; - } - - /** - * @return CompanyModule - */ - public function getInvitee(): CompanyModule - { - return $this->invitee; - } - - -} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/DataTransferObjects/EmployeeObject.php b/app/Classes/Modules/Companies/DataTransferObjects/EmployeeObject.php deleted file mode 100644 index 816a2de5..00000000 --- a/app/Classes/Modules/Companies/DataTransferObjects/EmployeeObject.php +++ /dev/null @@ -1,58 +0,0 @@ -companyModule = $companyModule; - $this->user = $user; - $this->role = $role; - } - - /** - * @return CompanyModule - */ - public function getCompanyModule(): CompanyModule - { - return $this->companyModule; - } - - /** - * @return User - */ - public function getUser(): User - { - return $this->user; - } - - /** - * @return int - */ - public function getRole(): int - { - return $this->role; - } - - -} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/DataTransferObjects/EmploymentObject.php b/app/Classes/Modules/Companies/DataTransferObjects/EmploymentObject.php new file mode 100644 index 00000000..8a6781a0 --- /dev/null +++ b/app/Classes/Modules/Companies/DataTransferObjects/EmploymentObject.php @@ -0,0 +1,58 @@ +company = $company; + $this->user = $user; + $this->status = $status; + } + + /** + * @return Company + */ + public function getCompany(): Company + { + return $this->company; + } + + /** + * @return User + */ + public function getUser(): User + { + return $this->user; + } + + /** + * @return int + */ + public function getStatus(): int + { + return $this->status; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/DataTransferObjects/ModuleObject.php b/app/Classes/Modules/Companies/DataTransferObjects/ModuleObject.php deleted file mode 100644 index 732799a3..00000000 --- a/app/Classes/Modules/Companies/DataTransferObjects/ModuleObject.php +++ /dev/null @@ -1,44 +0,0 @@ -company = $company; - $this->type = $type; - } - - /** - * @return Company - */ - public function getCompany(): Company - { - return $this->company; - } - - /** - * @return int - */ - public function getType(): int - { - return $this->type; - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Processors/AssignEmployeeProcessor.php b/app/Classes/Modules/Companies/Processors/AssignEmployeeProcessor.php new file mode 100644 index 00000000..e583833d --- /dev/null +++ b/app/Classes/Modules/Companies/Processors/AssignEmployeeProcessor.php @@ -0,0 +1,48 @@ +canAssignEmployee = $canAssignEmployee; + $this->assignsEmployee = $assignsEmployee; + } + + /** + * @param EmploymentObject $object + * @return Model + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function execute(EmploymentObject $object): Model { + + $this->canAssignEmployee->passes($object); + + return $this->assignsEmployee->execute($object); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Processors/AssignSegmentProcessor.php b/app/Classes/Modules/Companies/Processors/AssignSegmentProcessor.php new file mode 100644 index 00000000..66cfb08e --- /dev/null +++ b/app/Classes/Modules/Companies/Processors/AssignSegmentProcessor.php @@ -0,0 +1,56 @@ +canAssignSegment = $canAssignSegment; + $this->assignsSegment = $assignsSegment; + $this->fetchesSegment = $fetchesSegment; + } + + + /** + * @param Company $company + * @param int|null $segmentId + * @return Model + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function execute(Company $company, ?int $segmentId = SegmentConstants::STANDARD_SEGMENT): Model { + + $segment = $this->fetchesSegment->execute(['id' => $segmentId]); + + $this->canAssignSegment->passes(); + + return $this->assignsSegment->execute($company, $segment); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php b/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php new file mode 100644 index 00000000..4e188015 --- /dev/null +++ b/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php @@ -0,0 +1,59 @@ +canCreateCompany = $canCreateCompany; + $this->createsCompany = $createsCompany; + } + + + /** + * @param Request $request + * @param int $businessType + * @param int|null $companyType + * @param int|null $status + * @return Model + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function execute(Request $request, int $businessType = BusinessType::IMPORTER, ?int $companyType = CompanyType::COMPANY_BUSINESS, ?int $status = ApprovalStatus::PENDING_SUBMISSION): Model { + + $company_object = new CompanyObject( + $companyType === CompanyType::COMPANY_BUSINESS ? $request->input('company_name') : $request->input('name'), + mt_rand(1000, 9999).(new GeneratesInitials())->name($request->input('company_name'))->length(3)->generate(), + $businessType, $companyType, $status); + + $this->canCreateCompany->passes($company_object); + + return $this->createsCompany->execute($company_object); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/AddCurrenciesResourceToSupplierCompany.php b/app/Classes/Modules/Companies/Services/AddCurrenciesResourceToSupplierCompany.php new file mode 100644 index 00000000..dea32a07 --- /dev/null +++ b/app/Classes/Modules/Companies/Services/AddCurrenciesResourceToSupplierCompany.php @@ -0,0 +1,27 @@ +business_type === BusinessType::CURRENCY_VENDOR){ + $segment = SegmentConstant::where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $company->id)->first(); + + return ['currencies' => CurrencyResource::collection($segment ? Currency::whereIn('id', $segment->detail->currencies)->get() : [])]; + } + + return []; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/AssignsCompanyToSegment.php b/app/Classes/Modules/Companies/Services/AssignsCompanyToSegment.php new file mode 100644 index 00000000..81b6e964 --- /dev/null +++ b/app/Classes/Modules/Companies/Services/AssignsCompanyToSegment.php @@ -0,0 +1,33 @@ +segments()->attach($segment); + + return $company; + + } catch (QueryException $exception){ + throw new MalformedRequestException($exception); + } + + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/AssignsEmployee.php b/app/Classes/Modules/Companies/Services/AssignsEmployee.php new file mode 100644 index 00000000..229bcbd4 --- /dev/null +++ b/app/Classes/Modules/Companies/Services/AssignsEmployee.php @@ -0,0 +1,31 @@ +getCompany()->employees()->attach($object->getUser(), ['status' => $object->getStatus()]); + + return $object->getCompany(); + + } catch (QueryException $exception){ + throw new MalformedRequestException($exception); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/CreatesCompany.php b/app/Classes/Modules/Companies/Services/CreatesCompany.php index 722a9de6..cbe22161 100644 --- a/app/Classes/Modules/Companies/Services/CreatesCompany.php +++ b/app/Classes/Modules/Companies/Services/CreatesCompany.php @@ -20,6 +20,7 @@ class CreatesCompany extends AbstractUpdateRecord $model->name = $object->getName(); $model->reference = $object->getReference(); $model->type = $object->getType(); + $model->business_type = $object->getBusinessType(); return $this->handler($model); } diff --git a/app/Classes/Modules/Companies/Services/DeletesCompany.php b/app/Classes/Modules/Companies/Services/DeletesCompany.php new file mode 100644 index 00000000..963e6fd0 --- /dev/null +++ b/app/Classes/Modules/Companies/Services/DeletesCompany.php @@ -0,0 +1,20 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/FetchesCompanyPaymentAttemptLimit.php b/app/Classes/Modules/Companies/Services/FetchesCompanyPaymentAttemptLimit.php new file mode 100644 index 00000000..cf43840b --- /dev/null +++ b/app/Classes/Modules/Companies/Services/FetchesCompanyPaymentAttemptLimit.php @@ -0,0 +1,23 @@ +segments()->with([ + 'constants' => function ($query) { + $query->where('reference', SegmentConstants::PAYMENT_ATTEMPT_DURATION_LIMIT); + }])->get()->pluck('constants')->flatten()->pluck('detail')->max('minutes'); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/FetchesCompanyServiceSettings.php b/app/Classes/Modules/Companies/Services/FetchesCompanyServiceSettings.php new file mode 100644 index 00000000..a3827892 --- /dev/null +++ b/app/Classes/Modules/Companies/Services/FetchesCompanyServiceSettings.php @@ -0,0 +1,108 @@ +services()->where('id', $object->getServiceId())->first(); + + $constants= $service->constants()->whereIn('segment_id', $company->segments->pluck('id'))->get(); + + $standardConfigurations = $constants->firstWhere('reference', SegmentConstants::SERVICE_TYPE); + + $rate = Currency::find($object->getCurrencyId())->rates->where('payment_method_type', $object->getPaymentMethod()) + ->where('service_id', $object->getServiceId())->first(); + + $currency = collect($standardConfigurations->detail->currencies)->firstWhere('id','=', $object->getCurrencyId()); + + $standardConfigurations = new CompanyServiceConfigurationsObject($standardConfigurations->detail->is_billable, $standardConfigurations->detail->bank_id, $standardConfigurations->detail->po_limit->value, $standardConfigurations->detail->tax->value, + $standardConfigurations->detail->service_charge->value, $standardConfigurations->detail->minimum_charge->value, + $currency->max_limit->value, $currency->min_limit->value, $rate->selling); + + if($this->hasCustomOptions($constants)){ + $customOptions = $this->getServiceCustomOptions($constants, $object, $standardConfigurations, $object->getPaymentMethod())->sortByDesc(function($option) use($object) { + return (new CalculationObject($object, $option))->getTotal(); + })->first(); + + return $customOptions; + }; + + return $standardConfigurations; + } + + /** + * @param $constants + * @param CurrencyConversionObject $object + * @param CompanyServiceConfigurationsObject $standardConfigurations + * @return mixed + */ + private function getServiceCustomOptions($constants, CurrencyConversionObject $object, CompanyServiceConfigurationsObject $standardConfigurations){ + return $constants->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->map(function($constant) use($object, $standardConfigurations) { + + $customOptions = clone $standardConfigurations; + + $methods = collect(Helper::getClassMethodsArray(CompanyServiceConfigurationsObject::class))->filter(function($value){ return substr( $value, 0, 3) === "get"; }); + + $methods->map(function($methodName) use ($constant, $object, $customOptions) { + $option = Helper::getPropertyName($methodName); + + $setMethod = 'set'.Str::studly($option); + + if(in_array($option, ['min_limit', 'max_limit', 'rate']) && !empty($constant->detail->currencies)) { + + $currency = collect($constant->detail->currencies)->firstWhere('id','=', $object->getCurrencyId()); + + if($currency) { + if($option === 'rate') { + return $customOptions->$setMethod(collect($currency->rates)->firstWhere('payment_type','=', $object->getPaymentMethod())->selling->value); + } + + return $customOptions->$setMethod($currency->$option->value); + } + + }; + + if(property_exists($constant->detail, $option)) { + + if($option === 'bank') return $customOptions->$setMethod($constant->detail->bank_id); + + return $customOptions->$setMethod($constant->detail->$option->value); + } + }); + + return $customOptions; + + }); + + } + + private function hasCustomOptions(Collection $constants){ + return $constants->contains(function($value){ + return $value->reference === SegmentConstants::CUSTOM_SERVICE_TYPE; + }); + } + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/FetchesCompanyServices.php b/app/Classes/Modules/Companies/Services/FetchesCompanyServices.php new file mode 100644 index 00000000..d78fca75 --- /dev/null +++ b/app/Classes/Modules/Companies/Services/FetchesCompanyServices.php @@ -0,0 +1,29 @@ +map(function($service){ + $currencies = collect($service->getConfigurations()->detail->currencies)->pluck('id'); + if(!empty($service->getCustomOptions())){ + $currencies = $currencies->merge(collect($service->getCustomOptions())->flatMap(function($configurations){ + return collect($configurations->getConfigurationValue('currencies'))->pluck('id'); + })); + } + + return [ + 'id' => $service->getService()->id, + 'name' => $service->getService()->name, + 'currencies' => CurrencyResource::collection(Currency::whereIn('id', $currencies->filter()->unique()->toArray())->get()) + ]; + }); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/RemovesCompanyFromSegment.php b/app/Classes/Modules/Companies/Services/RemovesCompanyFromSegment.php new file mode 100644 index 00000000..d234bcb5 --- /dev/null +++ b/app/Classes/Modules/Companies/Services/RemovesCompanyFromSegment.php @@ -0,0 +1,33 @@ +segments()->detach($segment); + + return $company; + + } catch (QueryException $exception){ + throw new MalformedRequestException($exception); + } + + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/UpdatesCompany.php b/app/Classes/Modules/Companies/Services/UpdatesCompany.php index 876221d1..f89bbca8 100644 --- a/app/Classes/Modules/Companies/Services/UpdatesCompany.php +++ b/app/Classes/Modules/Companies/Services/UpdatesCompany.php @@ -10,6 +10,7 @@ class UpdatesCompany extends AbstractUpdateRecord { /** + * @param Company $model * @param CompanyObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException diff --git a/app/Classes/Modules/Companies/Services/UpdatesCompanyStatus.php b/app/Classes/Modules/Companies/Services/UpdatesCompanyStatus.php new file mode 100644 index 00000000..f0c0968b --- /dev/null +++ b/app/Classes/Modules/Companies/Services/UpdatesCompanyStatus.php @@ -0,0 +1,25 @@ +status = $status; + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyEmployees/Standards/Rules/CanCreateCompanyEmployee.php b/app/Classes/Modules/Companies/Standards/Rules/CanAssignEmployee.php similarity index 71% rename from app/Classes/Modules/CompanyEmployees/Standards/Rules/CanCreateCompanyEmployee.php rename to app/Classes/Modules/Companies/Standards/Rules/CanAssignEmployee.php index d5d66023..f34f83ff 100644 --- a/app/Classes/Modules/CompanyEmployees/Standards/Rules/CanCreateCompanyEmployee.php +++ b/app/Classes/Modules/Companies/Standards/Rules/CanAssignEmployee.php @@ -1,13 +1,13 @@ documentValidation = $documentValidation; + } + + + /** + * @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 $this->documentValidation->validate($object); + } + + /** + * @param DocumentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Standards/Rules/CanUpdateCompany.php b/app/Classes/Modules/Companies/Standards/Rules/CanUpdateCompany.php index bf16fef8..c7bd1f70 100644 --- a/app/Classes/Modules/Companies/Standards/Rules/CanUpdateCompany.php +++ b/app/Classes/Modules/Companies/Standards/Rules/CanUpdateCompany.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Companies\Standards\Rules; use App\Classes\General\Abstracts\AbstractRule; -use App\Classes\Modules\Companies\DataTransferObjects\UserObject; +use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject; use App\Classes\Modules\Companies\Standards\Validators\CompanyValidation; class CanUpdateCompany extends AbstractRule @@ -31,7 +31,7 @@ class CanUpdateCompany extends AbstractRule } /** - * @param UserObject $object + * @param CompanyObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -41,7 +41,7 @@ class CanUpdateCompany extends AbstractRule } /** - * @param UserObject $object + * @param CompanyObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/CompanyEmployees/Standards/Validators/CompanyEmployeeValidation.php b/app/Classes/Modules/Companies/Standards/Validators/CompanyEmployeeValidation.php similarity index 65% rename from app/Classes/Modules/CompanyEmployees/Standards/Validators/CompanyEmployeeValidation.php rename to app/Classes/Modules/Companies/Standards/Validators/CompanyEmployeeValidation.php index 2de1f504..f396ac41 100644 --- a/app/Classes/Modules/CompanyEmployees/Standards/Validators/CompanyEmployeeValidation.php +++ b/app/Classes/Modules/Companies/Standards/Validators/CompanyEmployeeValidation.php @@ -1,21 +1,21 @@ $object->getCompanyId(), - 'user_id' => $object->getUserId(), + 'company_id' => $object->getCompany()->id, + 'user_id' => $object->getUser()->id, ]; } diff --git a/app/Classes/Modules/Companies/Standards/Validators/CompanyValidation.php b/app/Classes/Modules/Companies/Standards/Validators/CompanyValidation.php index 027d3287..efc47355 100644 --- a/app/Classes/Modules/Companies/Standards/Validators/CompanyValidation.php +++ b/app/Classes/Modules/Companies/Standards/Validators/CompanyValidation.php @@ -16,7 +16,7 @@ class CompanyValidation extends AbstractValidation return [ 'company_name' => $object->getName(), 'company_reference' => $object->getReference(), - 'type' => $object->getType() + 'type' => $object->getBusinessType() ]; } diff --git a/app/Classes/Modules/CompanyBanks/ControllersLogic/CreateCompanyBankLogic.php b/app/Classes/Modules/CompanyBanks/ControllersLogic/CreateCompanyBankLogic.php deleted file mode 100644 index c6188a90..00000000 --- a/app/Classes/Modules/CompanyBanks/ControllersLogic/CreateCompanyBankLogic.php +++ /dev/null @@ -1,81 +0,0 @@ - 'Created Company Bank', - 'message' => 'You have successfully created a new Company Bank' - ]; - } - - /** @var CanCreateCompanyBank */ - private $canCreateCompanyBank; - - /** @var CreatesCompanyBank */ - private $createsCompanyBank; - - - /** - * CreateCompanyBankLogic constructor. - * @param CanCreateCompanyBank $canCreateCompanyBank - * @param CreatesCompanyBank $createsCompanyBank - */ - public function __construct( - CanCreateCompanyBank $canCreateCompanyBank, - CreatesCompanyBank $createsCompanyBank - ) - { - $this->canCreateCompanyBank = $canCreateCompanyBank; - $this->createsCompanyBank = $createsCompanyBank; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $company_bank_object = new CompanyBankObject( - $request->input('country_id'), - $request->input('company_id'), - $request->input('bank_name'), - $request->input('holder_name'), - $request->input('account_no'), - $request->input('type'), - $request->input('default') - ); - $this->canCreateCompanyBank->passes($company_bank_object); - $company_bank_query = $this->createsCompanyBank->execute($company_bank_object); - - DB::commit(); - - return $this->resourceResponse(new CompanyBankResource($company_bank_query)); - - } catch (\Exception $exception) { - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/ControllersLogic/DeleteCompanyBankLogic.php b/app/Classes/Modules/CompanyBanks/ControllersLogic/DeleteCompanyBankLogic.php deleted file mode 100644 index 4c33e308..00000000 --- a/app/Classes/Modules/CompanyBanks/ControllersLogic/DeleteCompanyBankLogic.php +++ /dev/null @@ -1,83 +0,0 @@ - 'Delete Company Bank', - 'message' => 'You have successfully deleted the Company Bank' - ]; - } - - /** @var CanDeleteCompanyBank */ - private $canDeleteCompanyBank; - - /** @var DeletesCompanyBank */ - private $deletesCompanyBank; - - /** @var FetchesCompanyBank */ - private $fetchesCompanyBank; - - - /** - * DeleteCompanyBankLogic constructor. - * @param CanDeleteCompanyBank $canDeleteCompanyBank - * @param DeletesCompanyBank $deletesCompanyBank - * @param FetchesCompanyBank $fetchesCompanyBank - */ - public function __construct( - CanDeleteCompanyBank $canDeleteCompanyBank, - DeletesCompanyBank $deletesCompanyBank, - FetchesCompanyBank $fetchesCompanyBank - ) - { - $this->canDeleteCompanyBank = $canDeleteCompanyBank; - $this->deletesCompanyBank = $deletesCompanyBank; - $this->fetchesCompanyBank = $fetchesCompanyBank; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $company_bank_query = $this->fetchesCompanyBank->execute(['id' => $request->route('id')]); - $this->canDeleteCompanyBank->passes(); - $this->deletesCompanyBank->execute($company_bank_query); - - DB::commit(); - - return $this->resourceResponse(new CompanyBankResource($company_bank_query)); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/ControllersLogic/UpdateCompanyBankLogic.php b/app/Classes/Modules/CompanyBanks/ControllersLogic/UpdateCompanyBankLogic.php deleted file mode 100644 index b2b78ee5..00000000 --- a/app/Classes/Modules/CompanyBanks/ControllersLogic/UpdateCompanyBankLogic.php +++ /dev/null @@ -1,93 +0,0 @@ - 'Updated Company Bank', - 'message' => 'You have successfully updated the Company Bank' - ]; - } - - /** @var CanUpdateCompanyBank */ - private $canUpdateCompanyBank; - - /** @var UpdatesCompanyBank */ - private $updatesCompanyBank; - - /** @var FetchesCompanyBank */ - private $fetchesCompanyBank; - - - /** - * UpdateCompanyBankLogic constructor. - * @param CanUpdateCompanyBank $canUpdateCompanyBank - * @param UpdatesCompanyBank $updatesCompanyBank - * @param FetchesCompanyBank $fetchesCompanyBank - */ - public function __construct( - CanUpdateCompanyBank $canUpdateCompanyBank, - UpdatesCompanyBank $updatesCompanyBank, - FetchesCompanyBank $fetchesCompanyBank - ) - { - $this->canUpdateCompanyBank = $canUpdateCompanyBank; - $this->updatesCompanyBank = $updatesCompanyBank; - $this->fetchesCompanyBank = $fetchesCompanyBank; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $company_bank_query = $this->fetchesCompanyBank->execute(['id' => $request->route('id')]); - - $company_bank_object = new CompanyBankObject( - $company_bank_query->country_id, - $company_bank_query->company_id, - $request->input('bank_name'), - $request->input('holder_name'), - $request->input('account_no'), - $company_bank_query->type, - $company_bank_query->default - ); - $this->canUpdateCompanyBank->passes($company_bank_object); - $company_bank_query = $this->updatesCompanyBank->execute($company_bank_query, $company_bank_object); - - DB::commit(); - - return $this->resourceResponse(new CompanyBankResource($company_bank_query)); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/ControllersLogic/UpdateToDefaultCompanyBankLogic.php b/app/Classes/Modules/CompanyBanks/ControllersLogic/UpdateToDefaultCompanyBankLogic.php deleted file mode 100644 index 7b262260..00000000 --- a/app/Classes/Modules/CompanyBanks/ControllersLogic/UpdateToDefaultCompanyBankLogic.php +++ /dev/null @@ -1,118 +0,0 @@ - 'Updated Company Bank', - 'message' => 'You have successfully updated the Company Bank' - ]; - } - - /** @var CanUpdateCompanyBank */ - private $canUpdateCompanyBank; - - /** @var UpdatesToNonDefaultCompanyBank */ - private $updatesToNonDefaultCompanyBank; - - /** @var UpdatesToDefaultCompanyBank */ - private $updatesToDefaultCompanyBank; - - /** @var ListsCompanyBank */ - private $listsCompanyBank; - - /** @var FetchesCompanyBank */ - private $fetchesCompanyBank; - - /** - * UpdateToDefaultCompanyBankLogic constructor. - * @param CanUpdateCompanyBank $canUpdateCompanyBank - * @param UpdatesToDefaultCompanyBank $updatesToDefaultCompanyBank - * @param FetchesCompanyBank $fetchesCompanyBank - */ - public function __construct( - CanUpdateCompanyBank $canUpdateCompanyBank, - UpdatesToNonDefaultCompanyBank $updatesToNonDefaultCompanyBank, - UpdatesToDefaultCompanyBank $updatesToDefaultCompanyBank, - ListsCompanyBank $listsCompanyBank, - FetchesCompanyBank $fetchesCompanyBank - ) - { - $this->canUpdateCompanyBank = $canUpdateCompanyBank; - $this->updatesToNonDefaultCompanyBank = $updatesToNonDefaultCompanyBank; - $this->updatesToDefaultCompanyBank = $updatesToDefaultCompanyBank; - $this->listsCompanyBank = $listsCompanyBank; - $this->fetchesCompanyBank = $fetchesCompanyBank; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorExceptionn - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $company_bank_query = $this->fetchesCompanyBank->execute(['id' => $request->route('id')]); - - $default_list_company_bank = $this->listsCompanyBank->execute([ - 'not_id' => $company_bank_query->id, - 'company_id' => $company_bank_query->company_id, - 'default_type' => DefaultType::DEFAULT - ]); - - foreach ($default_list_company_bank as $key => $row) { - $this->updatesToNonDefaultCompanyBank->execute($row); - } - - $company_bank_object = new CompanyBankObject( - $company_bank_query->country_id, - $company_bank_query->company_id, - $request->input('bank_name'), - $request->input('holder_name'), - $request->input('account_no'), - $company_bank_query->type, - $company_bank_query->default - ); - $this->canUpdateCompanyBank->passes($company_bank_object); - - $company_bank_query = $this->updatesToDefaultCompanyBank->execute($company_bank_query); - - DB::commit(); - - return $this->resourceResponse(new CompanyBankResource($company_bank_query)); - - } catch (\Exception $exception){ - dd($exception); - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/DataTransferObjects/CompanyBankObject.php b/app/Classes/Modules/CompanyBanks/DataTransferObjects/CompanyBankObject.php deleted file mode 100644 index 38e441bd..00000000 --- a/app/Classes/Modules/CompanyBanks/DataTransferObjects/CompanyBankObject.php +++ /dev/null @@ -1,102 +0,0 @@ -country_id = $country_id; - $this->company_id = $company_id; - $this->bank_name = $bank_name; - $this->holder_name = $holder_name; - $this->account_no = $account_no; - $this->type = $type; - $this->default = $default; - } - - /** - * @return int - */ - public function getCountryId(): ?int - { - return $this->country_id; - } - - /** - * @return int - */ - public function getCompanyId(): ?int - { - return $this->company_id; - } - - /** - * @return string - */ - public function getBankName(): ?string - { - return $this->bank_name; - } - - /** - * @return string - */ - public function getHolderName(): ?string - { - return $this->holder_name; - } - - /** - * @return string - */ - public function getAccountNo(): ?string - { - return $this->account_no; - } - - /** - * @return int - */ - public function getType(): ?int - { - return $this->type; - } - - /** - * @return int - */ - public function getDefault(): ?int - { - return $this->default; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/Services/DeletesCompanyBank.php b/app/Classes/Modules/CompanyBanks/Services/DeletesCompanyBank.php deleted file mode 100644 index 906ba1ae..00000000 --- a/app/Classes/Modules/CompanyBanks/Services/DeletesCompanyBank.php +++ /dev/null @@ -1,14 +0,0 @@ -handler($model); - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/Services/UpdatesToDefaultCompanyBank.php b/app/Classes/Modules/CompanyBanks/Services/UpdatesToDefaultCompanyBank.php deleted file mode 100644 index 1b2e6545..00000000 --- a/app/Classes/Modules/CompanyBanks/Services/UpdatesToDefaultCompanyBank.php +++ /dev/null @@ -1,23 +0,0 @@ -default = DefaultType::DEFAULT; - - return $this->handler($model); - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/Services/UpdatesToNonDefaultCompanyBank.php b/app/Classes/Modules/CompanyBanks/Services/UpdatesToNonDefaultCompanyBank.php deleted file mode 100644 index 1554d423..00000000 --- a/app/Classes/Modules/CompanyBanks/Services/UpdatesToNonDefaultCompanyBank.php +++ /dev/null @@ -1,23 +0,0 @@ -default = DefaultType::NONDEFAULT; - - return $this->handler($model); - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/Standards/Rules/CanCreateCompanyBank.php b/app/Classes/Modules/CompanyBanks/Standards/Rules/CanCreateCompanyBank.php deleted file mode 100644 index 751c3a63..00000000 --- a/app/Classes/Modules/CompanyBanks/Standards/Rules/CanCreateCompanyBank.php +++ /dev/null @@ -1,55 +0,0 @@ -companyBankValidation = $companyBankValidation; - } - - /** - * @return bool - */ - protected function authorized(): bool - { - // TODO Set Authorization rules - if (!\Auth::user()->can('add company_bank')) { - return false; - } - - return true; - } - - /** - * @param SegmentObject $object - * @return bool - * @throws \App\Classes\Exceptions\RequestValidationException - */ - protected function validators($object): bool - { - return $this->companyBankValidation->validate($object); - } - - /** - * @param SegmentObject $object - * @return bool - */ - protected function criteria($object): bool - { - return true; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyBanks/Standards/Rules/CanUpdateCompanyBank.php b/app/Classes/Modules/CompanyBanks/Standards/Rules/CanUpdateCompanyBank.php deleted file mode 100644 index 9a8d9a21..00000000 --- a/app/Classes/Modules/CompanyBanks/Standards/Rules/CanUpdateCompanyBank.php +++ /dev/null @@ -1,59 +0,0 @@ -CompanyBankValidation = $CompanyBankValidation; - } - - /** - * @return bool - */ - protected function authorized(): bool - { - // TODO Set Authorization rules - - if (!\Auth::user()->can('edit company_bank')) { - return false; - } - - return true; - } - - /** - * @param CompanyBankValidation $object - * @return bool - * @throws \App\Classes\Exceptions\RequestValidationException - */ - protected function validators($object): bool - { - return $this->CompanyBankValidation->validate($object); - } - - /** - * @param CompanyBankValidation $object - * @return bool - */ - protected function criteria($object): bool - { - return true; - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyEmployees/DataTransferObjects/CompanyEmployeeObject.php b/app/Classes/Modules/CompanyEmployees/DataTransferObjects/CompanyEmployeeObject.php deleted file mode 100644 index 9bb6732b..00000000 --- a/app/Classes/Modules/CompanyEmployees/DataTransferObjects/CompanyEmployeeObject.php +++ /dev/null @@ -1,45 +0,0 @@ -company_id = $company_id; - $this->user_id = $user_id; - } - - /** - * @return int|null - */ - public function getCompanyId(): ?int - { - return $this->company_id; - } - - /** - * @return int|null - */ - public function getUserId(): ?int - { - return $this->user_id; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CompanyEmployees/Services/CreatesCompanyEmployee.php b/app/Classes/Modules/CompanyEmployees/Services/CreatesCompanyEmployee.php deleted file mode 100644 index ea0d75fc..00000000 --- a/app/Classes/Modules/CompanyEmployees/Services/CreatesCompanyEmployee.php +++ /dev/null @@ -1,21 +0,0 @@ -company()->sync($object->getCompanyId()); - return $model; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php b/app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php index 3f2dae9f..f408d8cc 100644 --- a/app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php +++ b/app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php @@ -2,17 +2,15 @@ namespace App\Classes\Modules\Contacts\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; +use App\Classes\ValueObjects\Constants\Countries; class ContactObject implements DataTransferObject { - /** @var int|null */ - private $country_id; + /** @var int */ + private $companyId; - /** @var int|null */ - private $company_id; - - /** @var string|null */ + /** @var string */ private $reference; /** @var string|null */ @@ -24,59 +22,46 @@ class ContactObject implements DataTransferObject /** @var string|null */ private $wechat_id; + /** @var int|null */ + private $countryId; /** * ContactObject constructor. - * @param int|null $country_id - * @param int|null $company_id - * @param null|string $reference + * @param int $companyId + * @param string $reference * @param null|string $phone * @param null|string $email * @param null|string $wechat_id + * @param int|null $countryId */ - public function __construct( - ?int $country_id, - ?int $company_id, - ?string $reference, - ?string $phone, - ?string $email, - ?string $wechat_id - ) + public function __construct(int $companyId, string $reference, ?string $phone, ?string $email, ?string $wechat_id, ?int $countryId = Countries::MALAYSIA) { - $this->country_id = $country_id; - $this->company_id = $company_id; + $this->companyId = $companyId; $this->reference = $reference; $this->phone = $phone; $this->email = $email; $this->wechat_id = $wechat_id; + $this->countryId = $countryId; } /** - * @return int|null + * @return int */ - public function getCountryId(): ?int + public function getCompanyId(): int { - return $this->country_id; + return $this->companyId; } /** - * @return int|null + * @return string */ - public function getCompanyId(): ?int - { - return $this->company_id; - } - - /** - * @return string|null - */ - public function getReference(): ?string + public function getReference(): string { return $this->reference; } /** - * @return string|null + * @return null|string */ public function getPhone(): ?string { @@ -84,7 +69,7 @@ class ContactObject implements DataTransferObject } /** - * @return string|null + * @return null|string */ public function getEmail(): ?string { @@ -92,10 +77,22 @@ class ContactObject implements DataTransferObject } /** - * @return string|null + * @return null|string */ - public function getWeChatId(): ?string + public function getWechatId(): ?string { return $this->wechat_id; } + + /** + * @return int + */ + public function getCountryId(): int + { + return $this->countryId; + } + + + + } \ No newline at end of file diff --git a/app/Classes/Modules/Contacts/Processors/CreateContactProcessor.php b/app/Classes/Modules/Contacts/Processors/CreateContactProcessor.php new file mode 100644 index 00000000..0c1bccdb --- /dev/null +++ b/app/Classes/Modules/Contacts/Processors/CreateContactProcessor.php @@ -0,0 +1,51 @@ +canCreateContact = $canCreateContact; + $this->createsContact = $createsContact; + } + + /** + * @param Request $request + * @param Company $company + * @return Model + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function execute(Request $request, Company $company): Model { + + $contact_object = new ContactObject($company->id, $request->input('name'), + $request->input('phone'), $request->input('contact_email'), $request->input('wechat_id')); + + $this->canCreateContact->passes($contact_object); + + return $this->createsContact->execute($contact_object); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Countries/ControllersLogic/ListCountriesLogic.php b/app/Classes/Modules/Countries/ControllersLogic/ListCountriesLogic.php new file mode 100644 index 00000000..227d002d --- /dev/null +++ b/app/Classes/Modules/Countries/ControllersLogic/ListCountriesLogic.php @@ -0,0 +1,35 @@ + 'Retrieved Countries', + 'message' => 'You have successfully retrieved a list of Countries' + ]; + } + + + /** + * @param Request $request + * @return JsonResponse + */ + public function logic(Request $request) : JsonResponse + { + + return $this->response(['data' => countries()]); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Countries/DataTransferObjects/CountryObject.php b/app/Classes/Modules/Countries/DataTransferObjects/CountryObject.php new file mode 100644 index 00000000..157aebbc --- /dev/null +++ b/app/Classes/Modules/Countries/DataTransferObjects/CountryObject.php @@ -0,0 +1,63 @@ +country = $country; + } + + /** + * @return Country + */ + public function getCountry(): Country + { + return $this->country; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->getCountry()->getName(); + } + + /** + * @return string + */ + public function getShortCode(): string + { + return $this->getCountry()->getIsoAlpha2(); + } + + /** + * @return int + */ + public function getPhoneCode(): int + { + return $this->getCountry()->getCallingCode(); + } + + /** + * @return string + */ + public function getSvg(): string + { + return $this->getCountry()->getFlag(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Countries/Services/CreatesCountry.php b/app/Classes/Modules/Countries/Services/CreatesCountry.php new file mode 100644 index 00000000..91116396 --- /dev/null +++ b/app/Classes/Modules/Countries/Services/CreatesCountry.php @@ -0,0 +1,27 @@ +firstOrCreate([ + 'name' => $object->getName(), + 'short_code' => $object->getShortCode(), + 'phone_code' => $object->getPhoneCode(), + ]); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Countries/Services/FetchesCountry.php b/app/Classes/Modules/Countries/Services/FetchesCountry.php new file mode 100644 index 00000000..7a877108 --- /dev/null +++ b/app/Classes/Modules/Countries/Services/FetchesCountry.php @@ -0,0 +1,34 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/CreateCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/CreateCurrencyLogic.php index 06e49e16..6fc8c43c 100644 --- a/app/Classes/Modules/Currencies/ControllersLogic/CreateCurrencyLogic.php +++ b/app/Classes/Modules/Currencies/ControllersLogic/CreateCurrencyLogic.php @@ -2,31 +2,48 @@ namespace App\Classes\Modules\Currencies\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ResourceConflictException; +use App\Classes\Exceptions\ResourceNotFoundException; +use App\Classes\General\Abstracts\AbstractControllerLogic; +use App\Classes\Modules\Countries\DataTransferObjects\CountryObject; +use App\Classes\Modules\Countries\Services\CreatesCountry; +use App\Classes\Modules\Countries\Services\FetchesCountry; +use App\Classes\Modules\Currencies\Services\FetchesCurrency; use App\Classes\Modules\Currencies\Standards\Rules\CanCreateCurrency; use App\Classes\Modules\Currencies\Services\CreatesCurrency; use App\Classes\Modules\Currencies\Services\CreatesCurrencyLog; use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyObject; use App\Http\Resources\CurrencyResource; -use ErrorException; +use App\Models\Country; +use App\Models\Currency; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; -class CreateCurrencyLogic extends AbstractControllersLogic +class CreateCurrencyLogic extends AbstractControllerLogic { + /** * @return array */ protected function notification():array { return [ - 'title' => 'Created Currency', + 'title' => 'Create Currency', 'message' => 'You have successfully created a new Currency' ]; } + /** @var FetchesCountry */ + private $fetchesCountry; + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + /** @var CreatesCountry */ + private $createsCountry; + /** @var CanCreateCurrency */ private $canCreateCurrency; @@ -37,17 +54,19 @@ class CreateCurrencyLogic extends AbstractControllersLogic private $createsCurrencyLog; /** - * CreateSegmentLogic constructor. + * CreateCurrencyLogic constructor. + * @param FetchesCountry $fetchesCountry + * @param FetchesCurrency $fetchesCurrency + * @param CreatesCountry $createsCountry * @param CanCreateCurrency $canCreateCurrency * @param CreatesCurrency $createsCurrency * @param CreatesCurrencyLog $createsCurrencyLog */ - public function __construct( - CanCreateCurrency $canCreateCurrency, - CreatesCurrency $createsCurrency, - CreatesCurrencyLog $createsCurrencyLog - ) + public function __construct(FetchesCountry $fetchesCountry, FetchesCurrency $fetchesCurrency, CreatesCountry $createsCountry, CanCreateCurrency $canCreateCurrency, CreatesCurrency $createsCurrency, CreatesCurrencyLog $createsCurrencyLog) { + $this->fetchesCountry = $fetchesCountry; + $this->fetchesCurrency = $fetchesCurrency; + $this->createsCountry = $createsCountry; $this->canCreateCurrency = $canCreateCurrency; $this->createsCurrency = $createsCurrency; $this->createsCurrencyLog = $createsCurrencyLog; @@ -56,31 +75,34 @@ class CreateCurrencyLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws MalformedRequestException + * @throws ResourceConflictException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { + + $countryObject = Country($request->input('country_short_code')); + + /** @var Country $country */ + $country = $this->createsCountry->execute(new CountryObject($countryObject)); + + $currencyInfo = $countryObject->getCurrency(); + $currencyObject = new CurrencyObject($currencyInfo['iso_4217_name'], $currencyInfo['iso_4217_code']); + + $this->canCreateCurrency->passes($currencyObject); + try { - DB::beginTransaction(); - - $currency_object = new CurrencyObject( - $request->input('country_id'), - $request->input('name'), - $request->input('short_code'), - $request->input('symbol') - ); - $this->canCreateCurrency->passes($currency_object); - $currency_query = $this->createsCurrency->execute($currency_object); - - $currency_log_query = $this->createsCurrencyLog->execute($currency_query); - - DB::commit(); - - return $this->resourceResponse(new CurrencyResource($currency_query)); - - } catch (\Exception $exception) { - throw new ErrorException($exception->getMessage(), $exception->getCode()); + $this->fetchesCurrency->execute(['country_id' => $country->id, 'short_code' => $currencyObject->getShortCode()]); + throw new ResourceConflictException('Duplicated Currency. This currency already exists in the system'); + } catch (ResourceNotFoundException $exception){ + /** @var Currency $currency */ + $currency = $this->createsCurrency->execute($country, $currencyObject); + $this->createsCurrencyLog->execute($currency); } + return $this->resourceResponse(new CurrencyResource($currency)); + } } \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/DeleteCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/DeleteCurrencyLogic.php index c08279db..ed8e3745 100644 --- a/app/Classes/Modules/Currencies/ControllersLogic/DeleteCurrencyLogic.php +++ b/app/Classes/Modules/Currencies/ControllersLogic/DeleteCurrencyLogic.php @@ -4,20 +4,19 @@ namespace App\Classes\Modules\Currencies\ControllersLogic; use App\Http\Resources\CurrencyResource; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Currencies\Services\FetchesCurrency; use App\Classes\Modules\Currencies\Standards\Rules\CanDeleteCurrency; use App\Classes\Modules\Currencies\Services\DeletesCurrency; -use App\Classes\Modules\Currencies\DataTransferObjects\SegmentObject; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class DeleteCurrencyLogic extends AbstractControllersLogic +class DeleteCurrencyLogic extends AbstractControllerLogic { /** @@ -60,24 +59,19 @@ class DeleteCurrencyLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { - DB::beginTransaction(); + $this->canDeleteCurrency->passes(); - $currency_query = $this->fetchesCurrency->execute(['id' => $request->route('id')]); - $this->canDeleteCurrency->passes(); - $this->deletesCurrency->execute($currency_query); - - DB::commit(); + $currency_query = $this->fetchesCurrency->execute(['id' => $request->route('id')]); - return $this->resourceResponse(new CurrencyResource($currency_query)); + $this->deletesCurrency->execute($currency_query); - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->response([]); } } \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/FetchSystemPrimaryCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/FetchSystemPrimaryCurrencyLogic.php new file mode 100644 index 00000000..b9c7a75b --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/FetchSystemPrimaryCurrencyLogic.php @@ -0,0 +1,71 @@ + 'Fetch System\'s primary currency', + 'message' => 'You have successfully retrieved a Currency' + ]; + } + + + /** @var CanFetchCurrency */ + private $canFetchCurrency; + + /** @var FetchesConstant*/ + private $fetchesConstant; + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + /** + * FetchSystemPrimaryCurrencyLogic constructor. + * @param CanFetchCurrency $canFetchCurrency + * @param FetchesConstant $fetchesConstant + * @param FetchesCurrency $fetchesCurrency + */ + public function __construct(CanFetchCurrency $canFetchCurrency, FetchesConstant $fetchesConstant, FetchesCurrency $fetchesCurrency) + { + $this->canFetchCurrency = $canFetchCurrency; + $this->fetchesConstant = $fetchesConstant; + $this->fetchesCurrency = $fetchesCurrency; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $this->canFetchCurrency->passes(); + + $constant = $this->fetchesConstant->execute(['reference' => SegmentConstants::SYSTEM_PRIMARY_CURRENCY]); + + /** @var Currency $currency */ + $currency = $this->fetchesCurrency->execute(['id' => $constant->detail->id]); + + return $this->resourceResponse(new CurrencyResource($currency)); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/ListCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/ListCurrencyLogic.php index 8efab677..e23f99db 100644 --- a/app/Classes/Modules/Currencies/ControllersLogic/ListCurrencyLogic.php +++ b/app/Classes/Modules/Currencies/ControllersLogic/ListCurrencyLogic.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Currencies\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Currencies\Services\ListsCurrency; use App\Classes\Modules\Currencies\Standards\Rules\CanListCurrency; use App\Http\Resources\CurrencyResource; @@ -11,7 +11,7 @@ use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class ListCurrencyLogic extends AbstractControllersLogic +class ListCurrencyLogic extends AbstractControllerLogic { /** @@ -45,21 +45,17 @@ class ListCurrencyLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { - $this->canListCurrency->passes(); + $this->canListCurrency->passes(); - $query = $this->listsCurrency->execute(); + $query = $this->listsCurrency->execute($this->listsCurrency->deserializeFilters($request->input('filters'))); - return $this->collectionResponse(CurrencyResource::collection($query)); - - } catch (\Exception $exception){ - dd($exception); - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->collectionResponse(CurrencyResource::collection($query)); } diff --git a/app/Classes/Modules/Currencies/ControllersLogic/RateCalculateCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/RateCalculateCurrencyLogic.php index 35686210..ea3b0c64 100644 --- a/app/Classes/Modules/Currencies/ControllersLogic/RateCalculateCurrencyLogic.php +++ b/app/Classes/Modules/Currencies/ControllersLogic/RateCalculateCurrencyLogic.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Currencies\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Currencies\Services\FetchesCurrency; use App\Classes\Modules\Currencies\Services\RateCalculatesCurrency; @@ -12,7 +12,7 @@ use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class RateCalculateCurrencyLogic extends AbstractControllersLogic +class RateCalculateCurrencyLogic extends AbstractControllerLogic { /** @@ -32,7 +32,6 @@ class RateCalculateCurrencyLogic extends AbstractControllersLogic private $rateCalculatesCurrency; /** - * @param CanListStandardSegmentConstants $canListStandardSegmentConstants * @param FetchesCurrency $fetchesCurrency * @param RateCalculatesCurrency $rateCalculatesCurrency */ @@ -45,21 +44,16 @@ class RateCalculateCurrencyLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException */ public function logic(Request $request) : JsonResponse { - try { - $amount = $request->input('amount'); - $conversion_currency = $this->fetchesCurrency->execute(['id' => $request->input('conversion_currency_id')]); - $convertable_currency = $this->fetchesCurrency->execute(['id' => $request->input('convertable_currency_id')]); - $convert_amount = $this->rateCalculatesCurrency->execute($conversion_currency, $convertable_currency, $amount); - return $this->resourceResponse(new RateCalculateCurrencyResource($conversion_currency, $convertable_currency, $amount)); + $amount = $request->input('amount'); + $conversion_currency = $this->fetchesCurrency->execute(['id' => $request->input('conversion_currency_id')]); + $convertable_currency = $this->fetchesCurrency->execute(['id' => $request->input('convertable_currency_id')]); + $this->rateCalculatesCurrency->execute($conversion_currency, $convertable_currency, $amount); - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->resourceResponse(new RateCalculateCurrencyResource($conversion_currency, $convertable_currency, $amount)); } diff --git a/app/Classes/Modules/CurrencyRates/ControllersLogic/CalculateCurrencyRateLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/CalculateRateLogic.php similarity index 50% rename from app/Classes/Modules/CurrencyRates/ControllersLogic/CalculateCurrencyRateLogic.php rename to app/Classes/Modules/Currencies/ControllersLogic/Rates/CalculateRateLogic.php index ed2481fc..023c5df9 100644 --- a/app/Classes/Modules/CurrencyRates/ControllersLogic/CalculateCurrencyRateLogic.php +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/CalculateRateLogic.php @@ -1,18 +1,18 @@ fetchesCurrencyRate = $fetchesCurrencyRate; - $this->calculatesCurrencyRate = $calculatesCurrencyRate; + $this->fetchesRate = $fetchesRate; + $this->calculatesRate = $calculatesRate; } /** @@ -51,18 +50,18 @@ class CalculateCurrencyRateLogic extends AbstractControllersLogic { try { $amount = $request->input('amount'); - $conversion_currency_rate = $this->fetchesCurrencyRate->execute( + $conversion_currency_rate = $this->fetchesRate->execute( [ 'id' => $request->input('conversion_currency_rate_id'), ] ); - $convertable_currency_rate = $this->fetchesCurrencyRate->execute( + $convertable_currency_rate = $this->fetchesRate->execute( [ 'id' => $request->input('convertable_currency_rate_id') ] ); - $convert_amount = $this->calculatesCurrencyRate->execute($conversion_currency_rate, $convertable_currency_rate, $amount); + $convert_amount = $this->calculatesRate->execute($conversion_currency_rate, $convertable_currency_rate, $amount); return $this->resourceResponse(new CalculateCurrencyRateResource($conversion_currency_rate, $convertable_currency_rate, $convert_amount)); diff --git a/app/Classes/Modules/Currencies/ControllersLogic/Rates/CreateRateLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/CreateRateLogic.php new file mode 100644 index 00000000..3d697b8b --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/CreateRateLogic.php @@ -0,0 +1,96 @@ + 'Created Currency Rate', + 'message' => 'You have successfully created a new Currency Rate' + ]; + } + + /** @var CanCreateRate */ + private $canCreateRate; + + /** @var CreatesRate */ + private $createsRate; + + /** @var CreatesRateLog */ + private $createsRateLog; + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + /** + * CreateRateLogic constructor. + * @param CanCreateRate $canCreateRate + * @param CreatesRate $createsRate + * @param CreatesRateLog $createsRateLog + * @param FetchesCurrency $fetchesCurrency + */ + public function __construct( + CanCreateRate $canCreateRate, + CreatesRate $createsRate, + CreatesRateLog $createsRateLog, + FetchesCurrency $fetchesCurrency + ) + { + $this->canCreateRate = $canCreateRate; + $this->createsRate = $createsRate; + $this->createsRateLog = $createsRateLog; + $this->fetchesCurrency = $fetchesCurrency; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $currency_rate_object = new RateObject( + $request->input('currency_id'), + number_format( (float) $request->input('selling'), 5, '.', ''), + $request->input('payment_method_type') + ); + + $this->canCreateRate->passes($currency_rate_object); + + $currency_rate_query = $this->createsRate->execute($currency_rate_object); + + $this->createsRateLog->execute($currency_rate_query); + + DB::commit(); + + return $this->resourceResponse(new CurrencyRateResource($currency_rate_query)); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/Rates/DeleteRateLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/DeleteRateLogic.php new file mode 100644 index 00000000..2cacb51d --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/DeleteRateLogic.php @@ -0,0 +1,82 @@ + 'Delete Currency Rate', + 'message' => 'You have successfully deleted the Currency Rate' + ]; + } + + /** @var CanDeleteRate */ + private $canDeleteRate; + + /** @var DeletesRate */ + private $deletesRate; + + /** @var FetchesRate */ + private $fetchesRate; + + + /** + * DeleteRateRateLogic constructor. + * @param CanDeleteRate $canDeleteRate + * @param DeletesRate $deletesRate + * @param FetchesRate $fetchesRate + */ + public function __construct( + CanDeleteRate $canDeleteRate, + DeletesRate $deletesRate, + FetchesRate $fetchesRate + ) + { + $this->canDeleteRate = $canDeleteRate; + $this->deletesRate = $deletesRate; + $this->fetchesRate = $fetchesRate; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $currency_rate = $this->fetchesRate->execute(['id' => $request->route('id')]); + $this->canDeleteRate->passes(); + $this->deletesRate->execute($currency_rate); + + DB::commit(); + + return $this->resourceResponse(new CurrencyRateResource($currency_rate)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/Rates/FetchRateLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/FetchRateLogic.php new file mode 100644 index 00000000..e691885e --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/FetchRateLogic.php @@ -0,0 +1,66 @@ + 'Retrieved Currency Rate', + 'message' => 'You have successfully retrieved a Currency Rate' + ]; + } + + /** @var CanFetchRate */ + private $canFetchRate; + + /** @var FetchesRate */ + private $fetchesRate; + + /** + * FetchRateControllersLogic constructor. + * @param CanFetchRate $canFetchRate + * @param FetchesRate $fetchesRate + */ + public function __construct(CanFetchRate $canFetchRate, FetchesRate $fetchesRate) + { + $this->canFetchRate = $canFetchRate; + $this->fetchesRate = $fetchesRate; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + $this->canFetchRate->passes(); + + $query = $this->fetchesRate->execute(['id' => $request->route('id')]); + + return $this->resourceResponse(new CurrencyRateResource($query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/ControllersLogic/ListCurrencyRatesLogicLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/ListRatesLogic.php similarity index 52% rename from app/Classes/Modules/CurrencyRates/ControllersLogic/ListCurrencyRatesLogicLogic.php rename to app/Classes/Modules/Currencies/ControllersLogic/Rates/ListRatesLogic.php index 94c9312c..c62ec605 100644 --- a/app/Classes/Modules/CurrencyRates/ControllersLogic/ListCurrencyRatesLogicLogic.php +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/ListRatesLogic.php @@ -1,17 +1,17 @@ canListCurrencyRates = $canListCurrencyRates; - $this->listsCurrencyRates = $listsCurrencyRates; + $this->canListRates = $canListRates; + $this->listsRates = $listsRates; } @@ -50,9 +50,9 @@ class ListCurrencyRatesLogic extends AbstractControllersLogic public function logic(Request $request) : JsonResponse { try { - $this->canListCurrencyRates->passes(); + $this->canListRates->passes(); - $query = $this->listsCurrencyRates->execute( + $query = $this->listsRates->execute( [ 'currency_id' => $request->input('currency_id'), 'payment_method_type' => $request->input('payment_method_type') diff --git a/app/Classes/Modules/Currencies/ControllersLogic/Rates/UpdateRateLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/Rates/UpdateRateLogic.php new file mode 100644 index 00000000..8aa61056 --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/Rates/UpdateRateLogic.php @@ -0,0 +1,97 @@ +canUpdateRate = $canUpdateRate; + $this->updatesRate = $updatesRate; + $this->createsRateLog = $createsRateLog; + $this->fetchesRate = $fetchesRate; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $currency_rate_query = $this->fetchesRate->execute(['id' => $request->route('id')]); + + $currency_object_object = new RateObject( + $currency_rate_query->currency_id, + $request->input('selling', $currency_rate_query->selling), + $currency_rate_query->payment_method_type + ); + + $this->canUpdateRate->passes($currency_object_object); + $currency_rate_query = $this->updatesRate->execute($currency_rate_query, $currency_object_object); + + $this->createsRateLog->execute($currency_rate_query); + + DB::commit(); + + return $this->resourceResponse(new CurrencyRateResource($currency_rate_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Updated Currency Rate', + 'message' => 'You have successfully updated the Currency Rate' + ]; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyConversionObject.php b/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyConversionObject.php new file mode 100644 index 00000000..c4e91b1e --- /dev/null +++ b/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyConversionObject.php @@ -0,0 +1,86 @@ +amount = $amount; + $this->currencyId = $currencyId; + $this->serviceId = $serviceId; + $this->type = $type; + $this->paymentMethod = $paymentMethod; + } + + /** + * @return float + */ + public function getAmount(): float + { + return $this->amount; + } + + /** + * @return int + */ + public function getCurrencyId(): int + { + return $this->currencyId; + } + + /** + * @return int + */ + public function getServiceId(): int + { + return $this->serviceId; + } + + /** + * @return int + */ + public function getType(): int + { + return $this->type; + } + + /** + * @return int|null + */ + public function getPaymentMethod(): ?int + { + return $this->paymentMethod; + } + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyObject.php b/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyObject.php index 78460524..8e8e23d6 100644 --- a/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyObject.php +++ b/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyObject.php @@ -2,49 +2,36 @@ namespace App\Classes\Modules\Currencies\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; class CurrencyObject implements DataTransferObject { - /** @var string|null */ - private $country_id; + /** @var string */ private $name; - private $short_code; - private $symbol; + /** @var string */ + private $short_code; + + /** @var string|null */ + private $symbol; /** * CurrencyObject constructor. - * @param int|null $country_id - * @param null|string $name - * @param null|string $short_code + * @param string $name + * @param string $short_code * @param null|string $symbol */ - public function __construct( - ?int $country_id, - ?string $name, - ?string $short_code, - ?string $symbol - ) + public function __construct(string $name, string $short_code, ?string $symbol = null) { - $this->country_id = $country_id; $this->name = $name; $this->short_code = $short_code; $this->symbol = $symbol; } - /** - * @return int - */ - public function getCountryId(): ?int - { - return $this->country_id; - } - /** * @return string */ - public function getName(): ?string + public function getName(): string { return $this->name; } @@ -52,16 +39,20 @@ class CurrencyObject implements DataTransferObject /** * @return string */ - public function getShortCode(): ?string + public function getShortCode(): string { return $this->short_code; } /** - * @return string + * @return null|string */ public function getSymbol(): ?string { return $this->symbol; } + + + + } \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/DataTransferObjects/RateObject.php b/app/Classes/Modules/Currencies/DataTransferObjects/RateObject.php new file mode 100644 index 00000000..cde9dea9 --- /dev/null +++ b/app/Classes/Modules/Currencies/DataTransferObjects/RateObject.php @@ -0,0 +1,45 @@ +selling = $selling; + $this->payment_method_type = $payment_method_type; + } + + /** + * @return array + */ + public function getSelling(): array + { + return $this->selling; + } + + /** + * @return int + */ + public function getPaymentMethodType(): int + { + return PaymentMethodType::PAYMENT_METHODS[$this->payment_method_type]; + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/CreatesCurrency.php b/app/Classes/Modules/Currencies/Services/CreatesCurrency.php index 1f4f9cb6..d11667fd 100644 --- a/app/Classes/Modules/Currencies/Services/CreatesCurrency.php +++ b/app/Classes/Modules/Currencies/Services/CreatesCurrency.php @@ -2,24 +2,27 @@ namespace App\Classes\Modules\Currencies\Services; -use App\Classes\General\Eloquent\AbstractUpdateRecord; +use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord; use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyObject; +use App\Models\Country; use App\Models\Currency; -class CreatesCurrency extends AbstractUpdateRecord +class CreatesCurrency extends AbstractUpdateRelationshipRecord { /** + * @param Country $country * @param CurrencyObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(CurrencyObject $object) { + public function execute(Country $country, CurrencyObject $object) { + $model = new Currency(); - $model->country_id = $object->getCountryId(); $model->name = $object->getName(); $model->short_code = $object->getShortCode(); $model->symbol = $object->getSymbol(); - return $this->handler($model); + + return $this->handler($country->currencies(), $model); } } \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/CreatesCurrencyLog.php b/app/Classes/Modules/Currencies/Services/CreatesCurrencyLog.php index a5de84ab..cf2541c5 100644 --- a/app/Classes/Modules/Currencies/Services/CreatesCurrencyLog.php +++ b/app/Classes/Modules/Currencies/Services/CreatesCurrencyLog.php @@ -16,8 +16,7 @@ class CreatesCurrencyLog extends AbstractUpdateRecord public function execute(Currency $object) { $model = new CurrencyLog(); $model->currency_id = $object->id; - $model->selling = $object->selling; - $model->created_by = \Auth::user()->id; + $model->created_by = Auth()->user()->id; return $this->handler($model); } diff --git a/app/Classes/Modules/Currencies/Services/DeletesCurrency.php b/app/Classes/Modules/Currencies/Services/DeletesCurrency.php index 13606c86..3e4dd087 100644 --- a/app/Classes/Modules/Currencies/Services/DeletesCurrency.php +++ b/app/Classes/Modules/Currencies/Services/DeletesCurrency.php @@ -8,6 +8,11 @@ use App\Models\Currency; class DeletesCurrency extends AbstractDeleteRecord { + /** + * @param Currency $model + * @return mixed + * @throws \App\Classes\Exceptions\MalformedRequestException + */ public function execute(Currency $model) { return $this->handler($model); } diff --git a/app/Classes/Modules/CurrencyRates/Services/CalculatesCurrencyRate.php b/app/Classes/Modules/Currencies/Services/Rates/CalculatesRate.php similarity index 68% rename from app/Classes/Modules/CurrencyRates/Services/CalculatesCurrencyRate.php rename to app/Classes/Modules/Currencies/Services/Rates/CalculatesRate.php index 31396eeb..0751db76 100644 --- a/app/Classes/Modules/CurrencyRates/Services/CalculatesCurrencyRate.php +++ b/app/Classes/Modules/Currencies/Services/Rates/CalculatesRate.php @@ -1,19 +1,19 @@ selling / $convertable_currency_rate->selling) * $amount; } - public function execute_rate(CurrencyRate $conversion_currency_rate, CurrencyRate $convertable_currency_rate) + public function execute_rate(CurrencyRate $conversion_currency_rate, CurrencyRate $convertable_currency_rate) { return $convert_rate = ($conversion_currency_rate->selling / $convertable_currency_rate->selling); } diff --git a/app/Classes/Modules/Currencies/Services/Rates/CreatesRate.php b/app/Classes/Modules/Currencies/Services/Rates/CreatesRate.php new file mode 100644 index 00000000..dce10b28 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/Rates/CreatesRate.php @@ -0,0 +1,29 @@ +selling = $object->getSelling(); + $model->payment_method_type = $object->getPaymentMethodType(); + $model->service_id = $object->getServiceId(); + + return $this->handler($currency->rates(), $model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/Services/CreatesCurrencyRateLog.php b/app/Classes/Modules/Currencies/Services/Rates/CreatesRateLog.php similarity index 79% rename from app/Classes/Modules/CurrencyRates/Services/CreatesCurrencyRateLog.php rename to app/Classes/Modules/Currencies/Services/Rates/CreatesRateLog.php index 1d120a05..b8bf8275 100644 --- a/app/Classes/Modules/CurrencyRates/Services/CreatesCurrencyRateLog.php +++ b/app/Classes/Modules/Currencies/Services/Rates/CreatesRateLog.php @@ -1,15 +1,15 @@ update($rates)->save(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/Rates/DeletesRate.php b/app/Classes/Modules/Currencies/Services/Rates/DeletesRate.php new file mode 100644 index 00000000..30437c7e --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/Rates/DeletesRate.php @@ -0,0 +1,19 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/Services/FetchesCurrencyRate.php b/app/Classes/Modules/Currencies/Services/Rates/FetchesRate.php similarity index 77% rename from app/Classes/Modules/CurrencyRates/Services/FetchesCurrencyRate.php rename to app/Classes/Modules/Currencies/Services/Rates/FetchesRate.php index 7254387c..f8c2a4cd 100644 --- a/app/Classes/Modules/CurrencyRates/Services/FetchesCurrencyRate.php +++ b/app/Classes/Modules/Currencies/Services/Rates/FetchesRate.php @@ -1,20 +1,20 @@ selling = $object->getSelling(); diff --git a/app/Classes/Modules/Currencies/Standards/Rules/CanCreateCurrency.php b/app/Classes/Modules/Currencies/Standards/Rules/CanCreateCurrency.php index 42da8a25..873e03ce 100644 --- a/app/Classes/Modules/Currencies/Standards/Rules/CanCreateCurrency.php +++ b/app/Classes/Modules/Currencies/Standards/Rules/CanCreateCurrency.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Currencies\Standards\Rules; use App\Classes\General\Abstracts\AbstractRule; -use App\Classes\Modules\Currencies\DataTransferObjects\SegmentObject; +use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyObject; use App\Classes\Modules\Currencies\Standards\Validators\CurrencyValidation; class CanCreateCurrency extends AbstractRule @@ -27,15 +27,11 @@ class CanCreateCurrency extends AbstractRule protected function authorized(): bool { // TODO Set Authorization rules - if (!\Auth::user()->can('add currency')) { - return false; - } - return true; } /** - * @param SegmentObject $object + * @param CurrencyObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -45,7 +41,7 @@ class CanCreateCurrency extends AbstractRule } /** - * @param SegmentObject $object + * @param CurrencyObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/Currencies/Standards/Rules/CanDeleteCurrency.php b/app/Classes/Modules/Currencies/Standards/Rules/CanDeleteCurrency.php index bfeb6885..60820e79 100644 --- a/app/Classes/Modules/Currencies/Standards/Rules/CanDeleteCurrency.php +++ b/app/Classes/Modules/Currencies/Standards/Rules/CanDeleteCurrency.php @@ -13,13 +13,7 @@ class CanDeleteCurrency extends AbstractRule protected function authorized(): bool { // TODO Set Authorization rules - - if (!\Auth::user()->can('delete currency')) { - return false; - } - return true; - } /** diff --git a/app/Classes/Modules/Currencies/Standards/Rules/CanFetchCurrency.php b/app/Classes/Modules/Currencies/Standards/Rules/CanFetchCurrency.php new file mode 100644 index 00000000..624809ed --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Rules/CanFetchCurrency.php @@ -0,0 +1,40 @@ +can('view currency')) { - return false; - } - return true; } diff --git a/app/Classes/Modules/Currencies/Standards/Rules/CanUpdateCurrency.php b/app/Classes/Modules/Currencies/Standards/Rules/CanUpdateCurrency.php index 639070f0..d7e2ca93 100644 --- a/app/Classes/Modules/Currencies/Standards/Rules/CanUpdateCurrency.php +++ b/app/Classes/Modules/Currencies/Standards/Rules/CanUpdateCurrency.php @@ -10,7 +10,7 @@ use App\Classes\Modules\Currencies\Standards\Validators\CurrencyValidation; class CanUpdateCurrency extends AbstractRule { - /** @var currencyValidation */ + /** @var CurrencyValidation */ private $currencyValidation; @@ -29,16 +29,11 @@ class CanUpdateCurrency extends AbstractRule protected function authorized(): bool { // TODO Set Authorization rules - - if (!\Auth::user()->can('edit currency')) { - return false; - } - return true; } /** - * @param CurrencyValidation $object + * @param CurrencyObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -48,7 +43,7 @@ class CanUpdateCurrency extends AbstractRule } /** - * @param CurrencyValidation $object + * @param CurrencyObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanCreateRate.php b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanCreateRate.php new file mode 100644 index 00000000..842a548b --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanCreateRate.php @@ -0,0 +1,55 @@ +rateValidation = $rateValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + if (!\Auth::user()->can('add currency_rate')) { + return false; + } + + return true; + } + + /** + * @param RateObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->rateValidation->validate($object, 'POST'); + } + + /** + * @param RateObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/Standards/Rules/CanDeleteCurrencyRate.php b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanDeleteRate.php similarity index 67% rename from app/Classes/Modules/CurrencyRates/Standards/Rules/CanDeleteCurrencyRate.php rename to app/Classes/Modules/Currencies/Standards/Rules/Rates/CanDeleteRate.php index 33e47744..4ebefb9e 100644 --- a/app/Classes/Modules/CurrencyRates/Standards/Rules/CanDeleteCurrencyRate.php +++ b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanDeleteRate.php @@ -1,11 +1,11 @@ can('delete company_bank')) { - return false; - } - return true; } /** - * @param CompanyBankObject $object + * @param RateObject $object * @return bool */ protected function validators($object): bool @@ -34,7 +32,7 @@ class CanDeleteCompanyBank extends AbstractRule /** - * @param CompanyBankObject $object + * @param RateObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/CurrencyRates/Standards/Rules/CanListCurrencyRates.php b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanListRates.php similarity index 67% rename from app/Classes/Modules/CurrencyRates/Standards/Rules/CanListCurrencyRates.php rename to app/Classes/Modules/Currencies/Standards/Rules/Rates/CanListRates.php index 31364e37..496ba1e5 100644 --- a/app/Classes/Modules/CurrencyRates/Standards/Rules/CanListCurrencyRates.php +++ b/app/Classes/Modules/Currencies/Standards/Rules/Rates/CanListRates.php @@ -1,11 +1,11 @@ rateValidation = $rateValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + + if (!\Auth::user()->can('view currency_rate')) { + return false; + } + + return true; + } + + /** + * @param RateObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->rateValidation->validate($object, 'PUT'); + } + + /** + * @param RateObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Validators/CurrencyValidation.php b/app/Classes/Modules/Currencies/Standards/Validators/CurrencyValidation.php index 15ab0f89..fd3b8ce5 100644 --- a/app/Classes/Modules/Currencies/Standards/Validators/CurrencyValidation.php +++ b/app/Classes/Modules/Currencies/Standards/Validators/CurrencyValidation.php @@ -14,10 +14,8 @@ class CurrencyValidation extends AbstractValidation protected function data($object): array { return [ - 'country_id' => $object->getCountryId(), 'name' => $object->getName(), - 'short_code' => $object->getShortCode(), - 'symbol' => $object->getSymbol(), + 'short_code' => $object->getShortCode() ]; } @@ -27,10 +25,8 @@ class CurrencyValidation extends AbstractValidation protected function rules(): array { return [ - 'country_id' => 'required', 'name' => 'required', - 'short_code' => 'required', - 'short_code' => 'required', + 'short_code' => 'required' ]; } diff --git a/app/Classes/Modules/CurrencyRates/Standards/Validators/CurrencyRateValidation.php b/app/Classes/Modules/Currencies/Standards/Validators/RateValidation.php similarity index 76% rename from app/Classes/Modules/CurrencyRates/Standards/Validators/CurrencyRateValidation.php rename to app/Classes/Modules/Currencies/Standards/Validators/RateValidation.php index 3f57ba03..3372c28f 100644 --- a/app/Classes/Modules/CurrencyRates/Standards/Validators/CurrencyRateValidation.php +++ b/app/Classes/Modules/Currencies/Standards/Validators/RateValidation.php @@ -1,15 +1,15 @@ 'Created Currency Rate', - 'message' => 'You have successfully created a new Currency Rate' - ]; - } - - /** @var CanCreateCurrencyRate */ - private $canCreateCurrencyRate; - - /** @var CreatesCurrencyRate */ - private $createsCurrencyRate; - - /** @var CreatesCurrencyRateLog */ - private $createsCurrencyRateLog; - - /** @var FetchesCurrency */ - private $fetchesCurrency; - - /** - * CreateCurrencyRateLogic constructor. - * @param CanCreateCurrencyRate $canCreateCurrencyRate - * @param CreatesCurrencyRate $createsCurrencyRate - * @param FetchesCurrency $fetchesCurrency - */ - public function __construct( - CanCreateCurrencyRate $canCreateCurrencyRate, - CreatesCurrencyRate $createsCurrencyRate, - CreatesCurrencyRateLog $createsCurrencyRateLog, - FetchesCurrency $fetchesCurrency - ) - { - $this->canCreateCurrencyRate = $canCreateCurrencyRate; - $this->createsCurrencyRate = $createsCurrencyRate; - $this->createsCurrencyRateLog = $createsCurrencyRateLog; - $this->fetchesCurrency = $fetchesCurrency; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $currency_query = $this->fetchesCurrency->execute([ - 'id' => $request->input('currency_id', 1), - ]); - - $currency_rate_object = new CurrencyRateObject( - $request->input('currency_id'), - number_format( (float) $request->input('selling'), 5, '.', ''), - $request->input('payment_method_type') - ); - - $this->canCreateCurrencyRate->passes($currency_rate_object); - $currency_rate_query = $this->createsCurrencyRate->execute($currency_rate_object); - - $currency_rate_log_query = $this->createsCurrencyRateLog->execute($currency_rate_query); - - DB::commit(); - - return $this->resourceResponse(new CurrencyRateResource($currency_rate_query)); - - } catch (\Exception $exception) { - dd($exception); - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/ControllersLogic/DeleteCurrencyRateLogic.php b/app/Classes/Modules/CurrencyRates/ControllersLogic/DeleteCurrencyRateLogic.php deleted file mode 100644 index ee6200bc..00000000 --- a/app/Classes/Modules/CurrencyRates/ControllersLogic/DeleteCurrencyRateLogic.php +++ /dev/null @@ -1,83 +0,0 @@ - 'Delete Currency Rate', - 'message' => 'You have successfully deleted the Currency Rate' - ]; - } - - /** @var CanDeleteCurrencyRate */ - private $canDeleteCurrencyRate; - - /** @var DeletesCurrencyRate */ - private $deletesCurrencyRate; - - /** @var FetchesCurrencyRate */ - private $fetchesCurrencyRate; - - - /** - * DeleteCurrencyRateRateLogic constructor. - * @param CanDeleteCurrencyRate $canDeleteCurrencyRate - * @param DeletesCurrencyRate $deletesCurrencyRate - * @param FetchesCurrencyRate $fetchesCurrencyRate - */ - public function __construct( - CanDeleteCurrencyRate $canDeleteCurrencyRate, - DeletesCurrencyRate $deletesCurrencyRate, - FetchesCurrencyRate $fetchesCurrencyRate - ) - { - $this->canDeleteCurrencyRate = $canDeleteCurrencyRate; - $this->deletesCurrencyRate = $deletesCurrencyRate; - $this->fetchesCurrencyRate = $fetchesCurrencyRate; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $currency_rate = $this->fetchesCurrencyRate->execute(['id' => $request->route('id')]); - $this->canDeleteCurrencyRate->passes(); - $this->deletesCurrencyRate->execute($currency_rate); - - DB::commit(); - - return $this->resourceResponse(new CurrencyRateResource($currency_rate)); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/ControllersLogic/FetchCurrencyRateLogic.php b/app/Classes/Modules/CurrencyRates/ControllersLogic/FetchCurrencyRateLogic.php deleted file mode 100644 index 6dd31699..00000000 --- a/app/Classes/Modules/CurrencyRates/ControllersLogic/FetchCurrencyRateLogic.php +++ /dev/null @@ -1,67 +0,0 @@ - 'Retrieved Currency Rate', - 'message' => 'You have successfully retrieved a Currency Rate' - ]; - } - - /** @var CanFetchCurrencyRate */ - private $canFetchCurrencyRate; - - /** @var FetchesCurrencyRate */ - private $fetchesCurrencyRate; - - /** - * FetchCurrencyRateControllersLogic constructor. - * @param CanFetchCurrencyRate $canFetchCurrencyRate - * @param FetchesCurrencyRate $fetchesCurrencyRate - */ - public function __construct(CanFetchCurrencyRate $canFetchCurrencyRate, FetchesCurrencyRate $fetchesCurrencyRate) - { - $this->canFetchCurrencyRate = $canFetchCurrencyRate; - $this->fetchesCurrencyRate = $fetchesCurrencyRate; - } - - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - - $this->canFetchCurrencyRate->passes(); - - $query = $this->fetchesCurrencyRate->execute(['id' => $request->route('id')]); - - return $this->resourceResponse(new CurrencyRateResource($query)); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/ControllersLogic/UpdateCurrencyRateLogic.php b/app/Classes/Modules/CurrencyRates/ControllersLogic/UpdateCurrencyRateLogic.php deleted file mode 100644 index eeb19ccd..00000000 --- a/app/Classes/Modules/CurrencyRates/ControllersLogic/UpdateCurrencyRateLogic.php +++ /dev/null @@ -1,100 +0,0 @@ - 'Updated Currency Rate', - 'message' => 'You have successfully updated the Currency Rate' - ]; - } - - /** @var CanUpdateCurrencyRate */ - private $canUpdateCurrencyRate; - - /** @var UpdatesCurrencyRate */ - private $updatesCurrencyRate; - - /** @var CreatesCurrencyRateLog */ - private $createsCurrencyRateLog; - - /** @var FetchesCurrencyRate */ - private $fetchesCurrencyRate; - - /** - * UpdateStandardCurrencyRateLogic constructor. - * @param CanUpdateCurrencyRate $canUpdateCurrencyRate - * @param UpdatesCurrencyRate $updatesCurrencyRate - * @param FetchesCurrencyRate $fetchesCurrencyRate - */ - public function __construct( - CanUpdateCurrencyRate $canUpdateCurrencyRate, - UpdatesCurrencyRate $updatesCurrencyRate, - CreatesCurrencyRateLog $createsCurrencyRateLog, - FetchesCurrencyRate $fetchesCurrencyRate - ) - { - $this->canUpdateCurrencyRate = $canUpdateCurrencyRate; - $this->updatesCurrencyRate = $updatesCurrencyRate; - $this->createsCurrencyRateLog = $createsCurrencyRateLog; - $this->fetchesCurrencyRate = $fetchesCurrencyRate; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $currency_rate_query = $this->fetchesCurrencyRate->execute(['id' => $request->route('id')]); - - $currency_object_object = new CurrencyRateObject( - $currency_rate_query->currency_id, - $request->input('selling', $currency_rate_query->selling), - $currency_rate_query->payment_method_type - ); - - $this->canUpdateCurrencyRate->passes($currency_object_object); - $currency_rate_query = $this->updatesCurrencyRate->execute($currency_rate_query, $currency_object_object); - - $currency_rate_log_query = $this->createsCurrencyRateLog->execute($currency_rate_query); - - DB::commit(); - - return $this->resourceResponse(new CurrencyRateResource($currency_rate_query)); - - } catch (\Exception $exception){ - dd($exception); - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/DataTransferObjects/CurrencyRateObject.php b/app/Classes/Modules/CurrencyRates/DataTransferObjects/CurrencyRateObject.php deleted file mode 100644 index bd58dec9..00000000 --- a/app/Classes/Modules/CurrencyRates/DataTransferObjects/CurrencyRateObject.php +++ /dev/null @@ -1,58 +0,0 @@ -currency_id = $currency_id; - $this->selling = $selling; - $this->payment_method_type = $payment_method_type; - } - - /** - * @return int - */ - public function getCurrencyId(): ?int - { - return $this->currency_id; - } - - /** - * @return string - */ - public function getSelling(): ?string - { - return $this->selling; - } - - /** - * @return string - */ - public function getPaymentMethodType(): ?string - { - return $this->payment_method_type; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/Services/CreatesCurrencyRate.php b/app/Classes/Modules/CurrencyRates/Services/CreatesCurrencyRate.php deleted file mode 100644 index 9de33ca7..00000000 --- a/app/Classes/Modules/CurrencyRates/Services/CreatesCurrencyRate.php +++ /dev/null @@ -1,26 +0,0 @@ -currency_id = $object->getCurrencyId(); - $model->selling = $object->getSelling(); - $model->payment_method_type = $object->getPaymentMethodType(); - - return $this->handler($model); - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/Services/DeletesCurrencyRate.php b/app/Classes/Modules/CurrencyRates/Services/DeletesCurrencyRate.php deleted file mode 100644 index e6167808..00000000 --- a/app/Classes/Modules/CurrencyRates/Services/DeletesCurrencyRate.php +++ /dev/null @@ -1,14 +0,0 @@ -handler($model); - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/Standards/Rules/CanCreateCurrencyRate.php b/app/Classes/Modules/CurrencyRates/Standards/Rules/CanCreateCurrencyRate.php deleted file mode 100644 index 56ad219a..00000000 --- a/app/Classes/Modules/CurrencyRates/Standards/Rules/CanCreateCurrencyRate.php +++ /dev/null @@ -1,55 +0,0 @@ -currencyRateValidation = $currencyRateValidation; - } - - /** - * @return bool - */ - protected function authorized(): bool - { - // TODO Set Authorization rules - if (!\Auth::user()->can('add currency_rate')) { - return false; - } - - return true; - } - - /** - * @param SegmentObject $object - * @return bool - * @throws \App\Classes\Exceptions\RequestValidationException - */ - protected function validators($object): bool - { - return $this->currencyRateValidation->validate($object, 'POST'); - } - - /** - * @param SegmentObject $object - * @return bool - */ - protected function criteria($object): bool - { - return true; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/CurrencyRates/Standards/Rules/CanUpdateCurrencyRate.php b/app/Classes/Modules/CurrencyRates/Standards/Rules/CanUpdateCurrencyRate.php deleted file mode 100644 index 8dcb1982..00000000 --- a/app/Classes/Modules/CurrencyRates/Standards/Rules/CanUpdateCurrencyRate.php +++ /dev/null @@ -1,58 +0,0 @@ -currencyRateValidation = $currencyRateValidation; - } - - /** - * @return bool - */ - protected function authorized(): bool - { - // TODO Set Authorization rules - - if (!\Auth::user()->can('view currency_rate')) { - return false; - } - - return true; - } - - /** - * @param CurrencyRateValidation $object - * @return bool - * @throws \App\Classes\Exceptions\RequestValidationException - */ - protected function validators($object): bool - { - return $this->currencyRateValidation->validate($object, 'PUT'); - } - - /** - * @param CurrencyRateValidation $object - * @return bool - */ - protected function criteria($object): bool - { - return true; - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/ControllersLogic/ApproveDocumentLogic.php b/app/Classes/Modules/Documents/ControllersLogic/ApproveDocumentLogic.php index ab3f33c1..c15ab3ac 100644 --- a/app/Classes/Modules/Documents/ControllersLogic/ApproveDocumentLogic.php +++ b/app/Classes/Modules/Documents/ControllersLogic/ApproveDocumentLogic.php @@ -2,24 +2,19 @@ namespace App\Classes\Modules\Documents\ControllersLogic; +use App\Classes\Modules\Documents\Standards\Rules\CanApproveDocument; use App\Http\Resources\DocumentResource; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Documents\Services\FetchesDocument; -use App\Classes\Modules\Documents\Standards\Rules\CanUpdateDocument; use App\Classes\Modules\Documents\Services\ApprovesDocument; -use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; -use App\Classes\ValueObjects\Constants\ObjectStatus; - -use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; -class ApproveDocumentLogic extends AbstractControllersLogic +class ApproveDocumentLogic extends AbstractControllerLogic { /** @@ -32,8 +27,8 @@ class ApproveDocumentLogic extends AbstractControllersLogic ]; } - /** @var CanUpdateDocument */ - private $canUpdateDocument; + /** @var CanApproveDocument*/ + private $canApproveDocument; /** @var ApprovesDocument */ private $approvesDocument; @@ -43,18 +38,14 @@ class ApproveDocumentLogic extends AbstractControllersLogic /** - * ApproveDocumentLogic constructor. - * @param CanUpdateDocument $canUpdateDocument + * RejectDocumentLogic constructor. + * @param CanApproveDocument $canApproveDocument * @param ApprovesDocument $approvesDocument * @param FetchesDocument $fetchesDocument */ - public function __construct( - canUpdateDocument $canUpdateDocument, - ApprovesDocument $approvesDocument, - FetchesDocument $fetchesDocument - ) + public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, FetchesDocument $fetchesDocument) { - $this->canUpdateDocument = $canUpdateDocument; + $this->canApproveDocument = $canApproveDocument; $this->approvesDocument = $approvesDocument; $this->fetchesDocument = $fetchesDocument; } @@ -62,37 +53,21 @@ class ApproveDocumentLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { - DB::beginTransaction(); - $document_query = $this->fetchesDocument->execute(['id' => $request->route('id')]); + $document = $this->fetchesDocument->execute(['id' => $request->route('id')]); - $document_object = new DocumentObject( - $document_query->owner_id, - $document_query->owner_type, - $document_query->document_type, - $document_query->reference, - ObjectStatus::ACTIVE, - \Auth::user()->id, - $document_query->issued_date, - $document_query->expired_date, - $document_query->approved_date - ); - $this->canUpdateDocument->passes($document_object); - $document_query = $this->approvesDocument->execute($document_query, $document_object); - - DB::commit(); + $this->canApproveDocument->passes(); - return $this->resourceResponse(new DocumentResource($document_query)); + $document_query = $this->approvesDocument->execute($document); + + return $this->resourceResponse(new DocumentResource($document_query)); - } catch (\Exception $exception){ - dd($exception); - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } } } \ No newline at end of file diff --git a/app/Classes/Modules/Documents/ControllersLogic/ListDocumentLogic.php b/app/Classes/Modules/Documents/ControllersLogic/ListDocumentLogic.php index 37bdf2f5..02bdac9d 100644 --- a/app/Classes/Modules/Documents/ControllersLogic/ListDocumentLogic.php +++ b/app/Classes/Modules/Documents/ControllersLogic/ListDocumentLogic.php @@ -3,7 +3,7 @@ namespace App\Classes\Modules\Documents\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Documents\Services\ListsDocuments; use App\Classes\Modules\Documents\Standards\Rules\CanListDocuments; use App\Http\Resources\DocumentResource; @@ -11,7 +11,7 @@ use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class ListDocumentLogic extends AbstractControllersLogic +class ListDocumentLogic extends AbstractControllerLogic { /** @@ -30,9 +30,8 @@ class ListDocumentLogic extends AbstractControllersLogic /** @var ListsDocuments */ private $listsDocuments; - /** - * ListDocumentLogic constructor. + * ListStandardSegmentLogic constructor. * @param CanListDocuments $canListDocuments * @param ListsDocuments $listsDocuments */ @@ -46,37 +45,18 @@ class ListDocumentLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { - $document_type = $request->input('document_type'); - $reference = $request->input('reference'); - $status = $request->input('status'); + $this->canListDocuments->passes(); - $data = []; + $query = $this->listsDocuments->execute($this->listsDocuments->deserializeFilters($request->input('filters'))); - if ($document_type) { - $data['document_type'] = $document_type; - } - if ($reference) { - $data['reference'] = $reference; - } - if ($status) { - $data['status'] = $status; - } - - $this->canListDocuments->passes(); - - $query = $this->listsDocuments->execute($data); - - return $this->collectionResponse(DocumentResource::collection($query)); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->collectionResponse(DocumentResource::collection($query)); } diff --git a/app/Classes/Modules/Documents/ControllersLogic/RejectDocumentLogic.php b/app/Classes/Modules/Documents/ControllersLogic/RejectDocumentLogic.php new file mode 100644 index 00000000..c8f0cf8c --- /dev/null +++ b/app/Classes/Modules/Documents/ControllersLogic/RejectDocumentLogic.php @@ -0,0 +1,71 @@ + 'Reject Document', + 'message' => 'You have successfully rejected the Document' + ]; + } + + /** @var CanApproveDocument*/ + private $canApproveDocument; + + /** @var RejectsDocument */ + private $rejectsDocument; + + /** @var FetchesDocument */ + private $fetchesDocument; + + /** + * RejectDocumentLogic constructor. + * @param CanApproveDocument $canApproveDocument + * @param RejectsDocument $rejectsDocument + * @param FetchesDocument $fetchesDocument + */ + public function __construct(CanApproveDocument $canApproveDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument) + { + $this->canApproveDocument = $canApproveDocument; + $this->rejectsDocument = $rejectsDocument; + $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->canApproveDocument->passes(); + + $document_query = $this->rejectsDocument->execute($document); + + return $this->resourceResponse(new DocumentResource($document_query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/ControllersLogic/RenderDocumentLogic.php b/app/Classes/Modules/Documents/ControllersLogic/RenderDocumentLogic.php new file mode 100644 index 00000000..7ef87960 --- /dev/null +++ b/app/Classes/Modules/Documents/ControllersLogic/RenderDocumentLogic.php @@ -0,0 +1,65 @@ + '', + 'message' => '' + ]; + } + + /** @var CanRenderDocument */ + private $canRenderDocument; + + /** @var JWT */ + private $manager; + + /** + * RenderDocumentLogic constructor. + * @param CanRenderDocument $canRenderDocument + * @param JWT $manager + */ + public function __construct(CanRenderDocument $canRenderDocument, JWT $manager) + { + $this->canRenderDocument = $canRenderDocument; + $this->manager = $manager; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws AccessForbiddenException + * @throws RequestValidationException + * @throws ResourceNotFoundException + * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException + */ + public function logic(Request $request) : JsonResponse + { + $file = $request->route('fileName'); + + $this->canRenderDocument->passes(); + + if(!Storage::disk('documents')->exists($file)) + { + throw new ResourceNotFoundException(); + } + return $this->response(['src' => Storage::disk('documents')->get($file)]); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php b/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php index e4932b42..8f73dc1b 100644 --- a/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php +++ b/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php @@ -2,141 +2,79 @@ namespace App\Classes\Modules\Documents\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; +use App\Classes\Modules\Documents\Services\ConvertsBase64ToFile; class DocumentObject implements DataTransferObject { - /** @var int|null */ - private $owner_id; - /** @var int|null */ - private $owner_type; - - /** @var string|null */ + /** @var string */ private $document_type; - /** @var string|null */ + /** @var array */ + private $files; + + /** @var string */ private $reference; - /** @var int|null */ + /** @var int */ private $status; - /** @var int|null */ - private $approved_by; - - /** @var timestamp|null */ - private $issued_date; - - /** @var timestamp|null */ - private $expired_date; - - /** @var timestamp|null */ - private $approved_date; + /** @var string|null */ + private $path; /** - * CompanyObject constructor. - * @param int|null $owner_id - * @param int|null $owner_type - * @param null|string $document_type - * @param string|null $reference - * @param int|null $status - * @param int|null $approved_by - * @param timestamp|null $issued_date - * @param timestamp|null $expired_date - * @param timestamp|null $approved_date + * DocumentObject constructor. + * @param string $document_type + * @param array $files + * @param string $reference + * @param int $status + * @param null|string $path */ - public function __construct( - ?int $owner_id, - ?int $owner_type, - ?string $document_type, - ?string $reference, - ?int $status, - ?int $approved_by, - ?timestamp $issued_date, - ?timestamp $expired_date, - ?timestamp $approved_date - ) + public function __construct(string $document_type, array $files, string $reference, int $status, ?string $path = '') { - $this->owner_id = $owner_id; - $this->owner_type = $owner_type; $this->document_type = $document_type; + $this->files = $files; $this->reference = $reference; $this->status = $status; - $this->approved_by = $approved_by; - $this->issued_date = $issued_date; - $this->expired_date = $expired_date; - $this->approved_date = $approved_date; + $this->path = $path; } - /** - * @return int|null - */ - public function getOwnerId(): ?int - { - return $this->owner_id; - } /** - * @return int|null + * @return string */ - public function getOwnerType(): ?int - { - return $this->owner_type; - } - - /** - * @return string|null - */ - public function getDocumentType(): ?string + public function getDocumentType(): string { return $this->document_type; } /** - * @return string|null + * @return string */ - public function getReference(): ?string + public function getReference(): string { return $this->reference; } /** - * @return int|null + * @return int */ - public function getStatus(): ?int + public function getStatus(): int { return $this->status; } - /** - * @return int|null - */ - public function getApprovedBy(): ?int - { - return $this->approved_by; - } /** - * @return timestamp|null + * @return array + * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function getIssuedDate(): ?timestamp + public function getFiles(): array { - return $this->issued_date; + return (new ConvertsBase64ToFile($this->path))->convert($this->files); } - /** - * @return timestamp|null - */ - public function getExpiredDate(): ?timestamp - { - return $this->expired_date; - } - /** - * @return timestamp|null - */ - public function getApprovedDate(): ?timestamp - { - return $this->approved_date; - } + } \ No newline at end of file diff --git a/app/Classes/Modules/Documents/DataTransferObjects/FileObject.php b/app/Classes/Modules/Documents/DataTransferObjects/FileObject.php index e4d205a5..ed289eac 100644 --- a/app/Classes/Modules/Documents/DataTransferObjects/FileObject.php +++ b/app/Classes/Modules/Documents/DataTransferObjects/FileObject.php @@ -2,58 +2,85 @@ namespace App\Classes\Modules\Documents\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\General\Interfaces\DataTransferObject; +use App\Classes\ValueObjects\Constants\FileType; +use Illuminate\Support\Str; +use Intervention\Image\ImageManager; class FileObject implements DataTransferObject { - /** @var int|null */ - private $document_id; - - /** @var text|null */ - private $file; - - /** @var string|null */ - private $file_type; + /** @var string */ + private $data; /** - * CompanyObject constructor. - * @param int|null $document_id - * @param null|string $file - * @param string|null $file_type + * FileInfoObject constructor. + * @param string $data */ - public function __construct( - ?int $document_id, - ?string $file, - ?string $file_type - ) + public function __construct(string $data) { - $this->document_id = $document_id; - $this->file = $file; - $this->file_type = $file_type; + $this->data = $data; } /** - * @return int|null + * @return \Intervention\Image\Image|string + * @throws MalformedRequestException */ - public function getDocumentId(): ?int + public function getData() { - return $this->document_id; + return $this->getExtension() === 'pdf' ? $this->data : (new imageManager())->make($this->data); } /** - * @return string|null + * @return string */ - public function getFile(): ?string + public function getFileName(): string { - return $this->file; + return (string) Str::uuid(); } /** - * @return string|null + * @return string */ - public function getFileType(): ?string + public function getMimeType(): string { - return $this->file_type; + return finfo_file(finfo_open(), $this->data, FILEINFO_MIME_TYPE); } + /** + * @return string + * @throws MalformedRequestException + */ + public function getExtension(): string + { + if(array_key_exists($this->getMimeType(), FileType::EXTENSION)){ + return FileType::EXTENSION[$this->getMimeType()]; + } + + throw new MalformedRequestException('Failed to save file due to Unknown file extension'); + } + + /** + * @return string + * @throws MalformedRequestException + */ + public function getDecodedData(): string + { + return $this->getExtension() === 'pdf' ? + base64_decode((explode('base64,', $this->getData()))[1]): + $this->getData()->encode('data-url')->encoded; + } + + /** + * @param string $data + */ + public function setData(string $data): void + { + $this->data = $data; + } + + + + + } \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/ApprovesDocument.php b/app/Classes/Modules/Documents/Services/ApprovesDocument.php index 206d9efd..9458774e 100644 --- a/app/Classes/Modules/Documents/Services/ApprovesDocument.php +++ b/app/Classes/Modules/Documents/Services/ApprovesDocument.php @@ -3,21 +3,24 @@ namespace App\Classes\Modules\Documents\Services; use App\Classes\General\Eloquent\AbstractUpdateRecord; -use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; +use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Models\Document; +use Carbon\Carbon; class ApprovesDocument extends AbstractUpdateRecord { /** - * @param DocumentObject $object + * @param Document $model * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(Document $model, DocumentObject $object) + public function execute(Document $model) { - $model->status = $object->getStatus(); - $model->approved_by = $object->getApprovedBy(); + $model->status = ApprovalStatus::APPROVED; + $model->approver = Auth()->user()->id; + $model->approval_date = Carbon::now(); + return $this->handler($model); } } \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/Convert64ToFile.php b/app/Classes/Modules/Documents/Services/Convert64ToFile.php deleted file mode 100644 index 611e6a47..00000000 --- a/app/Classes/Modules/Documents/Services/Convert64ToFile.php +++ /dev/null @@ -1,147 +0,0 @@ -generateFolder($path); - - foreach ($file_set as $key => $row) { - - $file_data = $row; - $filename = (string) Str::uuid(); - - $f = finfo_open(); - $mime_type = finfo_file($f, $file_data, FILEINFO_MIME_TYPE); - - $extension = ''; - switch ($mime_type) { - case 'image/gif': - $extension = 'gif'; - break; - case 'image/png': - $extension = 'png'; - break; - case 'image/jpeg': - $extension = 'jpg'; - break; - case 'application/pdf': - $extension = 'pdf'; - break; - } - - if (empty($extension)) { - return false; - } - - $filename_with_ext = $filename . '.' . $extension; - - if ($extension != 'pdf') { - $img = Image::make($file_data)->save($folder_path . '/' . $filename_with_ext); - $file = $this->generateImages($path, $filename_with_ext, $filename, $extension); - } - else { - $file_data = explode('base64,', $file_data); - $file_data = base64_decode($file_data[1]); - $file = $this->generatePdf($path, $file_data, $filename, $extension); - } - - $file_info[] = [ - 'path' => $path, - 'filename' => $filename_with_ext, - 'mime_type' => $mime_type, - 'extension' => $extension, - 'file_info' => empty($file) ? [] : $file, - ]; - } - - return $file_info; - } - - /** - * @param string|null path - * @param string|null pdfdata - * @param string|null filename - * @param string|null extension - */ - public static function generatePdf($path = '', $pdfdata = '', $filename = '', $extension = '') - { - $file_info = []; - $file = \File::put(storage_path($path) . '/' . $filename . '.' . $extension, $pdfdata); - $file_info['original']['file'] = 'storage/' . $path . '/' . $filename . '.' . $extension; - $file_info['large']['file'] = 'storage/' . $path . '/' . $filename . '.' . $extension; - $file_info['medium']['file'] = 'storage/' . $path . '/' . $filename . '.' . $extension; - $file_info['small']['file'] = 'storage/' . $path . '/' . $filename . '.' . $extension; - - return $file_info; - } - - /** - * @param string|null path - * @param string|null file - * @param string|null filename - * @param string|null extension - */ - public function generateImages($path = '', $file = '', $filename = '', $extension = '') - { - $file_info = []; - - $img = Image::make(storage_path($path) . '/' . $file); - $file_info['original']['file'] = 'storage/' . $path . '/' . $file; - $file_info['original']['width'] = $img->width(); - $file_info['original']['height'] = $img->height(); - - $img->widen(800, function ($constraint) { - $constraint->upsize(); - })->heighten(800, function ($constraint) { - $constraint->upsize(); - }); - $img->save(storage_path($path) . '/' . $filename . '_' . 'l.' . $extension); - $file_info['large']['file'] = 'storage/' . $path . '/' . $filename . '_' . 'l.' . $extension; - $file_info['large']['width'] = $img->width(); - $file_info['large']['height'] = $img->height(); - - $img->widen(480, function ($constraint) { - $constraint->upsize(); - })->heighten(480, function ($constraint) { - $constraint->upsize(); - }); - $img->save(storage_path($path) . '/' . $filename . '_' . 'm.' . $extension); - $file_info['medium']['file'] = 'storage/' . $path . '/' . $filename . '_' . 'm.' . $extension; - $file_info['medium']['width'] = $img->width(); - $file_info['medium']['height'] = $img->height(); - - $img->widen(320, function ($constraint) { - $constraint->upsize(); - })->heighten(320, function ($constraint) { - $constraint->upsize(); - }); - $img->save(storage_path($path) . '/' . $filename . '_' . 's.' . $extension); - $file_info['small']['file'] = 'storage/' . $path . '/' . $filename . '_' . 's.' . $extension; - $file_info['small']['width'] = $img->width(); - $file_info['small']['height'] = $img->height(); - - return $file_info; - } - - /** - * @param string|null set_path - */ - public function generateFolder($set_path = '') - { - $folder = storage_path($set_path); - - \File::isDirectory($folder) or \File::makeDirectory($folder, 0777, true, true); //check folder is exist - return $folder; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php b/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php new file mode 100644 index 00000000..51df8bb8 --- /dev/null +++ b/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php @@ -0,0 +1,127 @@ +path = $path ? $path.'/': ''; + $this->filesInfo = []; + + File::isDirectory(storage_path($this->path)) or + File::makeDirectory(storage_path($this->path), 0700, true, true); + } + + + /** + * @param array $files + * @return array + * @throws MalformedRequestException + */ + public function convert($files = []){ + foreach ($files as $file) { + $object = new FileObject($file); + $object->getExtension() === 'pdf' ? $this->generatePDF($object) : $this->generateImage($object); + + } + + return $this->filesInfo; + + } + + /** + * @param FileObject $file + * @throws MalformedRequestException + */ + private function generatePDF(FileObject $file){ + + $filePath = $this->generateFile($file); + $this->updateFiles($file, [ 'original' => [ 'file' => $filePath ] ]); + } + + /** + * @param FileObject $file + * @throws MalformedRequestException + */ + private function generateImage(FileObject $file){ + + $fileInfo = []; + + foreach (['original' => null, 'large' => 800, 'medium' => 480, 'small' => 320] as $size => $value) { + $suffix = $size !== 'original' ? '_'.$size : ''; + + if($size !== 'original') { + $thumbnail = $file->getData()->widen($value, function ($constraint) { + + $constraint->upsize(); + + })->heighten($value, function ($constraint) { + + $constraint->upsize(); + + }); + + $file->setData($thumbnail->encode('data-url')->encoded); + } + + + $filePath = $this->generateFile($file, $suffix); + + $fileInfo[] = [ $size => [ 'file' => $filePath, 'width' => $file->getData()->width(), 'height' => $file->getData()->height() ]]; + + + } + + $this->updateFiles($file, $fileInfo); + + } + + /** + * @param FileObject $file + * @param string $suffix + * @return string + * @throws MalformedRequestException + */ + private function generateFile(FileObject $file, string $suffix = '') { + + $filePath = $this->path.$file->getFileName().$suffix.'.'.$file->getExtension(); + + Storage::disk('documents')->put($filePath, $file->getDecodedData()); + + return $filePath; + + } + + /** + * @param FileObject $file + * @param array $fileInfo + * @throws MalformedRequestException + */ + private function updateFiles(FileObject $file, array $fileInfo){ + $this->filesInfo[] = json_encode([ + 'path' => $this->path, + 'filename' => $file->getFileName().'.'.$file->getExtension(), + 'mime_type' => $file->getMimeType(), + 'extension' => $file->getExtension(), + 'file_info' => $fileInfo + ]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/CreatesDocument.php b/app/Classes/Modules/Documents/Services/CreatesDocument.php index 33f4523c..16e7d094 100644 --- a/app/Classes/Modules/Documents/Services/CreatesDocument.php +++ b/app/Classes/Modules/Documents/Services/CreatesDocument.php @@ -2,26 +2,25 @@ namespace App\Classes\Modules\Documents\Services; -use App\Classes\General\Eloquent\AbstractUpdateRecord; +use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord; +use App\Classes\General\Interfaces\Documentable; use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; use App\Models\Document; -class CreatesDocument extends AbstractUpdateRecord +class CreatesDocument extends AbstractUpdateRelationshipRecord { /** + * @param Documentable $documentable * @param DocumentObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(DocumentObject $object) + public function execute(Documentable $documentable, DocumentObject $object) { $model = new Document(); - $model->owner_id = $object->getOwnerId(); - $model->owner_type = $object->getOwnerType(); $model->document_type = $object->getDocumentType(); $model->reference = $object->getReference(); - $model->status = $object->getStatus(); - - return $this->handler($model); + + return $this->handler($documentable->documents(), $model); } } \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/CreatesFile.php b/app/Classes/Modules/Documents/Services/CreatesFile.php deleted file mode 100644 index ac87eb72..00000000 --- a/app/Classes/Modules/Documents/Services/CreatesFile.php +++ /dev/null @@ -1,25 +0,0 @@ -document_id = $object->getDocumentId(); - $model->file = $object->getFile(); - $model->file_type = $object->getFileType(); - - return $this->handler($model); - } -} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/CreatesFiles.php b/app/Classes/Modules/Documents/Services/CreatesFiles.php new file mode 100644 index 00000000..30c85a13 --- /dev/null +++ b/app/Classes/Modules/Documents/Services/CreatesFiles.php @@ -0,0 +1,32 @@ +getFiles() as $file) { + + $model = new File(['file' => $file]); + $models[] = $this->handler($document->files(), $model); + + } + + return $models; + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Services/FetchesDocument.php b/app/Classes/Modules/Documents/Services/FetchesDocument.php index 40dbb1c8..1aa12c87 100644 --- a/app/Classes/Modules/Documents/Services/FetchesDocument.php +++ b/app/Classes/Modules/Documents/Services/FetchesDocument.php @@ -13,9 +13,8 @@ class FetchesDocument extends AbstractFetchRecord /** @var Document */ private $repository; - /** - * FetchesDocument constructor. + * FetchesUser constructor. * @param Document $repository */ public function __construct(Document $repository) diff --git a/app/Classes/Modules/Documents/Services/RejectsDocument.php b/app/Classes/Modules/Documents/Services/RejectsDocument.php new file mode 100644 index 00000000..4a7c7bfa --- /dev/null +++ b/app/Classes/Modules/Documents/Services/RejectsDocument.php @@ -0,0 +1,26 @@ +status = ApprovalStatus::REJECTED; + $model->approver = Auth()->user()->id; + $model->approval_date = Carbon::now(); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Documents/Standards/Rules/CanApproveDocument.php b/app/Classes/Modules/Documents/Standards/Rules/CanApproveDocument.php new file mode 100644 index 00000000..544b605c --- /dev/null +++ b/app/Classes/Modules/Documents/Standards/Rules/CanApproveDocument.php @@ -0,0 +1,39 @@ + $object->getOwnerId(), - 'owner_type' => $object->getOwnerType(), 'document_type' => $object->getDocumentType(), 'reference' => $object->getReference(), 'status' => $object->getStatus(), - 'approved_by' => $object->getApprovedBy(), - 'issued_date' => $object->getIssuedDate(), - 'expired_date' => $object->getExpiredDate(), - 'approved_date' => $object->getApprovedDate() ]; } @@ -32,14 +26,9 @@ class DocumentValidation extends AbstractValidation protected function rules(): array { return [ - 'owner_id' => 'required', - 'owner_type' => 'required', 'document_type' => 'required', 'reference' => 'required', - 'status' => '', - 'issued_date' => '', - 'expired_date' => '', - 'approved_date' => '', + 'status' => 'required' ]; } diff --git a/app/Classes/Modules/Receipts/ControllersLogic/CreateReceiptLogic.php b/app/Classes/Modules/Receipts/ControllersLogic/CreateReceiptLogic.php index fd4cd12c..6c9e935f 100644 --- a/app/Classes/Modules/Receipts/ControllersLogic/CreateReceiptLogic.php +++ b/app/Classes/Modules/Receipts/ControllersLogic/CreateReceiptLogic.php @@ -2,7 +2,7 @@ namespace App\Classes\Modules\Receipts\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Receipts\Standards\Rules\CanCreateReceipt; use App\Classes\Modules\Receipts\Standards\Rules\CanCreateReceiptDetail; @@ -26,7 +26,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class CreateReceiptLogic extends AbstractControllersLogic +class CreateReceiptLogic extends AbstractControllerLogic { @@ -60,11 +60,18 @@ class CreateReceiptLogic extends AbstractControllersLogic private $createsReceiptDetail; private $fetchesTransaction; + /** * CreateWalletLogic constructor. - * @param CreatesWallet $createsWallet - * @param GeneratesWalletCode $generatesWalletCode - * @param CanCreateCompanyWallet $canCreateCompanyWallet + * @param GeneratesReceiptBillNo $generatesReceiptBillNo + * @param CanCreateReceipt $canCreateReceipt + * @param FetchesCurrency $fetchesCurrency + * @param RateCalculatesCurrency $rateCalculatesCurrency + * @param FetchesCompany $fetchesCompany + * @param CreatesReceipt $createsReceipt + * @param CanCreateReceiptDetail $canCreateReceiptDetail + * @param CreatesReceiptDetail $createsReceiptDetail + * @param FetchesTransaction $fetchesTransaction */ public function __construct( GeneratesReceiptBillNo $generatesReceiptBillNo, CanCreateReceipt $canCreateReceipt, diff --git a/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptDetailObject.php b/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptDetailObject.php index 6cf2b16e..4b234773 100644 --- a/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptDetailObject.php +++ b/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptDetailObject.php @@ -2,7 +2,7 @@ namespace App\Classes\Modules\Receipts\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; class ReceiptDetailObject implements DataTransferObject { diff --git a/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptObject.php b/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptObject.php index d8e66907..91107fc3 100644 --- a/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptObject.php +++ b/app/Classes/Modules/Receipts/DataTransferObjects/ReceiptObject.php @@ -2,7 +2,7 @@ namespace App\Classes\Modules\Receipts\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; class ReceiptObject implements DataTransferObject { diff --git a/app/Classes/Modules/Receipts/Services/CreatesReceipt.php b/app/Classes/Modules/Receipts/Services/CreatesReceipt.php index 2892ae62..c93d10d4 100644 --- a/app/Classes/Modules/Receipts/Services/CreatesReceipt.php +++ b/app/Classes/Modules/Receipts/Services/CreatesReceipt.php @@ -9,7 +9,7 @@ use App\Models\Receipt; class CreatesReceipt extends AbstractUpdateRecord { /** - * @param WalletObject $object + * @param ReceiptObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ diff --git a/app/Classes/Modules/Receipts/Services/CreatesReceiptDetail.php b/app/Classes/Modules/Receipts/Services/CreatesReceiptDetail.php index 4a3f1c62..dbee82eb 100644 --- a/app/Classes/Modules/Receipts/Services/CreatesReceiptDetail.php +++ b/app/Classes/Modules/Receipts/Services/CreatesReceiptDetail.php @@ -9,7 +9,7 @@ use App\Models\ReceiptDetail; class CreatesReceiptDetail extends AbstractUpdateRecord { /** - * @param WalletObject $object + * @param ReceiptDetailObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ diff --git a/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceipt.php b/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceipt.php index 58321a3f..ea6b4f02 100644 --- a/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceipt.php +++ b/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceipt.php @@ -4,12 +4,13 @@ namespace App\Classes\Modules\Receipts\Standards\Rules; use App\Classes\General\Abstracts\AbstractRule; +use App\Classes\Modules\Receipts\DataTransferObjects\ReceiptObject; use App\Classes\Modules\Receipts\Standards\Validators\ReceiptValidation; class CanCreateReceipt extends AbstractRule { - /** @var WalletTransactionValidation */ + /** @var ReceiptValidation */ private $receiptValidation; @@ -29,7 +30,7 @@ class CanCreateReceipt extends AbstractRule } /** - * @param CompanyWalletValidation $object + * @param ReceiptObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -39,7 +40,7 @@ class CanCreateReceipt extends AbstractRule } /** - * @param SegmentCompanyValidation $object + * @param ReceiptObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceiptDetail.php b/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceiptDetail.php index edc788e4..71466752 100644 --- a/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceiptDetail.php +++ b/app/Classes/Modules/Receipts/Standards/Rules/CanCreateReceiptDetail.php @@ -4,12 +4,13 @@ namespace App\Classes\Modules\Receipts\Standards\Rules; use App\Classes\General\Abstracts\AbstractRule; +use App\Classes\Modules\Receipts\DataTransferObjects\ReceiptDetailObject; use App\Classes\Modules\Receipts\Standards\Validators\ReceiptDetailValidation; class CanCreateReceiptDetail extends AbstractRule { - /** @var WalletTransactionValidation */ + /** @var ReceiptDetailValidation */ private $receiptDetailValidation; @@ -29,7 +30,7 @@ class CanCreateReceiptDetail extends AbstractRule } /** - * @param CompanyWalletValidation $object + * @param ReceiptDetailObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -39,7 +40,7 @@ class CanCreateReceiptDetail extends AbstractRule } /** - * @param SegmentCompanyValidation $object + * @param ReceiptDetailObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/Receipts/Standards/Validators/ReceiptDetailValidation.php b/app/Classes/Modules/Receipts/Standards/Validators/ReceiptDetailValidation.php index b970549f..8feac483 100644 --- a/app/Classes/Modules/Receipts/Standards/Validators/ReceiptDetailValidation.php +++ b/app/Classes/Modules/Receipts/Standards/Validators/ReceiptDetailValidation.php @@ -3,7 +3,6 @@ namespace App\Classes\Modules\Receipts\Standards\Validators; use App\Classes\General\Abstracts\AbstractValidation; -use App\Classes\Modules\Receipts\DataTransferObjects\ReceiptDetailObject; class ReceiptDetailValidation extends AbstractValidation { diff --git a/app/Classes/Modules/Receipts/Standards/Validators/ReceiptValidation.php b/app/Classes/Modules/Receipts/Standards/Validators/ReceiptValidation.php index a1c98a3f..f0ab7bbe 100644 --- a/app/Classes/Modules/Receipts/Standards/Validators/ReceiptValidation.php +++ b/app/Classes/Modules/Receipts/Standards/Validators/ReceiptValidation.php @@ -3,7 +3,6 @@ namespace App\Classes\Modules\Receipts\Standards\Validators; use App\Classes\General\Abstracts\AbstractValidation; -use App\Classes\Modules\Receipts\DataTransferObjects\ReceiptObject; class ReceiptValidation extends AbstractValidation { diff --git a/app/Classes/Modules/SegmentCompanies/DataTransferObjects/SegmentCompanyObject.php b/app/Classes/Modules/SegmentCompanies/DataTransferObjects/SegmentCompanyObject.php deleted file mode 100644 index fc7c5386..00000000 --- a/app/Classes/Modules/SegmentCompanies/DataTransferObjects/SegmentCompanyObject.php +++ /dev/null @@ -1,45 +0,0 @@ -segment_id = $segment_id; - $this->company_id = $company_id; - } - - /** - * @return int|null - */ - public function getSegmentId(): ?int - { - return $this->segment_id; - } - - /** - * @return int|null - */ - public function getCompanyId(): ?int - { - return $this->company_id; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentCompanies/Services/CreatesSegmentCompany.php b/app/Classes/Modules/SegmentCompanies/Services/CreatesSegmentCompany.php deleted file mode 100644 index ae791fca..00000000 --- a/app/Classes/Modules/SegmentCompanies/Services/CreatesSegmentCompany.php +++ /dev/null @@ -1,21 +0,0 @@ -segment()->sync($object->getSegmentId()); - return $model; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentCompanies/Standards/Rules/CanCreateSegmentCompany.php b/app/Classes/Modules/SegmentCompanies/Standards/Rules/CanCreateSegmentCompany.php deleted file mode 100644 index 016066e4..00000000 --- a/app/Classes/Modules/SegmentCompanies/Standards/Rules/CanCreateSegmentCompany.php +++ /dev/null @@ -1,54 +0,0 @@ -segmentCompanyValidation = $segmentCompanyValidation; - } - - /** - * @return bool - */ - protected function authorized(): bool - { - // TODO Set Authorization rules - return true; - } - - /** - * @param SegmentCompanyValidation $object - * @return bool - * @throws \App\Classes\Exceptions\RequestValidationException - */ - protected function validators($object): bool - { - return $this->segmentCompanyValidation->validate($object); - } - - /** - * @param SegmentCompanyValidation $object - * @return bool - */ - protected function criteria($object): bool - { - return true; - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentCompanies/Standards/Validators/SegmentCompanyValidation.php b/app/Classes/Modules/SegmentCompanies/Standards/Validators/SegmentCompanyValidation.php deleted file mode 100644 index 2185c519..00000000 --- a/app/Classes/Modules/SegmentCompanies/Standards/Validators/SegmentCompanyValidation.php +++ /dev/null @@ -1,40 +0,0 @@ - $object->getSegmentId(), - 'company_id' => $object->getCompanyId(), - ]; - } - - /** - * @return array - */ - protected function rules(): array - { - return [ - 'segment_id' => 'required', - 'company_id' => 'required', - ]; - } - - /** - * @return array - */ - protected function messages(): array - { - return []; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllersLogic/CreateSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllersLogic/CreateSegmentConstantLogic.php deleted file mode 100644 index a0bc7b80..00000000 --- a/app/Classes/Modules/SegmentConstants/ControllersLogic/CreateSegmentConstantLogic.php +++ /dev/null @@ -1,105 +0,0 @@ - 'Created Segment Constant', - 'message' => 'You have successfully created a new Segment Constant' - ]; - } - - /** @var CanCreateSegmentConstant */ - private $canCreateSegmentConstant; - - /** @var CreatesSegmentConstant */ - private $createsSegmentConstant; - - /** @var FetchesSegmentConstant */ - private $fetchesSegmentConstant; - - /** @var FetchesSegment */ - private $fetchesSegment; - - - /** - * CreateSegmentConstantLogic constructor. - * @param CanCreateSegmentConstant $canCreateSegmentConstant - * @param CreatesSegmentConstant $createsSegmentConstant - * @param FetchesSegmentConstant $fetchesSegmentConstant - * @param FetchesSegment $fetchesSegment - */ - public function __construct( - CanCreateSegmentConstant $canCreateSegmentConstant, - CreatesSegmentConstant $createsSegmentConstant, - FetchesSegmentConstant $fetchesSegmentConstant, - FetchesSegment $fetchesSegment - ) - { - $this->canCreateSegmentConstant = $canCreateSegmentConstant; - $this->createsSegmentConstant = $createsSegmentConstant; - $this->fetchesSegmentConstant = $fetchesSegmentConstant; - $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->input('segment_id'), - ]); - - $standard_segment_constant_query = $this->fetchesSegmentConstant->execute([ - 'id' => $request->input('standard_segment_constant_id'), - ]); - - $segment_constant_object = new SegmentConstantObject( - $request->input('segment_id'), - $standard_segment_constant_query->name, - $standard_segment_constant_query->reference, - $standard_segment_constant_query->detail->type, - $request->input('detail') - ); - - $this->canCreateSegmentConstant->passes($segment_constant_object); - $standard_segment_constant_query = $this->createsSegmentConstant->execute($segment_query, $segment_constant_object); - - DB::commit(); - - return $this->resourceResponse(new SegmentConstantResource($standard_segment_constant_query)); - - } catch (\Exception $exception) { - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - - } -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllersLogic/ListStandardSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllersLogic/ListStandardSegmentConstantLogic.php deleted file mode 100644 index 40daa24d..00000000 --- a/app/Classes/Modules/SegmentConstants/ControllersLogic/ListStandardSegmentConstantLogic.php +++ /dev/null @@ -1,69 +0,0 @@ - 'Retrieved Standard Segment Constant', - 'message' => 'You have successfully retrieved a list of Standard Segment Constant' - ]; - } - - /** @var CanListStandardSegmentConstants */ - private $canListStandardSegmentConstants; - - /** @var ListsSegmentConstants */ - private $listsSegmentConstants; - - /** - * ListStandardSegmentConstantLogic constructor. - * @param CanListStandardSegmentConstants $canListStandardSegmentConstants - * @param ListsSegmentConstants $listsSegmentConstants - */ - public function __construct(CanListStandardSegmentConstants $canListStandardSegmentConstants, ListsSegmentConstants $listsSegmentConstants) - { - $this->canListStandardSegmentConstants = $canListStandardSegmentConstants; - $this->listsSegmentConstants = $listsSegmentConstants; - } - - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - $this->canListStandardSegmentConstants->passes(); - - $query = $this->listsSegmentConstants->execute( - [ - 'segment_id' => 1 - ] - ); - - return $this->collectionResponse(SegmentResource::collection($query)); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllersLogic/UpdateSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllersLogic/UpdateSegmentConstantLogic.php deleted file mode 100644 index 2b15bba3..00000000 --- a/app/Classes/Modules/SegmentConstants/ControllersLogic/UpdateSegmentConstantLogic.php +++ /dev/null @@ -1,92 +0,0 @@ - 'Updated Segment Constant', - 'message' => 'You have successfully updated the Segment Constant' - ]; - } - - /** @var CanUpdateSegmentConstant */ - private $canUpdateSegmentConstant; - - /** @var UpdatesSegmentConstant */ - private $updatesSegmentConstant; - - /** @var FetchesSegmentConstant */ - private $fetchesSegmentConstant; - - /** - * UpdateStandardSegmentConstantLogic constructor. - * @param CanUpdateSegmentConstant $canUpdateSegmentConstant - * @param UpdatesSegmentConstant $updatesSegmentConstant - * @param FetchesSegmentConstant $fetchesSegmentConstant - */ - public function __construct( - CanUpdateSegmentConstant $canUpdateSegmentConstant, - UpdatesSegmentConstant $updatesSegmentConstant, - FetchesSegmentConstant $fetchesSegmentConstant - ) - { - $this->canUpdateSegmentConstant = $canUpdateSegmentConstant; - $this->updatesSegmentConstant = $updatesSegmentConstant; - $this->fetchesSegmentConstant = $fetchesSegmentConstant; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $segment_constant_query = $this->fetchesSegmentConstant->execute(['id' => $request->route('id')]); - - $segment_constant_object = new SegmentConstantObject( - $segment_constant_query->segment_id, - $segment_constant_query->name, - $segment_constant_query->reference, - $segment_constant_query->detail->type, - $request->input('detail') - ); - - $this->canUpdateSegmentConstant->passes($segment_constant_object); - $segment_constant_query = $this->updatesSegmentConstant->execute($segment_constant_query, $segment_constant_object); - - DB::commit(); - - return $this->resourceResponse(new SegmentConstantResource($segment_constant_query)); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllersLogic/UpdateStandardSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllersLogic/UpdateStandardSegmentConstantLogic.php deleted file mode 100644 index fd8f76a4..00000000 --- a/app/Classes/Modules/SegmentConstants/ControllersLogic/UpdateStandardSegmentConstantLogic.php +++ /dev/null @@ -1,91 +0,0 @@ - 'Updated Standard Segment Constant', - 'message' => 'You have successfully updated the Standard Segment Constant' - ]; - } - - /** @var CanUpdateStandardSegmentConstant */ - private $canUpdateStandardSegmentConstant; - - /** @var UpdatesSegmentConstantTax */ - private $updatesSegmentConstant; - - /** @var FetchesSegmentConstant */ - private $fetchesSegmentConstant; - - /** - * UpdateStandardSegmentConstantLogic constructor. - * @param CanUpdateStandardSegmentConstant $canUpdateStandardSegmentConstant - * @param UpdatesSegmentConstant $updatesSegmentConstant - * @param FetchesSegmentConstant $fetchesSegmentConstant - */ - public function __construct( - CanUpdateStandardSegmentConstant $canUpdateStandardSegmentConstant, - UpdatesSegmentConstant $updatesSegmentConstant, - FetchesSegmentConstant $fetchesSegmentConstant - ) - { - $this->canUpdateStandardSegmentConstant = $canUpdateStandardSegmentConstant; - $this->updatesSegmentConstant = $updatesSegmentConstant; - $this->fetchesSegmentConstant = $fetchesSegmentConstant; - } - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - DB::beginTransaction(); - - $segment_constant_query = $this->fetchesSegmentConstant->execute(['id' => $request->route('id')]); - - $segment_constant_object = new SegmentConstantObject( - $segment_constant_query->segment_id, - $segment_constant_query->name, - $segment_constant_query->reference, - $segment_constant_query->detail->type, - $request->input('detail') - ); - - $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); - $segment_constant_query = $this->updatesSegmentConstant->execute($segment_constant_query, $segment_constant_object); - - DB::commit(); - - return $this->resourceResponse(new SegmentConstantResource($segment_constant_query)); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantObject.php b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantObject.php deleted file mode 100644 index 0d8c6ce8..00000000 --- a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantObject.php +++ /dev/null @@ -1,86 +0,0 @@ -segment_id = $segment_id; - $this->name = $name; - $this->reference = $reference; - $this->type = $type; - $this->detail = $detail; - } - - /** - * @return int - */ - public function getSegmentId(): ?int - { - return $this->segment_id; - } - - /** - * @return string - */ - public function getName(): ?string - { - return $this->name; - } - - /** - * @return string - */ - public function getReference(): ?string - { - return $this->reference; - } - - /** - * @return string - */ - public function getType(): ?string - { - return $this->type; - } - - /** - * @return array - */ - public function getDetail(): ?array - { - return $this->detail; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstant.php b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstant.php deleted file mode 100644 index 72d22d90..00000000 --- a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstant.php +++ /dev/null @@ -1,27 +0,0 @@ -segment_id = $object->getSegmentId(); - $model->name = $object->getName(); - $model->reference = $object->getReference(); - $model->detail = json_encode($object->getDetail()); - - return $this->handler($model); - } -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanCreateSegmentConstant.php b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanCreateSegmentConstant.php deleted file mode 100644 index f8004575..00000000 --- a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanCreateSegmentConstant.php +++ /dev/null @@ -1,55 +0,0 @@ -segmentConstantValidation = $segmentConstantValidation; - } - - /** - * @return bool - */ - protected function authorized(): bool - { - // TODO Set Authorization rules - if (!\Auth::user()->can('add segment_constant')) { - return false; - } - - return true; - } - - /** - * @param SegmentObject $object - * @return bool - * @throws \App\Classes\Exceptions\RequestValidationException - */ - protected function validators($object): bool - { - return $this->segmentConstantValidation->validate($object, 'POST'); - } - - /** - * @param SegmentObject $object - * @return bool - */ - protected function criteria($object): bool - { - return true; - } -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanListStandardSegmentConstants.php b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanListStandardSegmentConstants.php deleted file mode 100644 index 094cdd48..00000000 --- a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanListStandardSegmentConstants.php +++ /dev/null @@ -1,45 +0,0 @@ -can('view standard_segment_constant')) { - return false; - } - - 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; - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateSegmentConstant.php b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateSegmentConstant.php deleted file mode 100644 index 2e1fa8a8..00000000 --- a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateSegmentConstant.php +++ /dev/null @@ -1,58 +0,0 @@ -segmentConstantValidation = $segmentConstantValidation; - } - - /** - * @return bool - */ - protected function authorized(): bool - { - // TODO Set Authorization rules - - if (!\Auth::user()->can('view segment_constant')) { - return false; - } - - return true; - } - - /** - * @param SegmentConstantValidation $object - * @return bool - * @throws \App\Classes\Exceptions\RequestValidationException - */ - protected function validators($object): bool - { - return $this->segmentConstantValidation->validate($object, 'PUT'); - } - - /** - * @param SegmentConstantValidation $object - * @return bool - */ - protected function criteria($object): bool - { - return true; - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateStandardSegmentConstant.php b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateStandardSegmentConstant.php deleted file mode 100644 index 678c7987..00000000 --- a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateStandardSegmentConstant.php +++ /dev/null @@ -1,59 +0,0 @@ -segmentConstantValidation = $segmentConstantValidation; - } - - /** - * @return bool - */ - protected function authorized(): bool - { - // TODO Set Authorization rules - - if (!\Auth::user()->can('view standard_segment_constant')) { - return false; - } - - return true; - } - - /** - * @param SegmentConstantValidation $object - * @return bool - * @throws \App\Classes\Exceptions\RequestValidationException - */ - protected function validators($object): bool - { - return $this->segmentConstantValidation->validate($object, 'PUT'); - } - - /** - * @param SegmentConstantValidation $object - * @return bool - */ - protected function criteria($object): bool - { - return true; - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/CreateSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/CreateSegmentLogic.php index c37c876e..32eeb217 100644 --- a/app/Classes/Modules/Segments/ControllersLogic/CreateSegmentLogic.php +++ b/app/Classes/Modules/Segments/ControllersLogic/CreateSegmentLogic.php @@ -2,7 +2,7 @@ namespace App\Classes\Modules\Segments\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Segments\Standards\Rules\CanCreateSegment; use App\Classes\Modules\Segments\Services\CreatesSegment; @@ -14,8 +14,9 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class CreateSegmentLogic extends AbstractControllersLogic +class CreateSegmentLogic extends AbstractControllerLogic { + /** * @return array */ @@ -32,15 +33,13 @@ class CreateSegmentLogic extends AbstractControllersLogic /** @var CreatesSegment */ private $createsSegment; + /** * CreateSegmentLogic constructor. * @param CanCreateSegment $canCreateSegment * @param CreatesSegment $createsSegment */ - public function __construct( - CanCreateSegment $canCreateSegment, - CreatesSegment $createsSegment - ) + public function __construct(CanCreateSegment $canCreateSegment, CreatesSegment $createsSegment) { $this->canCreateSegment = $canCreateSegment; $this->createsSegment = $createsSegment; @@ -49,27 +48,18 @@ class CreateSegmentLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { - DB::beginTransaction(); + $segment_object = new SegmentObject($request->input('name')); - $segment_object = new SegmentObject( - $request->input('name') - ); + $this->canCreateSegment->passes($segment_object); + $segment = $this->createsSegment->execute($segment_object); - $this->canCreateSegment->passes($segment_object); - $segment_query = $this->createsSegment->execute($segment_object); - - DB::commit(); - - return $this->resourceResponse(new SegmentResource($segment_query)); - - } catch (\Exception $exception) { - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->resourceResponse(new SegmentResource($segment)); } } \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/DeleteSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/DeleteSegmentLogic.php index 4e6f9775..ac441bb0 100644 --- a/app/Classes/Modules/Segments/ControllersLogic/DeleteSegmentLogic.php +++ b/app/Classes/Modules/Segments/ControllersLogic/DeleteSegmentLogic.php @@ -4,19 +4,17 @@ namespace App\Classes\Modules\Segments\ControllersLogic; use App\Http\Resources\SegmentResource; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Segments\Services\FetchesSegment; use App\Classes\Modules\Segments\Standards\Rules\CanDeleteSegment; use App\Classes\Modules\Segments\Services\DeletesSegment; -use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; -class DeleteSegmentLogic extends AbstractControllersLogic +class DeleteSegmentLogic extends AbstractControllerLogic { /** @@ -59,25 +57,18 @@ class DeleteSegmentLogic extends AbstractControllersLogic /** * @param Request $request * @return JsonResponse - * @throws ErrorException + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { - try { - DB::beginTransaction(); - $segment_query = $this->fetchesSegment->execute(['id' => $request->route('id')]); - $this->canDeleteSegment->passes(); - $this->deletesSegment->execute($segment_query); - - DB::commit(); + $segment_query = $this->fetchesSegment->execute(['id' => $request->route('id')]); + $this->canDeleteSegment->passes(); + $this->deletesSegment->execute($segment_query); - return $this->resourceResponse(new SegmentResource($segment_query)); - - } catch (\Exception $exception){ - dd($exception); - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } + return $this->resourceResponse(new SegmentResource($segment_query)); } } \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/FetchConstantLogic.php b/app/Classes/Modules/Segments/ControllersLogic/FetchConstantLogic.php new file mode 100644 index 00000000..6c5c5b0f --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/FetchConstantLogic.php @@ -0,0 +1,52 @@ + '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)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/FetchSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/FetchSegmentLogic.php new file mode 100644 index 00000000..d5c35fdc --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/FetchSegmentLogic.php @@ -0,0 +1,59 @@ + '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)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/ListSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/ListSegmentLogic.php new file mode 100644 index 00000000..d8299424 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/ListSegmentLogic.php @@ -0,0 +1,52 @@ + '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)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/ListStandardSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/ListStandardSegmentLogic.php deleted file mode 100644 index 4eb1fdec..00000000 --- a/app/Classes/Modules/Segments/ControllersLogic/ListStandardSegmentLogic.php +++ /dev/null @@ -1,65 +0,0 @@ - 'Retrieved Segment', - 'message' => 'You have successfully retrieved a list of Segment' - ]; - } - - /** @var CanListStandardSegments */ - private $canListStandardSegments; - - /** @var ListsSegments */ - private $listsSegments; - - /** - * ListStandardSegmentLogic constructor. - * @param CanListStandardSegments $canListStandardSegments - * @param ListsSegments $listsSegments - */ - public function __construct(CanListStandardSegments $canListStandardSegments, ListsSegments $listsSegments) - { - $this->canListStandardSegments = $canListStandardSegments; - $this->listsSegments = $listsSegments; - } - - - /** - * @param Request $request - * @return JsonResponse - * @throws ErrorException - */ - public function logic(Request $request) : JsonResponse - { - try { - $this->canListStandardSegments->passes(); - - $query = $this->listsSegments->execute(['id' => 1]); - - return $this->collectionResponse(SegmentResource::collection($query)); - - } catch (\Exception $exception){ - throw new ErrorException($exception->getMessage(), $exception->getCode()); - } - - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php b/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php new file mode 100644 index 00000000..dac04ec7 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php @@ -0,0 +1,104 @@ + '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)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php index 39ebbb30..43eaa54e 100644 --- a/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php +++ b/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php @@ -4,7 +4,7 @@ namespace App\Classes\Modules\Segments\ControllersLogic; use App\Http\Resources\SegmentResource; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Segments\Services\FetchesSegment; @@ -17,7 +17,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class UpdateSegmentLogic extends AbstractControllersLogic +class UpdateSegmentLogic extends AbstractControllerLogic { /** diff --git a/app/Classes/Modules/Segments/DataTransferObjects/ConstantObject.php b/app/Classes/Modules/Segments/DataTransferObjects/ConstantObject.php new file mode 100644 index 00000000..d5373a68 --- /dev/null +++ b/app/Classes/Modules/Segments/DataTransferObjects/ConstantObject.php @@ -0,0 +1,57 @@ +name = $name; + $this->reference = $reference; + $this->detail = $detail; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return string + */ + public function getReference(): string + { + return $this->reference; + } + + /** + * @return array + */ + public function getDetail(): array + { + return $this->detail; + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php b/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php index dc4de3ed..06045943 100644 --- a/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php +++ b/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php @@ -2,29 +2,47 @@ namespace App\Classes\Modules\Segments\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; +use App\Classes\ValueObjects\Constants\SegmentConstants; class SegmentObject implements DataTransferObject { - /** @var string|null */ + /** @var string */ private $name; + /** @var int|null */ + private $type; + /** * SegmentObject constructor. - * @param string|null $name + * @param string $name + * @param int|null $type */ - public function __construct( - ?string $name - ) + public function __construct(string $name, ?int $type = SegmentConstants::STANDARD_SEGMENT) { $this->name = $name; + $this->type = $type; } /** * @return string */ - public function getName(): ?string + public function getName(): string { return $this->name; } + + /** + * @return int + */ + public function getType(): int + { + return $this->type; + } + + + + + + } \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/ConvertsConstantDetailsToResource.php b/app/Classes/Modules/Segments/Services/ConvertsConstantDetailsToResource.php new file mode 100644 index 00000000..0e7ece81 --- /dev/null +++ b/app/Classes/Modules/Segments/Services/ConvertsConstantDetailsToResource.php @@ -0,0 +1,37 @@ +fetchesCurrency = $fetchesCurrency; + } + + + public function execute(ConstantResource $resource){ + + if($resource->reference === SegmentConstants::SUPPLIER_CURRENCIES) { + return property_exists($resource->detail, 'id') ? new CurrencyResource($this->fetchesCurrency->execute(['id' => $resource->detail->id])) : ''; + } + + return $resource->detail; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/CreatesConstant.php b/app/Classes/Modules/Segments/Services/CreatesConstant.php new file mode 100644 index 00000000..b2addae8 --- /dev/null +++ b/app/Classes/Modules/Segments/Services/CreatesConstant.php @@ -0,0 +1,27 @@ +name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode($object->getDetail()); + + return $this->handler($segment->constants(), $model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/CreatesSegment.php b/app/Classes/Modules/Segments/Services/CreatesSegment.php index f3dc2a1c..b18a8db5 100644 --- a/app/Classes/Modules/Segments/Services/CreatesSegment.php +++ b/app/Classes/Modules/Segments/Services/CreatesSegment.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Segments\Services; use App\Classes\General\Eloquent\AbstractUpdateRecord; use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject; +use App\Classes\ValueObjects\Constants\SegmentConstants; use App\Models\Segment; class CreatesSegment extends AbstractUpdateRecord @@ -16,6 +17,7 @@ class CreatesSegment extends AbstractUpdateRecord public function execute(SegmentObject $object) { $model = new Segment(); $model->name = $object->getName(); + $model->type = SegmentConstants::CUSTOM_SEGMENT; return $this->handler($model); diff --git a/app/Classes/Modules/Segments/Services/DeletesSegment.php b/app/Classes/Modules/Segments/Services/DeletesSegment.php index 88d44d60..9cc78c59 100644 --- a/app/Classes/Modules/Segments/Services/DeletesSegment.php +++ b/app/Classes/Modules/Segments/Services/DeletesSegment.php @@ -8,6 +8,11 @@ use App\Models\Segment; class DeletesSegment extends AbstractDeleteRecord { + /** + * @param Segment $model + * @return mixed + * @throws \App\Classes\Exceptions\MalformedRequestException + */ public function execute(Segment $model) { return $this->handler($model); } diff --git a/app/Classes/Modules/SegmentConstants/Services/FetchesSegmentConstant.php b/app/Classes/Modules/Segments/Services/FetchesConstant.php similarity index 76% rename from app/Classes/Modules/SegmentConstants/Services/FetchesSegmentConstant.php rename to app/Classes/Modules/Segments/Services/FetchesConstant.php index 003e20ba..bfa1b2cb 100644 --- a/app/Classes/Modules/SegmentConstants/Services/FetchesSegmentConstant.php +++ b/app/Classes/Modules/Segments/Services/FetchesConstant.php @@ -1,20 +1,20 @@ name = $object->getName(); $model->reference = $object->getReference(); diff --git a/app/Classes/Modules/Segments/Services/UpdatesSegment.php b/app/Classes/Modules/Segments/Services/UpdatesSegment.php index fed1fb2d..17f13efb 100644 --- a/app/Classes/Modules/Segments/Services/UpdatesSegment.php +++ b/app/Classes/Modules/Segments/Services/UpdatesSegment.php @@ -10,6 +10,7 @@ class UpdatesSegment extends AbstractUpdateRecord { /** + * @param Segment $model * @param SegmentObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanCreateConstant.php b/app/Classes/Modules/Segments/Standards/Rules/CanCreateConstant.php new file mode 100644 index 00000000..55f9c61a --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanCreateConstant.php @@ -0,0 +1,54 @@ +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; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanFetchSegment.php b/app/Classes/Modules/Segments/Standards/Rules/CanFetchSegment.php new file mode 100644 index 00000000..e6756305 --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanFetchSegment.php @@ -0,0 +1,43 @@ +can('view standard_segment')) { - return false; - } - return true; - } /** diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanUpdateConstant.php b/app/Classes/Modules/Segments/Standards/Rules/CanUpdateConstant.php new file mode 100644 index 00000000..650b249c --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanUpdateConstant.php @@ -0,0 +1,54 @@ +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; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php b/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php index 026ca4c6..58a8c0ca 100644 --- a/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php +++ b/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php @@ -38,7 +38,7 @@ class CanUpdateSegment extends AbstractRule } /** - * @param SegmentValidation $object + * @param SegmentObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -48,7 +48,7 @@ class CanUpdateSegment extends AbstractRule } /** - * @param SegmentValidation $object + * @param SegmentObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/SegmentConstants/Standards/Validators/SegmentConstantValidation.php b/app/Classes/Modules/Segments/Standards/Validators/ConstantValidation.php similarity index 55% rename from app/Classes/Modules/SegmentConstants/Standards/Validators/SegmentConstantValidation.php rename to app/Classes/Modules/Segments/Standards/Validators/ConstantValidation.php index 38035944..d5ac8819 100644 --- a/app/Classes/Modules/SegmentConstants/Standards/Validators/SegmentConstantValidation.php +++ b/app/Classes/Modules/Segments/Standards/Validators/ConstantValidation.php @@ -1,24 +1,22 @@ $object->getSegmentId(), 'name' => $object->getName(), 'reference' => $object->getReference(), - 'type' => $object->getType(), 'detail' => $object->getDetail() ]; @@ -28,12 +26,10 @@ class SegmentConstantValidation extends AbstractValidation /** * @return array */ - protected function rules(?string $type = 'POST'): array { + protected function rules(): array { return [ - 'segment_id' => $type == 'POST' ? 'required' : '', 'name' => 'required', 'reference' => 'required', - 'type' => 'required', 'detail' => 'required' ]; } diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/CreateServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/CreateServiceTypeLogic.php new file mode 100644 index 00000000..07672f85 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/CreateServiceTypeLogic.php @@ -0,0 +1,105 @@ + '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)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/DeleteServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/DeleteServiceTypeLogic.php new file mode 100644 index 00000000..c45c49d9 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/DeleteServiceTypeLogic.php @@ -0,0 +1,68 @@ + '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([]); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/FetchServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/FetchServiceTypeLogic.php new file mode 100644 index 00000000..f7835d34 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/FetchServiceTypeLogic.php @@ -0,0 +1,62 @@ + '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)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/ListServiceTypesLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/ListServiceTypesLogic.php new file mode 100644 index 00000000..10b390ae --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/ListServiceTypesLogic.php @@ -0,0 +1,62 @@ + '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)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateCustomServiceConstantLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateCustomServiceConstantLogic.php new file mode 100644 index 00000000..e08ef598 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateCustomServiceConstantLogic.php @@ -0,0 +1,110 @@ + '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)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeLogic.php new file mode 100644 index 00000000..51b88051 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeLogic.php @@ -0,0 +1,112 @@ + '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)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeStatusLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeStatusLogic.php new file mode 100644 index 00000000..f1d75665 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeStatusLogic.php @@ -0,0 +1,59 @@ + '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([]); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/CustomConfigurationsObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/CustomConfigurationsObject.php new file mode 100644 index 00000000..b14caa8c --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/CustomConfigurationsObject.php @@ -0,0 +1,75 @@ +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; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceConfigurationsObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceConfigurationsObject.php new file mode 100644 index 00000000..95b5fd52 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceConfigurationsObject.php @@ -0,0 +1,71 @@ +service = $service; + $this->configurations = $configurations; + $this->customOptions = $customOptions; + } + + /** + * @return ServiceType + */ + public function getService(): ServiceType + { + return $this->service; + } + + + + /** + * @return SegmentConstant + */ + public function getConfigurations(): SegmentConstant + { + return $this->configurations; + } + + /** + * @return Collection + */ + public function getCustomOptions(): Collection + { + return $this->customOptions->map(function($value){ + return new CustomConfigurationsObject($this->getConfigurations(), $value); + }); + } + + public function getBaseCurrencyRates(){ + return (App()->make(FetchesServiceCurrenciesConfigurations::class))->execute($this->configurations, SegmentConstants::SERVICE_TYPE); + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceCurrenciesObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceCurrenciesObject.php new file mode 100644 index 00000000..fa32e5dd --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceCurrenciesObject.php @@ -0,0 +1,90 @@ +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); + } + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceDetailObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceDetailObject.php new file mode 100644 index 00000000..233d1fb3 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceDetailObject.php @@ -0,0 +1,138 @@ +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); + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceTypeObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceTypeObject.php new file mode 100644 index 00000000..f65b7262 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceTypeObject.php @@ -0,0 +1,33 @@ +name = $name; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/CreatesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceType.php new file mode 100644 index 00000000..e9c05e94 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceType.php @@ -0,0 +1,19 @@ +name = $object->getName(); + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/CreatesServiceTypeConstantDetails.php b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceTypeConstantDetails.php new file mode 100644 index 00000000..aacf66f1 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceTypeConstantDetails.php @@ -0,0 +1,141 @@ +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; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/DeletesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/DeletesServiceType.php new file mode 100644 index 00000000..3cc4d69d --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/DeletesServiceType.php @@ -0,0 +1,15 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/FetchesServiceConfigurations.php b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceConfigurations.php new file mode 100644 index 00000000..b4230257 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceConfigurations.php @@ -0,0 +1,60 @@ +fetchesConstant = $fetchesConstant; + $this->fetchesServiceCurrenciesConfigurations = $fetchesServiceCurrenciesConfigurations; + } + + + 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' => $constant->detail->bank_id ?? '', + '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, '.', ''); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/FetchesServiceCurrenciesConfigurations.php b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceCurrenciesConfigurations.php new file mode 100644 index 00000000..7d00225a --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceCurrenciesConfigurations.php @@ -0,0 +1,69 @@ +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 + ] + ]; + }); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/FetchesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceType.php new file mode 100644 index 00000000..7b5899fa --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceType.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/ListsServiceTypes.php b/app/Classes/Modules/ServiceTypes/Services/ListsServiceTypes.php new file mode 100644 index 00000000..344d6c4d --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/ListsServiceTypes.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceCurrencyRates.php b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceCurrencyRates.php new file mode 100644 index 00000000..019d30b4 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceCurrencyRates.php @@ -0,0 +1,55 @@ +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); + } + + } + + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceType.php new file mode 100644 index 00000000..06bd1e4f --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceType.php @@ -0,0 +1,19 @@ +name = $object->getName(); + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceTypeStatus.php b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceTypeStatus.php new file mode 100644 index 00000000..065b218e --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceTypeStatus.php @@ -0,0 +1,19 @@ +status = $status; + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Standards/Rules/CanCreateServiceType.php b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanCreateServiceType.php new file mode 100644 index 00000000..0fb57c32 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanCreateServiceType.php @@ -0,0 +1,57 @@ +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; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Standards/Rules/CanDeleteServiceType.php b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanDeleteServiceType.php new file mode 100644 index 00000000..1a832257 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanDeleteServiceType.php @@ -0,0 +1,43 @@ +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; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Standards/Validators/ServiceTypeValidation.php b/app/Classes/Modules/ServiceTypes/Standards/Validators/ServiceTypeValidation.php new file mode 100644 index 00000000..86946a39 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Standards/Validators/ServiceTypeValidation.php @@ -0,0 +1,39 @@ + $object->getName() + ]; + } + + /** + * @return array + */ + protected function rules(): array { + return [ + 'name' => 'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array { + return []; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateMakePaymentPOTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateMakePaymentPOTransactionLogic.php index 7f9de898..48616385 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateMakePaymentPOTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateMakePaymentPOTransactionLogic.php @@ -2,15 +2,15 @@ namespace App\Classes\Modules\Transactions\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllerLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Transactions\Standards\Rules\CanCreateTransaction; use App\Classes\Modules\Transactions\Standards\Rules\CanCreateTransactionDetail; use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject; use App\Classes\Modules\Transactions\Services\CreatesTransaction; use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail; -use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNo; +use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; use App\Http\Resources\TransactionResource; use App\Http\Resources\TransactionDetailResource; @@ -21,8 +21,6 @@ use App\Classes\Modules\Receipts\DataTransferObjects\ReceiptDetailObject; use App\Classes\Modules\Receipts\Services\CreatesReceipt; use App\Classes\Modules\Receipts\Services\CreatesReceiptDetail; use App\Classes\Modules\Receipts\Services\GeneratesReceiptBillNo; -use App\Http\Resources\ReceiptResource; -use App\Http\Resources\ReceiptDetailResource; use App\Classes\Modules\Currencies\Services\FetchesCurrency; use App\Classes\Modules\Currencies\Services\RateCalculatesCurrency; @@ -37,8 +35,6 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -use App\Models\TransactionDetail; - class CreateMakePaymentPOTransactionLogic extends AbstractControllerLogic { @@ -54,7 +50,7 @@ class CreateMakePaymentPOTransactionLogic extends AbstractControllerLogic } - /** @var GeneratesTransactionBillNo */ + /** @var GeneratesTransactionBillNumber */ private $generatesTransactionBillNo; /** @var CanCreateTransaction */ @@ -89,7 +85,7 @@ class CreateMakePaymentPOTransactionLogic extends AbstractControllerLogic /** * CreateWalletLogic constructor. - * @param GeneratesTransactionBillNo $generatesTransactionBillNo + * @param GeneratesTransactionBillNumber $generatesTransactionBillNo * @param CanCreateTransaction $canCreateTransaction * @param FetchesCurrency $fetchesCurrency * @param RateCalculatesCurrency $rateCalculatesCurrency @@ -97,16 +93,23 @@ class CreateMakePaymentPOTransactionLogic extends AbstractControllerLogic * @param CreatesTransaction $createsTransaction * @param CanCreateTransactionDetail $canCreateTransactionDetail * @param CreatesTransactionDetail $createsTransactionDetail + * @param FetchesTransaction $fetchesTransaction + * @param FetchesTransactionDetail $fetchesTransactionDetail + * @param GeneratesReceiptBillNo $generatesReceiptBillNo + * @param CanCreateReceipt $canCreateReceipt + * @param CreatesReceipt $createsReceipt + * @param CanCreateReceiptDetail $canCreateReceiptDetail + * @param CreatesReceiptDetail $createsReceiptDetail */ public function __construct( - GeneratesTransactionBillNo $generatesTransactionBillNo, CanCreateTransaction $canCreateTransaction, - FetchesCurrency $fetchesCurrency,RateCalculatesCurrency $rateCalculatesCurrency, FetchesCompany $fetchesCompany, - CreatesTransaction $createsTransaction, - CanCreateTransactionDetail $canCreateTransactionDetail, CreatesTransactionDetail $createsTransactionDetail, - FetchesTransaction $fetchesTransaction , FetchesTransactionDetail $fetchesTransactionDetail, - GeneratesReceiptBillNo $generatesReceiptBillNo, CanCreateReceipt $canCreateReceipt, - CreatesReceipt $createsReceipt, - CanCreateReceiptDetail $canCreateReceiptDetail, CreatesReceiptDetail $createsReceiptDetail + GeneratesTransactionBillNumber $generatesTransactionBillNo, CanCreateTransaction $canCreateTransaction, + FetchesCurrency $fetchesCurrency, RateCalculatesCurrency $rateCalculatesCurrency, FetchesCompany $fetchesCompany, + CreatesTransaction $createsTransaction, + CanCreateTransactionDetail $canCreateTransactionDetail, CreatesTransactionDetail $createsTransactionDetail, + FetchesTransaction $fetchesTransaction , FetchesTransactionDetail $fetchesTransactionDetail, + GeneratesReceiptBillNo $generatesReceiptBillNo, CanCreateReceipt $canCreateReceipt, + CreatesReceipt $createsReceipt, + CanCreateReceiptDetail $canCreateReceiptDetail, CreatesReceiptDetail $createsReceiptDetail ){ $this->generatesTransactionBillNo = $generatesTransactionBillNo; $this->canCreateTransaction = $canCreateTransaction; @@ -137,7 +140,6 @@ class CreateMakePaymentPOTransactionLogic extends AbstractControllerLogic try { DB::beginTransaction(); - DB::enableQueryLog(); $json_array = json_decode($request->getContent(), true); $po_transaction = $this->fetchesTransaction->execute(['id' => $json_array['ref_po']]); @@ -190,14 +192,13 @@ class CreateMakePaymentPOTransactionLogic extends AbstractControllerLogic $transaction->amount, $transaction->amount ); $this->canCreateReceiptDetail->passes($object_detail); - $transaction_detail = $this->createsReceiptDetail->execute($object_detail); + $this->createsReceiptDetail->execute($object_detail); DB::commit(); return $this->resourceResponse($transaction_array); - return $this->resourceResponse($json_array); } catch (\Exception $exception) { throw new ErrorException($exception->getMessage(), $exception->getCode()); diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php new file mode 100644 index 00000000..da5c23b6 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php @@ -0,0 +1,83 @@ + 'Payment Proof Document', + 'message' => 'You have successfully submitted your payment proof document' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFile; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** + * CreatePaymentVerificationDocumentLogic constructor. + * @param FetchesTransaction $fetchesTransaction + * @param CreatesDocument $createsDocument + * @param CreatesFiles $createsFile + * @param UpdatesTransactionStatus $updatesTransactionStatus + */ + public function __construct(FetchesTransaction $fetchesTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesTransactionStatus $updatesTransactionStatus) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + $this->updatesTransactionStatus = $updatesTransactionStatus; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + + $object = new DocumentObject(DocumentType::CUSTOMER_PAYMENT_PROOF, $request->input('files'), '', ApprovalStatus::APPROVED, 'china_bank_slip'); + + /** @var Document $document */ + $document = $this->createsDocument->execute($transaction, $object); + + $this->createsFile->execute($document, $object); + + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::COMPLETED); + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php new file mode 100644 index 00000000..2ff128e3 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php @@ -0,0 +1,126 @@ +fetchesBooking = $fetchesBooking; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->createsTransaction = $createsTransaction; + $this->createsTransactionDetail = $createsTransactionDetail; + $this->updatesTransaction = $updatesTransaction; + $this->deletesTransactionDetails = $deletesTransactionDetails; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Update Purchase Order', + 'message' => 'You have successfully updated you booking\'s purchase order' + ]; + } + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var CreatesTransactionDetail */ + private $createsTransactionDetail; + + /** @var UpdatesTransaction */ + private $updatesTransaction; + + /** @var DeletesTransactionDetails */ + private $deletesTransactionDetails; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + /** @var Booking $booking */ + $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); + + /** @var Transaction $transaction */ + $transaction = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); + + $billNumber = $this->generatesTransactionBillNumber->execute('PO-'); + + $total = collect($request->input('products'))->sum(function($product){ + return $product['quantity'] * floatval(str_replace(',', '', $product['unit_price'])); + }); + + $object = new TransactionObject($billNumber, TransactionType::PURCHASE_ORDER, $booking->company->id, 1, + 1, PaymentMethodType::CASH, + $total, $total, $booking->fix_currency_id, $booking->fix_currency_id, + 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, $request->input('products')); + + !$transaction ? $transaction = $this->createsTransaction->execute($booking, $object) : $transaction = $this->updatesTransaction->execute($transaction, $object); + + $this->updatesTransactionStatus->execute($transaction, $total === $booking->fix_amount ? ApprovalStatus::PENDING_VERIFICATION : ApprovalStatus::PENDING_SUBMISSION); + + $this->deletesTransactionDetails->execute($transaction); + + foreach ($object->getDetails() as $product){ + $this->createsTransactionDetail->execute($transaction, $product); + } + + return $this->resourceResponse(new TransactionResource($transaction)); + + } + + + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php new file mode 100644 index 00000000..e14b0a67 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -0,0 +1,112 @@ + 'Create Supplier Transactions', + 'message' => 'You have successfully created currency supplier transactions' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var PDF */ + private $pdf; + + /** + * CreateSupplierTransactionLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param FetchesTransaction $fetchesTransaction + * @param UpdatesTransactionStatus $updatesTransactionStatus + * @param CreatesTransaction $createsTransaction + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param PDF $pdf + */ + public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, GeneratesTransactionBillNumber $generatesTransactionBillNumber, PDF $pdf) + { + + $this->fetchesCompany = $fetchesCompany; + $this->fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->createsTransaction = $createsTransaction; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->pdf = $pdf; + } + + public function logic(Request $request) : JsonResponse + { + + $supplier = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $rate = $request->input('rate'); + + $transactions = collect(); + + foreach($request->input('payments') as $payment){ + + /** @var Transaction $payment */ + $payment = $this->fetchesTransaction->execute(['id' => $payment['id']]); + $this->updatesTransactionStatus->execute($payment, ApprovalStatus::COMPLETED); + $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-'); + $object = new TransactionObject($billNumber, TransactionType::BILL, $supplier->id, 1, + $supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH, + $payment->amount * (1 / $rate), $payment->original_amount, 1, $payment->original_currency_id, + $rate, 0, 0, null, ApprovalStatus::APPROVED); + + $transactions[] = $this->createsTransaction->execute($payment->booking, $object); + + } + + $pdf = $this->pdf->loadView('pages.pdfs.supplier_order', ['transactions' => $transactions, 'supplier' => $supplier]); + + $path = Str::studly($supplier->name).'_'.Carbon::now()->format('Y_m_d_h_s_i').'.pdf'; + + Storage::disk('documents')->put('supplier_orders/'.$path, $pdf->output()); + + return $this->response([]); + + } + + + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php index 5bd0e4c5..02b69481 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php @@ -2,7 +2,7 @@ namespace App\Classes\Modules\Transactions\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Transactions\Standards\Rules\CanCreateTransaction; use App\Classes\Modules\Transactions\Standards\Rules\CanCreateTransactionDetail; @@ -10,7 +10,7 @@ use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject; use App\Classes\Modules\Transactions\Services\CreatesTransaction; use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail; -use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNo; +use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; use App\Http\Resources\TransactionResource; use App\Http\Resources\TransactionDetailResource; @@ -24,7 +24,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class CreateTransactionLogic extends AbstractControllersLogic +class CreateTransactionLogic extends AbstractControllerLogic { @@ -39,7 +39,7 @@ class CreateTransactionLogic extends AbstractControllersLogic } - /** @var GeneratesTransactionBillNo */ + /** @var GeneratesTransactionBillNumber */ private $generatesTransactionBillNo; /** @var CanCreateTransaction */ @@ -59,7 +59,7 @@ class CreateTransactionLogic extends AbstractControllersLogic /** * CreateWalletLogic constructor. - * @param GeneratesTransactionBillNo $generatesTransactionBillNo + * @param GeneratesTransactionBillNumber $generatesTransactionBillNo * @param CanCreateTransaction $canCreateTransaction * @param FetchesCurrency $fetchesCurrency * @param RateCalculatesCurrency $rateCalculatesCurrency @@ -69,10 +69,10 @@ class CreateTransactionLogic extends AbstractControllersLogic * @param CreatesTransactionDetail $createsTransactionDetail */ public function __construct( - GeneratesTransactionBillNo $generatesTransactionBillNo, CanCreateTransaction $canCreateTransaction, - FetchesCurrency $fetchesCurrency,RateCalculatesCurrency $rateCalculatesCurrency, FetchesCompany $fetchesCompany, - CreatesTransaction $createsTransaction, - CanCreateTransactionDetail $canCreateTransactionDetail, CreatesTransactionDetail $createsTransactionDetail + GeneratesTransactionBillNumber $generatesTransactionBillNo, CanCreateTransaction $canCreateTransaction, + FetchesCurrency $fetchesCurrency, RateCalculatesCurrency $rateCalculatesCurrency, FetchesCompany $fetchesCompany, + CreatesTransaction $createsTransaction, + CanCreateTransactionDetail $canCreateTransactionDetail, CreatesTransactionDetail $createsTransactionDetail ){ $this->generatesTransactionBillNo = $generatesTransactionBillNo; $this->canCreateTransaction = $canCreateTransaction; diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ListTransactionsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ListTransactionsLogic.php new file mode 100644 index 00000000..15cb9bfc --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/ListTransactionsLogic.php @@ -0,0 +1,50 @@ +listsTransactions = $listsTransactions; + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Retrieved Transactions', + 'message' => 'You have successfully retrieved a list of transactions' + ]; + } + + /** @var ListsTransactions */ + private $listsTransactions; + + + + public function logic(Request $request) : JsonResponse + { + + $query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(TransactionResource::collection($query)); + + } + + + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/SuspendTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/SuspendTransactionLogic.php new file mode 100644 index 00000000..07050078 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/SuspendTransactionLogic.php @@ -0,0 +1,61 @@ + 'Suspend Transaction', + 'message' => 'You have successfully suspended the payment attempt' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + + /** + * SuspendTransactionLogic constructor. + * @param FetchesTransaction $fetchesTransaction + * @param UpdatesTransactionStatus $updatesTransactionStatus + */ + public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + } + + + public function logic(Request $request) : JsonResponse + { + + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::SUSPENDED); + + return $this->response([]); + + } + + + +} diff --git a/app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php index 81fe6d23..a2e0d7be 100644 --- a/app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php +++ b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php @@ -2,112 +2,72 @@ namespace App\Classes\Modules\Transactions\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; class TransactionDetailObject implements DataTransferObject { + /** @var string */ + private $code; - /* - * - * $table->string('trans_type1'); - $table->string('trans_type2'); - $table->bigInteger('transaction_id')->unsigned(); - $table->string('product_code'); - $table->string('product_name'); - $table->integer('qty')->default(0); - $table->decimal('price', 14, 5)->default(0.00); - $table->decimal('amount', 14, 5)->default(0.00); - */ - private $trans_type1; - - private $trans_type2; - - private $transaction_id; - - private $product_code; - - private $product_name; - - private $qty; - + /** @var string */ + private $name; + + /** @var int */ + private $quantity; + + /** @var float */ private $price; - - private $amount; - - - public function __construct( - string $trans_type1,string $trans_type2, - int $transaction_id, string $product_code, $product_name, - int $qty, float $price,float $amount - ){ - $this->trans_type1= $trans_type1; - $this->trans_type2 = $trans_type2; - $this->transaction_id = $transaction_id; - $this->product_code = $product_code; - $this->product_name = $product_name; - $this->qty = $qty; + + /** + * TransactionDetailObject constructor. + * @param string $code + * @param string $name + * @param int $quantity + * @param float $price + */ + public function __construct(string $code, string $name, int $quantity, float $price) + { + $this->code = $code; + $this->name = $name; + $this->quantity = $quantity; $this->price = $price; - $this->amount = $amount; - } - /** * @return string */ - public function getTransType1(): string + public function getCode(): string { - return $this->trans_type1; + return $this->code; } - + /** * @return string */ - public function getTransType2(): string + public function getName(): string { - return $this->trans_type2; + return $this->name; } - + /** * @return int */ - public function getTransactionId(): int + public function getQuantity(): int { - return $this->transaction_id; + return $this->quantity; } - + /** - * @return string + * @return float */ - public function getProductCode(): string - { - return $this->product_code; - } - - /** - * @return string - */ - public function getProductName(): string - { - return $this->product_name; - } - - /** - * @return int - */ - public function getQty(): int - { - return $this->qty; - } - public function getPrice(): float { return $this->price; } - + public function getAmount(): float { - return $this->amount; + return $this->getQuantity() * $this->getPrice(); } } \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php index 22fc241a..204b7a6c 100644 --- a/app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php +++ b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php @@ -2,149 +2,231 @@ namespace App\Classes\Modules\Transactions\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use Carbon\Carbon; class TransactionObject implements DataTransferObject { - /* - * - * return [ - 'id' => $this->id, - 'trans_type1' => $this->trans_type1, - 'trans_type2' => $this->trans_type2, - 'bill_no' => (int) $this->bill_no, - 'amount' => (double) $this->amount, - 'currency_id' => (int) $this->currency_id, - 'original_amount' => (double) $this->original_amount, - 'original_currency_id' => (int) $this->original_currency_id, - 'currency_rate' => (double) $this->currency_rate, - 'dt_transaction' => $this->dt_transaction, - 'status' => (int) $this->status, - 'booking_id' => (int) $this->booking_id, - 'company_id' => (int) $this->company_id - ]; - */ - private $trans_type1; - - private $trans_type2; - - private $bill_no; - - private $amount; - - private $currency_id; - - private $original_amount; - - private $original_currency_id; + /** @var string */ + private $billNo; - private $currency_rate; - - private $dt_transaction; - + /** @var string */ + private $transactionType; + + /** @var int */ + private $issuer; + + /** @var int */ + private $receiver; + + /** @var int */ + private $recipientBankAccountId; + + /** @var int */ + private $paymentMethod; + + /** @var float */ + private $amount; + + /** @var float */ + private $originalAmount; + + /** @var int */ + private $currencyId; + + /** @var int */ + private $originalCurrencyId; + + /** @var float */ + private $currencyRate; + + /** @var float */ + private $tax; + + /** @var float */ + private $serviceCharge; + + /** @var Carbon|null */ + private $expiresOn; + + /** @var int|null */ private $status; - - private $booking_id; - - private $company_id; - - public function __construct( - int $bill_no,string $trans_type1,string $trans_type2, - float $amount, int $currency_id, int $original_amount, - int $original_currency_id, float $currency_rate, - string $dt_transaction,int $status,int $booking_id, - int $company_id - ){ - $this->bill_no = $bill_no; - $this->trans_type1= $trans_type1; - $this->trans_type2 = $trans_type2; - $this->amount= $amount; - $this->currency_id = $currency_id; - $this->original_amount = $original_amount; - $this->original_currency_id = $original_currency_id; - $this->currency_rate = $currency_rate; - $this->dt_transaction = $dt_transaction; + + /** @var array|null */ + private $details; + + /** + * TransactionObject constructor. + * @param string $billNo + * @param string $transactionType + * @param int $issuer + * @param int $receiver + * @param int $recipientBankAccountId + * @param int $paymentMethod + * @param float $amount + * @param float $originalAmount + * @param int $currencyId + * @param int $originalCurrencyId + * @param float $currencyRate + * @param float $tax + * @param float $serviceCharge + * @param Carbon|null $expiresOn + * @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 = []) + { + $this->billNo = $billNo; + $this->transactionType = $transactionType; + $this->issuer = $issuer; + $this->receiver = $receiver; + $this->recipientBankAccountId = $recipientBankAccountId; + $this->paymentMethod = $paymentMethod; + $this->amount = $amount; + $this->originalAmount = $originalAmount; + $this->currencyId = $currencyId; + $this->originalCurrencyId = $originalCurrencyId; + $this->currencyRate = $currencyRate; + $this->tax = $tax; + $this->serviceCharge = $serviceCharge; + $this->expiresOn = $expiresOn; $this->status = $status; - $this->booking_id = $booking_id; - $this->company_id = $company_id; + $this->details = $details; + } + + /** + * @return string + */ + public function getBillNo(): string + { + return $this->billNo; + } + + /** + * @return string + */ + public function getTransactionType(): string + { + return $this->transactionType; } - /** * @return int */ - public function getBillNo(): int + public function getIssuer(): int { - return $this->bill_no; + return $this->issuer; } - + /** - * @return string + * @return int */ - public function getTransType1(): string + public function getReceiver(): int { - return $this->trans_type1; + return $this->receiver; } - + /** - * @return string + * @return int */ - public function getTransType2(): string + public function getRecipientBankAccountId(): int { - return $this->trans_type2; + return $this->recipientBankAccountId; } - - + + /** + * @return int + */ + public function getPaymentMethod(): int + { + return $this->paymentMethod; + } + + /** + * @return float + */ public function getAmount(): float { return $this->amount; } /** - * @return int + * @return float */ - public function getCurrency(): int - { - return $this->currency_id; - } - - public function getOriginalAmount(): float { - return $this->original_amount; + return $this->originalAmount; } - - public function getOriginalCurrency(): int + + /** + * @return int + */ + public function getCurrencyId(): int { - return $this->original_currency_id; + return $this->currencyId; } - + + /** + * @return int + */ + public function getOriginalCurrencyId(): int + { + return $this->originalCurrencyId; + } + + /** + * @return float + */ public function getCurrencyRate(): float { - return $this->currency_rate; + return $this->currencyRate; } - + /** - * @return string + * @return float */ - public function getDtTransaction(): string + public function getTax(): float { - return $this->dt_transaction; + return $this->tax; } - + + /** + * @return float + */ + public function getServiceCharge(): float + { + return $this->serviceCharge; + } + + /** + * @return Carbon|null + */ + public function getExpiresOn(): ?Carbon + { + return $this->expiresOn; + } + + /** + * @return int + */ public function getStatus(): int { - return $this->original_currency_id; + return $this->status; } - - public function getBookingId(): int + + /** + * @return array + */ + public function getDetails(): array { - return $this->booking_id; - } - - public function getCompanyId(): int - { - return $this->company_id; + return array_map(function($product){ + return new TransactionDetailObject($product['stockCode'], $product['description'], $product['quantity'], floatval(str_replace(',', '', $product['unit_price']))); + }, $this->details); } + + + + } \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNoExists.php b/app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNumberExists.php similarity index 76% rename from app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNoExists.php rename to app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNumberExists.php index 0d933c7d..9b63985f 100644 --- a/app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNoExists.php +++ b/app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNumberExists.php @@ -5,7 +5,7 @@ namespace App\Classes\Modules\Transactions\Services; use App\Models\Transaction; -class ChecksIfTransactionBillNoExists +class ChecksIfTransactionBillNumberExists { private $repository; @@ -15,7 +15,7 @@ class ChecksIfTransactionBillNoExists $this->repository = $repository; } - public function execute(int $bill_no): bool { + public function execute(string $bill_no): bool { return $this->repository->where('bill_no', $bill_no)->exists(); } diff --git a/app/Classes/Modules/Transactions/Services/CreatesTransaction.php b/app/Classes/Modules/Transactions/Services/CreatesTransaction.php index e1bb92a7..ddebf0d5 100644 --- a/app/Classes/Modules/Transactions/Services/CreatesTransaction.php +++ b/app/Classes/Modules/Transactions/Services/CreatesTransaction.php @@ -3,33 +3,38 @@ 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\Transaction; -class CreatesTransaction extends AbstractUpdateRecord +class CreatesTransaction extends AbstractUpdateRelationshipRecord { /** - * @param WalletObject $object + * @param TransactionObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(TransactionObject $object) { + public function execute(Booking $booking, TransactionObject $object) { $model = new Transaction(); $model->bill_no = $object->getBillNo(); - $model->trans_type1 = $object->getTransType1(); - $model->trans_type2 = $object->getTransType2(); + $model->type = $object->getTransactionType(); + $model->issuer = $object->getIssuer(); + $model->receiver = $object->getReceiver(); + $model->recipient_bank_account_id = $object->getRecipientBankAccountId(); + $model->payment_method = $object->getPaymentMethod(); $model->amount = $object->getAmount(); - $model->currency_id = $object->getCurrency(); $model->original_amount = $object->getOriginalAmount(); - $model->original_currency_id = $object->getOriginalCurrency(); + $model->currency_id = $object->getCurrencyId(); + $model->original_currency_id = $object->getOriginalCurrencyId(); $model->currency_rate = $object->getCurrencyRate(); - $model->dt_transaction = $object->getDtTransaction(); + $model->tax = $object->getTax(); + $model->service_charge = $object->getServiceCharge(); + $model->expires_on = $object->getExpiresOn(); $model->status = $object->getStatus(); - $model->booking_id = $object->getBookingId(); - $model->company_id = $object->getCompanyId(); - - return $this->handler($model); + + return $this->handler($booking->transactions(), $model); } } \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php b/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php index c1e91c7f..0e852ddf 100644 --- a/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php +++ b/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php @@ -3,29 +3,28 @@ namespace App\Classes\Modules\Transactions\Services; use App\Classes\General\Eloquent\AbstractUpdateRecord; +use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord; use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject; +use App\Models\Transaction; use App\Models\TransactionDetail; -class CreatesTransactionDetail extends AbstractUpdateRecord +class CreatesTransactionDetail extends AbstractUpdateRelationshipRecord { /** - * @param WalletObject $object + * @param Transaction $transaction + * @param TransactionDetailObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(TransactionDetailObject $object) { + public function execute(Transaction $transaction, TransactionDetailObject $object) { $model = new TransactionDetail(); - $model->trans_type1 = $object->getTransType1(); - $model->trans_type2 = $object->getTransType2(); - $model->transaction_id = $object->getTransactionId(); - $model->product_code = $object->getProductCode(); - $model->product_name = $object->getProductName(); - $model->qty = $object->getQty(); + $model->product_code = $object->getCode(); + $model->product_name = $object->getName(); + $model->quantity = $object->getQuantity(); $model->price = $object->getPrice(); $model->amount = $object->getAmount(); - - return $this->handler($model); + return $this->handler($transaction->transactionDetails(), $model); } } \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/DeletesTransactionDetails.php b/app/Classes/Modules/Transactions/Services/DeletesTransactionDetails.php new file mode 100644 index 00000000..42b16d77 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/DeletesTransactionDetails.php @@ -0,0 +1,19 @@ +transactionDetails()->delete(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/FetchesTransactionDetail.php b/app/Classes/Modules/Transactions/Services/FetchesTransactionDetail.php index 8d77cc85..1f2f8c08 100644 --- a/app/Classes/Modules/Transactions/Services/FetchesTransactionDetail.php +++ b/app/Classes/Modules/Transactions/Services/FetchesTransactionDetail.php @@ -16,7 +16,7 @@ class FetchesTransactionDetail extends AbstractFetchRecord /** * FetchesTransaction constructor. - * @param Transaction $repository + * @param TransactionDetail $repository */ public function __construct(TransactionDetail $repository) { diff --git a/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNo.php b/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNo.php deleted file mode 100644 index fb7c6867..00000000 --- a/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNo.php +++ /dev/null @@ -1,27 +0,0 @@ -transationBillNoExists = $transationBillNoExists; - } - - - - public function execute(): int { - - $code = mt_rand(100000001, 999999999); - return !$this->transationBillNoExists->execute($code) ? $code : self::execute(); - - } - -} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNumber.php b/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNumber.php new file mode 100644 index 00000000..6e4e79dd --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNumber.php @@ -0,0 +1,37 @@ +checksIfTransactionBillNumberExists = $checksIfTransactionBillNumberExists; + } + + + /** + * @param string $prefix + * @return string + */ + public function execute(string $prefix): string { + $date = carbon::now(); + + $billNumber = $prefix.$date->format('Y').$date->format('m').$date->format('d').mt_rand(10000, 99999); + + return !$this->checksIfTransactionBillNumberExists->execute($billNumber) ? $billNumber : self::execute($prefix); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/ListsTransactions.php b/app/Classes/Modules/Transactions/Services/ListsTransactions.php new file mode 100644 index 00000000..8d77171f --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/ListsTransactions.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/Modules/Transactions/Services/UpdatesTransaction.php b/app/Classes/Modules/Transactions/Services/UpdatesTransaction.php new file mode 100644 index 00000000..aba7b07a --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/UpdatesTransaction.php @@ -0,0 +1,33 @@ +recipient_bank_account_id = $object->getRecipientBankAccountId(); + $transaction->payment_method = $object->getPaymentMethod(); + $transaction->amount = $object->getAmount(); + $transaction->original_amount = $object->getOriginalAmount(); + $transaction->currency_id = $object->getCurrencyId(); + $transaction->original_currency_id = $object->getOriginalCurrencyId(); + $transaction->currency_rate = $object->getCurrencyRate(); + $transaction->tax = $object->getTax(); + $transaction->service_charge = $object->getServiceCharge(); + + return $this->handler($transaction); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php b/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php new file mode 100644 index 00000000..769f2dc0 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php @@ -0,0 +1,22 @@ +status = $status; + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php index b81c4a09..39fdd05a 100644 --- a/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php +++ b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php @@ -4,12 +4,13 @@ namespace App\Classes\Modules\Transactions\Standards\Rules; use App\Classes\General\Abstracts\AbstractRule; +use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; use App\Classes\Modules\Transactions\Standards\Validators\TransactionValidation; class CanCreateTransaction extends AbstractRule { - /** @var WalletTransactionValidation */ + /** @var TransactionValidation */ private $transactionValidation; @@ -29,7 +30,7 @@ class CanCreateTransaction extends AbstractRule } /** - * @param CompanyWalletValidation $object + * @param TransactionObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -39,7 +40,7 @@ class CanCreateTransaction extends AbstractRule } /** - * @param SegmentCompanyValidation $object + * @param TransactionObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php index cc2f2f3c..2669ffbf 100644 --- a/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php +++ b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php @@ -4,12 +4,13 @@ namespace App\Classes\Modules\Transactions\Standards\Rules; use App\Classes\General\Abstracts\AbstractRule; +use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject; use App\Classes\Modules\Transactions\Standards\Validators\TransactionDetailValidation; class CanCreateTransactionDetail extends AbstractRule { - /** @var WalletTransactionValidation */ + /** @var TransactionDetailValidation */ private $transactionDetailValidation; @@ -29,7 +30,7 @@ class CanCreateTransactionDetail extends AbstractRule } /** - * @param CompanyWalletValidation $object + * @param TransactionDetailObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -39,7 +40,7 @@ class CanCreateTransactionDetail extends AbstractRule } /** - * @param SegmentCompanyValidation $object + * @param TransactionDetailObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php b/app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php index 15e23dcd..35357060 100644 --- a/app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php +++ b/app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php @@ -3,7 +3,6 @@ namespace App\Classes\Modules\Transactions\Standards\Validators; use App\Classes\General\Abstracts\AbstractValidation; -use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject; class TransactionDetailValidation extends AbstractValidation { diff --git a/app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php b/app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php index 3249f8a1..62443c3d 100644 --- a/app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php +++ b/app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php @@ -3,7 +3,6 @@ namespace App\Classes\Modules\Transactions\Standards\Validators; use App\Classes\General\Abstracts\AbstractValidation; -use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; class TransactionValidation extends AbstractValidation { diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php index 77ecdbc9..efcff6b3 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php @@ -2,11 +2,12 @@ namespace App\Classes\Modules\Wallets\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; use App\Classes\Modules\Wallets\Services\CreatesWallet; use App\Classes\Modules\Wallets\Services\GeneratesWalletCode; +use App\Classes\Modules\Wallets\Standards\Rules\CanCreateCompanyWallet; use App\Http\Resources\WalletResource; use ErrorException; @@ -14,7 +15,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class CreateWalletLogic extends AbstractControllersLogic +class CreateWalletLogic extends AbstractControllerLogic { diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php index 71713444..6fe72a52 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php @@ -2,7 +2,7 @@ namespace App\Classes\Modules\Wallets\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllersLogic; +use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Wallets\Standards\Rules\CanCreateWalletTransaction; use App\Classes\Modules\Wallets\DataTransferObjects\WalletTransactionObject; @@ -27,9 +27,9 @@ use App\Classes\Modules\Contacts\Standards\Rules\CanCreateContact; use App\Classes\Modules\Contacts\Services\CreatesContact; use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject; -use App\Classes\Modules\CompanyEmployees\Standards\Rules\CanCreateCompanyEmployee; -use App\Classes\Modules\CompanyEmployees\Services\CreatesCompanyEmployee; -use App\Classes\Modules\CompanyEmployees\DataTransferObjects\CompanyEmployeeObject; +use App\Classes\Modules\Companies\Standards\Rules\CanCreateCompanyEmployee; +use App\Classes\Modules\Companies\Services\CreatesCompanyEmployee; +use App\Classes\Modules\Companies\DataTransferObjects\CompanyEmployeeObject; use App\Classes\Modules\SegmentCompanies\Standards\Rules\CanCreateSegmentCompany; use App\Classes\Modules\SegmentCompanies\Services\CreatesSegmentCompany; @@ -40,7 +40,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class CreateWalletTransactionLogic extends AbstractControllersLogic +class CreateWalletTransactionLogic extends AbstractControllerLogic { diff --git a/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php b/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php index 29924744..6f4fcd83 100644 --- a/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php +++ b/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php @@ -2,7 +2,7 @@ namespace App\Classes\Modules\Wallets\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; class WalletObject implements DataTransferObject { diff --git a/app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php b/app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php index 7fdfecbd..234c8f57 100644 --- a/app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php +++ b/app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php @@ -2,7 +2,7 @@ namespace App\Classes\Modules\Wallets\DataTransferObjects; -use App\Classes\Interfaces\DataTransferObject; +use App\Classes\General\Interfaces\DataTransferObject; class WalletTransactionObject implements DataTransferObject { diff --git a/app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php b/app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php index 06877e6a..0b40879c 100644 --- a/app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php +++ b/app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php @@ -9,7 +9,7 @@ use App\Models\WalletTransaction; class CreatesWalletTransaction extends AbstractUpdateRecord { /** - * @param WalletObject $object + * @param WalletTransactionObject $object * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ diff --git a/app/Classes/Modules/Wallets/Services/FetchesWallet.php b/app/Classes/Modules/Wallets/Services/FetchesWallet.php index 1c7800ac..c3542bb7 100644 --- a/app/Classes/Modules/Wallets/Services/FetchesWallet.php +++ b/app/Classes/Modules/Wallets/Services/FetchesWallet.php @@ -10,7 +10,7 @@ use App\Models\Wallet; class FetchesWallet extends AbstractFetchRecord { - /** @var Currency */ + /** @var Wallet */ private $repository; diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanCreateCompanyWallet.php b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateCompanyWallet.php index e2569918..0f1dd065 100644 --- a/app/Classes/Modules/Wallets/Standards/Rules/CanCreateCompanyWallet.php +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateCompanyWallet.php @@ -4,7 +4,8 @@ namespace App\Classes\Modules\Wallets\Standards\Rules; use App\Classes\General\Abstracts\AbstractRule; -use App\Classes\Modules\SegmentCompanies\Standards\Validators\CompanyWalletValidation; +use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; +use App\Classes\Modules\Wallets\Standards\Validators\CompanyWalletValidation; class CanCreateCompanyWallet extends AbstractRule { @@ -32,7 +33,7 @@ class CanCreateCompanyWallet extends AbstractRule } /** - * @param CompanyWalletValidation $object + * @param WalletObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -43,7 +44,7 @@ class CanCreateCompanyWallet extends AbstractRule /** - * @param $object + * @param WalletObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php index 43f0118f..8beafb37 100644 --- a/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Wallets\Standards\Rules; use App\Classes\General\Abstracts\AbstractRule; +use App\Classes\Modules\Wallets\DataTransferObjects\WalletTransactionObject; use App\Classes\Modules\Wallets\Standards\Validators\WalletTransactionValidation; class CanCreateWalletTransaction extends AbstractRule @@ -29,7 +30,7 @@ class CanCreateWalletTransaction extends AbstractRule } /** - * @param CompanyWalletValidation $object + * @param WalletTransactionObject $object * @return bool * @throws \App\Classes\Exceptions\RequestValidationException */ @@ -39,7 +40,7 @@ class CanCreateWalletTransaction extends AbstractRule } /** - * @param SegmentCompanyValidation $object + * @param WalletTransactionObject $object * @return bool */ protected function criteria($object): bool diff --git a/app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php b/app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php index 925261ad..8944795c 100644 --- a/app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php +++ b/app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php @@ -3,8 +3,6 @@ namespace App\Classes\Modules\Wallets\Standards\Validators; use App\Classes\General\Abstracts\AbstractValidation; -use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; -use App\Classes\Modules\Wallets\DataTransferObjects\WalletTransactionObject; class WalletTransactionValidation extends AbstractValidation { diff --git a/app/Classes/Notifications/ResetPasswordEmail.php b/app/Classes/Notifications/ResetPasswordEmail.php new file mode 100644 index 00000000..f7a84ab8 --- /dev/null +++ b/app/Classes/Notifications/ResetPasswordEmail.php @@ -0,0 +1,38 @@ +user = $user; + $this->attempt = $attempt; + } + + public function toMail() + { + return (new MailMessage) + ->subject('Reset Password') + ->view('emails.account.reset_password', ['user' => $this->user, 'attempt' => $this->attempt]); + } + + +} \ No newline at end of file diff --git a/app/Classes/Notifications/UserVerificationEmail.php b/app/Classes/Notifications/UserVerificationEmail.php new file mode 100644 index 00000000..c718d5da --- /dev/null +++ b/app/Classes/Notifications/UserVerificationEmail.php @@ -0,0 +1,39 @@ +user = $user; + $this->attempt = $attempt; + } + + + public function toMail() + { + return (new MailMessage) + ->subject('Email Verification') + ->view('emails.accounts.user_verification', ['user' => $this->user, 'attempt' => $this->attempt]); + } + + +} diff --git a/app/Classes/ValueObjects/Constants/ApprovalStatus.php b/app/Classes/ValueObjects/Constants/ApprovalStatus.php index fcc5e568..2f6a7a4a 100644 --- a/app/Classes/ValueObjects/Constants/ApprovalStatus.php +++ b/app/Classes/ValueObjects/Constants/ApprovalStatus.php @@ -4,19 +4,18 @@ namespace App\Classes\ValueObjects\Constants; final class ApprovalStatus { - public const PENDING_VERIFICATION = 0; + public const PENDING_SUBMISSION = 0; - public const ACTIVE = 1; + public const PENDING_VERIFICATION = 1; - public const SUSPENDED = 2; + public const APPROVED = 2; - public const REJECTED = 3; + public const COMPLETED = 3; - public const STATUS = [ - 0 => 'Pending Verification', - 1 => 'Active', - 2 => 'Suspended', - 3 => 'Rejected' - ]; + public const REJECTED = 4; + + public const SUSPENDED = 5; + + public const EXPIRED = 6; } diff --git a/app/Classes/ValueObjects/Constants/CompanyBankType.php b/app/Classes/ValueObjects/Constants/BankAccountType.php similarity index 78% rename from app/Classes/ValueObjects/Constants/CompanyBankType.php rename to app/Classes/ValueObjects/Constants/BankAccountType.php index 34019c40..13a36fde 100644 --- a/app/Classes/ValueObjects/Constants/CompanyBankType.php +++ b/app/Classes/ValueObjects/Constants/BankAccountType.php @@ -2,7 +2,10 @@ namespace App\Classes\ValueObjects\Constants; -final class CompanyBankType { +final class BankAccountType { + public const PERSONAL = 1; + public const EXTERNAL = 2; + } diff --git a/app/Classes/ValueObjects/Constants/BusinessType.php b/app/Classes/ValueObjects/Constants/BusinessType.php index 4f9029c9..d24b975d 100644 --- a/app/Classes/ValueObjects/Constants/BusinessType.php +++ b/app/Classes/ValueObjects/Constants/BusinessType.php @@ -3,7 +3,11 @@ namespace App\Classes\ValueObjects\Constants; final class BusinessType { - public const IMPORTER = 1; - public const FREIGHT_FORARDER = 2; + + public const FREIGHT_FORWARDER = 1; + + public const IMPORTER = 2; + public const CURRENCY_VENDOR = 3; + } diff --git a/app/Classes/ValueObjects/Constants/CompanyType.php b/app/Classes/ValueObjects/Constants/CompanyType.php index e1a763bb..61918925 100644 --- a/app/Classes/ValueObjects/Constants/CompanyType.php +++ b/app/Classes/ValueObjects/Constants/CompanyType.php @@ -3,6 +3,9 @@ namespace App\Classes\ValueObjects\Constants; final class CompanyType { - public const PUBLIC_COMPANY = 1; - public const PERSONAL_COMPANY = 2; + + public const PERSONAL_BUSINESS = 0; + + public const COMPANY_BUSINESS = 1; + } diff --git a/app/Classes/ValueObjects/Constants/Countries.php b/app/Classes/ValueObjects/Constants/Countries.php new file mode 100644 index 00000000..5b2e8ca7 --- /dev/null +++ b/app/Classes/ValueObjects/Constants/Countries.php @@ -0,0 +1,11 @@ + 'gif', + 'image/png' => 'png', + 'image/jpeg' => 'jpeg', + 'application/pdf' => 'pdf', + ]; + +} \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/HttpStatus.php b/app/Classes/ValueObjects/Constants/HttpStatus.php index 9a95658a..d2f831f3 100644 --- a/app/Classes/ValueObjects/Constants/HttpStatus.php +++ b/app/Classes/ValueObjects/Constants/HttpStatus.php @@ -3,6 +3,7 @@ namespace App\Classes\ValueObjects\Constants; final class HttpStatus { + public const OK_WITH_MESSAGE = 200; public const RESOURCE_CREATED = 201; @@ -26,4 +27,5 @@ final class HttpStatus { public const VALIDATION_FAILED = 422; public const SERVER_ERROR = 500; + } diff --git a/app/Classes/ValueObjects/Constants/Notifications.php b/app/Classes/ValueObjects/Constants/Notifications.php new file mode 100644 index 00000000..5ffc79de --- /dev/null +++ b/app/Classes/ValueObjects/Constants/Notifications.php @@ -0,0 +1,14 @@ + 'Unknown Action', + 'message' => 'unknown message..' + ]; + +} \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/ObjectStatus.php b/app/Classes/ValueObjects/Constants/ObjectStatus.php deleted file mode 100644 index 18dcaa58..00000000 --- a/app/Classes/ValueObjects/Constants/ObjectStatus.php +++ /dev/null @@ -1,8 +0,0 @@ - self::CASH, + 'cheque' => self::CHEQUE, + 'ba' => self::BA, + 'wallet' => self::WALLET, + 'payment gateway' => self::PAYMENT_GATEWAY, + ]; + + public const PAYMENT_METHODS_ID = [ + self::CASH => 'cash', + self::CHEQUE => 'cheque', + self::BA => 'ba', + self::WALLET => 'wallet', + self::PAYMENT_GATEWAY => 'payment gateway' + ]; + } diff --git a/app/Classes/ValueObjects/Constants/RoleTypes.php b/app/Classes/ValueObjects/Constants/RoleTypes.php new file mode 100644 index 00000000..3027bcb1 --- /dev/null +++ b/app/Classes/ValueObjects/Constants/RoleTypes.php @@ -0,0 +1,19 @@ + 'User', - 1 => 'Admin', - 2 => 'Super Admin', - ]; - -} \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/SegmentConstants.php b/app/Classes/ValueObjects/Constants/SegmentConstants.php new file mode 100644 index 00000000..80e9cb71 --- /dev/null +++ b/app/Classes/ValueObjects/Constants/SegmentConstants.php @@ -0,0 +1,23 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Accounts/FetchUserController.php b/app/Http/Controllers/Accounts/FetchUserController.php new file mode 100644 index 00000000..acc62672 --- /dev/null +++ b/app/Http/Controllers/Accounts/FetchUserController.php @@ -0,0 +1,22 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Accounts/ListUsersController.php b/app/Http/Controllers/Accounts/ListUsersController.php index c63d898a..4cf01a43 100644 --- a/app/Http/Controllers/Accounts/ListUsersController.php +++ b/app/Http/Controllers/Accounts/ListUsersController.php @@ -4,25 +4,17 @@ namespace App\Http\Controllers\Accounts; use App\Classes\Modules\Accounts\ControllersLogic\ListUsersLogic; -use App\Classes\Modules\Accounts\Services\ListsUsers; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; class ListUsersController { - /** @var ListsUsers */ - private $listsUsers; /** - * ListUsersController constructor. - * @param ListsUsers $listsUsers + * @param Request $request + * @param ListUsersLogic $logic + * @return JsonResponse */ - public function __construct(ListsUsers $listsUsers) - { - $this->listsUsers = $listsUsers; - } - - public function list(Request $request, ListUsersLogic $logic): JsonResponse { return $logic->execute($request); } diff --git a/app/Http/Controllers/Accounts/RefreshAuthenticationTokenController.php b/app/Http/Controllers/Accounts/RefreshAuthenticationTokenController.php new file mode 100644 index 00000000..ca783070 --- /dev/null +++ b/app/Http/Controllers/Accounts/RefreshAuthenticationTokenController.php @@ -0,0 +1,21 @@ +execute($request); + } + +} diff --git a/app/Http/Controllers/Accounts/RegistrationStep2Controller.php b/app/Http/Controllers/Accounts/RegistrationStep2Controller.php deleted file mode 100644 index 2b2aa9ec..00000000 --- a/app/Http/Controllers/Accounts/RegistrationStep2Controller.php +++ /dev/null @@ -1,19 +0,0 @@ -execute($request); - } -} \ No newline at end of file diff --git a/app/Http/Controllers/Accounts/ResendEmailVerificationController.php b/app/Http/Controllers/Accounts/ResendEmailVerificationController.php new file mode 100644 index 00000000..224e794d --- /dev/null +++ b/app/Http/Controllers/Accounts/ResendEmailVerificationController.php @@ -0,0 +1,20 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Accounts/CreateUserController.php b/app/Http/Controllers/Accounts/UserAuthenticationLogoutController.php similarity index 55% rename from app/Http/Controllers/Accounts/CreateUserController.php rename to app/Http/Controllers/Accounts/UserAuthenticationLogoutController.php index e68becc5..9d574a21 100644 --- a/app/Http/Controllers/Accounts/CreateUserController.php +++ b/app/Http/Controllers/Accounts/UserAuthenticationLogoutController.php @@ -2,18 +2,20 @@ namespace App\Http\Controllers\Accounts; -use App\Classes\Modules\Accounts\ControllersLogic\CreateUserLogic; +use App\Classes\Modules\Accounts\ControllersLogic\LogoutUserLogic; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class CreateUserController +class UserAuthenticationLogoutController { + /** * @param Request $request - * @param CreateUserLogic $logic + * @param LogoutUserLogic $logic * @return JsonResponse */ - public function create(Request $request, CreateUserLogic $logic): JsonResponse { + public function logout(Request $request, LogoutUserLogic $logic): JsonResponse { return $logic->execute($request); } -} \ No newline at end of file + +} diff --git a/app/Http/Controllers/Accounts/UserEmailVerificationController.php b/app/Http/Controllers/Accounts/UserEmailVerificationController.php new file mode 100644 index 00000000..aee42b67 --- /dev/null +++ b/app/Http/Controllers/Accounts/UserEmailVerificationController.php @@ -0,0 +1,20 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Addresses/ListDistrictsController.php b/app/Http/Controllers/Addresses/ListDistrictsController.php new file mode 100644 index 00000000..26780cca --- /dev/null +++ b/app/Http/Controllers/Addresses/ListDistrictsController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Banks/CreateBankController.php b/app/Http/Controllers/Banks/CreateBankController.php new file mode 100644 index 00000000..79046096 --- /dev/null +++ b/app/Http/Controllers/Banks/CreateBankController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Banks/DeleteBankController.php b/app/Http/Controllers/Banks/DeleteBankController.php new file mode 100644 index 00000000..626842fc --- /dev/null +++ b/app/Http/Controllers/Banks/DeleteBankController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Banks/ListBanksController.php b/app/Http/Controllers/Banks/ListBanksController.php new file mode 100644 index 00000000..b8708529 --- /dev/null +++ b/app/Http/Controllers/Banks/ListBanksController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Banks/SetBankToDefaultController.php b/app/Http/Controllers/Banks/SetBankToDefaultController.php new file mode 100644 index 00000000..6d8688b0 --- /dev/null +++ b/app/Http/Controllers/Banks/SetBankToDefaultController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Banks/UpdateBankController.php b/app/Http/Controllers/Banks/UpdateBankController.php new file mode 100644 index 00000000..ddfb2ead --- /dev/null +++ b/app/Http/Controllers/Banks/UpdateBankController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/ApprovePaymentController.php b/app/Http/Controllers/Bookings/ApprovePaymentController.php new file mode 100644 index 00000000..0c104594 --- /dev/null +++ b/app/Http/Controllers/Bookings/ApprovePaymentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/ApprovePaymentVerificationController.php b/app/Http/Controllers/Bookings/ApprovePaymentVerificationController.php new file mode 100644 index 00000000..4c336bc2 --- /dev/null +++ b/app/Http/Controllers/Bookings/ApprovePaymentVerificationController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/ApprovePurchaseOrderController.php b/app/Http/Controllers/Bookings/ApprovePurchaseOrderController.php new file mode 100644 index 00000000..f72d56f4 --- /dev/null +++ b/app/Http/Controllers/Bookings/ApprovePurchaseOrderController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/CreateBookingPaymentController.php b/app/Http/Controllers/Bookings/CreateBookingPaymentController.php new file mode 100644 index 00000000..e47932a6 --- /dev/null +++ b/app/Http/Controllers/Bookings/CreateBookingPaymentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/CreatePaymentVerificationController.php b/app/Http/Controllers/Bookings/CreatePaymentVerificationController.php new file mode 100644 index 00000000..3c813bdd --- /dev/null +++ b/app/Http/Controllers/Bookings/CreatePaymentVerificationController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/FetchBookingController.php b/app/Http/Controllers/Bookings/FetchBookingController.php new file mode 100644 index 00000000..06b7433d --- /dev/null +++ b/app/Http/Controllers/Bookings/FetchBookingController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/FetchBookingPaymentQuotationController.php b/app/Http/Controllers/Bookings/FetchBookingPaymentQuotationController.php new file mode 100644 index 00000000..f96cb5a3 --- /dev/null +++ b/app/Http/Controllers/Bookings/FetchBookingPaymentQuotationController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/ListBookingsController.php b/app/Http/Controllers/Bookings/ListBookingsController.php index 8096b029..42d5fb6d 100644 --- a/app/Http/Controllers/Bookings/ListBookingsController.php +++ b/app/Http/Controllers/Bookings/ListBookingsController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers\Bookings; -use App\Classes\Modules\Addresses\ControllersLogic\ListAddressesLogic; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use App\Classes\Modules\Bookings\ControllersLogic\ListBookingsLogic; @@ -13,9 +12,9 @@ class ListBookingsController { /** * @param Request $request + * @param ListBookingsLogic $logic * @return JsonResponse - * @param ListBookingsLogic - */ + */ public function list(Request $request, ListBookingsLogic $logic) : JsonResponse { return $logic->execute($request); diff --git a/app/Http/Controllers/Companies/ApproveIdentificationDocumentController.php b/app/Http/Controllers/Companies/ApproveIdentificationDocumentController.php new file mode 100644 index 00000000..719350c3 --- /dev/null +++ b/app/Http/Controllers/Companies/ApproveIdentificationDocumentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/AssignCompanyToSegmentController.php b/app/Http/Controllers/Companies/AssignCompanyToSegmentController.php new file mode 100644 index 00000000..a5981771 --- /dev/null +++ b/app/Http/Controllers/Companies/AssignCompanyToSegmentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/CreateIdentificationDocumentController.php b/app/Http/Controllers/Companies/CreateIdentificationDocumentController.php new file mode 100644 index 00000000..dd8ca321 --- /dev/null +++ b/app/Http/Controllers/Companies/CreateIdentificationDocumentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/FetchCompanyBookingQuotationController.php b/app/Http/Controllers/Companies/FetchCompanyBookingQuotationController.php new file mode 100644 index 00000000..e2fd37b4 --- /dev/null +++ b/app/Http/Controllers/Companies/FetchCompanyBookingQuotationController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/RemoveCompanyFromSegmentController.php b/app/Http/Controllers/Companies/RemoveCompanyFromSegmentController.php new file mode 100644 index 00000000..604f8ee6 --- /dev/null +++ b/app/Http/Controllers/Companies/RemoveCompanyFromSegmentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Companies/UpdateSupplierCurrenciesController.php b/app/Http/Controllers/Companies/UpdateSupplierCurrenciesController.php new file mode 100644 index 00000000..f58f3997 --- /dev/null +++ b/app/Http/Controllers/Companies/UpdateSupplierCurrenciesController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/CompanyBanks/CreateCompanyBankController.php b/app/Http/Controllers/CompanyBanks/CreateCompanyBankController.php deleted file mode 100644 index 0bc71813..00000000 --- a/app/Http/Controllers/CompanyBanks/CreateCompanyBankController.php +++ /dev/null @@ -1,19 +0,0 @@ -execute($request); - } -} \ No newline at end of file diff --git a/app/Http/Controllers/CompanyBanks/DeleteCompanyBankController.php b/app/Http/Controllers/CompanyBanks/DeleteCompanyBankController.php deleted file mode 100644 index 8a86eb1e..00000000 --- a/app/Http/Controllers/CompanyBanks/DeleteCompanyBankController.php +++ /dev/null @@ -1,19 +0,0 @@ -execute($request); - } -} \ No newline at end of file diff --git a/app/Http/Controllers/CompanyBanks/UpdateCompanyBankController.php b/app/Http/Controllers/CompanyBanks/UpdateCompanyBankController.php deleted file mode 100644 index a69bad4d..00000000 --- a/app/Http/Controllers/CompanyBanks/UpdateCompanyBankController.php +++ /dev/null @@ -1,20 +0,0 @@ -execute($request); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/CompanyBanks/UpdateToDefaultCompanyBankController.php b/app/Http/Controllers/CompanyBanks/UpdateToDefaultCompanyBankController.php deleted file mode 100644 index c5788ff4..00000000 --- a/app/Http/Controllers/CompanyBanks/UpdateToDefaultCompanyBankController.php +++ /dev/null @@ -1,20 +0,0 @@ -execute($request); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/FetchSystemPrimaryCurrencyController.php b/app/Http/Controllers/Currencies/FetchSystemPrimaryCurrencyController.php new file mode 100644 index 00000000..73b8b1e5 --- /dev/null +++ b/app/Http/Controllers/Currencies/FetchSystemPrimaryCurrencyController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/CalculateRateController.php b/app/Http/Controllers/Currencies/Rates/CalculateRateController.php new file mode 100644 index 00000000..4ccd0923 --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/CalculateRateController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/CreateRateController.php b/app/Http/Controllers/Currencies/Rates/CreateRateController.php new file mode 100644 index 00000000..91a6f4d5 --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/CreateRateController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/DeleteRateController.php b/app/Http/Controllers/Currencies/Rates/DeleteRateController.php new file mode 100644 index 00000000..b361ed84 --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/DeleteRateController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/FetchRateController.php b/app/Http/Controllers/Currencies/Rates/FetchRateController.php new file mode 100644 index 00000000..b72b40df --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/FetchRateController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/ListRatesController.php b/app/Http/Controllers/Currencies/Rates/ListRatesController.php new file mode 100644 index 00000000..04ba3162 --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/ListRatesController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/Rates/UpdateRateController.php b/app/Http/Controllers/Currencies/Rates/UpdateRateController.php new file mode 100644 index 00000000..651854bc --- /dev/null +++ b/app/Http/Controllers/Currencies/Rates/UpdateRateController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/CurrencyRates/CalculateCurrencyRateController.php b/app/Http/Controllers/CurrencyRates/CalculateCurrencyRateController.php deleted file mode 100644 index dd432305..00000000 --- a/app/Http/Controllers/CurrencyRates/CalculateCurrencyRateController.php +++ /dev/null @@ -1,19 +0,0 @@ -execute($request); - } -} \ No newline at end of file diff --git a/app/Http/Controllers/CurrencyRates/CreateCurrencyRateController.php b/app/Http/Controllers/CurrencyRates/CreateCurrencyRateController.php deleted file mode 100644 index cfe150c5..00000000 --- a/app/Http/Controllers/CurrencyRates/CreateCurrencyRateController.php +++ /dev/null @@ -1,20 +0,0 @@ -execute($request); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/CurrencyRates/DeleteCurrencyRateController.php b/app/Http/Controllers/CurrencyRates/DeleteCurrencyRateController.php deleted file mode 100644 index 91a5df45..00000000 --- a/app/Http/Controllers/CurrencyRates/DeleteCurrencyRateController.php +++ /dev/null @@ -1,20 +0,0 @@ -execute($request); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/CurrencyRates/FetchCurrencyRateController.php b/app/Http/Controllers/CurrencyRates/FetchCurrencyRateController.php deleted file mode 100644 index 524ef007..00000000 --- a/app/Http/Controllers/CurrencyRates/FetchCurrencyRateController.php +++ /dev/null @@ -1,20 +0,0 @@ -execute($request); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/CurrencyRates/ListCurrencyRatesController.php b/app/Http/Controllers/CurrencyRates/ListCurrencyRatesController.php deleted file mode 100644 index 7254bca8..00000000 --- a/app/Http/Controllers/CurrencyRates/ListCurrencyRatesController.php +++ /dev/null @@ -1,20 +0,0 @@ -execute($request); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/CurrencyRates/UpdateCompanyController.php b/app/Http/Controllers/CurrencyRates/UpdateCompanyController.php deleted file mode 100644 index a6c6d61c..00000000 --- a/app/Http/Controllers/CurrencyRates/UpdateCompanyController.php +++ /dev/null @@ -1,20 +0,0 @@ -execute($request); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/Documents/ApproveDocumentController.php b/app/Http/Controllers/Documents/ApproveDocumentController.php index 964a3811..ae55f51c 100644 --- a/app/Http/Controllers/Documents/ApproveDocumentController.php +++ b/app/Http/Controllers/Documents/ApproveDocumentController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\Documents; -use App\Classes\Modules\Documents\ControllersLogic\ApproveDocumentLogic; +use App\Classes\Modules\Documents\ControllersLogic\ApproveIdentificationDocumentLogic; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -10,10 +10,10 @@ class ApproveDocumentController { /** * @param Request $request - * @param ApproveDocumentLogic $logic + * @param ApproveIdentificationDocumentLogic $logic * @return JsonResponse */ - public function approve(Request $request, ApproveDocumentLogic $logic): JsonResponse { + public function approve(Request $request, ApproveIdentificationDocumentLogic $logic): JsonResponse { return $logic->execute($request); } diff --git a/app/Http/Controllers/Documents/RejectDocumentController.php b/app/Http/Controllers/Documents/RejectDocumentController.php new file mode 100644 index 00000000..156d7d03 --- /dev/null +++ b/app/Http/Controllers/Documents/RejectDocumentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Documents/RenderDocumentController.php b/app/Http/Controllers/Documents/RenderDocumentController.php new file mode 100644 index 00000000..690f99f9 --- /dev/null +++ b/app/Http/Controllers/Documents/RenderDocumentController.php @@ -0,0 +1,22 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php b/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php deleted file mode 100644 index 7520e1d1..00000000 --- a/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php +++ /dev/null @@ -1,19 +0,0 @@ -execute($request); - } -} \ No newline at end of file diff --git a/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php b/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php deleted file mode 100644 index c34914dc..00000000 --- a/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php +++ /dev/null @@ -1,20 +0,0 @@ -execute($request); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/FetchConstantController.php b/app/Http/Controllers/Segments/FetchConstantController.php new file mode 100644 index 00000000..e3658802 --- /dev/null +++ b/app/Http/Controllers/Segments/FetchConstantController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/FetchSegmentController.php b/app/Http/Controllers/Segments/FetchSegmentController.php new file mode 100644 index 00000000..91961689 --- /dev/null +++ b/app/Http/Controllers/Segments/FetchSegmentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/ListSegmentsController.php b/app/Http/Controllers/Segments/ListSegmentsController.php new file mode 100644 index 00000000..3dc14ebd --- /dev/null +++ b/app/Http/Controllers/Segments/ListSegmentsController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/UpdateConstantController.php b/app/Http/Controllers/Segments/UpdateConstantController.php new file mode 100644 index 00000000..47def571 --- /dev/null +++ b/app/Http/Controllers/Segments/UpdateConstantController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/UpdateCustomServiceConstantController.php b/app/Http/Controllers/Segments/UpdateCustomServiceConstantController.php new file mode 100644 index 00000000..29bb6655 --- /dev/null +++ b/app/Http/Controllers/Segments/UpdateCustomServiceConstantController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/ServiceTypes/CreateServiceTypeController.php b/app/Http/Controllers/ServiceTypes/CreateServiceTypeController.php new file mode 100644 index 00000000..831383d0 --- /dev/null +++ b/app/Http/Controllers/ServiceTypes/CreateServiceTypeController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/ServiceTypes/DeleteServiceTypeController.php b/app/Http/Controllers/ServiceTypes/DeleteServiceTypeController.php new file mode 100644 index 00000000..2178f11a --- /dev/null +++ b/app/Http/Controllers/ServiceTypes/DeleteServiceTypeController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/ServiceTypes/FetchServiceTypeController.php b/app/Http/Controllers/ServiceTypes/FetchServiceTypeController.php new file mode 100644 index 00000000..80742a54 --- /dev/null +++ b/app/Http/Controllers/ServiceTypes/FetchServiceTypeController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/ServiceTypes/ListServiceTypesController.php b/app/Http/Controllers/ServiceTypes/ListServiceTypesController.php new file mode 100644 index 00000000..848e7f4c --- /dev/null +++ b/app/Http/Controllers/ServiceTypes/ListServiceTypesController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/ServiceTypes/UpdateServiceTypeController.php b/app/Http/Controllers/ServiceTypes/UpdateServiceTypeController.php new file mode 100644 index 00000000..0e103dcb --- /dev/null +++ b/app/Http/Controllers/ServiceTypes/UpdateServiceTypeController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/ServiceTypes/UpdateServiceTypeStatusController.php b/app/Http/Controllers/ServiceTypes/UpdateServiceTypeStatusController.php new file mode 100644 index 00000000..472d2535 --- /dev/null +++ b/app/Http/Controllers/ServiceTypes/UpdateServiceTypeStatusController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Services/CountriesListController.php b/app/Http/Controllers/Services/CountriesListController.php new file mode 100644 index 00000000..cebb0b48 --- /dev/null +++ b/app/Http/Controllers/Services/CountriesListController.php @@ -0,0 +1,14 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/StandardSegments/ListStandardSegmentsController.php b/app/Http/Controllers/StandardSegments/ListStandardSegmentsController.php index 0218ac37..606e43a7 100644 --- a/app/Http/Controllers/StandardSegments/ListStandardSegmentsController.php +++ b/app/Http/Controllers/StandardSegments/ListStandardSegmentsController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\StandardSegments; -use App\Classes\Modules\Segments\ControllersLogic\ListStandardSegmentLogic; +use App\Classes\Modules\Segments\ControllersLogic\ListSegmentLogic; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -10,10 +10,10 @@ class ListStandardSegmentsController { /** * @param Request $request - * @param ListStandardSegmentLogic $logic + * @param ListSegmentLogic $logic * @return JsonResponse */ - public function list(Request $request, ListStandardSegmentLogic $logic): JsonResponse { + public function list(Request $request, ListSegmentLogic $logic): JsonResponse { return $logic->execute($request); } diff --git a/app/Http/Controllers/Transactions/CreatePaymentProofDocumentController.php b/app/Http/Controllers/Transactions/CreatePaymentProofDocumentController.php new file mode 100644 index 00000000..c7a34bc4 --- /dev/null +++ b/app/Http/Controllers/Transactions/CreatePaymentProofDocumentController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/CreatePurchaseOrderTransactionController.php b/app/Http/Controllers/Transactions/CreatePurchaseOrderTransactionController.php new file mode 100644 index 00000000..67a74537 --- /dev/null +++ b/app/Http/Controllers/Transactions/CreatePurchaseOrderTransactionController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/CreateSupplierTransactionController.php b/app/Http/Controllers/Transactions/CreateSupplierTransactionController.php new file mode 100644 index 00000000..5c989ddb --- /dev/null +++ b/app/Http/Controllers/Transactions/CreateSupplierTransactionController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/ListTransactionsController.php b/app/Http/Controllers/Transactions/ListTransactionsController.php new file mode 100644 index 00000000..64571485 --- /dev/null +++ b/app/Http/Controllers/Transactions/ListTransactionsController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/SuspendTransactionController.php b/app/Http/Controllers/Transactions/SuspendTransactionController.php new file mode 100644 index 00000000..ad7eef91 --- /dev/null +++ b/app/Http/Controllers/Transactions/SuspendTransactionController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 94a92925..172d428b 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -48,7 +48,7 @@ class Kernel extends HttpKernel ], 'api' => [ - 'throttle:60,1', + 'throttle:300,1', \Illuminate\Routing\Middleware\SubstituteBindings::class, ], ]; diff --git a/app/Http/Middleware/ValidateToken.php b/app/Http/Middleware/ValidateToken.php index 41697e07..846972aa 100644 --- a/app/Http/Middleware/ValidateToken.php +++ b/app/Http/Middleware/ValidateToken.php @@ -2,27 +2,45 @@ namespace App\Http\Middleware; +use App\Classes\Exceptions\AccessUnauthorisedException; use App\Classes\ValueObjects\Constants\HttpStatus; use App\Classes\ValueObjects\Response\ApiResponseObject; use Closure; use Exception; -use Tymon\JWTAuth\Facades\JWTAuth; +use Tymon\JWTAuth\JWT; class ValidateToken { + /** @var JWT */ + private $manager; + + /** + * ValidateToken constructor. + * @param JWT $manager + */ + public function __construct(JWT $manager) + { + $this->manager = $manager; + } + + /** * Checks if jwt token is valid. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next + * @param \Illuminate\Http\Request $request + * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { try { - JWTAuth::parseToken()->authenticate(); + + if(!$this->manager->check()){ throw new AccessUnauthorisedException(); } + } catch (Exception $exception) { + return (new ApiResponseObject('Authentication', 'To keep your account secure we need to re-validate your account', HttpStatus::ACCESS_UNAUTHORISED))->handler(); + } return $next($request); diff --git a/app/Http/Resources/AddressResource.php b/app/Http/Resources/AddressResource.php index 1b2bebe9..4e545092 100644 --- a/app/Http/Resources/AddressResource.php +++ b/app/Http/Resources/AddressResource.php @@ -16,14 +16,12 @@ class AddressResource extends JsonResource { return [ 'id' => $this->id, - 'company_id' => $this->company_id, 'street_one' => $this->street_one, 'street_two' => $this->street_two, - 'city' => $this->city, + 'district' => $this->district, 'state' => $this->state, - 'post_code' => $this->post_code, + 'post_code' => $this->postcode, 'country' => $this->country, - 'default' => (int) $this->default, 'billing' => (int) $this->billing ]; } diff --git a/app/Http/Resources/CompanyBankResource.php b/app/Http/Resources/BankResource.php similarity index 80% rename from app/Http/Resources/CompanyBankResource.php rename to app/Http/Resources/BankResource.php index 5bb9e2d2..a0bce774 100644 --- a/app/Http/Resources/CompanyBankResource.php +++ b/app/Http/Resources/BankResource.php @@ -4,7 +4,7 @@ namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; -class CompanyBankResource extends JsonResource +class BankResource extends JsonResource { /** * Transform the resource into an array. @@ -16,12 +16,13 @@ class CompanyBankResource extends JsonResource { return [ 'id' => $this->id, - 'country_id' => $this->country_id, - 'company_id' => $this->company_id, + 'company_business_type' => $this->company->business_type, + 'type' => $this->type, + 'reference' => $this->reference, 'bank_name' => $this->bank_name, 'holder_name' => $this->holder_name, 'account_no' => $this->account_no, - 'type' => $this->type, + 'country_id' => $this->country_id, 'default' => $this->default, 'status' => $this->status, ]; diff --git a/app/Http/Resources/BookingResource.php b/app/Http/Resources/BookingResource.php index ee5c62a9..57d93e57 100644 --- a/app/Http/Resources/BookingResource.php +++ b/app/Http/Resources/BookingResource.php @@ -2,29 +2,53 @@ namespace App\Http\Resources; +use App\Classes\Modules\Bookings\Services\CalculatesBookingFloatingAmount; +use App\Classes\Modules\Bookings\Services\CalculatesBookingOutstanding; +use App\Classes\Modules\Bookings\Services\CalculatesBookingPaidAmount; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\ValueObjects\Constants\TransactionType; +use Carbon\Carbon; use Illuminate\Http\Resources\Json\JsonResource; class BookingResource extends JsonResource { + /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function toArray($request) { return [ 'id' => $this->id, - 'company_id' => $this->company_id, - 'transferable_bank_id' => $this->transferable_bank_id, + 'company' => new CompanyResource($this->company), + 'bank' => new BankResource($this->bank), + 'service' => new ServiceTypeResource($this->service), 'marking' => $this->marking, - 'reference' => $this->reference, - 'fix_amount' => $this->fix_amount, - 'fix_currency_id' => $this->fix_currency_id, - 'convertible_currency_id' => $this->convertible_currency_id, - 'conversion_currency_id' => $this->conversion_currency_id, - 'status' => $this->status + 'amount' => $this->fix_amount, + 'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)), + 'paid_amount' => floatval((App()->make(CalculatesBookingPaidAmount::class))->execute($this->resource, $this->fix_currency_id)), + 'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)), + 'fixed_currency' => new CurrencyResource($this->fixedCurrency), + 'convertible_currency' => new CurrencyResource($this->convertibleCurrency), + 'conversion_currency' => new CurrencyResource($this->conversionCurrency), + 'status' => $this->status, + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'), + $this->mergeWhen($this->relationLoaded('transactions'), [ + 'purchase_order' => new TransactionResource($this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()), + 'payment_attempts' => TransactionResource::collection($this->transactions()->where('type', TransactionType::PAYMENT)->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->get()), + 'expired_payment_attempts' => TransactionResource::collection($this->transactions()->where('type', TransactionType::PAYMENT)->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '<', Carbon::now())->get()), + 'payment_history' => TransactionResource::collection($this->transactions()->where(function($query){ + $query->where(function($query){ + $query->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::REJECTED]); + })->orWhere(function($query){ + $query->where('type', TransactionType::BILL)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); + }); + })->latest()->get()) + ]) ]; } } diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index af34cfdf..1cc465aa 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -2,6 +2,13 @@ namespace App\Http\Resources; +use App\Classes\Modules\Companies\Services\FetchesCompanyServices; +use App\Classes\ValueObjects\Constants\BankAccountType; +use App\Classes\ValueObjects\Constants\BusinessType; +use App\Classes\ValueObjects\Constants\DocumentType; +use App\Classes\ValueObjects\Constants\SegmentConstants; +use App\Models\Currency; +use App\Models\SegmentConstant; use Illuminate\Http\Resources\Json\JsonResource; class CompanyResource extends JsonResource @@ -19,7 +26,27 @@ class CompanyResource extends JsonResource 'name' => $this->name, 'reference' => $this->reference, 'type' => (int) $this->type, - 'status' => (int) $this->status + 'business_type' => (int) $this->business_type, + 'status' => (int) $this->status, + 'contact' => new ContactResource ($this->when($this->has('contacts'), $this->contacts->first())), + 'address' => new AddressResource($this->when($this->has('addresses'), $this->addresses->first())), + 'employee' => new UserResource($this->employees->first()), + 'identification' => new DocumentResource($this->whenLoaded('documents', $this->documents->whereIn('document_type', DocumentType::IDENTIFICATION_DOCUMENTS)->first())), + 'bookings' => BookingResource::collection($this->whenLoaded('bookings', $this->bookings()->orderBy('id', 'DESC')->get(), [])), + 'personal_banks' => BankResource::collection($this->banks->where('type', BankAccountType::PERSONAL)), + 'recipient_banks' => [ + 'accounts' => BankResource::collection($this->banks->where('type', BankAccountType::EXTERNAL)), + 'default' => new BankResource($this->banks->where('type', BankAccountType::EXTERNAL)->where('default', true)->first()) + ], + 'segments' => SegmentResource::collection($this->segments), + 'services' => (new FetchesCompanyServices())->getServices($this->servicesConfigurations()), + 'currencies' => $this->when($this->business_type === BusinessType::CURRENCY_VENDOR, function(){ + $segment = SegmentConstant::where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $this->id)->first(); + return $segment ? CurrencyResource::collection(Currency::whereIn('id', $segment->detail->currencies)->get()) : []; + }) + + ]; + } } diff --git a/app/Http/Resources/ConstantResource.php b/app/Http/Resources/ConstantResource.php new file mode 100644 index 00000000..3e1408c3 --- /dev/null +++ b/app/Http/Resources/ConstantResource.php @@ -0,0 +1,27 @@ + $this->id, + 'name' => $this->name, + 'reference' => $this->reference, + 'detail' => (App()->make(ConvertsConstantDetailsToResource::class))->execute($this) + ]; + } +} diff --git a/app/Http/Resources/ContactResource.php b/app/Http/Resources/ContactResource.php index 9a8435d4..359e61cd 100644 --- a/app/Http/Resources/ContactResource.php +++ b/app/Http/Resources/ContactResource.php @@ -16,8 +16,7 @@ class ContactResource extends JsonResource { return [ 'id' => $this->id, - 'country_id' => $this->country_id, - 'company_id' => $this->company_id, + 'country_code' => $this->country->phone_code, 'reference' => $this->reference, 'phone' => $this->phone, 'email' => $this->email, diff --git a/app/Http/Resources/CountryResource.php b/app/Http/Resources/CountryResource.php new file mode 100644 index 00000000..f15c41f8 --- /dev/null +++ b/app/Http/Resources/CountryResource.php @@ -0,0 +1,24 @@ + $this->id, + 'name' => $this->name, + 'short_code' => $this->short_code, + 'phone_code' => $this->phone_code, + ]; + } +} diff --git a/app/Http/Resources/CurrencyConversionResource.php b/app/Http/Resources/CurrencyConversionResource.php new file mode 100644 index 00000000..0c87a9e7 --- /dev/null +++ b/app/Http/Resources/CurrencyConversionResource.php @@ -0,0 +1,26 @@ + $this->id, + 'country' => new CountryResource($this->country), + 'name' => $this->name, + 'short_code' => $this->short_code, + 'symbol' => $this->symbol, + ]; + } +} diff --git a/app/Http/Resources/CurrencyRateResource.php b/app/Http/Resources/CurrencyRateResource.php index e94f0f67..66d548f1 100644 --- a/app/Http/Resources/CurrencyRateResource.php +++ b/app/Http/Resources/CurrencyRateResource.php @@ -2,6 +2,7 @@ namespace App\Http\Resources; +use App\Classes\ValueObjects\Constants\PaymentMethodType; use Illuminate\Http\Resources\Json\JsonResource; class CurrencyRateResource extends JsonResource @@ -15,10 +16,11 @@ class CurrencyRateResource extends JsonResource public function toArray($request) { return [ - 'id' => $this->id, - 'currency_id' => $this->currency_id, - 'selling' => $this->selling, - 'payment_method_type' => $this->payment_method_type + 'payment_method' => PaymentMethodType::PAYMENT_METHODS_ID[$this->payment_method_type], + 'selling' => [ + 'type' => property_exists($this->selling, 'type') ? $this->selling->type : 'rate', + 'value' => property_exists($this->selling, 'value') ? $this->selling->value : $this->selling + ] ]; } } diff --git a/app/Http/Resources/CurrencyResource.php b/app/Http/Resources/CurrencyResource.php index 52454483..e6265c67 100644 --- a/app/Http/Resources/CurrencyResource.php +++ b/app/Http/Resources/CurrencyResource.php @@ -2,6 +2,7 @@ namespace App\Http\Resources; +use App\Models\CurrencyRate; use Illuminate\Http\Resources\Json\JsonResource; class CurrencyResource extends JsonResource @@ -16,11 +17,10 @@ class CurrencyResource extends JsonResource { return [ 'id' => $this->id, - 'country_id' => $this->country_id, + 'country' => new CountryResource($this->country), 'name' => $this->name, 'short_code' => $this->short_code, 'symbol' => $this->symbol, - 'currency_rates' => $this->currency_rates()->get() ]; } } diff --git a/app/Http/Resources/CustomServiceTypeResource.php b/app/Http/Resources/CustomServiceTypeResource.php new file mode 100644 index 00000000..8ec26e47 --- /dev/null +++ b/app/Http/Resources/CustomServiceTypeResource.php @@ -0,0 +1,27 @@ + $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) + ]; + } +} diff --git a/app/Http/Resources/DistrictResource.php b/app/Http/Resources/DistrictResource.php new file mode 100644 index 00000000..c0c24f73 --- /dev/null +++ b/app/Http/Resources/DistrictResource.php @@ -0,0 +1,24 @@ + $this->id, + 'city' => $this->name, + 'state' => $this->state, + 'country' => $this->country + ]; + } +} diff --git a/app/Http/Resources/DocumentResource.php b/app/Http/Resources/DocumentResource.php index 51aef2e7..dbfea08c 100644 --- a/app/Http/Resources/DocumentResource.php +++ b/app/Http/Resources/DocumentResource.php @@ -2,6 +2,9 @@ namespace App\Http\Resources; +use App\Models\Company; +use App\Models\Document; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Resources\Json\JsonResource; class DocumentResource extends JsonResource @@ -16,11 +19,11 @@ class DocumentResource extends JsonResource { return [ 'id' => $this->id, - 'document_type' => $this->document_type, 'reference' => $this->reference, 'status' => (int) $this->status, - 'approved_by' => (int) $this->approved_by, - 'files' => $this->files()->get() + 'document_type' => $this->document_type, + 'owner' => new CompanyResource($this->whenLoaded('owner')), + 'files' => FileResource::collection($this->files) ]; } } diff --git a/app/Http/Resources/SegmentConstantResource.php b/app/Http/Resources/FileResource.php similarity index 73% rename from app/Http/Resources/SegmentConstantResource.php rename to app/Http/Resources/FileResource.php index aa939d8e..20a84589 100644 --- a/app/Http/Resources/SegmentConstantResource.php +++ b/app/Http/Resources/FileResource.php @@ -4,7 +4,7 @@ namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; -class SegmentConstantResource extends JsonResource +class FileResource extends JsonResource { /** * Transform the resource into an array. @@ -16,8 +16,8 @@ class SegmentConstantResource extends JsonResource { return [ 'id' => $this->id, - 'name' => $this->name, - 'detail' => $this->detail + 'file' => $this->file, + 'type' => (int) $this->file_type, ]; } } diff --git a/app/Http/Resources/SegmentResource.php b/app/Http/Resources/SegmentResource.php index f07e9661..58118e08 100644 --- a/app/Http/Resources/SegmentResource.php +++ b/app/Http/Resources/SegmentResource.php @@ -2,6 +2,7 @@ namespace App\Http\Resources; +use App\Classes\ValueObjects\Constants\SegmentConstants; use Illuminate\Http\Resources\Json\JsonResource; class SegmentResource extends JsonResource @@ -17,6 +18,10 @@ class SegmentResource extends JsonResource return [ 'id' => $this->id, 'name' => $this->name, + 'time_limit' => $this->when($this->whereHas('constants', function($query){ + $query->where('reference', SegmentConstants::PAYMENT_ATTEMPT_DURATION_LIMIT); + }), $this->constants->where('reference', SegmentConstants::PAYMENT_ATTEMPT_DURATION_LIMIT)->first()), + 'services' => CustomServiceTypeResource::collection($this->constants->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)) ]; } } diff --git a/app/Http/Resources/ServiceTypeResource.php b/app/Http/Resources/ServiceTypeResource.php new file mode 100644 index 00000000..bc46b23d --- /dev/null +++ b/app/Http/Resources/ServiceTypeResource.php @@ -0,0 +1,31 @@ +where('detail->id', $this->id)->first(); + return [ + 'id' => $this->id, + 'status' => (int) $this->status, + 'name' => $this->name, + 'configurations' => (App()->make(FetchesServiceConfigurations::class))->execute($constants, SegmentConstants::SERVICE_TYPE) + ]; + + } +} diff --git a/app/Http/Resources/TransactionDetailResource.php b/app/Http/Resources/TransactionDetailResource.php index 9589b1f7..1b60cfce 100644 --- a/app/Http/Resources/TransactionDetailResource.php +++ b/app/Http/Resources/TransactionDetailResource.php @@ -16,16 +16,11 @@ class TransactionDetailResource extends JsonResource { return [ - 'id' => $this->id, - 'trans_type1' => $this->trans_type1, - 'trans_type2' => $this->trans_type2, - 'transaction_id' => (int) $this->transaction_id, - 'product_code' => $this->product_code, - 'product_name' => $this->product_name, - 'qty' => (int) $this->qty, - 'price' => (double) $this->price, - 'amount' => (double) $this->amount - + 'stockCode' => $this->product_code, + 'description' => $this->product_name, + 'quantity' => $this->quantity, + 'unit_price' => (double) $this->price, + 'total' => (double) $this->amount ]; } } diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index c5ba9af5..a543f00d 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -2,6 +2,7 @@ namespace App\Http\Resources; +use Carbon\Carbon; use Illuminate\Http\Resources\Json\JsonResource; class TransactionResource extends JsonResource @@ -14,21 +15,21 @@ class TransactionResource extends JsonResource */ public function toArray($request) { - + return [ 'id' => $this->id, - 'trans_type1' => $this->trans_type1, - 'trans_type2' => $this->trans_type2, - 'bill_no' => (int) $this->bill_no, + 'booking' => new BookingResource($this->booking), + 'bill_no' => $this->bill_no, 'amount' => (double) $this->amount, - 'currency_id' => (int) $this->currency_id, 'original_amount' => (double) $this->original_amount, - 'original_currency_id' => (int) $this->original_currency_id, + 'currency' => new CurrencyResource($this->currency), + 'original_currency' => new CurrencyResource($this->original_currency), 'currency_rate' => (double) $this->currency_rate, - 'dt_transaction' => $this->dt_transaction, 'status' => (int) $this->status, - 'booking_id' => (int) $this->booking_id, - 'company_id' => (int) $this->company_id + 'details' => TransactionDetailResource::collection($this->transactionDetails), + 'documents' => new DocumentResource($this->documents()->first()), + 'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:s:i'), + 'updated_at' => Carbon::parse($this->update_at)->format('d-m-Y h:s:i') ]; } } diff --git a/app/Models/Address.php b/app/Models/Address.php index 78033755..47a615b2 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -2,13 +2,13 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Address * @package App\Models - * @version August 4, 2020, 4:36 am * * @property \App\Models\Country country_id * @property \App\Models\Company company_id @@ -28,34 +28,34 @@ class Address extends AbstractModel protected $dates = ['deleted_at']; /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - **/ - public function country(): HasOne + * @return BelongsTo + */ + public function country(): BelongsTo { - return $this->hasOne(Country::class, 'country_id', 'id'); + return $this->BelongsTo(Country::class, 'country_id', 'id'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - **/ - public function company(): HasOne + * @return BelongsTo + */ + public function company(): BelongsTo { - return $this->hasOne(Company::class, 'company_id', 'id'); + return $this->BelongsTo(Company::class, 'company_id', 'id'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - **/ - public function state(): HasOne + * @return BelongsTo + */ + public function state(): BelongsTo { - return $this->hasOne(State::class, 'state_id', 'id'); + return $this->BelongsTo(State::class, 'state_id', 'id'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - **/ - public function district(): HasOne + * @return BelongsTo + */ + public function district(): BelongsTo { - return $this->hasOne(District::class, 'district_id', 'id'); + return $this->BelongsTo(District::class, 'district_id', 'id'); } } diff --git a/app/Models/CompanyBank.php b/app/Models/Bank.php similarity index 68% rename from app/Models/CompanyBank.php rename to app/Models/Bank.php index 308d809d..9381b94a 100644 --- a/app/Models/CompanyBank.php +++ b/app/Models/Bank.php @@ -2,14 +2,14 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\HasOne; /** - * Class CompanyBank + * Class Bank * @package App\Models - * @version August 4, 2020, 4:36 am * * @property \App\Models\Country country_id * @property \App\Models\Company company_id @@ -20,11 +20,11 @@ use Illuminate\Database\Eloquent\Relations\HasOne; * @property int default * @property int status */ -class CompanyBank extends AbstractModel +class Bank extends AbstractModel { use SoftDeletes; - protected $table = 'company_banks'; + protected $table = 'banks'; /** * @return \Illuminate\Database\Eloquent\Relations\HasOne @@ -35,10 +35,10 @@ class CompanyBank extends AbstractModel } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo **/ - public function company(): HasOne + public function company(): BelongsTo { - return $this->hasOne(Company::class, 'company_id', 'id'); + return $this->BelongsTo(Company::class, 'company_id', 'id'); } } diff --git a/app/Models/Booking.php b/app/Models/Booking.php index 0e56c5fc..e719abc5 100644 --- a/app/Models/Booking.php +++ b/app/Models/Booking.php @@ -2,15 +2,20 @@ namespace App\Models; +use App\Classes\ValueObjects\Constants\RoleTypes; +use App\Scopes\CustomerBookingsScope; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Booking * @package App\Models - * @version August 4, 2020, 4:36 am * * @property \App\Models\Company company_id - * @property \App\Models\CompanyBank transferable_bank_id + * @property \App\Models\Bank transferable_bank_id * @property string marking * @property string reference * @property float fix_amount @@ -24,4 +29,69 @@ class Booking extends AbstractModel protected $table = 'bookings'; protected $dates = ['deleted_at']; + + /** + * @return BelongsTo + */ + public function company(): BelongsTo + { + return $this->BelongsTo(Company::class, 'company_id'); + } + + /** + * @return BelongsTo + */ + public function service(): BelongsTo + { + return $this->BelongsTo(ServiceType::class, 'service_id'); + } + + /** + * @return BelongsTo + */ + public function bank(): BelongsTo + { + return $this->BelongsTo(Bank::class, 'bank_id'); + } + + /** + * @return BelongsTo + */ + public function fixedCurrency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'fix_currency_id'); + } + + /** + * @return BelongsTo + */ + public function convertibleCurrency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'convertible_currency_id'); + } + + /** + * @return BelongsTo + */ + public function conversionCurrency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'conversion_currency_id'); + } + + /** + * @return HasMany + */ + public function transactions(): HasMany + { + return $this->HasMany(Transaction::class, 'booking_id'); + } + + protected static function booted() + { + if (auth()->user()->type === RoleTypes::USER) { + static::addGlobalScope(new CustomerBookingsScope); + } + } + + } diff --git a/app/Models/Company.php b/app/Models/Company.php index f791ddeb..c1a6a191 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -1,14 +1,21 @@ HasMany(Contact::class, 'company_id'); + } + + /** + * @return HasMany + */ + public function addresses(): HasMany + { + return $this->HasMany(Address::class, 'company_id'); + } + /** * @return belongsToMany */ - public function segment(): belongsToMany + public function segments(): belongsToMany { - return $this->belongsToMany(Segment::class, 'segment_company', 'company_id', 'segment_id'); + return $this->belongsToMany(Segment::class, (new SegmentCompany())->getTable(), 'company_id', 'segment_id'); } + + /** + * @return belongsToMany + */ + public function employees(): belongsToMany + { + return $this->belongsToMany(User::class, (new Employee())->getTable(), 'company_id','user_id'); + } + + /** + * @return MorphMany + */ + public function documents(): morphMany + { + return $this->morphMany(Document::class, 'owner'); + } + + /** + * @return HasMany + */ + public function banks(): HasMany + { + return $this->HasMany(Bank::class, 'company_id'); + } + + /** + * @return HasMany + */ + public function bookings(): HasMany + { + return $this->HasMany(Booking::class, 'company_id'); + } + + /** + * @return Builder + */ + public function services(): Builder { + return ServiceType::where('status', ApprovalStatus::APPROVED)->whereHas('constants', function($query) { + $query->Where(function($query){ + $query->where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->is_active', true); + })->orWhere(function($query) { + $query->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->where('detail->is_active', true)->whereIn('segment_id', $this->segments->pluck('id')); + }); + }); + } + + public function servicesConfigurations(): Collection { + return $this->services()->get()->map(function($service) { + return new ServiceConfigurationsObject($service, + $service->constants->where('reference', SegmentConstants::SERVICE_TYPE)->first(), + $service->constants->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->whereIn('segment_id', $this->segments->pluck('id'))); + }); + } + } diff --git a/app/Models/Contact.php b/app/Models/Contact.php index 5480d946..0a54d3f7 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -2,13 +2,13 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Contact * @package App\Models - * @version August 4, 2020, 4:36 am * * @property \App\Models\Country country_id * @property \App\Models\Company company_id @@ -30,6 +30,14 @@ class Contact extends AbstractModel **/ public function company(): HasOne { - return $this->hasOne(Company::class, 'company_id', 'id'); + return $this->hasOne(Company::class); + } + + /** + * @return belongsTo + **/ + public function country(): belongsTo + { + return $this->belongsTo(Country::class); } } diff --git a/app/Models/Country.php b/app/Models/Country.php index b1abd046..3232366a 100644 --- a/app/Models/Country.php +++ b/app/Models/Country.php @@ -2,12 +2,12 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Country * @package App\Models - * @version August 4, 2020, 4:36 am * * @property string name * @property string short_code @@ -20,4 +20,14 @@ class Country extends AbstractModel protected $table = 'countries'; protected $dates = ['deleted_at']; + + protected $fillable = ['name', 'short_code', 'phone_code']; + + /** + * @return HasMany + */ + public function currencies(): HasMany + { + return $this->HasMany(Currency::class, 'country_id', 'id'); + } } diff --git a/app/Models/Currency.php b/app/Models/Currency.php index 7297a2ce..cf3b4a6f 100644 --- a/app/Models/Currency.php +++ b/app/Models/Currency.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; @@ -10,7 +11,6 @@ use Illuminate\Database\Eloquent\Relations\hasMany; /** * Class Currency * @package App\Models - * @version August 4, 2020, 4:36 am * * @property \App\Models\Country country_id * @property string name @@ -27,17 +27,17 @@ class Currency extends AbstractModel protected $dates = ['deleted_at']; /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - **/ - public function country(): HasOne + * @return BelongsTo + */ + public function country(): BelongsTo { - return $this->hasOne(Country::class, 'country_id', 'id'); + return $this->BelongsTo(Country::class, 'country_id', 'id'); } /** * @return hasMany */ - public function currency_rates(): hasMany + public function rates(): hasMany { return $this->hasMany(CurrencyRate::class, 'currency_id'); } diff --git a/app/Models/CurrencyLog.php b/app/Models/CurrencyLog.php index d294b282..ee519e8f 100644 --- a/app/Models/CurrencyLog.php +++ b/app/Models/CurrencyLog.php @@ -2,8 +2,6 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; - class CurrencyLog extends AbstractModel { protected $table = 'currency_logs'; diff --git a/app/Models/CurrencyRate.php b/app/Models/CurrencyRate.php index 73b42c50..ca8cad92 100644 --- a/app/Models/CurrencyRate.php +++ b/app/Models/CurrencyRate.php @@ -10,5 +10,7 @@ class CurrencyRate extends AbstractModel protected $table = 'currency_rates'; + protected $fillable = ['currency_id', 'selling', 'payment_method_type']; + protected $dates = ['deleted_at']; } diff --git a/app/Models/District.php b/app/Models/District.php index 4cd4c7e6..13a90f85 100644 --- a/app/Models/District.php +++ b/app/Models/District.php @@ -2,18 +2,18 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; /** * Class District * @package App\Models - * @version August 4, 2020, 4:36 am * * @property \App\Models\Country country_id * @property \App\Models\State state_id * @property string name - * @property text postcode + * @property string postcode */ class District extends AbstractModel { @@ -24,18 +24,18 @@ class District extends AbstractModel protected $dates = ['deleted_at']; /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - **/ - public function country(): HasOne + * @return BelongsTo + */ + public function country(): BelongsTo { - return $this->hasOne(Country::class, 'country_id', 'id'); + return $this->belongsTo(Country::class, 'country_id', 'id'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne + * @return BelongsTo **/ - public function state(): HasOne + public function state(): BelongsTo { - return $this->hasOne(State::class, 'state_id', 'id'); + return $this->BelongsTo(State::class, 'state_id', 'id'); } } diff --git a/app/Models/Document.php b/app/Models/Document.php index 05899fdf..eb3f8c77 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -2,7 +2,9 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use Carbon\Traits\Timestamp; +use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\hasMany; @@ -17,7 +19,7 @@ use Illuminate\Database\Eloquent\Relations\hasMany; * @property int document_type * @property string reference * @property int status - * @property \App\Models\User approved_by + * @property \App\Models\User approver * @property timestamp issued_date * @property timestamp expired_date * @property timestamp approved_date @@ -30,6 +32,14 @@ class Document extends AbstractModel protected $dates = ['deleted_at']; + /** + * @return \Illuminate\Database\Eloquent\Relations\MorphTo + */ + public function owner(): morphTo + { + return $this->morphTo(); + } + /** * @return hasMany */ @@ -38,4 +48,12 @@ class Document extends AbstractModel return $this->hasMany(File::class, 'document_id'); } + /** + * @return HasOne + */ + public function approver(): hasOne + { + return $this->hasOne(User::class, 'id', 'approver'); + } + } diff --git a/app/Models/CompanyEmployee.php b/app/Models/Employee.php similarity index 58% rename from app/Models/CompanyEmployee.php rename to app/Models/Employee.php index bff993ad..65dab67d 100644 --- a/app/Models/CompanyEmployee.php +++ b/app/Models/Employee.php @@ -2,26 +2,26 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; /** * Class CompanyEmployee * @package App\Models - * @version August 4, 2020, 4:36 am * * @property \App\Models\Company company_id * @property \App\Models\User user_id */ -class CompanyEmployee extends AbstractModel +class Employee extends AbstractModel { - protected $table = 'company_employee'; - + protected $table = 'employees'; + /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - **/ - public function company(): HasOne + * @return HasMany + */ + public function company(): HasMany { - return $this->hasOne(Company::class, 'company_id', 'id'); + return $this->HasMany(Company::class, 'company_id', 'id'); } /** diff --git a/app/Models/File.php b/app/Models/File.php index 8c175039..6707fd9f 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -20,6 +20,8 @@ class File extends AbstractModel protected $table = 'files'; + protected $fillable = ['file']; + protected $dates = ['deleted_at']; public function getFileAttribute($value) diff --git a/app/Models/PasswordReset.php b/app/Models/PasswordReset.php new file mode 100644 index 00000000..6ab27179 --- /dev/null +++ b/app/Models/PasswordReset.php @@ -0,0 +1,25 @@ +where('is_expired', false)->where('is_complete', false); + } + + /** + * @return BelongsTo + */ + public function user(): BelongsTo { + return $this->belongsTo(User::class, 'user_id', 'id'); + } +} diff --git a/app/Models/Receipt.php b/app/Models/Receipt.php index d534e7fd..b4537c26 100644 --- a/app/Models/Receipt.php +++ b/app/Models/Receipt.php @@ -9,9 +9,9 @@ class Receipt extends AbstractModel { protected $table = 'receipt'; - public function company(): HasOne + public function transaction(): HasOne { - return $this->hasOne(Companies::class, 'company_id', 'id'); + return $this->hasOne(Transaction::class, 'transaction_id', 'id'); } public function currency(): HasOne diff --git a/app/Models/Role.php b/app/Models/Role.php index c6b6e3a6..495d37da 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -2,7 +2,6 @@ namespace App\Models; -use Spatie\Permission\Models\Role as SpatieRole; use Spatie\Permission\Models\Permission; class Role extends AbstractModel diff --git a/app/Models/Segment.php b/app/Models/Segment.php index 97e2fa1a..339e8e86 100644 --- a/app/Models/Segment.php +++ b/app/Models/Segment.php @@ -2,12 +2,12 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Segment * @package App\Models - * @version August 4, 2020, 4:36 am * * @property string name * @property string reference @@ -19,4 +19,12 @@ class Segment extends AbstractModel protected $table = 'segments'; protected $dates = ['deleted_at']; + + /** + * @return HasMany + */ + public function constants(): HasMany + { + return $this->HasMany(SegmentConstant::class, 'segment_id', 'id'); + } } diff --git a/app/Models/SegmentCompany.php b/app/Models/SegmentCompany.php index bda06fcf..660057fc 100644 --- a/app/Models/SegmentCompany.php +++ b/app/Models/SegmentCompany.php @@ -2,17 +2,7 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; - -/** - * Class SegmentCompany - * @package App\Models - * @version August 4, 2020, 4:36 am - * - * @property \App\Models\Segment segment_id - * @property \App\Models\CPmpany company_id - */ class SegmentCompany extends AbstractModel { - protected $table = 'segment_company'; + protected $table = 'segment_companies'; } diff --git a/app/Models/SegmentConstant.php b/app/Models/SegmentConstant.php index aae6648d..08c8b2af 100644 --- a/app/Models/SegmentConstant.php +++ b/app/Models/SegmentConstant.php @@ -2,15 +2,16 @@ namespace App\Models; +use App\Classes\ValueObjects\Constants\SegmentConstants; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; /** * Class SegmentConstant * @package App\Models - * @version August 4, 2020, 4:36 am * * @property \App\Models\Segment segment_id - * @property text detail + * @property string detail */ class SegmentConstant extends AbstractModel { @@ -25,4 +26,22 @@ class SegmentConstant extends AbstractModel return $value ? json_decode($value) : []; } + /** + * @return BelongsTo + */ + public function segment(): BelongsTo + { + return $this->BelongsTo(Segment::class, 'segment_id', 'id'); + } + + /** + * @return mixed + */ + public function service(){ + return $this->hasOne(ServiceType::class, 'id', 'detail->id') + ->whereIn('reference', [SegmentConstants::SERVICE_TYPE, SegmentConstants::CUSTOM_SERVICE_TYPE]); + } + + + } diff --git a/app/Models/ServiceType.php b/app/Models/ServiceType.php new file mode 100644 index 00000000..b3cac31b --- /dev/null +++ b/app/Models/ServiceType.php @@ -0,0 +1,71 @@ + 'string' + ]; + + /** + * Validation rules + * + * @var array + */ + public static $rules = [ + 'name' => 'required' + ]; + + /** + * @return hasMany + */ + public function rates(): hasMany + { + return $this->hasMany(CurrencyRate::class, 'service_id'); + } + + /** + * @return hasMany + */ + public function constants(): hasMany + { + return $this->hasMany(SegmentConstant::class, 'detail->id') + ->whereIn('reference', [SegmentConstants::SERVICE_TYPE, SegmentConstants::CUSTOM_SERVICE_TYPE]); + } + +} diff --git a/app/Models/State.php b/app/Models/State.php index 7912a1d7..fa920454 100644 --- a/app/Models/State.php +++ b/app/Models/State.php @@ -2,12 +2,12 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; /** * Class State * @package App\Models - * @version August 4, 2020, 4:36 am * * @property \App\Models\Country country_id * @property string name @@ -21,8 +21,8 @@ class State extends AbstractModel protected $dates = ['deleted_at']; /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne - **/ + * @return HasOne + */ public function country(): HasOne { return $this->hasOne(Country::class, 'country_id', 'id'); diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 51b28c09..51597ba2 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -2,26 +2,54 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Relations\HasOne; +use App\Classes\General\Interfaces\Documentable; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\MorphMany; -class Transaction extends AbstractModel +class Transaction extends AbstractModel implements Documentable { - protected $table = 'transaction'; + protected $table = 'transactions'; - public function company(): HasOne + /** + * @return BelongsTo + */ + public function booking(): BelongsTo { - return $this->hasOne(Companies::class, 'company_id', 'id'); + return $this->BelongsTo( booking::class, 'booking_id', 'id'); } - - public function currency(): HasOne + + /** + * @return MorphMany + */ + public function documents(): morphMany { - return $this->hasOne(Currency::class, 'currency_id', 'id'); + return $this->morphMany(Document::class, 'owner'); } - - public function original_currency(): HasOne + + /** + * @return BelongsTo + */ + public function currency(): BelongsTo { - return $this->hasOne(Currency::class, 'original_currency_id', 'id'); + return $this->BelongsTo(Currency::class, 'currency_id', 'id'); + } + + /** + * @return BelongsTo + */ + public function original_currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'original_currency_id', 'id'); + } + + /** + * @return HasMany + */ + public function transactionDetails(): HasMany + { + return $this->HasMany(TransactionDetail::class, 'transaction_id', 'id'); } } diff --git a/app/Models/User.php b/app/Models/User.php index 36e9e2ab..d41cbb7f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -60,8 +60,8 @@ class User extends AbstractModel implements /** * @return belongsToMany */ - public function company(): belongsToMany + public function company(): belongsToMany { - return $this->belongsToMany(Company::class, 'company_employee', 'user_id', 'company_id'); + return $this->belongsToMany(Company::class, (new Employee())->getTable(), 'user_id', 'company_id'); } } diff --git a/app/Models/UserEmailVerification.php b/app/Models/UserEmailVerification.php new file mode 100644 index 00000000..278c8cd6 --- /dev/null +++ b/app/Models/UserEmailVerification.php @@ -0,0 +1,28 @@ +where('is_active', true)->where('is_complete', false); + } + + /** + * @return BelongsTo + */ + public function user(): BelongsTo { + return $this->belongsTo(User::class, 'email', 'email'); + } +} diff --git a/app/Models/WalletTransaction.php b/app/Models/WalletTransaction.php index efd5a878..9441c396 100644 --- a/app/Models/WalletTransaction.php +++ b/app/Models/WalletTransaction.php @@ -13,6 +13,11 @@ class WalletTransaction extends AbstractModel { return $this->hasOne(Wallet::class, 'wallet_id', 'id'); } + + public function transaction(): HasOne + { + return $this->hasOne(Transaction::class, 'transaction_id', 'id'); + } public function currency(): HasOne { diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 30490683..b14e5898 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -3,7 +3,6 @@ namespace App\Providers; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; -use Illuminate\Support\Facades\Gate; class AuthServiceProvider extends ServiceProvider { diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 723a290d..1c0e60ee 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -5,7 +5,6 @@ namespace App\Providers; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -use Illuminate\Support\Facades\Event; class EventServiceProvider extends ServiceProvider { diff --git a/app/Scopes/CustomerBookingsScope.php b/app/Scopes/CustomerBookingsScope.php new file mode 100644 index 00000000..c2da5b86 --- /dev/null +++ b/app/Scopes/CustomerBookingsScope.php @@ -0,0 +1,27 @@ +whereHas('company', function($query){ + return $query->whereHas('employees', function($query){ + return $query->where('user_id', Auth()->user()->id); + }); + }); + } + +} \ No newline at end of file diff --git a/composer.json b/composer.json index 5aab2193..ec061d4f 100644 --- a/composer.json +++ b/composer.json @@ -9,13 +9,16 @@ "license": "MIT", "require": { "php": "^7.2.5", + "ext-fileinfo": "*", "ext-json": "^1.6", + "barryvdh/laravel-dompdf": "^0.9.0", "fideloper/proxy": "^4.2", "fruitcake/laravel-cors": "^1.0", "guzzlehttp/guzzle": "^6.3", "intervention/image": "^2.5", "laravel/framework": "^7.0", "laravel/tinker": "^2.0", + "rinvex/countries": "^6.1", "spatie/laravel-activitylog": "^3.14", "spatie/laravel-permission": "^3.17", "tymon/jwt-auth": "^1.0" diff --git a/config/app.php b/config/app.php index deade8b0..a8881019 100644 --- a/config/app.php +++ b/config/app.php @@ -67,7 +67,7 @@ return [ | */ - 'timezone' => 'UTC', + 'timezone' => 'Asia/Kuala_Lumpur', /* |-------------------------------------------------------------------------- @@ -177,6 +177,7 @@ return [ // Third Parties Spatie\Permission\PermissionServiceProvider::class, + Barryvdh\DomPDF\ServiceProvider::class, ], /* @@ -228,6 +229,7 @@ return [ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, + 'PDF' => Barryvdh\DomPDF\Facade::class, ], diff --git a/config/filesystems.php b/config/filesystems.php index 94c81126..3094b721 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -55,6 +55,13 @@ return [ 'visibility' => 'public', ], + 'documents' => [ + 'driver' => 'local', + 'root' => storage_path('app/documents'), + 'url' => env('APP_URL').'/storage', + 'visibility' => 'private', + ], + 's3' => [ 'driver' => 's3', 'key' => env('AWS_ACCESS_KEY_ID'), diff --git a/config/jwt.php b/config/jwt.php new file mode 100644 index 00000000..e1af3ccc --- /dev/null +++ b/config/jwt.php @@ -0,0 +1,302 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +return [ + + /* + |-------------------------------------------------------------------------- + | JWT Authentication Secret + |-------------------------------------------------------------------------- + | + | Don't forget to set this in your .env file, as it will be used to sign + | your tokens. A helper command is provided for this: + | `php artisan jwt:secret` + | + | Note: This will be used for Symmetric algorithms only (HMAC), + | since RSA and ECDSA use a private/public key combo (See below). + | + */ + + 'secret' => env('JWT_SECRET'), + + /* + |-------------------------------------------------------------------------- + | JWT Authentication Keys + |-------------------------------------------------------------------------- + | + | The algorithm you are using, will determine whether your tokens are + | signed with a random string (defined in `JWT_SECRET`) or using the + | following public & private keys. + | + | Symmetric Algorithms: + | HS256, HS384 & HS512 will use `JWT_SECRET`. + | + | Asymmetric Algorithms: + | RS256, RS384 & RS512 / ES256, ES384 & ES512 will use the keys below. + | + */ + + 'keys' => [ + + /* + |-------------------------------------------------------------------------- + | Public Key + |-------------------------------------------------------------------------- + | + | A path or resource to your public key. + | + | E.g. 'file://path/to/public/key' + | + */ + + 'public' => env('JWT_PUBLIC_KEY'), + + /* + |-------------------------------------------------------------------------- + | Private Key + |-------------------------------------------------------------------------- + | + | A path or resource to your private key. + | + | E.g. 'file://path/to/private/key' + | + */ + + 'private' => env('JWT_PRIVATE_KEY'), + + /* + |-------------------------------------------------------------------------- + | Passphrase + |-------------------------------------------------------------------------- + | + | The passphrase for your private key. Can be null if none set. + | + */ + + 'passphrase' => env('JWT_PASSPHRASE'), + + ], + + /* + |-------------------------------------------------------------------------- + | JWT time to live + |-------------------------------------------------------------------------- + | + | Specify the length of time (in minutes) that the token will be valid for. + | Defaults to 1 hour. + | + | You can also set this to null, to yield a never expiring token. + | Some people may want this behaviour for e.g. a mobile app. + | This is not particularly recommended, so make sure you have appropriate + | systems in place to revoke the token if necessary. + | Notice: If you set this to null you should remove 'exp' element from 'required_claims' list. + | + */ + + 'ttl' => env('JWT_TTL', 60), + + /* + |-------------------------------------------------------------------------- + | Refresh time to live + |-------------------------------------------------------------------------- + | + | Specify the length of time (in minutes) that the token can be refreshed + | within. I.E. The user can refresh their token within a 2 week window of + | the original token being created until they must re-authenticate. + | Defaults to 2 weeks. + | + | You can also set this to null, to yield an infinite refresh time. + | Some may want this instead of never expiring tokens for e.g. a mobile app. + | This is not particularly recommended, so make sure you have appropriate + | systems in place to revoke the token if necessary. + | + */ + + 'refresh_ttl' => env('JWT_REFRESH_TTL', 20160), + + /* + |-------------------------------------------------------------------------- + | JWT hashing algorithm + |-------------------------------------------------------------------------- + | + | Specify the hashing algorithm that will be used to sign the token. + | + | See here: https://github.com/namshi/jose/tree/master/src/Namshi/JOSE/Signer/OpenSSL + | for possible values. + | + */ + + 'algo' => env('JWT_ALGO', 'HS256'), + + /* + |-------------------------------------------------------------------------- + | Required Claims + |-------------------------------------------------------------------------- + | + | Specify the required claims that must exist in any token. + | A TokenInvalidException will be thrown if any of these claims are not + | present in the payload. + | + */ + + 'required_claims' => [ + 'iss', + 'iat', + 'exp', + 'nbf', + 'sub', + 'jti', + ], + + /* + |-------------------------------------------------------------------------- + | Persistent Claims + |-------------------------------------------------------------------------- + | + | Specify the claim keys to be persisted when refreshing a token. + | `sub` and `iat` will automatically be persisted, in + | addition to the these claims. + | + | Note: If a claim does not exist then it will be ignored. + | + */ + + 'persistent_claims' => [ + 'name', 'email', 'type', 'company_id', 'status', 'verification'], + + /* + |-------------------------------------------------------------------------- + | Lock Subject + |-------------------------------------------------------------------------- + | + | This will determine whether a `prv` claim is automatically added to + | the token. The purpose of this is to ensure that if you have multiple + | authentication models e.g. `App\User` & `App\OtherPerson`, then we + | should prevent one authentication request from impersonating another, + | if 2 tokens happen to have the same id across the 2 different models. + | + | Under specific circumstances, you may want to disable this behaviour + | e.g. if you only have one authentication model, then you would save + | a little on token size. + | + */ + + 'lock_subject' => true, + + /* + |-------------------------------------------------------------------------- + | Leeway + |-------------------------------------------------------------------------- + | + | This property gives the jwt timestamp claims some "leeway". + | Meaning that if you have any unavoidable slight clock skew on + | any of your servers then this will afford you some level of cushioning. + | + | This applies to the claims `iat`, `nbf` and `exp`. + | + | Specify in seconds - only if you know you need it. + | + */ + + 'leeway' => env('JWT_LEEWAY', 0), + + /* + |-------------------------------------------------------------------------- + | Blacklist Enabled + |-------------------------------------------------------------------------- + | + | In order to invalidate tokens, you must have the blacklist enabled. + | If you do not want or need this functionality, then set this to false. + | + */ + + 'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true), + + /* + | ------------------------------------------------------------------------- + | Blacklist Grace Period + | ------------------------------------------------------------------------- + | + | When multiple concurrent requests are made with the same JWT, + | it is possible that some of them fail, due to token regeneration + | on every request. + | + | Set grace period in seconds to prevent parallel request failure. + | + */ + + 'blacklist_grace_period' => env('JWT_BLACKLIST_GRACE_PERIOD', 0), + + /* + |-------------------------------------------------------------------------- + | Cookies encryption + |-------------------------------------------------------------------------- + | + | By default Laravel encrypt cookies for security reason. + | If you decide to not decrypt cookies, you will have to configure Laravel + | to not encrypt your cookie token by adding its name into the $except + | array available in the middleware "EncryptCookies" provided by Laravel. + | see https://laravel.com/docs/master/responses#cookies-and-encryption + | for details. + | + | Set it to true if you want to decrypt cookies. + | + */ + + 'decrypt_cookies' => false, + + /* + |-------------------------------------------------------------------------- + | Providers + |-------------------------------------------------------------------------- + | + | Specify the various providers used throughout the package. + | + */ + + 'providers' => [ + + /* + |-------------------------------------------------------------------------- + | JWT Provider + |-------------------------------------------------------------------------- + | + | Specify the provider that is used to create and decode the tokens. + | + */ + + 'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class, + + /* + |-------------------------------------------------------------------------- + | Authentication Provider + |-------------------------------------------------------------------------- + | + | Specify the provider that is used to authenticate users. + | + */ + + 'auth' => Tymon\JWTAuth\Providers\Auth\Illuminate::class, + + /* + |-------------------------------------------------------------------------- + | Storage Provider + |-------------------------------------------------------------------------- + | + | Specify the provider that is used to store tokens in the blacklist. + | + */ + + 'storage' => Tymon\JWTAuth\Providers\Storage\Illuminate::class, + + ], + +]; diff --git a/database/migrations/2013_06_01_000006_create_permission_tables.php b/database/migrations/2013_06_01_000006_create_permission_tables.php index ff39ab91..7859b785 100644 --- a/database/migrations/2013_06_01_000006_create_permission_tables.php +++ b/database/migrations/2013_06_01_000006_create_permission_tables.php @@ -1,5 +1,6 @@ unsignedBigInteger('permission_id'); + $table->foreignId('permission_id'); $table->string('model_type'); - $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->foreignId($columnNames['model_morph_key']); $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index'); $table->foreign('permission_id') @@ -52,10 +54,10 @@ class CreatePermissionTables extends Migration }); Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) { - $table->unsignedBigInteger('role_id'); + $table->foreignId('role_id'); $table->string('model_type'); - $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->foreignId($columnNames['model_morph_key']); $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index'); $table->foreign('role_id') @@ -68,8 +70,8 @@ class CreatePermissionTables extends Migration }); Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) { - $table->unsignedBigInteger('permission_id'); - $table->unsignedBigInteger('role_id'); + $table->foreignId('permission_id'); + $table->foreignId('role_id'); $table->foreign('permission_id') ->references('id') @@ -93,6 +95,7 @@ class CreatePermissionTables extends Migration * Reverse the migrations. * * @return void + * @throws Exception */ public function down() { diff --git a/database/migrations/2014_10_11_000000_create_users_table.php b/database/migrations/2014_10_11_000000_create_users_table.php index 9fda5b3e..3ac34a63 100644 --- a/database/migrations/2014_10_11_000000_create_users_table.php +++ b/database/migrations/2014_10_11_000000_create_users_table.php @@ -1,6 +1,7 @@ string('name'); $table->string('email')->unique(); $table->string('password'); - $table->integer('type')->nullable()->default(1); - $table->integer('status')->nullable()->default(1); + $table->integer('type')->default(RoleTypes::USER); + $table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION); $table->rememberToken(); $table->timestamp('active_at')->nullable(); - $table->timestamps(); $table->softDeletes(); + $table->timestamps(); }); } diff --git a/database/migrations/2014_10_11_100009_create_countries_table.php b/database/migrations/2014_10_11_100009_create_countries_table.php index c4946e70..11069e71 100644 --- a/database/migrations/2014_10_11_100009_create_countries_table.php +++ b/database/migrations/2014_10_11_100009_create_countries_table.php @@ -15,11 +15,11 @@ class CreateCountriesTable extends Migration { Schema::create('countries', function (Blueprint $table) { $table->id(); - $table->string('name')->nullable(); - $table->string('short_code')->nullable(); - $table->string('phone_code')->nullable(); - $table->timestamps(); + $table->string('name')->unique(); + $table->string('short_code')->unique(); + $table->string('phone_code')->unique(); $table->softDeletes(); + $table->timestamps(); }); } diff --git a/database/migrations/2014_10_11_100010_create_currencies_table.php b/database/migrations/2014_10_11_100010_create_currencies_table.php index 62e92cd6..b550c86b 100644 --- a/database/migrations/2014_10_11_100010_create_currencies_table.php +++ b/database/migrations/2014_10_11_100010_create_currencies_table.php @@ -15,13 +15,14 @@ class CreateCurrenciesTable extends Migration { Schema::create('currencies', function (Blueprint $table) { $table->id(); - $table->bigInteger('country_id')->unsigned()->nullable(); - $table->foreign('country_id')->references('id')->on('countries')->onDelete('cascade'); - $table->string('name')->nullable(); - $table->string('short_code')->nullable(); + $table->foreignId('country_id')->unsigned(); + $table->string('name'); + $table->string('short_code'); $table->string('symbol')->nullable(); - $table->timestamps(); $table->softDeletes(); + $table->timestamps(); + + $table->foreign('country_id')->references('id')->on('countries'); }); } diff --git a/database/migrations/2014_10_11_100011_create_currency_logs_table.php b/database/migrations/2014_10_11_100011_create_currency_logs_table.php index cd3ebb34..d356d5b5 100644 --- a/database/migrations/2014_10_11_100011_create_currency_logs_table.php +++ b/database/migrations/2014_10_11_100011_create_currency_logs_table.php @@ -15,12 +15,13 @@ class CreateCurrencyLogsTable extends Migration { Schema::create('currency_logs', function (Blueprint $table) { $table->id(); - $table->bigInteger('currency_id')->unsigned()->nullable(); - $table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade'); - $table->decimal('selling', 20, 5)->nullable(); - $table->bigInteger('created_by')->unsigned()->nullable(); - $table->foreign('created_by')->references('id')->on('users')->onDelete('cascade'); + $table->foreignId('currency_id')->unsigned(); + $table->foreignId('created_by')->unsigned(); + $table->softDeletes(); $table->timestamps(); + + $table->foreign('created_by')->references('id')->on('users'); + $table->foreign('currency_id')->references('id')->on('currencies'); }); } diff --git a/database/migrations/2014_10_11_100012_create_states_table.php b/database/migrations/2014_10_11_100012_create_states_table.php index e3c89c1d..63c077bf 100644 --- a/database/migrations/2014_10_11_100012_create_states_table.php +++ b/database/migrations/2014_10_11_100012_create_states_table.php @@ -1,5 +1,6 @@ id(); - $table->bigInteger('country_id')->unsigned()->nullable(); - $table->foreign('country_id')->references('id')->on('countries')->onDelete('cascade'); - $table->string('name')->nullable(); - $table->integer('status')->nullable(); - $table->timestamps(); + $table->foreignId('country_id')->unsigned(); + $table->string('name'); + $table->integer('status')->default(ApprovalStatus::APPROVED); $table->softDeletes(); + $table->timestamps(); + + $table->foreign('country_id')->references('id')->on('countries'); }); } diff --git a/database/migrations/2014_10_11_100013_create_districts_table.php b/database/migrations/2014_10_11_100013_create_districts_table.php index 42da9530..a5d1f51c 100644 --- a/database/migrations/2014_10_11_100013_create_districts_table.php +++ b/database/migrations/2014_10_11_100013_create_districts_table.php @@ -1,5 +1,6 @@ id(); - $table->bigInteger('country_id')->unsigned()->nullable(); - $table->foreign('country_id')->references('id')->on('countries')->onDelete('cascade'); - $table->bigInteger('state_id')->unsigned()->nullable(); - $table->foreign('state_id')->references('id')->on('states')->onDelete('cascade'); - $table->string('name')->nullable(); - $table->text('postcode')->nullable(); - $table->integer('status')->nullable(); - $table->timestamps(); + $table->foreignId('country_id')->unsigned(); + $table->foreignId('state_id')->unsigned(); + $table->string('name'); + $table->text('postcode'); + $table->integer('status')->default(ApprovalStatus::APPROVED); $table->softDeletes(); + $table->timestamps(); + + $table->foreign('country_id')->references('id')->on('countries'); + $table->foreign('state_id')->references('id')->on('states'); }); } diff --git a/database/migrations/2020_07_30_022600_create_password_resets_table.php b/database/migrations/2020_07_30_022600_create_password_resets_table.php index f465e56d..7d75d3c4 100644 --- a/database/migrations/2020_07_30_022600_create_password_resets_table.php +++ b/database/migrations/2020_07_30_022600_create_password_resets_table.php @@ -15,7 +15,7 @@ class CreatePasswordResetsTable extends Migration { Schema::create('password_resets', function (Blueprint $table) { $table->id(); - $table->bigInteger('user_id')->unsigned(); + $table->foreignId('user_id')->unsigned(); $table->string('token'); $table->boolean('is_expired')->default(true); $table->boolean('is_complete')->default(false); diff --git a/database/migrations/2020_07_30_023042_create_activity_log_table.php b/database/migrations/2020_07_30_023042_create_activity_log_table.php index 107cf045..2f49bef0 100644 --- a/database/migrations/2020_07_30_023042_create_activity_log_table.php +++ b/database/migrations/2020_07_30_023042_create_activity_log_table.php @@ -17,9 +17,9 @@ class CreateActivityLogTable extends Migration $table->id(); $table->string('log_name')->nullable(); $table->text('description'); - $table->unsignedBigInteger('subject_id')->nullable(); + $table->foreignId('subject_id')->nullable(); $table->string('subject_type')->nullable(); - $table->unsignedBigInteger('causer_id')->nullable(); + $table->foreignId('causer_id')->nullable(); $table->string('causer_type')->nullable(); $table->text('properties')->nullable(); $table->timestamps(); diff --git a/database/migrations/2020_10_22_071102_create_companies_table.php b/database/migrations/2020_10_22_071102_create_companies_table.php index de5f45ab..cb6747e5 100644 --- a/database/migrations/2020_10_22_071102_create_companies_table.php +++ b/database/migrations/2020_10_22_071102_create_companies_table.php @@ -1,6 +1,7 @@ id(); $table->string('name'); $table->string('reference'); - $table->integer('type'); + $table->integer('type')->default(CompanyType::COMPANY_BUSINESS); $table->integer('business_type')->default(BusinessType::IMPORTER); - $table->integer('status')->default(ApprovalStatus::ACTIVE); - $table->timestamps(); + $table->integer('status')->default(ApprovalStatus::PENDING_SUBMISSION); $table->softDeletes(); + $table->timestamps(); }); } diff --git a/database/migrations/2020_10_22_071120_create_contacts_table.php b/database/migrations/2020_10_22_071120_create_contacts_table.php index 5a685c90..c8e70331 100644 --- a/database/migrations/2020_10_22_071120_create_contacts_table.php +++ b/database/migrations/2020_10_22_071120_create_contacts_table.php @@ -15,15 +15,17 @@ class CreateContactsTable extends Migration { Schema::create('contacts', function (Blueprint $table) { $table->id(); - $table->bigInteger('country_id')->unsigned()->nullable(); - $table->foreign('country_id')->references('id')->on('countries')->onDelete('cascade'); - $table->bigInteger('company_id')->unsigned()->nullable(); - $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); - $table->string('reference')->nullable(); + $table->foreignId('company_id')->unsigned(); + $table->foreignId('country_id')->unsigned(); + $table->string('reference'); $table->string('phone')->nullable(); $table->string('email')->nullable(); $table->string('wechat_id')->nullable(); + $table->softDeletes(); $table->timestamps(); + + $table->foreign('country_id')->references('id')->on('countries'); + $table->foreign('company_id')->references('id')->on('companies'); }); } diff --git a/database/migrations/2020_10_22_071121_create_addresses_table.php b/database/migrations/2020_10_22_071121_create_addresses_table.php index 8c44b0f8..03583080 100644 --- a/database/migrations/2020_10_22_071121_create_addresses_table.php +++ b/database/migrations/2020_10_22_071121_create_addresses_table.php @@ -16,20 +16,21 @@ class CreateAddressesTable extends Migration { Schema::create('addresses', function (Blueprint $table) { $table->id(); - $table->bigInteger('country_id')->unsigned()->nullable(); - $table->foreign('country_id')->references('id')->on('countries')->onDelete('cascade'); - $table->bigInteger('company_id')->unsigned()->nullable(); - $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); - $table->bigInteger('state_id')->unsigned()->nullable(); - $table->foreign('state_id')->references('id')->on('states')->onDelete('cascade'); - $table->bigInteger('district_id')->unsigned()->nullable(); - $table->foreign('district_id')->references('id')->on('districts')->onDelete('cascade'); - $table->string('postcode')->nullable(); - $table->string('street_one')->nullable(); + $table->foreignId('company_id')->unsigned(); + $table->foreignId('country_id')->unsigned(); + $table->foreignId('state_id')->unsigned(); + $table->foreignId('district_id')->unsigned(); + $table->string('postcode'); + $table->string('street_one'); $table->string('street_two')->nullable(); - $table->integer('billing_type')->nullable(); - $table->timestamps(); + $table->integer('billing')->default(true); $table->softDeletes(); + $table->timestamps(); + + $table->foreign('country_id')->references('id')->on('countries'); + $table->foreign('company_id')->references('id')->on('companies'); + $table->foreign('state_id')->references('id')->on('states'); + $table->foreign('district_id')->references('id')->on('districts'); }); } diff --git a/database/migrations/2020_10_22_071150_create_company_employees_table.php b/database/migrations/2020_10_22_071150_create_employees_table.php similarity index 61% rename from database/migrations/2020_10_22_071150_create_company_employees_table.php rename to database/migrations/2020_10_22_071150_create_employees_table.php index b8fb2b48..916692f8 100644 --- a/database/migrations/2020_10_22_071150_create_company_employees_table.php +++ b/database/migrations/2020_10_22_071150_create_employees_table.php @@ -1,10 +1,11 @@ bigInteger('company_id')->unsigned(); - $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); - $table->bigInteger('user_id')->unsigned(); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + Schema::create('employees', function (Blueprint $table) { + $table->foreignId('company_id')->unsigned(); + $table->foreignId('user_id')->unsigned(); + $table->integer('status')->default(ApprovalStatus::APPROVED); + $table->primary(['company_id', 'user_id']); + $table->foreign('user_id')->references('id')->on('users'); + $table->foreign('company_id')->references('id')->on('companies'); }); } diff --git a/database/migrations/2020_11_03_122319_create_documents_table.php b/database/migrations/2020_11_03_122319_create_documents_table.php index dbe9c684..618a3b75 100644 --- a/database/migrations/2020_11_03_122319_create_documents_table.php +++ b/database/migrations/2020_11_03_122319_create_documents_table.php @@ -1,5 +1,6 @@ id(); - $table->integer('owner_id')->nullable(); - $table->integer('owner_type')->nullable(); - $table->string('document_type')->nullable(); - $table->string('reference')->nullable(); - $table->integer('status')->nullable(); - $table->bigInteger('approved_by')->unsigned()->nullable(); - $table->foreign('approved_by')->references('id')->on('users')->onDelete('cascade'); + $table->morphs('owner'); + $table->string('document_type'); + $table->string('reference'); + $table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION); $table->timestamp('issued_date')->nullable(); $table->timestamp('expired_date')->nullable(); - $table->timestamp('approved_date')->nullable(); - $table->timestamps(); + $table->foreignId('approver')->nullable()->unsigned(); + $table->timestamp('approval_date')->nullable(); $table->softDeletes(); + $table->timestamps(); + + $table->foreign('approver')->references('id')->on('users'); }); } diff --git a/database/migrations/2020_11_03_122358_create_files_table.php b/database/migrations/2020_11_03_122358_create_files_table.php index 483f0f4e..3ee1c9fe 100644 --- a/database/migrations/2020_11_03_122358_create_files_table.php +++ b/database/migrations/2020_11_03_122358_create_files_table.php @@ -1,5 +1,6 @@ id(); - $table->bigInteger('document_id')->unsigned(); - $table->foreign('document_id')->references('id')->on('documents')->onDelete('cascade'); - $table->text('file')->nullable(); - $table->string('file_type')->nullable(); - $table->timestamps(); + $table->foreignId('document_id')->unsigned(); + $table->text('file'); + $table->string('file_type')->default(FileType::JPEG); $table->softDeletes(); + $table->timestamps(); + + $table->foreign('document_id')->references('id')->on('documents'); }); } diff --git a/database/migrations/2020_11_11_065757_create_segments_table.php b/database/migrations/2020_11_11_065757_create_segments_table.php index 4bfa3f05..2d524073 100644 --- a/database/migrations/2020_11_11_065757_create_segments_table.php +++ b/database/migrations/2020_11_11_065757_create_segments_table.php @@ -1,5 +1,7 @@ id(); - $table->string('name')->nullable(); - $table->timestamps(); + $table->string('name'); + $table->integer('type')->default(SegmentConstants::STANDARD_SEGMENT); + $table->integer('status')->default(ApprovalStatus::APPROVED); $table->softDeletes(); + $table->timestamps(); }); } diff --git a/database/migrations/2020_11_11_065838_create_segment_constants_table.php b/database/migrations/2020_11_11_065838_create_segment_constants_table.php index a64fef62..85b8dc5e 100644 --- a/database/migrations/2020_11_11_065838_create_segment_constants_table.php +++ b/database/migrations/2020_11_11_065838_create_segment_constants_table.php @@ -15,14 +15,14 @@ class CreateSegmentConstantsTable extends Migration { Schema::create('segment_constants', function (Blueprint $table) { $table->id(); - $table->bigInteger('segment_id')->unsigned()->nullable(); - $table->foreign('segment_id')->references('id')->on('segments')->onDelete('cascade'); - $table->string('name')->nullable(); - $table->string('reference')->nullable(); - $table->text('detail')->nullable(); - $table->timestamps(); - $table->integer('type')->nullable(); + $table->foreignId('segment_id')->unsigned(); + $table->string('name'); + $table->string('reference'); + $table->json('detail'); $table->softDeletes(); + $table->timestamps(); + + $table->foreign('segment_id')->references('id')->on('segments'); }); } diff --git a/database/migrations/2020_11_11_065851_create_segment_companies_table.php b/database/migrations/2020_11_11_065851_create_segment_companies_table.php index f2a55572..676cc155 100644 --- a/database/migrations/2020_11_11_065851_create_segment_companies_table.php +++ b/database/migrations/2020_11_11_065851_create_segment_companies_table.php @@ -13,12 +13,15 @@ class CreateSegmentCompaniesTable extends Migration */ public function up() { - Schema::create('segment_company', function (Blueprint $table) { - $table->bigInteger('segment_id')->unsigned(); - $table->foreign('segment_id')->references('id')->on('segments')->onDelete('cascade'); - $table->bigInteger('company_id')->unsigned(); - $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); + Schema::create('segment_companies', function (Blueprint $table) { + $table->foreignId('segment_id')->unsigned(); + $table->foreignId('company_id')->unsigned(); + $table->softDeletes(); + $table->timestamps(); + $table->primary(['segment_id', 'company_id']); + $table->foreign('segment_id')->references('id')->on('segments'); + $table->foreign('company_id')->references('id')->on('companies'); }); } diff --git a/database/migrations/2020_11_24_062534_create_company_banks_table.php b/database/migrations/2020_11_24_062534_create_banks_table.php similarity index 55% rename from database/migrations/2020_11_24_062534_create_company_banks_table.php rename to database/migrations/2020_11_24_062534_create_banks_table.php index 5ab6788a..ebd91e1a 100644 --- a/database/migrations/2020_11_24_062534_create_company_banks_table.php +++ b/database/migrations/2020_11_24_062534_create_banks_table.php @@ -1,10 +1,12 @@ id(); - $table->bigInteger('country_id')->unsigned()->nullable(); - $table->foreign('country_id')->references('id')->on('countries')->onDelete('cascade'); - $table->bigInteger('company_id')->unsigned()->nullable(); - $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); + $table->foreignId('company_id')->unsigned(); + $table->string('reference')->nullable(); $table->string('bank_name'); $table->string('holder_name'); $table->string('account_no'); - $table->integer('type'); - $table->integer('default'); - $table->integer('status')->default(1); - $table->timestamps(); + $table->integer('type')->default(BankAccountType::EXTERNAL); + $table->integer('default')->default(false); + $table->integer('status')->default(ApprovalStatus::APPROVED); + $table->foreignId('country_id')->unsigned(); $table->softDeletes(); + $table->timestamps(); + + $table->foreign('country_id')->references('id')->on('countries'); + $table->foreign('company_id')->references('id')->on('companies'); }); } diff --git a/database/migrations/2020_11_28_060757_create_service_types_table.php b/database/migrations/2020_11_28_060757_create_service_types_table.php new file mode 100644 index 00000000..b9e31227 --- /dev/null +++ b/database/migrations/2020_11_28_060757_create_service_types_table.php @@ -0,0 +1,36 @@ +id(); + $table->string('name'); + $table->string('status')->default(ApprovalStatus::APPROVED); + $table->softDeletes(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('service_types'); + } +} diff --git a/database/migrations/2020_12_02_060758_create_bookings_table.php b/database/migrations/2020_11_28_060758_create_bookings_table.php similarity index 50% rename from database/migrations/2020_12_02_060758_create_bookings_table.php rename to database/migrations/2020_11_28_060758_create_bookings_table.php index 4b813510..115af43b 100644 --- a/database/migrations/2020_12_02_060758_create_bookings_table.php +++ b/database/migrations/2020_11_28_060758_create_bookings_table.php @@ -1,5 +1,6 @@ id(); - $table->bigInteger('company_id')->unsigned()->nullable(); - $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); - $table->bigInteger('transferable_bank_id')->unsigned()->nullable(); - $table->foreign('transferable_bank_id')->references('id')->on('company_banks')->onDelete('cascade'); - $table->string('marking'); - $table->string('reference'); - $table->float('fix_amount', 20, 5)->nullable(); - $table->bigInteger('fix_currency_id')->unsigned()->nullable(); - $table->foreign('fix_currency_id')->references('id')->on('currencies')->onDelete('cascade'); - $table->bigInteger('convertible_currency_id')->unsigned()->nullable(); - $table->foreign('convertible_currency_id')->references('id')->on('currencies')->onDelete('cascade'); - $table->bigInteger('conversion_currency_id')->unsigned()->nullable(); - $table->foreign('conversion_currency_id')->references('id')->on('currencies')->onDelete('cascade'); - $table->integer('status')->default(1); - $table->timestamps(); + $table->foreignId('company_id')->unsigned(); + $table->string('marking')->unique(); + $table->foreignId('service_id')->unsigned(); + $table->foreignId('bank_id')->unsigned(); + $table->float('fix_amount', 20, 5); + $table->foreignId('fix_currency_id')->unsigned(); + $table->foreignId('convertible_currency_id')->unsigned(); + $table->foreignId('conversion_currency_id')->unsigned(); + $table->integer('status')->default(ApprovalStatus::APPROVED); $table->softDeletes(); + $table->timestamps(); + + $table->foreign('company_id')->references('id')->on('companies'); + $table->foreign('service_id')->references('id')->on('service_types'); + $table->foreign('bank_id')->references('id')->on('banks'); + $table->foreign('fix_currency_id')->references('id')->on('currencies'); + $table->foreign('convertible_currency_id')->references('id')->on('currencies'); + $table->foreign('conversion_currency_id')->references('id')->on('currencies'); }); } diff --git a/database/migrations/2020_11_29_212614_create_companies_wallet_table.php b/database/migrations/2020_11_29_212614_create_companies_wallet_table.php index c55a9267..7a7ade13 100644 --- a/database/migrations/2020_11_29_212614_create_companies_wallet_table.php +++ b/database/migrations/2020_11_29_212614_create_companies_wallet_table.php @@ -16,14 +16,15 @@ class CreateCompaniesWalletTable extends Migration Schema::create('wallets', function (Blueprint $table) { $table->id(); - $table->bigInteger('company_id')->unsigned(); + $table->foreignId('company_id')->unsigned(); $table->string('code'); - $table->bigInteger('currency_id')->unsigned(); + $table->foreignId('currency_id')->unsigned(); $table->decimal('amount', 20, 5)->default(0.00); + $table->softDeletes(); $table->timestamps(); - $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); - $table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade'); + $table->foreign('company_id')->references('id')->on('companies'); + $table->foreign('currency_id')->references('id')->on('currencies'); }); } diff --git a/database/migrations/2020_12_01_102314_create_transaction_table.php b/database/migrations/2020_12_01_102314_create_transaction_table.php deleted file mode 100644 index c66a6fbe..00000000 --- a/database/migrations/2020_12_01_102314_create_transaction_table.php +++ /dev/null @@ -1,63 +0,0 @@ -id(); - $table->string('trans_type1'); - $table->string('trans_type2'); - $table->bigInteger('bill_no')->unsigned(); - $table->decimal('amount', 14, 5)->default(0.00); - $table->decimal('original_amount', 14, 5)->default(0.00); - $table->bigInteger('currency_id')->unsigned(); - $table->bigInteger('original_currency_id')->unsigned(); - $table->decimal('currency_rate', 14, 5)->default(0.00); - $table->date('dt_transaction'); - $table->integer('status'); - $table->bigInteger('booking_id')->unsigned(); - $table->bigInteger('company_id')->unsigned(); - $table->timestamps(); - $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); - $table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade'); - $table->foreign('original_currency_id')->references('id')->on('currencies')->onDelete('cascade'); - - }); - - Schema::create('transaction_detail', function (Blueprint $table) { - $table->id(); - $table->string('trans_type1'); - $table->string('trans_type2'); - $table->bigInteger('transaction_id')->unsigned(); - $table->string('product_code'); - $table->string('product_name'); - $table->integer('qty')->default(0); - $table->decimal('price', 14, 5)->default(0.00); - $table->decimal('amount', 14, 5)->default(0.00); - $table->timestamps(); - $table->foreign('transaction_id')->references('id')->on('transaction')->onDelete('cascade'); - - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('transaction'); - Schema::dropIfExists('transaction_detail'); - } -} diff --git a/database/migrations/2020_12_01_102314_create_transactions_table.php b/database/migrations/2020_12_01_102314_create_transactions_table.php new file mode 100644 index 00000000..a07bf413 --- /dev/null +++ b/database/migrations/2020_12_01_102314_create_transactions_table.php @@ -0,0 +1,59 @@ +id(); + $table->foreignId('booking_id')->unsigned(); + $table->string('type')->default(TransactionType::PAYMENT); + $table->foreignId('issuer')->unsigned(); + $table->foreignId('receiver')->unsigned(); + $table->foreignId('recipient_bank_account_id')->unsigned(); + $table->string('payment_method')->nullable(); + $table->string('payment_reference')->nullable(); + $table->string('bill_no')->unique(); + $table->decimal('amount', 14, 5)->default(0.00); + $table->decimal('original_amount', 14, 5)->default(0.00); + $table->foreignId('currency_id')->unsigned(); + $table->foreignId('original_currency_id')->unsigned(); + $table->decimal('currency_rate', 14, 5)->default(0.00); + $table->decimal('tax', 14, 5)->default(0.00); + $table->decimal('service_charge', 14, 5)->default(0.00); + $table->timestamp('expires_on')->nullable(); + $table->integer('status')->default(ApprovalStatus::PENDING_SUBMISSION); + $table->softDeletes(); + $table->timestamps(); + + $table->foreign('booking_id')->references('id')->on('bookings'); + $table->foreign('currency_id')->references('id')->on('currencies'); + $table->foreign('issuer')->references('id')->on('companies'); + $table->foreign('receiver')->references('id')->on('companies'); + $table->foreign('recipient_bank_account_id')->references('id')->on('banks'); + $table->foreign('original_currency_id')->references('id')->on('currencies'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('transaction'); + } +} diff --git a/database/migrations/2020_12_01_102315_create_transaction_details_table.php b/database/migrations/2020_12_01_102315_create_transaction_details_table.php new file mode 100644 index 00000000..04f1ee83 --- /dev/null +++ b/database/migrations/2020_12_01_102315_create_transaction_details_table.php @@ -0,0 +1,41 @@ +id(); + $table->foreignId('transaction_id')->unsigned(); + $table->string('product_code'); + $table->string('product_name'); + $table->integer('quantity')->default(0); + $table->decimal('price', 14, 5)->default(0.00); + $table->decimal('amount', 14, 5)->default(0.00); + $table->softDeletes(); + $table->timestamps(); + + $table->foreign('transaction_id')->references('id')->on('transactions'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('transaction_detail'); + } +} diff --git a/database/migrations/2020_11_30_212314_create_wallet_transaction_table.php b/database/migrations/2020_12_01_212314_create_wallet_transaction_table.php similarity index 57% rename from database/migrations/2020_11_30_212314_create_wallet_transaction_table.php rename to database/migrations/2020_12_01_212314_create_wallet_transaction_table.php index 92818335..f87780c7 100644 --- a/database/migrations/2020_11_30_212314_create_wallet_transaction_table.php +++ b/database/migrations/2020_12_01_212314_create_wallet_transaction_table.php @@ -1,5 +1,7 @@ id(); - $table->bigInteger('wallet_id')->unsigned(); - $table->bigInteger('bill_no')->unsigned(); - $table->integer('trans_type'); + $table->foreignId('wallet_id')->unsigned(); + $table->foreignId('transaction_id')->unsigned()->nullable(); + $table->foreignId('bill_no')->unsigned(); + $table->integer('type')->default(TransactionType::PAYMENT); $table->decimal('amount', 14, 5)->default(0.00); - $table->bigInteger('currency_id')->unsigned(); + $table->foreignId('currency_id')->unsigned(); $table->decimal('original_amount', 14, 5)->default(0.00); - $table->bigInteger('original_currency_id')->unsigned(); + $table->foreignId('original_currency_id')->unsigned(); $table->decimal('currency_rate', 14, 5)->default(0.00); + $table->integer('status')->default(ApprovalStatus::PENDING_SUBMISSION); + $table->softDeletes(); $table->timestamps(); - $table->foreign('wallet_id')->references('id')->on('wallets')->onDelete('cascade'); - $table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade'); - $table->foreign('original_currency_id')->references('id')->on('currencies')->onDelete('cascade'); + $table->foreign('transaction_id')->references('id')->on('transactions'); + $table->foreign('wallet_id')->references('id')->on('wallets'); + $table->foreign('currency_id')->references('id')->on('currencies'); + $table->foreign('original_currency_id')->references('id')->on('currencies'); }); } diff --git a/database/migrations/2020_12_02_131122_create_receipt_table.php b/database/migrations/2020_12_02_131122_create_receipt_table.php deleted file mode 100644 index a0569b25..00000000 --- a/database/migrations/2020_12_02_131122_create_receipt_table.php +++ /dev/null @@ -1,62 +0,0 @@ -id(); - $table->string('trans_type1'); - $table->string('trans_type2'); - $table->bigInteger('bill_no')->unsigned(); - $table->decimal('amount', 14, 5)->default(0.00); - $table->decimal('original_amount', 14, 5)->default(0.00); - $table->bigInteger('currency_id')->unsigned(); - $table->bigInteger('original_currency_id')->unsigned(); - $table->decimal('currency_rate', 14, 5)->default(0.00); - $table->date('dt_transaction'); - $table->integer('status'); - $table->bigInteger('booking_id')->unsigned(); - $table->bigInteger('company_id')->unsigned(); - $table->timestamps(); - $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); - $table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade'); - $table->foreign('original_currency_id')->references('id')->on('currencies')->onDelete('cascade'); - - }); - - Schema::create('receipt_detail', function (Blueprint $table) { - $table->id(); - $table->string('trans_type1'); - $table->string('trans_type2'); - $table->bigInteger('receipt_id')->unsigned(); - $table->bigInteger('transaction_id')->unsigned(); - $table->decimal('price', 14, 5)->default(0.00); - $table->decimal('amount', 14, 5)->default(0.00); - $table->timestamps(); - $table->foreign('receipt_id')->references('id')->on('receipt')->onDelete('cascade'); - $table->foreign('transaction_id')->references('id')->on('transaction')->onDelete('cascade'); - - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('receipt'); - Schema::dropIfExists('receipt_detail'); - } -} diff --git a/database/migrations/2020_12_02_131122_create_receipts_table.php b/database/migrations/2020_12_02_131122_create_receipts_table.php new file mode 100644 index 00000000..16ec2684 --- /dev/null +++ b/database/migrations/2020_12_02_131122_create_receipts_table.php @@ -0,0 +1,50 @@ +id(); + $table->foreignId('transaction_id')->unsigned(); + $table->string('bill_no')->unique(); + $table->decimal('amount', 14, 5)->default(0.00); + $table->decimal('original_amount', 14, 5)->default(0.00); + $table->foreignId('currency_id')->unsigned(); + $table->foreignId('original_currency_id')->unsigned(); + $table->decimal('currency_rate', 14, 5)->default(0.00); + $table->decimal('tax', 14, 5)->default(0.00); + $table->decimal('service_charge', 14, 5)->default(0.00); + $table->timestamp('transaction_date')->useCurrent(); + $table->integer('status')->default(ApprovalStatus::COMPLETED); + $table->softDeletes(); + $table->timestamps(); + + $table->foreign('transaction_id')->references('id')->on('transactions'); + $table->foreign('currency_id')->references('id')->on('currencies'); + $table->foreign('original_currency_id')->references('id')->on('currencies'); + + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('receipt'); + } +} diff --git a/database/migrations/2020_12_02_131123_create_receipt_details_table.php b/database/migrations/2020_12_02_131123_create_receipt_details_table.php new file mode 100644 index 00000000..0a008293 --- /dev/null +++ b/database/migrations/2020_12_02_131123_create_receipt_details_table.php @@ -0,0 +1,38 @@ +id(); + $table->foreignId('receipt_id')->unsigned(); + $table->decimal('price', 14, 5)->default(0.00); + $table->decimal('amount', 14, 5)->default(0.00); + $table->timestamps(); + + $table->foreign('receipt_id')->references('id')->on('receipts'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('receipt_detail'); + } +} diff --git a/database/migrations/2020_12_28_133342_create_currency_rates_table.php b/database/migrations/2020_12_28_133342_create_currency_rates_table.php index 33d733b7..59cec832 100644 --- a/database/migrations/2020_12_28_133342_create_currency_rates_table.php +++ b/database/migrations/2020_12_28_133342_create_currency_rates_table.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Schema; class CreateCurrencyRatesTable extends Migration { + /** * Run the migrations. * @@ -16,12 +17,15 @@ class CreateCurrencyRatesTable extends Migration { Schema::create('currency_rates', function (Blueprint $table) { $table->id(); - $table->bigInteger('currency_id')->unsigned()->nullable(); - $table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade'); - $table->decimal('selling', 20, 5)->nullable(); + $table->foreignId('currency_id')->unsigned(); + $table->decimal('selling', 20, 5); $table->integer('payment_method_type')->default(PaymentMethodType::CASH); - $table->timestamps(); + $table->foreignId('service_id'); $table->softDeletes(); + $table->timestamps(); + + $table->foreign('currency_id')->references('id')->on('currencies'); + $table->foreign('service_id')->references('id')->on('service_types'); }); } diff --git a/database/migrations/2020_12_28_133406_create_currency_rate_logs_table.php b/database/migrations/2020_12_28_133406_create_currency_rate_logs_table.php index 45e1f19a..29128f5a 100644 --- a/database/migrations/2020_12_28_133406_create_currency_rate_logs_table.php +++ b/database/migrations/2020_12_28_133406_create_currency_rate_logs_table.php @@ -15,12 +15,13 @@ class CreateCurrencyRateLogsTable extends Migration { Schema::create('currency_rate_logs', function (Blueprint $table) { $table->id(); - $table->bigInteger('currency_rate_id')->unsigned()->nullable(); - $table->foreign('currency_rate_id')->references('id')->on('currency_rates')->onDelete('cascade'); - $table->decimal('selling', 20, 5)->nullable(); - $table->bigInteger('created_by')->unsigned()->nullable(); - $table->foreign('created_by')->references('id')->on('users')->onDelete('cascade'); + $table->foreignId('currency_rate_id')->unsigned(); + $table->decimal('selling', 20, 5); + $table->foreignId('created_by')->unsigned(); $table->timestamps(); + + $table->foreign('currency_rate_id')->references('id')->on('currency_rates'); + $table->foreign('created_by')->references('id')->on('users'); }); } diff --git a/database/seeds/AddressesTableSeeder.php b/database/seeds/AddressesTableSeeder.php deleted file mode 100644 index 2cefe328..00000000 --- a/database/seeds/AddressesTableSeeder.php +++ /dev/null @@ -1,18 +0,0 @@ -environment('local')) - factory(App\Models\Address::class, 30)->create(); - - } -} diff --git a/database/seeds/AdminUserTableSeeder.php b/database/seeds/AdminUserTableSeeder.php index 0eb00cba..17e3d1c7 100644 --- a/database/seeds/AdminUserTableSeeder.php +++ b/database/seeds/AdminUserTableSeeder.php @@ -1,7 +1,9 @@ insert([ [ - 'id' => 1, - 'name' => 'The One', - 'email' => 'admin@exchange.com', - 'password' => bcrypt('pass123'), - 'type' => 1, - 'status' => 1, - 'remember_token' => (string) Str::uuid(), - 'active_at' => date('Y-m-d H:i:s'), - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'name' => 'Shadow Admin', + 'email' => 'omair@cief-malaysia.com', + 'password' => bcrypt('123456abcabc'), + 'type' => RoleTypes::SHADOW_ADMIN, + 'status' => ApprovalStatus::APPROVED, ], [ - 'id' => 2, - 'name' => 'The Admin', - 'email' => 'admin2@exchange.com', - 'password' => bcrypt('pass123'), - 'type' => 1, - 'status' => 1, - 'remember_token' => (string) Str::uuid(), - 'active_at' => date('Y-m-d H:i:s'), - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'name' => 'Super Admin', + 'email' => 'pm@cief-malaysia.com', + 'password' => bcrypt('123456abcabc'), + 'type' => RoleTypes::SUPER_ADMIN, + 'status' => ApprovalStatus::APPROVED, + ], + [ + 'name' => 'Admin', + 'email' => 'admin@cief-malaysia.com', + 'password' => bcrypt('123456abcabc'), + 'type' => RoleTypes::ADMIN, + 'status' => ApprovalStatus::APPROVED, ] ]); } diff --git a/database/seeds/CompaniesTableSeeder.php b/database/seeds/CompaniesTableSeeder.php index 54a0a74b..5e665a9e 100644 --- a/database/seeds/CompaniesTableSeeder.php +++ b/database/seeds/CompaniesTableSeeder.php @@ -1,7 +1,11 @@ insert([ - [ - 'id' => 1, - 'name' => 'CIEF SDN BHD', - 'reference' => 'CIEF', - 'type' => 2, - 'business_type' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s') - ] - ]); + $company = new Company(); + $company->name = 'CIEF SDN BHD'; + $company->reference = 'CIEF'; + $company->type = CompanyType::COMPANY_BUSINESS; + $company->business_type = BusinessType::FREIGHT_FORWARDER; + $company->status = ApprovalStatus::APPROVED; + + $company->save(); + } } diff --git a/database/seeds/CompanyBanksTableSeeder.php b/database/seeds/CompanyBanksTableSeeder.php deleted file mode 100644 index 7e77f6be..00000000 --- a/database/seeds/CompanyBanksTableSeeder.php +++ /dev/null @@ -1,31 +0,0 @@ -insert([ - [ - 'id' => 1, - 'country_id' => 1, - 'company_id' => 1, - 'bank_name' => '12345678', - 'holder_name' => '12345678', - 'account_no' => '12345678', - 'type' => 1, - 'default' => 1, - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s') - ] - ]); - } -} diff --git a/database/seeds/CountriesTableSeeder.php b/database/seeds/CountriesTableSeeder.php index 655f16d1..ad7d1570 100644 --- a/database/seeds/CountriesTableSeeder.php +++ b/database/seeds/CountriesTableSeeder.php @@ -1,34 +1,38 @@ createsCountry = $createsCountry; + } + + /** * Run the database seeds. * * @return void + * @throws \App\Classes\Exceptions\MalformedRequestException */ public function run() { - DB::table('countries')->insert([ - [ - 'id' => 1, - 'name' => 'Malaysia', - 'short_code' => 'MY', - 'phone_code' => '60', - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), - ], - [ - 'id' => 2, - 'name' => 'China', - 'short_code' => 'CN', - 'phone_code' => '852', - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), - ] - ]); + + foreach (['my', 'cn'] as $code) { + $object = new CountryObject(country($code)); + $this->createsCountry->execute($object); + } + } } diff --git a/database/seeds/CurrenciesTableSeeder.php b/database/seeds/CurrenciesTableSeeder.php index bf87e811..22fc52d3 100644 --- a/database/seeds/CurrenciesTableSeeder.php +++ b/database/seeds/CurrenciesTableSeeder.php @@ -1,36 +1,47 @@ fetchesCountry = $fetchesCountry; + $this->createsCurrency = $createsCurrency; + } + + /** * Run the database seeds. * * @return void + * @throws \App\Classes\Exceptions\MalformedRequestException */ public function run() { - DB::table('currencies')->insert([ - [ - 'id' => 1, - 'country_id' => 1, - 'name' => 'Ringgit', - 'short_code' => 'MYR', - 'symbol' => 'RM', - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s') - ], - [ - 'id' => 2, - 'country_id' => 2, - 'name' => 'Renminbi', - 'short_code' => 'RMB', - 'symbol' => '¥', - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s') - ] - ]); + + foreach (['my', 'cn'] as $code) { + $country = country($code); + $object = new CurrencyObject($country->getCurrency()['iso_4217_name'], + $code === 'cn' ? 'RMB' : $country->getCurrency()['iso_4217_code'], + $code === 'my' ? 'RM' : ( $code === 'cn' ? '¥' : '' )); + + $this->createsCurrency->execute($this->fetchesCountry->execute(['name' => $country->getName()]), $object); + } + } } diff --git a/database/seeds/CurrencyRatesTableSeeder.php b/database/seeds/CurrencyRatesTableSeeder.php deleted file mode 100644 index 31202e35..00000000 --- a/database/seeds/CurrencyRatesTableSeeder.php +++ /dev/null @@ -1,47 +0,0 @@ -insert([ - [ - 'currency_id' => 1, - 'selling' => 1, - 'payment_method_type' => PaymentMethodType::CASH, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s') - ], - [ - 'currency_id' => 1, - 'selling' => 1.1, - 'payment_method_type' => PaymentMethodType::CHEQUE, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s') - ], - [ - 'currency_id' => 2, - 'selling' => 0.62, - 'payment_method_type' => PaymentMethodType::CASH, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s') - ], - [ - 'currency_id' => 2, - 'selling' => 0.70, - 'payment_method_type' => PaymentMethodType::CHEQUE, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s') - ] - ]); - } -} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index bcd12e9b..5f813ef1 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -1,6 +1,7 @@ call(CountriesTableSeeder::class); $this->call(CurrenciesTableSeeder::class); - $this->call(CurrencyRatesTableSeeder::class); $this->call(StatesTableSeeder::class); $this->call(DistrictsTableSeeder::class); @@ -25,8 +25,7 @@ class DatabaseSeeder extends Seeder $this->call(SegmentConstantsTableSeeder::class); $this->call(CompaniesTableSeeder::class); - $this->call(CompanyBanksTableSeeder::class); - + // Admin $this->call(AdminUserTableSeeder::class); $this->call(AdminUserPermissionsTableSeeder::class); diff --git a/database/seeds/DistrictsTableSeeder.php b/database/seeds/DistrictsTableSeeder.php index 1076de9d..7d62de42 100644 --- a/database/seeds/DistrictsTableSeeder.php +++ b/database/seeds/DistrictsTableSeeder.php @@ -1,7 +1,7 @@ $row[3], 'postcode' => $row[4], 'status' => $row[5], - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), ]; } diff --git a/database/seeds/SegmentConstantsTableSeeder.php b/database/seeds/SegmentConstantsTableSeeder.php index 283bb4d5..8e8a20db 100644 --- a/database/seeds/SegmentConstantsTableSeeder.php +++ b/database/seeds/SegmentConstantsTableSeeder.php @@ -1,79 +1,52 @@ fetchesCurrency = $fetchesCurrency; + $this->fetchesSegment = $fetchesSegment; + $this->createsSegmentConstant = $createsSegmentConstant; + } + + /** * Run the database seeds. * * @return void + * @throws \App\Classes\Exceptions\MalformedRequestException */ public function run() { - DB::table('segment_constants')->insert([ - [ - 'id' => 1, - 'segment_id' => 1, - 'name' => 'Tax', - 'reference' => 'TAX', - 'detail' => json_encode([ - 'type' => 'percentage', - 'value' => '10' - ]), - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), - ], - [ - 'id' => 2, - 'segment_id' => 1, - 'name' => 'Billing Fee', - 'reference' => 'BILLING_FEE', - 'detail' => json_encode([ - 'type' => 'fix_rate', - 'value' => '10' - ]), - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), - ], - [ - 'id' => 3, - 'segment_id' => 1, - 'name' => 'Service Charge', - 'reference' => 'SERVICE_CHARGE', - 'detail' => json_encode([ - 'type' => 'fix_rate', - 'value' => '10' - ]), - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), - ], - [ - 'id' => 4, - 'segment_id' => 1, - 'name' => 'Booking Amount Max', - 'reference' => 'BOOKING_AMOUNT_MAX', - 'detail' => json_encode([ - 'type' => 'fix_rate', - 'value' => '10', - 'currency_id' => 1 - ]), - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), - ], - [ - 'id' => 5, - 'segment_id' => 1, - 'name' => 'Payment Attempt Expiry Time', - 'reference' => 'PAYMENT_ATTEMP_EXPIRY_TIME', - 'detail' => json_encode([ - 'type' => 'day', - 'value' => '10', - ]), - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), - ], - ]); + + $object = new ConstantObject('System Primary Currency', + SegmentConstants::SYSTEM_PRIMARY_CURRENCY, + ['id' => $this->fetchesCurrency->execute(['name' => country('my')->getName()])->id]); + + $this->createsSegmentConstant->execute($this->fetchesSegment->execute(['Standard Segment']), $object); + } } diff --git a/database/seeds/SegmentsTableSeeder.php b/database/seeds/SegmentsTableSeeder.php index bda12c31..574a7769 100644 --- a/database/seeds/SegmentsTableSeeder.php +++ b/database/seeds/SegmentsTableSeeder.php @@ -1,24 +1,23 @@ insert([ - [ - 'id' => 1, - 'name' => 'Standard Segment', - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), - ] + 'name' => 'Standard Segment', + 'type' => SegmentConstants::STANDARD_SEGMENT ]); } } diff --git a/database/seeds/StatesTableSeeder.php b/database/seeds/StatesTableSeeder.php index 8d710dd3..dec26b0b 100644 --- a/database/seeds/StatesTableSeeder.php +++ b/database/seeds/StatesTableSeeder.php @@ -1,10 +1,25 @@ fetchesCountry = $fetchesCountry; + } + + /** * Run the database seeds. * @@ -12,134 +27,89 @@ class StatesTableSeeder extends Seeder */ public function run() { + + $malaysia = $this->fetchesCountry->execute(['name' => country('my')->getName()]); DB::table('states')->insert([ [ - 'id' => 1, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Johor', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 2, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Kedah', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 3, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Kelantan', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 4, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Kuala Lumpur', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 5, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Labuan', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 + ], [ - 'id' => 6, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Melaka', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 7, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Negeri Sembilan', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 8, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Pahang', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 9, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Perak', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 10, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Perlis', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 11, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Pulau Pinang', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 12, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Putrajaya', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 13, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Sabah', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 14, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Sarawak', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 15, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Selangor', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ], [ - 'id' => 16, - 'country_id' => 1, + 'country_id' => $malaysia->id, 'name' => 'Terengganu', - 'status' => 1, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'status' => 1 ] ]); } diff --git a/gulpfile.js b/gulpfile.js index 7d64dac9..142c0ca4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -42,6 +42,14 @@ gulp.task('vendorCss', () => { gulp.task('vendorFonts', () => { fancyLog('Copying vendor fonts for dependencies'); + return gulp.src(pkg.globs.vendorFlags) + .pipe(plugins.plumber({errorHandler: onError})) + .pipe(plugins.print()) + .pipe(gulp.dest(pkg.paths.build.flags)); +}); + +gulp.task('vendorFlags', () => { + fancyLog('Copying flags svg for dependencies'); return gulp.src(pkg.globs.vendorFonts) .pipe(plugins.plumber({errorHandler: onError})) .pipe(plugins.print()) @@ -97,7 +105,7 @@ gulp.task('clean', () => { return del([pkg.paths.build.css + '/*', pkg.paths.build.js + '/*', !pkg.paths.build.js + '/app.js', pkg.paths.build.images + '/*', pkg.paths.build.fonts + '/*']); }); -gulp.task('vendor', gulp.series('vendorJs', 'vendorCss', 'vendorFonts', 'vendorImages')); +gulp.task('vendor', gulp.series('vendorJs', 'vendorCss', 'vendorFonts', 'vendorFlags', 'vendorImages')); gulp.task('source', gulp.series('sourceCss', 'sourceImages', 'sourceJs', 'sourceFonts')); gulp.task('build', gulp.series('clean', 'vendor', 'source')); diff --git a/load_font.php b/load_font.php new file mode 100644 index 00000000..066abfe7 --- /dev/null +++ b/load_font.php @@ -0,0 +1,202 @@ +getOptions()->set('fontDir', $fontDir); +} + +/** + * Installs a new font family + * This function maps a font-family name to a font. It tries to locate the + * bold, italic, and bold italic versions of the font as well. Once the + * files are located, ttf versions of the font are copied to the fonts + * directory. Changes to the font lookup table are saved to the cache. + * + * @param Dompdf $dompdf dompdf main object + * @param string $fontname the font-family name + * @param string $normal the filename of the normal face font subtype + * @param string $bold the filename of the bold face font subtype + * @param string $italic the filename of the italic face font subtype + * @param string $bold_italic the filename of the bold italic face font subtype + * + * @throws Exception + */ +function install_font_family($dompdf, $fontname, $normal, $bold = null, $italic = null, $bold_italic = null) { + $fontMetrics = $dompdf->getFontMetrics(); + + // Check if the base filename is readable + if ( !is_readable($normal) ) + throw new Exception("Unable to read '$normal'."); + + $dir = dirname($normal); + $basename = basename($normal); + $last_dot = strrpos($basename, '.'); + if ($last_dot !== false) { + $file = substr($basename, 0, $last_dot); + $ext = strtolower(substr($basename, $last_dot)); + } else { + $file = $basename; + $ext = ''; + } + + if ( !in_array($ext, array(".ttf", ".otf")) ) { + throw new Exception("Unable to process fonts of type '$ext'."); + } + + // Try $file_Bold.$ext etc. + $path = "$dir/$file"; + + $patterns = array( + "bold" => array("_Bold", "b", "B", "bd", "BD"), + "italic" => array("_Italic", "i", "I"), + "bold_italic" => array("_Bold_Italic", "bi", "BI", "ib", "IB"), + ); + + foreach ($patterns as $type => $_patterns) { + if ( !isset($$type) || !is_readable($$type) ) { + foreach($_patterns as $_pattern) { + if ( is_readable("$path$_pattern$ext") ) { + $$type = "$path$_pattern$ext"; + break; + } + } + + if ( is_null($$type) ) + echo ("Unable to find $type face file.\n"); + } + } + + $fonts = compact("normal", "bold", "italic", "bold_italic"); + $entry = array(); + + // Copy the files to the font directory. + foreach ($fonts as $var => $src) { + if ( is_null($src) ) { + $entry[$var] = $dompdf->getOptions()->get('fontDir') . '/' . mb_substr(basename($normal), 0, -4); + continue; + } + + // Verify that the fonts exist and are readable + if ( !is_readable($src) ) + throw new Exception("Requested font '$src' is not readable"); + + $dest = $dompdf->getOptions()->get('fontDir') . '/' . basename($src); + + if ( !is_writeable(dirname($dest)) ) + throw new Exception("Unable to write to destination '$dest'."); + + echo "Copying $src to $dest...\n"; + + if ( !copy($src, $dest) ) + throw new Exception("Unable to copy '$src' to '$dest'"); + + $entry_name = mb_substr($dest, 0, -4); + + echo "Generating Adobe Font Metrics for $entry_name...\n"; + + $font_obj = Font::load($dest); + $font_obj->saveAdobeFontMetrics("$entry_name.ufm"); + $font_obj->close(); + + $entry[$var] = $entry_name; + } + + // Store the fonts in the lookup table + $fontMetrics->setFontFamily($fontname, $entry); + + // Save the changes + $fontMetrics->saveFontFamilies(); +} + +// If installing system fonts (may take a long time) +if ( $_SERVER["argv"][1] === "system_fonts" ) { + $fontMetrics = $dompdf->getFontMetrics(); + $files = glob("/usr/share/fonts/truetype/*.ttf") + + glob("/usr/share/fonts/truetype/*/*.ttf") + + glob("/usr/share/fonts/truetype/*/*/*.ttf") + + glob("C:\\Windows\\fonts\\*.ttf") + + glob("C:\\WinNT\\fonts\\*.ttf") + + glob("/mnt/c_drive/WINDOWS/Fonts/"); + $fonts = array(); + foreach ($files as $file) { + $font = Font::load($file); + $records = $font->getData("name", "records"); + $type = $fontMetrics->getType($records[2]); + $fonts[mb_strtolower($records[1])][$type] = $file; + $font->close(); + } + + foreach ( $fonts as $family => $files ) { + echo " >> Installing '$family'... \n"; + + if ( !isset($files["normal"]) ) { + echo "No 'normal' style font file\n"; + } + else { + install_font_family($dompdf, $family, @$files["normal"], @$files["bold"], @$files["italic"], @$files["bold_italic"]); + echo "Done !\n"; + } + + echo "\n"; + } +} +else { + call_user_func_array("install_font_family", array_merge( array($dompdf), array_slice($_SERVER["argv"], 1) )); +} diff --git a/package.json b/package.json index 8bc1d6c5..b2003517 100644 --- a/package.json +++ b/package.json @@ -15,18 +15,24 @@ "bootstrap-datepicker": "^1.7.1", "dropzone": "^5.7.2", "epic-spinners": "^1.1.0", + "flag-icon-css": "^3.5.0", "font-awesome": "^4.7.0", "intro.js": "^3.1.0", "jquery": "^3.2", "jquery.scrollbar": "^0.2.11", + "jwt-decode": "^3.1.2", "noty": "^3.2.0-beta", + "pdfjs-dist": "^2.6.347", "perfect-scrollbar": "^1.5.0", "popper.js": "^1.12", "sass-loader": "10.1.0", "select2": "^4.0.6-rc.1", + "v-money": "^0.8.1", "vue": "^2.6.10", "vue-avatar": "^2.1.8", + "vue-debounce": "^2.6.0", "vue-template-compiler": "^2.6.10", + "vue-the-mask": "^0.11.1", "vuelidate": "^0.7.4", "vuex": "^3.1.1" }, @@ -62,6 +68,7 @@ "js": "./public/js/", "images": "./public/images/", "fonts": "./public/fonts/", + "flags": "./public/flag-icon-css/flags", "main": "./public/" } }, @@ -80,6 +87,7 @@ ], "vendorCss": [ "./node_modules/font-awesome/css/font-awesome.min.css", + "./node_modules/flag-icon-css/css/flag-icon.min.css", "./node_modules/jquery.scrollbar/jquery.scrollbar.css", "./node_modules/select2/dist/css/select2.min.css", "./node_modules/dropzone/dist/dropzone.css", @@ -93,6 +101,9 @@ "vendorFonts": [ "./node_modules/font-awesome/fonts/**/*" ], + "vendorFlags": [ + "./node_modules/flag-icon-css/flags/**/*" + ], "vendorImages": [ "./node_modules/jquery-ui-dist/images/**/*.png", "./node_modules/datatables.net-dt/images/**/*.png" diff --git a/resources/assets/images/2829248.png b/resources/assets/images/2829248.png new file mode 100644 index 00000000..50a0280f Binary files /dev/null and b/resources/assets/images/2829248.png differ diff --git a/resources/assets/images/2853457.png b/resources/assets/images/2853457.png new file mode 100644 index 00000000..b9107cf8 Binary files /dev/null and b/resources/assets/images/2853457.png differ diff --git a/resources/assets/images/2942005.jpg b/resources/assets/images/2942005.jpg new file mode 100644 index 00000000..83908287 Binary files /dev/null and b/resources/assets/images/2942005.jpg differ diff --git a/resources/assets/images/3231370.jpg b/resources/assets/images/3231370.jpg new file mode 100644 index 00000000..41002f1b Binary files /dev/null and b/resources/assets/images/3231370.jpg differ diff --git a/resources/assets/images/3568950.png b/resources/assets/images/3568950.png new file mode 100644 index 00000000..9003367b Binary files /dev/null and b/resources/assets/images/3568950.png differ diff --git a/resources/assets/images/easter-egg.png b/resources/assets/images/easter-egg.png new file mode 100644 index 00000000..cc7ff537 Binary files /dev/null and b/resources/assets/images/easter-egg.png differ diff --git a/resources/assets/images/iStock-976354264_Malaysia.jpg b/resources/assets/images/iStock-976354264_Malaysia.jpg new file mode 100644 index 00000000..3f8db0b0 Binary files /dev/null and b/resources/assets/images/iStock-976354264_Malaysia.jpg differ diff --git a/resources/assets/images/logo-dark.png b/resources/assets/images/logo-dark.png new file mode 100644 index 00000000..50c14872 Binary files /dev/null and b/resources/assets/images/logo-dark.png differ diff --git a/resources/assets/images/logo-gradient.png b/resources/assets/images/logo-gradient.png new file mode 100644 index 00000000..050fa371 Binary files /dev/null and b/resources/assets/images/logo-gradient.png differ diff --git a/resources/assets/images/logo-light.png b/resources/assets/images/logo-light.png new file mode 100644 index 00000000..e9bbd538 Binary files /dev/null and b/resources/assets/images/logo-light.png differ diff --git a/resources/assets/images/logo.png b/resources/assets/images/logo.png deleted file mode 100644 index c0a1f3bb..00000000 Binary files a/resources/assets/images/logo.png and /dev/null differ diff --git a/resources/assets/images/logo_white.png b/resources/assets/images/logo_white.png deleted file mode 100644 index c4be42e0..00000000 Binary files a/resources/assets/images/logo_white.png and /dev/null differ diff --git a/resources/assets/images/order_form.png b/resources/assets/images/order_form.png new file mode 100644 index 00000000..3f940fd5 Binary files /dev/null and b/resources/assets/images/order_form.png differ diff --git a/resources/assets/js/pages.js b/resources/assets/js/pages.js index fbeb52e3..2455508d 100644 --- a/resources/assets/js/pages.js +++ b/resources/assets/js/pages.js @@ -13,7 +13,7 @@ this.setUserOS(); this.setUserAgent(); - } + }; /** @function setUserOS * @description SET User Operating System eg: mac,windows,etc @@ -27,7 +27,7 @@ if (navigator.appVersion.indexOf("Linux") != -1) OSName = "linux"; this.$body.addClass(OSName); - } + }; /** @function setUserAgent * @description SET User Device Name to mobile | desktop @@ -42,7 +42,7 @@ this.$body.addClass('ie9'); } } - } + }; /** @function isVisibleXs * @description Checks if the screen size is XS - Extra Small i.e below W480px @@ -51,7 +51,7 @@ Pages.prototype.isVisibleXs = function() { (!$('#pg-visible-xs').length) && this.$body.append('
'); return $('#pg-visible-xs').is(':visible'); - } + }; /** @function isVisibleSm * @description Checks if the screen size is SM - Small Screen i.e Above W480px @@ -60,7 +60,7 @@ Pages.prototype.isVisibleSm = function() { (!$('#pg-visible-sm').length) && this.$body.append(''); return $('#pg-visible-sm').is(':visible'); - } + }; /** @function isVisibleMd * @description Checks if the screen size is MD - Medium Screen i.e Above W1024px @@ -69,7 +69,7 @@ Pages.prototype.isVisibleMd = function() { (!$('#pg-visible-md').length) && this.$body.append(''); return $('#pg-visible-md').is(':visible'); - } + }; /** @function isVisibleLg * @description Checks if the screen size is LG - Large Screen i.e Above W1200px @@ -78,7 +78,7 @@ Pages.prototype.isVisibleLg = function() { (!$('#pg-visible-lg').length) && this.$body.append(''); return $('#pg-visible-lg').is(':visible'); - } + }; /** @function getUserAgent * @description Get Current User Agent. @@ -86,7 +86,7 @@ */ Pages.prototype.getUserAgent = function() { return $('body').hasClass('mobile') ? "mobile" : "desktop"; - } + }; /** @function setFullScreen * @description Make Browser fullscreen. @@ -103,7 +103,7 @@ wscript.SendKeys("{F11}"); } } - } + }; /** @function getColor * @description Get Color from CSS @@ -124,7 +124,7 @@ var rgba = "rgba(" + rgb[1] + ", " + rgb[2] + ", " + rgb[3] + ', ' + opacity + ')'; return rgba; - } + }; /** @function initSidebar * @description Initialize side bar to open and close @@ -133,10 +133,10 @@ */ Pages.prototype.initSidebar = function(context) { $('[data-pages="sidebar"]', context).each(function() { - var $sidebar = $(this) + var $sidebar = $(this); $sidebar.sidebar($sidebar.data()) }) - } + }; /** @function initDropDown * @description Initialize Boot-Strap dropdown Menue @@ -158,7 +158,7 @@ $(this).find('.dropdown-menu').width(btn.actual('outerWidth')); } }); - } + }; /** @function initFormGroupDefault * @description Initialize Pages form group input @@ -193,7 +193,7 @@ }, function() { $(this).parents('.form-group').removeClass('focused'); }); - } + }; /** @function initSlidingTabs * @description Initialize Bootstrap Custom Sliding Tabs @@ -216,7 +216,7 @@ $(hrefCurrent).removeClass('sliding'); }, 100); }); - } + }; /** @function reponsiveTabs * @description Responsive handlers for Bootstrap Tabs */ @@ -225,7 +225,7 @@ $('[data-init-reponsive-tabs="dropdownfx"]').each(function() { var drop = $(this); drop.addClass("hidden-sm-down"); - var content = ''; drop.after(content); var select = drop.next()[0]; $(select).on('change', function (e) { @@ -251,11 +251,11 @@ tabLink = drop.find('a[data-target="'+valueSelected+'"]') } tabLink.tab('show') - }) + }); $(select).wrap(''); new SelectFx(select); }); - } + }; /** @function initNotificationCenter * @description Initialize Pages Header Notifcation Dropdown @@ -270,7 +270,7 @@ p.toggleClass('open'); }); }); - } + }; /** @function initProgressBars * @description Initialize Pages ProgressBars @@ -280,7 +280,7 @@ // Hack: FF doesn't play SVG animations set as background-image $('.progress-bar-indeterminate, .progress-circle-indeterminate, .mapplic-pin').hide().show(0); }); - } + }; /** @function initInputFile * @description Initialize File Input for Bootstrap Buttons and Input groups @@ -302,7 +302,7 @@ $(this).parent().html(log); } }); - } + }; /** @function initHorizontalMenu * @description Initialize Horizontal Dropdown Menu */ @@ -378,7 +378,7 @@ function autoHideLi(){ var hMenu = $("[data-pages-init='horizontal-menu']"); - var extraLiHide = parseInt(hMenu.data("hideExtraLi")) || 0 + var extraLiHide = parseInt(hMenu.data("hideExtraLi")) || 0; if(hMenu.length == 0){ return } @@ -429,7 +429,7 @@ "width":rect.width+"px", "height":rect.height+"px", "z-index":"auto" - }) + }); $el.append(ghost); var timingSpeed = ul.children("li").css('transition-duration'); @@ -459,14 +459,14 @@ ghost.height(rect.height); var timingSpeed = ghost.css('transition-duration'); - timingSpeed = parseInt(parseFloat(timingSpeed) * 1000) + timingSpeed = parseInt(parseFloat(timingSpeed) * 1000); window.clearTimeout(animationTimer); animationTimer = window.setTimeout(function(){ $el.addClass('opening'); ghost.remove() },timingSpeed); } - } + }; /** @function initTooltipPlugin * @description Initialize Bootstrap tooltip * @param {(Element|JQuery)} [context] - A DOM Element, Document, or jQuery to use as context. @@ -474,7 +474,7 @@ */ Pages.prototype.initTooltipPlugin = function(context) { $.fn.tooltip && $('[data-toggle="tooltip"]', context).tooltip(); - } + }; /** @function initSelect2Plugin * @description Initialize select2 dropdown * @param {(Element|JQuery)} [context] - A DOM Element, Document, or jQuery to use as context. @@ -490,7 +490,7 @@ }) }); }); - } + }; /** @function initScrollBarPlugin * @description Initialize Global Scroller * @param {(Element|JQuery)} [context] - A DOM Element, Document, or jQuery to use as context. @@ -500,7 +500,7 @@ $.fn.scrollbar && $('.scrollable', context).scrollbar({ ignoreOverlay: false }); - } + }; /** @function initListView * @description Initialize iOS like List view plugin * @param {(Element|JQuery)} [context] - A DOM Element, Document, or jQuery to use as context. @@ -512,7 +512,7 @@ $.fn.scrollbar && $('.list-view-wrapper', context).scrollbar({ ignoreOverlay: false }); - } + }; /** @function initSwitcheryPlugin * @description Initialize iOS like List view plugin @@ -529,7 +529,7 @@ size : (el.data("size") != null ? el.data("size") : "default") }); }); - } + }; /** @function initSelectFxPlugin * @description Initialize iOS like List view plugin @@ -542,7 +542,7 @@ $(el).wrap(''); new SelectFx(el); }); - } + }; /** @function initUnveilPlugin * @description To load retina images to img tag * @param {(Element|JQuery)} [context] - A DOM Element, Document, or jQuery to use as context. @@ -550,7 +550,7 @@ Pages.prototype.initUnveilPlugin = function(context) { // lazy load retina images $.fn.unveil && $("img", context).unveil(); - } + }; /** @function initValidatorPlugin * @description Inintialize and Overide exsisting jquery-validate methods. @@ -616,14 +616,14 @@ } } }); - } + }; /** @function setBackgroundImage * @description load images to div using data API */ Pages.prototype.setBackgroundImage = function() { $('[data-pages-bg-image]').each(function() { - var _elem = $(this) + var _elem = $(this); var defaults = { pagesBgImage: "", lazyLoad: 'true', @@ -632,7 +632,7 @@ bgOverlay:'', bgOverlayClass:'', overlayOpacity:0, - } + }; var data = _elem.data(); $.extend( defaults, data ); var url = defaults.pagesBgImage; @@ -657,7 +657,7 @@ } }) - } + }; /** @function secondarySidebar * @description dropdown Toggle and responive toggle for secondary sidebar */ @@ -703,7 +703,7 @@ menu.removeAttr("style"); } else{ - menu.addClass("open") + menu.addClass("open"); var menuRect = menu.get(0).getBoundingClientRect(); menu.css({ top : toggleRect.bottom, @@ -717,7 +717,7 @@ }); - } + }; /** @function init * @description Inintialize all core components. */ @@ -743,24 +743,13 @@ this.initInputFile(); this.reponsiveTabs(); this.secondarySidebar(); - } + }; $.Pages = new Pages(); $.Pages.Constructor = Pages; })(window.jQuery); -/** - * selectFx.js v1.0.0 - * http://www.codrops.com - * - * Licensed under the MIT license. - * http://www.opensource.org/licenses/mit-license.php - * - * Copyright 2014, Codrops - * http://www.codrops.com - */ -; (function(window) { 'use strict'; @@ -775,8 +764,7 @@ el = el.parentNode || false; } return (el !== false); - }; - + } /** * extend obj function */ @@ -848,7 +836,7 @@ event.initEvent('change', true, false); el.dispatchEvent(event); } - } + }; /** * init function @@ -886,7 +874,7 @@ var inputText = this.children[index].innerHTML.trim(); } - } + }; /** * creates the structure for the select element @@ -932,7 +920,7 @@ options += 'Forgot password?
+Forgot password?
+Select your account type
+Company
+Personal
+Personal Information
+Account Information
+Enter your email address to register/login.
-Looks like you already have an account with us.
-Looks like you are a new user.
Let's create a fresh new izyim profile for you.
+
+
+
+
+
+
+
+
+ 
Nothing To Show Here
+

No Results Found
+Nothing To Show Here

We have received a request to reset the the password for your account on https://www.izyim.com
+Click the link below to complete the process. Note that the link expires in 24 hours
+ +verify your email to finish your account registration on {{route('login')}}
+Please confirm that {{$user->email}} is your email address by clicking on the button below or use this link {{route('account.email.verification', $attempt->token)}} within 48 hours
+ +Browser Recommendations:
-To use IZYIM portal, we presently require
Microsoft Internet Explorer 7.x or higher
Support:
-To obtain access to this site or for any questions about its
use submit an email message to info@izyim.com
Enter your email address you're using for your account below
and we will send you a password reset link
To keep connected with us please login with your personal info
+Create an account with us to join our fast growing community and start making transfers overseas at a competitive exchange rates today.
+
+
- Users
-Forwarders
-Importers
-Warehouses
-Active Users
-Blocked Users
-User Invites
-Reports
-List of the system currently active users
-List of the system currently inactive users
-Orders
-Customers
-Warehouses
-Employees
-Active Users
-Blocked Users
-User Invites
-Reports
-List of the system currently active users
-| {{$supplier->name}} | +{{\Carbon\Carbon::now('Asia/Singapore')->format('d-m-Y h:s')}} | +
| Reference | +Rate | +Amount | +Bank in Details | +
| {{$transaction->booking->marking}} | +{{$transaction->currency_rate}} | +{{$transaction->original_currency->short_code}} {{$transaction->original_amount}} | +Account Holder Name: {{$transaction->booking->bank->holder_name}} {{$transaction->booking->bank->bank_name}}: {{$transaction->booking->bank->account_no}} + Branch: 首都 Bank in Amount: {{$transaction->original_amount}} |
+