📁 Showcase
Leave Sheet

Leave sheet

Backend

1. Variables

// picker variable for leave time

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

// picker variable for 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>"

// picker variable for approve 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

// this spreadsheet stores leave information of employee

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, Agent]
  updateRoleSet: [Owner]
  readRoleSet: [Owner]
  readAfterDurationVar: VarDurationAttendance

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

ensure field Employee
  disabled: true 
  roleDataSource: [Owner, Employee, Agent] 
  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" 
  required: true 
  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"

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

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. AddLeave

// employee can apply for leace

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

2. ViewLeaveSheet

// owner can view leaves for the current day

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

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

3. Group actions

// this group contains all the actions those can be performed for applying leave

ensure group MyPortal 
  pinnedActions: [AddAttendance,  ViewAttendanceSheet, CallAttendanceReport, AddAllowance, ViewAllowanceSheet, AddLeave, ViewLeaveSheet] 
  pinnedActionSetMobile: [AddAttendance, AddAllowance, AddLeave] 
  actionPermission: {
      'AddLeave': {
        'menuGroup': '1',
        'roles': [
          'Agent'
        ]
      },
      'ViewLeaveSheet': {
        'menuGroup': '2',
        'roles': [
          'Owner'
        ]
      }
    }