Example usage for org.joda.time LocalDate dayOfMonth

List of usage examples for org.joda.time LocalDate dayOfMonth

Introduction

In this page you can find the example usage for org.joda.time LocalDate dayOfMonth.

Prototype

public Property dayOfMonth() 

Source Link

Document

Get the day of month property which provides access to advanced functionality.

Usage

From source file:energy.usef.dso.workflow.settlement.collect.DsoCollectOrangeRegimeDataCoordinator.java

License:Apache License

/**
 * Initiates collect orange regime data process.
 *
 * @param event the {@link InitiateCollectOrangeRegimeDataEvent} event that triggers the process.
 *///  w  w  w  . ja v  a  2 s.c  o  m
@Asynchronous
@Lock(LockType.WRITE)
public void initiateCollectOrangeRegimeData(@Observes InitiateCollectOrangeRegimeDataEvent event) {
    LOGGER.info(LOG_COORDINATOR_START_HANDLING_EVENT, event);

    LocalDate dayOneMonthBefore = DateTimeUtil.getCurrentDate().minusMonths(1);
    LocalDate startDay = dayOneMonthBefore.withDayOfMonth(1);
    LocalDate endDay = dayOneMonthBefore.dayOfMonth().withMaximumValue();

    List<MeterDataCompany> mdcList = dsoPlanboardBusinessService.findAllMDCs();

    for (LocalDate day = startDay; !day.isAfter(endDay); day = day.plusDays(1)) {
        // Retrieving a list of all connections involved in the orange regime processing.
        Map<ConnectionGroup, List<Connection>> connectionsMap = corePlanboardBusinessService
                .findConnections(day, day, RegimeType.ORANGE);
        if (!connectionsMap.isEmpty()) {
            // Looping through all the MDCs
            for (MeterDataCompany meterDataCompany : mdcList) {
                sendMeterDataQuery(connectionsMap, meterDataCompany.getDomain(), day,
                        sequenceGeneratorService.next());
            }
        }
    }
    LOGGER.info(LOG_COORDINATOR_FINISHED_HANDLING_EVENT, event);
}

From source file:energy.usef.dso.workflow.settlement.initiate.DsoInitiateSettlementCoordinator.java

License:Apache License

/**
 * Preparation of the Initiate Settlement process.
 *
 * @param event the {@link CollectSmartMeterDataEvent} that triggers the process.
 *///from  w  w w  .  jav a2s  . c  o  m
