80 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
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;
|
|
|
19 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
20 |
|
|
|
21 |
import java.math.BigDecimal;
|
|
|
22 |
import java.util.Collection;
|
|
|
23 |
|
|
|
24 |
public class TotalCommandeClientProvider implements SpreadSheetCellValueProvider {
|
|
|
25 |
|
142 |
ilm |
26 |
public enum TypeTotalCommandeClientProvider {
|
180 |
ilm |
27 |
HT, TTC, TVA;
|
142 |
ilm |
28 |
};
|
|
|
29 |
|
|
|
30 |
private final TypeTotalCommandeClientProvider type;
|
|
|
31 |
|
|
|
32 |
public TotalCommandeClientProvider(TypeTotalCommandeClientProvider t) {
|
|
|
33 |
this.type = t;
|
|
|
34 |
}
|
|
|
35 |
|
80 |
ilm |
36 |
public Object getValue(SpreadSheetCellValueContext context) {
|
|
|
37 |
SQLRowAccessor row = context.getRow();
|
|
|
38 |
Collection<? extends SQLRowAccessor> rows = row.getReferentRows(row.getTable().getTable("TR_COMMANDE_CLIENT"));
|
|
|
39 |
long total = 0;
|
|
|
40 |
for (SQLRowAccessor sqlRowAccessor : rows) {
|
|
|
41 |
if (!sqlRowAccessor.isForeignEmpty("ID_COMMANDE_CLIENT")) {
|
|
|
42 |
SQLRowAccessor rowCmd = sqlRowAccessor.getForeign("ID_COMMANDE_CLIENT");
|
180 |
ilm |
43 |
if (this.type == TypeTotalCommandeClientProvider.HT) {
|
|
|
44 |
total += rowCmd.getLong("T_HT");
|
|
|
45 |
} else if (this.type == TypeTotalCommandeClientProvider.TVA) {
|
|
|
46 |
total += rowCmd.getLong("T_TVA");
|
|
|
47 |
} else if (this.type == TypeTotalCommandeClientProvider.TTC) {
|
|
|
48 |
total += rowCmd.getLong("T_TTC");
|
|
|
49 |
}
|
|
|
50 |
|
80 |
ilm |
51 |
}
|
|
|
52 |
}
|
|
|
53 |
return new BigDecimal(total).movePointLeft(2);
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
public static void register() {
|
142 |
ilm |
57 |
SpreadSheetCellValueProviderManager.put("sales.account.command.total", new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.HT));
|
|
|
58 |
SpreadSheetCellValueProviderManager.put("sales.account.command.total.ttc", new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.TTC));
|
180 |
ilm |
59 |
SpreadSheetCellValueProviderManager.put("sales.account.command.total.tva", new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.TVA));
|
80 |
ilm |
60 |
}
|
|
|
61 |
|
|
|
62 |
}
|