Class Timesheet

  • All Implemented Interfaces:
    java.io.Serializable

    public class Timesheet
    extends java.lang.Object
    implements java.io.Serializable
    Timesheet definition and instance
    See Also:
    Serialized Form
    • Field Detail

      • 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
      • m_showGanttInTimesheet

        public int m_showGanttInTimesheet
      • 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​(ObjectDB assign,
                         java.lang.String id,
                         java.lang.String name,
                         char type,
                         boolean flying,
                         boolean backward,
                         java.lang.String ref1,
                         java.lang.String ref2,
                         java.lang.String workloadField,
                         java.lang.String beginDateField,
                         java.lang.String endDateField,
                         java.lang.String statusField,
                         boolean chartRes,
                         boolean chartGantt,
                         int showGantt,
                         boolean dragX,
                         boolean dragY,
                         boolean resizable)
        Timesheet definition
        Parameters:
        assign - Assignment object between 2 resources
        id - Timesheet id
        name - Timesheet name
        type - TYPE_DAY, TYPE_WEEK or TYPE_MONTH
        flying - Floating period to the current date
        backward - Allow backward inputs
        ref1 - Foreign id of resource 1 in assignment
        ref2 - Foreign id of resource 2 in assignment
        workloadField - Optional workload field of assignment
        beginDateField - Optional begin field of assignment
        endDateField - Optional end field of assignment
        statusField - Optional status field for each timesheet
        chartRes - Enable resource chart
        chartGantt - Enable GANTT chart
        showGantt - GANTT option GANTT_*
        dragX - Enable GANTT X drag/drop = shift in time
        dragY - Enable GANTT Y drag/drop = reassignment
        resizable - Enable GANTT resizing
    • Method Detail

      • getObjectResource1

        public ObjectDB getObjectResource1​(Grant g)
      • getObjectResource2

        public ObjectDB getObjectResource2​(Grant g)
      • 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 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)
      • isFlying

        public boolean isFlying()
        Floating timesheet = starts period on any day
      • setFlying

        public void setFlying​(boolean f)
      • isBackwardInputAllowed

        public boolean isBackwardInputAllowed()
        Allows change for old inputs ?
      • setBackward

        public void setBackward​(boolean b)
      • isInputAllowed

        public boolean isInputAllowed​(java.lang.String key,
                                      java.lang.String assignId,
                                      java.lang.String resId1,
                                      java.lang.String resId2)
        Allows change for a period key ? Default is based on the backward input
        Parameters:
        key - Period key
        resId1 - Resource 1 id
        resId2 - Resource 2 id
        Returns:
        true if cell is editable
      • swapResourceAndInput

        public void swapResourceAndInput()
        Swap display of resource and input fields
      • isResourceAndInputSwapped

        public boolean isResourceAndInputSwapped()
      • isTimesheetEnabled

        public boolean isTimesheetEnabled()
        Use timesheet input form ?
      • setTimesheetEnabled

        public void setTimesheetEnabled​(boolean b)
      • isChartEnabled

        public boolean isChartEnabled()
        Use resource chart ?
      • setChartEnabled

        public void setChartEnabled​(boolean b)
      • isChartVisible

        public boolean isChartVisible()
        Is resource chart visible ?
      • 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,
                                  Grant g)
        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
        g - User rights
      • 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 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<java.lang.String[]> getCurrentPeriod()
        Current period to display
      • setCurrentPeriod

        public void setCurrentPeriod​(java.util.List<java.lang.String[]> 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<java.lang.String[]> buildPeriod​(java.lang.String begin,
                                                              java.lang.String end)
        Return a period between 2 dates
        Parameters:
        begin - Begin date
        end - End date
        Returns:
        List of Date+Key
      • 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 label
        color - #RRGGBB
      • fitPeriodToAssignments

        public void fitPeriodToAssignments​(Parameters 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 id
        resourceId2 - optional resource id
        beginDate - start date
        endDate - end date
        Returns:
        List of resource1 records if resource2 is set, and vice versa
      • getTimesheet

        public java.util.Map<java.lang.String,​Timesheet.TimesheetLine> getTimesheet​(boolean resetFilter,
                                                                                          boolean inPeriod)
        Load timesheet from DB
        Parameters:
        resetFilter - true to ignore UI filters
        inPeriod - true to watch timesheets in current period
        Returns:
        timesheet lines
      • save

        public java.util.List<java.lang.String> save​(java.util.List<Timesheet.TimesheetLine> lines,
                                                     java.util.List<java.lang.String[]> period)
        Save a timesheet. Calls first the preSaveTimesheet hook of the timesheet object. if succesful, save all timesheet lines, and finally calls the postSaveTimesheet hook.
        Parameters:
        lines - Input lines
        period - Perod to save
        Returns:
        messages User messages
      • save

        public java.util.List<java.lang.String> save()
        Save the current timesheet
        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 id
        oldBeginDate - Original begin date
        newBeginDate - Destination begin date
        oldEndDate - Original end date
        newEndDate - 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 object
        assignId - Master assignment to keep
        resId1 - Resource 1
        resId2 - 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 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
        Returns:
        Messages or null
      • 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)
      • getGanttFilters

        public java.util.Map<ObjectDB,​java.util.LinkedHashMap<java.lang.String,​java.util.HashMap<java.lang.String,​Timesheet.GanttNode>>> getGanttFilters()
        GANTT filters: Object in hierarchy => list of UK Label => list of id => Node
      • isGanttEnabled

        public boolean isGanttEnabled()
        Is the GANTT chart enabled ?
      • setGanttEnabled

        public void setGanttEnabled​(boolean b)
      • 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​(Parameters params)
        Returns:
        a tree of resources 0=hierarchy/1=resource1/2=resource2 and blocks=assignments
      • ganttDataToJson

        public java.lang.String ganttDataToJson​(Parameters params)
        Serialize to JSON the GANTT
        Returns:
        JSON flow
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object