@Asynchronous
@Lock(LockType.WRITE)
public void handleCollectSmartMeterDataEvent(
        @Observes(during = TransactionPhase.AFTER_COMPLETION) CollectSmartMeterDataEvent event) {
    LOGGER.debug(USEFConstants.LOG_COORDINATOR_START_HANDLING_EVENT, event);
    LocalDate dayOneMonthBefore = event.getPeriodInMonth();
    if (dayOneMonthBefore == null) {
        dayOneMonthBefore = DateTimeUtil.getCurrentDate().minusMonths(1);
    }
    LocalDate startDate = dayOneMonthBefore.withDayOfMonth(1);
    LocalDate endDate = dayOneMonthBefore.dayOfMonth().withMaximumValue();

    LOGGER.info("Preparing Initiate Settlement workflow for the start day {} and end day {}.", startDate,
            endDate);

    // retrieve a distinct list of all connections valid in given time frame and map them to a string list.
    Map<LocalDate, Map<ConnectionGroup, List<Connection>>> connectionGroupsWithConnections = corePlanboardBusinessService
            .findConnectionGroupWithConnectionsWithOverlappingValidity(startDate, endDate);
    List<LocalDate> daysWithOrders = corePlanboardBusinessService
            .findPlanboardMessages(DocumentType.FLEX_ORDER, startDate, endDate, DocumentStatus.ACCEPTED)
            .stream().map(PlanboardMessage::getPeriod).distinct().collect(toList());
    if (daysWithOrders.isEmpty()) {
        checkInitiateSettlementDoneEvent
                .fire(new CheckInitiateSettlementDoneEvent(startDate.getYear(), startDate.getMonthOfYear()));
        LOGGER.debug(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, event);
        return;
    }
    // loop through all the MDCs
    for (MeterDataCompany meterDataCompany : dsoPlanboardBusinessService.findAllMDCs()) {
        // query meter data company (MDC) for all connections
        LOGGER.info("Preparing sending MeterDataQuery to Meter Data Company {}", meterDataCompany.getDomain());
        for (LocalDate period : connectionGroupsWithConnections.keySet()) {
            if (!daysWithOrders.contains(period)) {
                continue;
            }
            LocalDateTime expirationDateTime = DateTimeUtil.getCurrentDateTime().plusHours(
                    configDso.getIntegerProperty(ConfigDsoParam.DSO_METER_DATA_QUERY_EXPIRATION_IN_HOURS));
            MessageMetadata messageMetadata = MessageMetadataBuilder
                    .build(meterDataCompany.getDomain(), USEFRole.MDC,
                            config.getProperty(ConfigParam.HOST_DOMAIN), USEFRole.DSO, TRANSACTIONAL)
                    .validUntil(expirationDateTime).build();
            // fill the MeterDataQuery message
            MeterDataQuery meterDataQuery = new MeterDataQuery();
            meterDataQuery.setMessageMetadata(messageMetadata);
            meterDataQuery.setDateRangeStart(period);
            meterDataQuery.setDateRangeEnd(period);
            meterDataQuery.getConnections()
                    .addAll(buildConnectionGroups(connectionGroupsWithConnections.get(period)));
            MeterDataQueryMessageUtil.populateConnectionsInConnectionGroups(meterDataQuery,
                    connectionGroupsWithConnections.get(period));

            // Store in PlanboardMessage, no connectionGroup available because query is for the whole grid.
            // the period should be the startDate of the month.
            PlanboardMessage meterDataQueryPlanboardMessage = new PlanboardMessage(
                    DocumentType.METER_DATA_QUERY_USAGE, sequenceGeneratorService.next(), DocumentStatus.SENT,
                    meterDataCompany.getDomain(), period, null, null, null);
            meterDataQueryPlanboardMessage.setExpirationDate(expirationDateTime);
            corePlanboardBusinessService.updatePlanboardMessage(meterDataQueryPlanboardMessage);

            // send the message
            jmsHelperService.sendMessageToOutQueue(XMLUtil.messageObjectToXml(meterDataQuery));
        }
    }
    LOGGER.debug(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, event);
}

From source file:net.jrkatz.minero.data.MonthlyPeriodDefinition.java

License:Open Source License

private LocalDate startForMonth(final int year, final int month) {
    LocalDate firstOfMonth = new LocalDate(year, month, 1);
    return firstOfMonth.withDayOfMonth(Math.min(firstOfMonth.dayOfMonth().getMaximumValue(), mDayStart));
}

From source file:net.objectlab.kit.datecalc.joda.LocalDatePeriodCountCalculator.java

License:Apache License

private int diff360EIsda(final LocalDate start, final LocalDate end) {
    if (start.equals(end)) {
        return 0;
    }/*from  w  w w  . ja va  2  s .  c  o m*/
    int dayStart = start.getDayOfMonth();
    int dayEnd = end.getDayOfMonth();

    if (start.dayOfMonth().getMaximumValue() == dayStart) {
        dayStart = MONTH_30_DAYS;
    }
    if (end.getMonthOfYear() != 2 && end.dayOfMonth().getMaximumValue() == dayEnd) {
        dayEnd = MONTH_30_DAYS;
    }

    return (end.getYear() - start.getYear()) * YEAR_360
            + (end.getMonthOfYear() - start.getMonthOfYear()) * MONTH_30_DAYS + dayEnd - dayStart;
}

From source file:nl.surfnet.coin.selfservice.control.StatisticsController.java

License:Apache License

private LocalDate getEndDate(String intervalType, LocalDate startDate) {
    LocalDate endDate;/*from  w  w w . java 2 s.c  om*/
    switch (intervalType) {
    case "week":
        endDate = startDate.dayOfWeek().withMaximumValue();
        break;
    case "month":
        endDate = startDate.dayOfMonth().withMaximumValue();
        break;
    case "year":
        endDate = startDate.dayOfYear().withMaximumValue();
        break;
    default:
        throw new IllegalArgumentException(intervalType);
    }
    return endDate;
}

From source file:op.allowance.PnlAllowance.java

License:Open Source License

