Search in sources :

Example 1 with PositionType

use of eu.ggnet.dwoss.rules.PositionType in project dwoss by gg-net.

the class ReportLineEao method findRevenueDataByPositionTypesAndDate.

/**
 * Generates a list of {@link DailyRevenue} that hold report data for INVOICES - ANNULATION_INVOICES in a date range containing daily summed prices
 * for specific {@link PositionType}s.
 * <p>
 * @param posTypes the {@link PositionType} that is searched for
 * @param start    the starting date range for the collected data
 * @param end      the end date range for the collected data
 * @return a list of {@link DailyRevenue} that hold report data for INVOICES - ANNULATION_INVOICES in a date range containing daily summed prices
 *         for specific {@link PositionType}s
 */
public List<Set<DailyRevenue>> findRevenueDataByPositionTypesAndDate(List<PositionType> posTypes, Date start, Date end) {
    try {
        L.info("Attempt to find revenue report data with posType={}, start={}, end={}", posTypes, start, end);
        List<Integer> posTypeOrdinals = new ArrayList<>();
        for (PositionType positionType : posTypes) {
            posTypeOrdinals.add(positionType.ordinal());
        }
        Query q = em.createNativeQuery("SELECT reportingDate, documentTypeName, sum(price), salesChannelName" + " FROM ReportLine rl WHERE rl.positionType in(:positions) and rl.reportingDate >= :start" + " and rl.reportingDate <= :end and rl.documentType in(1,3) GROUP BY rl.reportingDate, rl.documentTypeName, rl.salesChannelName");
        q.setParameter("positions", posTypeOrdinals);
        q.setParameter("start", start);
        q.setParameter("end", end);
        List<Object[]> data = q.getResultList();
        List<DailyRevenue> reportData = new ArrayList<>();
        for (Object[] object : data) {
            reportData.add(new DailyRevenue((Date) object[0], (String) object[1], (double) object[2], (String) object[3]));
        }
        Map<Date, Set<DailyRevenue>> revReports = new HashMap<>();
        for (DailyRevenue revenueReportCarrier : reportData) {
            Date d = DateUtils.truncate(revenueReportCarrier.getReportingDate(), Calendar.DATE);
            Set<DailyRevenue> neededSet = revReports.get(d);
            if (neededSet == null) {
                neededSet = new HashSet<>();
                neededSet.add(revenueReportCarrier);
                revReports.put(d, neededSet);
            } else {
                neededSet.add(revenueReportCarrier);
            }
        }
        return new ArrayList<>(revReports.values());
    } catch (Exception e) {
        L.error(ExceptionUtils.getStackTrace(e));
        return null;
    }
}
Also used : JPAQuery(com.mysema.query.jpa.impl.JPAQuery) PositionType(eu.ggnet.dwoss.rules.PositionType)

Example 2 with PositionType

use of eu.ggnet.dwoss.rules.PositionType in project dwoss by gg-net.

the class DocumentUpdateView method addNonUnitPosition.

// GEN-LAST:event_addUnitAction
private void addNonUnitPosition(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_addNonUnitPosition
    Ui.exec(() -> {
        PositionType type;
        if (((JButton) evt.getSource()) == addProductBatchButton) {
            type = PositionType.PRODUCT_BATCH;
        } else if (((JButton) evt.getSource()) == addServiceButton) {
            type = PositionType.SERVICE;
        } else if (((JButton) evt.getSource()) == addCommentButton) {
            type = PositionType.COMMENT;
        } else {
            type = PositionType.SHIPPING_COST;
        }
        try {
            controller.addPosition(document.getDossier().getId(), type, null, false);
            refreshAll();
        } catch (UserInfoException ex) {
            Ui.handle(ex);
        }
    });
}
Also used : PositionType(eu.ggnet.dwoss.rules.PositionType) UserInfoException(eu.ggnet.dwoss.util.UserInfoException)

Aggregations

PositionType (eu.ggnet.dwoss.rules.PositionType)2 JPAQuery (com.mysema.query.jpa.impl.JPAQuery)1 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)1