OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 180
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 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.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.generationDoc.provider;
14
 package org.openconcerto.erp.generationDoc.provider;
15
 
15
 
16
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
16
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
17
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProvider;
17
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProvider;
18
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
18
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
19
import org.openconcerto.sql.model.SQLRowAccessor;
19
import org.openconcerto.sql.model.SQLRowAccessor;
20
 
20
 
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 {
26
    public enum TypeTotalCommandeClientProvider {
27
        HT, TTC;
27
        HT, TTC, TVA;
28
    };
28
    };
29
 
29
 
30
    private final TypeTotalCommandeClientProvider type;
30
    private final TypeTotalCommandeClientProvider type;
31
 
31
 
32
    public TotalCommandeClientProvider(TypeTotalCommandeClientProvider t) {
32
    public TotalCommandeClientProvider(TypeTotalCommandeClientProvider t) {
33
        this.type = t;
33
        this.type = t;
34
    }
34
    }
35
 
35
 
36
    public Object getValue(SpreadSheetCellValueContext context) {
36
    public Object getValue(SpreadSheetCellValueContext context) {
37
        SQLRowAccessor row = context.getRow();
37
        SQLRowAccessor row = context.getRow();
38
        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"));
39
        long total = 0;
39
        long total = 0;
40
        for (SQLRowAccessor sqlRowAccessor : rows) {
40
        for (SQLRowAccessor sqlRowAccessor : rows) {
41
            if (!sqlRowAccessor.isForeignEmpty("ID_COMMANDE_CLIENT")) {
41
            if (!sqlRowAccessor.isForeignEmpty("ID_COMMANDE_CLIENT")) {
42
                SQLRowAccessor rowCmd = sqlRowAccessor.getForeign("ID_COMMANDE_CLIENT");
42
                SQLRowAccessor rowCmd = sqlRowAccessor.getForeign("ID_COMMANDE_CLIENT");
-
 
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");
43
                total += (this.type == TypeTotalCommandeClientProvider.HT ? rowCmd.getLong("T_HT") : rowCmd.getLong("T_TTC"));
47
                } else if (this.type == TypeTotalCommandeClientProvider.TTC) {
-
 
48
                    total += rowCmd.getLong("T_TTC");
-
 
49
                }
-
 
50
 
44
            }
51
            }
45
        }
52
        }
46
        return new BigDecimal(total).movePointLeft(2);
53
        return new BigDecimal(total).movePointLeft(2);
47
    }
54
    }
48
 
55
 
49
    public static void register() {
56
    public static void register() {
50
        SpreadSheetCellValueProviderManager.put("sales.account.command.total", new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.HT));
57
        SpreadSheetCellValueProviderManager.put("sales.account.command.total", new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.HT));
51
        SpreadSheetCellValueProviderManager.put("sales.account.command.total.ttc", new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.TTC));
58
        SpreadSheetCellValueProviderManager.put("sales.account.command.total.ttc", new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.TTC));
-
 
59
        SpreadSheetCellValueProviderManager.put("sales.account.command.total.tva", new TotalCommandeClientProvider(TypeTotalCommandeClientProvider.TVA));
52
    }
60
    }
53
 
61
 
54
}
62
}