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/admin/copyDrinksToBigDeans.cfm
John Mizerek 1210249f54 Normalize database column and table names across entire codebase
Update all SQL queries, query result references, and ColdFusion code to match
the renamed database schema. Tables use plural CamelCase, PKs are all `ID`,
column prefixes stripped (e.g. BusinessName→Name, UserFirstName→FirstName).

Key changes:
- Strip table-name prefixes from all column references (Businesses, Users,
  Addresses, Hours, Menus, Categories, Items, Stations, Orders,
  OrderLineItems, Tasks, TaskCategories, TaskRatings, QuickTaskTemplates,
  ScheduledTaskDefinitions, ChatMessages, Beacons, ServicePoints, Employees,
  VisitorTrackings, ApiPerfLogs, tt_States, tt_Days, tt_AddressTypes,
  tt_OrderTypes, tt_TaskTypes)
- Rename PK references from {TableName}ID to ID in all queries
- Rewrite 7 admin beacon files to use ServicePoints.BeaconID instead of
  dropped lt_Beacon_Businesses_ServicePoints link table
- Rewrite beacon assignment files (list, save, delete) for new schema
- Fix FK references incorrectly changed to ID (OrderLineItems.OrderID,
  Categories.MenuID, Tasks.CategoryID, ServicePoints.BeaconID)
- Update Addresses: AddressLat→Latitude, AddressLng→Longitude
- Update Users: UserPassword→Password, UserIsEmailVerified→IsEmailVerified,
  UserIsActive→IsActive, UserBalance→Balance, etc.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 15:39:12 -08:00

141 lines
5.7 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>
/**
* Copy drinks from In-N-Out (BusinessID 17) to Big Dean's (BusinessID 27)
*/
response = { "OK": false, "ItemsCreated": 0, "CategoryCreated": false };
try {
bigDeansBusinessId = 27;
// First, check if Big Dean's has a Beverages/Drinks category
qExistingCat = queryExecute("
SELECT ID, Name FROM Categories
WHERE BusinessID = :bizId AND (Name LIKE '%Drink%' OR Name LIKE '%Beverage%')
", { bizId: bigDeansBusinessId }, { datasource: "payfrit" });
if (qExistingCat.recordCount > 0) {
drinksCategoryId = qExistingCat.CategoryID;
response["CategoryNote"] = "Using existing category: " & qExistingCat.Name;
} else {
// Create a new Beverages category for Big Dean's
qMaxCat = queryExecute("SELECT COALESCE(MAX(CategoryID), 0) + 1 as nextId FROM Categories", {}, { datasource: "payfrit" });
drinksCategoryId = qMaxCat.nextId;
qMaxSort = queryExecute("
SELECT COALESCE(MAX(SortOrder), 0) + 1 as nextSort FROM Categories WHERE BusinessID = :bizId
", { bizId: bigDeansBusinessId }, { datasource: "payfrit" });
queryExecute("
INSERT INTO Categories (CategoryID, BusinessID, ParentCategoryID, Name, SortOrder, AddedOn)
VALUES (:catId, :bizId, 0, 'Beverages', :sortOrder, NOW())
", {
catId: drinksCategoryId,
bizId: bigDeansBusinessId,
sortOrder: qMaxSort.nextSort
}, { datasource: "payfrit" });
response["CategoryCreated"] = true;
response["CategoryNote"] = "Created new category: Beverages (ID: " & drinksCategoryId & ")";
}
// Drinks to add (from In-N-Out)
drinks = [
{ name: "Fountain Soda", price: 2.10, desc: "Coca-Cola, Diet Coke, Sprite, Fanta Orange, Lemonade" },
{ name: "Bottled Water", price: 1.50, desc: "" },
{ name: "Iced Tea", price: 2.25, desc: "Freshly brewed" },
{ name: "Coffee", price: 1.95, desc: "Hot brewed coffee" },
{ name: "Hot Cocoa", price: 2.25, desc: "" },
{ name: "Milk", price: 1.25, desc: "2% milk" },
{ name: "Orange Juice", price: 2.50, desc: "Fresh squeezed" },
{ name: "Milkshake", price: 4.95, desc: "Chocolate, Vanilla, or Strawberry - made with real ice cream", requiresChild: 1 }
];
itemsCreated = 0;
for (drink in drinks) {
// Check if item already exists
qExists = queryExecute("
SELECT ID FROM Items
WHERE BusinessID = :bizId AND Name = :name AND CategoryID = :catId
", { bizId: bigDeansBusinessId, name: drink.name, catId: drinksCategoryId }, { datasource: "payfrit" });
if (qExists.recordCount == 0) {
// Get next ItemID
qMaxItem = queryExecute("SELECT COALESCE(MAX(ItemID), 0) + 1 as nextId FROM Items", {}, { datasource: "payfrit" });
newItemId = qMaxItem.nextId;
queryExecute("
INSERT INTO Items (
ItemID, BusinessID, CategoryID, ParentItemID,
Name, Description, Price, IsActive,
SortOrder, IsCollapsible, RequiresChildSelection,
AddedOn
) VALUES (
:itemId, :bizId, :catId, 0,
:name, :desc, :price, 1,
:sortOrder, 0, :requiresChild,
NOW()
)
", {
itemId: newItemId,
bizId: bigDeansBusinessId,
catId: drinksCategoryId,
name: drink.name,
desc: structKeyExists(drink, "desc") ? drink.desc : "",
price: drink.price,
sortOrder: itemsCreated,
requiresChild: structKeyExists(drink, "requiresChild") ? drink.requiresChild : 0
}, { datasource: "payfrit" });
itemsCreated++;
// If milkshake, add flavor options
if (drink.name == "Milkshake") {
flavors = ["Chocolate", "Vanilla", "Strawberry"];
flavorSort = 0;
for (flavor in flavors) {
qMaxOpt = queryExecute("SELECT COALESCE(MAX(ItemID), 0) + 1 as nextId FROM Items", {}, { datasource: "payfrit" });
queryExecute("
INSERT INTO Items (
ItemID, BusinessID, CategoryID, ParentItemID,
Name, Description, Price, IsActive,
SortOrder, IsCollapsible, IsCheckedByDefault,
AddedOn
) VALUES (
:itemId, :bizId, 0, :parentId,
:name, '', 0, 1,
:sortOrder, 0, :isDefault,
NOW()
)
", {
itemId: qMaxOpt.nextId,
bizId: bigDeansBusinessId,
parentId: newItemId,
name: flavor,
sortOrder: flavorSort,
isDefault: (flavor == "Chocolate") ? 1 : 0
}, { datasource: "payfrit" });
flavorSort++;
}
}
}
}
response["OK"] = true;
response["ItemsCreated"] = itemsCreated;
response["CategoryID"] = drinksCategoryId;
} catch (any e) {
response["ERROR"] = "server_error";
response["MESSAGE"] = e.message;
response["DETAIL"] = e.detail;
}
writeOutput(serializeJSON(response));
</cfscript>