diff --git a/.env.example b/.env.example index 8f2f87a1..1c362992 100644 --- a/.env.example +++ b/.env.example @@ -10,9 +10,9 @@ LOG_LEVEL=debug DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 -DB_DATABASE=laravel +DB_DATABASE=shpping_portal DB_USERNAME=root -DB_PASSWORD= +DB_PASSWORD=root BROADCAST_DRIVER=log CACHE_DRIVER=file @@ -56,6 +56,8 @@ MIX_EXCHANGE_URL="${EXCHANGE_URL}" YD_API_CODE='' +JWT_SECRET=Btj63iMEleEaww6Bb2IBECkxWn7YHPhhPFluAkg9DfcQik0qDRy6QW75ABGmPT2h + PERFEXCRM_BASE_URL="" PERFEXCRM_API_KEY="" PERFEXCRM_IS_ENABLED="false" diff --git a/.env.testing b/.env.testing new file mode 100644 index 00000000..7fc36450 --- /dev/null +++ b/.env.testing @@ -0,0 +1,59 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY=base64:rIar2fvNeRzQdvKOgLUg03detGDMx6ym2SYFRjawrAc= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack +LOG_LEVEL=debug + +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=shpping_portal +DB_USERNAME=root +DB_PASSWORD=P@ssw0rd + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +FILESYSTEM_DRIVER=local +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +MEMCACHED_HOST=127.0.0.1 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=mailhog +MAIL_PORT=1025 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=null +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= +AWS_USE_PATH_STYLE_ENDPOINT=false + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + +UNITY_APP_URL="https://unity.izyim.com" +EXCHANGE_URL=https://dev.exchange.cief-malaysia.com/ +MIX_EXCHANGE_URL="${EXCHANGE_URL}" + +YD_API_CODE='' + +JWT_SECRET=Btj63iMEleEaww6Bb2IBECkxWn7YHPhhPFluAkg9DfcQik0qDRy6QW75ABGmPT2h diff --git a/.gitignore b/.gitignore index 00c3679e..96f0a5e2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ /public/hot /public/storage /storage/*.key +/tests/_output +/tests/_support /vendor **/.idea/ .env diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..daad27fa --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,120 @@ +image: php:7.4 +stages: + - service_build + - node + - building_assets + - database + - unit_test + - acceptance_test + - code_quality + +# Variables +variables: + MYSQL_ROOT_PASSWORD: root + MYSQL_USER: mysql_password + MYSQL_PASSWORD: mysql_password + MYSQL_DATABASE: shpping_portal + DB_HOST: mysql + + +before_script: + - apt-get update -yqq + - apt-get install -yqq + - apt-get install -y libonig-dev + - apt-get install -y libxml2-dev + - apt-get install -y libzip-dev + - apt-get install -y libgd-dev + - apt-get install -y libgd-dev + +# Install PDO MySQL extension + - docker-php-ext-install pdo_mysql + + #install php dependencies + - docker-php-ext-install mbstring xml zip gd + + # Install composer package manager + - curl --location --output /usr/local/bin/composer https://getcomposer.org/download/latest-stable/composer.phar + - chmod +x /usr/local/bin/composer + + # Install MySQL client + - apt-get install -y default-mysql-client + + #install node js + - apt-get update && apt-get install -y nodejs npm + + #install gulp Js + - npm install -g gulp-cli + + +#jobs + +#buld the backend +composer_php: + stage: service_build + script: + - composer install + - cp .env.example .env + - php artisan key:generate + rules: + - if: '$CI_COMMIT_BRANCH =~ /.*/' + +#build the UI +#node installation +npm: + stage: node + script: + - npm install # Install npm dependencies + rules: + - if: '$CI_COMMIT_BRANCH =~ /.*/' + +#building assets +building_assets: + stage: building_assets + # dependencies: + # - npm + script: + - npm install # Install npm dependencies + - gulp build # Build assets + rules: + - if: '$CI_COMMIT_BRANCH =~ /.*/' + +#mysql +database: + stage: database + services: + - name: mysql:8.0 + command: [ "--default-authentication-plugin=mysql_native_password" ] + #dependencies: + # - composer_php + script: + - composer install + - cp .env.example .env + - php artisan key:generate + - php artisan migrate:fresh + - php artisan db:seed + rules: + - if: '$CI_COMMIT_BRANCH =~ /.*/' + +#mysql +unit_test: + stage: unit_test + services: + - name: mysql:8.0 + command: [ "--default-authentication-plugin=mysql_native_password" ] + #dependencies: + # - database + script: + - npm install # Install npm dependencies + - gulp build # Build assets + - composer install + - cp .env.example .env + - php artisan key:generate + - php artisan migrate:fresh + - php artisan db:seed + - php artisan test + rules: + - if: '$CI_COMMIT_BRANCH =~ /.*/' + + + + diff --git a/README.md b/README.md index ceb6ac0a..c34829b6 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,39 @@ -
+## Shipping portal documentation - +simple documentation on how to install, run, test, commit and deploy application -## About Laravel +## creating and running unit tests -Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: +Required Tools -- [Simple, fast routing engine](https://laravel.com/docs/routing). -- [Powerful dependency injection container](https://laravel.com/docs/container). -- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. -- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). -- Database agnostic [schema migrations](https://laravel.com/docs/migrations). -- [Robust background job processing](https://laravel.com/docs/queues). -- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). +- Chromium Driver / selenium +- add running and setting selenium on all OS if possible -Laravel is accessible, powerful, and provides tools required for large, robust applications. +Required Packages : -## Learning Laravel +- laravel/legacy-factories -Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. +- codeception/codeception -If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. +Or Simply Run -## Laravel Sponsors +``Composer install`` -We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell). +To create a unit test -### Premium Partners +``php artisan make test: Test Example --unit`` -- **[Vehikl](https://vehikl.com/)** -- **[Tighten Co.](https://tighten.co)** -- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** -- **[64 Robots](https://64robots.com)** -- **[Cubet Techno Labs](https://cubettech.com)** -- **[Cyber-Duck](https://cyber-duck.co.uk)** -- **[Many](https://www.many.co.uk)** -- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)** -- **[DevSquad](https://devsquad.com)** -- **[Curotec](https://www.curotec.com/services/technologies/laravel/)** -- **[OP.GG](https://op.gg)** +Running the tests : -## Contributing +Running a single Test -Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). +`` php artisan test --filter Example`` -## Code of Conduct +Running Unit tests - -In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). +`` php artisan test `` -## Security Vulnerabilities +Running Codeception tests - -If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. +``vendor/bin/codecept run`` -## License - -The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). diff --git a/app/Classes/General/Eloquent/Filters/DoesNotHavePaymentStatusIn.php b/app/Classes/General/Eloquent/Filters/DoesNotHavePaymentStatusIn.php new file mode 100644 index 00000000..f8e9f214 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/DoesNotHavePaymentStatusIn.php @@ -0,0 +1,22 @@ +whereDoesntHave('transactions', function (Builder $query) use($value) { + $query->where('type', TransactionType::PAYMENT)->whereIn('status', $value); + }); + } +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/HavePaymentStatusNotIn.php b/app/Classes/General/Eloquent/Filters/HavePaymentStatusNotIn.php new file mode 100644 index 00000000..0b989f73 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/HavePaymentStatusNotIn.php @@ -0,0 +1,22 @@ +whereHas('transactions', function (Builder $query) use($value) { + $query->where('type', TransactionType::PAYMENT)->whereNotIn('status', $value); + }); + } +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/OwnerType.php b/app/Classes/General/Eloquent/Filters/OwnerType.php new file mode 100644 index 00000000..6a13fb08 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/OwnerType.php @@ -0,0 +1,20 @@ +where('owner_type', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/Jobs/UpdatePerfexCRMInvoice.php b/app/Classes/Jobs/UpdatePerfexCRMInvoice.php index ac16a77c..e3160a97 100644 --- a/app/Classes/Jobs/UpdatePerfexCRMInvoice.php +++ b/app/Classes/Jobs/UpdatePerfexCRMInvoice.php @@ -11,14 +11,16 @@ use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMInvoice; use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObject; use App\Classes\Modules\PerfexCRM\DataTransferObjects\InvoicePaymentPerfexCRMObject; use App\Classes\ValueObjects\Constants\PerfexCRMInvoiceStatus; +use App\Models\PackingList; use App\Models\Transaction; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Carbon\Carbon; use Illuminate\Support\Facades\Log; +use Carbon\Carbon; + use App\Classes\General\Helper; class UpdatePerfexCRMInvoice implements ShouldQueue diff --git a/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php index f019bab3..df552b6a 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php @@ -3,6 +3,9 @@ namespace App\Classes\Modules\Addresses\ControllersLogic; +use App\Classes\Exceptions\AccessForbiddenException; +use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\RequestValidationException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\General\Interfaces\Contactable; use App\Classes\Modules\Addresses\Services\CreatesAddress; @@ -17,6 +20,7 @@ use App\Classes\Modules\Remarks\Processors\CreateRemarkProcessor; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Http\Resources\AddressResource; use App\Models\Address; +use App\Transformers\AddressTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -27,7 +31,8 @@ class CreateAddressLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Created Address', 'message' => 'You have successfully created a new Address' @@ -74,11 +79,11 @@ class CreateAddressLogic extends AbstractControllerLogic /** * @param Request $request * @return JsonResponse - * @throws \App\Classes\Exceptions\AccessForbiddenException - * @throws \App\Classes\Exceptions\MalformedRequestException - * @throws \App\Classes\Exceptions\RequestValidationException + * @throws AccessForbiddenException + * @throws MalformedRequestException + * @throws RequestValidationException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]); @@ -90,16 +95,22 @@ class CreateAddressLogic extends AbstractControllerLogic /** @var Address $address */ $address = $this->createsAddress->execute($this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]), $object); - if($request->input('phone')){ + if ($request->input('phone')) { $contactObject = new ContactObject($request->input('person_in_charge'), $request->input('phone'), '', ''); $this->createContactProcessor->execute($contactObject, $address); } - if($request->input('remark')){ + if ($request->input('remark')) { $remarkObject = new RemarkObject($request->input('remark'), Auth()->user()->id); $this->createRemarkProcessor->execute($address, $remarkObject); } +/* return fractal() + ->item($address, new AddressTransformer()) + ->parseIncludes('remark') + ->respond(200, [], JSON_PRETTY_PRINT);*/ + + return $this->resourceResponse(new AddressResource($address)); } diff --git a/app/Classes/Modules/Addresses/ControllersLogic/CreateBillingAddressLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/CreateBillingAddressLogic.php index 31eb7c8f..e97ece85 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/CreateBillingAddressLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/CreateBillingAddressLogic.php @@ -3,6 +3,9 @@ namespace App\Classes\Modules\Addresses\ControllersLogic; +use App\Classes\Exceptions\AccessForbiddenException; +use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\RequestValidationException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Addresses\Services\CreatesAddress; use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress; @@ -14,6 +17,7 @@ use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Http\Resources\AddressResource; use App\Models\Address; use App\Models\CompanyModule; +use App\Transformers\AddressTransformer; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -23,7 +27,8 @@ class CreateBillingAddressLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Created Billing Address', 'message' => 'You have successfully created a new Billing Address' @@ -60,27 +65,35 @@ class CreateBillingAddressLogic extends AbstractControllerLogic /** * @param Request $request * @return JsonResponse - * @throws \App\Classes\Exceptions\AccessForbiddenException - * @throws \App\Classes\Exceptions\MalformedRequestException - * @throws \App\Classes\Exceptions\RequestValidationException + * @throws AccessForbiddenException + * @throws MalformedRequestException + * @throws RequestValidationException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $companyModule = $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]); - - $address = $this->fetchesAddress->execute(['id' => $request->input('billing_address_id')]); - if ($address->type !== AddressType::BILLING || $address->id !== $companyModule->addresses->where('type', AddressType::BILLING)->first()->id) { + $billingAddressInputed = $this->fetchesAddress->execute(['id' => $request->input('billing_address_id')]); + + if ($billingAddressInputed->type !== AddressType::BILLING || $billingAddressInputed->id !== $companyModule->addresses->where('type', AddressType::BILLING)->first()->id) { // delete all current billing address Address::where('owner_type', CompanyModule::class)->where('owner_id', $request->input('company_module_id'))->where('type', AddressType::BILLING)->delete(); - // create addrress - $billingAddress = new AddressObject($address->street_one, $address->street_two, $address->country_id, $address->state_id, $address->district_id, $address->postcode, AddressType::BILLING, ApprovalStatus::APPROVED, $address->reference); + // create new billing addrress + $billingAddress = new AddressObject($billingAddressInputed->street_one, $billingAddressInputed->street_two, $billingAddressInputed->country_id, $billingAddressInputed->state_id, $billingAddressInputed->district_id, $billingAddressInputed->postcode, AddressType::BILLING, ApprovalStatus::APPROVED, $billingAddressInputed->reference); $this->canCreateAddress->passes($billingAddress); $this->createsAddress->execute($companyModule, $billingAddress); } - return $this->resourceResponse(new AddressResource($address)); + //load address with only owner address + +/* return fractal() + ->item($billingAddressInputed, new AddressTransformer()) + ->parseIncludes('Owner_address') + ->respond(200, [], JSON_PRETTY_PRINT);*/ + + + return $this->resourceResponse(new AddressResource($billingAddressInputed)); } } \ No newline at end of file diff --git a/app/Classes/Modules/Addresses/ControllersLogic/FetchAddressLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/FetchAddressLogic.php index 2b1ae32e..bd9f4228 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/FetchAddressLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/FetchAddressLogic.php @@ -3,6 +3,8 @@ namespace App\Classes\Modules\Addresses\ControllersLogic; +use App\Classes\Exceptions\AccessForbiddenException; +use App\Classes\Exceptions\RequestValidationException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Addresses\Services\FetchesAddress; use App\Classes\Modules\Addresses\Standards\Rules\CanFetchAddress; @@ -17,7 +19,8 @@ class FetchAddressLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Retrieved Address', 'message' => 'You have successfully retrieved a Address' @@ -45,15 +48,22 @@ class FetchAddressLogic extends AbstractControllerLogic /** * @param Request $request * @return JsonResponse - * @throws \App\Classes\Exceptions\AccessForbiddenException - * @throws \App\Classes\Exceptions\RequestValidationException + * @throws AccessForbiddenException + * @throws RequestValidationException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $this->canFetchAddress->passes(); $query = $this->fetchesAddress->execute(['id' => $request->route('id')]); + + //load address with no relationships + /* return fractal() + ->item($address, new AddressTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + + return $this->resourceResponse(new AddressResource($query)); } diff --git a/app/Classes/Modules/Addresses/ControllersLogic/ListAddressesLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/ListAddressesLogic.php index 71e3b80d..08868c65 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/ListAddressesLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/ListAddressesLogic.php @@ -3,10 +3,14 @@ namespace App\Classes\Modules\Addresses\ControllersLogic; +use App\Classes\Exceptions\AccessForbiddenException; +use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\RequestValidationException; 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; +use App\Transformers\AddressTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -17,7 +21,8 @@ class ListAddressesLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Retrieved Addresses', 'message' => 'You have successfully retrieved a list of Addresses' @@ -45,17 +50,25 @@ class ListAddressesLogic extends AbstractControllerLogic /** * @param Request $request * @return JsonResponse - * @throws \App\Classes\Exceptions\AccessForbiddenException - * @throws \App\Classes\Exceptions\MalformedRequestException - * @throws \App\Classes\Exceptions\RequestValidationException + * @throws AccessForbiddenException + * @throws MalformedRequestException + * @throws RequestValidationException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $this->canListAddresses->passes(); $query = $this->listsAddresses->execute($this->listsAddresses->deserializeFilters($request->input('filters'))); + //a collection of addresses with all incluides + /* return fractal() + ->collection($query, new AddressTransformer) + ->parseIncludes('Owner_address') + ->parseIncludes('remark') + ->parseIncludes('contact') + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->collectionResponse(AddressResource::collection($query)); } diff --git a/app/Classes/Modules/Addresses/ControllersLogic/ListDistrictsLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/ListDistrictsLogic.php index b9a97fb3..6f47e517 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/ListDistrictsLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/ListDistrictsLogic.php @@ -7,7 +7,6 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Addresses\Services\ListsAddresses; use App\Classes\Modules\Addresses\Services\ListsDistricts; use App\Classes\Modules\Addresses\Standards\Rules\CanListAddresses; -use App\Http\Resources\AddressResource; use App\Http\Resources\DistrictResource; use ErrorException; use Illuminate\Http\JsonResponse; diff --git a/app/Classes/Modules/Addresses/ControllersLogic/ListStatesLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/ListStatesLogic.php index 3d6c484f..67b00b50 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/ListStatesLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/ListStatesLogic.php @@ -7,7 +7,6 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Addresses\Services\ListsAddresses; use App\Classes\Modules\Addresses\Services\ListsStates; use App\Classes\Modules\Addresses\Standards\Rules\CanListAddresses; -use App\Http\Resources\AddressResource; use App\Http\Resources\StateResource; use ErrorException; use Illuminate\Http\JsonResponse; diff --git a/app/Classes/Modules/Addresses/ControllersLogic/SetAddressToDefaultLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/SetAddressToDefaultLogic.php index f8fed1a0..1128de73 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/SetAddressToDefaultLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/SetAddressToDefaultLogic.php @@ -9,6 +9,7 @@ use App\Classes\Modules\Addresses\Services\FetchesAddress; use App\Classes\Modules\Addresses\Services\ResetsAddressesDefault; use App\Classes\Modules\Addresses\Services\SetsAddressToDefault; use App\Models\Address; +use App\Transformers\AddressTransformer; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -33,7 +34,7 @@ class SetAddressToDefaultLogic extends AbstractControllerLogic /** @var ResetsAddressesDefault */ private $resetsAddressesDefault; - /** @var SetsAddressToDefault*/ + /** @var SetsAddressToDefault */ private $setsAddressToDefault; @@ -64,7 +65,15 @@ class SetAddressToDefaultLogic extends AbstractControllerLogic $this->resetsAddressesDefault->execute($address->owner, $address->type); - return $this->resourceResponse(new AddressResource($this->setsAddressToDefault->execute($address))); + + $setAddress = $this->setsAddressToDefault->execute($address); + //no relationships needed + /* return fractal() + ->item($setAddress, new AddressTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + + + return $this->resourceResponse(new AddressResource($address)); } } diff --git a/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php b/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php index 94d960f6..4216a0e8 100644 --- a/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php +++ b/app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php @@ -17,6 +17,7 @@ use App\Classes\ValueObjects\Constants\AddressType; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Http\Resources\AddressResource; use App\Models\Address; +use App\Transformers\AddressTransformer; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -26,7 +27,8 @@ class UpdateAddressLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Updated Address', 'message' => 'You have successfully updated the Address' @@ -77,7 +79,7 @@ class UpdateAddressLogic extends AbstractControllerLogic * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]); @@ -90,18 +92,25 @@ class UpdateAddressLogic extends AbstractControllerLogic /** @var Address $address */ $address = $this->updatesAddress->execute($address, $object); - $address->contacts()->delete(); $address->remarks()->delete(); + $address->contacts()->delete(); + $address->remarks()->delete(); - if($request->input('phone')){ + if ($request->input('phone')) { $contactObject = new ContactObject($request->input('person_in_charge'), $request->input('phone'), '', ''); $this->createContactProcessor->execute($contactObject, $address); } - if($request->input('remark')){ + if ($request->input('remark')) { $remarkObject = new RemarkObject($request->input('remark'), Auth()->user()->id); $this->createRemarkProcessor->execute($address, $remarkObject); } + //only remark relationship needed +/* return fractal() + ->item($address, new AddressTransformer()) + ->parseIncludes('remark') + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new AddressResource($address)); } diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php index b5c3269a..fbb0fb63 100644 --- a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php +++ b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php @@ -45,6 +45,9 @@ class CallbackBillplzLogic /** @var UpdateDoFromYDPortalProcessor */ private $updateDoFromYDPortalProcessor ; + /** @var UpdatesWalletBalance */ + private $updatesWalletBalance; + /** * CallbackBillplzLogic constructor. * @param GetBillplzBill $getBillplzBill @@ -53,13 +56,14 @@ class CallbackBillplzLogic * @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor * @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor */ - public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor) + public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance) { $this->getBillplzBill = $getBillplzBill; $this->fetchesTransaction = $fetchesTransaction; $this->updatesTransactionStatus = $updatesTransactionStatus; $this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor; $this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor; + $this->updatesWalletBalance = $updatesWalletBalance; } @@ -102,6 +106,11 @@ class CallbackBillplzLogic $token = Auth::fromUser(User::find(1)); $request->headers->set('Authorization', 'Bearer '.$token); + // check if is wallet top up + if($transaction->owner instanceof Wallet && $status === ApprovalStatus::APPROVED &&!in_array($transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) { + $this->updatesWalletBalance->execute($transaction->owner, $transaction->amount); + } + $this->updatesTransactionStatus->execute($transaction, $status); $totalPaidAmount = $invoice->transactions->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount'); @@ -109,18 +118,28 @@ class CallbackBillplzLogic if(($invoice->amount - $totalPaidAmount) < 0.01) { $this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED); - $packingList->status = ApprovalStatus::APPROVED; - $packingList->save(); + if(($invoice->amount - $totalPaidAmount) < 0.01) { + $this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED); - if(app()->environment('production')){ - $this->updateDoFromVTPortalProcessor->execute($packingList); - $this->updateDoFromYDPortalProcessor->execute($packingList); + $packingList->status = ApprovalStatus::APPROVED; + $packingList->save(); + + if(app()->environment('production')){ + $this->updateDoFromVTPortalProcessor->execute($packingList); + $this->updateDoFromYDPortalProcessor->execute($packingList); + } } } + $company_module_marking = $transaction->owner->owner->connections? $transaction->owner->owner->connections->first()->invitee_reference: null; + if ($transaction->owner instanceof Wallet) { + $company_module_marking = $transaction->owner->owner->connections? $transaction->owner->owner->connections->first()->invitee_reference: null; + } else { + $company_module_marking = $order->companyModule->connections? $order->companyModule->connections->first()->invitee_reference: null; + } - return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $order->reference, 'transaction' => $transaction, 'status' => $status]); + return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $order->reference ?? null, 'company_module_marking' => $company_module_marking ?? null, 'transaction' => $transaction, 'status' => $status]); } } diff --git a/app/Classes/Modules/Companies/ControllersLogic/ListCompanyModulesLogic.php b/app/Classes/Modules/Companies/ControllersLogic/ListCompanyModulesLogic.php index 6d7bbc26..8a6a616b 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/ListCompanyModulesLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/ListCompanyModulesLogic.php @@ -3,10 +3,14 @@ namespace App\Classes\Modules\Companies\ControllersLogic; +use App\Classes\Exceptions\AccessForbiddenException; +use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\RequestValidationException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Companies\Services\ListsCompanyModules; use App\Classes\Modules\Companies\Standards\Rules\CanListCompanies; use App\Http\Resources\CompanyModuleResource; +use App\Transformers\CompanyTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -17,7 +21,8 @@ class ListCompanyModulesLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Retrieved Company Moduels', 'message' => 'You have successfully retrieved a list of Companies' @@ -45,15 +50,26 @@ class ListCompanyModulesLogic extends AbstractControllerLogic /** * @param Request $request * @return JsonResponse - * @throws \App\Classes\Exceptions\AccessForbiddenException - * @throws \App\Classes\Exceptions\MalformedRequestException - * @throws \App\Classes\Exceptions\RequestValidationException + * @throws AccessForbiddenException + * @throws MalformedRequestException + * @throws RequestValidationException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $this->canListCompanies->passes(); $query = $this->listsCompanyModules->execute($this->listsCompanyModules->deserializeFilters($request->input('filters'))); + + /*include all relationships*/ +/* return fractal() + ->collection($query, new CompanyTransformer) + ->parseIncludes('company') + ->parseIncludes('contact') + ->parseIncludes('remarks') + ->parseIncludes('address') + ->parseIncludes('billingAddress') + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->collectionResponse(CompanyModuleResource::collection($query)); } diff --git a/app/Classes/Modules/Contacts/ControllersLogic/UpdateContactLogic.php b/app/Classes/Modules/Contacts/ControllersLogic/UpdateContactLogic.php index 2a78da13..6fef5379 100644 --- a/app/Classes/Modules/Contacts/ControllersLogic/UpdateContactLogic.php +++ b/app/Classes/Modules/Contacts/ControllersLogic/UpdateContactLogic.php @@ -8,6 +8,7 @@ use App\Classes\Modules\Contacts\Services\UpdatesContact; use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject; use App\Classes\Modules\Contacts\Services\FetchesContact; use App\Http\Resources\ContactResource; +use App\Transformers\ContactTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -63,6 +64,13 @@ class UpdateContactLogic extends AbstractControllerLogic $query = $this->updatesContact->execute($query, $object); + /*uniformity*/ + /* return fractal() + ->item($query, new ContactTransformer()) + ->parseIncludes('remark') + ->respond(200, [], JSON_PRETTY_PRINT);*/ + + return $this->resourceResponse(new ContactResource($query)); } diff --git a/app/Classes/Modules/Delivery/ControllersLogic/CancelDeliveryOrderLogic.php b/app/Classes/Modules/Delivery/ControllersLogic/CancelDeliveryOrderLogic.php index e52c966b..3501244d 100644 --- a/app/Classes/Modules/Delivery/ControllersLogic/CancelDeliveryOrderLogic.php +++ b/app/Classes/Modules/Delivery/ControllersLogic/CancelDeliveryOrderLogic.php @@ -7,6 +7,7 @@ use App\Classes\Modules\Orders\Services\CancelsOrder; use App\Classes\Modules\Orders\Services\FetchesOrder; use App\Http\Resources\DeliveryOrderResource; use App\Models\Order; +use App\Transformers\DeliveryOrderTransformer; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -52,6 +53,14 @@ class CancelDeliveryOrderLogic extends AbstractControllerLogic /** @var Order $order */ $order = $this->fetchesOrder->execute(['id' => $request->route('id')]); + $order = $this->cancelsOrder->execute($order); + + //no relationship needed + /* return fractal() + ->item($order, new DeliveryOrderTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + + return $this->resourceResponse(new DeliveryOrderResource($this->cancelsOrder->execute($order))); } diff --git a/app/Classes/Modules/Delivery/ControllersLogic/CreateDeliveryOrderLogic.php b/app/Classes/Modules/Delivery/ControllersLogic/CreateDeliveryOrderLogic.php index f27d1e59..cd478206 100644 --- a/app/Classes/Modules/Delivery/ControllersLogic/CreateDeliveryOrderLogic.php +++ b/app/Classes/Modules/Delivery/ControllersLogic/CreateDeliveryOrderLogic.php @@ -172,6 +172,12 @@ class CreateDeliveryOrderLogic extends AbstractControllerLogic $packageObject = new PackageObject($request->input('packing_list.type'), $request->input('packing_list.description'), (float) 1, (float) 1, (float) 1, $request->input('packing_list.weight'), (float) $request->input('packing_list.quantity'), ApprovalStatus::APPROVED); $this->createsPackage->execute($packageObject, $packingList); + //add relationship to order + /* return fractal() + ->item($order, new DeliveryOrderTransformer()) + ->parseIncludes(['sender_address', 'delivery_address', 'sender_address.contacts', 'delivery_address.contacts', 'sender_address.remarks', 'delivery_address.remarks', 'packing_list', 'packing_list.packages']) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new DeliveryOrderResource($order)); } diff --git a/app/Classes/Modules/Delivery/ControllersLogic/ListOrdersLogic.php b/app/Classes/Modules/Delivery/ControllersLogic/ListOrdersLogic.php index ae51f1b2..9d4d9a73 100644 --- a/app/Classes/Modules/Delivery/ControllersLogic/ListOrdersLogic.php +++ b/app/Classes/Modules/Delivery/ControllersLogic/ListOrdersLogic.php @@ -48,6 +48,12 @@ class ListOrdersLogic extends AbstractControllerLogic $query = $this->listsOrders->execute(array_merge($this->listsOrders->deserializeFilters($request->input('filters')), ['with_parcels' => true, 'type_in' => [OrderType::LAST_MILE_DELIVERY]])); + + //no relationship needed + /* return fractal() + ->collection($query, new DeliveryOrderTransformer) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->collectionResponse(DeliveryOrderResource::collection($query)); } diff --git a/app/Classes/Modules/Documents/ControllersLogic/ListDocumentLogic.php b/app/Classes/Modules/Documents/ControllersLogic/ListDocumentLogic.php index 0bd05743..64e4d88e 100644 --- a/app/Classes/Modules/Documents/ControllersLogic/ListDocumentLogic.php +++ b/app/Classes/Modules/Documents/ControllersLogic/ListDocumentLogic.php @@ -7,9 +7,13 @@ 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; +use App\Models\Document; +use App\Transformers\DocumentTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use League\Fractal; + class ListDocumentLogic extends AbstractControllerLogic { @@ -58,6 +62,11 @@ class ListDocumentLogic extends AbstractControllerLogic return $this->collectionResponse(DocumentResource::collection($query)); + + /* return fractal() + ->collection($query, new DocumentTransformer) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + } } \ No newline at end of file diff --git a/app/Classes/Modules/Exports/Services/ExportsWarehousePackingList.php b/app/Classes/Modules/Exports/Services/ExportsWarehousePackingList.php index d670e02e..647dcc1a 100644 --- a/app/Classes/Modules/Exports/Services/ExportsWarehousePackingList.php +++ b/app/Classes/Modules/Exports/Services/ExportsWarehousePackingList.php @@ -5,7 +5,6 @@ namespace App\Classes\Modules\Exports\Services; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\PackingListType; use App\Models\Order; -use App\Models\State; use Maatwebsite\Excel\Concerns\Exportable; use Maatwebsite\Excel\Concerns\FromQuery; use Maatwebsite\Excel\Concerns\WithHeadingRow; @@ -32,10 +31,8 @@ class ExportsWarehousePackingList implements FromQuery, WithHeadings, WithHeadin */ public function query() { - $johor_state_id = State::where('name', 'johor')->first()->id; - - return Order::whereHas('addresses', function($address) use ($johor_state_id){ - $address->where('status', ApprovalStatus::APPROVED)->where('state_id', $johor_state_id); + return Order::whereHas('addresses', function($address) { + $address->where('status', ApprovalStatus::APPROVED); })->whereHas('packingLists', function($packingLists) { $packingLists->where('type', PackingListType::SHIPPING_PACKING_LIST)->whereDoesntHave('transports'); }); diff --git a/app/Classes/Modules/Orders/ControllersLogic/ApproveChangeOrderAddressLogic.php b/app/Classes/Modules/Orders/ControllersLogic/ApproveChangeOrderAddressLogic.php index 0b469fd1..1b6668a7 100644 --- a/app/Classes/Modules/Orders/ControllersLogic/ApproveChangeOrderAddressLogic.php +++ b/app/Classes/Modules/Orders/ControllersLogic/ApproveChangeOrderAddressLogic.php @@ -6,6 +6,7 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Orders\Processors\ApproveChangeOrderAddressProcessor; use App\Http\Resources\AddressResource; use App\Http\Resources\OrderResource; +use App\Transformers\AddressTransformer; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; @@ -39,6 +40,12 @@ class ApproveChangeOrderAddressLogic extends AbstractControllerLogic { $address = $this->approveChangeOrderAddressProcessor->execute($request); + + //load address with no relationships + /* return fractal() + ->item($address, new AddressTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new AddressResource($address)); } } diff --git a/app/Classes/Modules/Orders/ControllersLogic/CreateOrderLogic.php b/app/Classes/Modules/Orders/ControllersLogic/CreateOrderLogic.php index 3aded198..08462099 100644 --- a/app/Classes/Modules/Orders/ControllersLogic/CreateOrderLogic.php +++ b/app/Classes/Modules/Orders/ControllersLogic/CreateOrderLogic.php @@ -4,14 +4,20 @@ namespace App\Classes\Modules\Orders\ControllersLogic; use App\Classes\Exceptions\RequestValidationException; use App\Classes\General\Abstracts\AbstractControllerLogic; +use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject; +use App\Classes\Modules\Addresses\Services\CreatesAddress; use App\Classes\Modules\Addresses\Services\FetchesAddress; use App\Classes\Modules\Companies\Services\FetchesCompany; use App\Classes\Modules\Companies\Services\FetchesCompanyModule; use App\Classes\Modules\PerfexCRM\Processors\NewLeadTaskToPerfexCRMProcessor; use App\Classes\Modules\Orders\Processors\CreateOrderProcessor; use App\Classes\Modules\Orders\Services\GeneratesOrderNumber; +use App\Classes\ValueObjects\Constants\AddressType; +use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\WarehouseReferences; use App\Http\Resources\OrderResource; +use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress; +use App\Models\Address; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; @@ -41,6 +47,12 @@ class CreateOrderLogic extends AbstractControllerLogic /** @var GeneratesOrderNumber */ private $generatesOrderNumber; + /** @var CreatesAddress */ + private $createsAddress; + + /** @var CanCreateAddress */ + private $canCreateAddress; + /** @var NewLeadTaskToPerfexCRMProcessor */ private $newLeadTaskToPerfexCRMProcessor; /** @@ -51,14 +63,18 @@ class CreateOrderLogic extends AbstractControllerLogic * @param FetchesCompanyModule $fetchesCompanyModule * @param GeneratesOrderNumber $generatesOrderNumber * @param NewLeadTaskToPerfexCRMProcessor $newLeadTaskToPerfexCRMProcessor + * @param CreatesAddress $createsAddress + * @param CanCreateAddress $canCreateAddress */ - public function __construct(FetchesCompany $fetchesCompany, FetchesAddress $fetchesAddress, CreateOrderProcessor $createOrderProcessor, FetchesCompanyModule $fetchesCompanyModule, GeneratesOrderNumber $generatesOrderNumber, NewLeadTaskToPerfexCRMProcessor $newLeadTaskToPerfexCRMProcessor) + public function __construct(FetchesCompany $fetchesCompany, FetchesAddress $fetchesAddress, CreateOrderProcessor $createOrderProcessor, FetchesCompanyModule $fetchesCompanyModule, GeneratesOrderNumber $generatesOrderNumber, CreatesAddress $createsAddress, CanCreateAddress $canCreateAddress, NewLeadTaskToPerfexCRMProcessor $newLeadTaskToPerfexCRMProcessor) { $this->fetchesCompany = $fetchesCompany; $this->fetchesAddress = $fetchesAddress; $this->createOrderProcessor = $createOrderProcessor; $this->fetchesCompanyModule = $fetchesCompanyModule; $this->generatesOrderNumber = $generatesOrderNumber; + $this->createsAddress = $createsAddress; + $this->canCreateAddress = $canCreateAddress; $this->newLeadTaskToPerfexCRMProcessor = $newLeadTaskToPerfexCRMProcessor; } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/AssignPackingListContainerLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/AssignPackingListContainerLogic.php index 33310711..9931d785 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/AssignPackingListContainerLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/AssignPackingListContainerLogic.php @@ -6,6 +6,7 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer; use App\Classes\Modules\PackingLists\Services\FetchesPackingList; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -56,6 +57,13 @@ class AssignPackingListContainerLogic extends AbstractControllerLogic $container->packingLists()->attach($packing_list_item); } + //only return with packing list relationship + + /* return fractal() + ->item($container, new ContainerTransformer()) + ->parseInclude(['packingLists']) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new ContainerResource($container)); } catch (\Exception $exception){ diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CompleteContainerLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CompleteContainerLogic.php index 7720fc27..cde367d3 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CompleteContainerLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CompleteContainerLogic.php @@ -8,6 +8,7 @@ use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -19,7 +20,8 @@ class CompleteContainerLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Updated Container', 'message' => 'You have successfully updated the Container' @@ -51,10 +53,16 @@ class CompleteContainerLogic extends AbstractControllerLogic * @return JsonResponse * @throws ErrorException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $container = $this->fetchesContainer->execute(['id' => $request->route('id')]); $query = $this->updatesContainerStatus->execute($container, ApprovalStatus::COMPLETED); + + //no relationships needed +/* return fractal() + ->item($container, new ContainerTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new ContainerResource($container)); } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateContainerLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateContainerLogic.php index df22a66e..c9c6ba86 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateContainerLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateContainerLogic.php @@ -11,6 +11,7 @@ use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject; use App\Classes\Modules\PackingLists\Services\FetchesPackingList; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -70,6 +71,11 @@ class CreateContainerLogic extends AbstractControllerLogic $query = $this->createsContainer->execute($object, $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')])); + //no relationship needed + /* return fractal() + ->item($query, new ContainerTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new ContainerResource($query)); } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateContainerRemarkLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateContainerRemarkLogic.php index f35b828e..9d8d35cf 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateContainerRemarkLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateContainerRemarkLogic.php @@ -8,6 +8,7 @@ use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer; use App\Classes\Modules\Remarks\DataTransferObjects\RemarkObject; use App\Classes\Modules\Remarks\Processors\CreateRemarkProcessor; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -18,7 +19,8 @@ class CreateContainerRemarkLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Created Container Remark', 'message' => 'You have successfully created a new Container Remark' @@ -50,7 +52,7 @@ class CreateContainerRemarkLogic extends AbstractControllerLogic * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $container = $this->fetchesContainer->execute(['id' => $request->route('id')]); @@ -59,6 +61,12 @@ class CreateContainerRemarkLogic extends AbstractControllerLogic $this->createRemarkProcessor->execute($container, $object); + //load with remarks only + /* return fractal() + ->item($container, new ContainerTransformer()) + ->parseIncludes(['remarks']) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new ContainerResource($container)); } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateLoadContainerLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateLoadContainerLogic.php index 30fec0d4..36bc51e3 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateLoadContainerLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/CreateLoadContainerLogic.php @@ -17,6 +17,7 @@ use App\Classes\ValueObjects\Constants\TransportType; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -28,7 +29,8 @@ class CreateLoadContainerLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Created Container', 'message' => 'You have successfully created a new Container' @@ -41,7 +43,7 @@ class CreateLoadContainerLogic extends AbstractControllerLogic /** @var FetchesPackingList */ private $fetchesPackingList; - /** @var FetchesCompanyModule */ + /** @var FetchesCompanyModule */ private $fetchesCompanyModule; /** @var CreatesPackingList */ @@ -54,12 +56,12 @@ class CreateLoadContainerLogic extends AbstractControllerLogic private $createsSchedule; public function __construct( - CanCreateContainer $canCreateContainer, - FetchesPackingList $fetchesPackingList, - FetchesCompanyModule $fetchesCompanyModule, - CreatesContainer $createsContainer, - CreatesTransport $createsTransport, - CreatesSchedule $createsSchedule + CanCreateContainer $canCreateContainer, + FetchesPackingList $fetchesPackingList, + FetchesCompanyModule $fetchesCompanyModule, + CreatesContainer $createsContainer, + CreatesTransport $createsTransport, + CreatesSchedule $createsSchedule ) { $this->canCreateContainer = $canCreateContainer; @@ -77,11 +79,11 @@ class CreateLoadContainerLogic extends AbstractControllerLogic * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $object = new ContainerObject( - $request->input('container_reference'), - $request->input('container_number'), + $request->input('container_reference'), + $request->input('container_number'), $request->input('seal_reference'), $request->input('container_type'), ApprovalStatus::APPROVED @@ -92,21 +94,27 @@ class CreateLoadContainerLogic extends AbstractControllerLogic $container = $this->createsContainer->execute($object, $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')])); $transportObject = new TransportObject( - TransportType::LAND, null, - $request->input('tracking'), - Carbon::parse($request->input('etd')), - Carbon::parse($request->input('eta')), + TransportType::LAND, null, + $request->input('tracking'), + Carbon::parse($request->input('etd')), + Carbon::parse($request->input('eta')), ApprovalStatus::APPROVED ); $transport = $this->createsTransport->execute($transportObject, $container); $scheduleObject = new ScheduleObject( - Carbon::parse($request->input('etd')), + Carbon::parse($request->input('etd')), Carbon::parse($request->input('eta')), ApprovalStatus::APPROVED - ); + ); $schedule = $this->createsSchedule->execute($transport, $scheduleObject); + //include transport + /* return fractal() + ->item($container, new ContainerTransformer()) + ->parseIncludes(['transport']) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new ContainerResource($container)); } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/FetchContainerLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/FetchContainerLogic.php index f1f46eb1..b3ea17e5 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/FetchContainerLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/FetchContainerLogic.php @@ -7,6 +7,7 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer; use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanFetchContainer; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -17,7 +18,8 @@ class FetchContainerLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Retrieved Container', 'message' => 'You have successfully retrieved a Container' @@ -48,12 +50,18 @@ class FetchContainerLogic extends AbstractControllerLogic * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\RequestValidationException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $this->canFetchContainer->passes(); $query = $this->fetchesContainer->execute(['id' => $request->route('id'), 'with_packing_lists' => true]); + //load with packing lists +/* return fractal() + ->item($query, new ContainerTransformer()) + ->parseIncludes(['packing_lists']) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new ContainerResource($query)); } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/InboundCustomClearedLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/InboundCustomClearedLogic.php index 08af0bb7..e69fb995 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/InboundCustomClearedLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/InboundCustomClearedLogic.php @@ -9,6 +9,7 @@ use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanListContainer use App\Classes\Modules\PackingLists\Processors\FetchInboundCustomClearedProcessor; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -19,7 +20,8 @@ class InboundCustomClearedLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Retrieved Containers', 'message' => 'You have successfully retrieved a list of Containers' @@ -52,11 +54,16 @@ class InboundCustomClearedLogic extends AbstractControllerLogic * @return JsonResponse * @throws ErrorException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $query = $this->fetchInboundCustomCleared->execute(); + //no relations required + /* return fractal() + ->item($query, new ContainerTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->collectionResponse(ContainerResource::collection($query)); } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/ListContainersLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/ListContainersLogic.php index fc525322..cb47ba88 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/ListContainersLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/ListContainersLogic.php @@ -3,10 +3,14 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic\Containers; +use App\Classes\Exceptions\AccessForbiddenException; +use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\RequestValidationException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\PackingLists\Services\Containers\ListsContainers; use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanListContainers; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -17,7 +21,8 @@ class ListContainersLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Retrieved Containers', 'message' => 'You have successfully retrieved a list of Containers' @@ -45,16 +50,22 @@ class ListContainersLogic extends AbstractControllerLogic /** * @param Request $request * @return JsonResponse - * @throws \App\Classes\Exceptions\AccessForbiddenException - * @throws \App\Classes\Exceptions\MalformedRequestException - * @throws \App\Classes\Exceptions\RequestValidationException + * @throws AccessForbiddenException + * @throws MalformedRequestException + * @throws RequestValidationException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $this->canListContainers->passes(); $query = $this->listsContainers->execute($this->listsContainers->deserializeFilters($request->input('filters'))); + //load with no filters, a details page to be added to load one with all related data +/* return fractal() + ->collection($query, new ContainerTransformer) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + + return $this->collectionResponse(ContainerResource::collection($query)); } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/RescheduleContainerLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/RescheduleContainerLogic.php index b3638b90..f0214cba 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/RescheduleContainerLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/RescheduleContainerLogic.php @@ -10,6 +10,7 @@ use App\Classes\Modules\Schedules\DataTransferObjects\ScheduleObject; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -20,7 +21,8 @@ class RescheduleContainerLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Reschedule Container', 'message' => 'You have successfully Reschedule Container' @@ -54,7 +56,7 @@ class RescheduleContainerLogic extends AbstractControllerLogic * @return JsonResponse * @throws ErrorException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { try { $container = $this->fetchesContainer->execute(['id' => $request->route('id')]); @@ -65,15 +67,20 @@ class RescheduleContainerLogic extends AbstractControllerLogic $this->updatesScheduleStatus->execute($old_sechedule, ApprovalStatus::REJECTED); $scheduleObject = new ScheduleObject( - Carbon::parse($request->input('etd')), - Carbon::parse($request->input('eta')), + Carbon::parse($request->input('etd')), + Carbon::parse($request->input('eta')), ApprovalStatus::APPROVED - ); + ); $schedule = $this->createsSchedule->execute($transport, $scheduleObject); + //no relationship + /* return fractal() + ->item($container, new ContainerTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new ContainerResource($container)); - } catch (\Exception $exception){ + } catch (\Exception $exception) { throw new ErrorException($exception->getMessage(), $exception->getCode()); } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateContainerLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateContainerLogic.php index 75eeddae..e4876a80 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateContainerLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateContainerLogic.php @@ -3,12 +3,16 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic\Containers; +use App\Classes\Exceptions\AccessForbiddenException; +use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\RequestValidationException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\PackingLists\Services\Containers\UpdatesContainer; use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer; use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanUpdateContainer; use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -19,7 +23,8 @@ class UpdateContainerLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Updated Container', 'message' => 'You have successfully updated the Container' @@ -52,19 +57,19 @@ class UpdateContainerLogic extends AbstractControllerLogic /** * @param Request $request * @return JsonResponse - * @throws \App\Classes\Exceptions\AccessForbiddenException - * @throws \App\Classes\Exceptions\MalformedRequestException - * @throws \App\Classes\Exceptions\RequestValidationException + * @throws AccessForbiddenException + * @throws MalformedRequestException + * @throws RequestValidationException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $container = $this->fetchesContainer->execute(['id' => $request->route('id')]); - - $object = new ContainerObject( - $request->input('container_reference'), - $container->container_number, - $request->input('container_type'), + + $object = new ContainerObject( + $request->input('container_reference'), + $container->container_number, + $request->input('container_type'), $request->input('seal_reference'), $request->input('loading_date'), $container->status, @@ -74,6 +79,12 @@ class UpdateContainerLogic extends AbstractControllerLogic $query = $this->updatesContainer->execute($container, $object); + //no relationships +/* + return fractal() + ->item($query, new ContainerTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new ContainerResource($query)); } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateDispatchDateContainerLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateDispatchDateContainerLogic.php index 7b091fb6..9fa85b6a 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateDispatchDateContainerLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateDispatchDateContainerLogic.php @@ -6,6 +6,7 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Transports\Services\UpdatesDispatchDateTransport; use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -17,7 +18,8 @@ class UpdateDispatchDateContainerLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Updated Dispatch Date Container', 'message' => 'You have successfully updated the Dispatch Date Container' @@ -49,11 +51,18 @@ class UpdateDispatchDateContainerLogic extends AbstractControllerLogic * @return JsonResponse * @throws ErrorException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $container = $this->fetchesContainer->execute(['id' => $request->route('id')]); $transport = $container->transports()->first(); $query = $this->updatesDispatchDateTransport->execute($transport, Carbon::parse($request->input('dispatch_date'))); + + + //no relationships queried + /* return fractal() + ->item($query, new ContainerTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new ContainerResource($container)); } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateDropDateContainerLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateDropDateContainerLogic.php index 56d4d9b5..d55e24bb 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateDropDateContainerLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Containers/UpdateDropDateContainerLogic.php @@ -6,6 +6,7 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Transports\Services\UpdatesDropDateTransport; use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer; use App\Http\Resources\ContainerResource; +use App\Transformers\ContainerTransformer; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -17,7 +18,8 @@ class UpdateDropDateContainerLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Updated Drop Date Container', 'message' => 'You have successfully updated the Drop Date Container' @@ -49,11 +51,17 @@ class UpdateDropDateContainerLogic extends AbstractControllerLogic * @return JsonResponse * @throws ErrorException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $container = $this->fetchesContainer->execute(['id' => $request->route('id')]); $transport = $container->transports()->first(); $query = $this->updatesDropDateTransport->execute($transport, Carbon::parse($request->input('drop_date'))); + + //no relationship needed + /* return fractal() + ->item($query, new ContainerTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + return $this->resourceResponse(new ContainerResource($container)); } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/CreateDeliverPackingListLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/CreateDeliverPackingListLogic.php index 0e24c9ed..e657852b 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/CreateDeliverPackingListLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/CreateDeliverPackingListLogic.php @@ -14,6 +14,7 @@ use App\Classes\ValueObjects\Constants\OrderRoleTypes; use App\Classes\ValueObjects\Constants\PackingListType; use App\Http\Resources\DeliverPackingListResource; +use App\Transformers\DeliverPackingListTransformer; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -24,7 +25,8 @@ class CreateDeliverPackingListLogic extends AbstractControllerLogic /** * @return array */ - protected function notification():array { + protected function notification(): array + { return [ 'title' => 'Created Deliver PackingList', 'message' => 'You have successfully created a new Deliver PackingList' @@ -60,7 +62,7 @@ class CreateDeliverPackingListLogic extends AbstractControllerLogic * @param Request $request * @return JsonResponse */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request): JsonResponse { $company_module = $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]); $packing_list_id = $request->input('packing_list_id'); @@ -68,9 +70,9 @@ class CreateDeliverPackingListLogic extends AbstractControllerLogic $reference_number = $this->generatesPackingListReferenceNumber->execute(); $packingListObject = new PackingListObject( - $reference_number, - null, - PackingListType::DELIVERY_PACKING_LIST, + $reference_number, + null, + PackingListType::DELIVERY_PACKING_LIST, ApprovalStatus::PENDING_SUBMISSION ); @@ -82,6 +84,12 @@ class CreateDeliverPackingListLogic extends AbstractControllerLogic $deliverPackingList->packing_list_owner()->sync($packing_list_id); + //no relationships required + /* return fractal() + ->item($deliverPackingList, new DeliverPackingListTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + + return $this->resourceResponse(new DeliverPackingListResource($deliverPackingList)); } diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateCombinedInvoicesLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateCombinedInvoicesLogic.php new file mode 100644 index 00000000..93a3a0f9 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateCombinedInvoicesLogic.php @@ -0,0 +1,104 @@ + 'Shipping Invoice Status', + 'message' => 'You have successfully updated multiple shipping invoices status' + ]; + } + + /** @var FetchesPackingList */ + private $fetchesPackingList; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFiles; + + /** + * ApprovePaymentVerificationLogic constructor. + * @param FetchesPackingList $fetchesPackingList + * @param UpdatesTransactionStatus $updatesTransactionStatus + * @param CreatesDocument $createsDocument + * @param CreatesFiles $createsFiles + * @param CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor + */ + public function __construct(FetchesPackingList $fetchesPackingList, UpdatesTransactionStatus $updatesTransactionStatus, CreatesDocument $createsDocument, CreatesFiles $createsFiles) + { + $this->fetchesPackingList = $fetchesPackingList; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->createsDocument = $createsDocument; + $this->createsFiles = $createsFiles; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $items = $request->input('ids'); + $invoice_transactions=array(); + foreach($items as $item){ + + $packing_list = $this->fetchesPackingList->execute(['id' => $item['id']]); + + $invoice_transaction = $packing_list->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::PENDING_SUBMISSION])->first(); + array_push($invoice_transactions, $invoice_transaction); + + // $this->updatesTransactionStatus->execute($invoice_transaction, ApprovalStatus::APPROVED); + } + + $transaction_invoice_pdf = LaravelMpdf::loadView('pages.pdfs.shipping_invoices_combined', ['invoice_transactions' => $invoice_transactions]); + + $document_object = new DocumentObject( + DocumentType::SHIPPING_INVOICE, + [chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))], + '', + ApprovalStatus::COMPLETED, + 'shipping_invoice' + ); + + /** @var Document $document */ + $document = $this->createsDocument->execute($invoice_transaction, $document_object); + + $this->createsFiles->execute($document, $document_object); + $user = $packing_list->owner->companyModule->employees()->first(); + if(app()->environment(['production'])) { + $user->notify(new InvoiceIssuedEmail($user, $packing_list)); + } + + return $this->response([]); + } + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php new file mode 100644 index 00000000..e5d46f1b --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php @@ -0,0 +1,254 @@ + 'Create Group Transaction', + 'message' => 'You have successfully created a group transaction' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesTransactionableTransaction */ + private $createsTransactionableTransaction; + + /** @var CreatesBillplzBill */ + private $createsBillplzBill; + + /** @var UpdatesWalletBalance */ + private $updatesWalletBalance; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var CreatesPaymentTransaction */ + private $createsPaymentTransaction; + + /** @var UpdateDoFromVTPortalProcessor */ + private $updateDoFromVTPortalProcessor; + + /** @var UpdateDoFromYDPortalProcessor */ + private $updateDoFromYDPortalProcessor ; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus ; + + public function __construct( + FetchesTransaction $fetchesTransaction, + GeneratesTransactionBillNumber $generatesTransactionBillNumber, + CreatesTransactionableTransaction $createsTransactionableTransaction, + CreatesBillplzBill $createsBillplzBill, + UpdatesWalletBalance $updatesWalletBalance, + CreatesTransaction $createsTransaction, + CreatesPaymentTransaction $createsPaymentTransaction, + UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, + UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, + UpdatesTransactionStatus $updatesTransactionStatus + ) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransactionableTransaction = $createsTransactionableTransaction; + $this->createsBillplzBill = $createsBillplzBill; + $this->updatesWalletBalance = $updatesWalletBalance; + $this->createsPaymentTransaction = $createsPaymentTransaction; + $this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor; + $this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor; + $this->updatesTransactionStatus = $updatesTransactionStatus; + } + + public function logic(Request $request) : JsonResponse + { + $invoice_ids = json_decode($request->route('transaction_ids')); + $billNumber = $this->generatesTransactionBillNumber->execute('PYMT-'); + $approvalStatus = ApprovalStatus::PENDING_SUBMISSION; + $payment_method = PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')]; + + if (count($invoice_ids) > 1) { + dd('more than 1 invoice'); + // creates group transaction + $group = new Group(); + + $issuer = ''; + $receiver = ''; + $amount = 0; + $original_amount = 0; + $currency_id = 0; + $original_currency_id = ''; + $currency_rate = ''; + $tax = 0; + $service_charge = 0; + + // todo-new: check why is this not working + // $invoices = $this->fetchesTransaction->execute(['id_in' => $invoice_ids]); + $invoices = Transaction::whereIn('id', $invoice_ids)->get(); + + foreach ($invoices as $invoice) { + // todo-new: attach transaction to the group id + // create one payment for each, then mark as pending_approval + $issuer = $invoice->issuer; + $receiver = $invoice->receiver; + $amount += $invoice->amount; + $original_amount += $invoice->original_amount; + $currency_id = $invoice->currency_id; + $original_currency_id = $invoice->original_currency_id; + $currency_rate = $invoice->currency_rate; + $tax += $invoice->tax; + $service_charge += $invoice->service_charge; + } + + $group->issuer = $issuer; + $group->receiver = $receiver; + $group->reference = $billNumber; + $group->amount = $amount; + $group->original_amount = $original_amount; + $group->currency_id = $currency_id; + $group->original_currency_id = $original_currency_id; + $group->currency_rate = $currency_rate; + $group->tax = $tax; + $group->service_charge = $service_charge; + + $group->save(); + + + // attach payment on group transaction + + // $invoice_transaction = $this->fetchesTransaction->execute(['id' => $invoice_ids->first()]); + // $amount = $request->input('amount'); + // $company_module = $invoice_transaction->owner()->first()->owner()->first()->companyModule()->first(); + + $invoice_transaction = $group; + $transferDetails = $billNumber; + $company_module = $group->receiverCompany; + } else { + + $invoice_transaction = $this->fetchesTransaction->execute(['id' => $invoice_ids[0]]); + $amount = $request->input('amount'); + $company_module = $invoice_transaction->owner()->first()->owner()->first()->companyModule()->first(); + $transferDetails = $invoice_transaction->bill_no; + } + + $payment_reference = null; + if ($payment_method == PaymentMethodType::PAYMENT_GATEWAY) { + + // create billplz transaction + $payment_method = PaymentMethodType::PAYMENT_GATEWAY; + $billPlzBill = $this->createsBillplzBill->execute( + $company_module->name, + (app()->environment(['production'])) ? $company_module->employees()->first()->email : 'uldvstar@gmail.com', + 'This payment is for the invoice number . ' . $transferDetails, + $amount, + $billNumber, + $request->input('bank_code'), + true + ); + + $payment_reference = $billPlzBill->id; + } + else if ($payment_method === PaymentMethodType::WALLET) { + /** @var Wallet $wallet */ + $wallet = $company_module->wallets()->first(); + + if((float) number_format(($wallet->amount - $amount),2) < 0){ + throw new MalformedRequestException('Insufficient wallet balance. Please Top up your wallet.'); + } + + $walletPaymentBillNumber = $this->generatesTransactionBillNumber->execute('PYMT-'); + + $transaction_object = new TransactionObject($walletPaymentBillNumber, TransactionType::PAYMENT, 1, $company_module->id, 1, PaymentMethodType::WALLET, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], ''); + $transaction = $this->createsTransactionableTransaction->execute($wallet, $transaction_object); + + $payment_reference = $walletPaymentBillNumber; + + $this->updatesWalletBalance->execute($wallet, ($amount * -1)); + + if (count($invoice_ids) > 1) { + // do one by one + // dd($invoices); + // todo-new: update all the transaction inside + } else { + // $invoice_transaction; + $packingList = $invoice_transaction->owner; + $order = $packingList->owner; + $packingList->status = ApprovalStatus::APPROVED; + $packingList->save(); + } + + if(app()->environment('production')){ + $this->updateDoFromVTPortalProcessor->execute($packingList); + $this->updateDoFromYDPortalProcessor->execute($packingList); + } + + $approvalStatus = ApprovalStatus::APPROVED; + + // update invoice to completed + $this->updatesTransactionStatus->execute($invoice_transaction, ApprovalStatus::COMPLETED); + } + else { + $payment_method = PaymentMethodType::CASH; + } + + // createsPaymentTransaction + $object = new TransactionObject( + $billNumber, + TransactionType::PAYMENT, + $company_module->id, + 1, + 1, + $payment_method, + $request->input('amount'), + $request->input('amount'), + 1, + 1, + 0, + 0, + 0, + null, + $approvalStatus, + null, + $payment_reference + ); + + $payment_transaction = $this->createsPaymentTransaction->execute($invoice_transaction, $object); + + return $this->resourceResponse(new TransactionResource($payment_transaction)); + } +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php new file mode 100644 index 00000000..94ede815 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php @@ -0,0 +1,79 @@ + 'Delete Group Transaction', + 'message' => 'You have successfully deleted this Group Transaction' + ]; + } + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var FetchesGroup */ + private $fetchesGroup; + + /** @var DeletesTransaction */ + private $deletesTransaction; + + /** + * DeleteGroupLogic constructor. + * @param updatesTransactionStatus $updatesTransactionStatus + * @param FetchesGroup $fetchesGroup + * @param DeletesTransaction $deletesTransaction + */ + public function __construct(updatesTransactionStatus $updatesTransactionStatus, FetchesGroup $fetchesGroup, DeletesTransaction $deletesTransaction) + { + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->fetchesGroup = $fetchesGroup; + $this->deletesTransaction = $deletesTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $group = $this->fetchesGroup->execute(['id' => $request->route('id')]); + + $items = $group->transactions()->get(); + + foreach($items as $item) { + $bill = $item; + $payment = $bill->owner; + $group->transactions()->detach($bill->id); + $this->updatesTransactionStatus->execute($payment, ApprovalStatus::APPROVED); + $this->deletesTransaction->execute($bill); + } + + $group->delete(); + + //no relationship needed + /* return fractal() + ->item($group, new GroupTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + + return $this->resourceResponse(new GroupResource($group)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php new file mode 100644 index 00000000..c03136a9 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php @@ -0,0 +1,49 @@ +listsGroups = $listsGroups; + } + + /** + * @return array + */ + protected function notification(): array + { + return [ + 'title' => 'Retrieved Groups', + 'message' => 'You have successfully retrieved a list of groups' + ]; + } + + /** @var ListsGroups */ + private $listsGroups; + + public function logic(Request $request): JsonResponse + { + $query = $this->listsGroups->execute($this->listsGroups->deserializeFilters($request->input('filters'))); + + //no relationship needed + /* return fractal() + ->collection($query, new GroupTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + + return $this->collectionResponse(GroupResource::collection($query)); + } + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/RegenerateShippingInvoiceTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/RegenerateShippingInvoiceTransactionLogic.php new file mode 100644 index 00000000..8922e651 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/RegenerateShippingInvoiceTransactionLogic.php @@ -0,0 +1,78 @@ + 'Regenerate Shipping Invoice', + 'message' => 'You have successfully regenerated shipping invoice' + ]; + } + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFiles; + + /** + * @param CreatesDocument $createsDocument + */ + public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles) + { + $this->createsDocument = $createsDocument; + $this->createsFiles = $createsFiles; + } + + public function logic(Request $request) : JsonResponse + { + + $orders = Order::where('company_module_id', $request->route('company_module_id'))->get(); + + foreach ($orders as $order){ + $invoices = $order->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->get(); + foreach ($invoices as $invoice){ + + $invoice->documents()->delete(); + + $transaction_invoice_pdf = LaravelMpdf::loadView('pages.pdfs.shipping_invoice', ['invoice_transaction' => $invoice]); + + $document_object = new DocumentObject( + DocumentType::SHIPPING_INVOICE, + [chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))], + '', + ApprovalStatus::COMPLETED, + 'shipping_invoice' + ); + + $document =$this->createsDocument->execute($invoice, $document_object); + + $this->createsFiles->execute($document, $document_object); + + // dump($document); + } + } + + return $this->response([]); + } + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php new file mode 100644 index 00000000..801a7818 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php @@ -0,0 +1,191 @@ + 'Update Group Transaction', + 'message' => 'You have successfully updated this Group Transaction' + ]; + } + + /** @var FetchesGroup */ + private $fetchesGroup; + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var CalculatesTransactionServiceCharge */ + private $calculatesTransactionServiceCharge; + + /** @var UpdatesTransaction */ + private $updatesTransaction; + + /** @var CalculatesTransactionTransferFee */ + private $calculatesTransactionTransferFee; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFile; + + /** + * UpdateGroupLogic constructor. + * @param FetchesGroup $fetchesGroup + * @param FetchesCompany $fetchesCompany + * @param CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge + * @param UpdatesTransaction $updatesTransaction + * @param CalculatesTransactionTransferFee $calculatesTransactionTransferFee + * @param CreatesDocument $createsDocument + * @param CreatesFiles $createsFile + */ + public function __construct(FetchesGroup $fetchesGroup, FetchesCompany $fetchesCompany, CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, UpdatesTransaction $updatesTransaction, CalculatesTransactionTransferFee $calculatesTransactionTransferFee, CreatesDocument $createsDocument, CreatesFiles $createsFile) + { + $this->fetchesGroup = $fetchesGroup; + $this->fetchesCompany = $fetchesCompany; + $this->calculatesTransactionServiceCharge = $calculatesTransactionServiceCharge; + $this->updatesTransaction = $updatesTransaction; + $this->calculatesTransactionTransferFee = $calculatesTransactionTransferFee; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request): JsonResponse + { + $group = $this->fetchesGroup->execute(['id' => $request->route('id')]); + + $transactions = $group->transactions()->get(); + + $rate = $request->input('rate'); + + $supplier = $this->fetchesCompany->execute(['id' => $request->input('supplier_id')]); + +// $group->transactions()->update(['issuer' => $supplier->id, 'currency_rate' => $rate]); +// $group->transactions()->update(['amount' => DB::raw('(original_amount * (1 / currency_rate)) + service_charge + tax')]); + + + foreach ($transactions as $transaction) { + + $constant = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $supplier->id)->first(); + $serviceCharge = $this->calculatesTransactionServiceCharge->execute($transaction->original_amount, $rate, $constant); + + $object = new TransactionObject( + $transaction->bill_no, + TransactionType::BILL, + $supplier->id, + 1, + $supplier->banks()->where('default', true)->first()->id, + PaymentMethodType::CASH, + $transaction->original_amount * (1 / $rate), + $transaction->original_amount, + 1, + $transaction->original_currency_id, + $rate, + 0, + $serviceCharge, + null, + ApprovalStatus::PENDING_VERIFICATION + ); + + $billTransaction = $this->updatesTransaction->execute($transaction, $object); + + $transferTransaction = $transaction->transactions()->where('type', TransactionType::TRANSFER_FEE)->first(); + + $transferFee = $this->calculatesTransactionTransferFee->execute($billTransaction->original_amount, $constant); + + $object = new TransactionObject( + $transferTransaction->bill_no, + TransactionType::TRANSFER_FEE, + $supplier->id, + 1, + $supplier->banks()->where('default', true)->first()->id, + PaymentMethodType::CASH, + $transaction->original_amount, + $transaction->original_amount, + $transaction->original_currency_id, + $transaction->original_currency_id, + 1, + 0, + $transferFee, + null, + ApprovalStatus::PENDING_VERIFICATION + ); + + $this->updatesTransaction->execute($transferTransaction, $object); + } + + $group->issuer = $supplier->id; + $group->amount = $group->transactions()->sum('amount'); + $group->currency_rate = $rate; + $group->tax = $group->transactions()->sum('tax'); + $group->service_charge = $group->transactions()->sum('service_charge'); + + $group->save(); + + $group->documents()->delete(); + + $transferFeeTransactions = $group->transactions()->with([ + 'transactions' => function ($transaction) { + return $transaction->where('type', TransactionType::TRANSFER_FEE); + }])->get()->pluck('transactions')->flatten(); + + $pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $group->transactions, 'transferFeeTransactions' => $transferFeeTransactions, 'supplier' => $supplier]); + + $object = new DocumentObject( + DocumentType::CURRENCY_VENDOR_ORDER, + [chunk_split('data:application/pdf;base64,' . base64_encode($pdf->output()))], + '', + ApprovalStatus::COMPLETED, + 'currency_vendor_order' + ); + + /** @var Document $document */ + $document = $this->createsDocument->execute($group, $object); + $this->createsFile->execute($document, $object); + + //no relationship needed + /* return fractal() + ->item($group, new GroupTransformer()) + ->respond(200, [], JSON_PRETTY_PRINT);*/ + + return $this->resourceResponse(new GroupResource($group)); + } + +} diff --git a/app/Classes/Modules/Transactions/Processors/UpdateWalletTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/UpdateWalletTransactionProcessor.php new file mode 100644 index 00000000..a016db80 --- /dev/null +++ b/app/Classes/Modules/Transactions/Processors/UpdateWalletTransactionProcessor.php @@ -0,0 +1,71 @@ +fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->updatesWallet = $updatesWallet; + } + + + /** + * @param Booking $booking + * @return void + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(int $transactionId, int $transactionStatus) + { + + $transaction = $this->fetchesTransaction->execute(['id' => $transactionId]); + $wallet = $transaction->wallet; + + switch($transaction->type){ + case TransactionType::TOP_UP: + $updateWalletAmount = $transaction->amount + $wallet->amount; + break; + case TransactionType::WITHDRAW: + $updateWalletAmount = $wallet->amount - $transaction->amount; + break; + default: + break; + } + + $walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); + + $this->updatesTransactionStatus->execute($transaction, $transactionStatus); + + $this->updatesWallet->execute($wallet, $walletOject); + + return $wallet; + } +} diff --git a/app/Classes/Modules/Transactions/Services/CreatesTransactionableTransaction.php b/app/Classes/Modules/Transactions/Services/CreatesTransactionableTransaction.php new file mode 100644 index 00000000..373343d6 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CreatesTransactionableTransaction.php @@ -0,0 +1,40 @@ +bill_no = $object->getBillNo(); + $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->original_amount = $object->getOriginalAmount(); + $model->currency_id = $object->getCurrencyId(); + $model->original_currency_id = $object->getOriginalCurrencyId(); + $model->currency_rate = $object->getCurrencyRate(); + $model->tax = $object->getTax(); + $model->service_charge = $object->getServiceCharge(); + $model->expires_on = $object->getExpiresOn(); + $model->status = $object->getStatus(); + $model->payment_reference = $object->getPaymentReference(); + + return $this->handler($transactionable->transactions(), $model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/ListsGroups.php b/app/Classes/Modules/Transactions/Services/ListsGroups.php new file mode 100644 index 00000000..f9126739 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/ListsGroups.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php new file mode 100644 index 00000000..b49cb46c --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php @@ -0,0 +1,73 @@ + 'Created Company Wallet', + 'message' => 'You have successfully created a company wallet' + ]; + } + + /** @var CreatesWallet */ + private $createsWallet; + + /** @var GeneratesWalletCode */ + private $generatesWalletCode; + + /** @var CanCreateCompanyWallet */ + private $canCreateCompanyWallet; + + /** @var FetchesCompanyModule */ + private $fetchesCompanyModule; + + /** + * CreateWalletLogic constructor. + * @param CreatesWallet $createsWallet + * @param GeneratesWalletCode $generatesWalletCode + * @param CanCreateCompanyWallet $canCreateCompanyWallet + */ + public function __construct(CreatesWallet $createsWallet, GeneratesWalletCode $generatesWalletCode, CanCreateCompanyWallet $canCreateCompanyWallet, FetchesCompanyModule $fetchesCompanyModule) + { + $this->fetchesCompanyModule = $fetchesCompanyModule; + $this->createsWallet = $createsWallet; + $this->generatesWalletCode = $generatesWalletCode; + $this->canCreateCompanyWallet = $canCreateCompanyWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $object = new WalletObject($request->input('company_module_id'), $request->input('currency_id'), $this->generatesWalletCode->execute()); + + $this->canCreateCompanyWallet->passes($object); + + $company_module = $this->fetchesCompanyModule->execute(['id' => $request->input('company_id')]); + + $wallet = $this->createsWallet->execute($object, $company_module); + + return $this->resourceResponse(new WalletResource($wallet)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php new file mode 100644 index 00000000..6fe72a52 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php @@ -0,0 +1,132 @@ + 'Created Wallet Transaction', + 'message' => 'You have successfully created a wallet transaction' + ]; + } + + /** @var CreatesWalletTransaction */ + private $createsWalletTransaction; + + /** @var GeneratesWalletTransactionBillNo */ + private $generatesWalletTransactionBillNo; + + /** @var CanCreateWalletTransaction */ + private $canCreateWalletTransaction; + + private $fetchesCurrency; + + private $rateCalculatesCurrency; + + private $fetchesWallet; + + /** + * CreateWalletLogic constructor. + * @param CreatesWalletTransaction $createsWalletTransaction + * @param GeneratesWalletTransactionBillNo $generatesWalletTransactionBillNo + * @param CanCreateWalletTransaction $canCreateWalletTransaction + * @param FetchesCurrency $fetchesCurrency + * @param RateCalculatesCurrency $rateCalculatesCurrency + * @param FetchesWallet $fetchesWallet + */ + public function __construct( + CreatesWalletTransaction $createsWalletTransaction, GeneratesWalletTransactionBillNo $generatesWalletTransactionBillNo, CanCreateWalletTransaction $canCreateWalletTransaction, + FetchesCurrency $fetchesCurrency,RateCalculatesCurrency $rateCalculatesCurrency, FetchesWallet $fetchesWallet + ) + { + $this->createsWalletTransaction = $createsWalletTransaction; + $this->generatesWalletTransactionBillNo = $generatesWalletTransactionBillNo; + $this->canCreateWalletTransaction = $canCreateWalletTransaction; + $this->fetchesCurrency = $fetchesCurrency; + $this->rateCalculatesCurrency = $rateCalculatesCurrency; + $this->fetchesWallet = $fetchesWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + DB::beginTransaction(); + + $wallet = $this->fetchesWallet->execute(['id' => $request->route('id')]); + $conversion_currency = $this->fetchesCurrency->execute(['id' => $request->input('currency_id')]); + $convertable_currency = $this->fetchesCurrency->execute(['id' => $wallet->currency_id]);//MYR + + $convert_amount = $this->rateCalculatesCurrency->execute($conversion_currency, $convertable_currency, $request->input('amount')); + $convert_rate = $this->rateCalculatesCurrency->execute_rate($conversion_currency, $convertable_currency); + + + $object = new WalletTransactionObject( + $wallet->id, $this->generatesWalletTransactionBillNo->execute(),$request->input('trans_type'), + number_format( (float) $convert_amount, 5, '.', ''), $wallet->currency_id , number_format( (float) $request->input('amount'), 5, '.', ''), + $request->input('currency_id'),number_format( (float) $convert_rate, 5, '.', '') + ); + + $this->canCreateWalletTransaction->passes($object); + + $wallet_transaction = $this->createsWalletTransaction->execute($object); + + DB::commit(); + + return $this->resourceResponse(new WalletTransactionResource($wallet_transaction)); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php new file mode 100644 index 00000000..8ed8aa08 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php @@ -0,0 +1,101 @@ + 'Credit into Company Wallet', + 'message' => 'You have successfully credit company wallet' + ]; + } + + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var GeneratesWalletCode */ + private $generatesWalletCode; + + /** @var CreatesWallet */ + private $createsWallet; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var UpdatesWallet */ + private $updatesWallet; + + /** @var CreditWalletProcessor */ + private $creditWalletProcessor; + + /** + * CreateWalletLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param GeneratesWalletCode $generatesWalletCode + * @param CreatesWallet $createsWallet + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesTransaction $createsTransaction + * @param UpdatesWallet $updatesWallet + * @param CreditWalletProcessor $creditWalletProcessor + */ + public function __construct( + FetchesCompany $fetchesCompany, + GeneratesWalletCode $generatesWalletCode, + CreatesWallet $createsWallet, + GeneratesTransactionBillNumber $generatesTransactionBillNumber, + CreatesTransaction $createsTransaction, + UpdatesWallet $updatesWallet, + CreditWalletProcessor $creditWalletProcessor + ) + { + $this->fetchesCompany = $fetchesCompany; + $this->generatesWalletCode = $generatesWalletCode; + $this->createsWallet = $createsWallet; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->updatesWallet = $updatesWallet; + $this->creditWalletProcessor = $creditWalletProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $amount = floatval(str_replace(',', '', $request->input('amount'))); + + $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); + + $reference = $request->input('reference'); + + $type = $request->input('transaction_type'); + + $wallet = $this->creditWalletProcessor->execute($company, $type, $amount, $reference); + + return $this->resourceResponse(new WalletResource($wallet)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php new file mode 100644 index 00000000..682065c0 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php @@ -0,0 +1,117 @@ + 'Debit into Company Wallet', + 'message' => 'You have successfully debit company wallet' + ]; + } + + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var UpdatesWallet */ + private $updatesWallet; + + /** + * CreateWalletLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesTransaction $createsTransaction + * @param UpdatesWallet $updatesWallet + */ + public function __construct( + FetchesCompany $fetchesCompany, + GeneratesTransactionBillNumber $generatesTransactionBillNumber, + CreatesTransaction $createsTransaction, + UpdatesWallet $updatesWallet + ) + { + $this->fetchesCompany = $fetchesCompany; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->updatesWallet = $updatesWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $amount = floatval(str_replace(',', '', $request->input('amount'))); + $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); + $reference = $request->input('reference'); + + if (!$company->wallets()->first()) { + $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute()); + $wallet = $this->createsWallet->execute($object, $company); + } + + $wallet = $company->wallets()->first(); + + $billNumber = $this->generatesTransactionBillNumber->execute('DEBIT-NOTE-'); + + $transaction_object = new TransactionObject( + $billNumber, + TransactionType::DEBIT_NOTE, + 1, + $wallet->company->id, + 1, + PaymentMethodType::CASH, + $amount, + $amount, + 1, + 1, + 1, + 0, + 0, + null, + ApprovalStatus::APPROVED, + [], + $reference + ); + + $transaction = $this->createsTransaction->execute($wallet, $transaction_object); + $updateWalletAmount = $wallet->amount - $transaction->amount; + + $walletOject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); + + $wallet = $this->updatesWallet->execute($wallet, $walletOject); + + return $this->resourceResponse(new WalletResource($wallet)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/FetchWalletByCompanyModuleControllerLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/FetchWalletByCompanyModuleControllerLogic.php new file mode 100644 index 00000000..6a7c9515 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/FetchWalletByCompanyModuleControllerLogic.php @@ -0,0 +1,89 @@ + 'Retrieved Wallet', + 'message' => 'You have successfully retrieved a wallet' + ]; + } + + /** @var FetchesWallet */ + private $fetchesWallet; + + /** @var CreatesWallet */ + private $createsWallet; + + /** @var GeneratesWalletCode */ + private $generatesWalletCode; + + /** @var CanCreateCompanyWallet */ + private $canCreateCompanyWallet; + + /** @var FetchesCompanyModule */ + private $fetchesCompanyModule; + + + /** + * CreateWalletLogic constructor. + * @param FetchesWallet $fetchesWallet + */ + public function __construct(FetchesWallet $fetchesWallet, CreatesWallet $createsWallet, GeneratesWalletCode $generatesWalletCode, CanCreateCompanyWallet $canCreateCompanyWallet, FetchesCompanyModule $fetchesCompanyModule) + { + $this->fetchesWallet = $fetchesWallet; + $this->fetchesCompanyModule = $fetchesCompanyModule; + $this->createsWallet = $createsWallet; + $this->generatesWalletCode = $generatesWalletCode; + $this->canCreateCompanyWallet = $canCreateCompanyWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + // $this->canFetchWallet->passes(); + + if (!count(Wallet::where('owner_id', $request->route('company_module_id'))->get())) { + $object = new WalletObject($request->route('company_module_id'), $request->input('currency_id') ?? 1, $this->generatesWalletCode->execute()); + + $this->canCreateCompanyWallet->passes($object); + + $company_module = $this->fetchesCompanyModule->execute(['id' => $request->route('company_module_id')]); + + $wallet = $this->createsWallet->execute($object, $company_module); + + return $this->resourceResponse(new WalletResource($wallet)); + } + + $filters = $this->fetchesWallet->deserializeFilters($request->input('filters')); + + $filters['owner_id'] = $request->route('company_module_id'); + + $query = $this->fetchesWallet->execute($filters); + + return $this->resourceResponse(new WalletResource($query)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/ListWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/ListWalletLogic.php new file mode 100644 index 00000000..cf6b86bb --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/ListWalletLogic.php @@ -0,0 +1,60 @@ + 'List Company Wallet', + 'message' => 'You have successfully list company wallet' + ]; + } + + /** @var ListWallet */ + private $listsWallet; + + /** @var CanCreateCompanyWallet */ + private $canListWallet; + + /** + * CreateWalletLogic constructor. + * @param CreatesWallet $createsWallet + * @param GeneratesWalletCode $generatesWalletCode + * @param CanCreateCompanyWallet $canCreateCompanyWallet + */ + public function __construct(CanListWallet $canListWallet, ListsWallet $listsWallet) + { + $this->canListWallet = $canListWallet; + $this->listsWallet = $listsWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + //$this->canListWallet->passes(); + + $query = $this->listsWallet->execute($this->listsWallet->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(WalletResource::collection($query)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php new file mode 100644 index 00000000..3d345c5c --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php @@ -0,0 +1,109 @@ + 'TopUp into Company Wallet', + 'message' => 'You have successfully created a topup request for company\'s wallet' + ]; + } + + + /** @var FetchesCompanyModule */ + private $fetchesCompanyModule; + + /** @var GeneratesWalletCode */ + private $generatesWalletCode; + + /** @var CreatesWallet */ + private $createsWallet; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesBillplzBill */ + private $createsBillplzBill; + + /** @var CreatesTransactionableTransaction */ + private $createsTransactionableTransaction; + + + /** + * TopUpWalletLogic constructor. + * @param FetchesCompanyModule $fetchesCompanyModule + * @param GeneratesWalletCode $generatesWalletCode + * @param CreatesWallet $createsWallet + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesBillplzBill $createsBillplzBill + * @param CreatesTransaction $createsTransaction + */ + public function __construct(FetchesCompanyModule $fetchesCompanyModule, GeneratesWalletCode $generatesWalletCode, CreatesWallet $createsWallet, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesBillplzBill $createsBillplzBill, CreatesTransactionableTransaction $createsTransactionableTransaction) + { + $this->fetchesCompanyModule = $fetchesCompanyModule; + $this->generatesWalletCode = $generatesWalletCode; + $this->createsWallet = $createsWallet; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsBillplzBill = $createsBillplzBill; + $this->createsTransactionableTransaction = $createsTransactionableTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $amount = floatval(str_replace(',', '', $request->input('amount'))); + $companyModule = $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]); + + /** @var Wallet $wallet */ + $wallet = $companyModule->wallets()->first(); + + if (!$wallet) { + $object = new WalletObject($companyModule->id, 1, $this->generatesWalletCode->execute()); + /** @var Wallet $wallet */ + $wallet = $this->createsWallet->execute($object, $companyModule); + } + + $user = $companyModule->employees()->first(); + $billNumber = $this->generatesTransactionBillNumber->execute('TOPUP-'); + + if($amount < 0) { + throw new MalformedRequestException('Top up credit value must be greater than zero.'); + } + + $billPlzBill = $this->createsBillplzBill->execute($companyModule->name, $user->email, 'This payment is credit topup for company ref. ' . $companyModule->reference, $amount, $billNumber, $request->input('bank_code'), true); + + $transaction_object = new TransactionObject($billNumber, TransactionType::TOP_UP, 1, $companyModule->id, 1, PaymentMethodType::PAYMENT_GATEWAY, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, [], $billPlzBill->id); + + $transaction = $this->createsTransactionableTransaction->execute($wallet, $transaction_object); + + return $this->resourceResponse(new WalletTransactionResource($transaction)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/UpdateStatusWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/UpdateStatusWalletLogic.php new file mode 100644 index 00000000..b051d3e3 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/UpdateStatusWalletLogic.php @@ -0,0 +1,69 @@ + 'Update Status Transaction Company Wallet', + 'message' => 'You have successfully status transaction company wallet' + ]; + } + + /** @var ListWallet */ + private $fetchesWallet; + + /** @var CanCreateCompanyWallet */ + private $canListWallet; + + /** @var UpdateWalletTransactionProcessor */ + private $updateWalletTransactionProcessor; + + /** + * CreateWalletLogic constructor. + * @param CreatesWallet $createsWallet + * @param GeneratesWalletCode $generatesWalletCode + * @param CanCreateCompanyWallet $canCreateCompanyWallet + */ + public function __construct(FetchesWallet $fetchesWallet, UpdateWalletTransactionProcessor $updateWalletTransactionProcessor) + { + $this->fetchesWallet = $fetchesWallet; + $this->updateWalletTransactionProcessor = $updateWalletTransactionProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $status = ($request->route('status')=='approve') ? 2 : 4; + + $wallet = $this->updateWalletTransactionProcessor->execute($request->route('transaction_id'), $status); + + return $this->resourceResponse(new WalletResource($wallet)); + + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/WithdrawWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/WithdrawWalletLogic.php new file mode 100644 index 00000000..b1491ab7 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/WithdrawWalletLogic.php @@ -0,0 +1,72 @@ + 'Withdraw from Company Wallet', + 'message' => 'You have successfully withdraw company wallet' + ]; + } + + /** @var FetchesWallet */ + private $fetchesWallet; + + /** @var CanWithdrawWallet */ + private $canWithdrawWallet; + + /** @var CreateWalletTransactionProcessor */ + private $createWalletTransactionProcessor; + + /** + * CreateWalletLogic constructor. + * @param CreatesWallet $createsWallet + * @param GeneratesWalletCode $generatesWalletCode + * @param CanCreateCompanyWallet $canCreateCompanyWallet + */ + public function __construct(CanWithdrawWallet $canWithdrawWallet, FetchesWallet $fetchesWallet, CreateWalletTransactionProcessor $createWalletTransactionProcessor) + { + $this->canWithdrawWallet = $canWithdrawWallet; + $this->fetchesWallet = $fetchesWallet; + $this->createWalletTransactionProcessor = $createWalletTransactionProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]); + + $walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $request->input('amount')); + + $this->canWithdrawWallet->passes($walletOject); + + $transaction = $this->createWalletTransactionProcessor->execute($wallet, $walletOject, TransactionType::WITHDRAW); + + return $this->resourceResponse(new WalletResource($wallet)); + } +} diff --git a/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php b/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php new file mode 100644 index 00000000..cb01bb0c --- /dev/null +++ b/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php @@ -0,0 +1,65 @@ +company_module_id = $company_module_id; + $this->currency_id = $currency; + $this->code = $code; + $this->amount = $amount; + } + + /** + * @return int + */ + public function getCompanyModuleId(): int + { + return $this->company_module_id; + } + + /** + * @return int + */ + public function getCurrency(): int + { + return $this->currency_id; + } + + /** + * @return int + */ + public function getCode(): int + { + return $this->code; + } + + public function getAmount(): float + { + return $this->amount; + } + + +} diff --git a/app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php b/app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php new file mode 100644 index 00000000..234c8f57 --- /dev/null +++ b/app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php @@ -0,0 +1,94 @@ +wallet_id = $wallet_id; + $this->bill_no = $bill_no; + $this->trans_type = $trans_type; + $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; + } + + /** + * @return int + */ + public function getWalletId(): int + { + return $this->wallet_id; + } + + /** + * @return int + */ + public function getBillNo(): int + { + return $this->bill_no; + } + + /** + * @return int + */ + public function getTransType(): int + { + return $this->trans_type; + } + + + public function getAmount(): float + { + return $this->amount; + } + + /** + * @return int + */ + public function getCurrency(): int + { + return $this->currency_id; + } + + + public function getOriginalAmount(): float + { + return $this->original_amount; + } + + public function getOriginalCurrency(): int + { + return $this->original_currency_id; + } + + public function getCurrencyRate(): float + { + return $this->currency_rate; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php b/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php new file mode 100644 index 00000000..65f3b9b6 --- /dev/null +++ b/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php @@ -0,0 +1,90 @@ +generatesWalletCode = $generatesWalletCode; + $this->createsWallet = $createsWallet; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->updatesWallet = $updatesWallet; + } + + + /** + * @param Company $company + * @param int $transactionType + * @param float $amount + * @param string $reference + * @return \Illuminate\Database\Eloquent\Model + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(Company $company, int $transactionType, float $amount, string $reference) + { + if (!$company->wallets()->first()) { + $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute()); + $this->createsWallet->execute($object, $company); + } + + /** @var Wallet $wallet */ + $wallet = $company->wallets()->first(); + + $billNumber = $this->generatesTransactionBillNumber->execute($transactionType === 2 ? 'DEBIT-NOTE-' : 'CREDIT-NOTE-'); + + $transaction_object = new TransactionObject($billNumber, $transactionType === 2 ? TransactionType::DEBIT_NOTE : TransactionType::CREDIT_NOTE, 1, $wallet->owner->id, 1, PaymentMethodType::CASH, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], $reference); + $transaction = $this->createsTransaction->execute($wallet, $transaction_object); + + $updateWalletAmount = $transactionType === 2 ? ($wallet->amount - $transaction->amount) : ($wallet->amount + $transaction->amount); + + $walletObject = new WalletObject($wallet->owner->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); + + $wallet = $this->updatesWallet->execute($wallet, $walletObject); + + return $wallet; + } +} diff --git a/app/Classes/Modules/Wallets/Services/ChecksIfWalletCodeExists.php b/app/Classes/Modules/Wallets/Services/ChecksIfWalletCodeExists.php new file mode 100644 index 00000000..4d00540a --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/ChecksIfWalletCodeExists.php @@ -0,0 +1,28 @@ +repository = $repository; + } + + public function execute(int $code): bool { + return $this->repository->where('code', $code)->exists(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/ChecksIfWalletTransactionBillNoExists.php b/app/Classes/Modules/Wallets/Services/ChecksIfWalletTransactionBillNoExists.php new file mode 100644 index 00000000..43df87d4 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/ChecksIfWalletTransactionBillNoExists.php @@ -0,0 +1,22 @@ +repository = $repository; + } + + public function execute(int $bill_no): bool { + return $this->repository->where('bill_no', $bill_no)->exists(); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/CreatesWallet.php b/app/Classes/Modules/Wallets/Services/CreatesWallet.php new file mode 100644 index 00000000..f3d71743 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/CreatesWallet.php @@ -0,0 +1,27 @@ +company_module_id = $object->getCompanyModuleId(); + $model->code = $object->getCode(); + $model->currency_id = $object->getCurrency(); + + return $this->handler($companyModule->wallets(), $model); + } +} diff --git a/app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php b/app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php new file mode 100644 index 00000000..0b40879c --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php @@ -0,0 +1,30 @@ +wallet_id = $object->getWalletId(); + $model->bill_no = $object->getBillNo(); + $model->trans_type = $object->getTransType(); + $model->amount = $object->getAmount(); + $model->currency_id = $object->getCurrency(); + $model->original_amount = $object->getOriginalAmount(); + $model->original_currency_id = $object->getOriginalCurrency(); + $model->currency_rate = $object->getCurrencyRate(); + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/FetchesWallet.php b/app/Classes/Modules/Wallets/Services/FetchesWallet.php new file mode 100644 index 00000000..c3542bb7 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/FetchesWallet.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/Wallets/Services/GeneratesWalletCode.php b/app/Classes/Modules/Wallets/Services/GeneratesWalletCode.php new file mode 100644 index 00000000..af2bda7e --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/GeneratesWalletCode.php @@ -0,0 +1,32 @@ +walletCodeExists = $walletCodeExists; + } + + + /** + * @return int + */ + public function execute(): int { + + $code = mt_rand(100000001, 999999999); + return !$this->walletCodeExists->execute($code) ? $code : self::execute(); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/GeneratesWalletTransactionBillNo.php b/app/Classes/Modules/Wallets/Services/GeneratesWalletTransactionBillNo.php new file mode 100644 index 00000000..d3758d72 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/GeneratesWalletTransactionBillNo.php @@ -0,0 +1,27 @@ +walletTransationBillNoExists = $walletTransationBillNoExists; + } + + + + public function execute(): int { + + $code = mt_rand(100000001, 999999999); + return !$this->walletTransationBillNoExists->execute($code) ? $code : self::execute(); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Services/ListsWallet.php b/app/Classes/Modules/Wallets/Services/ListsWallet.php new file mode 100644 index 00000000..c11e2063 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/ListsWallet.php @@ -0,0 +1,30 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/Modules/Wallets/Services/UpdatesWallet.php b/app/Classes/Modules/Wallets/Services/UpdatesWallet.php new file mode 100644 index 00000000..8b268fab --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/UpdatesWallet.php @@ -0,0 +1,27 @@ +amount = $object->getAmount(); + $model->code = $object->getCode(); + $model->currency_id = $object->getCurrency(); + + + return $this->handler($model); + + } +} diff --git a/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php new file mode 100644 index 00000000..a724cf24 --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php @@ -0,0 +1,25 @@ +amount = $model->amount + $amount; + return $this->handler($model); + + } +} diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanCreateCompanyWallet.php b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateCompanyWallet.php new file mode 100644 index 00000000..0f1dd065 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateCompanyWallet.php @@ -0,0 +1,55 @@ +companyWalletValidation = $companyWalletValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param WalletObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->companyWalletValidation->validate($object); + } + + + /** + * @param WalletObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php new file mode 100644 index 00000000..8beafb37 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php @@ -0,0 +1,51 @@ +walletTransactionValidation = $walletTransactionValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param WalletTransactionObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->walletTransactionValidation->validate($object); + } + + /** + * @param WalletTransactionObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanListWallet.php b/app/Classes/Modules/Wallets/Standards/Rules/CanListWallet.php new file mode 100644 index 00000000..c87cb316 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanListWallet.php @@ -0,0 +1,51 @@ +listWalletValidation = $listWalletValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param WalletObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->listWalletValidation->validate($object); + } + + /** + * @param WalletTransactionObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanTopUpWallet.php b/app/Classes/Modules/Wallets/Standards/Rules/CanTopUpWallet.php new file mode 100644 index 00000000..9a005498 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanTopUpWallet.php @@ -0,0 +1,51 @@ +topUpWalletValidation = $topUpWalletValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param WalletObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->topUpWalletValidation->validate($object); + } + + /** + * @param WalletTransactionObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} diff --git a/app/Classes/Modules/Wallets/Standards/Rules/CanWithdrawWallet.php b/app/Classes/Modules/Wallets/Standards/Rules/CanWithdrawWallet.php new file mode 100644 index 00000000..6fb4019d --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanWithdrawWallet.php @@ -0,0 +1,51 @@ +witdrawWalletValidation = $witdrawWalletValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param WalletObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->witdrawWalletValidation->validate($object); + } + + /** + * @param WalletTransactionObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} diff --git a/app/Classes/Modules/Wallets/Standards/Validators/CompanyWalletValidation.php b/app/Classes/Modules/Wallets/Standards/Validators/CompanyWalletValidation.php new file mode 100644 index 00000000..2cb8628b --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Validators/CompanyWalletValidation.php @@ -0,0 +1,40 @@ + $object->getCompanyModuleId(), + 'currency_id' => $object->getCurrency(), + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'company_module_id' => 'required', + 'currency_id' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Standards/Validators/ListWalletValidation.php b/app/Classes/Modules/Wallets/Standards/Validators/ListWalletValidation.php new file mode 100644 index 00000000..1f75aa54 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Validators/ListWalletValidation.php @@ -0,0 +1,30 @@ + $object->getWalletId(), + 'currency_id' => $object->getCurrency(), + 'amount' => $object->getAmount(), + 'trans_type'=>$object->getTransType() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'wallet_id' => 'required', + 'currency_id' => 'required', + 'amount' => 'required', + 'trans_type'=>'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Standards/Validators/WithdrawWalletValidation.php b/app/Classes/Modules/Wallets/Standards/Validators/WithdrawWalletValidation.php new file mode 100644 index 00000000..78660228 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Validators/WithdrawWalletValidation.php @@ -0,0 +1,30 @@ + self::CHEQUE, 'ba' => self::BA, 'wallet' => self::WALLET, - 'payment gateway' => self::PAYMENT_GATEWAY, + 'payment_gateway' => self::PAYMENT_GATEWAY, ]; public const PAYMENT_METHODS_ID = [ diff --git a/app/Classes/ValueObjects/Constants/RouteType.php b/app/Classes/ValueObjects/Constants/RouteType.php new file mode 100644 index 00000000..f2e43f78 --- /dev/null +++ b/app/Classes/ValueObjects/Constants/RouteType.php @@ -0,0 +1,11 @@ + "Shipping Invoice", self::PAYMENT => "Payment", diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 259d5692..012018a4 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -28,26 +28,31 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule) { - $schedule->command('command:curlVTCommand') - ->cron('0 8 * * *') - ->withoutOverlapping() - ->appendOutputTo (storage_path().'/logs/curlvt.log'); + // $schedule->command('command:curlVTCommand') + // ->cron('0 8 * * *') + // ->withoutOverlapping() + // ->appendOutputTo (storage_path().'/logs/curlvt.log'); - $schedule->command('command:curlYdOrderListCommand') - ->cron('30 9-18/3 * * *') - ->withoutOverlapping() - ->appendOutputTo (storage_path().'/logs/curlyd.log'); + // $schedule->command('command:curlYdOrderListCommand') + // ->cron('30 9-18/3 * * *') + // ->withoutOverlapping() + // ->appendOutputTo (storage_path().'/logs/curlyd.log'); - $schedule->command('command:curlYdOrderListCommand') - ->cron('0 9 * * *') - ->withoutOverlapping() - ->appendOutputTo (storage_path().'/logs/departure_email.log'); + // $schedule->command('command:curlYdOrderListCommand') + // ->cron('0 9 * * *') + // ->withoutOverlapping() + // ->appendOutputTo (storage_path().'/logs/departure_email.log'); $schedule->command('invoice:generate') ->hourly() ->withoutOverlapping() ->appendOutputTo (storage_path().'/logs/auto_generate_invoice.log'); + $schedule->command('approve:invoice') + ->hourly() + ->withoutOverlapping() + ->appendOutputTo (storage_path().'/logs/approve_invoice.log'); + $schedule->command('billplz-failed-callback:fix') ->dailyAt('00:00') ->withoutOverlapping() diff --git a/app/Http/Controllers/Reports/MonthlyReportController.php b/app/Http/Controllers/Reports/MonthlyReportController.php index fdb218e6..a05c9f6b 100644 --- a/app/Http/Controllers/Reports/MonthlyReportController.php +++ b/app/Http/Controllers/Reports/MonthlyReportController.php @@ -19,7 +19,39 @@ use Illuminate\Http\Request; class MonthlyReportController { - public function salesReport(Request $request): JsonResponse { + + /** + * Get Containers + * @param $from + * @param $to + * @return mixed + */ + private function getContainersByLoadingDate($from, $to) + { + return Container::whereBetween('loading_date', [$from, $to])->orderBy('loading_date')->get(); + + } + + private function getPackages($from, $to) + { + + $containers = $this->getContainersByLoadingDate($from, $to); + + $packingLists = $containers->flatMap(function ($container) { + return $container->packingLists; + }); + + return $packingLists->map(function ($packingList) { + $replica = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]) ? $packingList : $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first(); + return $replica ? $replica : $packingList; + })->flatMap(function ($packingList) { + return $packingList->packages; + }); + + } + + public function salesReport(Request $request): JsonResponse + { $from = $request->route('from') ? Carbon::parse($request->route('from')) : Carbon::now()->startOfMonth(); $to = $request->route('to') ? Carbon::parse($request->route('to')) : Carbon::now()->endOfMonth(); @@ -39,16 +71,18 @@ class MonthlyReportController return $container->orders; })->unique(); - $packingLists = $containers->flatMap(function ($container) { - return $container->packingLists; - }); + $packages = $this->getPackages($from, $to); - $packages = $packingLists->map(function ($packingList) { - $replica = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]) ? $packingList : $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first(); - return $replica ? $replica : $packingList; - })->flatMap(function ($packingList) { - return $packingList->packages; - }); + /* $packingLists = $containers->flatMap(function ($container) { + return $container->packingLists; + }); + + $packages = $packingLists->map(function ($packingList) { + $replica = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]) ? $packingList : $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first(); + return $replica ? $replica : $packingList; + })->flatMap(function ($packingList) { + return $packingList->packages; + });*/ $totalCbm = $packages->sum(function($package){ return (( (float) $package->width / 100) * ( (float) $package->length / 100) * ( (float) $package->height / 100)) * $package->quantity; @@ -89,19 +123,18 @@ class MonthlyReportController $model = (int) $request->route('model'); $value = (float) $request->route('value'); + $packages = $this->getPackages($from, $to); - $containers = Container::whereBetween('loading_date', [$from, $to])->orderBy('loading_date')->get(); + /* $packingLists = $containers->flatMap(function ($container) { + return $container->packingLists; + }); - $packingLists = $containers->flatMap(function ($container) { - return $container->packingLists; - }); - - $packages = $packingLists->map(function ($packingList) { - $replica = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]) ? $packingList : $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first(); - return $replica ? $replica : $packingList; - })->flatMap(function ($packingList) { - return $packingList->packages; - }); + $packages = $packingLists->map(function ($packingList) { + $replica = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]) ? $packingList : $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first(); + return $replica ? $replica : $packingList; + })->flatMap(function ($packingList) { + return $packingList->packages; + });*/ $totalCbm = $packages->sum(function($package){ return (( (float) $package->width / 100) * ( (float) $package->length / 100) * ( (float) $package->height / 100)) * $package->quantity; @@ -142,18 +175,20 @@ class MonthlyReportController $from = $request->route('from') ? Carbon::parse($request->route('from')) : Carbon::parse('01-01-2018'); $to = $request->route('to') ? Carbon::parse($request->route('to')) : Carbon::now(); - $containers = Container::whereBetween('loading_date', [$from, $to])->orderBy('loading_date')->get(); + /* $containers = $this->getContainersByLoadingDate($from, $to); - $packingLists = $containers->flatMap(function ($container) { - return $container->packingLists; - }); + $packingLists = $containers->flatMap(function ($container) { + return $container->packingLists; + }); - $packages = $packingLists->map(function ($packingList) { - $replica = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]) ? $packingList : $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first(); - return $replica ? $replica : $packingList; - })->flatMap(function ($packingList) { - return $packingList->packages; - }); + $packages = $packingLists->map(function ($packingList) { + $replica = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]) ? $packingList : $packingList->packingLists()->where('type', PackingListType::SHIPPING_PACKING_LIST_REPLICA)->first(); + return $replica ? $replica : $packingList; + })->flatMap(function ($packingList) { + return $packingList->packages; + });*/ + + $packages = $this->getPackages($from, $to); $packages = $packages->filter(function($package) use ($id) { return $package->companyModule->id === $id; @@ -210,17 +245,19 @@ class MonthlyReportController $minCbm = $request->input('cbm'); $minOrders = $request->input('minOrders'); - $activeCompanies = CompanyModule::where('type', \App\Classes\ValueObjects\Constants\BusinessType::IMPORTER)->whereHas('orderPackingLists', function($query) use($inactive_start, $inactive_end) { - return $query->where('packing_lists.type', \App\Classes\ValueObjects\Constants\PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($inactive_start, $inactive_end) { - return $query->where('drop_date', '>=', \Carbon\Carbon::parse($inactive_start))->where('drop_date', '<=', \Carbon\Carbon::parse($inactive_end)->addDay()); - }); - })->pluck('id'); + /* $activeCompanies = CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orderPackingLists', function ($query) use ($inactive_start, $inactive_end) { + return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($inactive_start, $inactive_end) { + return $query->where('drop_date', '>=', Carbon::parse($inactive_start))->where('drop_date', '<=', Carbon::parse($inactive_end)->addDay()); + }); + })->pluck('id'); - $companies = CompanyModule::where('type', \App\Classes\ValueObjects\Constants\BusinessType::IMPORTER)->whereHas('orderPackingLists', function($query) use($active_start, $active_end) { - return $query->where('packing_lists.type', \App\Classes\ValueObjects\Constants\PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($active_start, $active_end) { - return $query->whereDate('drop_date', '>=', \Carbon\Carbon::parse($active_start))->whereDate('drop_date', '<=', \Carbon\Carbon::parse($active_end)->addDay()); - }); - })->whereNotIn('id', $activeCompanies)->get(); + $companies = CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orderPackingLists', function ($query) use ($active_start, $active_end) { + return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($active_start, $active_end) { + return $query->whereDate('drop_date', '>=', Carbon::parse($active_start))->whereDate('drop_date', '<=', Carbon::parse($active_end)->addDay()); + }); + })->whereNotIn('id', $activeCompanies)->get();*/ + + $companies = getActiveCompanies($inactive_start, $inactive_end, $active_start, $active_end); $customerActivityData = []; $counter = 1; @@ -240,7 +277,7 @@ class MonthlyReportController if ($minOrders != 'null' && $packingList->count() < $minOrders) { continue; } array_push($customerActivityData, array( - 'key' => $counter, + 'key' => $counter, 'marking' => $marking, 'packingListCount'=> $packingList->count(), 'totalCbm'=> $totalCbm, diff --git a/app/Http/Controllers/Transactions/CreateCombinedInvoicesController.php b/app/Http/Controllers/Transactions/CreateCombinedInvoicesController.php new file mode 100644 index 00000000..1b87441f --- /dev/null +++ b/app/Http/Controllers/Transactions/CreateCombinedInvoicesController.php @@ -0,0 +1,15 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/CreateGroupsController.php b/app/Http/Controllers/Transactions/CreateGroupsController.php new file mode 100644 index 00000000..c0863e7e --- /dev/null +++ b/app/Http/Controllers/Transactions/CreateGroupsController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/DeleteGroupController.php b/app/Http/Controllers/Transactions/DeleteGroupController.php new file mode 100644 index 00000000..14ba54f9 --- /dev/null +++ b/app/Http/Controllers/Transactions/DeleteGroupController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/ListGroupsController.php b/app/Http/Controllers/Transactions/ListGroupsController.php new file mode 100644 index 00000000..730633e9 --- /dev/null +++ b/app/Http/Controllers/Transactions/ListGroupsController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/RegenerateShippingInvoiceTransactionController.php b/app/Http/Controllers/Transactions/RegenerateShippingInvoiceTransactionController.php new file mode 100644 index 00000000..d5bf121d --- /dev/null +++ b/app/Http/Controllers/Transactions/RegenerateShippingInvoiceTransactionController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/UpdateGroupController.php b/app/Http/Controllers/Transactions/UpdateGroupController.php new file mode 100644 index 00000000..db0b3a17 --- /dev/null +++ b/app/Http/Controllers/Transactions/UpdateGroupController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/CreateWalletController.php b/app/Http/Controllers/Wallets/CreateWalletController.php new file mode 100644 index 00000000..1aa71179 --- /dev/null +++ b/app/Http/Controllers/Wallets/CreateWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Wallets/CreateWalletTransactionController.php b/app/Http/Controllers/Wallets/CreateWalletTransactionController.php new file mode 100644 index 00000000..70b94a03 --- /dev/null +++ b/app/Http/Controllers/Wallets/CreateWalletTransactionController.php @@ -0,0 +1,15 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Wallets/CreditWalletController.php b/app/Http/Controllers/Wallets/CreditWalletController.php new file mode 100644 index 00000000..b3143588 --- /dev/null +++ b/app/Http/Controllers/Wallets/CreditWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/DebitWalletController.php b/app/Http/Controllers/Wallets/DebitWalletController.php new file mode 100644 index 00000000..7feafb39 --- /dev/null +++ b/app/Http/Controllers/Wallets/DebitWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/FetchWalletByCompanyModuleController.php b/app/Http/Controllers/Wallets/FetchWalletByCompanyModuleController.php new file mode 100644 index 00000000..d4c0ae71 --- /dev/null +++ b/app/Http/Controllers/Wallets/FetchWalletByCompanyModuleController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} diff --git a/app/Http/Controllers/Wallets/ListWalletController.php b/app/Http/Controllers/Wallets/ListWalletController.php new file mode 100644 index 00000000..45b2f1d1 --- /dev/null +++ b/app/Http/Controllers/Wallets/ListWalletController.php @@ -0,0 +1,14 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/TopUpWalletController.php b/app/Http/Controllers/Wallets/TopUpWalletController.php new file mode 100644 index 00000000..aaa707bd --- /dev/null +++ b/app/Http/Controllers/Wallets/TopUpWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/UpdateStatusWalletController.php b/app/Http/Controllers/Wallets/UpdateStatusWalletController.php new file mode 100644 index 00000000..21eea924 --- /dev/null +++ b/app/Http/Controllers/Wallets/UpdateStatusWalletController.php @@ -0,0 +1,14 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/WalletReportController.php b/app/Http/Controllers/Wallets/WalletReportController.php new file mode 100644 index 00000000..998bba53 --- /dev/null +++ b/app/Http/Controllers/Wallets/WalletReportController.php @@ -0,0 +1,29 @@ + [ + 'walletSum' => (float) Wallet::all()->sum('amount'), + 'outgoingSum' => (float) Transaction::where('type', TransactionType::PAYMENT)->where('owner_type', Wallet::class)->sum('amount'), + 'incomingSum' => (float) Transaction::whereIn('type', [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE])->where('owner_type', Wallet::class)->sum('amount'), + ]] + ))->handler(); + } +} diff --git a/app/Http/Controllers/Wallets/WithdrawWalletController.php b/app/Http/Controllers/Wallets/WithdrawWalletController.php new file mode 100644 index 00000000..7c7b944a --- /dev/null +++ b/app/Http/Controllers/Wallets/WithdrawWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index dc3bc265..ea01cbbe 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -38,11 +38,13 @@ class Kernel extends HttpKernel \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, + // \App\Http\Middleware\WebRouteLogs::class, ], 'api' => [ 'throttle:300,1', \Illuminate\Routing\Middleware\SubstituteBindings::class, + // \App\Http\Middleware\ApiRouteLogs::class, ], 'apipub' => [ diff --git a/app/Http/Middleware/ApiRouteLogs.php b/app/Http/Middleware/ApiRouteLogs.php new file mode 100644 index 00000000..984ff5ea --- /dev/null +++ b/app/Http/Middleware/ApiRouteLogs.php @@ -0,0 +1,64 @@ +fullUrl()); + $request_method = $request->method(); + $platform = $request->header('sec-ch-ua-platform'); + $browser = Str::after($request->header('sec-ch-ua'), 'Not?A_Brand";v="8", "Chromium";v="108", "'); + $geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$ip_address")); + $longitude = $geo["geoplugin_longitude"]; + $latitude = $geo["geoplugin_latitude"]; + $last_page = url()->previous(); + $countryName = $geo["geoplugin_countryName"]; + + $user_id = Auth::user() ? Auth::user()->id : 0; + + // if ($user_id != 0) { + // // $ip_address + // $webRouteLogWithSameIp = RouteLog::where('ip_address', $ip_address)->where('user_id', 0)->get(); + // dd($webRouteLogWithSameIp); + // foreach($webRouteLogWithSameIp as $result){ + // $result + // } + // } + + $route_log = [ + 'user_id' => $user_id, + // 'ip_address' => $request->ip(), + 'ip_address' => $ip_address, + 'url' => $url, + 'request_method' => $request_method, + 'browser' => $browser, + 'platform' => $platform, + 'longitude' => $longitude, + 'latitude' => $latitude, + 'last_page' => $last_page, + 'countryname' => $countryName, + 'route_type' => RouteType::API, + ]; + + RouteLog::create($route_log); + + return $next($request); + } +} diff --git a/app/Http/Middleware/WebRouteLogs.php b/app/Http/Middleware/WebRouteLogs.php new file mode 100644 index 00000000..b5200de6 --- /dev/null +++ b/app/Http/Middleware/WebRouteLogs.php @@ -0,0 +1,55 @@ +fullUrl(); + $request_method = $request->method(); + $platform = $request->header('sec-ch-ua-platform'); + $browser = Str::after($request->header('sec-ch-ua'), 'Not?A_Brand";v="8", "Chromium";v="108", "'); + $geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$ip_address")); + $longitude = $geo["geoplugin_longitude"]; + $latitude = $geo["geoplugin_latitude"]; + $last_page = url()->previous(); + $countryName = $geo["geoplugin_countryName"]; + + $route_log = [ + 'user_id' => Auth::user() ? Auth::user()->id : 0, + // 'ip_address' => $request->ip(), + 'ip_address' => $ip_address, + 'url' => $url, + 'request_method' => $request_method, + 'browser' => $browser, + 'platform' => $platform, + 'longitude' => $longitude, + 'latitude' => $latitude, + 'last_page' => $last_page, + 'countryname' => $countryName, + 'route_type' => RouteType::WEB, + ]; + + // dd($route_log); + + RouteLog::create($route_log); + + return $next($request); + } +} diff --git a/app/Http/Resources/AirShipmentItemPriceResource.php b/app/Http/Resources/AirShipmentItemPriceResource.php index 7210ba05..8cd4d90f 100644 --- a/app/Http/Resources/AirShipmentItemPriceResource.php +++ b/app/Http/Resources/AirShipmentItemPriceResource.php @@ -2,6 +2,7 @@ namespace App\Http\Resources; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class AirShipmentItemPriceResource extends JsonResource @@ -9,10 +10,10 @@ class AirShipmentItemPriceResource extends JsonResource /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request + * @param Request $request * @return array */ - public function toArray($request) + public function toArray($request): array { $object = $this->resource; $detailsArray = (array)json_decode($object['details']); diff --git a/app/Http/Resources/AnnouncementResource.php b/app/Http/Resources/AnnouncementResource.php index 2e6048e0..9355725c 100644 --- a/app/Http/Resources/AnnouncementResource.php +++ b/app/Http/Resources/AnnouncementResource.php @@ -2,6 +2,7 @@ namespace App\Http\Resources; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use Carbon\Carbon; @@ -10,10 +11,10 @@ class AnnouncementResource extends JsonResource /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request + * @param Request $request * @return array */ - public function toArray($request) + public function toArray($request): array { return [ 'id' => $this->id, diff --git a/app/Http/Resources/BankResource.php b/app/Http/Resources/BankResource.php index 35fec923..86d14423 100644 --- a/app/Http/Resources/BankResource.php +++ b/app/Http/Resources/BankResource.php @@ -2,6 +2,7 @@ namespace App\Http\Resources; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class BankResource extends JsonResource @@ -9,10 +10,10 @@ class BankResource extends JsonResource /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request + * @param Request $request * @return array */ - public function toArray($request) + public function toArray($request): array { return [ 'id' => $this->id, diff --git a/app/Http/Resources/BookingResource.php b/app/Http/Resources/BookingResource.php index b91bf7f8..7042834b 100644 --- a/app/Http/Resources/BookingResource.php +++ b/app/Http/Resources/BookingResource.php @@ -11,6 +11,7 @@ use App\Classes\ValueObjects\Constants\DocumentType; use Carbon\Carbon; use Illuminate\Http\Resources\Json\JsonResource; +/*todo delete this*/ class BookingResource extends JsonResource { diff --git a/app/Http/Resources/DocumentResource.php b/app/Http/Resources/DocumentResource.php index 2595ed55..aa5d3117 100644 --- a/app/Http/Resources/DocumentResource.php +++ b/app/Http/Resources/DocumentResource.php @@ -28,4 +28,16 @@ class DocumentResource extends JsonResource 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A') ]; } + + /** + * include only when should include file, to be loaded if needed in the UI + * @param bool $includeFile + * @return bool + */ + private function shouldIncludeFiles(bool $includeFile): bool + { + return $includeFile; + } + + } diff --git a/app/Http/Resources/GroupResource.php b/app/Http/Resources/GroupResource.php new file mode 100644 index 00000000..abd017ec --- /dev/null +++ b/app/Http/Resources/GroupResource.php @@ -0,0 +1,53 @@ +issuerCompany){ + dd($this->id); + } + return [ + 'id' => $this->id, + 'original_amount' => (float) $this->original_amount, + 'original_currency' => new CurrencyResource($this->original_currency), + 'issuer_name' => $this->issuerCompany->name, + 'issuer_id' => $this->issuerCompany->id, + 'amount' => (float) $this->amount, + 'service_charge' => (float) $this->amount, + 'currency' => new CurrencyResource($this->currency), + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'), + 'currency_rate' => (float) $this->currency_rate, + 'transactions' => $this->transactions()->get()->pluck('owner.owner.marking'), + 'complete_transactions' => $this->transactions()->whereHasMorph('owner', [Transaction::class], function($query){ + return $query->whereHas('booking', function($query){ + return $query->whereHas('transactions', function($query){ + return $query->where('type', TransactionType::PURCHASE_ORDER)->where('status', '=', ApprovalStatus::APPROVED); + }); + }); + })->get()->pluck('owner.owner.marking'), + 'documents' => [ + 'currency_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::CURRENCY_VENDOR_ORDER)->first()), + 'purchase_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::BULK_PURCHASE_ORDER)->first()) + ] + ]; + } +} diff --git a/app/Http/Resources/WalletResource.php b/app/Http/Resources/WalletResource.php new file mode 100644 index 00000000..0529e170 --- /dev/null +++ b/app/Http/Resources/WalletResource.php @@ -0,0 +1,29 @@ + $this->id, + 'code' => $this->code, + 'currency_id' => $this->currency_id, + 'amount' => (double) $this->amount, + 'company_id' => (int) $this->owner->id, + 'transactions' => $this->whenLoaded('transactions', WalletTransactionResource::collection($this->transactions()->whereIn('status', [2, 3])->orderBy('id', 'DESC')->get()), []), + 'top_up_records' => $this->whenLoaded('transactions', WalletTransactionResource::collection($this->transactions()->whereNotIn('status', [0])->where('type', TransactionType::TOP_UP)->orderBy('id', 'DESC')->get()), []), + 'company_module_marking' => $this->owner->connections->first()->invitee_reference, + ]; + } +} diff --git a/app/Http/Resources/WalletTransactionResource.php b/app/Http/Resources/WalletTransactionResource.php new file mode 100644 index 00000000..c43d2346 --- /dev/null +++ b/app/Http/Resources/WalletTransactionResource.php @@ -0,0 +1,64 @@ +type){ + case TransactionType::TOP_UP: + $description = (double) $this->amount.' Credit Top up'; + break; + case TransactionType::CREDIT_NOTE: + $description = 'Credit Voucher for '.$this->payment_reference; + break; + case TransactionType::PAYMENT: + $order = Transaction::where('payment_reference', $this->bill_no)->first()->owner->owner->owner; + + if(!$order) { + $description = 'Payment for unknown order, please contact tech support.'; + break; + } + + $marking = $order->reference; + $description = 'Payment For order refs.'.''.$marking.''; + break; + case 11: + $description = 'Debit Voucher for '.$this->payment_reference; + break; + + } + + return [ + 'type' => (int) $this->type, + 'marking' => $this->owner->owner->reference, + 'bill_no' => $this->bill_no, + 'reference' => $this->payment_reference, + 'payment_method' => (float) $this->payment_method, + // 'issuer_name' => $this->issuerCompany->name, + 'amount' => (double) $this->amount, + 'service_charge' => (double) $this->service_charge, + 'tax' => (double) $this->tax, + 'status' => (int) $this->status, + 'description' => $description, + 'details' => TransactionDetailResource::collection($this->transactionDetails), + 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'), + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A') + ]; + } +} diff --git a/app/Library/helper.php b/app/Library/helper.php new file mode 100644 index 00000000..94a9ac07 --- /dev/null +++ b/app/Library/helper.php @@ -0,0 +1,49 @@ +whereHas('orderPackingLists', function ($query) use ($inactive_start, $inactive_end) { + return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($inactive_start, $inactive_end) { + return $query->where('drop_date', '>=', Carbon::parse($inactive_start))->where('drop_date', '<=', Carbon::parse($inactive_end)->addDay()); + }); + })->pluck('id'); + + return CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orderPackingLists', function ($query) use ($active_start, $active_end) { + return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($active_start, $active_end) { + return $query->whereDate('drop_date', '>=', Carbon::parse($active_start))->whereDate('drop_date', '<=', Carbon::parse($active_end)->addDay()); + }); + })->whereNotIn('id', $activeCompanies)->get(); + + } +} +/** + * + * Get Packing List + * TODO change all packing related query to this + * @param Company $company + * @return mixed + */ +if (!function_exists('getPackingList')) { + function getPackingList(Company $company) + { + return $company->orderPackingLists()->where('packing_lists.type', PackingListType::SHIPPING_PACKING_LIST)->get(); + } +} + diff --git a/app/Models/Address.php b/app/Models/Address.php index 8357940f..32ac4841 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -4,16 +4,22 @@ namespace App\Models; use App\Classes\General\Interfaces\Contactable; use App\Classes\General\Interfaces\Remarkable; +use Barryvdh\LaravelIdeHelper\Eloquent; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\MorphTo; +use Illuminate\Support\Carbon; +use Spatie\Activitylog\Models\Activity; + /** * Class Address - * @package App\Models * + * @package App\Models * @property int country_id * @property int company_id * @property int state_id @@ -22,6 +28,53 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; * @property string street_one * @property string street_two * @property integer billing_type + * @property int $id + * @property string $owner_type + * @property int $owner_id + * @property string|null $reference + * @property int $type + * @property int $default + * @property int $status + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Model|Eloquent $causer + * @property-read Collection|Contact[] $contacts + * @property-read int|null $contacts_count + * @property-read Country|null $country + * @property-read District|null $district + * @property-read Model|Eloquent $owner + * @property-read Collection|Remark[] $remarks + * @property-read int|null $remarks_count + * @property-read State|null $state + * @property-read Model|Eloquent $subject + * @property-read Model|Eloquent $target + * @method static Builder|Address defaultAddress() + * @method static Builder|Address newModelQuery() + * @method static Builder|Address newQuery() + * @method static \Illuminate\Database\Query\Builder|Address onlyTrashed() + * @method static Builder|Address query() + * @method static Builder|Address whereCountryId($value) + * @method static Builder|Address whereCreatedAt($value) + * @method static Builder|Address whereDefault($value) + * @method static Builder|Address whereDeletedAt($value) + * @method static Builder|Address whereDistrictId($value) + * @method static Builder|Address whereId($value) + * @method static Builder|Address whereOwnerId($value) + * @method static Builder|Address whereOwnerType($value) + * @method static Builder|Address wherePostcode($value) + * @method static Builder|Address whereReference($value) + * @method static Builder|Address whereStateId($value) + * @method static Builder|Address whereStatus($value) + * @method static Builder|Address whereStreetOne($value) + * @method static Builder|Address whereStreetTwo($value) + * @method static Builder|Address whereType($value) + * @method static Builder|Address whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|Address withTrashed() + * @method static \Illuminate\Database\Query\Builder|Address withoutTrashed() + * @mixin Eloquent */ class Address extends AbstractModel implements Contactable, Remarkable { @@ -58,7 +111,7 @@ class Address extends AbstractModel implements Contactable, Remarkable } /** - * @return \Illuminate\Database\Eloquent\Relations\MorphTo + * @return MorphTo */ public function owner(): morphTo { diff --git a/app/Models/Announcement.php b/app/Models/Announcement.php index b0094a6c..2cd69d3d 100644 --- a/app/Models/Announcement.php +++ b/app/Models/Announcement.php @@ -2,13 +2,56 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Carbon; +use Spatie\Activitylog\Models\Activity; /** * Class Announcement - * @package App\Models * + * @package App\Models + * @property int $id + * @property string $title + * @property string $description + * @property string|null $starting_on + * @property string|null $ending_on + * @property int $is_all_day + * @property int $duration + * @property int $is_recurring + * @property string|null $recurrence_pattern + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Model|\Eloquent $causer + * @property-read Collection|Segment[] $segments + * @property-read int|null $segments_count + * @property-read Model|\Eloquent $subject + * @property-read Model|\Eloquent $target + * @method static Builder|Announcement newModelQuery() + * @method static Builder|Announcement newQuery() + * @method static \Illuminate\Database\Query\Builder|Announcement onlyTrashed() + * @method static Builder|Announcement query() + * @method static Builder|Announcement whereCreatedAt($value) + * @method static Builder|Announcement whereDeletedAt($value) + * @method static Builder|Announcement whereDescription($value) + * @method static Builder|Announcement whereDuration($value) + * @method static Builder|Announcement whereEndingOn($value) + * @method static Builder|Announcement whereId($value) + * @method static Builder|Announcement whereIsAllDay($value) + * @method static Builder|Announcement whereIsRecurring($value) + * @method static Builder|Announcement whereRecurrencePattern($value) + * @method static Builder|Announcement whereStartingOn($value) + * @method static Builder|Announcement whereTitle($value) + * @method static Builder|Announcement whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|Announcement withTrashed() + * @method static \Illuminate\Database\Query\Builder|Announcement withoutTrashed() + * @mixin \Eloquent */ class Announcement extends AbstractModel { @@ -17,7 +60,7 @@ class Announcement extends AbstractModel protected $table = 'announcements'; /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany **/ public function segments(): BelongsToMany { diff --git a/app/Models/BankAccount.php b/app/Models/BankAccount.php index 94e2f00f..33254bcb 100644 --- a/app/Models/BankAccount.php +++ b/app/Models/BankAccount.php @@ -3,13 +3,64 @@ namespace App\Models; use App\Classes\General\Interfaces\DataTransferObject; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Support\Carbon; +use Spatie\Activitylog\Models\Activity; +/** + * App\Models\BankAccount + * + * @property int $id + * @property string $owner_type + * @property int $owner_id + * @property int $country_id + * @property string $bank_name + * @property string|null $bank_branch + * @property string $account_name + * @property string $account_number + * @property int $type + * @property int $default + * @property int $status + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Model|\Eloquent $causer + * @property-read Country|null $country + * @property-read Model|\Eloquent $owner + * @property-read Model|\Eloquent $subject + * @property-read Model|\Eloquent $target + * @method static Builder|BankAccount newModelQuery() + * @method static Builder|BankAccount newQuery() + * @method static \Illuminate\Database\Query\Builder|BankAccount onlyTrashed() + * @method static Builder|BankAccount query() + * @method static Builder|BankAccount whereAccountName($value) + * @method static Builder|BankAccount whereAccountNumber($value) + * @method static Builder|BankAccount whereBankBranch($value) + * @method static Builder|BankAccount whereBankName($value) + * @method static Builder|BankAccount whereCountryId($value) + * @method static Builder|BankAccount whereCreatedAt($value) + * @method static Builder|BankAccount whereDefault($value) + * @method static Builder|BankAccount whereDeletedAt($value) + * @method static Builder|BankAccount whereId($value) + * @method static Builder|BankAccount whereOwnerId($value) + * @method static Builder|BankAccount whereOwnerType($value) + * @method static Builder|BankAccount whereStatus($value) + * @method static Builder|BankAccount whereType($value) + * @method static Builder|BankAccount whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|BankAccount withTrashed() + * @method static \Illuminate\Database\Query\Builder|BankAccount withoutTrashed() + * @mixin \Eloquent + */ class BankAccount extends AbstractModel implements DataTransferObject { use SoftDeletes; diff --git a/app/Models/Company.php b/app/Models/Company.php index 6305b971..bf5dabd0 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -5,24 +5,72 @@ namespace App\Models; use App\Classes\General\Interfaces\Documentable; use App\Classes\General\Interfaces\Contactable; use App\Classes\ValueObjects\Constants\BusinessType; +use Eloquent; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Carbon; +use Spatie\Activitylog\Models\Activity; use Staudenmeir\EloquentHasManyDeep\HasManyDeep; use Staudenmeir\EloquentHasManyDeep\HasRelationships; /** * Class Company - * @package App\Models * - * @property \App\Models\Country country_id - * @property \App\Models\State state_id - * @property \App\Models\District district_id + * @package App\Models + * @property Country country_id + * @property State state_id + * @property District district_id * @property string postcode * @property string street_one * @property string street_two * @property integer billing_type + * @property int $id + * @property string $name + * @property string $reference + * @property string|null $debtor + * @property int $type + * @property int $status + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Collection|Address[] $addresses + * @property-read int|null $addresses_count + * @property-read Collection|BankAccount[] $banks + * @property-read int|null $banks_count + * @property-read Model|Eloquent $causer + * @property-read Collection|CompanyModule[] $companyModules + * @property-read int|null $company_modules_count + * @property-read Collection|Contact[] $contacts + * @property-read int|null $contacts_count + * @property-read Collection|Document[] $documents + * @property-read int|null $documents_count + * @property-read Collection|User[] $employees + * @property-read int|null $employees_count + * @property-read Model|Eloquent $subject + * @property-read Model|Eloquent $target + * @method static Builder|Company newModelQuery() + * @method static Builder|Company newQuery() + * @method static \Illuminate\Database\Query\Builder|Company onlyTrashed() + * @method static Builder|Company query() + * @method static Builder|Company whereCreatedAt($value) + * @method static Builder|Company whereDebtor($value) + * @method static Builder|Company whereDeletedAt($value) + * @method static Builder|Company whereId($value) + * @method static Builder|Company whereName($value) + * @method static Builder|Company whereReference($value) + * @method static Builder|Company whereStatus($value) + * @method static Builder|Company whereType($value) + * @method static Builder|Company whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|Company withTrashed() + * @method static \Illuminate\Database\Query\Builder|Company withoutTrashed() + * @mixin Eloquent */ class Company extends AbstractModel implements Documentable, Contactable { diff --git a/app/Models/CompanyModule.php b/app/Models/CompanyModule.php index 4e9c0526..22c09ddc 100644 --- a/app/Models/CompanyModule.php +++ b/app/Models/CompanyModule.php @@ -10,7 +10,9 @@ use App\Classes\General\Interfaces\Packable; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\BusinessType; +use Eloquent; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -20,18 +22,83 @@ use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Carbon; use PhpParser\Node\Expr\AssignOp\Mod; +use Spatie\Activitylog\Models\Activity; use Staudenmeir\EloquentHasManyDeep\HasManyDeep; use Staudenmeir\EloquentHasManyDeep\HasRelationships; use App\Classes\General\Interfaces\Remarkable; /** * Class CompanyModule - * @package App\Models * - * @property \App\Models\Company company_id + * @package App\Models + * @property Company company_id * @property integer type * @property integer status + * @property int $id + * @property string $name + * @property string $reference + * @property string $unity_hash_id + * @property string $unity_signature + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Collection|Address[] $addresses + * @property-read int|null $addresses_count + * @property-read Collection|BankAccount[] $banks + * @property-read int|null $banks_count + * @property-read Model|Eloquent $causer + * @property-read Company $company + * @property-read Collection|CompanyConnection[] $connections + * @property-read int|null $connections_count + * @property-read Collection|Contact[] $contacts + * @property-read int|null $contacts_count + * @property-read Collection|Container[] $containers + * @property-read int|null $containers_count + * @property-read Collection|Document[] $documents + * @property-read int|null $documents_count + * @property-read Collection|User[] $employees + * @property-read int|null $employees_count + * @property-read Collection|CompanyModule[] $inviters + * @property-read int|null $inviters_count + * @property-read Collection|CompanyModule[] $invites + * @property-read int|null $invites_count + * @property-read Collection|Order[] $orders + * @property-read int|null $orders_count + * @property-read Collection|PackingList[] $packingLists + * @property-read int|null $packing_lists_count + * @property-read Collection|Remark[] $remarks + * @property-read int|null $remarks_count + * @property-read Collection|Segment[] $segments + * @property-read int|null $segments_count + * @property-read Model|Eloquent $subject + * @property-read Model|Eloquent $target + * @property-read Collection|Wallet[] $wallets + * @property-read int|null $wallets_count + * @method static Builder|CompanyModule freightForwarders() + * @method static Builder|CompanyModule importers() + * @method static Builder|CompanyModule newModelQuery() + * @method static Builder|CompanyModule newQuery() + * @method static \Illuminate\Database\Query\Builder|CompanyModule onlyTrashed() + * @method static Builder|CompanyModule query() + * @method static Builder|CompanyModule warehouses() + * @method static Builder|CompanyModule whereCompanyId($value) + * @method static Builder|CompanyModule whereCreatedAt($value) + * @method static Builder|CompanyModule whereDeletedAt($value) + * @method static Builder|CompanyModule whereId($value) + * @method static Builder|CompanyModule whereName($value) + * @method static Builder|CompanyModule whereReference($value) + * @method static Builder|CompanyModule whereStatus($value) + * @method static Builder|CompanyModule whereType($value) + * @method static Builder|CompanyModule whereUnityHashId($value) + * @method static Builder|CompanyModule whereUnitySignature($value) + * @method static Builder|CompanyModule whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|CompanyModule withTrashed() + * @method static \Illuminate\Database\Query\Builder|CompanyModule withoutTrashed() + * @mixin Eloquent */ class CompanyModule extends AbstractModel implements Addressable, Documentable, Contactable, ContainerOwner, Packable, Remarkable { @@ -194,7 +261,11 @@ class CompanyModule extends AbstractModel implements Addressable, Documentable, return $this->hasManyDeep(Transaction::class, [Order::class], ['company_module_id', 'owner_id'], ['id', 'id']); } - - - + /** + * @return MorphMany + */ + public function wallets(): morphMany + { + return $this->morphMany(Wallet::class, 'owner'); + } } diff --git a/app/Models/Contact.php b/app/Models/Contact.php index f8ce6213..d36efb09 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -2,13 +2,18 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\MorphTo; +use Illuminate\Support\Carbon; +use Spatie\Activitylog\Models\Activity; /** * Class Contact - * @package App\Models * + * @package App\Models * @property int owner_id * @property string owner_type * @property string reference @@ -16,6 +21,34 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; * @property string email * @property string wechat_id * @property int default + * @property int $id + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Model|\Eloquent $causer + * @property-read Model|\Eloquent $owner + * @property-read Model|\Eloquent $subject + * @property-read Model|\Eloquent $target + * @method static Builder|Contact newModelQuery() + * @method static Builder|Contact newQuery() + * @method static \Illuminate\Database\Query\Builder|Contact onlyTrashed() + * @method static Builder|Contact query() + * @method static Builder|Contact whereCreatedAt($value) + * @method static Builder|Contact whereDefault($value) + * @method static Builder|Contact whereDeletedAt($value) + * @method static Builder|Contact whereEmail($value) + * @method static Builder|Contact whereId($value) + * @method static Builder|Contact whereOwnerId($value) + * @method static Builder|Contact whereOwnerType($value) + * @method static Builder|Contact wherePhone($value) + * @method static Builder|Contact whereReference($value) + * @method static Builder|Contact whereUpdatedAt($value) + * @method static Builder|Contact whereWechatId($value) + * @method static \Illuminate\Database\Query\Builder|Contact withTrashed() + * @method static \Illuminate\Database\Query\Builder|Contact withoutTrashed() + * @mixin \Eloquent */ class Contact extends AbstractModel { diff --git a/app/Models/Container.php b/app/Models/Container.php index efe946f9..7a40795e 100644 --- a/app/Models/Container.php +++ b/app/Models/Container.php @@ -5,12 +5,63 @@ namespace App\Models; use App\Classes\General\Interfaces\Remarkable; use App\Classes\General\Interfaces\Transportable; use App\Classes\General\Traits\LogData; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\MorphMany; +use Illuminate\Support\Carbon; +use Spatie\Activitylog\Models\Activity; use Staudenmeir\EloquentHasManyDeep\HasManyDeep; use Staudenmeir\EloquentHasManyDeep\HasRelationships; +/** + * App\Models\Container + * + * @property int $id + * @property string $owner_type + * @property int $owner_id + * @property string $reference + * @property string|null $container_number + * @property int $container_type + * @property string|null $seal_reference + * @property Carbon|null $loading_date + * @property int $status + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Model|\Eloquent $causer + * @property-read Collection|PackingList[] $packingLists + * @property-read int|null $packing_lists_count + * @property-read Collection|Remark[] $remarks + * @property-read int|null $remarks_count + * @property-read Model|\Eloquent $subject + * @property-read Model|\Eloquent $target + * @property-read Collection|\App\Models\Transport[] $transports + * @property-read int|null $transports_count + * @method static Builder|Container newModelQuery() + * @method static Builder|Container newQuery() + * @method static \Illuminate\Database\Query\Builder|Container onlyTrashed() + * @method static Builder|Container query() + * @method static Builder|Container whereContainerNumber($value) + * @method static Builder|Container whereContainerType($value) + * @method static Builder|Container whereCreatedAt($value) + * @method static Builder|Container whereDeletedAt($value) + * @method static Builder|Container whereId($value) + * @method static Builder|Container whereLoadingDate($value) + * @method static Builder|Container whereOwnerId($value) + * @method static Builder|Container whereOwnerType($value) + * @method static Builder|Container whereReference($value) + * @method static Builder|Container whereSealReference($value) + * @method static Builder|Container whereStatus($value) + * @method static Builder|Container whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|Container withTrashed() + * @method static \Illuminate\Database\Query\Builder|Container withoutTrashed() + * @mixin \Eloquent + */ class Container extends AbstractModel implements Transportable, Remarkable { use HasRelationships; diff --git a/app/Models/Currency.php b/app/Models/Currency.php index cf3b4a6f..0b2718db 100644 --- a/app/Models/Currency.php +++ b/app/Models/Currency.php @@ -2,20 +2,52 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\hasMany; +use Illuminate\Support\Carbon; +use Spatie\Activitylog\Models\Activity; /** * Class Currency - * @package App\Models * - * @property \App\Models\Country country_id + * @package App\Models + * @property Country country_id * @property string name * @property string short_code * @property string symbol + * @property int $id + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Model|\Eloquent $causer + * @property-read Country|null $country + * @property-read Collection|CurrencyRate[] $rates + * @property-read int|null $rates_count + * @property-read Model|\Eloquent $subject + * @property-read Model|\Eloquent $target + * @method static Builder|Currency newModelQuery() + * @method static Builder|Currency newQuery() + * @method static \Illuminate\Database\Query\Builder|Currency onlyTrashed() + * @method static Builder|Currency query() + * @method static Builder|Currency whereCountryId($value) + * @method static Builder|Currency whereCreatedAt($value) + * @method static Builder|Currency whereDeletedAt($value) + * @method static Builder|Currency whereId($value) + * @method static Builder|Currency whereName($value) + * @method static Builder|Currency whereShortCode($value) + * @method static Builder|Currency whereSymbol($value) + * @method static Builder|Currency whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|Currency withTrashed() + * @method static \Illuminate\Database\Query\Builder|Currency withoutTrashed() + * @mixin \Eloquent */ class Currency extends AbstractModel diff --git a/app/Models/Document.php b/app/Models/Document.php index eb3f8c77..b2b7779b 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -3,17 +3,21 @@ namespace App\Models; use Carbon\Traits\Timestamp; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\hasMany; +use Illuminate\Support\Carbon; +use Spatie\Activitylog\Models\Activity; /** * Class Document * @package App\Models * @version August 4, 2020, 4:36 am - * * @property int owner_id * @property int owner_type * @property int document_type @@ -23,6 +27,39 @@ use Illuminate\Database\Eloquent\Relations\hasMany; * @property timestamp issued_date * @property timestamp expired_date * @property timestamp approved_date + * @property int $id + * @property string|null $approval_date + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Model|\Eloquent $causer + * @property-read Collection|File[] $files + * @property-read int|null $files_count + * @property-read Model|\Eloquent $owner + * @property-read Model|\Eloquent $subject + * @property-read Model|\Eloquent $target + * @method static Builder|Document newModelQuery() + * @method static Builder|Document newQuery() + * @method static \Illuminate\Database\Query\Builder|Document onlyTrashed() + * @method static Builder|Document query() + * @method static Builder|Document whereApprovalDate($value) + * @method static Builder|Document whereApprover($value) + * @method static Builder|Document whereCreatedAt($value) + * @method static Builder|Document whereDeletedAt($value) + * @method static Builder|Document whereDocumentType($value) + * @method static Builder|Document whereExpiredDate($value) + * @method static Builder|Document whereId($value) + * @method static Builder|Document whereIssuedDate($value) + * @method static Builder|Document whereOwnerId($value) + * @method static Builder|Document whereOwnerType($value) + * @method static Builder|Document whereReference($value) + * @method static Builder|Document whereStatus($value) + * @method static Builder|Document whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|Document withTrashed() + * @method static \Illuminate\Database\Query\Builder|Document withoutTrashed() + * @mixin \Eloquent */ class Document extends AbstractModel { @@ -43,7 +80,7 @@ class Document extends AbstractModel /** * @return hasMany */ - public function files(): hasMany + public function files(): hasMany { return $this->hasMany(File::class, 'document_id'); } diff --git a/app/Models/File.php b/app/Models/File.php index 6707fd9f..9b307501 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -2,17 +2,45 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Carbon; +use Spatie\Activitylog\Models\Activity; /** * Class File + * * @package App\Models * @version August 4, 2020, 4:36 am - * - * @property \App\Models\Document document_id + * @property Document document_id * @property text file * @property int file_type_id + * @property int $id + * @property string $file_type + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Model|\Eloquent $causer + * @property-read Model|\Eloquent $subject + * @property-read Model|\Eloquent $target + * @method static Builder|File newModelQuery() + * @method static Builder|File newQuery() + * @method static \Illuminate\Database\Query\Builder|File onlyTrashed() + * @method static Builder|File query() + * @method static Builder|File whereCreatedAt($value) + * @method static Builder|File whereDeletedAt($value) + * @method static Builder|File whereDocumentId($value) + * @method static Builder|File whereFile($value) + * @method static Builder|File whereFileType($value) + * @method static Builder|File whereId($value) + * @method static Builder|File whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|File withTrashed() + * @method static \Illuminate\Database\Query\Builder|File withoutTrashed() + * @mixin \Eloquent */ class File extends AbstractModel { diff --git a/app/Models/Group.php b/app/Models/Group.php new file mode 100644 index 00000000..a201b1ca --- /dev/null +++ b/app/Models/Group.php @@ -0,0 +1,106 @@ +belongsToMany(Transaction::class, GroupTransaction::class); + // return $this->MorphMany(Transaction::class, 'owner'); + // } + + /** + * @return MorphMany + */ + public function transactions(): MorphMany + { + return $this->MorphMany(Transaction::class, 'owner'); + } + + /** + * @return MorphMany + */ + public function documents(): morphMany + { + return $this->morphMany(Document::class, 'owner'); + } + + /** + * @return BelongsTo + */ + public function currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'currency_id', 'id'); + } + + + /** + * @return HasManyDeep + */ + public function transferFees(): HasManyDeep + { + return $this->HasManyDeep(Transaction::class, [GroupTransaction::class, Transaction::class.' as alias'], ['group_id', ['owner_type', 'owner_id'], ['owner_type', 'owner_id']], ['id', null, null]); + } + + /** + * @return BelongsTo + */ + public function issuerCompany(): BelongsTo + { + return $this->BelongsTo(CompanyModule::class, 'issuer', 'id'); + } + + /** + * @return BelongsTo + */ + public function receiverCompany(): BelongsTo + { + return $this->BelongsTo(CompanyModule::class, 'receiver', 'id'); + } + + /** + * @return BelongsTo + */ + public function original_currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'original_currency_id', 'id'); + } +} diff --git a/app/Models/GroupTransaction.php b/app/Models/GroupTransaction.php new file mode 100644 index 00000000..9ab72d18 --- /dev/null +++ b/app/Models/GroupTransaction.php @@ -0,0 +1,27 @@ +BelongsTo(Group::class, 'group_id', 'id'); + } + + /** + * @return BelongsTo + */ + public function transaction(): BelongsTo + { + return $this->BelongsTo(Transaction::class, 'transaction_id', 'id'); + } +} diff --git a/app/Models/Order.php b/app/Models/Order.php index 312cd244..8bb7955f 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -11,14 +11,70 @@ use App\Classes\ValueObjects\Constants\PackingListType; use App\Classes\ValueObjects\Constants\RoleTypes; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Scopes\CustomerOrdersScope; +use Eloquent; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphMany; +use Illuminate\Database\Query\Builder; +use Illuminate\Support\Carbon; +use Spatie\Activitylog\Models\Activity; use Staudenmeir\EloquentHasManyDeep\HasManyDeep; use Staudenmeir\EloquentHasManyDeep\HasRelationships; +/** + * App\Models\Order + * + * @method static whereBetween(string $string, array $array) + * @property int $id + * @property int $company_module_id + * @property string $reference + * @property string|null $reference_contract + * @property int $type Order packages can be shipped in shared or dedicated container + * @property int $status Status of this order, e.g. processing, shipping etc. + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|OrderRole[] $OrderRoles + * @property-read int|null $order_roles_count + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Collection|Addon[] $addons + * @property-read int|null $addons_count + * @property-read Collection|Address[] $addresses + * @property-read int|null $addresses_count + * @property-read Model|Eloquent $causer + * @property-read CompanyModule|null $companyModule + * @property-read Collection|Step[] $orderSteps + * @property-read int|null $order_steps_count + * @property-read Collection|PackingList[] $packingLists + * @property-read int|null $packing_lists_count + * @property-read Collection|Package[] $parcels + * @property-read int|null $parcels_count + * @property-read Collection|Remark[] $remarks + * @property-read int|null $remarks_count + * @property-read Model|Eloquent $subject + * @property-read Model|Eloquent $target + * @method static \Illuminate\Database\Eloquent\Builder|Order newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Order newQuery() + * @method static Builder|Order onlyTrashed() + * @method static \Illuminate\Database\Eloquent\Builder|Order query() + * @method static \Illuminate\Database\Eloquent\Builder|Order whereCompanyModuleId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Order whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Order whereDeletedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Order whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Order whereReference($value) + * @method static \Illuminate\Database\Eloquent\Builder|Order whereReferenceContract($value) + * @method static \Illuminate\Database\Eloquent\Builder|Order whereStatus($value) + * @method static \Illuminate\Database\Eloquent\Builder|Order whereType($value) + * @method static \Illuminate\Database\Eloquent\Builder|Order whereUpdatedAt($value) + * @method static Builder|Order withTrashed() + * @method static Builder|Order withoutTrashed() + * @mixin Eloquent + */ class Order extends AbstractModel implements Addressable, Packable, Remarkable, Notifiable { use SoftDeletes; diff --git a/app/Models/Package.php b/app/Models/Package.php index cb2bf35f..02b19a3a 100644 --- a/app/Models/Package.php +++ b/app/Models/Package.php @@ -7,15 +7,71 @@ use App\Classes\ValueObjects\Constants\PackingListType; use App\Classes\ValueObjects\Constants\RoleTypes; use App\Scopes\CustomerOrdersScope; use App\Scopes\CustomerPackagesScope; +use Barryvdh\LaravelIdeHelper\Eloquent; use Carbon\Carbon; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasOneThrough; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Query\Builder; +use Spatie\Activitylog\Models\Activity; use Staudenmeir\EloquentHasManyDeep\HasManyDeep; use Staudenmeir\EloquentHasManyDeep\HasOneDeep; use Staudenmeir\EloquentHasManyDeep\HasRelationships; +/** + * App\Models\Package + * + * @property int $id + * @property int $packing_list_id + * @property int $type + * @property string|null $reference + * @property string|null $description + * @property string $width + * @property string $height + * @property string $length + * @property string $weight + * @property int $quantity + * @property int $status + * @property \Illuminate\Support\Carbon|null $deleted_at + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Model|Eloquent $causer + * @property-read Collection|Transport[] $deliveryTransports + * @property-read int|null $delivery_transports_count + * @property-read PackingList|null $packingList + * @property-read Model|Eloquent $subject + * @property-read Model|Eloquent $target + * @method static \Illuminate\Database\Eloquent\Builder|Package newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Package newQuery() + * @method static Builder|Package onlyTrashed() + * @method static \Illuminate\Database\Eloquent\Builder|Package query() + * @method static \Illuminate\Database\Eloquent\Builder|Package shipped() + * @method static \Illuminate\Database\Eloquent\Builder|Package shipping() + * @method static \Illuminate\Database\Eloquent\Builder|Package shippingList() + * @method static \Illuminate\Database\Eloquent\Builder|Package warehouseReceiveList() + * @method static \Illuminate\Database\Eloquent\Builder|Package whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereDeletedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereDescription($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereHeight($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereLength($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package wherePackingListId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereQuantity($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereReference($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereStatus($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereType($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereWeight($value) + * @method static \Illuminate\Database\Eloquent\Builder|Package whereWidth($value) + * @method static Builder|Package withTrashed() + * @method static Builder|Package withoutTrashed() + * @mixin Eloquent + */ class Package extends AbstractModel { use HasRelationships; diff --git a/app/Models/PackingList.php b/app/Models/PackingList.php index c26fca6c..d9be736b 100644 --- a/app/Models/PackingList.php +++ b/app/Models/PackingList.php @@ -10,15 +10,78 @@ use App\Classes\General\Interfaces\Transactionable; use App\Classes\General\Traits\LogData; use App\Classes\ValueObjects\Constants\ApprovalStatus; use Carbon\Carbon; +use Eloquent; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Query\Builder; +use Spatie\Activitylog\Models\Activity; use Staudenmeir\EloquentHasManyDeep\HasManyDeep; use Staudenmeir\EloquentHasManyDeep\HasRelationships; use Staudenmeir\EloquentHasManyDeep\HasTableAlias; +/** + * App\Models\PackingList + * + * @property int $id + * @property string $owner_type + * @property int $owner_id + * @property int|null $claimant_id + * @property string|null $reference_contract + * @property string $reference + * @property int $type + * @property int $status + * @property \Illuminate\Support\Carbon|null $deleted_at + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Collection|Addon[] $addons + * @property-read int|null $addons_count + * @property-read Model|Eloquent $causer + * @property-read Collection|Container[] $containers + * @property-read int|null $containers_count + * @property-read Model|Eloquent $owner + * @property-read Collection|Package[] $packages + * @property-read int|null $packages_count + * @property-read Collection|PackingList[] $packingLists + * @property-read int|null $packing_lists_count + * @property-read Collection|PackingList[] $packing_list_owner + * @property-read int|null $packing_list_owner_count + * @property-read Collection|Remark[] $remarks + * @property-read int|null $remarks_count + * @property-read Collection|Step[] $steps + * @property-read int|null $steps_count + * @property-read Model|Eloquent $subject + * @property-read Model|Eloquent $target + * @property-read Collection|Transaction[] $transactions + * @property-read int|null $transactions_count + * @property-read Collection|Transport[] $transports + * @property-read int|null $transports_count + * @method static \Illuminate\Database\Eloquent\Builder|PackingList newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|PackingList newQuery() + * @method static Builder|PackingList onlyTrashed() + * @method static \Illuminate\Database\Eloquent\Builder|PackingList query() + * @method static \Illuminate\Database\Eloquent\Builder|PackingList shipping() + * @method static \Illuminate\Database\Eloquent\Builder|PackingList whereClaimantId($value) + * @method static \Illuminate\Database\Eloquent\Builder|PackingList whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|PackingList whereDeletedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|PackingList whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|PackingList whereOwnerId($value) + * @method static \Illuminate\Database\Eloquent\Builder|PackingList whereOwnerType($value) + * @method static \Illuminate\Database\Eloquent\Builder|PackingList whereReference($value) + * @method static \Illuminate\Database\Eloquent\Builder|PackingList whereReferenceContract($value) + * @method static \Illuminate\Database\Eloquent\Builder|PackingList whereStatus($value) + * @method static \Illuminate\Database\Eloquent\Builder|PackingList whereType($value) + * @method static \Illuminate\Database\Eloquent\Builder|PackingList whereUpdatedAt($value) + * @method static Builder|PackingList withTrashed() + * @method static Builder|PackingList withoutTrashed() + * @mixin Eloquent + */ class PackingList extends AbstractModel implements Transportable, Steppable, Packable, Transactionable { use HasTableAlias; @@ -31,7 +94,7 @@ class PackingList extends AbstractModel implements Transportable, Steppable, Pac protected $fillable = ['status']; /** - * @return \Illuminate\Database\Eloquent\Relations\MorphTo + * @return MorphTo */ public function owner(): morphTo { diff --git a/app/Models/Remark.php b/app/Models/Remark.php index f2de3a5c..b17f6a43 100644 --- a/app/Models/Remark.php +++ b/app/Models/Remark.php @@ -2,10 +2,50 @@ namespace App\Models; +use Barryvdh\LaravelIdeHelper\Eloquent; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Query\Builder; +use Illuminate\Support\Carbon; +use Spatie\Activitylog\Models\Activity; +/** + * App\Models\Remark + * + * @property int $id + * @property string $owner_type + * @property int $owner_id + * @property int $commenter_id + * @property string $content + * @property Carbon|null $deleted_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Collection|Activity[] $activities + * @property-read int|null $activities_count + * @property-read Model|Eloquent $causer + * @property-read User|null $commenter + * @property-read Model|Eloquent $owner + * @property-read Model|Eloquent $subject + * @property-read Model|Eloquent $target + * @method static \Illuminate\Database\Eloquent\Builder|Remark newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Remark newQuery() + * @method static Builder|Remark onlyTrashed() + * @method static \Illuminate\Database\Eloquent\Builder|Remark query() + * @method static \Illuminate\Database\Eloquent\Builder|Remark whereCommenterId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Remark whereContent($value) + * @method static \Illuminate\Database\Eloquent\Builder|Remark whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Remark whereDeletedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Remark whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Remark whereOwnerId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Remark whereOwnerType($value) + * @method static \Illuminate\Database\Eloquent\Builder|Remark whereUpdatedAt($value) + * @method static Builder|Remark withTrashed() + * @method static Builder|Remark withoutTrashed() + * @mixin Eloquent + */ class Remark extends AbstractModel { use SoftDeletes; diff --git a/app/Models/RouteLog.php b/app/Models/RouteLog.php new file mode 100644 index 00000000..7e530293 --- /dev/null +++ b/app/Models/RouteLog.php @@ -0,0 +1,25 @@ +morphTo(); + } + + /** + * @return morphMany + */ + public function transactions(): morphMany + { + return $this->morphMany(Transaction::class, 'owner'); + } +} diff --git a/app/Transformers/AddressTransformer.php b/app/Transformers/AddressTransformer.php new file mode 100644 index 00000000..3eeeb999 --- /dev/null +++ b/app/Transformers/AddressTransformer.php @@ -0,0 +1,120 @@ + $address->id, + 'reference' => $address->reference, + 'street_one' => $address->street_one, + 'street_two' => $address->street_two, + 'district' => $address->district, + 'state' => $address->state, + 'postcode' => $address->postcode, + 'post_code' => $address->postcode, + 'post_code_area' => $this->getPostalCodeArea($address), + 'country' => $address->country, + 'default' => $address->default, + 'status' => $address->status, + 'type' => $address->type, + + ]; + } + + + /** + * Get Postal code Area + * @param Address $address + * @return string|null + */ + private function getPostalCodeArea(Address $address): ?string + { + $centerPostcodeConstantObject = SegmentConstant::where('reference', SegmentConstants::CENTER_POSTCODE)->get(); + $centerPostcodeConstant = $centerPostcodeConstantObject->isEmpty() ? [] : (array)$centerPostcodeConstantObject->first()->value; + return in_array($address->postcode, $centerPostcodeConstant) ? 'CENTER_POSTCODE' : null; + } + + /** + * Include Contact + * + * @param Address $address + * @return Item + */ + public function includeContact(Address $address): Item + { + $contact = $address->contacts(); + + return $this->item($contact->first(), new ContactTransformer()); + } + + /** + * Include in Remark + * @param Address $address + * @return Item + */ + public function includeRemark(Address $address): Item + { + $remarks = $address->remarks(); + return $this->item($remarks->first(), new RemarkTransformer()); + + } + + /** + * ?Owner Address info + * @param Address $address + * @return array + */ + public function includeOwner_address(Address $address): array + { + + return [ + 'owner' => $address->when($address->owner instanceof Order, [ + 'reference' => $address->owner->reference, + 'company_module' => $this->item($address->owner->companyModule, new RemarkTransformer()), + 'address' => $this->item($address->owner->addresses()->where('status', '=', ApprovalStatus::APPROVED)->first(), new AddressTransformer()), + ]) + ]; + + } + + +} diff --git a/app/Transformers/AnnouncementTransformer.php b/app/Transformers/AnnouncementTransformer.php new file mode 100644 index 00000000..f3b06032 --- /dev/null +++ b/app/Transformers/AnnouncementTransformer.php @@ -0,0 +1,47 @@ + $announcement->id, + 'title' => $announcement->title, + 'description' => $announcement->description, + 'segments' => $announcement->segments, + 'starting_on' => Carbon::parse($announcement->starting_on)->format('d-m-Y'), + 'ending_on' => Carbon::parse($announcement->ending_on)->format('d-m-Y'), + 'created_at' => Carbon::parse($announcement->created_at)->format('d-m-Y'), + ]; + } +} diff --git a/app/Transformers/BankAccountTransformer.php b/app/Transformers/BankAccountTransformer.php new file mode 100644 index 00000000..9bb3816b --- /dev/null +++ b/app/Transformers/BankAccountTransformer.php @@ -0,0 +1,50 @@ + $account->id, + 'company_business_type' => $account->company->business_type, + 'type' => $account->type, + 'reference' => $account->reference, + 'bank_name' => $account->bank_name, + 'bank_branch' => $account->bank_branch, + 'holder_name' => $account->holder_name, + 'account_no' => $account->account_no, + 'country_id' => $account->country_id, + 'default' => $account->default, + 'status' => $account->status, + ]; + } +} diff --git a/app/Transformers/CompanyModuleTransformer.php b/app/Transformers/CompanyModuleTransformer.php new file mode 100644 index 00000000..35f0e31f --- /dev/null +++ b/app/Transformers/CompanyModuleTransformer.php @@ -0,0 +1,140 @@ + $module->id, + 'type' => $module->type, + 'name' => $module->name, + 'reference' => $module->reference, + 'connections' => $module->connections, + 'marking' => $this->getMarkings($module), + 'warehouseCharges' => $this->calculateWarehouseCharges($module), + ]; + } + + /** + * Load Default Address + * @param CompanyModule $module + * @return Item + */ + public function includeAddress(CompanyModule $module): \League\Fractal\Resource\Item + { + $defaultAddress = $module->addresses()->defaultAddress()->first(); + $defaultAddress = $defaultAddress ? $defaultAddress : $this->addresses()->first(); + + return $this->item($defaultAddress, new AddressTransformer()); + } + + /** + * Load Billing Address + * @param CompanyModule $module + * @return Item + */ + + public function includeBillingAddress(CompanyModule $module): Item + { + $billingAddress = $module->addresses()->where('type', AddressType::BILLING)->where('status', ApprovalStatus::APPROVED)->first(); + return $this->item($billingAddress, new AddressTransformer()); + } + + /** + * include the company + * @param CompanyModule $module + * @return Item + */ + public function includeCompany(CompanyModule $module): Item + { + $company = $module->company()->first(); + return $this->item($company, new CompanyTransformer()); + + } + + /** + * Load Remarks + * @param CompanyModule $module + * @return Collection + */ + public function includeRemarks(CompanyModule $module): Collection + { + $remarks = $module->remarks(); + return $this->collection($remarks, new RemarkTransformer); + + } + + /** + * Get Markings + * @param CompanyModule $module + * @return string + */ + public function getMarkings(CompanyModule $module): string + { + $connection = $module->inviters()->withPivot('invitee_reference')->first(); + return $connection ? $connection->pivot->invitee_reference : ''; + } + + /** + * calculate warehouse charges + * @param CompanyModule $module + * @return mixed|null + */ + public function calculateWarehouseCharges(CompanyModule $module) + { + $segmentConstantObject = SegmentConstant::where('reference', SegmentConstants::WAREHOUSE_RATE)->get(); + $segmentConstant = $segmentConstantObject->isEmpty() ? [] : (array)$segmentConstantObject->first()->value; + + return array_key_exists($module->id, $segmentConstant) ? $segmentConstant[$module->id] : null; + } + + /** + * include the contact + * @param CompanyModule $module + * @return Item + */ + public function includeContact(CompanyModule $module): Item + { + $contact = $module->contacts()->first(); + return $this->item($contact, new ContactTransformer()); + } + +} diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php new file mode 100644 index 00000000..504c2e23 --- /dev/null +++ b/app/Transformers/CompanyTransformer.php @@ -0,0 +1,64 @@ + $company->id, + 'hash_id' => Crypt::encryptString($company->id), + 'name' => $company->name, + 'debtor' => $company->debtor, + 'reference' => $company->reference, + 'type' => $company->type, + 'business_type' => (int)$company->business_type, + 'status' => $company->status, + 'created_at' => $company->created_at->format('d-m-Y') + ]; + + } + + + /** + * Include Contact + * + * @param Company $company + * @return Item + */ + public function includeContact(Company $company): Item + { + $contact = $company->contacts(); + + return $this->item($contact->first(), new ContactTransformer()); + } +} diff --git a/app/Transformers/ContactTransformer.php b/app/Transformers/ContactTransformer.php new file mode 100644 index 00000000..f23bfa57 --- /dev/null +++ b/app/Transformers/ContactTransformer.php @@ -0,0 +1,35 @@ + $contact->id, + 'reference' => $contact->reference, + 'phone' => $contact->phone, + 'email' => $contact->email, + 'wechat_id' => $contact->wechat_id, + ]; + + } + +} diff --git a/app/Transformers/ContainerTransformer.php b/app/Transformers/ContainerTransformer.php new file mode 100644 index 00000000..40bb0b3f --- /dev/null +++ b/app/Transformers/ContainerTransformer.php @@ -0,0 +1,89 @@ + $container->id, + 'container_reference' => $container->reference, + 'container_specification' => ContainerTypes::CONTAINER_SPECIFICATION[$container->container_type], + 'container_number' => $container->container_number, + 'seal_reference' => $container->seal_reference, + 'loading_date' => $container->loading_date ? $container->loading_date->format('d-m-Y') : $container->loading_date, + 'packages_count' => $container->packages()->where('packages.type', '!=', 2)->sum('quantity'), + 'total_cbm' => $container->packages()->sum(DB::raw('(width/100) * (height/100) * (length/100) * quantity')), + 'status' => $container->status, + ]; + } + + /** + * Include Transport + * @param Container $container + * @return Item + */ + public function includeTransport(Container $container): Item + { + $container = $container->transport()->first(); + return $this->item($container, new TransportTransformer()); + } + + /** + * Include Remarks + * @param Container $container + * @return Collection + */ + public function includeRemarks(Container $container): Collection + { + $remarks = $container->remarks()->get(); + return $this->collection($remarks, new RemarkTransformer()); + } + + /** + * include Packages Lists + * @param Container $container + * @return Collection + */ + public function includePackagesList(Container $container): Collection + { + $packages = $container->packingLists()->get()->sortBy(function ($packingList) { + return $packingList->owner->company_module_id; + }); + return $this->collection($packages, new PackageListTransformer); + } +} + diff --git a/app/Transformers/CurrencyTransformer.php b/app/Transformers/CurrencyTransformer.php new file mode 100644 index 00000000..5d5ffa37 --- /dev/null +++ b/app/Transformers/CurrencyTransformer.php @@ -0,0 +1,43 @@ + $currency->id, + 'name' => $currency->name, + 'short_code' => $currency->short_code, + 'phone_code' => $currency->phone_code, + ]; + } +} diff --git a/app/Transformers/DeliverPackingListTransformer.php b/app/Transformers/DeliverPackingListTransformer.php new file mode 100644 index 00000000..9e4fd620 --- /dev/null +++ b/app/Transformers/DeliverPackingListTransformer.php @@ -0,0 +1,78 @@ + $this->$list, + 'claimant_id' => $list->claimant_id, + 'reference' => $list->reference, + 'status' => $list->status, + ]; + } + + /** + * include transport + * @param PackingList $list + * @return Item + */ + public function includeTransport(PackingList $list): Item + { + return $this->item($list->transports()->first(), new TransportTransformer); + } + + /** + * add packing list + * @param PackingList $list + * @return Collection + */ + public function includePackingList(PackingList $list): Collection + { + return $this->collection($list->packing_list_owner(), new PackageListTransformer); + } + + /** + * add company + * @param PackingList $list + * @return Item + */ + public function includeCompany(PackingList $list): Item + { + return $this->item($list->owner(), new CompanyModuleTransformer); + } +} diff --git a/app/Transformers/DeliveryOrderTransformer.php b/app/Transformers/DeliveryOrderTransformer.php new file mode 100644 index 00000000..f6c6a51a --- /dev/null +++ b/app/Transformers/DeliveryOrderTransformer.php @@ -0,0 +1,102 @@ + $order->id, + 'reference' => $order->reference, + 'type' => $order->type, + 'status' => $order->status, + 'created_at' => $order->created_at->format('d-m-Y') + ]; + } + + /** + * Include CompanyModule + * @param Order $order + * @return Item + */ + public function includeCompanyModule(Order $order): Item + { + return $this->item($order->companyModule, new CompanyModuleTransformer()); + } + + /** + * Include SenderAddress + * @param Order $order + * @return Item + */ + public function includeSenderAddress(Order $order): Item + { + return $this->item($order->addresses()->where('status', '=', ApprovalStatus::APPROVED)->where('type', AddressType::PICK_UP)->first(), new AddressTransformer()); + } + + /** + * Include DeliveryAddress + * @param Order $order + * @return Item + */ + + public function includeDeliveryAddress(Order $order): Item + { + return $this->item($order->addresses()->where('status', '=', ApprovalStatus::APPROVED)->where('type', AddressType::DELIVERY)->first(), new AddressTransformer()); + } + + /** + * Include PackingList + * @param Order $order + * @return Item + */ + public function includePackingList(Order $order): Item + { + return $this->item($order->packingLists()->first(), new DeliveryPackingListTransformer()); + } + + /** + * Include Remarks + * @param Order $order + * @return Item + */ + public function includeRemarks(Order $order): Item + { + return $this->item($order->remarks, new RemarkTransformer()); + } +} diff --git a/app/Transformers/DeliveryPackingListTransformer.php b/app/Transformers/DeliveryPackingListTransformer.php new file mode 100644 index 00000000..af9e18b4 --- /dev/null +++ b/app/Transformers/DeliveryPackingListTransformer.php @@ -0,0 +1,60 @@ +packages()->first(); + + return [ + 'id' => $list->id, + 'claimant_id' => $list->claimant_id, + 'reference' => $list->reference, + 'status' => $list->status, + 'type' => $package->type, + 'description' => $package->description, + 'weight' => (float)$package->weight, + 'quantity' => (float)$package->quantity, + ]; + } + + /** + * Include Transport + * + * @param PackingList $list + * @return Item + */ + public function includeTransport(PackingList $list): Item + { + return $this->item($list->transports()->first(), new TransportTransformer()); + } +} diff --git a/app/Transformers/DocumentTransformer.php b/app/Transformers/DocumentTransformer.php new file mode 100644 index 00000000..9931a04b --- /dev/null +++ b/app/Transformers/DocumentTransformer.php @@ -0,0 +1,52 @@ + $document->id, + 'reference' => $document->reference, + 'status' => $document->status, + 'document_type' => $document->document_type, + 'created_at' => Carbon::parse($document->created_at)->format('d-m-Y h:i:s A') + ]; + } + + public function includeFiles(Document $document): Collection + { + $files = $document->files; + return $this->collection($files, new FileTransformer()); + } + + public function includeOwner(Document $document): Item + { + $owner = $document->owner; + return $this->item($owner, new CompanyTransformer()); + } + +} diff --git a/app/Transformers/FileTransformer.php b/app/Transformers/FileTransformer.php new file mode 100644 index 00000000..94cf07ac --- /dev/null +++ b/app/Transformers/FileTransformer.php @@ -0,0 +1,34 @@ + $file->id, + 'file' => $file->file, + 'type' => (int)$file->file_type, + ]; + + } +} diff --git a/app/Transformers/GroupTransformer.php b/app/Transformers/GroupTransformer.php new file mode 100644 index 00000000..33162b17 --- /dev/null +++ b/app/Transformers/GroupTransformer.php @@ -0,0 +1,126 @@ + $transaction->id, + 'original_amount' => (float)$transaction->original_amount, + 'issuer_name' => $transaction->issuerCompany->name, + 'issuer_id' => $transaction->issuerCompany->id, + 'amount' => (float)$transaction->amount, + 'service_charge' => (float)$transaction->amount, + 'created_at' => Carbon::parse($transaction->created_at)->format('d-m-Y h:i:s A'), + 'currency_rate' => (float)$transaction->currency_rate, + 'transactions' => $this->transactions($transaction), + 'complete_transactions' => $this->complete_transactions($transaction), + 'documents' => [ + 'currency_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::CURRENCY_VENDOR_ORDER)->first()), + 'purchase_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::BULK_PURCHASE_ORDER)->first()) + ] + ]; + } + + /** + * Include Original Currency + * + * @param Transaction $transaction + * @return Item + */ + public function includeOriginalCurrency(Transaction $transaction): Item + { + return $this->item($transaction->original_currency, new CurrencyTransformer()); + } + + /** + * Include Currency + * + * @param Transaction $transaction + * @return Item + */ + public function includeCurrency(Transaction $transaction): Item + { + return $this->item($transaction->currency, new CurrencyTransformer()); + } + + /** + * Get Transactions + * @param Transaction $transaction + * @return Collection + */ + protected function transactions(Transaction $transaction): Collection + { + return $transaction->transactions()->get()->pluck('owner.owner.marking'); + } + + /** + * complete Transactions + * @param Transaction $transaction + * @return Collection + */ + protected function complete_transactions(Transaction $transaction): Collection + { + return $transaction->transactions()->whereHasMorph('owner', [Transaction::class], function ($query) { + return $query->whereHas('booking', function ($query) { + return $query->whereHas('transactions', function ($query) { + return $query->where('type', TransactionType::PURCHASE_ORDER)->where('status', '=', ApprovalStatus::APPROVED); + }); + }); + })->get()->pluck('owner.owner.marking'); + + } + + /** + * Include Documents + * + * @param Transaction $transaction + * @return array + */ + public function includeDocuments(Transaction $transaction): array + { + return [ + 'currency_order' => $this->item($transaction->documents()->where('document_type', DocumentType::CURRENCY_VENDOR_ORDER)->first(), new DocumentTransformer()), + 'purchase_order' => $this->item($transaction->documents()->where('document_type', DocumentType::BULK_PURCHASE_ORDER)->first(), new DocumentTransformer()) + ]; + + } + +} + diff --git a/app/Transformers/InvoiceTransformer.php b/app/Transformers/InvoiceTransformer.php new file mode 100644 index 00000000..4332016a --- /dev/null +++ b/app/Transformers/InvoiceTransformer.php @@ -0,0 +1,38 @@ + $order->id, + 'reference' => $order->reference, + 'reference_contract' => $order->type, + 'type' => $order->type, + 'status' => $order->status, + 'created_at' => $order->created_at->format('d-m-Y') + ]; + } + + /** + * Include company module + * @param Order $order + * @return Item + */ + public function includeCompanyModule(Order $order): Item + { + return $this->item($order->companyModule, new CompanyModuleTransformer()); + } + + /** + * + * Include warehouse + * @param Order $order + * @return Item + */ + public function includeWarehouse(Order $order): Item + { + return $this->item($order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee, new CompanyModuleTransformer()); + } + + /** + * include address + * @param Order $order + * @return Item + */ + public function includeAddress(Order $order): Item + { + return $this->item($order->addresses()->where('status', '=', ApprovalStatus::APPROVED)->first(), new AddressTransformer()); + } + + /** + * include address change request + * @param Order $order + * @return Item + */ + public function includeAddressChangeRequest(Order $order): Item + { + return $this->item($order->addressesPendingVerification()->first(), new AddressTransformer()); + } + + /** + * include parcels + * @param Order $order + * @return array + */ + public function includeParcels(Order $order): array + { + return [ + 'origin_warehouse_packages' => $this->collection($order->originWarehousePackages()->get(), new PackageListTransformer()), + + 'in_transit_packages' => $this->collection($order->inTransitPackages()->get(), new PackageListTransformer()), + + 'destination_warehouse_packages' => $this->collection($order->destinationWarehousePackages()->get(), new PackageListTransformer()), + + 'delivered_packages' => $this->collection($order->deliveredPackages()->get(), new PackageListTransformer()), + + 'received_packages' => $this->collection($order->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('packages')->get(), new PackageListTransformer()), + ]; + } + + /** + * + * include invoices + * @param Order $order + * @return Collection + */ + public function includeInvoices(Order $order): Collection + { + + $invoices = $order->transactions()->whereNotIn('transactions.status', [0, 1])->get(); + return $this->collection($invoices, new TransactionTransformer()); + } + + public function includeRemarks(Order $order): Collection + { + return $this->collection($order->remarks()->get(), new RemarkTransformer); + } +} diff --git a/app/Transformers/PackageListTransformer.php b/app/Transformers/PackageListTransformer.php new file mode 100644 index 00000000..058f954f --- /dev/null +++ b/app/Transformers/PackageListTransformer.php @@ -0,0 +1,120 @@ + $packingList->id, + 'claimant_id' => $packingList->claimant_id, + 'reference' => $packingList->reference, + 'status' => $packingList->status, + 'type' => $packingList->type, + ]; + } + + /** + * include Transport + * @param PackingList $packingList + * @return Item + */ + public function includeTransport(PackingList $packingList): Item + { + return $this->item($packingList->transport()->first(), new TransportTransformer); + } + + /** + * Include Receive Packing List + * @param PackingList $packingList + * @return Item + */ + public function includeReceivePackageList(PackingList $packingList): Item + { + + //$this->when($this->type === PackingListType::SHIPPING_PACKING_LIST, new PackingListResource(PackingList::where('reference', $this->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->first())), + + return $this->item($packingList->receivePackageList()->first(), new PackageListTransformer); + } + + /** + * Include Packages + * @param PackingList $packingList + * @return Collection + */ + public function includePackages(PackingList $packingList): Collection + { + $exceptionUsers = in_array(Auth()->user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]); + $packages = !$packingList->packingLists()->exists() || $exceptionUsers ? $packingList->packages : $packingList->packingLists->first()->packages; + + return $this->collection($packages, new PackageTransformer); + } + + /** + * include Order + * @param PackingList $packingList + * @return Item + */ + public function includeOrder(PackingList $packingList): Item + { + return $this->item($packingList->owner, new OrderTransformer); + } + + /** + * include Shipping Transaction + * @param PackingList $packingList + * @return Item + */ + public function includeShippingTransaction(PackingList $packingList): Item + { + return $this->item($packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereNotIn('status', [ApprovalStatus::SUSPENDED, ApprovalStatus::EXPIRED])->first(), new TransactionTransformer()); + } + + /** + * include Suspended Invoice + * @param PackingList $packingList + * @return Item + */ + public function includeSuspendedInvoice(PackingList $packingList): Item + { + return $this->item($packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::SUSPENDED])->first(), new TransactionTransformer()); + } + +} diff --git a/app/Transformers/PackageTransformer.php b/app/Transformers/PackageTransformer.php new file mode 100644 index 00000000..e31ff232 --- /dev/null +++ b/app/Transformers/PackageTransformer.php @@ -0,0 +1,82 @@ + $package->id, + 'type' => $package->type, + 'description' => $package->description, + 'width' => floatval($package->width), + 'height' => floatval($package->height), + 'length' => floatval($package->length), + 'weight' => $package->weight, + 'quantity' => $package->quantity, + 'cbm' => (($package->width / 100) * ($package->height / 100) * ($package->length / 100)) * $package->quantity, + 'reference' => $package->packingList->reference, + 'status' => $package->status, + ]; + } + + /** + * Include Transport + * @param Package $package + * @return Item + */ + public function includeTransport(Package $package): Item + { + return $this->item($package->packingList->transports()->first(), new TransportTransformer()); + } + + /** + * Include Container + * @param Package $package + * @return Item + */ + public function includeContainers(Package $package): Item + { + return $this->item($package->packingList->containers()->first(), new TransportTransformer()); + } + + /** + * Include Order + * @param Package $package + * @return Item + */ + public function includeOrder(Package $package): Item + { + return $this->item($package->packingList->owner, new OrderTransformer()); + } +} diff --git a/app/Transformers/RemarkTransformer.php b/app/Transformers/RemarkTransformer.php new file mode 100644 index 00000000..ae651005 --- /dev/null +++ b/app/Transformers/RemarkTransformer.php @@ -0,0 +1,58 @@ + $remark->id, + 'owner_id' => $remark->owner_id, + 'content' => $remark->content, + 'created_at' => $remark->created_at->format('d-m-Y H:i'), + 'long_ago' => $remark->created_at->diffForHumans() + ]; + } + + /** + * load commenter + * @param Remark $remark + * @return \League\Fractal\Resource\Item + */ + public function includeCommenter(Remark $remark): \League\Fractal\Resource\Item + { + $user = $remark->commenter(); + return $this->item($user, new UserTransformer()); + + } +} diff --git a/app/Transformers/ScheduleTransformer.php b/app/Transformers/ScheduleTransformer.php new file mode 100644 index 00000000..effdf0b9 --- /dev/null +++ b/app/Transformers/ScheduleTransformer.php @@ -0,0 +1,48 @@ + $schedule->id, + 'etd' => $schedule->etd ? $schedule->etd->format('d-m-Y') : 'n/a', + 'eta' => $schedule->eta ? $schedule->eta->format('d-m-Y') : 'n/a', + 'billing_days_left' => [ + 'value' => (Carbon::parse($schedule->eta)->subDays(7)->gt(Carbon::now())) ? '+' : '-', + 'duration' => Carbon::parse($schedule->eta)->subDays(7)->diffInDays(Carbon::now()), + ], + 'status' => $schedule->status, + ]; + } +} diff --git a/app/Transformers/TransactionDetailTransformer.php b/app/Transformers/TransactionDetailTransformer.php new file mode 100644 index 00000000..ef55de2f --- /dev/null +++ b/app/Transformers/TransactionDetailTransformer.php @@ -0,0 +1,44 @@ + $detail->reference, + 'quantity' => $detail->quantity, + 'price' => (double)$detail->price, + 'name' => $detail->name, + 'amount' => (double)$detail->amount + ]; + } +} diff --git a/app/Transformers/TransactionTransformer.php b/app/Transformers/TransactionTransformer.php new file mode 100644 index 00000000..ba2604d0 --- /dev/null +++ b/app/Transformers/TransactionTransformer.php @@ -0,0 +1,178 @@ + $transaction->id, + 'type' => (int)$transaction->type, + 'bill_no' => $transaction->bill_no, + 'amount' => (double)$transaction->amount, + 'payment_method' => (int)$transaction->payment_method, + 'payment_reference' => $transaction->payment_reference, + 'outstanding' => $this->getOutstandingAmount($transaction), + 'floating' => $this->getFloatingAmount($transaction), + 'service_charge' => (double)$transaction->service_charge, + 'tax' => (double)$transaction->tax, + 'original_amount' => (double)$transaction->original_amount, + 'currency_rate' => (double)$transaction->currency_rate, + 'status' => $transaction->status, + 'expires_on' => Carbon::parse($transaction->expires_on)->format('d-m-Y h:s:i'), + 'updated_at' => Carbon::parse($transaction->updated_at)->format('d-m-Y'), + 'created_at' => Carbon::parse($transaction->created_at)->format('d-m-Y') + ]; + } + + /** + * Include order + * @param Transaction $transaction + * @return Item + */ + public function includeOrder(Transaction $transaction): Item + { + return ($transaction->owner instanceof Transaction) ? $this->item($transaction->owner->owner->owner, new OrderTransformer) : $this->item($transaction->owner->owner, new OrderTransformer); + } + + /** + * Include documents + * @param Transaction $transaction + * @return Collection + */ + public function includeDocuments(Transaction $transaction): Collection + { + return $this->collection($transaction->documents, new DocumentTransformer()); + } + + /** + * Get outstanding amount + * @param Transaction $transaction + * @return float + */ + public function getOutstandingAmount(Transaction $transaction): float + { + return (float)$transaction->amount - ($transaction->transactions()->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount')); + } + + /** + * Get floating amount + * @param Transaction $transaction + * @return float + */ + public function getFloatingAmount(Transaction $transaction): float + { + return (double)$transaction->transactions()->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION])->sum('amount'); + } + + /** + * Include currency + * @param Transaction $transaction + * @return Item + */ + public function includeCurrency(Transaction $transaction): Item + { + return $this->item($transaction->currency, new CurrencyTransformer); + } + + /** + * include original currency + * @param Transaction $transaction + * @return Item + */ + public function includeOriginalCurrency(Transaction $transaction): Item + { + return $this->item($transaction->original_currency, new CurrencyTransformer); + } + + /** + * Include transaction details details + * @param Transaction $transaction + * @return Collection + */ + public function includeDetails(Transaction $transaction): Collection + { + return $this->collection($transaction->transactionDetails, new TransactionDetailTransformer()); + } + + /** + * include transactions + * @param Transaction $transaction + * @return Collection + */ + public function includeTransactions(Transaction $transaction): Collection + { + return $this->collection($transaction->transactions, new TransactionTransformer()); + } + + /** + * include payment attempts + * @param Transaction $transaction + * @return Collection + */ + public function includePaymentAttempts(Transaction $transaction): Collection + { + return $this->collection($transaction->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->get(), new TransactionTransformer()); + } + + /** + * include payment history + * @param Transaction $transaction + * @return Collection + */ + public function includePaymentHistory(Transaction $transaction): Collection + { + return $this->collection($transaction->transactions()->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED])->get(), new TransactionTransformer()); + } + + /** + * include remarks + * @param Transaction $transaction + * @return Collection + */ + public function includeRemarks(Transaction $transaction): Collection + { + return $this->collection($transaction->remarks, new RemarkTransformer()); + } +} diff --git a/app/Transformers/TransportTransformer.php b/app/Transformers/TransportTransformer.php new file mode 100644 index 00000000..5320d082 --- /dev/null +++ b/app/Transformers/TransportTransformer.php @@ -0,0 +1,85 @@ + $transport->id, + 'type' => $transport->type, + 'courier' => $transport->courier, + 'tracking_number' => $transport->tracking_number, + 'dispatch_date' => $transport->dispatch_date ? $transport->dispatch_date->format('d-m-Y') : $transport->dispatch_date, + 'drop_date' => $transport->drop_date ? $transport->drop_date->format('d-m-Y') : $transport->drop_date, + 'status' => $transport->status, + 'dropped_days' => Carbon::now()->diffInDays($transport->drop_date, false), + 'schedule_complete' => $this->isScheduleComplete($transport) + ]; + } + + /** + * Include Current Schedule + * @param Transport $transport + * @return Item + */ + public function includeCurrentSchedule(Transport $transport): Item + { + $currentSchedule = $transport->schedules()->where('status', '=', ApprovalStatus::APPROVED)->first(); + return $this->item($currentSchedule, new ScheduleTransformer); + } + + /** + * include Schedule History + * @param Transport $transport + * @return Collection + */ + public function includeScheduleHistory(Transport $transport): Collection + { + $history = $transport->schedules()->where('status', '=', ApprovalStatus::EXPIRED)->get(); + return $this->collection($history, new ScheduleTransformer); + } + + public function isScheduleComplete(Transport $transport): bool + { + $currentSchedule = $transport->schedules()->where('status', '=', ApprovalStatus::APPROVED)->first(); + return $currentSchedule && $currentSchedule->eta <= Carbon::now(); + } + + +} \ No newline at end of file diff --git a/app/Transformers/UserTransformer.php b/app/Transformers/UserTransformer.php new file mode 100644 index 00000000..99a12725 --- /dev/null +++ b/app/Transformers/UserTransformer.php @@ -0,0 +1,38 @@ + $user->id, + 'name' => $user->name, + 'email' => $user->email, + 'type' => $user->type, + 'status' => $user->status + ]; + + } + +} diff --git a/codeception.yml b/codeception.yml new file mode 100644 index 00000000..6283d5f8 --- /dev/null +++ b/codeception.yml @@ -0,0 +1,12 @@ +paths: + tests: tests + output: tests/_output + data: tests/_data + support: tests/_support + envs: tests/_envs +actor_suffix: Tester +extensions: + enabled: + - Codeception\Extension\RunFailed +params: + - .env.testing diff --git a/composer.json b/composer.json index af20f32d..e2b684e5 100644 --- a/composer.json +++ b/composer.json @@ -2,29 +2,42 @@ "name": "laravel/laravel", "type": "project", "description": "The Laravel Framework.", - "keywords": ["framework", "laravel"], + "keywords": [ + "framework", + "laravel" + ], "license": "MIT", "require": { "php": "^7.3", "ext-fileinfo": "^7.3", "ext-json": "*", "barryvdh/laravel-dompdf": "^0.9.0", - "carlos-meneses/laravel-mpdf": "^2.1", + "carlos-meneses/laravel-mpdf": "*", "doctrine/dbal": "^3.1", "fideloper/proxy": "^4.4", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0.1", "intervention/image": "^2.5", "laravel/framework": "^8.40", + "laravel/legacy-factories": "^1.3", "laravel/tinker": "^2.5", + "league/fractal": "^0.20.1", "maatwebsite/excel": "^3.1", "rinvex/countries": "^6.1", "spatie/laravel-activitylog": "^3.14", + "spatie/laravel-fractal": "^5.8", "spatie/laravel-permission": "^4.2", "staudenmeir/eloquent-has-many-deep": "^1.7", "tymon/jwt-auth": "^1.0" }, "require-dev": { + "barryvdh/laravel-ide-helper": "^2.12", + "codeception/codeception": "^4.2", + "codeception/module-asserts": "^2.0", + "codeception/module-laravel": "^2.3", + "codeception/module-phpbrowser": "^2.0", + "codeception/module-rest": "^2.0", + "codeception/module-webdriver": "^2.0", "facade/ignition": "^2.5", "fakerphp/faker": "^1.9.1", "laravel/sail": "^1.0.1", @@ -42,7 +55,10 @@ "autoload-dev": { "psr-4": { "Tests\\": "tests/" - } + }, + "files": [ + "app/Library/helper.php" + ] }, "scripts": { "post-autoload-dump": [ diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index a24ce53f..6b7a9bb2 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -25,23 +25,9 @@ class UserFactory extends Factory return [ 'name' => $this->faker->name(), 'email' => $this->faker->unique()->safeEmail(), - 'email_verified_at' => now(), 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 'remember_token' => Str::random(10), ]; } - /** - * Indicate that the model's email address should be unverified. - * - * @return \Illuminate\Database\Eloquent\Factories\Factory - */ - public function unverified() - { - return $this->state(function (array $attributes) { - return [ - 'email_verified_at' => null, - ]; - }); - } } diff --git a/database/migrations/2022_12_27_165842_create_route_logs_table.php b/database/migrations/2022_12_27_165842_create_route_logs_table.php new file mode 100644 index 00000000..bdab0257 --- /dev/null +++ b/database/migrations/2022_12_27_165842_create_route_logs_table.php @@ -0,0 +1,42 @@ +id(); + $table->foreignId('user_id')->unsigned(); + $table->string('ip_address'); + $table->string('url', 255); + $table->string('request_method'); + $table->string('browser')->nullable(); + $table->string('platform')->nullable(); + $table->string('longitude')->nullable(); + $table->string('latitude')->nullable(); + $table->string('last_page')->nullable(); + $table->string('countryname')->nullable(); + $table->integer('route_type'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('route_logs'); + } +} diff --git a/database/migrations/2023_03_11_212614_create_companies_wallet_table.php b/database/migrations/2023_03_11_212614_create_companies_wallet_table.php new file mode 100644 index 00000000..3837a0e1 --- /dev/null +++ b/database/migrations/2023_03_11_212614_create_companies_wallet_table.php @@ -0,0 +1,38 @@ +id(); + $table->morphs('owner'); + $table->string('code'); + $table->foreignId('currency_id')->unsigned(); + $table->decimal('amount', 20, 5)->default(0.00); + $table->softDeletes(); + $table->timestamps(); + + $table->foreign('currency_id')->references('id')->on('currencies'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('wallets'); + } +} diff --git a/database/migrations/2023_03_19_170628_create_groups_table.php b/database/migrations/2023_03_19_170628_create_groups_table.php new file mode 100644 index 00000000..569627c2 --- /dev/null +++ b/database/migrations/2023_03_19_170628_create_groups_table.php @@ -0,0 +1,43 @@ +id(); + $table->string('reference')->unique(); + $table->foreignId('issuer')->unsigned(); + $table->foreignId('receiver')->unsigned(); + $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->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('groups'); + } +} diff --git a/database/migrations/2023_03_19_170641_create_group_transactions_table.php b/database/migrations/2023_03_19_170641_create_group_transactions_table.php new file mode 100644 index 00000000..53f33356 --- /dev/null +++ b/database/migrations/2023_03_19_170641_create_group_transactions_table.php @@ -0,0 +1,32 @@ +id(); + $table->foreignId('group_id')->unsigned(); + $table->foreignId('transaction_id')->unsigned(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('group_transactions'); + } +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..f3297e22 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +version: '3' +services: + web: + build: + context: . + args: + PHP_VERSION: 7.4 + ports: + - "9000:9000" + db: + image: mysql:5.7 + environment: + MYSQL_DATABASE: laravel + MYSQL_USER: laravel + MYSQL_PASSWORD: secret + MYSQL_ROOT_PASSWORD: secret + ports: + - "3306:3306" + tests: + build: + context: . + args: + PHP_VERSION: 7.4 + command: bash -c "composer install && php artisan migrate --seed && vendor/bin/phpunit" + links: + - db + - redis + acceptance: + image: node:14 + working_dir: /app + volumes: + - ./:/app + command: bash -c "npm install && gulp build" + links: + - web + - redis + redis: + image: redis:6.0 + ports: + - "6379:6379" diff --git a/phpunit.xml b/phpunit.xml index 4ae4d979..76a606bb 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -21,8 +21,8 @@Use Delivery Address
+Amount
Payment Date
+Online Banking
+Wallet
+Manual Transfer
+
Nothing To Show Here
+
Nothing To Show Here
+Credit
+Debit
+| Invoices | '; -foreach ($duplicatedTransactions as $transaction) { - $transactionIds = explode(',', $transaction->transaction_ids); + foreach ($duplicatedTransactions as $transaction) { + $transactionIds = explode(',', $transaction->transaction_ids); - $duplicatedInvoice = Transaction::whereIn('id', $transactionIds)->get(); - - $order_reference = $duplicatedInvoice->first()->owner->owner->reference ?? null; + $duplicatedInvoice = Transaction::whereIn('id', $transactionIds)->get(); + + $order_reference = $duplicatedInvoice->first()->owner->owner->reference ?? null; - if ($transaction->type == TransactionType::PAYMENT) { - $order_reference = $duplicatedInvoice->first()->owner->owner->owner->reference ?? null; - } - - echo '||||||
|---|---|---|---|---|---|---|
| ' . $transaction->owner_type . ' | '; - // echo '' . $transaction->owner_id . ' | '; - echo '' . $transaction->receiver . ' | '; - echo '' . ''. $order_reference .'' . ' | '; - echo '' . $transactionType[$transaction->type] . ' | '; - echo '' . count($transactionIds) . ' | '; - echo '';
- foreach ($duplicatedInvoice as $invoice) {
- echo ' ID: ' . $invoice->id . '. Status: ' . $approvalStatusArray[$invoice->status] . '. Amount: ' . $invoice->amount . ' '; + if ($transaction->type == TransactionType::PAYMENT) { + $order_reference = $duplicatedInvoice->first()->owner->owner->owner->reference ?? null; } - echo' | ';
- echo '
ID: ' . $invoice->id . '. Status: ' . $approvalStatusArray[$invoice->status] . '. Amount: ' . $invoice->amount . '
'; + } + echo'