← Back to team overview

dhis2-devs team mailing list archive

Re: [Branch ~dhis2-devs-core/dhis2/trunk] Rev 2086: Add FinancialAprilPeriod periodtype.

 

On 17 November 2010 03:20,  <noreply@xxxxxxxxxxxxx> wrote:
> ------------------------------------------------------------
> revno: 2086
> committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
> branch nick: dhis2
> timestamp: Wed 2010-11-17 10:17:16 +0700
> message:
>  Add  FinancialAprilPeriod periodtype.
> added:
>  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java
> modified:
>  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
>  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/period/hibernate/PeriodType.hbm.xml

This is interesting.  I know the likes of PEPFAR and other WHO
groupies are particularly interested in the US gov financial year -
they of course keep calling it the "the" financial year but no matter.
 Not sure if this has surfaced as a dhis requireent yet. Anyway I
think it runs from October (or to October). Is it worth trying to
conceive of a general year-with-an-offset period type, or are these
financial period types so few (I only know the April to March one, the
US one and the Jan to Dec one) as to make it simpler to just create
different FinancialZZZPeriodTypes as the need might arise?

Bob

>
>
>
>
> --
> lp:dhis2
> https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
>
> Your team DHIS 2 developers is subscribed to branch lp:dhis2.
> To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
>
> === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java'
> --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java    1970-01-01 00:00:00 +0000
> +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java    2010-11-17 03:17:16 +0000
> @@ -0,0 +1,146 @@
> +/*
> + * Copyright (c) 2004-2010, University of Oslo
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions are met:
> + * * Redistributions of source code must retain the above copyright notice, this
> + *   list of conditions and the following disclaimer.
> + * * Redistributions in binary form must reproduce the above copyright notice,
> + *   this list of conditions and the following disclaimer in the documentation
> + *   and/or other materials provided with the distribution.
> + * * Neither the name of the HISP project nor the names of its contributors may
> + *   be used to endorse or promote products derived from this software without
> + *   specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
> + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
> + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
> + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
> + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
> + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +package org.hisp.dhis.period;
> +
> +import java.util.ArrayList;
> +import java.util.Calendar;
> +import java.util.Date;
> +import java.util.List;
> +
> +/**
> + * @author Chau Thu Tran
> + *
> + * @version FinancialAprilPeriodType.java Nov 3, 2010 12:55:07 PM
> + */
> +public class FinancialAprilPeriodType
> +    extends CalendarPeriodType
> +{
> +    /**
> +     * The name of the FinancialAprilPeriods, which is "FinancialApril".
> +     */
> +    public static final String NAME = "FinancialApril";
> +
> +    public static final int FREQUENCY_ORDER = 365;
> +
> +    // -------------------------------------------------------------------------
> +    // PeriodType functionality
> +    // -------------------------------------------------------------------------
> +
> +    @Override
> +    public String getName()
> +    {
> +        return NAME;
> +    }
> +
> +    @Override
> +    public Period createPeriod()
> +    {
> +        return createPeriod( createCalendarInstance() );
> +    }
> +
> +    @Override
> +    public Period createPeriod( Date date )
> +    {
> +        return createPeriod( createCalendarInstance( date ) );
> +    }
> +
> +    private Period createPeriod( Calendar cal )
> +    {
> +        cal.set( Calendar.YEAR, cal.get( Calendar.YEAR ) + cal.get( Calendar.MONDAY ) / 7 - 1);
> +        cal.set( Calendar.DAY_OF_YEAR, cal.getActualMinimum( Calendar.DAY_OF_YEAR ) + 90 );
> +
> +        Date startDate = cal.getTime();
> +
> +        cal.add( Calendar.YEAR, 1 );
> +        cal.set( Calendar.DAY_OF_YEAR, cal.getActualMinimum( Calendar.DAY_OF_YEAR ) + 89 );
> +
> +        return new Period( this, startDate, cal.getTime() );
> +    }
> +
> +    @Override
> +    public int getFrequencyOrder()
> +    {
> +        return FREQUENCY_ORDER;
> +    }
> +
> +    // -------------------------------------------------------------------------
> +    // CalendarPeriodType functionality
> +    // -------------------------------------------------------------------------
> +
> +    @Override
> +    public Period getNextPeriod( Period period )
> +    {
> +        Calendar cal = createCalendarInstance( period.getStartDate() );
> +
> +        cal.set( Calendar.YEAR, cal.get( Calendar.YEAR ) - cal.get( Calendar.YEAR ) % 2 + 10 );
> +
> +        Date startDate = cal.getTime();
> +        cal.add( Calendar.YEAR, 1 );
> +        cal.add( Calendar.DAY_OF_YEAR, -2 );
> +        System.out.println( "" );
> +        return new Period( this, startDate, cal.getTime() );
> +    }
> +
> +    @Override
> +    public Period getPreviousPeriod( Period period )
> +    {
> +        Calendar cal = createCalendarInstance( period.getStartDate() );
> +        cal.set( Calendar.YEAR, cal.get( Calendar.YEAR ) - cal.get( Calendar.YEAR ) % 2 - 1 );
> +        Date startDate = cal.getTime();
> +
> +        cal.add( Calendar.YEAR, 1 );
> +        cal.add( Calendar.DAY_OF_YEAR, -2 );
> +
> +        return new Period( this, startDate, cal.getTime() );
> +    }
> +
> +    /**
> +     * Generates FinancialAprilPeriods for the last 5, current and next 5 years.
> +     */
> +    @Override
> +    public List<Period> generatePeriods( Date date )
> +    {
> +        ArrayList<Period> years = new ArrayList<Period>();
> +
> +        Calendar cal = createCalendarInstance( date );
> +        cal.add( Calendar.YEAR, cal.get( Calendar.YEAR ) % 2 == 0 ? -10 : -9 );
> +
> +        for ( int i = 0; i < 11; ++i )
> +        {
> +            Date startDate = cal.getTime();
> +
> +            cal.add( Calendar.DAY_OF_YEAR, -1 );
> +            cal.add( Calendar.YEAR, 1 );
> +            years.add( new Period( this, startDate, cal.getTime() ) );
> +
> +            cal.add( Calendar.DAY_OF_YEAR, 1 );
> +        }
> +
> +        return years;
> +    }
> +}
>
> === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
> --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java  2010-07-18 15:17:23 +0000
> +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java  2010-11-17 03:17:16 +0000
> @@ -63,9 +63,10 @@
>         periodTypes.add( new SixMonthlyPeriodType() );
>         periodTypes.add( new YearlyPeriodType() );
>         periodTypes.add( new TwoYearlyPeriodType() );
> +        periodTypes.add( new FinancialAprilPeriodType() );
>         //periodTypes.add( new OnChangePeriodType() );
>         //periodTypes.add( new SurveyPeriodType() );
> -
> +
>         periodTypeMap = new HashMap<String, PeriodType>();
>
>         for ( PeriodType periodType : periodTypes )
>
> === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/period/hibernate/PeriodType.hbm.xml'
> --- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/period/hibernate/PeriodType.hbm.xml 2010-06-23 17:50:25 +0000
> +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/period/hibernate/PeriodType.hbm.xml 2010-11-17 03:17:16 +0000
> @@ -29,5 +29,7 @@
>       discriminator-value="OnChange"/>
>     <subclass name="org.hisp.dhis.period.SurveyPeriodType"
>       discriminator-value="Survey"/>
> +    <subclass name="org.hisp.dhis.period.FinancialAprilPeriodType"
> +      discriminator-value="FinancialApril"/>
>   </class>
>  </hibernate-mapping>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dhis2-devs
> Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dhis2-devs
> More help   : https://help.launchpad.net/ListHelp
>
>



Follow ups

References