All lookup/reference tables use prefixed column names (tt_StateID, tt_StateAbbreviation, tt_DayID, tt_DayAbbrev, tt_OrderTypeID, tt_OrderTypeName, ServicePointID, ServicePointName, UserID, UserFirstName, UserLastName, AddressID, AddressLine1, etc). Updated all affected queries to use correct column names with aliases to maintain API compatibility. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
92 lines
2.9 KiB
Text
92 lines
2.9 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 Business Settings
|
|
* Returns settings for the currently selected business
|
|
*
|
|
* Requires: request.BusinessID (set by auth middleware)
|
|
*/
|
|
|
|
function apiAbort(obj) {
|
|
writeOutput(serializeJSON(obj));
|
|
abort;
|
|
}
|
|
|
|
if (!structKeyExists(request, "BusinessID") || !isNumeric(request.BusinessID) || request.BusinessID LTE 0) {
|
|
apiAbort({ OK: false, ERROR: "no_business_selected" });
|
|
}
|
|
|
|
try {
|
|
q = queryExecute("
|
|
SELECT
|
|
b.BusinessID AS ID,
|
|
b.BusinessName AS Name,
|
|
b.BusinessTaxRate AS TaxRate,
|
|
b.BusinessPhone AS Phone
|
|
FROM Businesses b
|
|
WHERE b.BusinessID = :businessId
|
|
LIMIT 1
|
|
", { businessId: request.BusinessID }, { datasource: "payfrit" });
|
|
|
|
if (q.recordCount == 0) {
|
|
apiAbort({ OK: false, ERROR: "business_not_found" });
|
|
}
|
|
|
|
// Get address from Addresses table
|
|
qAddr = queryExecute("
|
|
SELECT a.AddressLine1 AS Line1, a.AddressLine2 AS Line2, a.AddressCity AS City, a.AddressZIPCode AS ZIPCode, s.tt_StateAbbreviation AS State
|
|
FROM Addresses a
|
|
LEFT JOIN tt_States s ON s.tt_StateID = a.AddressStateID
|
|
WHERE (a.AddressBusinessID = :businessId OR a.AddressID = (SELECT BusinessAddressID FROM Businesses WHERE BusinessID = :businessId))
|
|
AND a.AddressIsDeleted = 0
|
|
LIMIT 1
|
|
", { businessId: request.BusinessID }, { datasource: "payfrit" });
|
|
|
|
addressStr = "";
|
|
addrCity = "";
|
|
addrState = "";
|
|
addrZip = "";
|
|
if (qAddr.recordCount > 0) {
|
|
addressStr = qAddr.Line1 ?: "";
|
|
addrCity = qAddr.City ?: "";
|
|
addrState = qAddr.State ?: "";
|
|
addrZip = qAddr.ZIPCode ?: "";
|
|
}
|
|
|
|
// Get owner email from Users table
|
|
qUser = queryExecute("
|
|
SELECT UserContactNumber AS ContactNumber, UserEmailAddress AS EmailAddress
|
|
FROM Users
|
|
WHERE UserID = (SELECT BusinessUserID FROM Businesses WHERE BusinessID = :businessId)
|
|
LIMIT 1
|
|
", { businessId: request.BusinessID }, { datasource: "payfrit" });
|
|
|
|
// Format tax rate as percentage for display (0.0825 -> 8.25)
|
|
taxRateRaw = isNumeric(q.TaxRate) ? q.TaxRate : 0;
|
|
taxRatePercent = taxRateRaw * 100;
|
|
|
|
writeOutput(serializeJSON({
|
|
"OK": true,
|
|
"SETTINGS": {
|
|
"BusinessID": q.ID,
|
|
"Name": q.Name,
|
|
"TaxRate": taxRateRaw,
|
|
"TaxRatePercent": taxRatePercent,
|
|
"Address": addressStr,
|
|
"City": addrCity,
|
|
"State": addrState,
|
|
"Zip": addrZip,
|
|
"Phone": q.Phone ?: "",
|
|
"Email": qUser.recordCount > 0 ? (qUser.EmailAddress ?: "") : ""
|
|
}
|
|
}));
|
|
|
|
} catch (any e) {
|
|
apiAbort({ OK: false, ERROR: "server_error", MESSAGE: e.message });
|
|
}
|
|
</cfscript>
|