This repository has been archived on 2026-03-21. You can view files and clone it, but cannot push or open issues or pull requests.
payfrit-biz/api/tabs/getActive.cfm
John Mizerek 4c0479db5c Add Open Tabs feature: tab APIs, presence tracking, shared tabs, cron, portal settings
- New api/tabs/ directory with 13 endpoints: open, close, cancel, get, getActive,
  addOrder, increaseAuth, addMember, removeMember, getPresence, approveOrder,
  rejectOrder, pendingOrders
- New api/presence/heartbeat.cfm for beacon-based user presence tracking
- New cron/expireTabs.cfm for idle tab expiry and presence cleanup
- Modified submit.cfm for tab-aware order submission (skip payment, update running total)
- Modified getOrCreateCart.cfm to auto-detect active tab and set TabID on new carts
- Modified webhook.cfm to handle tab capture events (metadata type=tab_close)
- Modified businesses/get.cfm and updateTabs.cfm with new tab config columns
- Updated portal tab settings UI with auth amounts, max members, approval toggle
- Added tab and presence endpoints to Application.cfm public allowlist

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 20:56:07 -08:00

83 lines
3 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<cfheader name="Cache-Control" value="no-store">
<cfscript>
/**
* Get Active Tab
* Checks if user has/is on an active tab (globally).
*
* POST: { UserID: int }
*/
try {
requestData = deserializeJSON(toString(getHttpRequestData().content));
userID = val(requestData.UserID ?: 0);
if (userID == 0) apiAbort({ "OK": false, "ERROR": "missing_UserID" });
qTab = queryTimed("
SELECT t.ID, t.UUID, t.BusinessID, t.OwnerUserID, t.ServicePointID,
t.StatusID, t.AuthAmountCents, t.RunningTotalCents,
t.OpenedOn, t.LastActivityOn, t.PaymentStatus,
b.Name AS BusinessName, b.TabApprovalRequired,
tm.RoleID,
sp.Name AS ServicePointName,
u.FirstName AS OwnerFirstName, u.LastName AS OwnerLastName
FROM TabMembers tm
JOIN Tabs t ON t.ID = tm.TabID
JOIN Businesses b ON b.ID = t.BusinessID
LEFT JOIN ServicePoints sp ON sp.ID = t.ServicePointID
JOIN Users u ON u.ID = t.OwnerUserID
WHERE tm.UserID = :userID AND tm.StatusID = 1 AND t.StatusID = 1
LIMIT 1
", { userID: { value: userID, cfsqltype: "cf_sql_integer" } });
if (qTab.recordCount == 0) {
apiAbort({ "OK": true, "HAS_TAB": false });
}
// Get member count
qMembers = queryTimed("
SELECT COUNT(*) AS MemberCount FROM TabMembers
WHERE TabID = :tabID AND StatusID = 1
", { tabID: { value: qTab.ID, cfsqltype: "cf_sql_integer" } });
// Get pending order count (for tab owner)
pendingCount = 0;
if (qTab.RoleID == 1) {
qPending = queryTimed("
SELECT COUNT(*) AS PendingCount FROM TabOrders
WHERE TabID = :tabID AND ApprovalStatus = 'pending'
", { tabID: { value: qTab.ID, cfsqltype: "cf_sql_integer" } });
pendingCount = qPending.PendingCount;
}
apiAbort({
"OK": true,
"HAS_TAB": true,
"TAB": {
"ID": qTab.ID,
"UUID": qTab.UUID,
"BusinessID": qTab.BusinessID,
"BusinessName": qTab.BusinessName,
"OwnerUserID": qTab.OwnerUserID,
"OwnerName": "#qTab.OwnerFirstName# #qTab.OwnerLastName#",
"ServicePointID": val(qTab.ServicePointID),
"ServicePointName": qTab.ServicePointName ?: "",
"StatusID": qTab.StatusID,
"AuthAmountCents": qTab.AuthAmountCents,
"RunningTotalCents": qTab.RunningTotalCents,
"RemainingCents": qTab.AuthAmountCents - qTab.RunningTotalCents,
"OpenedOn": toISO8601(qTab.OpenedOn),
"MemberCount": qMembers.MemberCount,
"PendingOrderCount": pendingCount,
"IsOwner": qTab.RoleID == 1,
"ApprovalRequired": qTab.TabApprovalRequired == 1
}
});
} catch (any e) {
apiAbort({ "OK": false, "ERROR": "server_error", "MESSAGE": e.message });
}
</cfscript>