Search in sources :

Example 1 with Revenue

use of eu.ggnet.dwoss.report.ee.eao.Revenue in project dwoss by gg-net.

the class ReportLineEaoIT method testRevenue.

@Test
public void testRevenue() throws Exception {
    ReportLineEao reportLineEao = new ReportLineEao(em);
    utx.begin();
    em.joinTransaction();
    em.persist(make("2010-06-01", INVOICE, UNIT, 100));
    em.persist(make("2010-06-02", INVOICE, UNIT, 100));
    em.persist(make("2010-06-03", INVOICE, UNIT, 100));
    em.persist(make("2010-06-04", INVOICE, UNIT, 100));
    em.persist(make("2010-06-04", ANNULATION_INVOICE, UNIT, -50));
    em.persist(make("2010-06-05", INVOICE, UNIT, 100));
    em.persist(make("2010-07-05", INVOICE, UNIT, 100));
    utx.commit();
    // Month and count
    utx.begin();
    em.joinTransaction();
    NavigableMap<Date, Revenue> result = reportLineEao.revenueByPositionTypesAndDate(Arrays.asList(UNIT), parseDate("2010-06-01", "yyyy-MM-dd"), parseDate("2010-06-05", "yyyy-MM-dd"), DAY, true);
    for (Entry<Date, Revenue> e : result.entrySet()) {
        assertEquals(100.0, e.getValue().sumBy(INVOICE), 0.0001);
    // System.out.println(DateFormats.ISO.format(e.getKey()) + " - I:" + e.getValue().sum(INVOICE) + " A:" + e.getValue().sum(ANNULATION_INVOICE) + " S:" + e.getValue().sum());
    }
    result = reportLineEao.revenueByPositionTypesAndDate(Arrays.asList(UNIT), parseDate("2010-06-01", "yyyy-MM-dd"), parseDate("2010-06-05", "yyyy-MM-dd"), Step.MONTH, true);
    assertEquals(1, result.size());
    assertEquals(500.0, result.firstEntry().getValue().sumBy(INVOICE), 0.0001);
    assertEquals(-50.0, result.firstEntry().getValue().sumBy(ANNULATION_INVOICE), 0.0001);
    assertEquals(450.0, result.firstEntry().getValue().sum(), 0.0001);
    // result = reportLineEao.revenueByPositionTypesAndDate(Arrays.asList(UNIT), parseDate("2010-06-01", "yyyy-MM-dd"), parseDate("2010-07-30", "yyyy-MM-dd"), DAY);
    // for (Entry<Date, Revenue> e : result.entrySet()) {
    // System.out.println(DateFormats.ISO.format(e.getKey()) + " - I:" + e.getValue().sum(INVOICE) + " A:" + e.getValue().sum(ANNULATION_INVOICE) + " S:" + e.getValue().sum());
    // }
    System.out.println(" -- ");
    result = reportLineEao.revenueByPositionTypesAndDate(Arrays.asList(UNIT), parseDate("2010-06-01", "yyyy-MM-dd"), parseDate("2010-07-30", "yyyy-MM-dd"), Step.MONTH, true);
    assertEquals(2, result.size());
    assertEquals(500.0, result.firstEntry().getValue().sumBy(INVOICE), 0.0001);
    assertEquals(-50.0, result.firstEntry().getValue().sumBy(ANNULATION_INVOICE), 0.0001);
    assertEquals(450.0, result.firstEntry().getValue().sum(), 0.0001);
    assertEquals(100.0, result.lastEntry().getValue().sumBy(INVOICE), 0.0001);
    assertEquals(0.0, result.lastEntry().getValue().sumBy(ANNULATION_INVOICE), 0.0001);
    assertEquals(100.0, result.lastEntry().getValue().sum(), 0.0001);
    for (Step step : Step.values()) {
        // Shortcut to test all steps.
        // System.out.println("-----");
        // System.out.println(step);
        // System.out.println("-----");
        result = reportLineEao.revenueByPositionTypesAndDate(Arrays.asList(UNIT), parseDate("2010-01-01", "yyyy-MM-dd"), parseDate("2010-12-31", "yyyy-MM-dd"), step, true);
    // for (Entry<Date, Revenue> e : result.entrySet()) {
    // System.out.println(step.format(e.getKey()) + "|" + DateFormats.ISO.format(e.getKey()) + " - " + e.getValue());
    // }
    }
    utx.commit();
}
Also used : ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) Revenue(eu.ggnet.dwoss.report.ee.eao.Revenue) DateUtils.parseDate(org.apache.commons.lang3.time.DateUtils.parseDate) Test(org.junit.Test)

Aggregations

ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)1 Revenue (eu.ggnet.dwoss.report.ee.eao.Revenue)1 DateUtils.parseDate (org.apache.commons.lang3.time.DateUtils.parseDate)1 Test (org.junit.Test)1