From af512688bc3cd8f28c4457476dbece2c5a43dcae Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Mon, 4 Dec 2023 18:39:50 +0500 Subject: [PATCH] add metrics --- app/Nova/Dashboards/Main.php | 6 ++ .../Concerns/LoanOrderFieldsForDetail.php | 1 - .../Loan/Concerns/LoanOrderFieldsForIndex.php | 2 - app/Nova/Resources/Order/Loan/LoanOrder.php | 2 +- .../Order/Loan/Metrics/LoanOrderPerDay.php | 64 +++++++++++++++++++ .../Order/Loan/Metrics/LoanOrderPerStatus.php | 55 ++++++++++++++++ .../Order/Loan/Metrics/NewLoanOrders.php | 53 +++++++++++++++ app/Providers/NovaServiceProvider.php | 4 +- app/Repos/Order/OrderRepo.php | 2 +- lang/tk.json | 3 +- lang/vendor/nova/tk.json | 4 +- 11 files changed, 185 insertions(+), 11 deletions(-) create mode 100644 app/Nova/Resources/Order/Loan/Metrics/LoanOrderPerDay.php create mode 100644 app/Nova/Resources/Order/Loan/Metrics/LoanOrderPerStatus.php create mode 100644 app/Nova/Resources/Order/Loan/Metrics/NewLoanOrders.php diff --git a/app/Nova/Dashboards/Main.php b/app/Nova/Dashboards/Main.php index b190b88..455e1a5 100644 --- a/app/Nova/Dashboards/Main.php +++ b/app/Nova/Dashboards/Main.php @@ -2,6 +2,9 @@ namespace App\Nova\Dashboards; +use App\Nova\Resources\Order\Loan\Metrics\LoanOrderPerDay; +use App\Nova\Resources\Order\Loan\Metrics\LoanOrderPerStatus; +use App\Nova\Resources\Order\Loan\Metrics\NewLoanOrders; use Laravel\Nova\Dashboards\Main as Dashboard; class Main extends Dashboard @@ -20,6 +23,9 @@ class Main extends Dashboard public function cards(): array { return [ + NewLoanOrders::make(), + LoanOrderPerDay::make(), + LoanOrderPerStatus::make(), ]; } } diff --git a/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForDetail.php b/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForDetail.php index 8a1c78c..51a9e05 100644 --- a/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForDetail.php +++ b/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForDetail.php @@ -5,7 +5,6 @@ namespace App\Nova\Resources\Order\Loan\Concerns; use App\Nova\Resources\Branch\Branch; use App\Nova\Resources\Order\Loan\LoanType; use App\Nova\Resources\System\Location\Province; -use App\Repos\Order\Loan\LoanTypeRepo; use App\Repos\Order\OrderRepo; use App\Repos\System\Settings\Legal\EducationRepo; use App\Repos\System\Settings\Legal\MarriageRepo; diff --git a/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForIndex.php b/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForIndex.php index 205b162..ef0a4ed 100644 --- a/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForIndex.php +++ b/app/Nova/Resources/Order/Loan/Concerns/LoanOrderFieldsForIndex.php @@ -4,8 +4,6 @@ namespace App\Nova\Resources\Order\Loan\Concerns; use App\Nova\Resources\Branch\Branch; use App\Nova\Resources\Order\Loan\LoanType; -use App\Repos\Branch\BranchRepo; -use App\Repos\Order\Loan\LoanTypeRepo; use App\Repos\Order\OrderRepo; use App\Repos\System\Settings\Location\RegionRepo; use Laravel\Nova\Fields\Badge; diff --git a/app/Nova/Resources/Order/Loan/LoanOrder.php b/app/Nova/Resources/Order/Loan/LoanOrder.php index 3dd1cca..f00801c 100644 --- a/app/Nova/Resources/Order/Loan/LoanOrder.php +++ b/app/Nova/Resources/Order/Loan/LoanOrder.php @@ -52,7 +52,7 @@ class LoanOrder extends Resource public static $title = 'unique_id'; /** - * The relationships that should be eager loaded on index queries. + * The relationships that should be eager loaded on index queries. * * @var array */ diff --git a/app/Nova/Resources/Order/Loan/Metrics/LoanOrderPerDay.php b/app/Nova/Resources/Order/Loan/Metrics/LoanOrderPerDay.php new file mode 100644 index 0000000..a1789a1 --- /dev/null +++ b/app/Nova/Resources/Order/Loan/Metrics/LoanOrderPerDay.php @@ -0,0 +1,64 @@ +countByDays($request, LoanOrder::class); + } + + /** + * Get the ranges available for the metric. + * + * @return array + */ + public function ranges(): array + { + return [ + 30 => Nova::__('30 Days'), + 60 => Nova::__('60 Days'), + 90 => Nova::__('90 Days'), + ]; + } + + /** + * Determine the amount of time the results of the metric should be cached. + * + * @return \DateTimeInterface|\DateInterval|float|int|null + */ + public function cacheFor() + { + // return now()->addMinutes(5); + } + + /** + * Get the URI key for the metric. + * + * @return string + */ + public function uriKey(): string + { + return 'loan-order-per-day'; + } +} diff --git a/app/Nova/Resources/Order/Loan/Metrics/LoanOrderPerStatus.php b/app/Nova/Resources/Order/Loan/Metrics/LoanOrderPerStatus.php new file mode 100644 index 0000000..5ee75d8 --- /dev/null +++ b/app/Nova/Resources/Order/Loan/Metrics/LoanOrderPerStatus.php @@ -0,0 +1,55 @@ +count($request, LoanOrder::class, 'status') + ->colors(OrderRepo::statusColors()) + ->label(fn ($value) => match ($value) { + null => __('None'), + default => OrderRepo::statusFormatted($value) + }); + } + + /** + * Determine the amount of time the results of the metric should be cached. + * + * @return \DateTimeInterface|\DateInterval|float|int|null + */ + public function cacheFor() + { + // return now()->addMinutes(5); + } + + /** + * Get the URI key for the metric. + * + * @return string + */ + public function uriKey(): string + { + return 'loan-order-per-status'; + } +} diff --git a/app/Nova/Resources/Order/Loan/Metrics/NewLoanOrders.php b/app/Nova/Resources/Order/Loan/Metrics/NewLoanOrders.php new file mode 100644 index 0000000..ced1bbb --- /dev/null +++ b/app/Nova/Resources/Order/Loan/Metrics/NewLoanOrders.php @@ -0,0 +1,53 @@ +count($request, LoanOrder::class); + } + + /** + * Get the ranges available for the metric. + */ + public function ranges(): array + { + return [ + 30 => Nova::__('30 Days'), + 60 => Nova::__('60 Days'), + 365 => Nova::__('365 Days'), + 'TODAY' => Nova::__('Today'), + 'MTD' => Nova::__('Month To Date'), + 'QTD' => Nova::__('Quarter To Date'), + 'YTD' => Nova::__('Year To Date'), + ]; + } + + /** + * Determine the amount of time the results of the metric should be cached. + * + * @return \DateTimeInterface|\DateInterval|float|int|null + */ + public function cacheFor() + { + // return now()->addMinutes(5); + } +} diff --git a/app/Providers/NovaServiceProvider.php b/app/Providers/NovaServiceProvider.php index 063ad32..d284d64 100644 --- a/app/Providers/NovaServiceProvider.php +++ b/app/Providers/NovaServiceProvider.php @@ -183,8 +183,6 @@ class NovaServiceProvider extends NovaApplicationServiceProvider */ public function setupFieldMacros(): void { - Date::macro('toTurkmenFormat', function () { - return $this->displayUsing(fn ($value) => $value?->format('d.m.Y')); - }); + Date::macro('toTurkmenFormat', fn () => $this->displayUsing(fn ($value) => $value?->format('d.m.Y'))); } } diff --git a/app/Repos/Order/OrderRepo.php b/app/Repos/Order/OrderRepo.php index b733dff..ea81a7b 100644 --- a/app/Repos/Order/OrderRepo.php +++ b/app/Repos/Order/OrderRepo.php @@ -98,6 +98,6 @@ class OrderRepo */ public static function statusFormatted(string $status = 'pending'): string { - return static::values()[$status] ?? __('None'); + return static::statusValues()[$status] ?? __('None'); } } diff --git a/lang/tk.json b/lang/tk.json index ab679f5..f0d921b 100644 --- a/lang/tk.json +++ b/lang/tk.json @@ -226,5 +226,6 @@ "Now you can set your password, but please make sure that you don't forget it!": "Indi açar sözüni täzeläp bilersiňiz, ýöne ýatdan çykarmaň!", "Your password has been updated": "Siziň açar sözüňiz üýtgedildi", "We send you a verification code to": "Tassyklama belgini şu belgä ugratdyk", - "Backups": "Bekaplar" + "Backups": "Bekaplar", + "all": "ählisi" } diff --git a/lang/vendor/nova/tk.json b/lang/vendor/nova/tk.json index 2352811..fcfab05 100644 --- a/lang/vendor/nova/tk.json +++ b/lang/vendor/nova/tk.json @@ -288,8 +288,8 @@ "No Current Data": "Häzirki maglumatlar ýok", "No Data": "Maglumat ýok", "no file selected": "faýl saýlanmady", - "No Increase": "Okarlandyrma", - "No Prior Data": "Öňünden maglumat ýok", + "No Increase": "Ýokarlanma ýok", + "No Prior Data": "Öňki maglumat ýok", "No Results Found.": "Netije tapylmady", "Norfolk Island": "Norfolk adasy", "Northern Mariana Islands": "Demirgazyk Mariana adalary",