/** * Calculates the net price of the given amount according to its tax rate. * Whether the provided amount is already net or gross is determined by the tax rate. * @param amount the monetary amount * @param taxRate the tax rate corresponding to the {@code amount} * @return the net monetary amount */ public static MonetaryAmount calculateNetPrice(final MonetaryAmount amount, final TaxRate taxRate) { return taxRate.isIncludedInPrice() ? convertGrossToNetPrice(amount, taxRate.getAmount()) : amount; }
/** * Calculates the gross price of the given amount according to its tax rate. * Whether the provided amount is already gross or net is determined by the tax rate. * @param amount the monetary amount * @param taxRate the tax rate corresponding to the {@code amount} * @return the gross monetary amount */ public static MonetaryAmount calculateGrossPrice(final MonetaryAmount amount, final TaxRate taxRate) { return taxRate.isIncludedInPrice() ? amount : convertNetToGrossPrice(amount, taxRate.getAmount()); }
/** * Calculates the gross price of the given amount according to its tax rate. * Whether the provided amount is already gross or net is determined by the tax rate. * @param amount the monetary amount * @param taxRate the tax rate corresponding to the {@code amount} * @return the gross monetary amount */ public static MonetaryAmount calculateGrossPrice(final MonetaryAmount amount, final TaxRate taxRate) { return taxRate.isIncludedInPrice() ? amount : convertNetToGrossPrice(amount, taxRate.getAmount()); }
/** * Calculates the net price of the given amount according to its tax rate. * Whether the provided amount is already net or gross is determined by the tax rate. * @param amount the monetary amount * @param taxRate the tax rate corresponding to the {@code amount} * @return the net monetary amount */ public static MonetaryAmount calculateNetPrice(final MonetaryAmount amount, final TaxRate taxRate) { return taxRate.isIncludedInPrice() ? convertGrossToNetPrice(amount, taxRate.getAmount()) : amount; }
public static TaxRateBuilder of(final TaxRate taxRate) { return of(taxRate.getName(), taxRate.getAmount(), taxRate.isIncludedInPrice(), taxRate.getCountry()) .id(taxRate.getId()) .state(taxRate.getState()); }
public static TaxRateDraftBuilder of(final TaxRate taxRate) { return of(taxRate.getName(), taxRate.getAmount(), taxRate.isIncludedInPrice(), taxRate.getCountry()) .state(taxRate.getState()) .subRates(taxRate.getSubRates()); }
public static TaxRateDraftBuilder of(final TaxRate taxRate) { return of(taxRate.getName(), taxRate.getAmount(), taxRate.isIncludedInPrice(), taxRate.getCountry()) .state(taxRate.getState()) .subRates(taxRate.getSubRates()); }
@Test public void replaceTaxRate() { withUpdateableTaxCategory(client(), taxCategory -> { final TaxRate old = taxCategory.getTaxRates().get(0); final double newAmount = old.getAmount() * 2; final TaxRateDraft newTaxRate = TaxRateDraftBuilder.of(old).amount(newAmount).build(); final TaxCategory updatedTaxCategory = client().executeBlocking(TaxCategoryUpdateCommand.of(taxCategory, ReplaceTaxRate.of(old.getId(), newTaxRate))); final TaxRate actual = updatedTaxCategory.getTaxRates().get(0); assertThat(actual.getCountry()).isEqualTo(old.getCountry()); assertThat(actual.getAmount()).isEqualTo(newAmount); assertThat(actual.getName()).isEqualTo(old.getName()); return updatedTaxCategory; }); } }
@Test public void addTaxRate() { withUpdateableTaxCategory(client(), taxCategory -> { //add tax rate final String name = "ag7"; final CountryCode countryCode = CountryCode.AG; final TaxRateDraft de7 = TaxRateDraftBuilder.of(name, 0.07, true, countryCode).build(); final TaxCategory taxCategoryWithTaRate = client().executeBlocking(TaxCategoryUpdateCommand.of(taxCategory, AddTaxRate.of(de7))); final TaxRate actual = taxCategoryWithTaRate.getTaxRates().stream().filter(rate -> name.equals(rate.getName())).findFirst().get(); assertThat(actual.getCountry()).isEqualTo(countryCode); assertThat(actual.getAmount()).isEqualTo(0.07); assertThat(actual.getId()) .overridingErrorMessage("the tax rate fetched from API has an id") .isNotNull(); assertThat(actual.getName()).isEqualTo(de7.getName()); //remove tax rate final TaxCategory updatedTaxCategory = client().executeBlocking(TaxCategoryUpdateCommand.of(taxCategoryWithTaRate, RemoveTaxRate.of(actual.getId()))); assertThat(updatedTaxCategory.getTaxRates()).matches(rates -> !rates.stream().anyMatch(rate -> name.equals(rate.getName()))); return updatedTaxCategory; }); }
assertThat(taxRate.getId()).isNull(); assertThat(taxRate.getName()).isEqualTo(taxRateName); assertThat(taxRate.getAmount()).isEqualTo(0.2); assertThat(taxRate.isIncludedInPrice()).isFalse(); assertThat(lineItem.getTotalPrice()).isEqualTo(MoneyImpl.ofCents(3000, "EUR"));
final TaxRate taxRate = lineItem.getTaxRate(); s.assertThat(taxRate.getName()).isEqualTo(taxRateName); s.assertThat(taxRate.getAmount()).isEqualTo(rate); s.assertThat(taxRate.getCountry()).isEqualTo(DE); s.assertThat(taxRate.getId()).as("tax rate id").isNull();