From 3a7ac7efb82a0b863c231fdd8a1b02000fe45108 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 11 Feb 2023 16:37:01 +0800 Subject: [PATCH 1/6] rate history module --- .../History/ListCurrencyRateHistoryLogic.php | 78 ++++++++++ .../Services/Rates/ListsRateLogs.php | 33 +++++ .../History/ListCurrencyRateHistory.php | 20 +++ .../Resources/CurrencyRateLogResource.php | 23 +++ .../forms/ChooseCurrencyComponent.vue | 118 ++++++++++++++++ .../bookings/forms/ChooseServiceComponent.vue | 97 +++++++++++++ .../bookings/forms/RateHistoriesComponent.vue | 133 ++++++++++++++++++ .../views/pages/rate_histories.blade.php | 8 ++ routes/currency.php | 6 +- routes/web.php | 3 + 10 files changed, 518 insertions(+), 1 deletion(-) create mode 100644 app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php create mode 100644 app/Classes/Modules/Currencies/Services/Rates/ListsRateLogs.php create mode 100644 app/Http/Controllers/Currencies/History/ListCurrencyRateHistory.php create mode 100644 app/Http/Resources/CurrencyRateLogResource.php create mode 100644 resources/assets/vue/components/bookings/forms/ChooseCurrencyComponent.vue create mode 100644 resources/assets/vue/components/bookings/forms/ChooseServiceComponent.vue create mode 100644 resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue create mode 100644 resources/views/pages/rate_histories.blade.php diff --git a/app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php new file mode 100644 index 00000000..f1fb4f10 --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php @@ -0,0 +1,78 @@ + 'Retrieved Currency Rate History', + 'message' => 'You have successfully retrieved a list of Currency Rate History' + ]; + } + + /** @var CanListRates */ + private $canListRates; + + /** @var ListsRateLogs */ + private $listsRateLogs; + + /** @var FetchesRate */ + private $fetchesRate; + + /** + * ListRatesLogic constructor. + * @param CanListRates $canListRates + * @param ListsRates $listsRates + */ + public function __construct(CanListRates $canListRates, ListsRateLogs $listsRateLogs, FetchesRate $fetchesRate) + { + $this->canListRates = $canListRates; + $this->listsRateLogs = $listsRateLogs; + $this->fetchesRate = $fetchesRate; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request): JsonResponse + { + //$this->canListRates->passes(); + + $filterArray = json_decode($request->input('filters')); + + $rate_filter['currency_id'] = $filterArray->currency_id; + $rate_filter['service_id'] = $filterArray->service_id; + + $currency_rate = $this->fetchesRate->execute( + [ + 'currency_id' => $filterArray->currency_id, + 'service_id' => $filterArray->service_id, + ] + )->first(); + + $query = CurrencyRateLog::where('currency_rate_id', $currency_rate->id)->get(); + + return $this->collectionResponse(CurrencyRateLogResource::collection($query)); + } +} diff --git a/app/Classes/Modules/Currencies/Services/Rates/ListsRateLogs.php b/app/Classes/Modules/Currencies/Services/Rates/ListsRateLogs.php new file mode 100644 index 00000000..d3cfa469 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/Rates/ListsRateLogs.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/History/ListCurrencyRateHistory.php b/app/Http/Controllers/Currencies/History/ListCurrencyRateHistory.php new file mode 100644 index 00000000..7e7db955 --- /dev/null +++ b/app/Http/Controllers/Currencies/History/ListCurrencyRateHistory.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Resources/CurrencyRateLogResource.php b/app/Http/Resources/CurrencyRateLogResource.php new file mode 100644 index 00000000..436d8359 --- /dev/null +++ b/app/Http/Resources/CurrencyRateLogResource.php @@ -0,0 +1,23 @@ + $this->currency_rate_id, + 'rate' => $this->selling, + 'created_at' => $this->created_at->format('d-m-Y'), + ]; + } +} diff --git a/resources/assets/vue/components/bookings/forms/ChooseCurrencyComponent.vue b/resources/assets/vue/components/bookings/forms/ChooseCurrencyComponent.vue new file mode 100644 index 00000000..e670a450 --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/ChooseCurrencyComponent.vue @@ -0,0 +1,118 @@ + + + diff --git a/resources/assets/vue/components/bookings/forms/ChooseServiceComponent.vue b/resources/assets/vue/components/bookings/forms/ChooseServiceComponent.vue new file mode 100644 index 00000000..a6d89538 --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/ChooseServiceComponent.vue @@ -0,0 +1,97 @@ + + + diff --git a/resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue b/resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue new file mode 100644 index 00000000..90d6bb01 --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue @@ -0,0 +1,133 @@ + + + diff --git a/resources/views/pages/rate_histories.blade.php b/resources/views/pages/rate_histories.blade.php new file mode 100644 index 00000000..accb0591 --- /dev/null +++ b/resources/views/pages/rate_histories.blade.php @@ -0,0 +1,8 @@ +@extends('layouts.base_portal') +@section('inner_content') +
+
+ +
+
+@endsection diff --git a/routes/currency.php b/routes/currency.php index ba308402..b621aad6 100644 --- a/routes/currency.php +++ b/routes/currency.php @@ -7,4 +7,8 @@ Route::group(['namespace' => 'Currencies', 'as' => 'currency.', 'prefix' => 'cur Route::get('/list', 'ListCurrencyController@list')->name('list'); Route::post('/create', 'CreateCurrencyController@create')->name('create'); Route::delete('/delete/{id}', 'DeleteCurrencyController@delete')->name('delete'); -}); \ No newline at end of file + + Route::group(['prefix' => 'history', 'namespace' => 'History', 'as' => 'history.'], function () { + Route::get('/list', 'ListCurrencyRateHistory@list')->name('list'); + }); +}); diff --git a/routes/web.php b/routes/web.php index 411a0e71..21aec30e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -538,5 +538,8 @@ Route::get('/refund/fix', function(){ }); +Route::get('/currency-rate-history', function () { + return view('pages.rate_histories'); +})->name('currency_rate.history'); From a423ec43cd8049486b70fc6872e756d801b028d8 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sun, 12 Feb 2023 10:40:50 +0800 Subject: [PATCH 2/6] update rate history module --- .../History/ListCurrencyRateHistoryLogic.php | 7 ++++--- app/Http/Resources/CurrencyRateLogResource.php | 3 +++ app/Models/CurrencyRateLog.php | 9 +++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php index f1fb4f10..c36eebf6 100644 --- a/app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php +++ b/app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php @@ -64,14 +64,15 @@ class ListCurrencyRateHistoryLogic extends AbstractControllerLogic $rate_filter['currency_id'] = $filterArray->currency_id; $rate_filter['service_id'] = $filterArray->service_id; - $currency_rate = $this->fetchesRate->execute( + $currency_rate_ids = $this->fetchesRate->execute( [ 'currency_id' => $filterArray->currency_id, 'service_id' => $filterArray->service_id, ] - )->first(); + )->pluck('id')->toArray(); - $query = CurrencyRateLog::where('currency_rate_id', $currency_rate->id)->get(); + // todo: add in date filters + $query = CurrencyRateLog::whereIn('currency_rate_id', $currency_rate_ids)->get(); return $this->collectionResponse(CurrencyRateLogResource::collection($query)); } diff --git a/app/Http/Resources/CurrencyRateLogResource.php b/app/Http/Resources/CurrencyRateLogResource.php index 436d8359..f8560dd8 100644 --- a/app/Http/Resources/CurrencyRateLogResource.php +++ b/app/Http/Resources/CurrencyRateLogResource.php @@ -14,10 +14,13 @@ class CurrencyRateLogResource extends JsonResource */ public function toArray($request) { + $currencyRate = $this->currencyRate; + return [ 'currency_rate_id' => $this->currency_rate_id, 'rate' => $this->selling, 'created_at' => $this->created_at->format('d-m-Y'), + 'payment_method_type' => $currencyRate->payment_method_type, ]; } } diff --git a/app/Models/CurrencyRateLog.php b/app/Models/CurrencyRateLog.php index 38130956..85b0eecf 100644 --- a/app/Models/CurrencyRateLog.php +++ b/app/Models/CurrencyRateLog.php @@ -1,10 +1,19 @@ BelongsTo(CurrencyRate::class, 'currency_rate_id', 'id'); + } } From 81cf90e4c0da7f3959227749023226393104980c Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sun, 12 Feb 2023 19:50:28 +0800 Subject: [PATCH 3/6] update rate history --- .../Eloquent/Filters/CreatedAtBetween.php | 20 ++++++++++++++++ .../Eloquent/Filters/CurrencyRateIdIn.php | 20 ++++++++++++++++ .../History/ListCurrencyRateHistoryLogic.php | 23 +++++++++++-------- .../bookings/forms/ChooseServiceComponent.vue | 6 ++--- .../bookings/forms/RateHistoriesComponent.vue | 17 ++++++++++---- 5 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 app/Classes/General/Eloquent/Filters/CreatedAtBetween.php create mode 100644 app/Classes/General/Eloquent/Filters/CurrencyRateIdIn.php diff --git a/app/Classes/General/Eloquent/Filters/CreatedAtBetween.php b/app/Classes/General/Eloquent/Filters/CreatedAtBetween.php new file mode 100644 index 00000000..4aeebb8c --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/CreatedAtBetween.php @@ -0,0 +1,20 @@ +whereBetween('created_at', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/CurrencyRateIdIn.php b/app/Classes/General/Eloquent/Filters/CurrencyRateIdIn.php new file mode 100644 index 00000000..f80d0855 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/CurrencyRateIdIn.php @@ -0,0 +1,20 @@ +whereIn('currency_rate_id', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php b/app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php index c36eebf6..aae7d3aa 100644 --- a/app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php +++ b/app/Classes/Modules/Currencies/ControllersLogic/History/ListCurrencyRateHistoryLogic.php @@ -5,14 +5,14 @@ namespace App\Classes\Modules\Currencies\ControllersLogic\History; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Currencies\Services\Rates\ListsRateLogs; -use App\Classes\Modules\Currencies\Services\Rates\FetchesRate; +use App\Classes\Modules\Currencies\Services\Rates\ListsRates; use App\Classes\Modules\Currencies\Standards\Rules\Rates\CanListRates; use App\Http\Resources\CurrencyRateLogResource; -use App\Models\CurrencyRate; use App\Models\CurrencyRateLog; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Carbon\Carbon; class ListCurrencyRateHistoryLogic extends AbstractControllerLogic { @@ -34,19 +34,19 @@ class ListCurrencyRateHistoryLogic extends AbstractControllerLogic /** @var ListsRateLogs */ private $listsRateLogs; - /** @var FetchesRate */ - private $fetchesRate; + /** @var ListsRate */ + private $listsRates; /** * ListRatesLogic constructor. * @param CanListRates $canListRates * @param ListsRates $listsRates */ - public function __construct(CanListRates $canListRates, ListsRateLogs $listsRateLogs, FetchesRate $fetchesRate) + public function __construct(CanListRates $canListRates, ListsRateLogs $listsRateLogs, listsRates $listsRates) { $this->canListRates = $canListRates; $this->listsRateLogs = $listsRateLogs; - $this->fetchesRate = $fetchesRate; + $this->listsRates = $listsRates; } @@ -64,15 +64,20 @@ class ListCurrencyRateHistoryLogic extends AbstractControllerLogic $rate_filter['currency_id'] = $filterArray->currency_id; $rate_filter['service_id'] = $filterArray->service_id; - $currency_rate_ids = $this->fetchesRate->execute( + $currency_rate_ids = $this->listsRates->execute( [ 'currency_id' => $filterArray->currency_id, 'service_id' => $filterArray->service_id, ] )->pluck('id')->toArray(); - // todo: add in date filters - $query = CurrencyRateLog::whereIn('currency_rate_id', $currency_rate_ids)->get(); + $query = $this->listsRateLogs->execute( + [ + 'currency_rate_id_in' => $currency_rate_ids, + 'date_start' => new Carbon($filterArray->date_from), + 'date_end' => new Carbon($filterArray->date_to), + ] + ); return $this->collectionResponse(CurrencyRateLogResource::collection($query)); } diff --git a/resources/assets/vue/components/bookings/forms/ChooseServiceComponent.vue b/resources/assets/vue/components/bookings/forms/ChooseServiceComponent.vue index a6d89538..43d8791e 100644 --- a/resources/assets/vue/components/bookings/forms/ChooseServiceComponent.vue +++ b/resources/assets/vue/components/bookings/forms/ChooseServiceComponent.vue @@ -1,9 +1,9 @@ From e50a3777fd0f230cd6cdc8233ace96396fcc6c9b Mon Sep 17 00:00:00 2001 From: sharifcse57 Date: Mon, 13 Feb 2023 09:23:54 +0600 Subject: [PATCH 5/6] Fix: loading previous data --- .../vue/components/bookings/forms/RateHistoriesComponent.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue b/resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue index 54b8e721..bc24b896 100644 --- a/resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue +++ b/resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue @@ -142,6 +142,8 @@ export default { }, watch: { rateHistory: function(newVal) { + this.chartLebels = []; + this.chartData = []; for (var i = 0; i < newVal.length; i++) { this.chartLebels.push(newVal[i].created_at.split("-")[0]); this.chartData.push(newVal[i]["rate"]); From f55822344a7801ccba3dd7ea60ee49bc1f5dbb83 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 16 Feb 2023 23:20:36 +0800 Subject: [PATCH 6/6] code review --- .../components/bookings/forms/RateHistoriesComponent.vue | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue b/resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue index bc24b896..b55d39c9 100644 --- a/resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue +++ b/resources/assets/vue/components/bookings/forms/RateHistoriesComponent.vue @@ -29,10 +29,8 @@
-
-
- -
+
+