CustomScheduleService.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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_get($data, 'quantity', 1);
  50. $specialityIds = data_get($data, 'speciality_ids', []);
  51. $createdCustomSchedules = [];
  52. for ($i = 0; $i < $quantity; $i++) {
  53. $scheduleData = [
  54. 'client_id' => data_get($data, 'client_id'),
  55. 'provider_id' => null,
  56. 'address_id' => data_get($data, 'address_id'),
  57. 'date' => data_get($data, 'date'),
  58. 'period_type' => data_get($data, 'period_type'),
  59. 'schedule_type' => 'custom',
  60. 'start_time' => data_get($data, 'start_time'),
  61. 'end_time' => data_get($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_get($data, 'address_type'),
  71. 'service_type_id' => data_get($data, 'service_type_id'),
  72. 'description' => data_get($data, 'description'),
  73. 'min_price' => data_get($data, 'min_price'),
  74. 'max_price' => data_get($data, 'max_price'),
  75. 'offers_meal' => data_get($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('Erro ao criar agendamento personalizado: '.$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 (data_get($data, 'address_id') !== null) {
  109. $scheduleUpdateData['address_id'] = data_get($data, 'address_id');
  110. }
  111. if (data_get($data, 'date') !== null) {
  112. $scheduleUpdateData['date'] = data_get($data, 'date');
  113. }
  114. if (data_get($data, 'period_type') !== null) {
  115. $scheduleUpdateData['period_type'] = data_get($data, 'period_type');
  116. }
  117. if (data_get($data, 'start_time') !== null) {
  118. $scheduleUpdateData['start_time'] = data_get($data, 'start_time');
  119. }
  120. if (data_get($data, 'end_time') !== null) {
  121. $scheduleUpdateData['end_time'] = data_get($data, 'end_time');
  122. }
  123. if (! empty($scheduleUpdateData)) {
  124. $schedule->update($scheduleUpdateData);
  125. }
  126. $customScheduleUpdateData = [];
  127. if (data_get($data, 'address_type') !== null) {
  128. $customScheduleUpdateData['address_type'] = data_get($data, 'address_type');
  129. }
  130. if (data_get($data, 'service_type_id') !== null) {
  131. $customScheduleUpdateData['service_type_id'] = data_get($data, 'service_type_id');
  132. }
  133. if (data_get($data, 'description') !== null) {
  134. $customScheduleUpdateData['description'] = data_get($data, 'description');
  135. }
  136. if (data_get($data, 'min_price') !== null) {
  137. $customScheduleUpdateData['min_price'] = data_get($data, 'min_price');
  138. }
  139. if (data_get($data, 'max_price') !== null) {
  140. $customScheduleUpdateData['max_price'] = data_get($data, 'max_price');
  141. }
  142. if (data_get($data, 'offers_meal') !== null) {
  143. $customScheduleUpdateData['offers_meal'] = data_get($data, 'offers_meal');
  144. }
  145. if (! empty($customScheduleUpdateData)) {
  146. $customSchedule->update($customScheduleUpdateData);
  147. }
  148. if (data_get($data, 'speciality_ids') !== null) {
  149. $custom_schedule = CustomScheduleSpeciality::where('custom_schedule_id', $customSchedule->id);
  150. $custom_schedule->delete();
  151. foreach (data_get($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('Erro ao atualizar agendamento personalizado: '.$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('Erro ao excluir agendamento personalizado: '.$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' => __('notifications.new_proposal_title'),
  324. 'description' => __('notifications.new_proposal_description', ['provider' => $provider->user->name]),
  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' => __('notifications.opportunity_refused_title'),
  346. 'description' => __('notifications.opportunity_refused_description', ['provider' => $provider->user->name]),
  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(__('messages.invalid_schedule_period'));
  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 = app(NotificationService::class);
  388. $notificationService->create([
  389. 'title' => __('notifications.proposal_accepted_title'),
  390. 'description' => __('notifications.proposal_accepted_description'),
  391. 'origin' => 'schedule',
  392. 'origin_id' => $schedule->id,
  393. 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_PROPOSAL_ACCEPTED->value,
  394. 'user_id' => $provider->user_id,
  395. ]);
  396. app(ScheduleService::class)->updateStatus($schedule->id, 'accepted');
  397. ScheduleProposal::where('schedule_id', $schedule->id)
  398. ->where('id', '!=', $proposalId)
  399. ->delete();
  400. return $schedule->fresh(['provider.user']);
  401. });
  402. }
  403. public function refuseProposal($proposalId)
  404. {
  405. return DB::transaction(function () use ($proposalId) {
  406. $proposal = ScheduleProposal::findOrFail($proposalId);
  407. ScheduleRefuse::create([
  408. 'schedule_id' => $proposal->schedule_id,
  409. 'provider_id' => $proposal->provider_id,
  410. ]);
  411. $notificationService = app(NotificationService::class);
  412. $notificationService->create([
  413. 'title' => __('notifications.proposal_refused_title'),
  414. 'description' => __('notifications.proposal_refused_description'),
  415. 'origin' => 'schedule',
  416. 'origin_id' => $proposal->schedule_id,
  417. 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
  418. 'user_id' => $proposal->provider->user_id,
  419. ]);
  420. $proposal->delete();
  421. return true;
  422. });
  423. }
  424. //
  425. public function formatCustomSchedules($schedules)
  426. {
  427. $grouped = $schedules->groupBy('client_id')->map(function ($clientSchedules) {
  428. $firstSchedule = $clientSchedules->first();
  429. $clientPhotoPath = $firstSchedule->client->profileMedia?->path;
  430. return [
  431. 'client_id' => $firstSchedule->client_id,
  432. 'client_name' => $firstSchedule->client->user->name ?? 'N/A',
  433. 'customer_photo' => $clientPhotoPath
  434. ? Storage::temporaryUrl($clientPhotoPath, now()->addMinutes(60))
  435. : null,
  436. 'schedules' => $clientSchedules->map(function ($schedule) {
  437. $customSchedule = $schedule->customSchedule;
  438. return [
  439. 'id' => $schedule->id,
  440. 'date' => $schedule->date ? Carbon::parse($schedule->date)->format('d/m/Y') : null,
  441. 'start_time' => $schedule->start_time,
  442. 'end_time' => $schedule->end_time,
  443. 'period_type' => $schedule->period_type,
  444. 'status' => $schedule->status,
  445. 'total_amount' => $schedule->total_amount,
  446. 'code' => $schedule->code,
  447. 'code_verified' => $schedule->code_verified,
  448. 'provider_id' => $schedule->provider_id,
  449. 'client_id' => $schedule->client_id,
  450. 'provider_name' => $schedule->provider?->user->name ?? 'N/A',
  451. 'address' => $schedule->address ? [
  452. 'id' => $schedule->address->id,
  453. 'address' => $schedule->address->address,
  454. 'complement' => $schedule->address->complement,
  455. 'zip_code' => $schedule->address->zip_code,
  456. 'city' => $schedule->address->city->name ?? '',
  457. 'state' => $schedule->address->city->state->name ?? '',
  458. ] : null,
  459. 'client_name' => $schedule->client->user->name ?? 'N/A',
  460. 'custom_schedule' => $customSchedule ? [
  461. 'id' => $customSchedule->id,
  462. 'address_type' => $customSchedule->address_type,
  463. 'service_type_id' => $customSchedule->service_type_id,
  464. 'service_type_name' => $customSchedule->serviceType?->description ?? 'N/A',
  465. 'description' => $customSchedule->description,
  466. 'min_price' => $customSchedule->min_price,
  467. 'max_price' => $customSchedule->max_price,
  468. 'offers_meal' => $customSchedule->offers_meal,
  469. 'specialities' => $customSchedule->specialities->map(function ($speciality) {
  470. return [
  471. 'id' => $speciality->id,
  472. 'description' => $speciality->description,
  473. ];
  474. })->values(),
  475. ] : null,
  476. 'reviews' => $schedule->reviews->map(function ($review) {
  477. return [
  478. 'id' => $review->id,
  479. 'stars' => $review->stars,
  480. 'comment' => $review->comment,
  481. 'origin' => $review->origin,
  482. 'origin_id' => $review->origin_id,
  483. 'created_at' => Carbon::parse($review->created_at)->format('Y-m-d H:i'),
  484. 'updated_at' => Carbon::parse($review->updated_at)->format('Y-m-d H:i'),
  485. 'improvements' => $review->reviewsImprovements->map(function ($ri) {
  486. return [
  487. 'id' => $ri->id,
  488. 'improvement_type_id' => $ri->improvement_type_id,
  489. 'improvement_type_name' => $ri->improvementType ? $ri->improvementType->description : null,
  490. ];
  491. })->values(),
  492. ];
  493. }),
  494. ];
  495. })->values(),
  496. ];
  497. })->sortBy('id')->values();
  498. return $grouped;
  499. }
  500. public function verifyScheduleCode($scheduleId, $code)
  501. {
  502. $schedule = Schedule::findOrFail($scheduleId);
  503. if ($schedule->code_verified) {
  504. throw new \Exception(__('validation.custom.opportunity.code_already_verified'));
  505. }
  506. if ($schedule->code !== $code) {
  507. throw new \Exception(__('validation.custom.opportunity.invalid_code'));
  508. }
  509. $schedule->update([
  510. 'code_verified' => true,
  511. ]);
  512. return $schedule;
  513. }
  514. //
  515. private function checkProviderAvailability($providerId, $schedule)
  516. {
  517. $client_id = $schedule->client_id;
  518. $provider_id = $providerId;
  519. $date = Carbon::parse($schedule->date);
  520. $dayOfWeek = $date->dayOfWeek; // 0-6
  521. $startTime = $schedule->start_time;
  522. $endTime = $schedule->end_time;
  523. $date_ymd = $date->format('Y-m-d');
  524. $period = $startTime < '13:00:00' ? 'morning' : 'afternoon';
  525. $period_type = $schedule->period_type; // 2,4,6,8
  526. // bloqueio 2 schedules por semana para o mesmo client e provider
  527. ScheduleBusinessRules::validateWeeklyScheduleLimit(
  528. $client_id,
  529. $provider_id,
  530. $date_ymd
  531. );
  532. // bloqueio provider trabalha no dia/periodo
  533. ScheduleBusinessRules::validateWorkingDay(
  534. $provider_id,
  535. $dayOfWeek,
  536. $period
  537. );
  538. // bloqueio provider tem blockedday para dia/hora
  539. ScheduleBusinessRules::validateBlockedDay(
  540. $provider_id,
  541. $date_ymd,
  542. $startTime,
  543. $endTime
  544. );
  545. // bloqueio daily_price do provider esta fora do range min_price e max_price
  546. ScheduleBusinessRules::validatePricePeriod(
  547. $provider_id,
  548. $schedule->customSchedule->min_price,
  549. $schedule->customSchedule->max_price,
  550. $period_type
  551. );
  552. // bloqueio provider tem outro agendamento para dia/hora
  553. ScheduleBusinessRules::validateConflictingSchedule(
  554. $provider_id,
  555. $date_ymd,
  556. $startTime,
  557. $endTime
  558. );
  559. // bloqueio provider tem outra proposta para o mesmo agendamento
  560. ScheduleBusinessRules::validateConflictingSameProposal(
  561. $provider_id,
  562. $schedule->id
  563. );
  564. // bloqueio provider tem outra proposta na mesma data
  565. ScheduleBusinessRules::validateConflictingProposalSameDate(
  566. $provider_id,
  567. $date_ymd,
  568. $startTime,
  569. $endTime,
  570. $schedule->id
  571. );
  572. // bloqueio caso o client tenha bloqueado o provider
  573. ScheduleBusinessRules::validateClientNotBlockedByProvider(
  574. $client_id,
  575. $provider_id
  576. );
  577. // bloqueio caso o provider tenha bloqueado o client
  578. ScheduleBusinessRules::validateProviderNotBlockedByClient(
  579. $client_id,
  580. $provider_id
  581. );
  582. return true;
  583. }
  584. }