Search in sources :

Example 16 with Month

use of org.activityinfo.model.type.time.Month in project activityinfo by bedatadriven.

the class UpdateMonthlyReportsAsync method queryPeriodMap.

private Promise<Map<Month, Integer>> queryPeriodMap(UpdateMonthlyReports command, ExecutionContext context) {
    final Promise<Map<Month, Integer>> promise = new Promise<>();
    SqlQuery.select("reportingPeriodId", "Date2").from(Tables.REPORTING_PERIOD, "rp").where("siteId").equalTo(command.getSiteId()).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            Map<Month, Integer> periodMap = Maps.newHashMap();
            for (SqlResultSetRow row : results.getRows()) {
                Date endDate = row.getDate("Date2");
                Month month = Month.of(endDate);
                periodMap.put(month, row.getInt("reportingPeriodId"));
            }
            promise.resolve(periodMap);
        }
    });
    return promise;
}
Also used : Promise(org.activityinfo.promise.Promise) Month(org.activityinfo.model.type.time.Month) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) Map(java.util.Map) Date(java.util.Date)

Example 17 with Month

use of org.activityinfo.model.type.time.Month in project activityinfo by bedatadriven.

the class MonthWidget method input.

private FieldInput input() {
    try {
        int year = Integer.parseInt(yearBox.getText());
        int monthOfYear = MONTHS.indexOf(monthBox.getText()) + 1;
        return new FieldInput(new Month(year, monthOfYear));
    } catch (Exception e) {
        return FieldInput.INVALID_INPUT;
    }
}
Also used : Month(org.activityinfo.model.type.time.Month) FieldInput(org.activityinfo.ui.client.input.model.FieldInput)

Example 18 with Month

use of org.activityinfo.model.type.time.Month in project activityinfo by bedatadriven.

the class MonthWidget method init.

@Override
public void init(FieldValue value) {
    if (value instanceof Month) {
        Month month = (Month) value;
        yearBox.setText(Integer.toString(month.getYear()));
        monthBox.setText(MONTHS.get(month.getMonth() - 1));
    }
}
Also used : Month(org.activityinfo.model.type.time.Month)

Example 19 with Month

use of org.activityinfo.model.type.time.Month in project activityinfo by bedatadriven.

the class HandlerUtil method monthFromRange.

static Month monthFromRange(Date date1, Date date2) {
    Calendar c1 = Calendar.getInstance();
    c1.setTime(date1);
    if (c1.get(Calendar.DAY_OF_MONTH) != 1) {
        return null;
    }
    Calendar c2 = Calendar.getInstance();
    c2.setTime(date2);
    if (c2.get(Calendar.DAY_OF_MONTH) != c2.getActualMaximum(Calendar.DAY_OF_MONTH)) {
        return null;
    }
    if (c2.get(Calendar.MONTH) != c1.get(Calendar.MONTH) || c2.get(Calendar.YEAR) != c2.get(Calendar.YEAR)) {
        return null;
    }
    return new Month(c1.get(Calendar.YEAR), c1.get(Calendar.MONTH) + 1);
}
Also used : Month(org.activityinfo.model.type.time.Month) Calendar(java.util.Calendar)

Example 20 with Month

use of org.activityinfo.model.type.time.Month in project activityinfo by bedatadriven.

the class SyncIntegrationTest method updateMonthlyReports.

