CustomScheduleService.php 25 KB

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