# Ticket header

### Support by Time module **[WHMCS](https://puqcloud.com/link.php?id=77)**
#####  [Order now](https://puqcloud.com/whmcs-module-support-by-time.php) | [Download](https://download.puqcloud.com/WHMCS/servers/PUQ_WHMCS-Support-by-time/) | [Community](https://community.puqcloud.com/)

## Time-logging header

Whenever an administrator opens a ticket in the WHMCS admin area, the module injects a context-aware header above the ticket. The header loads its state over AJAX and renders entirely client-side — every action (save, close, reopen, timer, order) happens **without reloading the page**. It detects the situation (active service, terminated service, no service, ticket charged in a previous month, ticket closed, license issue) and renders the appropriate UI.

---

### Open ticket — time form

![Open ticket time form](https://doc.puq.info/uploads/images/gallery/2026-10/embedded-image-pmv5jzwt.png)
*15-ticket-time-form.png*

The default view is a panel containing:

- **Service selector:** A drop-down listing all customer support services. Active services are listed first with `Active` priority, followed by suspended and terminated services. Each entry displays package allocation and remaining hours: `Service name (cycle - status) — Available: 3h 17m / 5h`.
  - **Smart default selection:** When opening a ticket with no hours logged yet, the header automatically pre-selects the first usable **Active** service (prioritizing packages with available quota).
  - **Reactive switching:** Switching services updates the form immediately without page reload, recalculating available time and adjusting controls while preserving any text already typed into the **Note** field.
- An **HH:MM** time input with `−` / `+` buttons (minute steps; minutes roll over into hours). For *One Time* services the value is automatically capped at the hours remaining in the bucket.
- An optional **Note** field (visible to the client when *Show work log to client* is enabled on the product).
- Action buttons:
  - **Save time** — appends the entered time as a new entry; the ticket stays open.
  - **Close ticket and save time** — appends the entry and sets the WHMCS ticket status to *Closed*.
  - **Start** — starts a live timer (see below).

> Each save **adds** a new entry to the ticket — it does not overwrite previous entries. The running total ("Already logged") and the full breakdown are shown in the audit trail.

#### Dynamic button state and status guard

The action buttons and time picker adapt dynamically to the selected service's status and remaining quota:

- **Active recurring service:** Buttons and inputs are always enabled. If usage exceeds included quota, an orange notice displays the overage rate per hour.
- **Active One Time service with hours remaining:** Buttons and inputs are enabled; the maximum loggable time is capped at the remaining bucket hours.
- **Active One Time service exhausted (0 hours left):** Action buttons (**Save time**, **Close & save**, **Start**) and the time input are disabled. A red notice informs: *Package hours exhausted. All prepaid hours for this One Time service have been used. Additional time cannot be added. Please order a new support package.*
- **Non-Active service (Terminated / Suspended):** Action buttons and inputs are disabled, and a warning alert is displayed: *Selected service is {Status}. You cannot log time to this service.*
- **Instant unblocking:** If an operator switches in the drop-down from a Terminated or Suspended service to an Active service, the alert banner disappears immediately and all action buttons and inputs are unblocked without reloading the page.
- **Backend security validation:** All backend endpoints (`save_time`, `timer_start`, `SetItem`) enforce `domainstatus === 'Active'`. Any attempt to log time or start a timer against a non-Active service is rejected at the server level.

#### Audit trail

Below the form, a timeline lists every action taken on the ticket (time logged, edited, deleted, timer start/stop/cancel, service ordered), with the operator name and a relative timestamp.

![Time form with audit trail](https://doc.puq.info/uploads/images/gallery/2026-10/embedded-image-r3recfdt.png)
*16-ticket-time-form-audit.png*

---

### Live timer

Pressing **Start** opens a red *Timer running* panel with a server-anchored running clock and **Stop** / **Cancel** buttons. **Stop** rounds the elapsed time up to the nearest minute and appends it as a regular time entry (with the note, if any); **Cancel** discards it.

![Timer running](https://doc.puq.info/uploads/images/gallery/2026-10/embedded-image-bsrg9ki6.png)
*17-ticket-timer-running.png*

After stopping, the action is recorded in the audit trail (elapsed time, added hours, new total):

![Audit trail after stopping the timer](https://doc.puq.info/uploads/images/gallery/2026-10/embedded-image-l9nm1ld0.png)
*18-ticket-timer-audit.png*

---

### Closed ticket

![Closed ticket](https://doc.puq.info/uploads/images/gallery/2026-10/embedded-image-vkbir0nx.png)
*19-ticket-closed.png*

When the ticket is closed, the header shows a compact summary (logged time + service) plus a **ReOpen** button that switches the WHMCS ticket status back to *Open* so the operator can log more time. If the ticket has already been billed, ReOpen is refused (the time is locked).

---

### Ticket charged in a previous month

![Ticket charged in a previous month](https://doc.puq.info/uploads/images/gallery/2026-10/embedded-image-sgql7ele.png)
*20-ticket-past-month.png*

If the ticket's time belongs to a previous month, editing is locked: the header shows a red panel with the recorded time, the service, and a hint to **recreate or split the ticket** if more time needs to be logged. This prevents retroactive changes after the monthly billable item has been created.

---

### Inactive or terminated service handling

If a ticket has existing logged time associated with a service that has since been terminated or suspended:
- The header displays an alert informing that the selected service is not active and time cannot be added to it.
- If the customer has other active services, the operator can simply switch to an active service in the drop-down — the buttons unblock immediately.
- If the customer has no active services, the operator can order or activate a new package directly from the ticket header using the inline order form.

---

### Client without a support service

![Order service inline](https://doc.puq.info/uploads/images/gallery/2026-10/embedded-image-rsqqec8s.png)
*21-ticket-order-service.png*

If the client does not yet have an Active or Suspended Support by Time service, the header shows an inline order form: a drop-down with all available Support by Time products and a drop-down with available WHMCS payment methods. Submitting it creates a WHMCS order, accepts it, runs auto-setup and reloads the ticket.

---

### License issue

When any of the customer's Support by Time products has an invalid or unreachable license, the header shows a red banner instead of the time form, with the product name and the error message returned by the license server.


<!-- sync:513a3693a84b92ea -->