@Test
@OnDataSet("/dbunit/monthly-calc-indicators.db.xml")
public void updateMonthlyReports() throws SQLException, InterruptedException {
    synchronize();
    int siteId = 1;
    MonthlyReportResult result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 5));
    IndicatorRowDTO women = result.getData().get(0);
    IndicatorRowDTO men = result.getData().get(1);
    assertThat(women.getIndicatorName(), equalTo("women"));
    assertThat(women.getIndicatorId(), equalTo(7002));
    assertThat(men.getIndicatorName(), equalTo("men"));
    assertThat(men.getActivityName(), equalTo("NFI"));
    assertThat(men.getActivityId(), equalTo(901));
    assertThat(men.getIndicatorId(), equalTo(7001));
    assertThat(men.getValue(2009, 1), CoreMatchers.equalTo(200d));
    assertThat(women.getValue(2009, 1), equalTo(300d));
    assertThat(men.getValue(2009, 2), equalTo(150d));
    assertThat(women.getValue(2009, 2), equalTo(330d));
    // Update locally
    executeLocally(new UpdateMonthlyReports(siteId, Lists.newArrayList(new Change(men.getIndicatorId(), new Month(2009, 1), 221d), new Change(men.getIndicatorId(), new Month(2009, 3), 444d), new Change(women.getIndicatorId(), new Month(2009, 5), 200d), new Change(men.getIndicatorId(), new Month(2009, 5), 522d))));
    result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 12));
    women = result.getData().get(0);
    men = result.getData().get(1);
    assertThat(men.getValue(2009, 1), equalTo(221d));
    assertThat(women.getValue(2009, 1), equalTo(300d));
    // same - no change
    assertThat(men.getValue(2009, 2), equalTo(150d));
    assertThat(women.getValue(2009, 2), equalTo(330d));
    // new periods
    assertThat(men.getValue(2009, 3), equalTo(444d));
    assertThat(women.getValue(2009, 5), equalTo(200d));
    assertThat(men.getValue(2009, 5), equalTo(522d));
    // Synchronize
    synchronize();
    newRequest();
    MonthlyReportResult remoteResult = executeRemotely(new GetMonthlyReports(siteId, new Month(2009, 1), 12));
    women = remoteResult.getData().get(0);
    men = remoteResult.getData().get(1);
    assertThat(men.getValue(2009, 1), equalTo(221d));
    assertThat(women.getValue(2009, 1), equalTo(300d));
    // same - no change
    assertThat(men.getValue(2009, 2), equalTo(150d));
    assertThat(women.getValue(2009, 2), equalTo(330d));
    // new periods
    assertThat(men.getValue(2009, 3), equalTo(444d));
    assertThat(women.getValue(2009, 5), equalTo(200d));
    assertThat(men.getValue(2009, 5), equalTo(522d));
    newRequest();
    // REmote update
    executeRemotely(new UpdateMonthlyReports(siteId, Lists.newArrayList(new Change(men.getIndicatorId(), new Month(2009, 1), 40d), new Change(women.getIndicatorId(), new Month(2009, 3), 6000d))));
    newRequest();
    synchronize();
    result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 5));
    women = result.getData().get(0);
    men = result.getData().get(1);
    assertThat(men.getValue(2009, 1), CoreMatchers.equalTo(40d));
    // unchanged
    assertThat(women.getValue(2009, 1), CoreMatchers.equalTo(300d));
    assertThat(women.getValue(2009, 3), equalTo(6000d));
}
Also used : Month(org.activityinfo.model.type.time.Month) Change(org.activityinfo.legacy.shared.command.UpdateMonthlyReports.Change) MonthlyReportResult(org.activityinfo.legacy.shared.command.result.MonthlyReportResult) IndicatorRowDTO(org.activityinfo.legacy.shared.model.IndicatorRowDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

Month (org.activityinfo.model.type.time.Month)23 Test (org.junit.Test)9 MonthlyReportResult (org.activityinfo.legacy.shared.command.result.MonthlyReportResult)7 ArrayList (java.util.ArrayList)5 UpdateMonthlyReports (org.activityinfo.legacy.shared.command.UpdateMonthlyReports)5 GetMonthlyReports (org.activityinfo.legacy.shared.command.GetMonthlyReports)3 IndicatorRowDTO (org.activityinfo.legacy.shared.model.IndicatorRowDTO)3 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)2 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)2 DateWrapper (com.extjs.gxt.ui.client.util.DateWrapper)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 Change (org.activityinfo.legacy.shared.command.UpdateMonthlyReports.Change)2 IllegalAccessCommandException (org.activityinfo.legacy.shared.exception.IllegalAccessCommandException)2 OnDataSet (org.activityinfo.server.database.OnDataSet)2 Timed (org.activityinfo.server.util.monitoring.Timed)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 FieldEvent (com.extjs.gxt.ui.client.event.FieldEvent)1 LabelToolItem (com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem)1