Search in sources :

Example 1 with ZERO

use of java.math.BigDecimal.ZERO in project betca-tpv-core by miw-upm.

the class TicketServiceIT method tesCreateNotFoundException.

@Test
void tesCreateNotFoundException() {
    AtomicInteger stock = new AtomicInteger();
    StepVerifier.create(this.articleService.read("8400000000093")).consumeNextWith(article -> stock.set(article.getStock())).verifyComplete();
    Shopping shopping = Shopping.builder().barcode("kk").amount(2).discount(BigDecimal.TEN).state(ShoppingState.NOT_COMMITTED).build();
    Ticket ticket = Ticket.builder().cash(new BigDecimal("200")).card(ZERO).voucher(ZERO).note("note").shoppingList(List.of(shopping)).build();
    StepVerifier.create(this.ticketService.create(ticket)).expectError(NotFoundException.class).verify();
    StepVerifier.create(this.articleService.read("8400000000093")).assertNext(article -> assertEquals(stock.get(), article.getStock())).verifyComplete();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) UserMicroservice(es.upm.miw.betca_tpv_core.domain.rest.UserMicroservice) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) StepVerifier(reactor.test.StepVerifier) Autowired(org.springframework.beans.factory.annotation.Autowired) ZERO(java.math.BigDecimal.ZERO) Mono(reactor.core.publisher.Mono) Test(org.junit.jupiter.api.Test) es.upm.miw.betca_tpv_core.domain.model(es.upm.miw.betca_tpv_core.domain.model) BDDMockito(org.mockito.BDDMockito) BigDecimal(java.math.BigDecimal) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NotFoundException(es.upm.miw.betca_tpv_core.domain.exceptions.NotFoundException) TestConfig(es.upm.miw.betca_tpv_core.TestConfig) MockBean(org.springframework.boot.test.mock.mockito.MockBean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NotFoundException(es.upm.miw.betca_tpv_core.domain.exceptions.NotFoundException) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 2 with ZERO

use of java.math.BigDecimal.ZERO in project urlaubsverwaltung by synyx.

the class VacationDaysService method getUsedDaysBetweenTwoMilestones.

BigDecimal getUsedDaysBetweenTwoMilestones(Person person, LocalDate firstMilestone, LocalDate lastMilestone) {
    // get all applications for leave for a person
    final List<Application> allApplicationsForLeave = applicationService.getApplicationsForACertainPeriodAndPerson(firstMilestone, lastMilestone, person);
    // filter them since only WAITING, ALLOWED and ALLOWED_CANCELLATION_REQUESTED applications for leave of type holiday are relevant
    final List<Application> applicationsForLeave = allApplicationsForLeave.stream().filter(application -> HOLIDAY.equals(application.getVacationType().getCategory()) && // TODO and what is with the TEMPORARY_ALLOWED?
    (application.hasStatus(WAITING) || application.hasStatus(ALLOWED) || application.hasStatus(ALLOWED_CANCELLATION_REQUESTED))).collect(toList());
    BigDecimal usedDays = ZERO;
    for (Application applicationForLeave : applicationsForLeave) {
        LocalDate startDate = applicationForLeave.getStartDate();
        LocalDate endDate = applicationForLeave.getEndDate();
        if (startDate.isBefore(firstMilestone)) {
            startDate = firstMilestone;
        }
        if (endDate.isAfter(lastMilestone)) {
            endDate = lastMilestone;
        }
        usedDays = usedDays.add(workDaysCountService.getWorkDaysCount(applicationForLeave.getDayLength(), startDate, endDate, person));
    }
    return usedDays;
}
Also used : Person(org.synyx.urlaubsverwaltung.person.Person) DateUtil.getLastDayOfMonth(org.synyx.urlaubsverwaltung.util.DateUtil.getLastDayOfMonth) DateUtil.isBeforeApril(org.synyx.urlaubsverwaltung.util.DateUtil.isBeforeApril) Autowired(org.springframework.beans.factory.annotation.Autowired) ZERO(java.math.BigDecimal.ZERO) APRIL(java.time.Month.APRIL) BigDecimal(java.math.BigDecimal) DateUtil.getFirstDayOfMonth(org.synyx.urlaubsverwaltung.util.DateUtil.getFirstDayOfMonth) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ALLOWED_CANCELLATION_REQUESTED(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.ALLOWED_CANCELLATION_REQUESTED) MARCH(java.time.Month.MARCH) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) Clock(java.time.Clock) Optional(java.util.Optional) Application(org.synyx.urlaubsverwaltung.application.application.Application) JANUARY(java.time.Month.JANUARY) HOLIDAY(org.synyx.urlaubsverwaltung.application.vacationtype.VacationCategory.HOLIDAY) ApplicationService(org.synyx.urlaubsverwaltung.application.application.ApplicationService) WorkDaysCountService(org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService) DECEMBER(java.time.Month.DECEMBER) ALLOWED(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.ALLOWED) WAITING(org.synyx.urlaubsverwaltung.application.application.ApplicationStatus.WAITING) Application(org.synyx.urlaubsverwaltung.application.application.Application) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 3 with ZERO

