Line 1... |
Line 1... |
1 |
/*
|
1 |
/*
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
3 |
*
|
3 |
*
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
5 |
*
|
5 |
*
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
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
|
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
|
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.
|
9 |
* language governing permissions and limitations under the License.
|
Line 29... |
Line 29... |
29 |
public enum TypeTotalAcompteProvider {
|
29 |
public enum TypeTotalAcompteProvider {
|
30 |
HT, TTC;
|
30 |
HT, TTC;
|
31 |
};
|
31 |
};
|
32 |
|
32 |
|
33 |
private final TypeTotalAcompteProvider type;
|
33 |
private final TypeTotalAcompteProvider type;
|
- |
|
34 |
private boolean old;
|
34 |
|
35 |
|
35 |
public TotalAcompteProvider(TypeTotalAcompteProvider t) {
|
36 |
public TotalAcompteProvider(TypeTotalAcompteProvider t, boolean old) {
|
36 |
this.type = t;
|
37 |
this.type = t;
|
- |
|
38 |
this.old = old;
|
37 |
}
|
39 |
}
|
38 |
|
40 |
|
39 |
public Object getValue(SpreadSheetCellValueContext context) {
|
41 |
public Object getValue(SpreadSheetCellValueContext context) {
|
40 |
SQLRowAccessor row = context.getRow();
|
42 |
SQLRowAccessor row = context.getRow();
|
41 |
Calendar c = row.getDate("DATE");
|
43 |
Calendar c = row.getDate("DATE");
|
42 |
|
44 |
|
43 |
Collection<? extends SQLRowAccessor> rows = row.getReferentRows(row.getTable().getTable("TR_COMMANDE_CLIENT"));
|
45 |
Collection<? extends SQLRowAccessor> rows = row.getReferentRows(row.getTable().getTable("TR_COMMANDE_CLIENT"));
|
44 |
long total = 0;
|
46 |
long total = 0;
|
45 |
Set<SQLRowAccessor> facture = new HashSet<SQLRowAccessor>();
|
47 |
Set<SQLRowAccessor> facture = new HashSet<SQLRowAccessor>();
|
46 |
facture.add(row);
|
- |
|
- |
|
48 |
|
47 |
for (SQLRowAccessor sqlRowAccessor : rows) {
|
49 |
for (SQLRowAccessor sqlRowAccessor : rows) {
|
48 |
total += getPreviousAcompte(sqlRowAccessor.getForeign("ID_COMMANDE_CLIENT"), facture, c, row);
|
50 |
total += getPreviousAcompte(sqlRowAccessor.getForeign("ID_COMMANDE_CLIENT"), facture, c, row);
|
49 |
}
|
51 |
}
|
50 |
|
52 |
|
51 |
return new BigDecimal(total).movePointLeft(2);
|
53 |
return new BigDecimal(total).movePointLeft(2);
|
52 |
}
|
54 |
}
|
53 |
|
55 |
|
54 |
public static void register() {
|
56 |
public static void register() {
|
- |
|
57 |
SpreadSheetCellValueProviderManager.put("sales.account.total.cumul", new TotalAcompteProvider(TypeTotalAcompteProvider.HT, true));
|
- |
|
58 |
SpreadSheetCellValueProviderManager.put("sales.account.total.cumul.ttc", new TotalAcompteProvider(TypeTotalAcompteProvider.TTC, true));
|
55 |
SpreadSheetCellValueProviderManager.put("sales.account.total", new TotalAcompteProvider(TypeTotalAcompteProvider.HT));
|
59 |
SpreadSheetCellValueProviderManager.put("sales.account.total", new TotalAcompteProvider(TypeTotalAcompteProvider.HT, false));
|
56 |
SpreadSheetCellValueProviderManager.put("sales.account.total.ttc", new TotalAcompteProvider(TypeTotalAcompteProvider.TTC));
|
60 |
SpreadSheetCellValueProviderManager.put("sales.account.total.ttc", new TotalAcompteProvider(TypeTotalAcompteProvider.TTC, false));
|
57 |
}
|
61 |
}
|
58 |
|
62 |
|
59 |
public long getPreviousAcompte(SQLRowAccessor sqlRowAccessor, Set<SQLRowAccessor> alreadyAdded, Calendar c, SQLRowAccessor origin) {
|
63 |
public long getPreviousAcompte(SQLRowAccessor sqlRowAccessor, Set<SQLRowAccessor> alreadyAdded, Calendar c, SQLRowAccessor origin) {
|
60 |
if (sqlRowAccessor == null || sqlRowAccessor.isUndefined()) {
|
64 |
if (sqlRowAccessor == null || sqlRowAccessor.isUndefined()) {
|
61 |
return 0L;
|
65 |
return 0L;
|
Line 63... |
Line 67... |
63 |
Collection<? extends SQLRowAccessor> rows = sqlRowAccessor.getReferentRows(sqlRowAccessor.getTable().getTable("TR_COMMANDE_CLIENT"));
|
67 |
Collection<? extends SQLRowAccessor> rows = sqlRowAccessor.getReferentRows(sqlRowAccessor.getTable().getTable("TR_COMMANDE_CLIENT"));
|
64 |
long l = 0;
|
68 |
long l = 0;
|
65 |
for (SQLRowAccessor sqlRowAccessor2 : rows) {
|
69 |
for (SQLRowAccessor sqlRowAccessor2 : rows) {
|
66 |
SQLRowAccessor rowFact = sqlRowAccessor2.getForeign("ID_SAISIE_VENTE_FACTURE");
|
70 |
SQLRowAccessor rowFact = sqlRowAccessor2.getForeign("ID_SAISIE_VENTE_FACTURE");
|
67 |
|
71 |
|
- |
|
72 |
final boolean sameFact = rowFact.getDate("DATE").equals(c) && rowFact.getID() < origin.getID();
|
68 |
if (rowFact != null && !rowFact.isUndefined() && !alreadyAdded.contains(rowFact)
|
73 |
final boolean oldFact = rowFact.getID() == origin.getID() && this.old;
|
69 |
&& (rowFact.getDate("DATE").before(c) || (rowFact.getDate("DATE").equals(c) && rowFact.getID() < origin.getID()))) {
|
74 |
if (rowFact != null && !rowFact.isUndefined() && !alreadyAdded.contains(rowFact) && (rowFact.getDate("DATE").before(c) || sameFact || oldFact)) {
|
70 |
alreadyAdded.add(rowFact);
|
75 |
alreadyAdded.add(rowFact);
|
71 |
l += this.type == TypeTotalAcompteProvider.HT ? rowFact.getLong("T_HT") : rowFact.getLong("T_TTC");
|
76 |
l += this.type == TypeTotalAcompteProvider.HT ? rowFact.getLong("T_HT") : rowFact.getLong("T_TTC");
|
72 |
}
|
77 |
}
|
73 |
}
|
78 |
}
|
74 |
return l;
|
79 |
return l;
|
75 |
}
|
80 |
}
|
76 |
|
- |
|
77 |
}
|
81 |
}
|