📁 Showcase
Spreadsheet

Order spreadsheet

Backend

1. Variables

Create a VarTextPatternOrderId and VarSequenceOrder variables for the EntityOrder form to uniquely identify an order.

ensure var VarTextPatternOrderId kind: text
  deploy: fixedOnDeploy
  value: "Order-${p1}"

ensure var VarSequenceOrder kind: sequence deploy: fixedOnDeploy value: 100

Create a VarPatternOrderBubbleTitle variable for an order bubble title.

ensure var VarPatternOrderBubbleTitle kind: text
  deploy: fixedOnDeploy
  value: "${p1}"

Create a VarSetOfTextOrderStatus variable to represent and display the status of an order.

ensure var VarSetOfTextOrderStatus kind: setOfText
  deploy: fixedOnDeploy
  value: "<root>
      <node key='keyCreated'>Created</node>
      <node key='keyDispatched'>Dispatched</node>
      <node key='keyInTransit'>In Transit</node>
      <node key='keyCompleted'>Completed</node>
      <node key='keyCancelled'>Cancelled</node>
    </root>"

2. OrderBook

Create an OrderBook spreadsheet to store data related to visit-related order data.

ensure spreadsheet: OrderBook
  withFields: ["Date", "OrderId"]
  ofTypes: [date, identifier]
  removeRoleSet: [Owner]
  insertRoleSet: [Owner, Salesman]
  updateRoleSet: [Owner, Salesman]
  readRoleSet: [Owner]

ensure form EntityOrder
  label: "Order"
  // Employees can comment in the chat bubble
  commentRoleSet: [Employee]
  // Heading label of the chat bubble
  chatLabelPatternVar: {
      'var': 'VarTextPatternOrderId',
      'paramSet': [
        '${f:Details.OrderId}'
      ]
    }

a. Details

Configure the properties of the OrderBook form and its associated fields.

ensure section: Details
ensure field Date defaultValue: "now"
ensure field OrderId
  textPatternVar: {
      'var': 'VarTextPatternOrderId',
      'paramSet': [
        '${var:VarSequenceOrder}'
      ]
    }

ensure field VisitRef kind: ref
  spreadsheet: VisitBook
  layoutSpreadsheet: ListLayout
  copyFieldMap: {
      'VisitRowId': '$RowId',
      'CustomerName': 'CustomerName',
      'MobileNumber': 'MobileNumber',
      'GSTNo': 'GSTNo'
    }

ensure field Remarks kind: paragraph

b. Items

Add an Items grid to the EntityOrder form to capture and organize the tile item details, which will then be stored in the OrderBook spreadsheet for further processing.

// grid declaration
ensure grid: Items
ensure field ItemRef kind: ref
  spreadsheet: ItemMaster
  copyFieldMap: {
      'ItemMasterRowId': '$RowId',
      'Price': 'Price',
      'Name': 'Name',
      'ItemSize': 'ItemSize',
      'ItemType': 'ItemType'
    }
  layoutSpreadsheet: ListLayout
ensure field Quantity kind: counter
ensure field Total kind: number
ensure field ItemRef
  overlayLayoutSpreadsheet.item.firstLine.caption.lineFields: [Quantity]

Apply a ListLayout to the Items grid to display the data in a list format.

// grid layout - list
ensure layoutGrid ListLayout kind: list
  firstLine.first.lineFields: [Name]
  firstLine.caption.lineFields: [Quantity]
  secondLine.first.lineFields: [Price]
  secondLine.first.showLabels: true
  secondLine.caption.lineFields: [Total]

Apply a TableLayout to the Items grid to display the data in a tabular format.

// grid layout - table
ensure layoutGrid TableLayout kind: table
  columnSizeSet: ["Flex", "AutoSize"]
  showComps: [Name, ItemType, ItemSize, Price, Quantity, Total]

Set the default layout to the Items grid.

