Class Timesheet

  • All Implemented Interfaces:

    public class Timesheet
    extends java.lang.Object
    Timesheet instance
    See Also:
    Serialized Form
    • Field Detail

      • TYPE_MONTH

        public static final char TYPE_MONTH
        Manage inputs by months
        See Also:
        Constant Field Values

        public static final int GANTT_HIDDEN
        Hide Gantt access in the timesheet view
        See Also:
        Constant Field Values

        public static final int GANTT_INLINED
        Inline Gantt display in the timesheet view
        See Also:
        Constant Field Values

        public static final int GANTT_FORWARD
        Add a link to Gantt view in the timesheet view
        See Also:
        Constant Field Values

        public static final int PERIOD_DAY_SIZE
        Minimum size of period in days
        See Also:
        Constant Field Values

        public static final int PERIOD_WEEK_SIZE
        Minimum size of period in weeks
        See Also:
        Constant Field Values

        public static final int PERIOD_MONTH_SIZE
        Minimum size of period in months
        See Also:
        Constant Field Values
    • Method Detail

      • init

        public void init​(Grant g)
        Instance initialization
        g - User rights
      • getObjectResource1

        public ObjectDB getObjectResource1()
        Get instance of resource 1
        tsheet instance
      • getObjectResource2

        public ObjectDB getObjectResource2()
        Get instance of resource 2
        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
        b - Boolean
        obj - 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.
        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.
        name - The name of the input field
        factor - 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)
      • 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
        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
        begin - Begin date
        end - End date
        List of periods
      • getCurrentColor

        public java.lang.String getCurrentColor​(java.lang.String label)
        Get the color of a resource
        label - Any resource label
        color #RRGGBB
      • setCurrentColor

        public void setCurrentColor​(java.lang.String label,
                                    java.lang.String color)
        Assign a color to a resource
        label - Any resource label
        color - #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
        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
        resourceId1 - optional resource id
        resourceId2 - optional resource id
        beginDate - start date
        endDate - end date
        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
        resetFilter - true to ignore UI filters
        inPeriod - true to find timesheets in current period
        timesheet lines
      • 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.
        lines - Input lines
        periods - Periods to save
        messages User messages
      • save

        public java.util.List<java.lang.String> save()
        Save the current timesheet
      • save

        public java.util.List<java.lang.String> save​(org.json.JSONObject data)
        Save the current timesheet with incoming UI data
      • 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
        assignId - Assignment id
        oldBeginDate - Original begin date
        newBeginDate - Destination begin date
        oldEndDate - Original end date
        newEndDate - Destination end date
        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
        assign - Assign object
        assignId - Master assignment to keep
        resId1 - Resource 1
        resId2 - Resource 2
        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
        assign - Assign object
        assignIdFrom - Source assign id to transfer
        assignIdTo - Target assign id (create a new one if null)
        resIdTo - New resource id (in case of creation)
        resId1 - Id to get timesheets from resource 1
        resId2 - or Id to get timesheets from resource 2
        factor - Percentage of charge to reassign (0=nothing .. 1=100%)
        begin - Optional start date
        end - Optional end date
        Messages or null
      • convertDateToKey

        public java.lang.String convertDateToKey​(java.lang.String date)
        Convert a date to its key
        date - yyyy-MM-dd
        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
        key - yyyy-MM-dd (day), yyyy-WW (week), yyyy-MM (month)
        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)
        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
        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
        JSON { data, meta, period }
      • toString

        public java.lang.String toString()
        toString in class java.lang.Object
      • toJSON

        public java.lang.String toJSON()
        Timesheet meta and current data
        JSON object
      • service

        public java.lang.String service​(ObjectDB obj,
                                        org.json.JSONObject params)
        Ajax service
        obj - Object of resource 1 or 2, or Assign object for Gantt
        params - Service parameters: action, resId, start, end