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();
}
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;
}
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);
}
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());
}
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);
}
Aggregations