|
@@ -4,6 +4,7 @@ namespace App\Services;
|
|
|
|
|
|
|
|
use App\Models\PartnerAgreement;
|
|
use App\Models\PartnerAgreement;
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
+use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
|
|
|
|
class PartnerAgreementService
|
|
class PartnerAgreementService
|
|
|
{
|
|
{
|
|
@@ -14,6 +15,33 @@ class PartnerAgreementService
|
|
|
->get();
|
|
->get();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function getAllPaginated(array $filters = [], int $perPage = 10): LengthAwarePaginator
|
|
|
|
|
+ {
|
|
|
|
|
+ $query = PartnerAgreement::with(['category', 'city', 'state', 'logo'])
|
|
|
|
|
+ ->orderBy('company_name');
|
|
|
|
|
+
|
|
|
|
|
+ if (!empty($filters['search'])) {
|
|
|
|
|
+ $search = $filters['search'];
|
|
|
|
|
+ $query->where(function ($q) use ($search) {
|
|
|
|
|
+ $q->where('company_name', 'like', "%{$search}%")
|
|
|
|
|
+ ->orWhere('responsible', 'like', "%{$search}%")
|
|
|
|
|
+ ->orWhere('cnpj', 'like', "%{$search}%");
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!empty($filters['expires_in_days'])) {
|
|
|
|
|
+ $days = (int) $filters['expires_in_days'];
|
|
|
|
|
+ $query->whereBetween('contract_end', [now()->startOfDay(), now()->addDays($days)->endOfDay()]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!empty($filters['created_month']) && $filters['created_month'] === 'current') {
|
|
|
|
|
+ $query->whereMonth('created_at', now()->month)
|
|
|
|
|
+ ->whereYear('created_at', now()->year);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $query->paginate($perPage);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function findById(int $id): ?PartnerAgreement
|
|
public function findById(int $id): ?PartnerAgreement
|
|
|
{
|
|
{
|
|
|
return PartnerAgreement::with(['category', 'city', 'state', 'services', 'logo', 'media'])->find($id);
|
|
return PartnerAgreement::with(['category', 'city', 'state', 'services', 'logo', 'media'])->find($id);
|