Skip to content

Instantly share code, notes, and snippets.

@carlosble
Created April 21, 2021 17:03
Show Gist options
  • Save carlosble/43adeeb7406d77498876d7e00c73c2cb to your computer and use it in GitHub Desktop.
Save carlosble/43adeeb7406d77498876d7e00c73c2cb to your computer and use it in GitHub Desktop.
class ProjectBillingService {
private final CustomerContract contract;
private final DeveloperHistoryRepository repository;
/*...*/
public ProjectBillingService(DeveloperHistoryRepository repository, CustomerContract contract) {
this.repository = repository;
this.contract = contract;
}
/*...*/
public BigDecimal calculateCost(YearMonth yearMonth){
Date startDate = getStartDate(yearMonth);
Date endDate = getEndDate(yearMonth);
List<DeveloperHistory> history = repository.findBy(contract.id(), startDate, endDate);
return contract.applyFeeTo(developersCost(history, contract, yearMonth));
}
private BigDecimal developersCost(List<DeveloperHistory> history,
CustomerContract contract,
YearMonth yearMonth) {
return history.stream()
.map(developerHistory -> costPerDeveloper(developerHistory,
contract, yearMonth))
.reduce(new BigDecimal(0), BigDecimal::add);
}
private BigDecimal costPerDeveloper(DeveloperHistory developerHistory,
CustomerContract contract,
YearMonth yearMonth){
return multiply(
contract.dailyRateFor(
developerHistory.seniorityLevelOn(yearMonth)),
developerHistory.billableDaysOn(yearMonth, contract.id()));
}
private BigDecimal multiply(BigDecimal dailyRate, float numberOfWorkingDays) {
return dailyRate.multiply(BigDecimal.valueOf(numberOfWorkingDays));
}
private Date getEndDate(YearMonth yearMonth) {
return new Date(); // TODO: implement this
}
private Date getStartDate(YearMonth yearMonth) {
return new Date(); // TODO: implement this
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment