A simple solution to add location support

164 views
Skip to first unread message

Jason March

unread,
Jun 3, 2023, 5:08:44 AM6/3/23
to Easy!Appointments - Support Group
This is the easiest and most minimal way, I could think to add location support without adding a Locations_model, view, database table, etc... 

Create services with locations (ex: haircut @ chair 1) or just create a new service for a location (ex: Room 1 @ Room 1) then change the appointment view to show a select box for all predefined service locations
.
<from installation root directory> 
in  `/application/views/backend/calendar.php`

remove line for text input  
`<input id="appointment-location" class="form-control">`

replace with service location select field
`
                                    <select id="appointment-location" class="required form-control">
                                      <?php
                                      // Place all service locations in a select field
                                      // sort and remove duplicates
                                      foreach ($available_services as $service)
                                      {
                                        $available_locations[] = $service['location'];
                                      }

                                      $available_locations = array_unique($available_locations);  
                                      foreach ($available_locations as $location)
                                      {
                                        echo '<option value="' . $location . '">'
                                            . $location . '</option>';
                                      }
                                    ?>
                                    </select>
`

If you want to prevent duplicate appointment entry for  the same location at a given time. Adjust the `Appointments_model` `validate($appointment)` function to check for it before it adds an appointment to the database.

in `/application/models/Appointments_model.php`

add validation code to this old code
`
           if ($num_rows === 0)
            {
                throw new Exception('Appointment service id is invalid.');
            }
<----- NEW CODE GOES IN THIS LINE SPACE---->
        }
`
This is the new code to add
`
            // Check if the location is in use.
            $num_rows = $this->db
              ->select('*')
              ->from('appointments')
              ->where('start_datetime <=', $appointment['start_datetime'])
              ->where('end_datetime >=', $appointment['start_datetime'])
              ->where('location', $appointment['location'])
              ->get()->num_rows();

            if ($num_rows !== 0)
            {
                throw new Exception('That location has an unfinished event.');
            }

            $num_rows = $this->db
              ->select('*')
              ->from('appointments')
              ->where('start_datetime <=', $appointment['end_datetime'])
              ->where('end_datetime >=', $appointment['end_datetime'])
              ->where('location', $appointment['location'])
              ->get()->num_rows();

            if ($num_rows !== 0)
            {
                throw new Exception('That location has an upcoming event.');
            }
`
Remember your appointment locations cant overlap at all so it is best to change your reduce your services by 1 minute (ex: prior 60 min to 59 min duration)
With this mod you can maintain a 100% compatible install and database with the official release. 

if you want to see the code or download it via git clone I have put it on my github here.

Alex Tselegidis

unread,
Jun 12, 2023, 6:36:22 AM6/12/23
to Easy!Appointments - Support Group
Hello! 

That's great, thanks for sharing this! 


Alex Tselegidis, Easy!Appointments Creator
Need a customization? Get a free quote!



Carlos Henrique Biscuola de Souza

unread,
Jul 9, 2025, 9:13:20 AMJul 9
to Easy!Appointments - Support Group
Hello, 
Still this mod valid for 1.5.1 version?

Thanks

Alex Tselegidis

unread,
Jul 14, 2025, 3:23:01 AMJul 14
to Easy!Appointments - Support Group
Hello! 

I haven't tested it with the latest release, but it seems that it would work without problems. 



Alex Tselegidis, Easy!Appointments Creator
Need a customization? Get a free quote!



Reply all
Reply to author
Forward
0 new messages