From 5b7148d8792ebee348def7b72b15b028862bb5a4 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Mon, 7 Dec 2020 10:44:35 +0800 Subject: [PATCH 1/8] clean up api routes --- ...4_10_11_100010_create_currencies_table.php | 2 +- ...0_11_100011_create_currency_logs_table.php | 2 +- ...9_212614_create_companies_wallet_table.php | 2 +- routes/api.php | 18 ++++++++------- routes/crud.php | 3 ++- routes/document.php | 10 +++------ routes/segment_constant.php | 22 +++++++++++++++++++ 7 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 routes/segment_constant.php diff --git a/database/migrations/2014_10_11_100010_create_currencies_table.php b/database/migrations/2014_10_11_100010_create_currencies_table.php index fed59198..f356e780 100644 --- a/database/migrations/2014_10_11_100010_create_currencies_table.php +++ b/database/migrations/2014_10_11_100010_create_currencies_table.php @@ -20,7 +20,7 @@ class CreateCurrenciesTable extends Migration $table->string('name')->nullable(); $table->string('short_code')->nullable(); $table->string('symbol')->nullable(); - $table->float('selling', 20, 5)->nullable(); + $table->decimal('selling', 20, 5)->nullable(); $table->timestamps(); $table->softDeletes(); }); diff --git a/database/migrations/2014_10_11_100011_create_currency_logs_table.php b/database/migrations/2014_10_11_100011_create_currency_logs_table.php index 1b2499d0..cd3ebb34 100644 --- a/database/migrations/2014_10_11_100011_create_currency_logs_table.php +++ b/database/migrations/2014_10_11_100011_create_currency_logs_table.php @@ -17,7 +17,7 @@ class CreateCurrencyLogsTable extends Migration $table->id(); $table->bigInteger('currency_id')->unsigned()->nullable(); $table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade'); - $table->float('selling', 20, 5)->nullable(); + $table->decimal('selling', 20, 5)->nullable(); $table->bigInteger('created_by')->unsigned()->nullable(); $table->foreign('created_by')->references('id')->on('users')->onDelete('cascade'); $table->timestamps(); diff --git a/database/migrations/2020_11_29_212614_create_companies_wallet_table.php b/database/migrations/2020_11_29_212614_create_companies_wallet_table.php index 057e21cc..c55a9267 100644 --- a/database/migrations/2020_11_29_212614_create_companies_wallet_table.php +++ b/database/migrations/2020_11_29_212614_create_companies_wallet_table.php @@ -19,7 +19,7 @@ class CreateCompaniesWalletTable extends Migration $table->bigInteger('company_id')->unsigned(); $table->string('code'); $table->bigInteger('currency_id')->unsigned(); - $table->decimal('amount', 14, 5)->default(0.00); + $table->decimal('amount', 20, 5)->default(0.00); $table->timestamps(); $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); diff --git a/routes/api.php b/routes/api.php index 1771abb5..6518bda2 100644 --- a/routes/api.php +++ b/routes/api.php @@ -17,16 +17,18 @@ use Illuminate\Support\Facades\Route; Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function () { require __DIR__ . '/account.php'; - - require __DIR__ . '/wallet.php'; - - require __DIR__ . '/document.php'; - - require __DIR__ . '/segment.php'; - - require __DIR__ . '/company_bank.php'; Route::group(['middleware' => 'valid.token'], function () { require __DIR__ . '/crud.php'; + + require __DIR__ . '/wallet.php'; + + require __DIR__ . '/document.php'; + + require __DIR__ . '/segment.php'; + + require __DIR__ . '/company_bank.php'; + + require __DIR__ . '/currency.php'; }); }); diff --git a/routes/crud.php b/routes/crud.php index 1e117e14..8dc59e9f 100644 --- a/routes/crud.php +++ b/routes/crud.php @@ -13,4 +13,5 @@ Route::group(['prefix' => 'address', 'as' => 'address.', 'namespace' => 'Address Route::delete('/delete/{id}', 'DeleteAddressController@destroy')->name('delete'); -}); \ No newline at end of file +}); + diff --git a/routes/document.php b/routes/document.php index d6d16a4e..d8705b2b 100644 --- a/routes/document.php +++ b/routes/document.php @@ -2,11 +2,7 @@ use Illuminate\Support\Facades\Route; -Route::group(['namespace' => 'Documents'], function () { - Route::group(['middleware' => 'valid.token'], function () { - Route::group(['prefix' => 'document'], function () { - Route::get('/list', 'ListDocumentsController@list')->name('document.list'); - Route::put('/approve/{id}', 'ApproveDocumentController@approve')->name('document.approve'); - }); - }); +Route::group(['prefix' => 'document', 'as' => 'document.', 'namespace' => 'Documents'], function () { + Route::get('/list', 'ListDocumentsController@list')->name('list'); + Route::put('/approve/{id}', 'ApproveDocumentController@approve')->name('approve'); }); \ No newline at end of file diff --git a/routes/segment_constant.php b/routes/segment_constant.php new file mode 100644 index 00000000..e49e9e97 --- /dev/null +++ b/routes/segment_constant.php @@ -0,0 +1,22 @@ + 'StandardSegmentConstants'], function () { + Route::group(['middleware' => 'valid.token'], function () { + Route::group(['prefix' => 'standard-segment-constant'], function () { + Route::get('/list', 'ListStandardSegmentConstantsController@list')->name('standard_segment.update'); + Route::put('/update/{id}', 'UpdateStandardSegmentConstantController@update')->name('standard_segment_constant.update'); + }); + }); +}); + + +Route::group(['namespace' => 'SegmentConstants'], function () { + Route::group(['middleware' => 'valid.token'], function () { + Route::group(['prefix' => 'segment-constant'], function () { + Route::post('/create', 'CreateSegmentConstantController@create')->name('segment_constant.create'); + Route::put('/update/{id}', 'UpdateSegmentConstantController@update')->name('segment_constant.update'); + }); + }); +}); \ No newline at end of file From 042b8e7ef13e7b98e56548d2ce878fe6cc292f07 Mon Sep 17 00:00:00 2001 From: "weiken.intex" Date: Sun, 6 Dec 2020 00:25:17 +0800 Subject: [PATCH 2/8] Fixed wallet - integrate --- .env.example | 48 ------------------- .../ControllersLogic/CreateWalletLogic.php | 2 +- .../DataTransferObjects/WalletObject.php | 6 +-- .../Wallets/Services/CreatesWallet.php | 2 +- .../Validators/CompanyWalletValidation.php | 4 +- app/Http/Resources/WalletResource.php | 2 +- nbproject/project.properties | 7 +++ nbproject/project.xml | 9 ++++ routes/wallet.php | 2 +- 9 files changed, 25 insertions(+), 57 deletions(-) delete mode 100644 .env.example create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml diff --git a/.env.example b/.env.example deleted file mode 100644 index a0701a99..00000000 --- a/.env.example +++ /dev/null @@ -1,48 +0,0 @@ -APP_NAME=Laravel -APP_ENV=local -APP_KEY= -APP_DEBUG=true -APP_URL=http://localhost - -LOG_CHANNEL=stack - -DB_CONNECTION=mysql -DB_HOST=127.0.0.1 -DB_PORT=3306 -DB_DATABASE=laravel -DB_USERNAME=root -DB_PASSWORD= - -BROADCAST_DRIVER=log -CACHE_DRIVER=file -QUEUE_CONNECTION=sync -SESSION_DRIVER=file -SESSION_LIFETIME=120 - -REDIS_HOST=127.0.0.1 -REDIS_PASSWORD=null -REDIS_PORT=6379 - -MAIL_MAILER=smtp -MAIL_HOST=smtp.mailtrap.io -MAIL_PORT=2525 -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= - -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}" - -JWT_SECRET= diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php index bc0803d8..d0401218 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletLogic.php @@ -84,7 +84,7 @@ class CreateWalletLogic extends AbstractControllerLogic DB::beginTransaction(); - $object = new WalletObject($request->input('currency'), $request->input('company_id'), $this->generatesWalletCode->execute()); + $object = new WalletObject($request->input('currency_id'), $request->input('company_id'), $this->generatesWalletCode->execute()); $this->canCreateCompanyWallet->passes($object); diff --git a/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php b/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php index e24fe2f9..29924744 100644 --- a/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php +++ b/app/Classes/Modules/Wallets/DataTransferObjects/WalletObject.php @@ -11,7 +11,7 @@ class WalletObject implements DataTransferObject private $company_id; /** @var int */ - private $currency; + private $currency_id; /** @var int */ private $code; @@ -25,7 +25,7 @@ class WalletObject implements DataTransferObject public function __construct(int $company_id, int $currency, int $code) { $this->company_id = $company_id; - $this->currency = $currency; + $this->currency_id = $currency; $this->code = $code; } @@ -42,7 +42,7 @@ class WalletObject implements DataTransferObject */ public function getCurrency(): int { - return $this->currency; + return $this->currency_id; } /** diff --git a/app/Classes/Modules/Wallets/Services/CreatesWallet.php b/app/Classes/Modules/Wallets/Services/CreatesWallet.php index c76113c7..720049cb 100644 --- a/app/Classes/Modules/Wallets/Services/CreatesWallet.php +++ b/app/Classes/Modules/Wallets/Services/CreatesWallet.php @@ -17,7 +17,7 @@ class CreatesWallet extends AbstractUpdateRecord $model = new Wallet(); $model->company_id = $object->getCompanyId(); $model->code = $object->getCode(); - $model->currency = $object->getCurrency(); + $model->currency_id = $object->getCurrency(); return $this->handler($model); diff --git a/app/Classes/Modules/Wallets/Standards/Validators/CompanyWalletValidation.php b/app/Classes/Modules/Wallets/Standards/Validators/CompanyWalletValidation.php index 5d4cea89..5bd1f698 100644 --- a/app/Classes/Modules/Wallets/Standards/Validators/CompanyWalletValidation.php +++ b/app/Classes/Modules/Wallets/Standards/Validators/CompanyWalletValidation.php @@ -16,7 +16,7 @@ class CompanyWalletValidation extends AbstractValidation { return [ 'company_id' => $object->getCompanyId(), - 'currency' => $object->getCurrency(), + 'currency_id' => $object->getCurrency(), ]; } @@ -27,7 +27,7 @@ class CompanyWalletValidation extends AbstractValidation { return [ 'company_id' => 'required', - 'currency' => 'required', + 'currency_id' => 'required', ]; } diff --git a/app/Http/Resources/WalletResource.php b/app/Http/Resources/WalletResource.php index 567e5db0..37ff5dbd 100644 --- a/app/Http/Resources/WalletResource.php +++ b/app/Http/Resources/WalletResource.php @@ -17,7 +17,7 @@ class WalletResource extends JsonResource return [ 'id' => $this->id, 'code' => $this->code, - 'currency' => $this->currency, + 'currency_id' => $this->currency_id, 'amount' => (double) $this->amount, 'company_id' => (int) $this->company_id ]; diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 00000000..911a7b8b --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_70 +source.encoding=UTF-8 +src.dir=. +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 00000000..05ea1cf9 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + laravel + + + diff --git a/routes/wallet.php b/routes/wallet.php index b80135ce..3c63ac88 100644 --- a/routes/wallet.php +++ b/routes/wallet.php @@ -2,7 +2,7 @@ use Illuminate\Support\Facades\Route; -Route::group(['prefix' => 'wallet', 'namespace' => 'Wallet', 'as' => 'wallet.'], function () { +Route::group(['prefix' => 'wallets', 'namespace' => 'Wallets', 'as' => 'wallet.'], function () { Route::post('/create', 'CreateWalletController@create')->name('create'); From f08a863e2c7b5bdf810681236a5c7ee32d04324a Mon Sep 17 00:00:00 2001 From: "weiken.intex" Date: Sun, 6 Dec 2020 02:14:22 +0800 Subject: [PATCH 3/8] create Wallet Transaction - integration --- .../CreateWalletTransactionLogic.php | 106 ++++++++++++++++++ .../WalletTransactionObject.php | 94 ++++++++++++++++ .../ChecksIfWalletTransactionBillNoExists.php | 22 ++++ .../Services/CreatesWalletTransaction.php | 30 +++++ .../GeneratesWalletTransactionBillNo.php | 27 +++++ .../Rules/CanCreateWalletTransaction.php | 50 +++++++++ .../WalletTransactionValidation.php | 40 +++++++ .../CreateWalletTransactionController.php | 15 +++ .../Resources/WalletTransactionResource.php | 29 +++++ app/Models/WalletTransaction.php | 27 +++++ ...212314_create_wallet_transaction_table.php | 45 ++++++++ routes/wallet.php | 1 + 12 files changed, 486 insertions(+) create mode 100644 app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php create mode 100644 app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php create mode 100644 app/Classes/Modules/Wallets/Services/ChecksIfWalletTransactionBillNoExists.php create mode 100644 app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php create mode 100644 app/Classes/Modules/Wallets/Services/GeneratesWalletTransactionBillNo.php create mode 100644 app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php create mode 100644 app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php create mode 100644 app/Http/Controllers/Wallets/CreateWalletTransactionController.php create mode 100644 app/Http/Resources/WalletTransactionResource.php create mode 100644 app/Models/WalletTransaction.php create mode 100644 database/migrations/2020_11_30_212314_create_wallet_transaction_table.php diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php new file mode 100644 index 00000000..7d6a642d --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php @@ -0,0 +1,106 @@ + 'Created Wallet Transaction', + 'message' => 'You have successfully created a wallet transaction' + ]; + } + + /** @var CreatesWalletTransaction */ + private $createsWalletTransaction; + + /** @var GeneratesWalletTransactionBillNo */ + private $generatesWalletTransactionBillNo; + + /** @var CanCreateWalletTransaction */ + private $canCreateWalletTransaction; + + /** + * CreateWalletLogic constructor. + * @param CreatesWallet $createsWallet + * @param GeneratesWalletCode $generatesWalletCode + * @param CanCreateCompanyWallet $canCreateCompanyWallet + */ + public function __construct(CreatesWalletTransaction $createsWalletTransaction, GeneratesWalletTransactionBillNo $generatesWalletTransactionBillNo, CanCreateWalletTransaction $canCreateWalletTransaction) + { + $this->createsWalletTransaction = $createsWalletTransaction; + $this->generatesWalletTransactionBillNo = $generatesWalletTransactionBillNo; + $this->canCreateWalletTransaction = $canCreateWalletTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + DB::beginTransaction(); + + + $object = new WalletTransactionObject( + $request->route('id'), $this->generatesWalletTransactionBillNo->execute(),$request->input('trans_type'), + number_format( (float) $request->input('amount'), 5, '.', ''), $request->input('currency_id') , number_format( (float) $request->input('original_amount'), 5, '.', ''), + $request->input('original_currency_id'),number_format( (float) $request->input('currency_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/DataTransferObjects/WalletTransactionObject.php b/app/Classes/Modules/Wallets/DataTransferObjects/WalletTransactionObject.php new file mode 100644 index 00000000..7fdfecbd --- /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/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/CreatesWalletTransaction.php b/app/Classes/Modules/Wallets/Services/CreatesWalletTransaction.php new file mode 100644 index 00000000..06877e6a --- /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/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/Standards/Rules/CanCreateWalletTransaction.php b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php new file mode 100644 index 00000000..43f0118f --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Rules/CanCreateWalletTransaction.php @@ -0,0 +1,50 @@ +walletTransactionValidation = $walletTransactionValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param CompanyWalletValidation $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->walletTransactionValidation->validate($object); + } + + /** + * @param SegmentCompanyValidation $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php b/app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php new file mode 100644 index 00000000..14129c03 --- /dev/null +++ b/app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php @@ -0,0 +1,40 @@ + $object->getWalletId(), + 'currency_id' => $object->getCurrency(), + 'original_currency_id' => $object->getOriginalCurrency(), + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'wallet_id' => 'required', + 'currency_id' => 'required', + 'original_currency_id' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ 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/Resources/WalletTransactionResource.php b/app/Http/Resources/WalletTransactionResource.php new file mode 100644 index 00000000..1d0037fe --- /dev/null +++ b/app/Http/Resources/WalletTransactionResource.php @@ -0,0 +1,29 @@ + $this->id, + 'wallet_id' => (int) $this->wallet_id, + 'bill_no' => (int) $this->bill_no, + 'trans_type'=>(int) $this->trans_type, + 'amount' => (double) $this->amount, + 'currency_id' => (int) $this->currency_id, + 'original_amount' => (double) $this->original_amount, + 'original_currency_id' => (int) $this->original_currency_id, + 'currency_rate' => (double) $this->currency_rate + ]; + } +} diff --git a/app/Models/WalletTransaction.php b/app/Models/WalletTransaction.php new file mode 100644 index 00000000..efd5a878 --- /dev/null +++ b/app/Models/WalletTransaction.php @@ -0,0 +1,27 @@ +hasOne(Wallet::class, 'wallet_id', 'id'); + } + + public function currency(): HasOne + { + return $this->hasOne(Currency::class, 'currency_id', 'id'); + } + + public function original_currency(): HasOne + { + return $this->hasOne(Currency::class, 'original_currency_id', 'id'); + } + +} diff --git a/database/migrations/2020_11_30_212314_create_wallet_transaction_table.php b/database/migrations/2020_11_30_212314_create_wallet_transaction_table.php new file mode 100644 index 00000000..92818335 --- /dev/null +++ b/database/migrations/2020_11_30_212314_create_wallet_transaction_table.php @@ -0,0 +1,45 @@ +id(); + + $table->bigInteger('wallet_id')->unsigned(); + $table->bigInteger('bill_no')->unsigned(); + $table->integer('trans_type'); + $table->decimal('amount', 14, 5)->default(0.00); + $table->bigInteger('currency_id')->unsigned(); + $table->decimal('original_amount', 14, 5)->default(0.00); + $table->bigInteger('original_currency_id')->unsigned(); + $table->decimal('currency_rate', 14, 5)->default(0.00); + $table->timestamps(); + + $table->foreign('wallet_id')->references('id')->on('wallets')->onDelete('cascade'); + $table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade'); + $table->foreign('original_currency_id')->references('id')->on('currencies')->onDelete('cascade'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('wallet_transaction'); + } +} diff --git a/routes/wallet.php b/routes/wallet.php index 3c63ac88..6b19a47c 100644 --- a/routes/wallet.php +++ b/routes/wallet.php @@ -5,5 +5,6 @@ use Illuminate\Support\Facades\Route; Route::group(['prefix' => 'wallets', 'namespace' => 'Wallets', 'as' => 'wallet.'], function () { Route::post('/create', 'CreateWalletController@create')->name('create'); + Route::post('/create-transaction/{id}', 'CreateWalletTransactionController@create')->name('create_transaction'); }); \ No newline at end of file From 3eef8cff259f130bf08279afdd25923a2e766519 Mon Sep 17 00:00:00 2001 From: "weiken.intex" Date: Sun, 6 Dec 2020 22:01:42 +0800 Subject: [PATCH 4/8] create Wallet Transaction - integration (convert the amount) --- .../Services/RateCalculatesCurrency.php | 5 +++ .../CreateWalletTransactionLogic.php | 33 ++++++++++++++++--- .../Wallets/Services/FetchesWallet.php | 33 +++++++++++++++++++ .../WalletTransactionValidation.php | 6 ++-- 4 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 app/Classes/Modules/Wallets/Services/FetchesWallet.php diff --git a/app/Classes/Modules/Currencies/Services/RateCalculatesCurrency.php b/app/Classes/Modules/Currencies/Services/RateCalculatesCurrency.php index 07975388..e51f3338 100644 --- a/app/Classes/Modules/Currencies/Services/RateCalculatesCurrency.php +++ b/app/Classes/Modules/Currencies/Services/RateCalculatesCurrency.php @@ -12,4 +12,9 @@ class RateCalculatesCurrency extends AbstractUpdateRecord { return $convert_amount = ($conversion_currency->selling / $convertable_currency->selling) * $amount; } + + public function execute_rate(Currency $conversion_currency, Currency $convertable_currency) + { + return $convert_rate = ($conversion_currency->selling / $convertable_currency->selling); + } } \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php index 7d6a642d..ecaf36f6 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreateWalletTransactionLogic.php @@ -9,6 +9,10 @@ use App\Classes\Modules\Wallets\DataTransferObjects\WalletTransactionObject; use App\Classes\Modules\Wallets\Services\CreatesWalletTransaction; use App\Classes\Modules\Wallets\Services\GeneratesWalletTransactionBillNo; use App\Http\Resources\WalletTransactionResource; +use App\Classes\Modules\Wallets\Services\FetchesWallet; + +use App\Classes\Modules\Currencies\Services\FetchesCurrency; +use App\Classes\Modules\Currencies\Services\RateCalculatesCurrency; /* use App\Classes\Modules\Accounts\Standards\Rules\CanCreateUser; use App\Classes\Modules\Accounts\Services\CreatesUser; @@ -58,6 +62,12 @@ class CreateWalletTransactionLogic extends AbstractControllerLogic /** @var CanCreateWalletTransaction */ private $canCreateWalletTransaction; + + private $fetchesCurrency; + + private $rateCalculatesCurrency; + + private $fetchesWallet; /** * CreateWalletLogic constructor. @@ -65,11 +75,17 @@ class CreateWalletTransactionLogic extends AbstractControllerLogic * @param GeneratesWalletCode $generatesWalletCode * @param CanCreateCompanyWallet $canCreateCompanyWallet */ - public function __construct(CreatesWalletTransaction $createsWalletTransaction, GeneratesWalletTransactionBillNo $generatesWalletTransactionBillNo, CanCreateWalletTransaction $canCreateWalletTransaction) + 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; } /** @@ -82,12 +98,19 @@ class CreateWalletTransactionLogic extends AbstractControllerLogic 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( - $request->route('id'), $this->generatesWalletTransactionBillNo->execute(),$request->input('trans_type'), - number_format( (float) $request->input('amount'), 5, '.', ''), $request->input('currency_id') , number_format( (float) $request->input('original_amount'), 5, '.', ''), - $request->input('original_currency_id'),number_format( (float) $request->input('currency_rate'), 5, '.', '') + $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); diff --git a/app/Classes/Modules/Wallets/Services/FetchesWallet.php b/app/Classes/Modules/Wallets/Services/FetchesWallet.php new file mode 100644 index 00000000..48677e4c --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/FetchesWallet.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php b/app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php index 14129c03..925261ad 100644 --- a/app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php +++ b/app/Classes/Modules/Wallets/Standards/Validators/WalletTransactionValidation.php @@ -14,7 +14,8 @@ class WalletTransactionValidation extends AbstractValidation return [ 'wallet_id' => $object->getWalletId(), 'currency_id' => $object->getCurrency(), - 'original_currency_id' => $object->getOriginalCurrency(), + 'amount' => $object->getAmount(), + 'trans_type'=>$object->getTransType() ]; } @@ -26,7 +27,8 @@ class WalletTransactionValidation extends AbstractValidation return [ 'wallet_id' => 'required', 'currency_id' => 'required', - 'original_currency_id' => 'required', + 'amount' => 'required', + 'trans_type'=>'required' ]; } From 9ed67e74e2fab7b1bc168676a2c84c5234edfe2c Mon Sep 17 00:00:00 2001 From: "weiken.intex" Date: Mon, 7 Dec 2020 14:00:24 +0800 Subject: [PATCH 5/8] create Transaction & Transaction Detail - Supplier (AP) - PO - DO - INV - Customer (AR) - PO - DO - INV --- .../Companies/Services/FetchesCompany.php | 33 ++++ .../CreateTransactionLogic.php | 147 +++++++++++++++++ .../TransactionDetailObject.php | 113 +++++++++++++ .../DataTransferObjects/TransactionObject.php | 150 ++++++++++++++++++ .../ChecksIfTransactionBillNoExists.php | 22 +++ .../Services/CreatesTransaction.php | 35 ++++ .../Services/CreatesTransactionDetail.php | 31 ++++ .../Services/GeneratesTransactionBillNo.php | 27 ++++ .../Standards/Rules/CanCreateTransaction.php | 50 ++++++ .../Rules/CanCreateTransactionDetail.php | 50 ++++++ .../TransactionDetailValidation.php | 63 ++++++++ .../Validators/TransactionValidation.php | 69 ++++++++ .../CreateTransactionController.php | 15 ++ .../Resources/TransactionDetailResource.php | 31 ++++ app/Http/Resources/TransactionResource.php | 34 ++++ app/Models/Transaction.php | 27 ++++ app/Models/TransactionDetail.php | 17 ++ ..._12_01_102314_create_transaction_table.php | 63 ++++++++ routes/transaction.php | 10 ++ 19 files changed, 987 insertions(+) create mode 100644 app/Classes/Modules/Companies/Services/FetchesCompany.php create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php create mode 100644 app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php create mode 100644 app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php create mode 100644 app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNoExists.php create mode 100644 app/Classes/Modules/Transactions/Services/CreatesTransaction.php create mode 100644 app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php create mode 100644 app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNo.php create mode 100644 app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php create mode 100644 app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php create mode 100644 app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php create mode 100644 app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php create mode 100644 app/Http/Controllers/Transactions/CreateTransactionController.php create mode 100644 app/Http/Resources/TransactionDetailResource.php create mode 100644 app/Http/Resources/TransactionResource.php create mode 100644 app/Models/Transaction.php create mode 100644 app/Models/TransactionDetail.php create mode 100644 database/migrations/2020_12_01_102314_create_transaction_table.php create mode 100644 routes/transaction.php diff --git a/app/Classes/Modules/Companies/Services/FetchesCompany.php b/app/Classes/Modules/Companies/Services/FetchesCompany.php new file mode 100644 index 00000000..2ff37e7a --- /dev/null +++ b/app/Classes/Modules/Companies/Services/FetchesCompany.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php new file mode 100644 index 00000000..fef47022 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateTransactionLogic.php @@ -0,0 +1,147 @@ + 'Created Transaction', + 'message' => 'You have successfully created a transaction' + ]; + } + + + /** @var GeneratesTransactionBillNo */ + private $generatesTransactionBillNo; + + /** @var CanCreateTransaction */ + private $canCreateTransaction; + + private $fetchesCurrency; + + private $rateCalculatesCurrency; + + private $fetchesCompany; + + private $createsTransaction; + + private $canCreateTransactionDetail; + + private $createsTransactionDetail; + /** + * CreateWalletLogic constructor. + * @param CreatesWallet $createsWallet + * @param GeneratesWalletCode $generatesWalletCode + * @param CanCreateCompanyWallet $canCreateCompanyWallet + */ + public function __construct( + GeneratesTransactionBillNo $generatesTransactionBillNo, CanCreateTransaction $canCreateTransaction, + FetchesCurrency $fetchesCurrency,RateCalculatesCurrency $rateCalculatesCurrency, FetchesCompany $fetchesCompany, + CreatesTransaction $createsTransaction, + CanCreateTransactionDetail $canCreateTransactionDetail, CreatesTransactionDetail $createsTransactionDetail + ){ + $this->generatesTransactionBillNo = $generatesTransactionBillNo; + $this->canCreateTransaction = $canCreateTransaction; + $this->fetchesCurrency = $fetchesCurrency; + $this->rateCalculatesCurrency = $rateCalculatesCurrency; + $this->fetchesCompany = $fetchesCompany; + $this->createsTransaction =$createsTransaction; + $this->canCreateTransactionDetail =$canCreateTransactionDetail; + $this->createsTransactionDetail = $createsTransactionDetail; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + DB::beginTransaction(); + $json_array = json_decode($request->getContent(), true); + $company = $this->fetchesCompany->execute(['id' => $json_array['company_id']]); + + $conversion_currency = $this->fetchesCurrency->execute(['id' => $json_array['currency_id']]); + $convertable_currency = $this->fetchesCurrency->execute(['id' => 1]);//MYR + $convert_amount = $this->rateCalculatesCurrency->execute($conversion_currency, $convertable_currency, $json_array['amount']); + $convert_rate = $this->rateCalculatesCurrency->execute_rate($conversion_currency, $convertable_currency); + /* + int $bill_no,string $trans_type1,string $trans_type2, + float $amount, int $currency_id, int $original_amount, + int $original_currency_id, float $currency_rate, + string $dt_transaction,int $status,int $booking_id, + int $company_id + */ + $object = new TransactionObject( + $this->generatesTransactionBillNo->execute(),$json_array['trans_type1'],$json_array['trans_type2'], + number_format( (float) $convert_amount, 5, '.', ''), 1 , number_format( (float) $json_array['amount'], 5, '.', ''), + $json_array['currency_id'],number_format( (float) $convert_rate, 5, '.', ''), + $json_array['dt_transaction'],1,$request->route('id'), + $company->id + ); + + $this->canCreateTransaction->passes($object); + + $transaction = $this->createsTransaction->execute($object); + + $transaction_array = new TransactionResource($transaction); + $transaction_detail_array = array(); + foreach ($json_array['transaction_detail'] as $key => $value) { + + $object_detail = new TransactionDetailObject( + $json_array['trans_type1'],$json_array['trans_type2'], + $transaction->id,$value['product_code'],$value['product_name'], + (int)$value['qty'],number_format( (float) $convert_amount, 5, '.', ''), number_format( (float) $json_array['amount'], 5, '.', '') + ); + $this->canCreateTransactionDetail->passes($object_detail); + $transaction_detail = $this->createsTransactionDetail->execute($object_detail); + //array_push($stack, "apple", "raspberry"); + $transaction_detail_resource= new TransactionDetailResource($transaction_detail); + $transaction_detail_array[]= $transaction_detail_resource->toArray($request); + + } + + //$transaction_array['transaction_detail']= $transaction_detail_array; + //print_r($transaction_detail_array); + //dd($transaction_detail_array); + DB::commit(); + + return $this->resourceResponse($transaction_array); + //return $this->resourceResponse($json_array); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php new file mode 100644 index 00000000..81fe6d23 --- /dev/null +++ b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionDetailObject.php @@ -0,0 +1,113 @@ +string('trans_type1'); + $table->string('trans_type2'); + $table->bigInteger('transaction_id')->unsigned(); + $table->string('product_code'); + $table->string('product_name'); + $table->integer('qty')->default(0); + $table->decimal('price', 14, 5)->default(0.00); + $table->decimal('amount', 14, 5)->default(0.00); + */ + private $trans_type1; + + private $trans_type2; + + private $transaction_id; + + private $product_code; + + private $product_name; + + private $qty; + + private $price; + + private $amount; + + + public function __construct( + string $trans_type1,string $trans_type2, + int $transaction_id, string $product_code, $product_name, + int $qty, float $price,float $amount + ){ + $this->trans_type1= $trans_type1; + $this->trans_type2 = $trans_type2; + $this->transaction_id = $transaction_id; + $this->product_code = $product_code; + $this->product_name = $product_name; + $this->qty = $qty; + $this->price = $price; + $this->amount = $amount; + + } + + + /** + * @return string + */ + public function getTransType1(): string + { + return $this->trans_type1; + } + + /** + * @return string + */ + public function getTransType2(): string + { + return $this->trans_type2; + } + + /** + * @return int + */ + public function getTransactionId(): int + { + return $this->transaction_id; + } + + /** + * @return string + */ + public function getProductCode(): string + { + return $this->product_code; + } + + /** + * @return string + */ + public function getProductName(): string + { + return $this->product_name; + } + + /** + * @return int + */ + public function getQty(): int + { + return $this->qty; + } + + public function getPrice(): float + { + return $this->price; + } + + public function getAmount(): float + { + return $this->amount; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php new file mode 100644 index 00000000..22fc241a --- /dev/null +++ b/app/Classes/Modules/Transactions/DataTransferObjects/TransactionObject.php @@ -0,0 +1,150 @@ + $this->id, + 'trans_type1' => $this->trans_type1, + 'trans_type2' => $this->trans_type2, + 'bill_no' => (int) $this->bill_no, + 'amount' => (double) $this->amount, + 'currency_id' => (int) $this->currency_id, + 'original_amount' => (double) $this->original_amount, + 'original_currency_id' => (int) $this->original_currency_id, + 'currency_rate' => (double) $this->currency_rate, + 'dt_transaction' => $this->dt_transaction, + 'status' => (int) $this->status, + 'booking_id' => (int) $this->booking_id, + 'company_id' => (int) $this->company_id + ]; + */ + private $trans_type1; + + private $trans_type2; + + private $bill_no; + + private $amount; + + private $currency_id; + + private $original_amount; + + private $original_currency_id; + + private $currency_rate; + + private $dt_transaction; + + private $status; + + private $booking_id; + + private $company_id; + + public function __construct( + int $bill_no,string $trans_type1,string $trans_type2, + float $amount, int $currency_id, int $original_amount, + int $original_currency_id, float $currency_rate, + string $dt_transaction,int $status,int $booking_id, + int $company_id + ){ + $this->bill_no = $bill_no; + $this->trans_type1= $trans_type1; + $this->trans_type2 = $trans_type2; + $this->amount= $amount; + $this->currency_id = $currency_id; + $this->original_amount = $original_amount; + $this->original_currency_id = $original_currency_id; + $this->currency_rate = $currency_rate; + $this->dt_transaction = $dt_transaction; + $this->status = $status; + $this->booking_id = $booking_id; + $this->company_id = $company_id; + } + + + /** + * @return int + */ + public function getBillNo(): int + { + return $this->bill_no; + } + + /** + * @return string + */ + public function getTransType1(): string + { + return $this->trans_type1; + } + + /** + * @return string + */ + public function getTransType2(): string + { + return $this->trans_type2; + } + + + 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; + } + + /** + * @return string + */ + public function getDtTransaction(): string + { + return $this->dt_transaction; + } + + public function getStatus(): int + { + return $this->original_currency_id; + } + + public function getBookingId(): int + { + return $this->booking_id; + } + + public function getCompanyId(): int + { + return $this->company_id; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNoExists.php b/app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNoExists.php new file mode 100644 index 00000000..0d933c7d --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/ChecksIfTransactionBillNoExists.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/Transactions/Services/CreatesTransaction.php b/app/Classes/Modules/Transactions/Services/CreatesTransaction.php new file mode 100644 index 00000000..e1bb92a7 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CreatesTransaction.php @@ -0,0 +1,35 @@ +bill_no = $object->getBillNo(); + $model->trans_type1 = $object->getTransType1(); + $model->trans_type2 = $object->getTransType2(); + $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(); + $model->dt_transaction = $object->getDtTransaction(); + $model->status = $object->getStatus(); + $model->booking_id = $object->getBookingId(); + $model->company_id = $object->getCompanyId(); + + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php b/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php new file mode 100644 index 00000000..c1e91c7f --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CreatesTransactionDetail.php @@ -0,0 +1,31 @@ +trans_type1 = $object->getTransType1(); + $model->trans_type2 = $object->getTransType2(); + $model->transaction_id = $object->getTransactionId(); + $model->product_code = $object->getProductCode(); + $model->product_name = $object->getProductName(); + $model->qty = $object->getQty(); + $model->price = $object->getPrice(); + $model->amount = $object->getAmount(); + + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNo.php b/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNo.php new file mode 100644 index 00000000..fb7c6867 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/GeneratesTransactionBillNo.php @@ -0,0 +1,27 @@ +transationBillNoExists = $transationBillNoExists; + } + + + + public function execute(): int { + + $code = mt_rand(100000001, 999999999); + return !$this->transationBillNoExists->execute($code) ? $code : self::execute(); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php new file mode 100644 index 00000000..b81c4a09 --- /dev/null +++ b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransaction.php @@ -0,0 +1,50 @@ +transactionValidation = $transactionValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param CompanyWalletValidation $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->transactionValidation->validate($object); + } + + /** + * @param SegmentCompanyValidation $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php new file mode 100644 index 00000000..cc2f2f3c --- /dev/null +++ b/app/Classes/Modules/Transactions/Standards/Rules/CanCreateTransactionDetail.php @@ -0,0 +1,50 @@ +transactionDetailValidation = $transactionDetailValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param CompanyWalletValidation $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->transactionDetailValidation->validate($object); + } + + /** + * @param SegmentCompanyValidation $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php b/app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php new file mode 100644 index 00000000..15e23dcd --- /dev/null +++ b/app/Classes/Modules/Transactions/Standards/Validators/TransactionDetailValidation.php @@ -0,0 +1,63 @@ +bill_no = $bill_no; + $this->trans_type1= $trans_type1; + $this->trans_type2 = $trans_type2; + $this->amount= $amount; + $this->currency_id = $currency_id; + $this->original_amount = $original_amount; + $this->original_currency_id = $original_currency_id; + $this->currency_rate = $currency_rate; + $this->dt_transaction = $dt_transaction; + $this->status = $status; + $this->booking_id = $booking_id; + $this->company_id = $company_id; + */ + protected function data($object): array + { + return [ + 'trans_type1' => $object->getTransType1(), + 'trans_type2' => $object->getTransType2(), + 'transaction_id' => $object->getTransactionId(), + 'product_code' => $object->getProductCode(), + 'product_name'=>$object->getProductName(), + 'qty'=>$object->getQty(), + 'price'=>$object->getPrice(), + 'amount' => $object->getAmount() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'trans_type1' => 'required', + 'trans_type2' => 'required', + 'transaction_id' => 'required', + 'product_code' => 'required', + 'product_name'=>'required', + 'qty'=>'required', + 'price'=>'required', + 'amount' => 'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php b/app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php new file mode 100644 index 00000000..3249f8a1 --- /dev/null +++ b/app/Classes/Modules/Transactions/Standards/Validators/TransactionValidation.php @@ -0,0 +1,69 @@ +bill_no = $bill_no; + $this->trans_type1= $trans_type1; + $this->trans_type2 = $trans_type2; + $this->amount= $amount; + $this->currency_id = $currency_id; + $this->original_amount = $original_amount; + $this->original_currency_id = $original_currency_id; + $this->currency_rate = $currency_rate; + $this->dt_transaction = $dt_transaction; + $this->status = $status; + $this->booking_id = $booking_id; + $this->company_id = $company_id; + */ + protected function data($object): array + { + return [ + 'bill_no' => $object->getBillNo(), + 'trans_type1' => $object->getBillNo(), + 'trans_type2' => $object->getTransType2(), + 'amount' => $object->getAmount(), + 'currency_id' => $object->getCurrency(), + 'original_amount' => $object->getOriginalAmount(), + 'original_currency_id'=>$object->getOriginalCurrency(), + 'dt_transaction'=>$object->getDtTransaction(), + 'status'=>$object->getStatus(), + 'booking_id'=>$object->getBookingId(), + 'company_id'=>$object->getCompanyId() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'bill_no' => 'required', + 'trans_type1' => 'required', + 'trans_type2' => 'required', + 'amount' => 'required', + 'currency_id' => 'required', + 'original_amount' => 'required', + 'original_currency_id'=>'required', + 'dt_transaction'=>'required', + 'status'=>'required', + 'booking_id'=>'required', + 'company_id'=>'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Transactions/CreateTransactionController.php b/app/Http/Controllers/Transactions/CreateTransactionController.php new file mode 100644 index 00000000..c311ca19 --- /dev/null +++ b/app/Http/Controllers/Transactions/CreateTransactionController.php @@ -0,0 +1,15 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Resources/TransactionDetailResource.php b/app/Http/Resources/TransactionDetailResource.php new file mode 100644 index 00000000..9589b1f7 --- /dev/null +++ b/app/Http/Resources/TransactionDetailResource.php @@ -0,0 +1,31 @@ + $this->id, + 'trans_type1' => $this->trans_type1, + 'trans_type2' => $this->trans_type2, + 'transaction_id' => (int) $this->transaction_id, + 'product_code' => $this->product_code, + 'product_name' => $this->product_name, + 'qty' => (int) $this->qty, + 'price' => (double) $this->price, + 'amount' => (double) $this->amount + + ]; + } +} diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php new file mode 100644 index 00000000..c5ba9af5 --- /dev/null +++ b/app/Http/Resources/TransactionResource.php @@ -0,0 +1,34 @@ + $this->id, + 'trans_type1' => $this->trans_type1, + 'trans_type2' => $this->trans_type2, + 'bill_no' => (int) $this->bill_no, + 'amount' => (double) $this->amount, + 'currency_id' => (int) $this->currency_id, + 'original_amount' => (double) $this->original_amount, + 'original_currency_id' => (int) $this->original_currency_id, + 'currency_rate' => (double) $this->currency_rate, + 'dt_transaction' => $this->dt_transaction, + 'status' => (int) $this->status, + 'booking_id' => (int) $this->booking_id, + 'company_id' => (int) $this->company_id + ]; + } +} diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php new file mode 100644 index 00000000..51b28c09 --- /dev/null +++ b/app/Models/Transaction.php @@ -0,0 +1,27 @@ +hasOne(Companies::class, 'company_id', 'id'); + } + + public function currency(): HasOne + { + return $this->hasOne(Currency::class, 'currency_id', 'id'); + } + + public function original_currency(): HasOne + { + return $this->hasOne(Currency::class, 'original_currency_id', 'id'); + } + +} diff --git a/app/Models/TransactionDetail.php b/app/Models/TransactionDetail.php new file mode 100644 index 00000000..49494327 --- /dev/null +++ b/app/Models/TransactionDetail.php @@ -0,0 +1,17 @@ +hasOne(Transaction::class, 'transaction_id', 'id'); + } + +} diff --git a/database/migrations/2020_12_01_102314_create_transaction_table.php b/database/migrations/2020_12_01_102314_create_transaction_table.php new file mode 100644 index 00000000..c66a6fbe --- /dev/null +++ b/database/migrations/2020_12_01_102314_create_transaction_table.php @@ -0,0 +1,63 @@ +id(); + $table->string('trans_type1'); + $table->string('trans_type2'); + $table->bigInteger('bill_no')->unsigned(); + $table->decimal('amount', 14, 5)->default(0.00); + $table->decimal('original_amount', 14, 5)->default(0.00); + $table->bigInteger('currency_id')->unsigned(); + $table->bigInteger('original_currency_id')->unsigned(); + $table->decimal('currency_rate', 14, 5)->default(0.00); + $table->date('dt_transaction'); + $table->integer('status'); + $table->bigInteger('booking_id')->unsigned(); + $table->bigInteger('company_id')->unsigned(); + $table->timestamps(); + $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); + $table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade'); + $table->foreign('original_currency_id')->references('id')->on('currencies')->onDelete('cascade'); + + }); + + Schema::create('transaction_detail', function (Blueprint $table) { + $table->id(); + $table->string('trans_type1'); + $table->string('trans_type2'); + $table->bigInteger('transaction_id')->unsigned(); + $table->string('product_code'); + $table->string('product_name'); + $table->integer('qty')->default(0); + $table->decimal('price', 14, 5)->default(0.00); + $table->decimal('amount', 14, 5)->default(0.00); + $table->timestamps(); + $table->foreign('transaction_id')->references('id')->on('transaction')->onDelete('cascade'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('transaction'); + Schema::dropIfExists('transaction_detail'); + } +} diff --git a/routes/transaction.php b/routes/transaction.php new file mode 100644 index 00000000..e0e9ba86 --- /dev/null +++ b/routes/transaction.php @@ -0,0 +1,10 @@ + 'transactions', 'namespace' => 'Transactions', 'as' => 'transaction.'], function () { + + Route::post('/create/{id}', 'CreateTransactionController@create')->name('create'); + //Route::post('/create-transaction/{id}', 'CreateWalletTransactionController@create')->name('create_transaction'); + +}); \ No newline at end of file From 7a31cabfc631ee524e71ceebaf54b40d1f5b61f4 Mon Sep 17 00:00:00 2001 From: "weiken.intex" Date: Mon, 7 Dec 2020 14:01:08 +0800 Subject: [PATCH 6/8] create Transaction & Transaction Detail - Supplier (AP) - PO - DO - INV - Customer (AR) - PO - DO - INV --- routes/api.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routes/api.php b/routes/api.php index 6518bda2..e6884405 100644 --- a/routes/api.php +++ b/routes/api.php @@ -30,5 +30,7 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function require __DIR__ . '/company_bank.php'; require __DIR__ . '/currency.php'; + + require __DIR__ . '/transaction.php'; }); }); From 8d4853c279e82ff23ef221459626efd58f95d2c8 Mon Sep 17 00:00:00 2001 From: "weiken.intex" Date: Mon, 7 Dec 2020 14:22:56 +0800 Subject: [PATCH 7/8] temporary don't validate account --- routes/api.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/routes/api.php b/routes/api.php index e6884405..b18f4bb9 100644 --- a/routes/api.php +++ b/routes/api.php @@ -17,6 +17,8 @@ use Illuminate\Support\Facades\Route; Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function () { require __DIR__ . '/account.php'; + + require __DIR__ . '/transaction.php'; Route::group(['middleware' => 'valid.token'], function () { require __DIR__ . '/crud.php'; @@ -31,6 +33,5 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function require __DIR__ . '/currency.php'; - require __DIR__ . '/transaction.php'; }); }); From cd571a00eed23daa1132b626c82e817afea2ddab Mon Sep 17 00:00:00 2001 From: omair saleh Date: Mon, 7 Dec 2020 16:14:24 +0800 Subject: [PATCH 8/8] clean up api routes --- .env.example | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..5ac21009 --- /dev/null +++ b/.env.example @@ -0,0 +1,48 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack + +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=laravel +DB_USERNAME=root +DB_PASSWORD= + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +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= + +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}" + +JWT_SECRET= \ No newline at end of file