|
@@ -2,9 +2,12 @@
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
|
|
+use App\Enums\UserTypeEnum;
|
|
|
use App\Models\PartnerAgreement;
|
|
use App\Models\PartnerAgreement;
|
|
|
|
|
+use App\Models\User;
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
|
+use Illuminate\Support\Facades\Hash;
|
|
|
|
|
|
|
|
class PartnerAgreementService
|
|
class PartnerAgreementService
|
|
|
{
|
|
{
|
|
@@ -42,6 +45,15 @@ class PartnerAgreementService
|
|
|
return $query->paginate($perPage);
|
|
return $query->paginate($perPage);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function getExpiringPaginated(int $days = 30, int $perPage = 10): LengthAwarePaginator
|
|
|
|
|
+ {
|
|
|
|
|
+ return PartnerAgreement::with(['category', 'city', 'logo'])
|
|
|
|
|
+ ->whereNotNull('contract_end')
|
|
|
|
|
+ ->whereBetween('contract_end', [now()->startOfDay(), now()->addDays($days)->endOfDay()])
|
|
|
|
|
+ ->orderBy('contract_end')
|
|
|
|
|
+ ->paginate($perPage);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function findById(int $id): ?PartnerAgreement
|
|
public function findById(int $id): ?PartnerAgreement
|
|
|
{
|
|
{
|
|
|
return PartnerAgreement::with(['category', 'city', 'state', 'services', 'logo', 'media', 'user'])->find($id);
|
|
return PartnerAgreement::with(['category', 'city', 'state', 'services', 'logo', 'media', 'user'])->find($id);
|
|
@@ -86,8 +98,20 @@ class PartnerAgreementService
|
|
|
|
|
|
|
|
public function create(array $data): PartnerAgreement
|
|
public function create(array $data): PartnerAgreement
|
|
|
{
|
|
{
|
|
|
- $model = PartnerAgreement::create($data);
|
|
|
|
|
- return $model->fresh(['category', 'logo']);
|
|
|
|
|
|
|
+ $user = User::create([
|
|
|
|
|
+ 'name' => $data['user_name'],
|
|
|
|
|
+ 'email' => $data['user_email'],
|
|
|
|
|
+ 'password' => Hash::make($data['user_password']),
|
|
|
|
|
+ 'type' => UserTypeEnum::PARCEIRO,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ $partnerData = collect($data)
|
|
|
|
|
+ ->except(['user_name', 'user_email', 'user_password'])
|
|
|
|
|
+ ->put('user_id', $user->id)
|
|
|
|
|
+ ->all();
|
|
|
|
|
+
|
|
|
|
|
+ $model = PartnerAgreement::create($partnerData);
|
|
|
|
|
+ return $model->fresh(['category', 'logo', 'user']);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function update(int $id, array $data): ?PartnerAgreement
|
|
public function update(int $id, array $data): ?PartnerAgreement
|