This commit is contained in:
2025-09-25 03:03:31 +05:00
commit ae480cf2f6
2768 changed files with 1485826 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Nova\Resources\Ecommerce\Product\Order\Metrics;
use App\Models\Ecommerce\Product\Order\Order;
use Illuminate\Support\Facades\DB;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Value;
class NewOrders extends Value
{
/**
* Calculate the value of the metric.
*
* @return mixed
*/
public function calculate(NovaRequest $request)
{
if ($request->user()->hasRole('vendor')) {
$channel = $request->user()->channel();
$vendor_orders = DB::table('order_items')->where('channel_id', $channel->id)->pluck('order_id');
return $this->count($request, Order::whereIntegerInRaw('id', $vendor_orders));
}
return $this->count($request, Order::class);
}
/**
* Get the ranges available for the metric.
*/
public function ranges(): array
{
return [
'TODAY' => __('Today'),
30 => __('30 Days'),
60 => __('60 Days'),
365 => __('365 Days'),
'MTD' => __('Month To Date'),
'QTD' => __('Quarter To Date'),
'YTD' => __('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);
}
/**
* Get the URI key for the metric.
*/
public function uriKey(): string
{
return 'orders-new-orders';
}
/**
* Get the displayable name of the metric
*/
public function name(): string
{
return __('Orders');
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Nova\Resources\Ecommerce\Product\Order\Metrics;
use App\Models\Ecommerce\Product\Order\Order;
use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
use DateTimeInterface;
use Illuminate\Support\Facades\DB;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Partition;
class OrdersPerStatus extends Partition
{
/**
* Calculate the value of the metric.
*/
public function calculate(NovaRequest $request): mixed
{
$model = Order::class;
if ($request->user()->hasRole('vendor')) {
$channel = $request->user()->channel();
$vendor_orders = DB::table('order_items')->where('channel_id', $channel->id)->pluck('order_id');
$model = Order::whereIntegerInRaw('id', $vendor_orders);
}
return $this->count($request, $model, 'status')
->colors(OrderStatus::colors())
->label(fn ($value) => OrderStatus::formattedStatusFor($value));
}
/**
* Determine the amount of time the results of the metric should be cached.
*
* @return \DateTimeInterface|\DateInterval|float|int|null
*/
public function cacheFor(): DateTimeInterface|DateInterval|float|int|null
{
return now()->addMinutes(5);
}
/**
* Get the URI key for the metric.
*/
public function uriKey(): string
{
return 'orders-orders-per-status';
}
/**
* Get the displayable name of the metric
*/
public function name(): string
{
return __('Order Per Status');
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace App\Nova\Resources\Ecommerce\Product\Order\Metrics;
use App\Models\Ecommerce\Product\Order\OrderItem;
use DateTimeInterface;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Trend;
class ProductSoldPerDay extends Trend
{
/**
* Calculate the value of the metric.
*/
public function calculate(NovaRequest $request): mixed
{
if ($request->user()->hasRole('vendor')) {
$channel = $request->user()->channel();
return $this->countByDays($request, OrderItem::where('channel_id', $channel->id))->showLatestValue();
}
return $this->countByDays($request, OrderItem::class)->showLatestValue();
}
/**
* Get the ranges available for the metric.
*/
public function ranges(): array
{
return [
30 => __('30 Days'),
60 => __('60 Days'),
90 => __('90 Days'),
];
}
/**
* Determine the amount of time the results of the metric should be cached.
*
* @return \DateTimeInterface|\DateInterval|float|int|null
*/
public function cacheFor(): DateTimeInterface|DateInterval|float|int|null
{
return now()->addMinutes(5);
}
/**
* Get the URI key for the metric.
*/
public function uriKey(): string
{
return 'orders-product-sold-per-day';
}
/**
* Get the displayable name of the metric
*/
public function name(): string
{
return __('Product Sold Per Day');
}
}