47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Purchase\Services;
|
|
|
|
use App\Domains\Logging\Models\ValueChange;
|
|
use App\Domains\Purchase\Models\Purchase;
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
class AdminAppPurchaseService
|
|
{
|
|
public function confirmedSalesTotal(Tenant $tenant): string
|
|
{
|
|
$total = Purchase::query()
|
|
->where('tenant_codigo', $tenant->codigo)
|
|
->where('status', Purchase::STATUS_PAID)
|
|
->sum('total');
|
|
|
|
return number_format((float) $total, 2, '.', '');
|
|
}
|
|
|
|
/** @return LengthAwarePaginator<Purchase> */
|
|
public function purchases(Tenant $tenant): LengthAwarePaginator
|
|
{
|
|
return Purchase::query()
|
|
->where('tenant_codigo', $tenant->codigo)
|
|
->with(['items.imageAttachment'])
|
|
->withCount('tickets')
|
|
->latest()
|
|
->paginateFromRequest()
|
|
->withQueryString();
|
|
}
|
|
|
|
/** @return LengthAwarePaginator<ValueChange> */
|
|
public function modifications(Tenant $tenant): LengthAwarePaginator
|
|
{
|
|
return ValueChange::query()
|
|
->where('tenant_code', $tenant->codigo)
|
|
->where('trackable_type', (new Purchase)->getMorphClass())
|
|
->with(['trackable', 'user'])
|
|
->orderByDesc('changed_at')
|
|
->orderByDesc('id')
|
|
->paginateFromRequest()
|
|
->withQueryString();
|
|
}
|
|
}
|