Example usage for java.math BigDecimal add

List of usage examples for java.math BigDecimal add

Introduction

In this page you can find the example usage for java.math BigDecimal add.

Prototype

public BigDecimal add(BigDecimal augend) 

Source Link

Document

Returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale()) .

Usage

From source file:net.sourceforge.fenixedu.domain.Shift.java

public BigDecimal getTotalHours() {
    Collection<Lesson> lessons = getAssociatedLessonsSet();
    BigDecimal lessonTotalHours = BigDecimal.ZERO;
    for (Lesson lesson : lessons) {
        lessonTotalHours = lessonTotalHours.add(lesson.getTotalHours());
    }//from  w ww  . j  a  v  a 2s  .c  om
    return lessonTotalHours;
}

From source file:com.xumpy.timesheets.services.implementations.JobsGraphics.java

public OverviewWorkDetails getOverviewWorkDetails(List<Jobs> jobs) throws ParseException {
    MathContext mc = new MathContext(3, RoundingMode.HALF_UP);

    OverviewWorkDetailsSrvPojo overviewWorkDetails = new OverviewWorkDetailsSrvPojo();

    List<WorkingDay> workingDays = calculateWorkingDates(jobs);

    overviewWorkDetails.setHoursToWorkPerDay(new BigDecimal(8)); // Hardcoded

    BigDecimal hoursPayedPerDay = new BigDecimal(0, mc);
    BigDecimal workedWeekHours = new BigDecimal(0, mc);
    BigDecimal workedWeekendHours = new BigDecimal(0, mc);
    BigDecimal weekDays = new BigDecimal(0, mc);
    BigDecimal weekendDays = new BigDecimal(0, mc);
    BigDecimal workedWeekDays = new BigDecimal(0, mc);
    BigDecimal workedWeekendDays = new BigDecimal(0, mc);
    BigDecimal overtimeHours = new BigDecimal(0, mc);
    BigDecimal overtimeDays = new BigDecimal(0, mc);

    for (WorkingDay workingDay : workingDays) {
        if (CustomDateUtils.isWeekDay(workingDay.getDate())) {
            weekDays = weekDays.add(new BigDecimal(1));
            workedWeekHours = workedWeekHours.add(workingDay.getActualWorkHours(), mc);
            workedWeekDays = workedWeekDays.add(new BigDecimal(1));
        } else {/*  w w  w  .  j ava  2s  . com*/
            weekendDays = weekendDays.add(new BigDecimal(1));
            workedWeekendHours = workedWeekendHours.add(workingDay.getActualWorkHours(), mc);
            workedWeekendDays = workedWeekendDays.add(new BigDecimal(1));
        }

        overtimeHours = overtimeHours.add(workingDay.getOvertimeHours(), mc);

        for (Jobs jobPerDay : workingDay.getJobs()) {
            if (jobPerDay.getJobsGroup().getCompany() != null) {
                if (hoursPayedPerDay
                        .compareTo(jobPerDay.getJobsGroup().getCompany().getDailyPayedHours()) < 0) {
                    hoursPayedPerDay = jobPerDay.getJobsGroup().getCompany().getDailyPayedHours();
                }
            }
        }

        if (!hoursPayedPerDay.equals(new BigDecimal(0))) {
            overtimeDays = overtimeHours.divide(hoursPayedPerDay, mc);
        } else {
            overtimeDays = workedWeekDays.add(workedWeekendDays);
        }
    }

    overviewWorkDetails.setHoursPayedPerDay(hoursPayedPerDay);

    overviewWorkDetails.setWorkedWeekHours(workedWeekHours);
    overviewWorkDetails.setWorkedWeekendHours(workedWeekendHours);
    overviewWorkDetails.setWeekDays(weekDays);
    overviewWorkDetails.setWeekendDays(weekendDays);

    overviewWorkDetails.setWorkedWeekDays(workedWeekDays);
    overviewWorkDetails.setWorkedWeekendDays(workedWeekendDays);

    overviewWorkDetails.setOvertimeHours(overtimeHours);
    overviewWorkDetails.setOvertimeDays(overtimeDays);

    return overviewWorkDetails;
}

From source file:net.sourceforge.fenixedu.domain.Shift.java

