CustomScheduleService.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <?php
  2. namespace App\Services;
  3. use App\Enums\NotificationTypeEnum;
  4. use App\Models\Address;
  5. use App\Models\CustomSchedule;
  6. use App\Models\CustomScheduleSpeciality;
  7. use App\Models\Provider;
  8. use App\Models\Schedule;
  9. use App\Models\ScheduleProposal;
  10. use App\Models\ScheduleRefuse;
  11. use App\Rules\ScheduleBusinessRules;
  12. use App\Services\NotificationService;
  13. use Carbon\Carbon;
  14. use Illuminate\Support\Facades\DB;
  15. use Illuminate\Support\Facades\Log;
  16. use Illuminate\Support\Facades\Storage;
  17. class CustomScheduleService
  18. {
  19. public function __construct() {}
  20. public function getAll()
  21. {
  22. $custom_schedules = CustomSchedule::with([
  23. 'schedule.client.user',
  24. 'schedule.address',
  25. 'serviceType',
  26. 'specialities.speciality',
  27. ])
  28. ->orderBy('id', 'desc')
  29. ->get();
  30. return $custom_schedules;
  31. }
  32. public function getById($id)
  33. {
  34. $customSchedule = CustomSchedule::with([
  35. 'schedule.client.user',
  36. 'schedule.client.profileMedia',
  37. 'schedule.address',
  38. 'serviceType',
  39. 'specialities.speciality',
  40. ])->find($id);
  41. return $customSchedule;
  42. }
  43. public function create(array $data)
  44. {
  45. DB::beginTransaction();
  46. try {
  47. $quantity = $data['quantity'] ?? 1;
  48. $specialityIds = $data['speciality_ids'] ?? [];
  49. $createdCustomSchedules = [];
  50. for ($i = 0; $i < $quantity; $i++) {
  51. $scheduleData = [
  52. 'client_id' => $data['client_id'],
  53. 'provider_id' => null,
  54. 'address_id' => $data['address_id'],
  55. 'date' => $data['date'],
  56. 'period_type' => $data['period_type'],
  57. 'schedule_type' => 'custom',
  58. 'start_time' => $data['start_time'],
  59. 'end_time' => $data['end_time'],
  60. 'status' => 'pending',
  61. 'total_amount' => 0,
  62. 'code' => str_pad(random_int(0, 9999), 4, '0', STR_PAD_LEFT),
  63. 'code_verified' => false,
  64. ];
  65. $schedule = Schedule::create($scheduleData);
  66. $customScheduleData = [
  67. 'schedule_id' => $schedule->id,
  68. 'address_type' => $data['address_type'],
  69. 'service_type_id' => $data['service_type_id'],
  70. 'description' => $data['description'] ?? null,
  71. 'min_price' => $data['min_price'],
  72. 'max_price' => $data['max_price'],
  73. 'offers_meal' => $data['offers_meal'] ?? false,
  74. ];
  75. $customSchedule = CustomSchedule::create($customScheduleData);
  76. if (! empty($specialityIds)) {
  77. foreach ($specialityIds as $specialityId) {
  78. CustomScheduleSpeciality::create([
  79. 'custom_schedule_id' => $customSchedule->id,
  80. 'speciality_id' => $specialityId,
  81. ]);
  82. }
  83. }
  84. $createdCustomSchedules[] = $customSchedule->load([
  85. 'schedule.client.user',
  86. 'schedule.address',
  87. 'serviceType',
  88. 'specialities.speciality',
  89. ]);
  90. }
  91. DB::commit();
  92. return $createdCustomSchedules;
  93. } catch (\Exception $e) {
  94. DB::rollBack();
  95. Log::error('Error creating custom schedule: '.$e->getMessage());
  96. throw $e;
  97. }
  98. }
  99. public function update($id, array $data)
  100. {
  101. DB::beginTransaction();
  102. try {
  103. $customSchedule = CustomSchedule::findOrFail($id);
  104. $schedule = $customSchedule->schedule;
  105. $scheduleUpdateData = [];
  106. if (isset($data['address_id'])) {
  107. $scheduleUpdateData['address_id'] = $data['address_id'];
  108. }
  109. if (isset($data['date'])) {
  110. $scheduleUpdateData['date'] = $data['date'];
  111. }
  112. if (isset($data['period_type'])) {
  113. $scheduleUpdateData['period_type'] = $data['period_type'];
  114. }
  115. if (isset($data['start_time'])) {
  116. $scheduleUpdateData['start_time'] = $data['start_time'];
  117. }
  118. if (isset($data['end_time'])) {
  119. $scheduleUpdateData['end_time'] = $data['end_time'];
  120. }
  121. if (! empty($scheduleUpdateData)) {
  122. $schedule->update($scheduleUpdateData);
  123. }
  124. $customScheduleUpdateData = [];
  125. if (isset($data['address_type'])) {
  126. $customScheduleUpdateData['address_type'] = $data['address_type'];
  127. }
  128. if (isset($data['service_type_id'])) {
  129. $customScheduleUpdateData['service_type_id'] = $data['service_type_id'];
  130. }
  131. if (isset($data['description'])) {
  132. $customScheduleUpdateData['description'] = $data['description'];
  133. }
  134. if (isset($data['min_price'])) {
  135. $customScheduleUpdateData['min_price'] = $data['min_price'];
  136. }
  137. if (isset($data['max_price'])) {
  138. $customScheduleUpdateData['max_price'] = $data['max_price'];
  139. }
  140. if (isset($data['offers_meal'])) {
  141. $customScheduleUpdateData['offers_meal'] = $data['offers_meal'];
  142. }
  143. if (! empty($customScheduleUpdateData)) {
  144. $customSchedule->update($customScheduleUpdateData);
  145. }
  146. if (isset($data['speciality_ids'])) {
  147. $custom_schedule = CustomScheduleSpeciality::where('custom_schedule_id', $customSchedule->id);
  148. $custom_schedule->delete();
  149. foreach ($data['speciality_ids'] as $specialityId) {
  150. CustomScheduleSpeciality::create([
  151. 'custom_schedule_id' => $customSchedule->id,
  152. 'speciality_id' => $specialityId,
  153. ]);
  154. }
  155. }
  156. DB::commit();
  157. return $customSchedule->fresh([
  158. 'schedule.client.user',
  159. 'schedule.address',
  160. 'serviceType',
  161. 'specialities.speciality',
  162. ]);
  163. } catch (\Exception $e) {
  164. DB::rollBack();
  165. Log::error('Error updating custom schedule: '.$e->getMessage());
  166. throw $e;
  167. }
  168. }
  169. public function delete($id)
  170. {
  171. DB::beginTransaction();
  172. try {
  173. $customSchedule = CustomSchedule::findOrFail($id);
  174. $schedule = $customSchedule->schedule;
  175. CustomScheduleSpeciality::where('custom_schedule_id', $customSchedule->id)->delete();
  176. $customSchedule->delete();
  177. $schedule->delete();
  178. DB::commit();
  179. return $customSchedule;
  180. } catch (\Exception $e) {
  181. DB::rollBack();
  182. Log::error('Error deleting custom schedule: '.$e->getMessage());
  183. throw $e;
  184. }
  185. }
  186. //
  187. public function getAvailableOpportunities($providerId)
  188. {
  189. $provider = Provider::find($providerId);
  190. $providerAddress = Address::where('source', 'provider')
  191. ->where('source_id', $providerId)
  192. ->orderBy('is_primary', 'desc')
  193. ->first();
  194. $providerLat = $providerAddress?->latitude !== null ? (float) $providerAddress->latitude : null;
  195. $providerLng = $providerAddress?->longitude !== null ? (float) $providerAddress->longitude : null;
  196. $opportunities = Schedule::with([
  197. 'client.user',
  198. 'client.profileMedia',
  199. 'address',
  200. 'customSchedule.serviceType',
  201. 'customSchedule.specialities',
  202. ])
  203. ->leftJoin('schedule_refuses', function ($join) use ($providerId) {
  204. $join->on('schedules.id', '=', 'schedule_refuses.schedule_id')
  205. ->where('schedule_refuses.provider_id', $providerId);
  206. })
  207. ->whereNull('schedule_refuses.id')
  208. ->where('schedules.schedule_type', 'custom')
  209. ->where('schedules.status', 'pending')
  210. ->whereNull('schedules.provider_id')
  211. ->whereDate('schedules.date', '>=', now()->toDateString())
  212. ->select(
  213. 'schedules.id',
  214. 'schedules.client_id',
  215. 'schedules.address_id',
  216. 'schedules.date',
  217. 'schedules.period_type',
  218. 'schedules.start_time',
  219. 'schedules.end_time',
  220. 'schedules.total_amount',
  221. DB::raw("
  222. CASE
  223. WHEN schedules.period_type = '2' THEN {$provider->daily_price_2h}
  224. WHEN schedules.period_type = '4' THEN {$provider->daily_price_4h}
  225. WHEN schedules.period_type = '6' THEN {$provider->daily_price_6h}
  226. WHEN schedules.period_type = '8' THEN {$provider->daily_price_8h}
  227. ELSE 0
  228. END AS total_amount
  229. "),
  230. )
  231. ->get();
  232. $availableOpportunities = $opportunities->filter(function ($opportunity) use ($providerId) {
  233. try {
  234. return $this->checkProviderAvailability($providerId, $opportunity);
  235. } catch (\Exception $e) {
  236. return false;
  237. }
  238. });
  239. $availableOpportunities->each(function ($opportunity) use ($providerLat, $providerLng) {
  240. $opportunity->distance_km = DistanceService::calculate(
  241. $providerLat,
  242. $providerLng,
  243. $opportunity->address?->latitude !== null ? (float) $opportunity->address->latitude : null,
  244. $opportunity->address?->longitude !== null ? (float) $opportunity->address->longitude : null,
  245. );
  246. $photoPath = $opportunity->client->profileMedia?->path;
  247. $opportunity->customer_photo = $photoPath
  248. ? Storage::temporaryUrl($photoPath, now()->addMinutes(60))
  249. : null;
  250. });
  251. return $availableOpportunities->values();
  252. }
  253. public function getOpportunityProposals($scheduleId)
  254. {
  255. return ScheduleProposal::with(['provider.user'])
  256. ->where('schedule_id', $scheduleId)
  257. ->orderBy('created_at', 'desc')
  258. ->get();
  259. }
  260. public function getProvidersProposalsAndOpportunities($providerId)
  261. {
  262. $proposals = $this->getProviderProposals($providerId);
  263. $opportunities = $this->formatCustomSchedules($this->getAvailableOpportunities($providerId));
  264. return [
  265. 'proposals' => $proposals,
  266. 'opportunities' => $opportunities,
  267. ];
  268. }
  269. public function getProviderProposals($providerId)
  270. {
  271. return ScheduleProposal::with([
  272. 'schedule.client.user',
  273. 'schedule.address',
  274. 'schedule.address.city',
  275. 'schedule.address.state',
  276. 'schedule.customSchedule.serviceType',
  277. 'schedule.customSchedule.specialities',
  278. 'schedule.provider.user',
  279. ])
  280. ->where('provider_id', $providerId)
  281. ->orderBy('created_at', 'desc')
  282. ->get();
  283. }
  284. public function getSchedulesCustomGroupedByClient()
  285. {
  286. $schedules = Schedule::with(['client.user', 'provider.user', 'address', 'customSchedule.serviceType', 'customSchedule.specialities', 'reviews.reviewsImprovements.improvementType'])
  287. ->orderBy('id', 'desc')
  288. ->where('schedule_type', 'custom')
  289. ->get();
  290. $grouped = $this->formatCustomSchedules($schedules);
  291. return $grouped;
  292. }
  293. //
  294. public function proposeOpportunity($scheduleId, $providerId)
  295. {
  296. $schedule = Schedule::findOrFail($scheduleId);
  297. if ($schedule->provider_id) {
  298. throw new \Exception(__('validation.custom.opportunity.already_assigned'));
  299. }
  300. $existingProposal = ScheduleProposal::where('schedule_id', $scheduleId)
  301. ->where('provider_id', $providerId)
  302. ->first();
  303. if ($existingProposal) {
  304. throw new \Exception(__('validation.custom.opportunity.proposal_already_sent'));
  305. }
  306. $wasRefused = ScheduleRefuse::where('schedule_id', $scheduleId)
  307. ->where('provider_id', $providerId)
  308. ->exists();
  309. if ($wasRefused) {
  310. throw new \Exception(__('validation.custom.opportunity.provider_refused'));
  311. }
  312. $this->checkProviderAvailability($providerId, $schedule);
  313. $provider = Provider::with([
  314. 'user'
  315. ])->findOrFail($providerId);
  316. $schedule->load([
  317. 'client.user'
  318. ]);
  319. $notificationService = app(NotificationService::class);
  320. $notificationService->create([
  321. 'title' => 'Nova proposta recebida!',
  322. 'description' => $provider->user->name . ' enviou uma proposta para seu agendamento sob medida.',
  323. 'origin' => 'schedule',
  324. 'origin_id' => $schedule->id,
  325. 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_NEW_SOLICITATION->value,
  326. 'user_id' => $schedule->client->user_id,
  327. ]);
  328. return ScheduleProposal::create([
  329. 'schedule_id' => $scheduleId,
  330. 'provider_id' => $providerId,
  331. ]);
  332. }
  333. public function refuseOpportunity($scheduleId, $providerId)
  334. {
  335. $schedule = Schedule::with(['client.user'])->findOrFail($scheduleId);
  336. $provider = Provider::with(['user'])->findOrFail($providerId);
  337. $schedule_refuse = ScheduleRefuse::create([
  338. 'schedule_id' => $scheduleId,
  339. 'provider_id' => $providerId,
  340. ]);
  341. $notificationService = app(NotificationService::class);
  342. $notificationService->create([
  343. 'title' => 'Oportunidade recusada!',
  344. 'description' => $provider->user->name . ' recusou sua solicitação sob medida.',
  345. 'origin' => 'schedule',
  346. 'origin_id' => $scheduleId,
  347. 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
  348. 'user_id' => $schedule->client->user_id,
  349. ]);
  350. return $schedule_refuse;
  351. }
  352. //
  353. public function acceptProposal($proposalId)
  354. {
  355. return DB::transaction(function () use ($proposalId) {
  356. $proposal = ScheduleProposal::findOrFail($proposalId);
  357. $schedule = $proposal->schedule;
  358. if ($schedule->provider_id) {
  359. throw new \Exception(__('validation.custom.opportunity.already_assigned'));
  360. }
  361. $provider = Provider::find($proposal->provider_id);
  362. switch ($schedule->period_type) {
  363. case '8':
  364. $baseAmount = $provider->daily_price_8h;
  365. break;
  366. case '6':
  367. $baseAmount = $provider->daily_price_6h;
  368. break;
  369. case '4':
  370. $baseAmount = $provider->daily_price_4h;
  371. break;
  372. case '2':
  373. $baseAmount = $provider->daily_price_2h;
  374. break;
  375. default:
  376. throw new \Exception('Periodo do agendamento invalido.');
  377. }
  378. $schedule->total_amount = $baseAmount;
  379. $schedule->save();
  380. $schedule->update([
  381. 'provider_id' => $proposal->provider_id,
  382. ]);
  383. $schedule->refresh();
  384. $schedule->load(['provider.user', 'client.user']);
  385. $notificationService->create([
  386. 'title' => 'Proposta aceita!',
  387. 'description' => 'O cliente aceitou sua proposta de diária.',
  388. 'origin' => 'schedule',
  389. 'origin_id' => $schedule->id,
  390. 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_PROPOSAL_ACCEPTED->value,
  391. 'user_id' => $provider->user_id,
  392. ]);
  393. app(ScheduleService::class)->updateStatus($schedule->id, 'accepted');
  394. ScheduleProposal::where('schedule_id', $schedule->id)
  395. ->where('id', '!=', $proposalId)
  396. ->delete();
  397. return $schedule->fresh(['provider.user']);
  398. });
  399. }
  400. public function refuseProposal($proposalId)
  401. {
  402. return DB::transaction(function () use ($proposalId) {
  403. $proposal = ScheduleProposal::findOrFail($proposalId);
  404. ScheduleRefuse::create([
  405. 'schedule_id' => $proposal->schedule_id,
  406. 'provider_id' => $proposal->provider_id,
  407. ]);
  408. $notificationService = app(NotificationService::class);
  409. $notificationService->create([
  410. 'title' => 'Proposta recusada!',
  411. 'description' => 'O cliente recusou sua proposta de diária.',
  412. 'origin' => 'schedule',
  413. 'origin_id' => $proposal->schedule_id,
  414. 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
  415. 'user_id' => $proposal->provider->user_id,
  416. ]);
  417. $proposal->delete();
  418. return true;
  419. });
  420. }
  421. //
  422. public function formatCustomSchedules($schedules)
  423. {
  424. $grouped = $schedules->groupBy('client_id')->map(function ($clientSchedules) {
  425. $firstSchedule = $clientSchedules->first();
  426. $clientPhotoPath = $firstSchedule->client->profileMedia?->path;
  427. return [
  428. 'client_id' => $firstSchedule->client_id,
  429. 'client_name' => $firstSchedule->client->user->name ?? 'N/A',
  430. 'customer_photo' => $clientPhotoPath
  431. ? Storage::temporaryUrl($clientPhotoPath, now()->addMinutes(60))
  432. : null,
  433. 'schedules' => $clientSchedules->map(function ($schedule) {
  434. $customSchedule = $schedule->customSchedule;
  435. return [
  436. 'id' => $schedule->id,
  437. 'date' => $schedule->date ? Carbon::parse($schedule->date)->format('d/m/Y') : null,
  438. 'start_time' => $schedule->start_time,
  439. 'end_time' => $schedule->end_time,
  440. 'period_type' => $schedule->period_type,
  441. 'status' => $schedule->status,
  442. 'total_amount' => $schedule->total_amount,
  443. 'code' => $schedule->code,
  444. 'code_verified' => $schedule->code_verified,
  445. 'provider_id' => $schedule->provider_id,
  446. 'client_id' => $schedule->client_id,
  447. 'provider_name' => $schedule->provider?->user->name ?? 'N/A',
  448. 'address' => $schedule->address ? [
  449. 'id' => $schedule->address->id,
  450. 'address' => $schedule->address->address,
  451. 'complement' => $schedule->address->complement,
  452. 'zip_code' => $schedule->address->zip_code,
  453. 'city' => $schedule->address->city->name ?? '',
  454. 'state' => $schedule->address->city->state->name ?? '',
  455. ] : null,
  456. 'client_name' => $schedule->client->user->name ?? 'N/A',
  457. 'custom_schedule' => $customSchedule ? [
  458. 'id' => $customSchedule->id,
  459. 'address_type' => $customSchedule->address_type,
  460. 'service_type_id' => $customSchedule->service_type_id,
  461. 'service_type_name' => $customSchedule->serviceType?->description ?? 'N/A',
  462. 'description' => $customSchedule->description,
  463. 'min_price' => $customSchedule->min_price,
  464. 'max_price' => $customSchedule->max_price,
  465. 'offers_meal' => $customSchedule->offers_meal,
  466. 'specialities' => $customSchedule->specialities->map(function ($speciality) {
  467. return [
  468. 'id' => $speciality->id,
  469. 'description' => $speciality->description,
  470. ];
  471. })->values(),
  472. ] : null,
  473. 'reviews' => $schedule->reviews->map(function ($review) {
  474. return [
  475. 'id' => $review->id,
  476. 'stars' => $review->stars,
  477. 'comment' => $review->comment,
  478. 'origin' => $review->origin,
  479. 'origin_id' => $review->origin_id,
  480. 'created_at' => Carbon::parse($review->created_at)->format('Y-m-d H:i'),
  481. 'updated_at' => Carbon::parse($review->updated_at)->format('Y-m-d H:i'),
  482. 'improvements' => $review->reviewsImprovements->map(function ($ri) {
  483. return [
  484. 'id' => $ri->id,
  485. 'improvement_type_id' => $ri->improvement_type_id,
  486. 'improvement_type_name' => $ri->improvementType ? $ri->improvementType->description : null,
  487. ];
  488. })->values(),
  489. ];
  490. }),
  491. ];
  492. })->values(),
  493. ];
  494. })->sortBy('id')->values();
  495. return $grouped;
  496. }
  497. public function verifyScheduleCode($scheduleId, $code)
  498. {
  499. $schedule = Schedule::findOrFail($scheduleId);
  500. if ($schedule->code_verified) {
  501. throw new \Exception(__('validation.custom.opportunity.code_already_verified'));
  502. }
  503. if ($schedule->code !== $code) {
  504. throw new \Exception(__('validation.custom.opportunity.invalid_code'));
  505. }
  506. $schedule->update([
  507. 'code_verified' => true,
  508. ]);
  509. return $schedule;
  510. }
  511. //
  512. private function checkProviderAvailability($providerId, $schedule)
  513. {
  514. $client_id = $schedule->client_id;
  515. $provider_id = $providerId;
  516. $date = Carbon::parse($schedule->date);
  517. $dayOfWeek = $date->dayOfWeek; // 0-6
  518. $startTime = $schedule->start_time;
  519. $endTime = $schedule->end_time;
  520. $date_ymd = $date->format('Y-m-d');
  521. $period = $startTime < '13:00:00' ? 'morning' : 'afternoon';
  522. $period_type = $schedule->period_type; // 2,4,6,8
  523. // bloqueio 2 schedules por semana para o mesmo client e provider
  524. ScheduleBusinessRules::validateWeeklyScheduleLimit(
  525. $client_id,
  526. $provider_id,
  527. $date_ymd
  528. );
  529. // bloqueio provider trabalha no dia/periodo
  530. ScheduleBusinessRules::validateWorkingDay(
  531. $provider_id,
  532. $dayOfWeek,
  533. $period
  534. );
  535. // bloqueio provider tem blockedday para dia/hora
  536. ScheduleBusinessRules::validateBlockedDay(
  537. $provider_id,
  538. $date_ymd,
  539. $startTime,
  540. $endTime
  541. );
  542. // bloqueio daily_price do provider esta fora do range min_price e max_price
  543. ScheduleBusinessRules::validatePricePeriod(
  544. $provider_id,
  545. $schedule->customSchedule->min_price,
  546. $schedule->customSchedule->max_price,
  547. $period_type
  548. );
  549. // bloqueio provider tem outro agendamento para dia/hora
  550. ScheduleBusinessRules::validateConflictingSchedule(
  551. $provider_id,
  552. $date_ymd,
  553. $startTime,
  554. $endTime
  555. );
  556. // bloqueio provider tem outra proposta para o mesmo agendamento
  557. ScheduleBusinessRules::validateConflictingSameProposal(
  558. $provider_id,
  559. $schedule->id
  560. );
  561. // bloqueio provider tem outra proposta na mesma data
  562. ScheduleBusinessRules::validateConflictingProposalSameDate(
  563. $provider_id,
  564. $date_ymd,
  565. $startTime,
  566. $endTime,
  567. $schedule->id
  568. );
  569. // bloqueio caso o client tenha bloqueado o provider
  570. ScheduleBusinessRules::validateClientNotBlockedByProvider(
  571. $client_id,
  572. $provider_id
  573. );
  574. // bloqueio caso o provider tenha bloqueado o client
  575. ScheduleBusinessRules::validateProviderNotBlockedByClient(
  576. $client_id,
  577. $provider_id
  578. );
  579. return true;
  580. }
  581. }