use of java.math.BigDecimal.ZERO in project Employee-Self-Service by nysenate.

the class EssAllowanceService method getAttendRecordAllowanceUsage.

/**
 * Get estimated hours and money used by the given attendance record
 * Add estimated hours/money to the given allowance usage
 * @param allowanceUsage AllowanceUsage
 * @param record AttendanceRecord
 * @return Pair<BigDecimal, BigDecimal> tuple containing used hours and money respectively
 */
private Pair<BigDecimal, BigDecimal> getAttendRecordAllowanceUsage(AllowanceUsage allowanceUsage, AttendanceRecord record) {
    // Get the highest temporary salary rate that was effective during the attendance record
    BigDecimal appliedRate = allowanceUsage.getSalaryRecs().stream().filter(salaryRec -> salaryRec.getPayType() == TE).filter(salaryRec -> RangeUtils.intersects(salaryRec.getEffectiveRange(), record.getDateRange())).map(SalaryRec::getSalaryRate).max(BigDecimal::compareTo).orElse(ZERO);
    BigDecimal attendRecordHours = record.getWorkHours().orElse(ZERO);
    BigDecimal attendRecordMoney = attendRecordHours.multiply(appliedRate);
    return Pair.of(attendRecordHours, attendRecordMoney);
}
Also used : AllowanceUsage(gov.nysenate.ess.time.model.allowances.AllowanceUsage) TimeRecord(gov.nysenate.ess.time.model.attendance.TimeRecord) java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) RangeUtils(gov.nysenate.ess.core.util.RangeUtils) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) NONE(gov.nysenate.ess.core.util.SortOrder.NONE) BigDecimal(java.math.BigDecimal) PeriodAllowanceUsage(gov.nysenate.ess.time.model.allowances.PeriodAllowanceUsage) Pair(org.apache.commons.lang3.tuple.Pair) Service(org.springframework.stereotype.Service) EmpTransactionService(gov.nysenate.ess.core.service.transaction.EmpTransactionService) DateUtils(gov.nysenate.ess.core.util.DateUtils) AttendanceDao(gov.nysenate.ess.time.dao.attendance.AttendanceDao) TE(gov.nysenate.ess.core.model.payroll.PayType.TE) com.google.common.collect(com.google.common.collect) PayPeriod(gov.nysenate.ess.core.model.period.PayPeriod) AttendanceRecord(gov.nysenate.ess.time.model.attendance.AttendanceRecord) Logger(org.slf4j.Logger) AF(gov.nysenate.ess.core.model.period.PayPeriodType.AF) TransactionCode(gov.nysenate.ess.core.model.transaction.TransactionCode) TimeRecordStatus(gov.nysenate.ess.time.model.attendance.TimeRecordStatus) TimeEntry(gov.nysenate.ess.time.model.attendance.TimeEntry) ZERO(java.math.BigDecimal.ZERO) TimeRecordService(gov.nysenate.ess.time.service.attendance.TimeRecordService) Collectors(java.util.stream.Collectors) HourlyWorkPayment(gov.nysenate.ess.time.model.allowances.HourlyWorkPayment) SalaryRec(gov.nysenate.ess.core.model.payroll.SalaryRec) TransactionHistory(gov.nysenate.ess.core.model.transaction.TransactionHistory) LocalDate(java.time.LocalDate) TransactionRecord(gov.nysenate.ess.core.model.transaction.TransactionRecord) PayPeriodService(gov.nysenate.ess.core.service.period.PayPeriodService) SalaryRec(gov.nysenate.ess.core.model.payroll.SalaryRec) BigDecimal(java.math.BigDecimal)

Example 4 with ZERO

use of java.math.BigDecimal.ZERO in project Employee-Self-Service by nysenate.

the class EssAllowanceService method getHourlyPayments.

/**
 * Get a list of hourly work payments that are applicable to work performed in the given year
 * @param year int
 * @return List<HourlyWorkPayment>
 */