private CollapsiblePane createCP4(final Resident resident, final int year) {
    LocalDate min = SYSCalendar.bom(minmax.get(resident).getFirst());
    LocalDate max = resident.isActive() ? new LocalDate() : SYSCalendar.eom(minmax.get(resident).getSecond());
    final LocalDate start = new LocalDate(year, 1, 1).isBefore(min.dayOfMonth().withMinimumValue())
            ? min.dayOfMonth().withMinimumValue()
            : new LocalDate(year, 1, 1);
    final LocalDate end = new LocalDate(year, 12, 31).isAfter(max.dayOfMonth().withMaximumValue())
            ? max.dayOfMonth().withMaximumValue()
            : new LocalDate(year, 12, 31);

    final String key = resident.getRID() + "-" + year;
    if (!cpMap.containsKey(key)) {
        cpMap.put(key, new CollapsiblePane());
        try {/*from   w ww .  ja v a2  s .c o m*/
            cpMap.get(key).setCollapsed(true);
        } catch (PropertyVetoException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }

    }

    final CollapsiblePane cpYear = cpMap.get(key);

    if (!carrySums.containsKey(key + "-12")) {
        carrySums.put(key + "-12", AllowanceTools.getSUM(resident, SYSCalendar.eoy(start)));
    }

    String title = "<html><table border=\"0\">" + "<tr>" +

            "<td width=\"520\" align=\"left\"><font size=+1>" + Integer.toString(year) + "</font></td>"
            + "<td width=\"200\" align=\"right\">"
            + (carrySums.get(key + "-12").compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "")
            + cf.format(carrySums.get(key + "-12"))
            + (carrySums.get(key + "-12").compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" +

            "</tr>" + "</table>" +

            "</font></html>";

    DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                cpYear.setCollapsed(!cpYear.isCollapsed());
            } catch (PropertyVetoException pve) {
                // BAH!
            }
        }
    });

    GUITools.addExpandCollapseButtons(cpYear, cptitle.getRight());

    /***
     *      ____       _       _ __   __
     *     |  _ \ _ __(_)_ __ | |\ \ / /__  __ _ _ __
     *     | |_) | '__| | '_ \| __\ V / _ \/ _` | '__|
     *     |  __/| |  | | | | | |_ | |  __/ (_| | |
     *     |_|   |_|  |_|_| |_|\__||_|\___|\__,_|_|
     *
     */
    final JButton btnPrintYear = new JButton(SYSConst.icon22print2);
    btnPrintYear.setPressedIcon(SYSConst.icon22print2Pressed);
    btnPrintYear.setAlignmentX(Component.RIGHT_ALIGNMENT);
    btnPrintYear.setContentAreaFilled(false);
    btnPrintYear.setBorder(null);
    btnPrintYear.setToolTipText(SYSTools.xx("misc.tooltips.btnprintyear"));
    btnPrintYear.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String carry4printKey = resident.getRID() + "-" + (year - 1) + "-12";
            if (!carrySums.containsKey(carry4printKey)) {
                carrySums.put(carry4printKey,
                        AllowanceTools.getSUM(resident, SYSCalendar.eoy(start.minusYears(1))));
            }
            SYSFilesTools.print(AllowanceTools.getAsHTML(AllowanceTools.getYear(resident, start.toDate()),
                    carrySums.get(carry4printKey), resident), true);
        }

    });
    cptitle.getRight().add(btnPrintYear);

    cpYear.setTitleLabelComponent(cptitle.getMain());
    cpYear.setSlidingDirection(SwingConstants.SOUTH);
    cpYear.setBackground(SYSConst.orange1[SYSConst.medium3]);
    cpYear.setOpaque(true);

    /***
     *           _ _      _            _
     *       ___| (_) ___| | _____  __| |   ___  _ __    _   _  ___  __ _ _ __
     *      / __| | |/ __| |/ / _ \/ _` |  / _ \| '_ \  | | | |/ _ \/ _` | '__|
     *     | (__| | | (__|   <  __/ (_| | | (_) | | | | | |_| |  __/ (_| | |
     *      \___|_|_|\___|_|\_\___|\__,_|  \___/|_| |_|  \__, |\___|\__,_|_|
     *                                                   |___/
     */
    cpYear.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
            JPanel pnlContent = new JPanel(new VerticalLayout());

            // somebody clicked on the year
            // monthly informations will be generated. even if there
            // are no allowances for that month
            for (LocalDate month = end; month.compareTo(start) >= 0; month = month.minusMonths(1)) {
                pnlContent.add(createCP4(resident, month));
            }

            cpYear.setContentPane(pnlContent);
            cpYear.setOpaque(false);
        }

    });
    cpYear.setBackground(getBG(resident, 9));

    if (!cpYear.isCollapsed()) {
        JPanel pnlContent = new JPanel(new VerticalLayout());
        for (LocalDate month = end; month.compareTo(start) > 0; month = month.minusMonths(1)) {
            pnlContent.add(createCP4(resident, month));
        }
        cpYear.setContentPane(pnlContent);
    }

    cpYear.setHorizontalAlignment(SwingConstants.LEADING);
    cpYear.setOpaque(false);

    return cpYear;
}

