-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
InvoiceProcessingServiceCompany: add ValidFrom and Percent
Take into account ValidFrom when selecting the correct InvoiceProcessingServiceCompanyConfig #6904
- Loading branch information
1 parent
eb7236f
commit a696010
Showing
6 changed files
with
252 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...tas/invoice/invoiceProcessingServiceCompany/InvoiceProcessingServiceCompanyConfigMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* #%L | ||
* de.metas.business | ||
* %% | ||
* Copyright (C) 2020 metas GmbH | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-2.0.html>. | ||
* #L% | ||
*/ | ||
|
||
package de.metas.invoice.invoiceProcessingServiceCompany; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableListMultimap; | ||
import de.metas.bpartner.BPartnerId; | ||
import lombok.NonNull; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
// TODO tbp: add unit test to see that getting stuff (and entering duplicates work) | ||
/* package */ class InvoiceProcessingServiceCompanyConfigMap | ||
{ | ||
private final ImmutableListMultimap<BPartnerId, InvoiceProcessingServiceCompanyConfig> bpartnersToConfigsSorted; | ||
|
||
public InvoiceProcessingServiceCompanyConfigMap(@NonNull final List<InvoiceProcessingServiceCompanyConfig> configs) | ||
{ | ||
final ImmutableListMultimap.Builder<BPartnerId, InvoiceProcessingServiceCompanyConfig> map = ImmutableListMultimap.builder(); | ||
for (final InvoiceProcessingServiceCompanyConfig config : configs) | ||
{ | ||
for (final BPartnerId partnerId : config.getBPartnerIds()) | ||
{ | ||
map.put(partnerId, config); | ||
} | ||
} | ||
// for ease of access and calculation: sort by ValidFrom | ||
map.orderValuesBy(Comparator.comparing(InvoiceProcessingServiceCompanyConfig::getValidFrom)); | ||
|
||
bpartnersToConfigsSorted = map.build(); | ||
} | ||
|
||
public Optional<InvoiceProcessingServiceCompanyConfig> getByCustomerIdAndDate(@NonNull final BPartnerId customerId, @NonNull final ZonedDateTime validFrom) | ||
{ | ||
final ImmutableList<InvoiceProcessingServiceCompanyConfig> configs = bpartnersToConfigsSorted.get(customerId); | ||
for (int i = configs.size() - 1; i >= 0; i--) | ||
{ | ||
final InvoiceProcessingServiceCompanyConfig config = configs.get(i); | ||
if (config.getValidFrom().isBefore(validFrom) || config.getValidFrom().isEqual(validFrom)) | ||
{ | ||
return Optional.of(config); | ||
} | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.