| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace IproSync\Jobs\Properties; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Bus\Queueable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Contracts\Queue\ShouldQueue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Foundation\Bus\Dispatchable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Queue\InteractsWithQueue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Illuminate\Queue\SerializesModels; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use IproSync\Models\Property; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use LaravelIproSoftwareApi\IproSoftwareFacade; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | class PropertyPull implements ShouldQueue | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     protected int $iproPropertyId; | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     protected array $requestParams; | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     public function __construct(int $iproPropertyId, array $requestParams = []) | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         $this->iproPropertyId = $iproPropertyId; | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         $this->requestParams  = $requestParams; | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     public function handle() | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $response = IproSoftwareFacade::getPropertyAll($this->iproPropertyId, [ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |             'query' => $this->requestParams, | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         ])->onlySuccessful(); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         $item = $response->json(); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         self::createOrUpdateProperty($item); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public static function createOrUpdateProperty(array $item): ?Property | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $propertyDescription = $item['PropertyDetails'] ?? []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         if (isset($propertyDescription['Id'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             /** @var Property $model */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             $model = Property::firstOrNew(['id' => $propertyDescription['Id']], ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                              ->fill([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                                  'property_reference'     => !empty($propertyDescription['PropertyReference']) ? (string) $propertyDescription['PropertyReference'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                                  'owner_company_id'       => !empty($propertyDescription['OwnerCompanyId']) ? (int) $propertyDescription['OwnerCompanyId'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                                  'owner_contact_id'       => !empty($propertyDescription['OwnerContactId']) ? (int) $propertyDescription['OwnerContactId'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                                  'name'                   => !empty($propertyDescription['Name']) ? (string) $propertyDescription['Name'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                                  'property_name'          => !empty($propertyDescription['PropertyName']) ? (string) $propertyDescription['PropertyName'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                                  'title'                  => !empty($propertyDescription['Title']) ? (string) $propertyDescription['Title'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                                  'owner_property_name'    => !empty($propertyDescription['OwnerPropertyName']) ? (string) $propertyDescription['OwnerPropertyName'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                                  'suspended'              => (bool) ($propertyDescription['Suspended'] ?? false), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                                  'withdrawn'              => (bool) ($propertyDescription['Withdrawn'] ?? false), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                                  'hide_on_website'        => (bool) ($propertyDescription['HideOnWebsite'] ?? false), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                                  'disable_online_booking' => (bool) ($propertyDescription['DisableOnlineBooking'] ?? false), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                                  'contract_renewal_date'  => !empty($propertyDescription['ContractRenewalDate']) ? (string) $propertyDescription['ContractRenewalDate'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                                  'property_website'       => !empty($propertyDescription['PropertyWebsite']) ? (string) $propertyDescription['PropertyWebsite'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                                  'url'                    => !empty($propertyDescription['Url']) ? (string) $propertyDescription['Url'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                                  'currency'               => !empty($propertyDescription['Currency']) ? (string) $propertyDescription['Currency'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                                  'currency_iso'           => !empty($propertyDescription['CurrencyISO']) ? (string) $propertyDescription['CurrencyISO'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                                  'hide_rates'             => (bool) ($propertyDescription['HideRates'] ?? false), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                                  'min_rate'               => !empty($propertyDescription['MinRate']) ? round((float) $propertyDescription['MinRate'], 2) : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                                  'max_rate'               => !empty($propertyDescription['MaxRate']) ? round((float) $propertyDescription['MaxRate'], 2) : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                                  'rates_include_vat'      => (bool) ($propertyDescription['RatesIncludeVat'] ?? false), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                                  'commission'             => !empty($propertyDescription['Commission']) ? round((float) $propertyDescription['Commission'], 2) : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                                  'breakages_deposit'      => !empty($propertyDescription['BreakagesDeposit']) ? round((float) $propertyDescription['BreakagesDeposit'], 2) : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                                  'availability_notes'     => !empty($propertyDescription['AvailabilityNotes']) ? (string) $propertyDescription['AvailabilityNotes'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                                  'intro'                  => !empty($propertyDescription['Intro']) ? (string) $propertyDescription['Intro'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                                  'main_description'       => !empty($propertyDescription['MainDescription']) ? (string) $propertyDescription['MainDescription'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                                  'region_description'     => !empty($propertyDescription['RegionDescription']) ? (string) $propertyDescription['RegionDescription'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                                  'location_description'   => !empty($propertyDescription['LocationDescription']) ? (string) $propertyDescription['LocationDescription'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                                  'warnings'               => !empty($propertyDescription['Warnings']) ? (string) $propertyDescription['Warnings'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                                  'rental_notes_title'     => !empty($propertyDescription['RentalNotesTitle']) ? (string) $propertyDescription['RentalNotesTitle'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                                  'rental_notes'           => !empty($propertyDescription['RentalNotes']) ? (string) $propertyDescription['RentalNotes'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                                  'rental_notes_title_1'   => !empty($propertyDescription['RentalNotesTitle1']) ? (string) $propertyDescription['RentalNotesTitle1'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                                  'rental_notes_1'         => !empty($propertyDescription['RentalNotes1']) ? (string) $propertyDescription['RentalNotes1'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                                  'virtual_tour_title'     => !empty($propertyDescription['VirtualTour']) ? (string) $propertyDescription['VirtualTour'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                                  'virtual_tour'           => !empty($propertyDescription['VirtualTourTitle']) ? (string) $propertyDescription['VirtualTourTitle'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                                  'address'                => !empty($propertyDescription['Address']) ? (string) $propertyDescription['Address'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                                  'address_2'              => !empty($propertyDescription['Address2']) ? (string) $propertyDescription['Address2'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                                  'city'                   => !empty($propertyDescription['City']) ? (string) $propertyDescription['City'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                                  'county'                 => !empty($propertyDescription['County']) ? (string) $propertyDescription['County'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                                  'postcode'               => !empty($propertyDescription['Postcode']) ? (string) $propertyDescription['Postcode'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                                  'country'                => !empty($propertyDescription['Country']) ? (string) $propertyDescription['Country'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                                  'geolocation'            => !empty($propertyDescription['GeoLocation']) ? (string) $propertyDescription['GeoLocation'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                                  'location'               => !empty($propertyDescription['GeoLocation']) ? (array) $propertyDescription['Location'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                                  'pros'                   => !empty($propertyDescription['Pros']) ? (string) $propertyDescription['Pros'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                                  'cons'                   => !empty($propertyDescription['Cons']) ? (string) $propertyDescription['Cons'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                                  'build_size'             => !empty($propertyDescription['BuildSize']) ? (string) $propertyDescription['BuildSize'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                                  'plot_size'              => !empty($propertyDescription['PlotSize']) ? (string) $propertyDescription['PlotSize'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                                  'licence'                => !empty($propertyDescription['Licence']) ? (string) $propertyDescription['Licence'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                                  'trust_pilot_tag'        => !empty($propertyDescription['TrustPilotTag']) ? (string) $propertyDescription['TrustPilotTag'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                                  'seo_title'              => !empty($propertyDescription['SEOTitle']) ? (string) $propertyDescription['SEOTitle'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                                  'seo_keywords'           => !empty($propertyDescription['SEOKeywords']) ? (string) $propertyDescription['SEOKeywords'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                                  'seo_description'        => !empty($propertyDescription['SEODescription']) ? (string) $propertyDescription['SEODescription'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                                  'property_attributes'    => !empty($propertyDescription['Attributes']) ? (array) $propertyDescription['Attributes'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                                  'rooms'                  => !empty($propertyDescription['Rooms']) ? (array) $propertyDescription['Rooms'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                                  'distances'              => !empty($propertyDescription['Distances']) ? (array) $propertyDescription['Distances'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                                  'reviews'                => !empty($propertyDescription['Reviews']) ? (array) $propertyDescription['Reviews'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                                  'assigned_contacts'      => !empty($propertyDescription['AssignedContacts']) ? (array) $propertyDescription['AssignedContacts'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                                  'floor_plan'             => !empty($propertyDescription['FloorPlan']) ? (string) $propertyDescription['FloorPlan'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                                  'press'                  => !empty($propertyDescription['Press']) ? (string) $propertyDescription['Press'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                                  'images'                 => !empty($item['PropertyImages']) ? (array) $item['PropertyImages'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                                  'rates'                  => !empty($item['PropertyRates']) ? (array) $item['PropertyRates'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                                  'availabilities'         => !empty($item['PropertyAvailabilities']) ? (array) $item['PropertyAvailabilities'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                                  'holiday_extras'         => !empty($item['PropertyHolidayExtras']) ? (array) $item['PropertyHolidayExtras'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                                  'discounts'              => !empty($item['PropertyDiscounts']) ? (array) $item['PropertyDiscounts'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                              ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                              ->fillPulled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             $model->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             return $model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  |         return null; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 115 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 116 |  |  |  |