private static List<HourlyWorkPayment> getHourlyPayments(int year, TransactionHistory transHistory) {
    LocalDate prevYearStart = LocalDate.of(year - 1, 1, 1);
    LocalDate nextYearEnd = LocalDate.of(year + 1, 12, 31);
    Range<LocalDate> auditDateRange = Range.closed(prevYearStart, nextYearEnd);
    Range<LocalDate> yearRange = DateUtils.yearDateRange(year);
    List<TransactionRecord> effectiveRecords = transHistory.getRecords(TransactionCode.HWT).stream().filter(record -> auditDateRange.contains(record.getAuditDate().toLocalDate())).collect(toList());
    Map<LocalDate, TransactionRecord> priorYearPayments = transHistory.getRecords(TransactionCode.PYA).stream().collect(Collectors.toMap(TransactionRecord::getEffectDate, Function.identity()));
    // Return the HourlyWorkPayments with work date ranges that overlap with the requested year
    return effectiveRecords.stream().map(record -> new HourlyWorkPayment(record.getAuditDate(), record.getEffectDate(), record.getLocalDateValue("DTENDTE"), record.getBigDecimalValue("NUHRHRSPD"), new BigDecimal(transHistory.latestValueOf("MOTOTHRSPD", record.getEffectDate(), false).orElse("0")), priorYearPayments.containsKey(record.getEffectDate()) ? priorYearPayments.get(record.getEffectDate()).getBigDecimalValue("MOPRIORYRTE") : ZERO)).filter(payment -> RangeUtils.intersects(yearRange, payment.getWorkingRange())).sorted(Comparator.comparing(HourlyWorkPayment::getEffectDate)).collect(toList());
}
Also used : AllowanceUsage(gov.nysenate.ess.time.model.allowances.AllowanceUsage) TimeRecord(gov.nysenate.ess.time.model.attendance.TimeRecord) java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) RangeUtils(gov.nysenate.ess.core.util.RangeUtils) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) NONE(gov.nysenate.ess.core.util.SortOrder.NONE) BigDecimal(java.math.BigDecimal) PeriodAllowanceUsage(gov.nysenate.ess.time.model.allowances.PeriodAllowanceUsage) Pair(org.apache.commons.lang3.tuple.Pair) Service(org.springframework.stereotype.Service) EmpTransactionService(gov.nysenate.ess.core.service.transaction.EmpTransactionService) DateUtils(gov.nysenate.ess.core.util.DateUtils) AttendanceDao(gov.nysenate.ess.time.dao.attendance.AttendanceDao) TE(gov.nysenate.ess.core.model.payroll.PayType.TE) com.google.common.collect(com.google.common.collect) PayPeriod(gov.nysenate.ess.core.model.period.PayPeriod) AttendanceRecord(gov.nysenate.ess.time.model.attendance.AttendanceRecord) Logger(org.slf4j.Logger) AF(gov.nysenate.ess.core.model.period.PayPeriodType.AF) TransactionCode(gov.nysenate.ess.core.model.transaction.TransactionCode) TimeRecordStatus(gov.nysenate.ess.time.model.attendance.TimeRecordStatus) TimeEntry(gov.nysenate.ess.time.model.attendance.TimeEntry) ZERO(java.math.BigDecimal.ZERO) TimeRecordService(gov.nysenate.ess.time.service.attendance.TimeRecordService) Collectors(java.util.stream.Collectors) HourlyWorkPayment(gov.nysenate.ess.time.model.allowances.HourlyWorkPayment) SalaryRec(gov.nysenate.ess.core.model.payroll.SalaryRec) TransactionHistory(gov.nysenate.ess.core.model.transaction.TransactionHistory) LocalDate(java.time.LocalDate) TransactionRecord(gov.nysenate.ess.core.model.transaction.TransactionRecord) PayPeriodService(gov.nysenate.ess.core.service.period.PayPeriodService) LocalDate(java.time.LocalDate) TransactionRecord(gov.nysenate.ess.core.model.transaction.TransactionRecord) BigDecimal(java.math.BigDecimal) HourlyWorkPayment(gov.nysenate.ess.time.model.allowances.HourlyWorkPayment)

Example 5 with ZERO

use of java.math.BigDecimal.ZERO in project Employee-Self-Service by nysenate.

the class EssAllowanceService method getTimeRecordAllowanceUsage.

/**
 * Get hours and money used by the given time records to the given allowance usage object.
 *
 * @param allowanceUsage {@link AllowanceUsage}
 * @param timeRecords {@link Collection<TimeRecord>}
 * @param validDates {@link RangeSet<LocalDate>}
 *
 * @return Pair<BigDecimal, BigDecimal> tuple containing used hours and money respectively
 */
