OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 80 Rev 142
Line 21... Line 21...
21
import java.math.BigDecimal;
21
import java.math.BigDecimal;
22
import java.util.Collection;
22
import java.util.Collection;
23
 
23
 
24
public class TotalCommandeClientProvider implements SpreadSheetCellValueProvider {
24
public class TotalCommandeClientProvider implements SpreadSheetCellValueProvider {
25
 
25
 
-
 
26
    public enum TypeTotalCommandeClientProvider {
-
 
27
        HT, TTC;
-
 
28
    };
-
 
29
 
-
 
30
    private final TypeTotalCommandeClientProvider type;
-
 
31
 
-
 
32
    public TotalCommandeClientProvider(TypeTotalCommandeClientProvider t) {
-
 
33
        this.type = t;
-
 
34
    }
-
 
35
 
26
    public Object getValue(SpreadSheetCellValueContext context) {
36
    public Object getValue(SpreadSheetCellValueContext context) {
27
        SQLRowAccessor row = context.getRow();
37
        SQLRowAccessor row = context.getRow();
28
        Collection<? extends SQLRowAccessor> rows = row.getReferentRows(row.getTable().getTable("TR_COMMANDE_CLIENT"));
38
        Collection<? extends SQLRowAccessor> rows = row.getReferentRows(row.getTable().getTable("TR_COMMANDE_CLIENT"));
29
        long total = 0;
39
        long total = 0;
30
        for (SQLRowAccessor sqlRowAccessor : rows) {
40
        for (SQLRowAccessor sqlRowAccessor : rows) {
31
            if (!sqlRowAccessor.isForeignEmpty("ID_COMMANDE_CLIENT")) {
41
            if (!sqlRowAccessor.isForeignEmpty("ID_COMMANDE_CLIENT")) {
32
                SQLRowAccessor rowCmd = sqlRowAccessor.getForeign("ID_COMMANDE_CLIENT");
42
                SQLRowAccessor rowCmd = sqlRowAccessor.getForeign("ID_COMMANDE_CLIENT");
33
                total += rowCmd.getLong("T_HT");
43
                total += (this.type == TypeTotalCommandeClientProvider.HT ? rowCmd.getLong("T_HT") : rowCmd.getLong("T_TTC"));
34
            }
44
            }
35
        }
45
        }
36
        return new BigDecimal(total).movePointLeft(2);
46
        return new BigDecimal(total).movePointLeft(2);
37
    }
47
    }
38
 
48
 
39
    public static void register() {
49
    public static void register() {
40
        SpreadSheetCellValueProviderManager.put("sales.account.command.total", new TotalCommandeClientProvider());
50
        SpreadSheetCellValueProviderManager.put("sales.account.command.total", new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.HT));
-
 
51
        SpreadSheetCellValueProviderManager.put("sales.account.command.total.ttc", new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.TTC));
41
    }
52
    }
42
 
53
 
43
}
54
}