From source file:op.allowance.PnlAllowance.java

License:Open Source License

private JPanel createContentPanel4(final Resident resident, LocalDate month) {
    final String key = getKey(resident, month);

    if (!contentmap.containsKey(key)) {

        JPanel pnlMonth = new JPanel(new VerticalLayout());

        pnlMonth.setBackground(getBG(resident, 11));
        pnlMonth.setOpaque(false);//w ww . jav  a  2  s . c  o m

        //            final String prevKey = resident.getRID() + "-" + SYSCalendar.eom(month.minusMonths(1)).getYear() + "-" + SYSCalendar.eom(month.minusMonths(1)).getMonthOfYear();
        if (!carrySums.containsKey(key)) {
            carrySums.put(key, AllowanceTools.getSUM(resident, SYSCalendar.eom(month.minusMonths(1))));
        }

        BigDecimal rowsum = carrySums.get(key);

        if (!cashmap.containsKey(key)) {
            cashmap.put(key, AllowanceTools.getMonth(resident, month.toDate()));
        }

        JLabel lblEOM = new JLabel("<html><table border=\"0\">" + "<tr>" + "<td width=\"130\" align=\"left\">"
                + DateFormat.getDateInstance().format(month.dayOfMonth().withMaximumValue().toDate()) + "</td>"
                + "<td width=\"400\" align=\"left\">" + SYSTools.xx("admin.residents.cash.endofmonth") + "</td>"
                + "<td width=\"100\" align=\"right\"></td>" + "<td width=\"100\" align=\"right\">"
                + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + cf.format(rowsum)
                + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + "</tr>" + "</table>" +

                "</font></html>");
        pnlMonth.add(lblEOM);

        for (final Allowance allowance : cashmap.get(key)) {

            String title = "<html><table border=\"0\">" + "<tr>" + "<td width=\"130\" align=\"left\">"
                    + DateFormat.getDateInstance().format(allowance.getPit()) + "</td>"
                    + "<td width=\"400\" align=\"left\">" + allowance.getText() + "</td>"
                    + "<td width=\"100\" align=\"right\">"
                    + (allowance.getAmount().compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "")
                    + cf.format(allowance.getAmount())
                    + (allowance.getAmount().compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>"
                    + "<td width=\"100\" align=\"right\">"
                    + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + cf.format(rowsum)
                    + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + "</tr>" + "</table>"
                    +

                    "</font></html>";

            DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {

                }
            });
            cptitle.getButton().setIcon(
                    allowance.isReplaced() || allowance.isReplacement() ? SYSConst.icon22eraser : null);

            if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) {
                /***
                 *      _____    _ _ _
                 *     | ____|__| (_) |_
                 *     |  _| / _` | | __|
                 *     | |__| (_| | | |_
                 *     |_____\__,_|_|\__|
                 *
                 */
                final JButton btnEdit = new JButton(SYSConst.icon22edit3);
                btnEdit.setPressedIcon(SYSConst.icon22edit3Pressed);
                btnEdit.setAlignmentX(Component.RIGHT_ALIGNMENT);
                btnEdit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                btnEdit.setContentAreaFilled(false);
                btnEdit.setBorder(null);
                btnEdit.setToolTipText(SYSTools.xx("admin.residents.cash.btnedit.tooltip"));
                btnEdit.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {

                        final JidePopup popupTX = new JidePopup();
                        popupTX.setMovable(false);
                        PnlTX pnlTX = getPnlTX(resident, allowance);
                        popupTX.setContentPane(pnlTX);
                        popupTX.removeExcludedComponent(pnlTX);
                        popupTX.setDefaultFocusComponent(pnlTX);

                        popupTX.setOwner(btnEdit);
                        GUITools.showPopup(popupTX, SwingConstants.WEST);

                    }
                });
                cptitle.getRight().add(btnEdit);
                // you can edit your own entries or you are a manager. once they are replaced or a replacement record, its over.
                btnEdit.setEnabled((OPDE.getAppInfo().isAllowedTo(InternalClassACL.MANAGER, internalClassID)
                        || allowance.getUser().equals(OPDE.getLogin().getUser())) && !allowance.isReplaced()
                        && !allowance.isReplacement());

                /***
                 *      _   _           _         _______  __
                 *     | | | |_ __   __| | ___   |_   _\ \/ /
                 *     | | | | '_ \ / _` |/ _ \    | |  \  /
                 *     | |_| | | | | (_| | (_) |   | |  /  \
                 *      \___/|_| |_|\__,_|\___/    |_| /_/\_\
                 *
                 */
                final JButton btnUndoTX = new JButton(SYSConst.icon22undo);
                btnUndoTX.setPressedIcon(SYSConst.icon22Pressed);
                btnUndoTX.setAlignmentX(Component.RIGHT_ALIGNMENT);
                btnUndoTX.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                btnUndoTX.setContentAreaFilled(false);
                btnUndoTX.setBorder(null);
                btnUndoTX.setToolTipText(SYSTools.xx("admin.residents.cash.btnundotx.tooltip"));
                btnUndoTX.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {

                        new DlgYesNo(
                                SYSTools.xx("misc.questions.undo1") + "<br/><i>" + "<br/><i>"
                                        + allowance.getText() + "&nbsp;" + cf.format(allowance.getAmount())
                                        + "</i><br/>" + SYSTools.xx("misc.questions.undo2"),
                                SYSConst.icon48undo, new Closure() {
                                    @Override
                                    public void execute(Object answer) {
                                        if (answer.equals(JOptionPane.YES_OPTION)) {
                                            EntityManager em = OPDE.createEM();
                                            try {
                                                em.getTransaction().begin();

                                                Allowance myOldAllowance = em.merge(allowance);
                                                Allowance myCancelAllowance = em
                                                        .merge(new Allowance(myOldAllowance));
                                                em.lock(em.merge(myOldAllowance.getResident()),
                                                        LockModeType.OPTIMISTIC);
                                                em.lock(myOldAllowance, LockModeType.OPTIMISTIC);
                                                myOldAllowance.setReplacedBy(myCancelAllowance,
                                                        em.merge(OPDE.getLogin().getUser()));

                                                em.getTransaction().commit();

                                                DateTime txDate = new DateTime(myCancelAllowance.getPit());

                                                final String keyMonth = myCancelAllowance.getResident().getRID()
                                                        + "-" + txDate.getYear() + "-"
                                                        + txDate.getMonthOfYear();
                                                contentmap.remove(keyMonth);
                                                cpMap.remove(keyMonth);
                                                cashmap.get(keyMonth).remove(allowance);
                                                cashmap.get(keyMonth).add(myOldAllowance);
                                                cashmap.get(keyMonth).add(myCancelAllowance);
                                                Collections.sort(cashmap.get(keyMonth));

                                                updateCarrySums(myCancelAllowance);

                                                createCP4(myCancelAllowance.getResident());

                                                try {
                                                    cpMap.get(keyMonth).setCollapsed(false);
                                                } catch (PropertyVetoException e) {
                                                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                                                }

                                                buildPanel();

                                            } catch (OptimisticLockException ole) {
                                                OPDE.warn(ole);
                                                if (em.getTransaction().isActive()) {
                                                    em.getTransaction().rollback();
                                                }
                                                if (ole.getMessage()
                                                        .indexOf("Class> entity.info.Resident") > -1) {
                                                    OPDE.getMainframe().emptyFrame();
                                                    OPDE.getMainframe().afterLogin();
                                                }
                                                OPDE.getDisplayManager()
                                                        .addSubMessage(DisplayManager.getLockMessage());
                                            } catch (Exception e) {
                                                if (em.getTransaction().isActive()) {
                                                    em.getTransaction().rollback();
                                                }
                                                OPDE.fatal(e);
                                            } finally {
                                                em.close();
                                            }
                                        }
                                    }
                                });
                    }
                });
                cptitle.getRight().add(btnUndoTX);
                btnUndoTX.setEnabled(!allowance.isReplaced() && !allowance.isReplacement());
            }

            if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, internalClassID)) {
                /***
                 *      ____       _      _
                 *     |  _ \  ___| | ___| |_ ___
                 *     | | | |/ _ \ |/ _ \ __/ _ \
                 *     | |_| |  __/ |  __/ ||  __/
                 *     |____/ \___|_|\___|\__\___|
                 *
                 */
                final JButton btnDelete = new JButton(SYSConst.icon22delete);
                btnDelete.setPressedIcon(SYSConst.icon22deletePressed);
                btnDelete.setAlignmentX(Component.RIGHT_ALIGNMENT);
                btnDelete.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                btnDelete.setContentAreaFilled(false);
                btnDelete.setBorder(null);
                btnDelete.setToolTipText(SYSTools.xx("admin.residents.cash.btndelete.tooltip"));
                btnDelete.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        new DlgYesNo(
                                SYSTools.xx("misc.questions.delete1") + "<br/><i>" + allowance.getText()
                                        + "&nbsp;" + cf.format(allowance.getAmount()) + "</i><br/>"
                                        + SYSTools.xx("misc.questions.delete2"),
                                SYSConst.icon48delete, new Closure() {
                                    @Override
                                    public void execute(Object answer) {
                                        if (answer.equals(JOptionPane.YES_OPTION)) {
                                            EntityManager em = OPDE.createEM();
                                            try {
                                                em.getTransaction().begin();
                                                Allowance myAllowance = em.merge(allowance);
                                                em.lock(em.merge(myAllowance.getResident()),
                                                        LockModeType.OPTIMISTIC);

                                                Allowance theOtherOne = null;
                                                // Check for special cases
                                                if (myAllowance.isReplacement()) {
                                                    theOtherOne = em.merge(myAllowance.getReplacementFor());
                                                    theOtherOne.setReplacedBy(null);
                                                    theOtherOne.setEditedBy(null);
                                                    myAllowance.setEditPit(null);
                                                }
                                                if (myAllowance.isReplaced()) {
                                                    theOtherOne = em.merge(myAllowance.getReplacedBy());
                                                    theOtherOne.setReplacementFor(null);
                                                }

                                                em.remove(myAllowance);
                                                em.getTransaction().commit();

                                                DateTime txDate = new DateTime(myAllowance.getPit());
                                                final String keyMonth = myAllowance.getResident().getRID() + "-"
                                                        + txDate.getYear() + "-" + txDate.getMonthOfYear();

                                                cpMap.remove(keyMonth);
                                                cashmap.get(keyMonth).remove(myAllowance);
                                                if (theOtherOne != null) {
                                                    cashmap.get(keyMonth).remove(theOtherOne);
                                                    cashmap.get(keyMonth).add(theOtherOne);
                                                    Collections.sort(cashmap.get(keyMonth));
                                                }

                                                // only to update the carrysums. myAllowance will be discarded soon.
                                                myAllowance.setAmount(myAllowance.getAmount().negate());
                                                updateCarrySums(myAllowance);

                                                createCP4(myAllowance.getResident());

                                                try {
                                                    if (cpMap.containsKey(keyMonth)) {
                                                        cpMap.get(keyMonth).setCollapsed(false);
                                                    }
                                                } catch (PropertyVetoException e) {
                                                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                                                }

                                                buildPanel();
                                            } catch (OptimisticLockException ole) {
                                                OPDE.warn(ole);
                                                if (em.getTransaction().isActive()) {
                                                    em.getTransaction().rollback();
                                                }
                                                if (ole.getMessage()
                                                        .indexOf("Class> entity.info.Resident") > -1) {
                                                    OPDE.getMainframe().emptyFrame();
                                                    OPDE.getMainframe().afterLogin();
                                                }
                                                OPDE.getDisplayManager()
                                                        .addSubMessage(DisplayManager.getLockMessage());
                                            } catch (Exception e) {
                                                if (em.getTransaction().isActive()) {
                                                    em.getTransaction().rollback();
                                                }
                                                OPDE.fatal(e);
                                            } finally {
                                                em.close();
                                            }
                                        }
                                    }
                                });
                    }
                });
                cptitle.getRight().add(btnDelete);
            }
            pnlMonth.add(cptitle.getMain());
            linemap.put(allowance, cptitle.getMain());

            rowsum = rowsum.subtract(allowance.getAmount());
        }

        JLabel lblBOM = new JLabel("<html><table border=\"0\">" + "<tr>" + "<td width=\"130\" align=\"left\">"
                + DateFormat.getDateInstance().format(month.dayOfMonth().withMinimumValue().toDate()) + "</td>"
                + "<td width=\"400\" align=\"left\">" + SYSTools.xx("admin.residents.cash.startofmonth")
                + "</td>" + "<td width=\"100\" align=\"right\"></td>" + "<td width=\"100\" align=\"right\">"
                + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + cf.format(rowsum)
                + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + "</tr>" + "</table>" +

                "</font></html>");
        lblBOM.setBackground(getBG(resident, 11));
        pnlMonth.add(lblBOM);
        contentmap.put(key, pnlMonth);
    }

    return contentmap.get(key);
}

