=== HAQ Booking ===
Contributors: husainahmedqureshi
Tags: booking, appointment, calendar, scheduling, reservations
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.1.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Appointment booking for WordPress with services, staff, calendar, a front-end booking form and email notifications.

== Description ==

HAQ Booking turns your WordPress site into an appointment booking system. Everything runs inside this plugin — no theme dependency and no required companion plugins.

= Features =

* Create services with duration, price and status
* Manage staff, working hours, breaks and assigned services
* Customer records with booking history
* Appointment list and admin calendar
* Availability engine with open time slots
* Mobile-friendly booking form via shortcode `[haq_booking]` or Gutenberg block
* Email confirmation, cancellation and reschedule notices
* Customer cancel and reschedule via secure token links
* GDPR export / erase personal data support

= Admin screens =

All screens live under the **HAQ Booking** menu and require the `manage_haq_booking` capability (granted to administrators on activation).

* **Dashboard** – today's totals (confirmed, pending, cancelled), the next upcoming appointments, a setup checklist with progress bar and quick links.
* **Appointments** – book on behalf of a customer (existing customers are matched by email), edit staff, time, status and notes, delete, and filter by status.
* **Calendar** – month view with previous / next / today navigation, colour-coded by status; click any appointment to edit it.
* **Services** – name, description, duration in minutes, price and active / inactive status.
* **Staff** – name, email, phone, active switch, services offered and weekly working hours with work and break rows. New staff start with Monday–Friday, 9:00–17:00.
* **Customers** – searchable list with booking counters (total, completed, cancelled, no-show), WhatsApp number, messaging opt-in and private notes.
* **Settings** – business details, booking rules, email sender, currency and date/time formats with live preview, and the booking page.
* **WordPress dashboard widget** – today's appointment counts at a glance.

= Booking form =

* Four steps: service → staff → date and time → your details, followed by a confirmation screen with the booking code.
* Optional "Any available staff" choice that picks a free staff member automatically.
* Name and email are required; phone and notes are optional.
* Works with any theme, uses no jQuery, and loads its assets only on pages that contain the form.
* Falls back to `?rest_route=` automatically if pretty REST URLs are unavailable.

= How available times are calculated =

For the chosen service, date and staff member, the plugin:

1. Takes the staff member's working blocks for that weekday.
2. Removes the staff member's break rows.
3. Steps through the day using the **Slot interval** setting and keeps start times where the whole service duration fits.
4. Removes times that overlap existing appointments (cancelled appointments free the slot).
5. Removes times sooner than the **Minimum notice** and dates beyond the **Booking window**.

= Appointment statuses =

`pending`, `confirmed`, `completed`, `cancelled` and `no_show`. Choose **Pending** as the default status in Settings if you want to approve each booking manually.

= Email notifications =

Plain-text emails are sent with `wp_mail()` from the sender name and address set in Settings.

* **New booking** – to the customer (with a manage link), the admin notification email and the assigned staff member.
* **Cancellation** – to the customer and the admin.
* **Reschedule** – to the customer and the admin.

= Customer self-service =

Each booking gets a unique booking code and a secret manage token. The link in the customer's email opens the booking page with `?haqb_manage=TOKEN`, where the customer can cancel or pick a new time. Select your booking page in **Settings** so these links point to the right page.

= Settings reference =

* **Business name** and **Admin notification email**
* **Slot interval** (default 15 minutes), **Minimum notice** (default 1 hour), **Booking window** (default 60 days)
* **Default booking status** (confirmed or pending) and **Any available staff** on/off
* **From name** and **From address** for emails
* **Currency code**, **currency symbol**, **date format** and **time format**
* **Booking page** used for manage links

= Shortcode =

Place this shortcode on any page:

`[haq_booking]`

Or insert the **HAQ Booking** block in the editor.

= For developers =

REST API (namespace `haq-booking/v1`):

* `GET /services` – active services
* `GET /staff?service_id=` – staff who offer a service
* `GET /slots?service_id=&staff_id=&date=YYYY-MM-DD` – available start times
* `POST /book` – create a booking (requires the `wp_rest` nonce)
* `GET /manage/{token}` and `POST /manage/{token}` – view, cancel or reschedule a booking

Actions:

* `haqb_appointment_created`, `haqb_appointment_confirmed`, `haqb_appointment_cancelled`, `haqb_appointment_completed` – receive the appointment object
* `haqb_appointment_rescheduled` – receives the updated and previous appointment
* `haqb_booking_after_submit` – after a booking made through the public form
* `haqb_booking_form_fields` – output extra fields in the details step
* `haqb_enqueue_booking_assets` – enqueue extra scripts with the form
* `haqb_daily_maintenance_run` – daily maintenance cron

Filters:

