Add Order
Feature
- DeliveryBoys book orders, which are stored in the OrderBook spreadsheet.
- Each DeliveryBoy can view only their own orders, while the Owner has access to all orders.
Backend
1. Variables
// declare a variable to model Tea time
ensure var VarSetOfTextTime kind: setOfText
deploy: fixedOnDeploy
value: "<root>
<node key='morning'>Morning</node>
<node key='afternoon'>Afternoon</node>
</root>"
2. OrderBook
Create an OrderBook spreadsheet to store office-related order data.
ensure spreadsheet: OrderBook
withFields: ["Date", "Time", "TeaCount*", "CoffeeCount*", "Signature", "Total"]
ofTypes: [date, pickText, number, number, signature, number]
readRoleSet: [Owner, $Self]
insertRoleSet: [DeliveryBoy]
updateRoleSet: [Owner]
removeRoleSet: [Owner]
// switch context to EntityOrder form
ensure form EntityOrder
label: "Order"
commentRoleSet: [Owner, DeliveryBoy] // roles that can write comments
// switch context to Details section
ensure section: Details
// rename section Details to Order
ctx rename Order
// modify fields
ensure field Date defaultValue: "now"
ensure field Total disabled: true
// use VarSetOfTextTime variable on Time field
ensure field Time
sourceVar: VarSetOfTextTime
defaultOptionId: "morning"
a. OfficeRef
Establish a reference between OrderBook and OfficeMaster to link each order to its respective office.
// ensure section Office and move it above section Order
ensure section: Office
ctx moveup
// specify the fields that will be copied along with reference to Office row id
ensure field OfficeRef kind: ref
spreadsheet: OfficeMaster
layoutSpreadsheet: ListLayout
copyFieldMap: {
'OfficeMasterRowId': '$RowId',
'Name': 'Name',
'OfficeNumber': 'OfficeNumber',
'MobileNumber': 'MobileNumber',
'TeaPrice': 'TeaPrice',
'CoffeePrice': 'CoffeePrice'
}
ensure field OfficeMasterRowId
permissionMatrix: {
'defaultPermission': 'hide'
}
ensure form EntityOrder chatLabelField: Name
b. Searchable...
// make some fields queryable and searchable for faster access
// you can even use copied fields from OfficeRef
ensure spreadsheet OrderBook
searchables: [
Office.Name,
OfficeNumber,
TeaPrice,
CoffeePrice,
Time,
Total,
MobileNumber
]
queryables: [
Office.Name,
OfficeNumber,
TeaPrice,
CoffeePrice,
Time,
TeaCount,
CoffeeCount,
Total
]
c. TotalFormula
Set a formula to calculate the Order price.
ensure form EntityOrder
ensure formula TotalFormula
assignToField: Total
formula: "(${f:TeaPrice} * ${f:TeaCount}) + (${f:CoffeePrice} * ${f:CoffeeCount})"
Frontend
1. AddOrder
Implement an AddOrder action to insert new orders into the OrderBook spreadsheet.
ensure action AddOrder kind: rowInsert
icon: "AddShoppingCartRounded"
spreadsheet: OrderBook
sendMessageToInbox: true
2. Group actions
Make the AddOrder action accessible through the "OrderBook" group.
ensure group OrderBook
allowPromptAssistant: true
hideActionMenu: true
pinnedActions: [AddOrder]
actionPermission: {
'AddOrder': {
'roles': [
'DeliveryBoy'
]
}
}