From source file:op.care.reports.PnlReport.java

License:Open Source License

private CollapsiblePane createCP4Year(final int year, LocalDate min, LocalDate max) {
    /***//  www  . ja  v  a2  s. c o m
     *                          _        ____ ____     __             __   _______    _    ____
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \   / _| ___  _ __  \ \ / / ____|  / \  |  _ \
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | | |_ / _ \| '__|  \ V /|  _|   / _ \ | |_) |
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/  |  _| (_) | |      | | | |___ / ___ \|  _ <
     *      \___|_|  \___|\__,_|\__\___|\____|_|     |_|  \___/|_|      |_| |_____/_/   \_\_| \_\
     *
     */

    final LocalDate start = new LocalDate(year, 1, 1).isBefore(min.dayOfMonth().withMinimumValue())
            ? min.dayOfMonth().withMinimumValue()
            : new LocalDate(year, 1, 1);
    final LocalDate end = new LocalDate(year, 12, 31).isAfter(max.dayOfMonth().withMaximumValue())
            ? max.dayOfMonth().withMaximumValue()
            : new LocalDate(year, 12, 31);

    final String keyYear = Integer.toString(year) + ".year";
    synchronized (cpMap) {
        if (!cpMap.containsKey(keyYear)) {
            cpMap.put(keyYear, new CollapsiblePane());
            try {
                cpMap.get(keyYear).setCollapsed(true);
            } catch (PropertyVetoException e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }

        }
    }

    final CollapsiblePane cpYear = cpMap.get(keyYear);

    String title = "<html><font size=+1>" + "<b>" + Integer.toString(year) + "</b>" + "</font></html>";

    DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                cpYear.setCollapsed(!cpYear.isCollapsed());
            } catch (PropertyVetoException pve) {
                // BAH!
            }
        }
    });

    cpYear.setTitleLabelComponent(cptitle.getMain());
    cpYear.setSlidingDirection(SwingConstants.SOUTH);
    cpYear.setBackground(SYSConst.orange1[SYSConst.medium3]);
    cpYear.setOpaque(true);

    /***
     *           _ _      _            _
     *       ___| (_) ___| | _____  __| |   ___  _ __    _   _  ___  __ _ _ __
     *      / __| | |/ __| |/ / _ \/ _` |  / _ \| '_ \  | | | |/ _ \/ _` | '__|
     *     | (__| | | (__|   <  __/ (_| | | (_) | | | | | |_| |  __/ (_| | |
     *      \___|_|_|\___|_|\_\___|\__,_|  \___/|_| |_|  \__, |\___|\__,_|_|
     *                                                   |___/
     */
    cpYear.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
            JPanel pnlContent = new JPanel(new VerticalLayout());

            // somebody clicked on the year
            for (LocalDate month = end; month.compareTo(start) >= 0; month = month.minusMonths(1)) {
                pnlContent.add(createCP4Month(month));
            }

            cpYear.setContentPane(pnlContent);

        }
    });
    //        cpYear.setBackground(getColor(vtype, SYSConst.light4));

    if (!cpYear.isCollapsed()) {
        JPanel pnlContent = new JPanel(new VerticalLayout());

        for (LocalDate month = end; month.compareTo(start) >= 0; month = month.minusMonths(1)) {
            pnlContent.add(createCP4Month(month));
        }

        cpYear.setContentPane(pnlContent);
        cpYear.setOpaque(false);
    }

    cpYear.setHorizontalAlignment(SwingConstants.LEADING);
    cpYear.setOpaque(false);

    return cpYear;
}

