📁 Showcase
Leave Sheet

Leave sheet

Backend

1. Variables

Create a VarSetOfTextLeaveTime variable to represent and display the classification of time.

ensure var VarSetOfTextLeaveTime kind: setOfText
  deploy: fixedOnDeploy
  value: "<root>
      <node key='keyFirstHalf'>First Half</node>
      <node key='keySecondHalf'>Second Half</node>
    </root>"

Create a VarSetOfTextTypeOfLeave variable to represent and display the classification of a leave type.

ensure var VarSetOfTextTypeOfLeave kind: setOfText
  deploy: fixedOnDeploy
  value: "<root>
      <node key='keyPrivilegeLeave'>Privilege Leave</node>
      <node key='keyCasualLeave'>Casual Leave</node>
      <node key='keySickLeave'>Sick Leave</node>
    </root>"

Create a VarSetOfTextApprovalStatus variable to represent and display the classification of an approval status.

ensure var VarSetOfTextApprovalStatus kind: setOfText
  deploy: fixedOnDeploy
  value: "<root>
      <node color='secondary' key='keyPending'>Pending</node>
      <node color='success' key='keyApproved'>Approved</node>
      <node color='deepOrange' key='keyRejected' shade='s500'>Rejected</node>
    </root>"

2. LeaveSheet

Create a LeaveSheet spreadsheet to track and store leave data of all salesmen.

ensure spreadsheet: LeaveSheet
  withFields: ["Employee", "HalfDay", "LeaveTime", "FromDate", "ToDate", "NumberOfDays", 
      "NumberOfHolidays", "TotalLeaveDays", "TypeOfLeave*", "LeaveReason", "MedicalProof", 
      "Divider", "EmployeeRowId", "Error", "ApprovalStatus"]
  ofTypes: [pickUser, bool, pickText, date, date, decimal, 
      number, number, pickText, paragraph, document, 
      divider, rowId, error, pickText]
  removeRoleSet: [Owner]
  insertRoleSet: [Owner, Employee, Salesman]
  updateRoleSet: [Owner]
  readRoleSet: [Owner]
  readAfterDurationVar: VarDurationAttendance

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

ensure form EntityLeave
 label: "Leave Application"
ensure section: Details

ensure field Employee
  disabled: true
  roleDataSource: [Owner, Employee, Salesman]
  defaultValue: $Self
ensure field HalfDay
  showAsCheckbox: true
ensure field LeaveTime
  showAs: radioButtonVertical
  sourceVar: VarSetOfTextLeaveTime
ensure field FromDate
  disabled: false
  defaultValue: "now"
ensure field ToDate
  disabled: false
  defaultValue: "now"
ensure field NumberOfDays
  disabled: true
  numberOfDigitsAfterPeriod: 1
ensure field NumberOfHolidays
  label: "Holidays Between Leave"
  disabled: false
  permissionMatrix: {
      'defaultPermission': 'invisible'
    }
ensure field TotalLeaveDays
  disabled: true
  permissionMatrix: {
      'defaultPermission': 'invisible'
    }
ensure field TypeOfLeave
  label: "Type of Leave"
  sourceVar: VarSetOfTextTypeOfLeave
ensure field LeaveReason kind: paragraph
ensure field MedicalProof kind: document
  fileTypeSet: ["any"]
ensure field Divider
ensure field EmployeeRowId
  permissionMatrix: {
      'defaultPermission': 'invisible'
    }
ensure field Error
  showCloseButton: false
ensure field ApprovalStatus
  label: "Approval Status"
  permissionMatrix: {
      'defaultPermission': 'read',
      'Owner': 'write'
    }
  sourceVar: VarSetOfTextApprovalStatus
  defaultOptionId: "keyPending"

3. Formulas

Set a formula to set the Error.

ensure formula Error
  assignToField: Details.Error
  formula: "let NumberOfDays = ${f:NumberOfDays};
    let TypeofLeave = ${f:TypeOfLeave.optionId};
    let MedicalProof = ${f:MedicalProof.value.fileName}

    if(TypeofLeave=='keySickLeave' && NumberOfDays>2) {
        'Please upload medical proof'
    }
    else if(TypeofLeave=='keyCasualLeave' && NumberOfDays>4) {
        'Cannot take more than 4 casual leave at a time'
    }"

