Package com.simplicite.util
Class Timesheet
- java.lang.Object
-
- com.simplicite.util.Timesheet
-
- All Implemented Interfaces:
java.io.Serializable
public class Timesheet extends java.lang.Object implements java.io.Serializable
Timesheet instance- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Timesheet.GanttBlock
Assignment element as a floating blockclass
Timesheet.GanttNode
Node of resource with blocksstatic class
Timesheet.Period
Timesheet period = day or week or monthstatic class
Timesheet.TimesheetDefinition
Timesheet definitionclass
Timesheet.TimesheetLine
Timesheet line between 2 resources
-
Field Summary
Fields Modifier and Type Field Description static int
GANTT_FORWARD
Add a link to Gantt view in the timesheet viewstatic int
GANTT_HIDDEN
Hide Gantt access in the timesheet viewstatic int
GANTT_INLINED
Inline Gantt display in the timesheet viewstatic int
PERIOD_DAY_SIZE
Minimum size of period in daysstatic int
PERIOD_MONTH_SIZE
Minimum size of period in monthsstatic int
PERIOD_WEEK_SIZE
Minimum size of period in weeksstatic char
TYPE_DAY
Manage inputs by daysstatic char
TYPE_MONTH
Manage inputs by monthsstatic char
TYPE_WEEK
Manage inputs by weeks
-
Constructor Summary
Constructors Constructor Description Timesheet(Timesheet.TimesheetDefinition ts)
Timesheet instance
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addInputField(java.lang.String name)
Add an input field in the timesheet.void
buildCurrentPeriod(java.lang.String begin, java.lang.String end)
Build the current period to displayTimesheet.GanttNode
buildGanttData(ObjectDB assign, org.json.JSONObject params)
Build tree with assignment blocksjava.util.List<Timesheet.Period>
buildPeriod(java.lang.String begin, java.lang.String end)
Return the periods between 2 datesboolean
canShiftField(int fieldIndex)
Shift the field charges when its GanttBlock moves (from copiable property of field) ?java.lang.String
convertDateToKey(java.lang.String date)
Convert a date to its keydouble[]
convertInputToMonthCharges(java.lang.String encodedInput)
Convert the encoded input into 12 months of charges (TYPE_DAYS and TYPE_WEEK only)java.lang.String
convertKeyToDate(java.lang.String key)
Convert a key to its datevoid
enableGanttDragX(boolean b)
void
enableGanttDragY(boolean b)
void
enableGanttResizable(boolean b)
void
fitPeriodToAssignments(ObjectDB assign, org.json.JSONObject params)
Period including all assignments periodsvoid
fitPeriodToInputs()
Change the current period to include all timesheet inputs for the current resourcesjava.lang.String
ganttDataToJson(Timesheet.GanttNode root)
Serialize to JSON the GANTTjava.lang.String
getCurrentColor(java.lang.String label)
Get the color of a resourceObjectField
getCurrentEndDate()
Current end date to displayjava.util.List<Timesheet.TimesheetLine>
getCurrentLines()
Current timesheet linesjava.util.List<Timesheet.Period>
getCurrentPeriod()
Current period to displayjava.lang.String
getCurrentResource1()
Current parent resource 1 (null when 2 is set)java.lang.String
getCurrentResource2()
Current parent resource 2 (null when 1 is set)ObjectField
getCurrentStartDate()
Current first date to displayObjectField
getFieldBeginDate()
Get the begin date fieldObjectField
getFieldEndDate()
Get the end date fieldObjectField
getFieldResource1()
Get the resource1 fieldObjectField
getFieldResource2()
Get the resource2 fieldObjectField
getFieldStatus()
Get the timesheet status fieldObjectField
getFieldWorkload()
Get the workload fieldjava.lang.String
getId()
Timesheet idObjectField
getInputField(java.lang.String name)
Input field by namejava.util.List<ObjectField>
getInputFields()
Input fields for each linejava.lang.String[]
getInputMinMaxDates()
Get the period including all timesheet inputs for the current resourcesjava.lang.String
getName()
Timesheet nameObjectDB
getObjectAssign()
Get the assignment objectObjectDB
getObjectResource1()
Get instance of resource 1ObjectDB
getObjectResource2()
Get instance of resource 2ObjectDB
getObjectTimesheet()
Get the timesheet object to store all inputsjava.util.List<java.lang.String[]>
getResources(boolean resetFilter, java.lang.String resourceId1, java.lang.String resourceId2, java.lang.String beginDate, java.lang.String endDate)
Retrieve resources from the otherdouble
getResourceWorkloadFactor(java.lang.String name)
java.util.Map<java.lang.String,Timesheet.TimesheetLine>
getTimesheet(ObjectDB assign, ObjectField r1, ObjectField r2, java.lang.String resId1, java.lang.String resId2, ObjectField assignFromDate, ObjectField assignToDate, boolean resetFilter, boolean loadLabel, boolean inPeriod, java.lang.String fromKey, java.lang.String toKey, ObjectField wl)
char
getType()
get the timesheet type : TYPE_DAY, TYPE_WEEK or TYPE_MONTHvoid
init(Grant g)
Instance initializationboolean
isBackwardInputAllowed()
Allows change for previous period?boolean
isChartEnabled()
Use resource chart ?boolean
isChartVisible()
Is resource chart visible on UI?boolean
isFloatingDate()
Floating timesheet = starts period on any dayboolean
isGanttDragXEnabled()
Is the horizontal drag allowed ?boolean
isGanttDragYEnabled()
Is the vertical drag allowed ?boolean
isGanttEnabled()
Is the GANTT chart enabled ?boolean
isGanttResizable()
Is the block resizing allowed ?boolean
isGanttVisible()
Is the GANTT chart visible ?boolean
isResourceAndInputSwapped()
Swap display of resource and input fields?boolean
isTimesheetEnabled()
Use timesheet input form ?java.util.Map<java.lang.String,Timesheet.TimesheetLine>
loadTimesheet(boolean resetFilter, boolean inPeriod)
Load timesheet from DBjava.util.List<java.lang.String>
merge(ObjectDB assign, java.lang.String assignId, java.lang.String resId1, java.lang.String resId2)
Merge assignments and related timesheetsjava.util.List<java.lang.String>
reassign(ObjectDB assign, java.lang.String assignIdFrom, java.lang.String assignIdTo, java.lang.String resIdTo, java.lang.String resId1, java.lang.String resId2, double factor, java.lang.String begin, java.lang.String end)
Transfers assignment charge between 2 resourcesjava.util.List<java.lang.String>
save()
Save the current timesheetjava.util.List<java.lang.String>
save(java.util.List<Timesheet.TimesheetLine> lines, java.util.List<Timesheet.Period> periods)
Save a timesheet.java.util.List<java.lang.String>
save(org.json.JSONObject data)
Save the current timesheet with incoming UI datajava.lang.String
service(ObjectDB obj, org.json.JSONObject params)
Ajax servicevoid
setBackward(boolean b)
void
setChartEnabled(boolean b)
void
setChartVisible(boolean b)
void
setCurrentColor(java.lang.String label, java.lang.String color)
Assign a color to a resourcevoid
setCurrentLines(java.util.List<Timesheet.TimesheetLine> lines)
void
setCurrentPeriod(java.util.List<Timesheet.Period> p)
void
setCurrentResource1(java.lang.String id)
void
setCurrentResource2(java.lang.String id)
void
setFloatingDate(boolean f)
void
setGanttEnabled(boolean b, ObjectCore obj)
Enable Gantt diagram (only if timesheet has dates)void
setGanttInTimesheet(int option)
void
setGanttVisible(boolean b)
void
setResourceWorkloadFactor(java.lang.String name, double factor)
Factor to get charge in days of input value on the resource/gantt chart.void
setShiftable(int fieldIndex, boolean shift)
void
setTimesheetEnabled(boolean b, ObjectCore obj)
Enable timesheet for the objectvoid
setType(char type)
java.util.List<java.lang.String>
shiftTimesheet(ObjectDB assign, java.lang.String assignId, java.lang.String resId1, java.lang.String resId2, java.lang.String oldBeginDate, java.lang.String newBeginDate, java.lang.String oldEndDate, java.lang.String newEndDate)
Shifts the timesheet charges of one assignmentint
showGanttInTimesheet()
Is GANTT accessible in the timesheet view ? GANTT_HIDDEN, GANTT_INLINED or GANTT_FORWARDvoid
swapResourceAndInput(boolean b)
java.lang.String
toJSON()
Timesheet meta and current datastatic java.util.List<Timesheet.TimesheetLine>
toList(java.util.Map<java.lang.String,Timesheet.TimesheetLine> lines, boolean sort)
Sort lines by resource labelsjava.lang.String
toString()
-
-
-
Field Detail
-
TYPE_DAY
public static final char TYPE_DAY
Manage inputs by days- See Also:
- Constant Field Values
-
TYPE_WEEK
public static final char TYPE_WEEK
Manage inputs by weeks- See Also:
- Constant Field Values
-
TYPE_MONTH
public static final char TYPE_MONTH
Manage inputs by months- See Also:
- Constant Field Values
-
GANTT_HIDDEN
public static final int GANTT_HIDDEN
Hide Gantt access in the timesheet view- See Also:
- Constant Field Values
-
GANTT_INLINED
public static final int GANTT_INLINED
Inline Gantt display in the timesheet view- See Also:
- Constant Field Values
-
GANTT_FORWARD
public static final int GANTT_FORWARD
Add a link to Gantt view in the timesheet view- See Also:
- Constant Field Values
-
PERIOD_DAY_SIZE
public static final int PERIOD_DAY_SIZE
Minimum size of period in days- See Also:
- Constant Field Values
-
PERIOD_WEEK_SIZE
public static final int PERIOD_WEEK_SIZE
Minimum size of period in weeks- See Also:
- Constant Field Values
-
PERIOD_MONTH_SIZE
public static final int PERIOD_MONTH_SIZE
Minimum size of period in months- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Timesheet
public Timesheet(Timesheet.TimesheetDefinition ts)
Timesheet instance- Parameters:
ts
- Definition to clone
-
-
Method Detail
-
init
public void init(Grant g)
Instance initialization- Parameters:
g
- User rights
-
getObjectResource1
public ObjectDB getObjectResource1()
Get instance of resource 1- Returns:
- tsheet instance
-
getObjectResource2
public ObjectDB getObjectResource2()
Get instance of resource 2- Returns:
- tsheet instance
-
getId
public java.lang.String getId()
Timesheet id
-
getName
public java.lang.String getName()
Timesheet name
-
getObjectAssign
public ObjectDB getObjectAssign()
Get the assignment object
-
getObjectTimesheet
public ObjectDB getObjectTimesheet()
Get the timesheet object to store all inputs
-
getFieldStatus
public ObjectField getFieldStatus()
Get the timesheet status field
-
getFieldResource1
public ObjectField getFieldResource1()
Get the resource1 field
-
getFieldResource2
public ObjectField getFieldResource2()
Get the resource2 field
-
getFieldWorkload
public ObjectField getFieldWorkload()
Get the workload field
-
getFieldBeginDate
public ObjectField getFieldBeginDate()
Get the begin date field
-
getFieldEndDate
public ObjectField getFieldEndDate()
Get the end date field
-
getType
public char getType()
get the timesheet type : TYPE_DAY, TYPE_WEEK or TYPE_MONTH
-
setType
public void setType(char type)
-
isFloatingDate
public boolean isFloatingDate()
Floating timesheet = starts period on any day
-
setFloatingDate
public void setFloatingDate(boolean f)
-
isBackwardInputAllowed
public boolean isBackwardInputAllowed()
Allows change for previous period?
-
setBackward
public void setBackward(boolean b)
-
isResourceAndInputSwapped
public boolean isResourceAndInputSwapped()
Swap display of resource and input fields?
-
swapResourceAndInput
public void swapResourceAndInput(boolean b)
-
isTimesheetEnabled
public boolean isTimesheetEnabled()
Use timesheet input form ?
-
setTimesheetEnabled
public void setTimesheetEnabled(boolean b, ObjectCore obj)
Enable timesheet for the object- Parameters:
b
- Booleanobj
- Optional object to generate UI action
-
isChartEnabled
public boolean isChartEnabled()
Use resource chart ?
-
setChartEnabled
public void setChartEnabled(boolean b)
-
isChartVisible
public boolean isChartVisible()
Is resource chart visible on UI?
-
setChartVisible
public void setChartVisible(boolean b)
-
showGanttInTimesheet
public int showGanttInTimesheet()
Is GANTT accessible in the timesheet view ? GANTT_HIDDEN, GANTT_INLINED or GANTT_FORWARD
-
setGanttInTimesheet
public void setGanttInTimesheet(int option)
-
getInputFields
public java.util.List<ObjectField> getInputFields()
Input fields for each line
-
getInputField
public ObjectField getInputField(java.lang.String name)
Input field by name
-
addInputField
public void addInputField(java.lang.String name)
Add an input field in the timesheet. Default value is used as a input limit. Calculated expression is used as a charge in day factor. Copiable property is used as shiftable in GANTT view.- Parameters:
name
- Field name
-
canShiftField
public boolean canShiftField(int fieldIndex)
Shift the field charges when its GanttBlock moves (from copiable property of field) ?
-
setShiftable
public void setShiftable(int fieldIndex, boolean shift)
-
setResourceWorkloadFactor
public void setResourceWorkloadFactor(java.lang.String name, double factor)
Factor to get charge in days of input value on the resource/gantt chart. Default value is 1 when no calculated expression is set.- Parameters:
name
- The name of the input fieldfactor
- Factor value to convert the input charge in days
-
getResourceWorkloadFactor
public double getResourceWorkloadFactor(java.lang.String name)
-
getCurrentResource1
public java.lang.String getCurrentResource1()
Current parent resource 1 (null when 2 is set)
-
setCurrentResource1
public void setCurrentResource1(java.lang.String id)
-
getCurrentResource2
public java.lang.String getCurrentResource2()
Current parent resource 2 (null when 1 is set)
-
setCurrentResource2
public void setCurrentResource2(java.lang.String id)
-
getCurrentLines
public java.util.List<Timesheet.TimesheetLine> getCurrentLines()
Current timesheet lines
-
setCurrentLines
public void setCurrentLines(java.util.List<Timesheet.TimesheetLine> lines)
-
getCurrentPeriod
public java.util.List<Timesheet.Period> getCurrentPeriod()
Current period to display
-
setCurrentPeriod
public void setCurrentPeriod(java.util.List<Timesheet.Period> p)
-
getCurrentStartDate
public ObjectField getCurrentStartDate()
Current first date to display
-
getCurrentEndDate
public ObjectField getCurrentEndDate()
Current end date to display
-
buildCurrentPeriod
public void buildCurrentPeriod(java.lang.String begin, java.lang.String end)
Build the current period to display- Parameters:
begin
- Optional start date yyyy-MM-dd (default is today)end
- Optional end date yyyy-MM-dd
-
buildPeriod
public java.util.List<Timesheet.Period> buildPeriod(java.lang.String begin, java.lang.String end)
Return the periods between 2 dates- Parameters:
begin
- Begin dateend
- End date- Returns:
- List of periods
-
getCurrentColor
public java.lang.String getCurrentColor(java.lang.String label)
Get the color of a resource- Parameters:
label
- Any resource label- Returns:
- color #RRGGBB
-
setCurrentColor
public void setCurrentColor(java.lang.String label, java.lang.String color)
Assign a color to a resource- Parameters:
label
- Any resource labelcolor
- #RRGGBB
-
fitPeriodToAssignments
public void fitPeriodToAssignments(ObjectDB assign, org.json.JSONObject params)
Period including all assignments periods
-
getInputMinMaxDates
public java.lang.String[] getInputMinMaxDates()
Get the period including all timesheet inputs for the current resources- Returns:
- 2 dates
-
fitPeriodToInputs
public void fitPeriodToInputs()
Change the current period to include all timesheet inputs for the current resources
-
getResources
public java.util.List<java.lang.String[]> getResources(boolean resetFilter, java.lang.String resourceId1, java.lang.String resourceId2, java.lang.String beginDate, java.lang.String endDate)
Retrieve resources from the other- Parameters:
resourceId1
- optional resource idresourceId2
- optional resource idbeginDate
- start dateendDate
- end date- Returns:
- List of resource1 records if resource2 is set, and vice versa
-
loadTimesheet
public java.util.Map<java.lang.String,Timesheet.TimesheetLine> loadTimesheet(boolean resetFilter, boolean inPeriod)
Load timesheet from DB- Parameters:
resetFilter
- true to ignore UI filtersinPeriod
- true to find timesheets in current period- Returns:
- timesheet lines
-
getTimesheet
public java.util.Map<java.lang.String,Timesheet.TimesheetLine> getTimesheet(ObjectDB assign, ObjectField r1, ObjectField r2, java.lang.String resId1, java.lang.String resId2, ObjectField assignFromDate, ObjectField assignToDate, boolean resetFilter, boolean loadLabel, boolean inPeriod, java.lang.String fromKey, java.lang.String toKey, ObjectField wl)
-
save
public java.util.List<java.lang.String> save(java.util.List<Timesheet.TimesheetLine> lines, java.util.List<Timesheet.Period> periods)
Save a timesheet. Calls first the preSaveTimesheet hook of the timesheet object. If successful, save all timesheet lines, and finally calls the postSaveTimesheet hook.- Parameters:
lines
- Input linesperiods
- Periods to save- Returns:
- messages User messages
-
save
public java.util.List<java.lang.String> save()
Save the current timesheet- Returns:
- messages
-
save
public java.util.List<java.lang.String> save(org.json.JSONObject data)
Save the current timesheet with incoming UI data- Returns:
- messages
-
shiftTimesheet
public java.util.List<java.lang.String> shiftTimesheet(ObjectDB assign, java.lang.String assignId, java.lang.String resId1, java.lang.String resId2, java.lang.String oldBeginDate, java.lang.String newBeginDate, java.lang.String oldEndDate, java.lang.String newEndDate)
Shifts the timesheet charges of one assignment- Parameters:
assignId
- Assignment idoldBeginDate
- Original begin datenewBeginDate
- Destination begin dateoldEndDate
- Original end datenewEndDate
- Destination end date- Returns:
- Messages or null
-
merge
public java.util.List<java.lang.String> merge(ObjectDB assign, java.lang.String assignId, java.lang.String resId1, java.lang.String resId2)
Merge assignments and related timesheets- Parameters:
assign
- Assign objectassignId
- Master assignment to keepresId1
- Resource 1resId2
- Resource 2- Returns:
- Messages or null
-
reassign
public java.util.List<java.lang.String> reassign(ObjectDB assign, java.lang.String assignIdFrom, java.lang.String assignIdTo, java.lang.String resIdTo, java.lang.String resId1, java.lang.String resId2, double factor, java.lang.String begin, java.lang.String end)
Transfers assignment charge between 2 resources- Parameters:
assign
- Assign objectassignIdFrom
- Source assign id to transferassignIdTo
- Target assign id (create a new one if null)resIdTo
- New resource id (in case of creation)resId1
- Id to get timesheets from resource 1resId2
- or Id to get timesheets from resource 2factor
- Percentage of charge to reassign (0=nothing .. 1=100%)begin
- Optional start dateend
- Optional end date- Returns:
- Messages or null
-
toList
public static java.util.List<Timesheet.TimesheetLine> toList(java.util.Map<java.lang.String,Timesheet.TimesheetLine> lines, boolean sort)
Sort lines by resource labels
-
convertDateToKey
public java.lang.String convertDateToKey(java.lang.String date)
Convert a date to its key- Parameters:
date
- yyyy-MM-dd- Returns:
- yyyy-MM-dd (day), yyyy-WW (week), yyyy-MM (month)
-
convertKeyToDate
public java.lang.String convertKeyToDate(java.lang.String key)
Convert a key to its date- Parameters:
key
- yyyy-MM-dd (day), yyyy-WW (week), yyyy-MM (month)- Returns:
- date yyyy-MM-dd
-
convertInputToMonthCharges
public double[] convertInputToMonthCharges(java.lang.String encodedInput)
Convert the encoded input into 12 months of charges (TYPE_DAYS and TYPE_WEEK only)
-
isGanttEnabled
public boolean isGanttEnabled()
Is the GANTT chart enabled ?
-
setGanttEnabled
public void setGanttEnabled(boolean b, ObjectCore obj)
Enable Gantt diagram (only if timesheet has dates)- Parameters:
b
- enabled?obj
- Optional object to generate UI action
-
isGanttVisible
public boolean isGanttVisible()
Is the GANTT chart visible ?
-
setGanttVisible
public void setGanttVisible(boolean b)
-
isGanttDragXEnabled
public boolean isGanttDragXEnabled()
Is the horizontal drag allowed ?
-
enableGanttDragX
public void enableGanttDragX(boolean b)
-
isGanttDragYEnabled
public boolean isGanttDragYEnabled()
Is the vertical drag allowed ?
-
enableGanttDragY
public void enableGanttDragY(boolean b)
-
isGanttResizable
public boolean isGanttResizable()
Is the block resizing allowed ?
-
enableGanttResizable
public void enableGanttResizable(boolean b)
-
buildGanttData
public Timesheet.GanttNode buildGanttData(ObjectDB assign, org.json.JSONObject params)
Build tree with assignment blocks- Returns:
- a tree of resources 0=hierarchy/1=resource1/2=resource2 and blocks=assignments
-
ganttDataToJson
public java.lang.String ganttDataToJson(Timesheet.GanttNode root)
Serialize to JSON the GANTT- Returns:
- JSON { data, meta, period }
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toJSON
public java.lang.String toJSON()
Timesheet meta and current data- Returns:
- JSON object
-
service
public java.lang.String service(ObjectDB obj, org.json.JSONObject params)
Ajax service- Parameters:
obj
- Object of resource 1 or 2, or Assign object for Ganttparams
- Service parameters: action, resId, start, end- Returns:
- JSON
-
-