From source file:op.care.reports.PnlReport.java

License:Open Source License

private JPanel createContentPanel4Month(LocalDate month) {
    /***//ww w  .  ja  va  2 s  .c om
     *                      _             _      __              __  __  ___  _   _ _____ _   _
     *       ___ ___  _ __ | |_ ___ _ __ | |_   / _| ___  _ __  |  \/  |/ _ \| \ | |_   _| | | |
     *      / __/ _ \| '_ \| __/ _ \ '_ \| __| | |_ / _ \| '__| | |\/| | | | |  \| | | | | |_| |
     *     | (_| (_) | | | | ||  __/ | | | |_  |  _| (_) | |    | |  | | |_| | |\  | | | |  _  |
     *      \___\___/|_| |_|\__\___|_| |_|\__| |_|  \___/|_|    |_|  |_|\___/|_| \_| |_| |_| |_|
     *
     */

    //        if (!contentmap.containsKey(key)) {

    JPanel pnlMonth = new JPanel(new VerticalLayout());

    pnlMonth.setOpaque(false);

    LocalDate now = new LocalDate();

    boolean sameMonth = now.dayOfMonth().withMaximumValue().equals(month.dayOfMonth().withMaximumValue());

    final LocalDate start = sameMonth ? now : SYSCalendar.eom(month);
    final LocalDate end = SYSCalendar.bom(month);

    for (LocalDate week = start; end.compareTo(week) <= 0; week = week.minusWeeks(1)) {
        pnlMonth.add(createCP4Week(week));
    }

    return pnlMonth;
}

From source file:op.care.supervisor.PnlHandover.java

License:Open Source License

private CollapsiblePane createCP4Year(final int year, LocalDate min, LocalDate max) {
    /***/*from  w  w  w . j  a va  2s.  c  om*/
     *                          _        ____ ____     __             __   _______    _    ____
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \   / _| ___  _ __  \ \ / / ____|  / \  |  _ \
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | | |_ / _ \| '__|  \ V /|  _|   / _ \ | |_) |
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/  |  _| (_) | |      | | | |___ / ___ \|  _ <
     *      \___|_|  \___|\__,_|\__\___|\____|_|     |_|  \___/|_|      |_| |_____/_/   \_\_| \_\
     *
     */

    final LocalDate start = new LocalDate(year, 1, 1).isBefore(min.dayOfMonth().withMinimumValue())
            ? min.dayOfMonth().withMinimumValue()
            : new LocalDate(year, 1, 1);
    final LocalDate end = new LocalDate(year, 12, 31).isAfter(max.dayOfMonth().withMaximumValue())
            ? max.dayOfMonth().withMaximumValue()
            : new LocalDate(year, 12, 31);

    final String keyYear = Integer.toString(year) + ".year";
    synchronized (cpMap) {
        if (!cpMap.containsKey(keyYear)) {
            cpMap.put(keyYear, new CollapsiblePane());
            try {
                cpMap.get(keyYear).setCollapsed(true);
            } catch (PropertyVetoException e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }

        }
    }

    final CollapsiblePane cpYear = cpMap.get(keyYear);

    String title = "<html><font size=+1>" + "<b>" + Integer.toString(year) + "</b>" + "</font></html>";

    DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                cpYear.setCollapsed(!cpYear.isCollapsed());
            } catch (PropertyVetoException pve) {
                // BAH!
            }
        }
    });

    cpYear.setTitleLabelComponent(cptitle.getMain());
    cpYear.setSlidingDirection(SwingConstants.SOUTH);
    cpYear.setBackground(SYSConst.orange1[SYSConst.medium3]);
    cpYear.setOpaque(true);

    /***
     *           _ _      _            _
     *       ___| (_) ___| | _____  __| |   ___  _ __    _   _  ___  __ _ _ __
     *      / __| | |/ __| |/ / _ \/ _` |  / _ \| '_ \  | | | |/ _ \/ _` | '__|
     *     | (__| | | (__|   <  __/ (_| | | (_) | | | | | |_| |  __/ (_| | |
     *      \___|_|_|\___|_|\_\___|\__,_|  \___/|_| |_|  \__, |\___|\__,_|_|
     *                                                   |___/
     */
    cpYear.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
            JPanel pnlContent = new JPanel(new VerticalLayout());

            // somebody clicked on the year
            for (LocalDate month = end; month.compareTo(start) >= 0; month = month.minusMonths(1)) {
                pnlContent.add(createCP4Month(month));
            }

            cpYear.setContentPane(pnlContent);

        }
    });

    if (!cpYear.isCollapsed()) {
        JPanel pnlContent = new JPanel(new VerticalLayout());

        for (LocalDate month = end; month.compareTo(start) >= 0; month = month.minusMonths(1)) {
            pnlContent.add(createCP4Month(month));
        }

        cpYear.setContentPane(pnlContent);
        cpYear.setOpaque(false);
    }

    cpYear.setHorizontalAlignment(SwingConstants.LEADING);
    cpYear.setOpaque(false);

    return cpYear;
}