Set a formula to calculate NumberOfDays which represents number of leaves.

ensure formula NumberOfDays
  assignToField: Details.NumberOfDays
  formula: "const fromDate = ${f:FromDate};
    const toDate = ${f:ToDate};
    const halfDay = ${f:HalfDay};

    if(fromDate && toDate) {
        const date1 = new Date(fromDate);
        const date2 = new Date(toDate);

        const diffInMs = date2 - date1;

        const diffInDays = diffInMs / (1000 * 60 * 60 * 24);

        (halfDay==true) ? 0.5 : diffInDays+1
    } else {
        0
    }"

Set a formula to calculate TotalLeaveDays.

ensure formula TotalDays
  assignToField: Details.TotalLeaveDays
  formula: "const numberOfDays = ${f:NumberOfDays};
    const numberOfHolidays = ${f:NumberOfHolidays};

    if(numberOfDays>0) {
        numberOfDays - numberOfHolidays
    }
    "

4. Visibility rules

Apply a HalfDay rule to the EntityLeave form to toggle the visibility of HalfDay related fields, making them either visible or concealed based on the rule.

ensure visibilityRule HalfDay
  condition: "<root>
      <stmt>Details.HalfDay == ${d:HalfDay.true}</stmt>
    </root>"
ensure actionMapIfTrue Disable
  comp: ToDate
  visibilityAction: disable
  visibilityActionOn: field
ensure actionMapIfTrue Show
  comp: LeaveTime
  visibilityAction: visible
  visibilityActionOn: field
ensure actionMapIfFalse Enable
  comp: ToDate
  visibilityAction: enable
  visibilityActionOn: field
ensure actionMapIfFalse Invisible
  comp: LeaveTime
  visibilityAction: invisible
  visibilityActionOn: field

Apply a DisableForm rule to the EntityLeave form to toggle the visibility of DisableForm related fields, making them either visible or concealed based on the rule.

ensure visibilityRule DisableForm
  condition: "<root>
      <stmt>ApprovalStatus == ${d:ApprovalStatus.keyApproved}</stmt>
    </root>"
ensure actionMapIfTrue Disable
  comp: Details
  visibilityAction: disable
  visibilityActionOn: component
ensure actionMapIfFalse Enable
  comp: Details
  visibilityAction: enable
  visibilityActionOn: component

Apply a ShowMedicalProof rule to the EntityLeave form to toggle the visibility of ShowMedicalProof related fields, making them either visible or concealed based on the rule.

ensure visibilityRule ShowMedicalProof
  condition: "<root>
      <and>
        <stmt>Error has value</stmt>
        <stmt>TypeOfLeave == ${d:TypeOfLeave.keySickLeave}</stmt>
      </and>
    </root>"
ensure actionMapIfTrue Show
  comp: MedicalProof
  visibilityAction: visible
  visibilityActionOn: field
ensure actionMapIfFalse Hide
  comp: MedicalProof
  visibilityAction: invisible
  visibilityActionOn: field

Frontend

1. Actions

a. AddLeave

Implement an AddLeave action to insert leave details into the LeaveSheet spreadsheet.

ensure action AddLeave kind: rowInsert
  icon: "AddCircleOutlineRounded"
  spreadsheet: LeaveSheet
  sendMessageToInbox: true

b. EditLeaveSheet

Implement an EditLeaveSheet action to facilitate the modification and updating of existing leave details within the LeaveSheet spreadsheet.

ensure spreadsheet LeaveSheet
ensure layoutSpreadsheet TableLayout kind: table
  showComps: [
      Employee,
      FromDate,
      ToDate,
      NumberOfDays,
      TypeOfLeave,
      LeaveReason,
      ApprovalStatus
    ]

ensure action EditLeaveSheet kind: spreadsheetEditor
  icon: "ViewListRounded"
  spreadsheet: LeaveSheet
  layoutSpreadsheet: TableLayout

3. Group actions

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

ensure group MyPortal
  pinnedActions: [AddAttendance, ReportAttendance, AddAllowance, AddLeave]
  pinnedActionSetMobile: [AddAttendance]
  actionPermission: {
      'AddLeave': {
        'menuGroup': '1',
        'roles': [
          'Salesman'
        ]
      },
      'EditLeaveSheet': {
        'menuGroup': '2',
        'roles': [
          'Owner'
        ]
      }
    }