public BigDecimal getCourseLoadWeeklyAverage() {
    BigDecimal weeklyHours = BigDecimal.ZERO;
    for (CourseLoad courseLoad : getCourseLoadsSet()) {
        weeklyHours = weeklyHours.add(courseLoad.getWeeklyHours());
    }/*  w w w. j  a v  a  2s.c  o  m*/
    return weeklyHours;
}

From source file:net.sourceforge.fenixedu.domain.Shift.java

public BigDecimal getCourseLoadTotalHours() {
    BigDecimal weeklyHours = BigDecimal.ZERO;
    for (CourseLoad courseLoad : getCourseLoadsSet()) {
        weeklyHours = weeklyHours.add(courseLoad.getTotalQuantity());
    }/*from   ww  w .  j a  va  2  s  . co m*/
    return weeklyHours;
}

From source file:churashima.action.manage.WorkingAction.java

@Execute(validator = false)
public String search() {
    WorkDao workDao = SingletonS2Container.getComponent(WorkDao.class);

    Long searchUserId = null;//  w ww .  j  a  v a  2 s .  co m
    if (workingForm.searchUserId != null && !"all".equals(workingForm.searchUserId)) {
        searchUserId = Long.valueOf(workingForm.searchUserId);
    }

    Long searchSubjectId = null;
    if (workingForm.searchSubjectId != null && !"all".equals(workingForm.searchSubjectId)) {
        searchSubjectId = Long.valueOf(workingForm.searchSubjectId);
    }

    String searchKind = null;
    if (workingForm.searchKind != null && !"all".equals(workingForm.searchKind)) {
        searchKind = workingForm.searchKind;
    }

    String searchAuth = null;
    if (workingForm.searchAuth != null && !"all".equals(workingForm.searchAuth)) {
        searchAuth = workingForm.searchAuth;
    }

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
    Date dateFrom = null;
    if (StringUtils.isNotEmpty(workingForm.searchDayFrom)) {
        try {
            dateFrom = sdf.parse(workingForm.searchDayFrom);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    Date dateTo = null;
    if (StringUtils.isNotEmpty(workingForm.searchDayTo)) {
        try {
            dateTo = sdf.parse(workingForm.searchDayTo);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    List<Work> workList = workDao.selectForSearch(searchUserId, searchSubjectId, searchKind, searchAuth,
            dateFrom, dateTo, null);

    workingForm.workList = workList;

    // ?
    BigDecimal hour = new BigDecimal(0);
    for (Work work : workList) {
        hour = hour.add(work.workHour);
    }
    workingForm.workHourTotal = hour;

    // ??
    UserInfoDao userInfoDao = SingletonS2Container.getComponent(UserInfoDao.class);
    SubjectDao subjectDao = SingletonS2Container.getComponent(SubjectDao.class);

    workingForm.userInfoList = userInfoDao.selectForSearch(null, null);
    workingForm.subjectList = subjectDao.selectForSearch(null, null);

    return "workList.jsp";
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.directiveCouncil.SummariesControlAction.java

private BigDecimal getDeclaredLesson(Double percentage, Shift shift, BigDecimal lessonGiven,
        LocalDate oneWeekBeforeToday) {
    BigDecimal shiftLessonSum = EMPTY;
    for (Lesson lesson : shift.getAssociatedLessonsSet()) {
        shiftLessonSum = shiftLessonSum.add(
                BigDecimal.valueOf(lesson.getAllLessonDatesUntil(new YearMonthDay(oneWeekBeforeToday)).size()));
    }/*  www  . j a v a2  s  .  c o m*/
    return lessonGiven.add(BigDecimal.valueOf((percentage / 100)).multiply(shiftLessonSum));
}

From source file:org.key2gym.business.services.OrdersServiceBean.java

public static OrderDTO wrapOrderEntity(OrderEntity order) {

    OrderDTO orderDTO = new OrderDTO();
    orderDTO.setId(order.getId());//from  www  .  j  a v  a 2s.  c  o m
    orderDTO.setDate(new DateMidnight(order.getDate()));
    orderDTO.setPayment(order.getPayment().setScale(2));

    /*
     * Order lines
     */
    List<OrderLineDTO> orderLineDTOs = new LinkedList<OrderLineDTO>();

    BigDecimal total = BigDecimal.ZERO.setScale(2);

    if (order.getOrderLines() != null) {
        for (OrderLine orderLine : order.getOrderLines()) {
            Item item = orderLine.getItem();
            Discount discount = orderLine.getDiscount();

            OrderLineDTO orderLineDTO = new OrderLineDTO();
            orderLineDTO.setId(orderLine.getId());
            orderLineDTO.setItemId(item.getId());
            orderLineDTO.setItemTitle(item.getTitle());
            orderLineDTO.setItemPrice(item.getPrice());
            if (discount != null) {
                orderLineDTO.setDiscountPercent(discount.getPercent());
                orderLineDTO.setDiscountTitle(discount.getTitle());
                orderLineDTO.setDiscountId(discount.getId());
            }
            orderLineDTO.setQuantity(orderLine.getQuantity());
            orderLineDTO.setTotal(orderLine.getTotal());

            total = total.add(orderLine.getTotal());

            orderLineDTOs.add(orderLineDTO);
        }
    }
    orderDTO.setOrderLines(orderLineDTOs);

    /*
     * Client
     */
    if (order.getClient() != null) {
        orderDTO.setClientId(order.getClient().getId());
        orderDTO.setClientFullName(order.getClient().getFullName());
    }

    /*
     * Attendance
     */
    if (order.getAttendance() != null) {
        orderDTO.setAttendanceId(order.getAttendance().getId());
        orderDTO.setKeyTitle(order.getAttendance().getKey().getTitle());
    }

    /*
     * Total
     */
    orderDTO.setTotal(total);

    /*
     * Due
     */
    orderDTO.setDue(total.subtract(order.getPayment()));

    /*
     * Money balance
     */
    if (order.getClient() != null) {
        orderDTO.setMoneyBalance(order.getClient().getMoneyBalance().setScale(2).underlying());
    }
    return orderDTO;
}

From source file:com.liato.bankdroid.banking.Bank.java

public BigDecimal getBalance() {
    if (STATIC_BALANCE) {
        return balance;
    } else {//w  w  w.  j  av  a2s  .  c o  m
        BigDecimal bal = new BigDecimal(0);
        for (Account account : accounts) {
            if (account.getType() == Account.REGULAR || account.getType() == Account.CCARD) {
                if (!account.isHidden()
                        && (account.getAliasfor() == null || account.getAliasfor().length() == 0)) {
                    bal = bal.add(account.getBalance());
                }
            }
        }
        return bal;
    }
}

From source file:net.sourceforge.fenixedu.domain.Shift.java

public BigDecimal getUnitHours() {
    BigDecimal hours = BigDecimal.ZERO;
    Collection<Lesson> lessons = getAssociatedLessonsSet();
    for (Lesson lesson : lessons) {
        hours = hours.add(lesson.getUnitHours());
    }/*from w  ww. ja va  2  s .c o m*/
    return hours;
}

From source file:org.openvpms.archetype.rules.finance.account.CustomerAccountRules.java

/**
 * Calculates a new balance for a customer from the current outstanding
 * balance and a running total.//from   www . j  av  a  2  s.c  om
 * If the new balance is:
 * <ul>
 * <li>&lt; 0 returns 0.00 for payments, or -balance for refunds</li>
 * <li>&gt; 0 returns 0.00 for refunds</li>
 * </ul>
 *
 * @param customer the customer
 * @param total    the running total
 * @param payment  if {@code true} indicates the total is for a payment,
 *                 if {@code false} indicates it is for a refund
 * @return the new balance
 * @throws ArchetypeServiceException for any archetype service error
 */
public BigDecimal getBalance(Party customer, BigDecimal total, boolean payment) {
    BigDecimal balance = getBalance(customer);
    BigDecimal result;
    if (payment) {
        result = balance.subtract(total);
    } else {
        result = balance.add(total);
    }
    if (result.signum() == -1) {
        result = (payment) ? BigDecimal.ZERO : result.negate();
    } else if (result.signum() == 1 && !payment) {
        result = BigDecimal.ZERO;
    }
    return result;
}