add metrics

This commit is contained in:
2023-12-04 18:39:50 +05:00
parent 6c0afca80a
commit af512688bc
11 changed files with 185 additions and 11 deletions

View File

@@ -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(),
];
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Nova\Resources\Order\Loan\Metrics;
use App\Models\Order\Loan\LoanOrder;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Trend;
use Laravel\Nova\Nova;
class LoanOrderPerDay extends Trend
{
/**
* Get the displayable name of the metric
*/
public function name(): string
{
return sprintf('%s (%s)', __('Loan orders'), __('all'));
}
/**
* Calculate the value of the metric.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return mixed
*/
public function calculate(NovaRequest $request): mixed
{
return $this->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';
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Nova\Resources\Order\Loan\Metrics;
use App\Models\Order\Loan\LoanOrder;
use App\Repos\Order\OrderRepo;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Partition;
class LoanOrderPerStatus extends Partition
{
/**
* Get the displayable name of the metric
*/
public function name(): string
{
return sprintf('%s (%s)', __('Loan orders'), __('all'));
}
/**
* Calculate the value of the metric.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return mixed
*/
public function calculate(NovaRequest $request): mixed
{
return $this->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';
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Nova\Resources\Order\Loan\Metrics;
use App\Models\Order\Loan\LoanOrder;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Value;
use Laravel\Nova\Nova;
class NewLoanOrders extends Value
{
/**
* Get the displayable name of the metric
*/
public function name(): string
{
return sprintf('%s (%s)', __('Loan orders'), __('all'));
}
/**
* Calculate the value of the metric.
*/
public function calculate(NovaRequest $request): mixed
{
return $this->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);
}
}

View File

@@ -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')));
}
}

View File

@@ -98,6 +98,6 @@ class OrderRepo
*/
public static function statusFormatted(string $status = 'pending'): string
{
return static::values()[$status] ?? __('None');
return static::statusValues()[$status] ?? __('None');
}
}

View File

@@ -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"
}

View File

@@ -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",