* `haqb_can_book` – allow or reject a booking (return `true`, `false` or a `WP_Error`)
* `haqb_available_slots` – modify the list of available times
* `haqb_booking_response` – modify the public booking API response
* `haqb_notification_recipients` – change an email recipient per notification type and role
* `haqb_booking_form_fields_allowed_html` – allowed HTML for extra form fields
* `haqb_show_whatsapp_fields` – show or hide the WhatsApp number and opt-in fields

JavaScript: the form dispatches a `haqb:bookingSuccess` event on `document` with `{ root, booking }` in `event.detail`.

= Optional extensions =

An optional commercial add-on can extend HAQ Booking with messaging, payments and calendar sync. The free plugin works fully on its own.

= Privacy =

The plugin stores customer name, email, phone, optional messaging number, appointment details and related notes in your WordPress database. The free plugin does not send data to third-party APIs.

Data is kept in these custom tables: `haqb_services`, `haqb_staff`, `haqb_staff_services`, `haqb_staff_availability`, `haqb_holidays`, `haqb_customers` and `haqb_appointments`. Settings are stored in the `haqb_settings` option.

The plugin registers with the WordPress **Export Personal Data** and **Erase Personal Data** tools. Erasing anonymises the customer record and clears appointment notes while keeping the appointment history for your records. Suggested text is added to the privacy policy guide.

Deactivating the plugin keeps all data. Deleting the plugin from the Plugins screen removes its tables, settings and capability.

== Installation ==

1. Upload the `haq-booking` folder to `/wp-content/plugins/`, or install through the Plugins screen.
2. Activate the plugin.
3. Go to **HAQ Booking → Settings** and set your business name and notification email.
4. Add services and staff under **HAQ Booking**.
5. Place the `[haq_booking]` shortcode on a page, or insert the HAQ Booking block.
6. In **Settings**, select that page as the Booking page (needed for cancel/reschedule email links).

== Screenshots ==

1. Booking form, step 1: the customer chooses a service.
2. Booking form, step 2: the customer chooses a staff member.
3. Booking form, step 3: the customer picks a date and an available time slot.
4. Booking form, step 4: the customer enters their contact details.
5. Booking confirmation screen shown after a successful booking.
6. Admin dashboard: today's figures, upcoming appointments, getting-started checklist and quick links.
7. Appointments: add a booking on behalf of a customer and filter bookings by status.
8. Calendar: month view of every appointment, color-coded by status.
9. Services: add services with duration, price and active status.
10. Staff: add team members and choose the services each one offers.
11. Customers: customer records with WhatsApp opt-in, notes and booking history.
12. Settings: business details, booking rules, email, currency and the booking page.


== Frequently Asked Questions ==

= Does this require a specific theme? =

No. It works with any standard WordPress theme.

= Where is data stored? =

In custom tables in your WordPress database (`wp_haqb_*`).

= Can customers cancel or reschedule? =

Yes. Confirmation emails include a secure manage link when a booking page is configured in Settings.

= Does the free plugin send WhatsApp messages? =

No. Messaging integrations, if any, are provided only by optional add-ons and require your own provider credentials.

= Can I approve bookings before they are confirmed? =

Yes. In **Settings → Booking rules**, set **Default booking status** to **Pending**. New bookings then wait for you to change their status on the Appointments screen.

= Does the free plugin send reminders? =

No. It sends confirmation, cancellation and reschedule emails only.

= Does it take online payments? =

No. Service prices are shown on the form and stored with each appointment, but no payment is collected.

= The booking form says "Invalid security token". =

The form uses a WordPress security token that expires. If you use a page-caching plugin or host cache, exclude your booking page from the cache.

= Does it support multisite? =

Yes. Network activation installs the tables on every site, and new sites are set up automatically.

== Changelog ==

= 1.1.2 =
* Fixed plugin page screenshots, banner and icon assets.

= 1.1.1 =
* Added screenshots and detailed screenshot captions to the plugin page.

= 1.1.0 =
* WordPress.org packaging and structure cleanup.
* Renamed display name to HAQ Booking for clearer free-plugin scope.
* Server-rendered services on the booking form for more reliable loading.
* Improved Settings admin UI.
* Fixed asset URL scheme handling and REST fallback for local/https setups.
* Daily maintenance cron now flushes plugin object-cache groups.
* Softened optional add-on mentions for directory guidelines.
* Regenerated translation template.

= 1.0.3 =
* Settings UI sections and sticky save bar.
* Admin CSS shared with Pro screens when present.

= 1.0.2 =
* Booking form reliability fixes (inline config, relative assets).

= 1.0.1 =
* Empty/error states for the public booking form.

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.1.2 =
Maintenance release: plugin page asset fixes. No functional changes.

= 1.1.1 =
Documentation update: adds screenshots and captions. No functional changes.

= 1.1.0 =
Recommended update before submitting or distributing the plugin. Includes packaging, naming and booking-form reliability improvements.
