📁 Showcase
Allowance Sheet

Allowance sheet

Backend

1. Variables

// picker variable for vehicle type

ensure var VarSetOfTextVehicleType kind: setOfText 
  deploy: fixedOnDeploy 
  value: "<root>
      <node key='keyTwoWheeler'>Two wheeler</node>
      <node key='keyFourWheeler'>Four Wheeler</node>
    </root>"

// picker variable for tour type

ensure var VarSetOfTextTourType kind: setOfText 
  deploy: fixedOnDeploy 
  value: "<root>
      <node key='keyTourAndReturnToHqOnSameDay'>Tour and return to HQ on same day</node>
      <node key='keyNightHalt'>Night Halt</node>
    </root>"

// picker variable for expense status

ensure var VarSetOfTextExpenseStatus kind: setOfText 
  deploy: fixedOnDeploy 
  value: "<root>
      <node key='pending'>Pending</node>
      <node key='approved'>Approved</node>
      <node key='rejected'>Rejected</node>
    </root>"

2. AllowanceSheet

// this spreadsheet stores information of employees attendance

ensure spreadsheet: AllowanceSheet
  withFields: [Date, Employee, Terminated, Divider]
  ofTypes: [date, pickUser, bool, divider]
  removeRoleSet: [Owner]
  readRoleSet: [Owner]
  insertRoleSet: [Agent]
  updateRoleSet: [Agent]

ensure form EntityAllowance label: "Allowance" commentRoleSet:[Employee]
ensure section: Details label: "Expense  Details"
ensure field Date defaultValue: "now" label: "Date of submission"
ensure field Employee disabled: true roleDataSource: [$Self] defaultValue: $Self
ensure field Terminated
  permissionMatrix: {
      'defaultPermission': 'invisible'
    }
ensure field Divider dividerKind: thick

ensure section: Lodging label: "Lodging & Boarding"
ensure field TransparentDivider1 kind: divider color.value: transparent
ensure field StayStartDate kind: date
ensure field StayEndDate kind: date disabled: false
ensure field NumberOfDay kind: number disabled: true min: 0
ensure field LodgingAmount kind: decimal min: 0.0 max: 800.0 numberOfDigitsAfterPeriod: 2
ensure field TotalAmount01 kind: decimal label: "Total amount" disabled: true numberOfDigitsAfterPeriod: 2
ensure field HotelName kind: text 
ensure field HotelLocation kind: location 
ensure field LodgingReceiptCopy kind: image label: "Receipt copy" showLabel: true

ensure section: MotorCarRunning label: "Motor Car Running & Maintenance"
ensure field TransparentDivider2 kind: divider color.value: transparent
ensure field VehicleType kind: pickText sourceVar: VarSetOfTextVehicleType
ensure field StartKm kind: decimal min: 0.0
ensure field EndKm kind: decimal 
ensure field KmsTravelled kind: decimal disabled: true required: false
ensure field TotalAmount02 kind: decimal label: "Total amount" disabled: true helperText: "₹ 3 / Km"
ensure field MaintenanceCost kind: decimal disabled: false min: 0.0
ensure field Attachment kind: image showLabel: true

ensure section: DearnessAllowanceCharges label: "Dearness Allowance"
ensure field TransparentDivider3 kind: divider color.value: transparent
ensure field TourType kind: pickText sourceVar: VarSetOfTextTourType
ensure field NumberOfNight kind: number 
ensure field PlacesTravelled kind: text 
ensure field TotalAmount03 kind: decimal label: "Total amount" disabled: true
ensure field DearnessAllowanceReceiptCopy kind: image label: "Receipt copy" showLabel: true

ensure section: CourierXerox label: "Courier/Xerox/stationery"
ensure field TransparentDivider4 kind: divider color.value: transparent
ensure field Amount01 kind: decimal label: "Amount" max: 500.0
ensure field CourierXeroxReceiptCopy kind: image label: "Receipt copy" showLabel: true

ensure section: PublicTransportation label: "Public Transportation & Misc. Reimbursement"
ensure field TransparentDivider5 kind: divider color.value: transparent
ensure field Amount02 kind: decimal label: "Amount" max: 1000.0
ensure field PublicTransportationReceiptCopy kind: image label: "Receipt copy" showLabel: true

ensure section: Summary
ensure field Divider01 kind: divider 
ensure field GrandTotal kind: decimal disabled: true min: 0.0 numberOfDigitsAfterPeriod: 2
ensure field Remarks kind: paragraph 
ensure field ManagerStatus kind: pickText 
  permissionMatrix: {
      'defaultPermission': 'read',
      'Owner': 'write',
      '$Manager': 'write'
    } 
  sourceVar: VarSetOfTextExpenseStatus 
  defaultOptionId: "pending"
ensure field TransparentDivider6 kind: divider color.value: transparent

ensure layout Editor kind: editor 
  composites: [Details, Lodging, MotorCarRunning, DearnessAllowanceCharges, CourierXerox, PublicTransportation, Summary] 
  hideLabelComposites: [Details, Summary] 
  editorLayoutRenderingMode: stack

ensure form EntityAllowance asideDefaultLayout: Editor

1. Formula

// formulas for pre calculation before form submit

ensure form EntityAllowance

ensure formula KmsTravelled 
  assignToField: MotorCarRunning.KmsTravelled 
  formula: "let ans = ${f:EndKm} - ${f:StartKm};

ans
"

ensure formula Amount3 
  assignToField: MotorCarRunning.TotalAmount02 
  formula: "let ans = ${f:MotorCarRunning.KmsTravelled} * 3;

ans
"

ensure formula Amount7 
  assignToField: DearnessAllowanceCharges.TotalAmount03 
  formula: "let tourType = ${f:TourType};
let ans;

if (tourType == 'keyTourAndReturnToHqOnSameDay'){
    ans = 125;
} else {
    ans = 250 * ${f:NumberOfNight};
}

ans
"

ensure formula TotalAmount01 
  assignToField: Lodging.TotalAmount01 
  formula: "${f:NumberOfDay}*${f:LodgingAmount}"

ensure formula NumberOfDay 
  assignToField: Lodging.NumberOfDay 
  formula: "const fromDate = ${f:StayStartDate}; 
    const toDate = ${f:StayEndDate}; 

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

        const diffInMs = date2 - date1;
        
        const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
        
        diffInDays
    }else{
        0
    }"

ensure formula GrandTotal 
  assignToField: Summary.GrandTotal 
  formula: "${f:TotalAmount01} + ${f:TotalAmount02} + ${f:TotalAmount03} + ${f:Amount01} + ${f:Amount02}"

Frontend

1. AddAllowance

// this action will insert allowance data to spreadsheet

ensure action AddAllowance kind: rowInsert 
  icon: "AddCircleOutlineRounded" 
  spreadsheet: AllowanceSheet 
  sendMessageToInbox: true

2. ViewAllowanceSheet

// this action will allow user to view 

ensure spreadsheet AllowanceSheet 

ensure layoutSpreadsheet TableLayout kind: table 
  showComps: [Details.Date, Details.Employee, Summary.GrandTotal, Summary.Remarks, Summary.ManagerStatus] 

ensure action ViewAllowanceSheet kind: spreadsheetEditor 
  icon: "ViewListRounded" 
  spreadsheet: AllowanceSheet 
  layoutSpreadsheet: TableLayout

3. Group actions

// this group has all the actions those can be performed on allownace

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