feat: Add tenant code to value changes; implement PurchaseController and related services for tenant-specific purchase management
This commit is contained in:
46
app/Domains/Purchase/Services/AdminAppPurchaseService.php
Normal file
46
app/Domains/Purchase/Services/AdminAppPurchaseService.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user