private Pair<BigDecimal, BigDecimal> getTimeRecordAllowanceUsage(AllowanceUsage allowanceUsage, Collection<TimeRecord> timeRecords, RangeSet<LocalDate> validDates) {
    // Get non empty time entries falling within the set of valid dates
    Collection<TimeEntry> timeEntries = timeRecords.stream().filter(tRec -> validDates.intersects(tRec.getDateRange())).map(TimeRecord::getTimeEntries).flatMap(Collection::stream).filter(e -> e.getPayType() == TE && validDates.contains(e.getDate()) && !e.isEmpty()).collect(toList());
    RangeSet<LocalDate> appliedDates = TreeRangeSet.create();
    BigDecimal recordHours = ZERO;
    BigDecimal recordMoney = ZERO;
    // Add up hours and calculated payment for submitted time records that have not been paid out yet
    for (TimeEntry entry : timeEntries) {
        recordHours = recordHours.add(entry.getWorkHours().orElse(ZERO));
        recordMoney = recordMoney.add(allowanceUsage.getEntryCost(entry));
        appliedDates.add(Range.closedOpen(entry.getDate(), entry.getDate().plusDays(1)));
    }
    return Pair.of(recordHours, recordMoney);
}
Also used : AllowanceUsage(gov.nysenate.ess.time.model.allowances.AllowanceUsage) TimeRecord(gov.nysenate.ess.time.model.attendance.TimeRecord) java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) RangeUtils(gov.nysenate.ess.core.util.RangeUtils) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) NONE(gov.nysenate.ess.core.util.SortOrder.NONE) BigDecimal(java.math.BigDecimal) PeriodAllowanceUsage(gov.nysenate.ess.time.model.allowances.PeriodAllowanceUsage) Pair(org.apache.commons.lang3.tuple.Pair) Service(org.springframework.stereotype.Service) EmpTransactionService(gov.nysenate.ess.core.service.transaction.EmpTransactionService) DateUtils(gov.nysenate.ess.core.util.DateUtils) AttendanceDao(gov.nysenate.ess.time.dao.attendance.AttendanceDao) TE(gov.nysenate.ess.core.model.payroll.PayType.TE) com.google.common.collect(com.google.common.collect) PayPeriod(gov.nysenate.ess.core.model.period.PayPeriod) AttendanceRecord(gov.nysenate.ess.time.model.attendance.AttendanceRecord) Logger(org.slf4j.Logger) AF(gov.nysenate.ess.core.model.period.PayPeriodType.AF) TransactionCode(gov.nysenate.ess.core.model.transaction.TransactionCode) TimeRecordStatus(gov.nysenate.ess.time.model.attendance.TimeRecordStatus) TimeEntry(gov.nysenate.ess.time.model.attendance.TimeEntry) ZERO(java.math.BigDecimal.ZERO) TimeRecordService(gov.nysenate.ess.time.service.attendance.TimeRecordService) Collectors(java.util.stream.Collectors) HourlyWorkPayment(gov.nysenate.ess.time.model.allowances.HourlyWorkPayment) SalaryRec(gov.nysenate.ess.core.model.payroll.SalaryRec) TransactionHistory(gov.nysenate.ess.core.model.transaction.TransactionHistory) LocalDate(java.time.LocalDate) TransactionRecord(gov.nysenate.ess.core.model.transaction.TransactionRecord) PayPeriodService(gov.nysenate.ess.core.service.period.PayPeriodService) TimeEntry(gov.nysenate.ess.time.model.attendance.TimeEntry) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Aggregations

ZERO (java.math.BigDecimal.ZERO)22 BigDecimal (java.math.BigDecimal)19 List (java.util.List)14 Optional (java.util.Optional)13 Autowired (org.springframework.beans.factory.annotation.Autowired)12 Collectors (java.util.stream.Collectors)8 Test (org.junit.jupiter.api.Test)8 Stream (java.util.stream.Stream)7 CurrencyPairDTO (tech.cassandre.trading.bot.dto.util.CurrencyPairDTO)7 Logger (org.slf4j.Logger)6 TickerDTO (tech.cassandre.trading.bot.dto.market.TickerDTO)6 LocalDate (java.time.LocalDate)5 Collections (java.util.Collections)5 TradeDTO (tech.cassandre.trading.bot.dto.trade.TradeDTO)5 FLOOR (java.math.RoundingMode.FLOOR)4 HALF_UP (java.math.RoundingMode.HALF_UP)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)4 Service (org.springframework.stereotype.Service)4 LONG (tech.cassandre.trading.bot.dto.position.PositionTypeDTO.LONG)4