load( local!headerCells: { a!gridLayoutHeaderCell( label: "Day" ), a!gridLayoutHeaderCell( label: "Start", align: "CENTER" ), a!gridLayoutHeaderCell( label: "Finish", align: "CENTER" ), a!gridLayoutHeaderCell( label: "Total", align: "CENTER" ), a!gridLayoutHeaderCell( label: "Lunch", align: "CENTER" ), a!gridLayoutHeaderCell( label: "Credits", align: "CENTER" ), a!gridLayoutHeaderCell( label: "Holiday and other paid leave", align: "CENTER" ), a!gridLayoutHeaderCell( label: "Net Hours", align: "CENTER" ) }, local!columnConfigs: { a!gridLayoutColumnConfig( weight: 3 ), a!gridLayoutColumnConfig( weight: 1 ), a!gridLayoutColumnConfig( weight: 1 ), a!gridLayoutColumnConfig( weight: 1 ), a!gridLayoutColumnConfig( weight: 1 ), a!gridLayoutColumnConfig( weight: 1 ), a!gridLayoutColumnConfig( weight: 8 ), a!gridLayoutColumnConfig( weight: 1 ), a!gridLayoutColumnConfig( width: "ICON" ) }, local!pagingInfo: a!pagingInfo( startIndex: 1, batchSize: - 1 ), local!defaultTime: "00:00", local!defaultStartTime: "09:00", local!defaultFinishTime: "17:00", local!defaultLunch: "00:30", local!employeeId: user( loggedInUser(), "customField1" ), local!endOfWeekDate: rule!Flexi_Time_getEndOfWeekDate( today() ), /*Get all dates for selected week */ local!selectedDateRange: rule!Flexi_Time_getWeekDateArray( local!endOfWeekDate ), /*Get Timesheet Id */ local!timesheetId: rule!Flexi_Time_fetchTimesheetForEmployeeIdAndPeriodDates( employeeId: local!employeeId, startDate: rule!Flexi_Time_getTimesheetPeriodDates( local!selectedDateRange ).startDate, endDate: rule!Flexi_Time_getTimesheetPeriodDates( local!selectedDateRange ).endDate ).timesheetId, /*Get Workweek Id */ local!workweekId: with( local!data: rule!Flexi_Time_getCombinedTimesheetField( local!employeeId, local!selectedDateRange, "workweekId" ), if( rule!APN_isEmpty( local!data ), null, local!data.workweekId ) ), /*Determine if a timesheet needs to be created or if one already exists for current period */ local!timesheetIsRequired: rule!Flexi_Time_requiresTimesheet( employeeId: local!employeeId, dates: local!selectedDateRange ), /*Determine if a workweek needs to be created */ local!workweekIsRequired: rule!APN_isEmpty( local!workweekId ), /*Get all workdays that exist in DB for selected week, otherwise build empty/default ones */ local!workdays: a!forEach( items: local!selectedDateRange, expression: with( local!workday: rule!Flexi_Time_getEmployeeWorkday( fv!item, local!employeeId ), if( rule!APN_isEmpty( local!workday.workdayId ), rule!Flexi_Time_buildEmptyWorkdayCDT( workweekId: local!workweekId, date: fv!item, startTime: local!defaultStartTime, finishTime: local!defaultFinishTime, lunch: local!defaultLunch ), local!workday ) ) ), a!formLayout( contents: { a!boxLayout( label: "Summary", contents: {}, style: "INFO", marginBelow: "STANDARD" ), a!boxLayout( label: "Weekly Timesheets", contents: { a!sideBySideLayout( items: { a!sideBySideItem( item: a!richTextDisplayField( value: a!richTextImage( image: a!documentImage( document: cons!FLEXI_TIME_LEFTARROWICON, /*alternate appian icon: */ /*document: a!iconIndicator("MOVE_LEFT"), */ altText: "N/A", caption: "View previous week", link: a!dynamicLink( saveInto: { a!save( local!endOfWeekDate, local!endOfWeekDate - 7 ), a!save( local!selectedDateRange, rule!Flexi_Time_getWeekDateArray( local!endOfWeekDate ) ), a!save( local!timesheetId, rule!Flexi_Time_fetchTimesheetForEmployeeIdAndPeriodDates( employeeId: local!employeeId, startDate: rule!Flexi_Time_getTimesheetPeriodDates( local!selectedDateRange ).startDate, endDate: rule!Flexi_Time_getTimesheetPeriodDates( local!selectedDateRange ).endDate ).timesheetId ), a!save( local!workweekId, with( local!data: rule!Flexi_Time_getCombinedTimesheetField( local!employeeId, local!selectedDateRange, "workweekId" ), if( rule!APN_isEmpty( local!data ), null, local!data.workweekId ) ) ), a!save( local!timesheetIsRequired, rule!Flexi_Time_requiresTimesheet( employeeId: local!employeeId, dates: local!selectedDateRange ) ), a!save( local!workweekIsRequired, rule!APN_isEmpty( local!workweekId ) ), a!forEach( local!workdays, a!save( fv!item, with( local!workday: rule!Flexi_Time_getEmployeeWorkday( local!selectedDateRange[fv!index], local!employeeId ), if( rule!APN_isEmpty( local!workday.workdayId ), rule!Flexi_Time_buildEmptyWorkdayCDT( workweekId: local!workweekId, date: local!selectedDateRange[fv!index], startTime: local!defaultStartTime, finishTime: local!defaultFinishTime, lunch: local!defaultLunch ), local!workday ) ) ) ) } ) ) ), align: "LEFT" ) ), a!sideBySideItem( item: a!dateField( label: "Week Ending", labelPosition: "ADJACENT", value: local!endOfWeekDate, saveInto: { a!save( local!endOfWeekDate, rule!Flexi_Time_getEndOfWeekDate( save!value ) ), a!save( local!selectedDateRange, rule!Flexi_Time_getWeekDateArray( local!endOfWeekDate ) ), a!save( local!timesheetId, rule!Flexi_Time_fetchTimesheetForEmployeeIdAndPeriodDates( employeeId: local!employeeId, startDate: rule!Flexi_Time_getTimesheetPeriodDates( local!selectedDateRange ).startDate, endDate: rule!Flexi_Time_getTimesheetPeriodDates( local!selectedDateRange ).endDate ).timesheetId ), a!save( local!workweekId, with( local!data: rule!Flexi_Time_getCombinedTimesheetField( local!employeeId, local!selectedDateRange, "workweekId" ), if( rule!APN_isEmpty( local!data ), null, local!data.workweekId ) ) ), a!save( local!timesheetIsRequired, rule!Flexi_Time_requiresTimesheet( employeeId: local!employeeId, dates: local!selectedDateRange ) ), a!save( local!workweekIsRequired, rule!APN_isEmpty( local!workweekId ) ), a!forEach( local!workdays, a!save( fv!item, with( local!workday: rule!Flexi_Time_getEmployeeWorkday( local!selectedDateRange[fv!index], local!employeeId ), if( rule!APN_isEmpty( local!workday.workdayId ), rule!Flexi_Time_buildEmptyWorkdayCDT( workweekId: local!workweekId, date: local!selectedDateRange[fv!index], startTime: local!defaultStartTime, finishTime: local!defaultFinishTime, lunch: local!defaultLunch ), local!workday ) ) ) ) }, align: "CENTER" ) ), a!sideBySideItem( item: a!richTextDisplayField( value: a!richTextImage( image: a!documentImage( document: cons!FLEXI_TIME_RIGHTARROWICON, /*alternate appian icon: */ /*document: a!iconIndicator("MOVE_RIGHT"), */ altText: "N/A", caption: "View next week", link: a!dynamicLink( saveInto: { a!save( local!endOfWeekDate, local!endOfWeekDate + 7 ), a!save( local!selectedDateRange, rule!Flexi_Time_getWeekDateArray( local!endOfWeekDate ) ), a!save( local!timesheetId, rule!Flexi_Time_fetchTimesheetForEmployeeIdAndPeriodDates( employeeId: local!employeeId, startDate: rule!Flexi_Time_getTimesheetPeriodDates( local!selectedDateRange ).startDate, endDate: rule!Flexi_Time_getTimesheetPeriodDates( local!selectedDateRange ).endDate ).timesheetId ), a!save( local!workweekId, with( local!data: rule!Flexi_Time_getCombinedTimesheetField( local!employeeId, local!selectedDateRange, "workweekId" ), if( rule!APN_isEmpty( local!data ), null, local!data.workweekId ) ) ), a!save( local!timesheetIsRequired, rule!Flexi_Time_requiresTimesheet( employeeId: local!employeeId, dates: local!selectedDateRange ) ), a!save( local!workweekIsRequired, rule!APN_isEmpty( local!workweekId ) ), a!forEach( local!workdays, a!save( fv!item, with( local!workday: rule!Flexi_Time_getEmployeeWorkday( local!selectedDateRange[fv!index], local!employeeId ), if( rule!APN_isEmpty( local!workday.workdayId ), rule!Flexi_Time_buildEmptyWorkdayCDT( workweekId: local!workweekId, date: local!selectedDateRange[fv!index], startTime: local!defaultStartTime, finishTime: local!defaultFinishTime, lunch: local!defaultLunch ), local!workday ) ) ) ) } ) ) ), align: "RIGHT" ) ) }, alignVertical: "MIDDLE" ), a!gridLayout( headerCells: append( local!headerCells, a!gridLayoutHeaderCell( label: "" ) ), columnConfigs: local!columnConfigs, rows: { a!forEach( local!workdays, rule!Flexi_Time_TimesheetGridRow( dayOfWeek: rule!Flexi_Time_displayDayOfWeek( local!selectedDateRange[fv!index] ), startTime: fv!item.startTime, finishTime: fv!item.finishTime, totalTime: fv!item.totalHours, lunchTime: fv!item.lunch, credits: fv!item.credits, leave: fv!item.paidLeave, netHours: fv!item.netHours ) ) } ) }, style: "INFO", marginBelow: "STANDARD" ), a!buttonLayout( primaryButtons: { a!buttonWidget( label: "SAVE WEEK", style: "PRIMARY", saveInto: { a!save( ri!workdays, local!workdays ), a!save( ri!workweekIsRequired, local!workweekIsRequired ), a!save( ri!timesheetIsRequired, local!timesheetIsRequired ), a!save( ri!workweekId, local!workweekId ), a!save( ri!timesheetId, local!timesheetId ), a!save( ri!selectedDateRange, local!selectedDateRange ), a!save( ri!employeeId, local!employeeId ) }, submit: true ) } ) } ) )