132 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
185 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
132 |
ilm |
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.generationDoc.provider;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
|
|
|
17 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProvider;
|
|
|
18 |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
|
142 |
ilm |
19 |
import org.openconcerto.erp.generationDoc.provider.TotalAcompteProvider.TypeTotalAcompteProvider;
|
|
|
20 |
import org.openconcerto.erp.generationDoc.provider.TotalCommandeClientProvider.TypeTotalCommandeClientProvider;
|
132 |
ilm |
21 |
|
|
|
22 |
import java.math.BigDecimal;
|
|
|
23 |
|
|
|
24 |
public class RestantAReglerProvider implements SpreadSheetCellValueProvider {
|
|
|
25 |
|
142 |
ilm |
26 |
final TotalAcompteProvider acompteProv;
|
|
|
27 |
final TotalCommandeClientProvider cmdProvider;
|
132 |
ilm |
28 |
|
142 |
ilm |
29 |
private enum TypeRestantAReglerProvider {
|
|
|
30 |
HT, TTC;
|
|
|
31 |
};
|
|
|
32 |
|
|
|
33 |
private final TypeRestantAReglerProvider type;
|
|
|
34 |
|
|
|
35 |
public RestantAReglerProvider(TypeRestantAReglerProvider t) {
|
|
|
36 |
this.type = t;
|
|
|
37 |
if (this.type == TypeRestantAReglerProvider.HT) {
|
185 |
ilm |
38 |
this.acompteProv = new TotalAcompteProvider(TypeTotalAcompteProvider.HT, false);
|
|
|
39 |
this.cmdProvider = new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.HT);
|
142 |
ilm |
40 |
} else {
|
185 |
ilm |
41 |
this.acompteProv = new TotalAcompteProvider(TypeTotalAcompteProvider.TTC, false);
|
|
|
42 |
this.cmdProvider = new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.TTC);
|
142 |
ilm |
43 |
}
|
|
|
44 |
|
|
|
45 |
}
|
|
|
46 |
|
132 |
ilm |
47 |
public Object getValue(SpreadSheetCellValueContext context) {
|
185 |
ilm |
48 |
Object acompte = this.acompteProv.getValue(context);
|
|
|
49 |
Object cmd = this.cmdProvider.getValue(context);
|
132 |
ilm |
50 |
if (acompte != null && cmd != null) {
|
|
|
51 |
return ((BigDecimal) cmd).subtract((BigDecimal) acompte);
|
|
|
52 |
} else {
|
|
|
53 |
return null;
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
public static void register() {
|
142 |
ilm |
58 |
SpreadSheetCellValueProviderManager.put("sales.account.due", new RestantAReglerProvider(TypeRestantAReglerProvider.HT));
|
|
|
59 |
SpreadSheetCellValueProviderManager.put("sales.account.due.ttc", new RestantAReglerProvider(TypeRestantAReglerProvider.TTC));
|
132 |
ilm |
60 |
}
|
|
|
61 |
|
|
|
62 |
}
|