// default grid layout - list
// user can toggle between list and table layouts through overlay menu
ensure grid: Items
  layoutGridMap.asideDefaultLayout: ListLayout

c. Summary

Add a Summary section to the EntityOrder form to capture and present the overall, aggregated details of an order.

ensure section: Summary
ensure field TotalBill kind: number
  prefix: "₹"
  suffix: "/-"
ensure field OrderStatus kind: pickText
  permissionMatrix: {
      'defaultPermission': 'write',
      'Employee': 'read'
    }
  sourceVar: VarSetOfTextOrderStatus
  defaultOptionId: "keyCreated"

d. Formulas

Set the formulas to compute the Total price for each individual item and the overall TotalBill for the entire order.

ensure formula TotalFormula
  assignToField: Items.Total
  formula: "${f:Items.Price} * ${f:Items.Quantity}"

ensure formula TotalBillFormula
  assignToField: Summary.TotalBill
  formula: "SUM(${f:Items.Total})"

Frontend

1. Actions

a. AddOrder

Create a VarMappingVisitToOrder variable to map data between the source and target forms in the action permission section of the EntityVisit form.

ensure var VarMappingVisitToOrder kind: mapping
  deploy: fixedOnDeploy
  fromForm: EntityVisit
  toForm: EntityOrder
  fieldMappingMap: {
      'map': {
        '${f:SysRowId}': 'VisitRowId',
        '${f:Details.CustomerName}': 'CustomerName',
        '${f:Details.MobileNumber}': 'MobileNumber',
        '${f:Details.GSTNo}': 'GSTNo'
      }
    }

Implement an AddOrder action to insert a new order into the OrderBook spreadsheet.

ensure action AddOrder kind: rowInsert
  icon: "AddShoppingCartRounded"
  spreadsheet: OrderBook
  sendMessageToInbox: true

Add the AddOrder action to the action permission section of the EntityVisit form. Once the visit is added, the salesman can directly place an order for that visit from the chat bubble.

// attach action to EntityVisit's overlay menu on both form and chat bubble
ensure form EntityVisit
  actionPermission: {
    'AddOrder': {
      'mappingVar': 'VarMappingVisitToOrder',
      'roles': [
        'Salesman',
        'Owner'
      ],
      'groups': [
        'MyVisits'
      ]
    }
  }

b. EditOrderBook

Apply a KanbanLayout to the OrderBook spreadsheet for the EditOrderBook action.

// create Kanban layout on OrderBook spreadsheet
ensure spreadsheet OrderBook
ensure layoutSpreadsheet KanbanLayout kind: kanban
  kanbanField: Summary.OrderStatus
  showFields: [Date, OrderId, CustomerName, MobileNumber, TotalBill]
  showCommentCount: true
  showFooter: true

Implement an EditOrderBook action to facilitate the modification and updating of existing order information within the OrderBook spreadsheet.

// on EditOrderBook click open KanbanLayout
ensure action EditOrderBook kind: spreadsheetEditor
  icon: "LibraryBooksRounded"
  spreadsheet: OrderBook
  layoutSpreadsheet: KanbanLayout

b. ShowOrderHistory

Implement a ShowOrderHistory action to display the update history for a specific order, as well as the history for all orders.

ensure action ShowOrderHistory kind: spreadsheetHistory 
  icon: "HistoryRounded" 
  spreadsheet: OrderBook

2. Group actions

Group all these actions into a MyVisits section for more convenient access.

ensure group MyVisits
  pinnedActions: [AddVisit, AddOrder, EditOrderBook, ReportVisit]
  pinnedActionSetMobile: [AddVisit, AddOrder]
  actionPermission: {
      'AddOrder': {
        'menuGroup': '1',
        'roles': [
          'Salesman'
        ]
      },
      'EditOrderBook': {
        'menuGroup': '2',
        'roles': [
          'Owner'
        ]
      },
      'ShowOrderHistory': {
        'menuGroup': '3',
        'roles': [
          'Owner'
        ]
      }
    }