📁 Showcase
Leave Sheet

Leave sheet

Backend

1. Variables

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

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>"

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

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

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

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'
    }"

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
    }"

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

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

4. Visibility rules

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

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

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

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

b. EditLeaveSheet

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

Final grouping of actions. Merging the grouped actions from Allowance Sheet.

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