OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 177
Line 36... Line 36...
36
 
36
 
37
    private static final SQLRowValuesListFetcher getSel() {
37
    private static final SQLRowValuesListFetcher getSel() {
38
        final DBRoot root = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete();
38
        final DBRoot root = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete();
39
        final SQLTable table = root.getTable("TAXE");
39
        final SQLTable table = root.getTable("TAXE");
40
        SQLRowValues rowVals = new SQLRowValues(table);
40
        SQLRowValues rowVals = new SQLRowValues(table);
41
        rowVals.putNulls("TAUX", "CODE", "NOM", "ID_TAXE", "DEFAULT");
41
        rowVals.putNulls("TAUX", "CODE", "NOM", "ID_TAXE", "DEFAULT", "DEFAULT_ACHAT");
42
        List<String> compteFields = Arrays.asList("ID_COMPTE_PCE_COLLECTE", "ID_COMPTE_PCE_DED", "ID_COMPTE_PCE", "ID_COMPTE_PCE_VENTE", "ID_COMPTE_PCE_VENTE_SERVICE", "ID_COMPTE_PCE_COLLECTE_INTRA",
42
        List<String> compteFields = Arrays.asList("ID_COMPTE_PCE_COLLECTE", "ID_COMPTE_PCE_DED", "ID_COMPTE_PCE", "ID_COMPTE_PCE_VENTE", "ID_COMPTE_PCE_VENTE_SERVICE", "ID_COMPTE_PCE_COLLECTE_INTRA",
43
                "ID_COMPTE_PCE_DED_INTRA");
43
                "ID_COMPTE_PCE_DED_INTRA");
44
        for (String foreignFieldName : compteFields) {
44
        for (String foreignFieldName : compteFields) {
45
            rowVals.putRowValues(foreignFieldName).putNulls("NUMERO", "NOM");
45
            rowVals.putRowValues(foreignFieldName).putNulls("NUMERO", "NOM");
46
        }
46
        }
Line 49... Line 49...
49
 
49
 
50
    private final Map<Integer, Float> mapTaux = new HashMap<>();
50
    private final Map<Integer, Float> mapTaux = new HashMap<>();
51
    private final Map<SQLRowAccessor, Float> mapRowTaux = new LinkedHashMap<>();
51
    private final Map<SQLRowAccessor, Float> mapRowTaux = new LinkedHashMap<>();
52
    private static TaxeCache instance;
52
    private static TaxeCache instance;
53
    private SQLRow firstIdTaxe = null;
53
    private SQLRow firstIdTaxe = null;
-
 
54
    private SQLRow firstIdTaxeAchat = null;
54
 
55
 
55
    private TaxeCache() {
56
    private TaxeCache() {
56
        loadCache();
57
        loadCache();
57
    }
58
    }
58
 
59
 
59
    private void loadCache() {
60
    private void loadCache() {
60
 
61
 
61
        this.mapRowTaux.clear();
62
        this.mapRowTaux.clear();
62
        this.mapTaux.clear();
63
        this.mapTaux.clear();
63
        this.firstIdTaxe = null;
64
        this.firstIdTaxe = null;
-
 
65
        this.firstIdTaxeAchat = null;
64
 
66
 
65
        final SQLRowValuesListFetcher sel = getSel();
67
        final SQLRowValuesListFetcher sel = getSel();
66
 
68
 
67
        final List<SQLRowValues> l = sel.fetch();
69
        final List<SQLRowValues> l = sel.fetch();
68
        for (SQLRowValues sqlRow : l) {
70
        for (SQLRowValues sqlRow : l) {
69
            this.mapRowTaux.put(sqlRow, sqlRow.getFloat("TAUX"));
71
            this.mapRowTaux.put(sqlRow, sqlRow.getFloat("TAUX"));
70
            this.mapTaux.put(sqlRow.getID(), sqlRow.getFloat("TAUX"));
72
            this.mapTaux.put(sqlRow.getID(), sqlRow.getFloat("TAUX"));
71
            if (sqlRow.getBoolean("DEFAULT")) {
73
            if (sqlRow.getBoolean("DEFAULT")) {
72
                this.firstIdTaxe = sqlRow.asRow();
74
                this.firstIdTaxe = sqlRow.asRow();
73
            }
75
            }
-
 
76
            if (sqlRow.getBoolean("DEFAULT_ACHAT")) {
-
 
77
                this.firstIdTaxeAchat = sqlRow.asRow();
-
 
78
            }
74
        }
79
        }
75
    }
80
    }
76
 
81
 
77
    public static synchronized TaxeCache getCache() {
82
    public static synchronized TaxeCache getCache() {
78
        if (instance == null) {
83
        if (instance == null) {
Line 121... Line 126...
121
 
126
 
122
        }
127
        }
123
        return this.firstIdTaxe;
128
        return this.firstIdTaxe;
124
    }
129
    }
125
 
130
 
-
 
131
    public synchronized SQLRow getFirstTaxeAchat() {
-
 
132
        if (this.firstIdTaxeAchat == null) {
-
 
133
            final SQLRowValuesListFetcher sel = getSel();
-
 
134
            final List<SQLRowValues> rows = sel.fetch(new Where(sel.getReq().getTable("TAXE").getField("DEFAULT_ACHAT"), "=", Boolean.TRUE));
-
 
135
            if (rows != null && !rows.isEmpty()) {
-
 
136
                this.firstIdTaxeAchat = rows.get(0).asRow();
-
 
137
            } else {
-
 
138
                this.firstIdTaxeAchat = getFirstTaxe();
-
 
139
            }
-
 
140
 
-
 
141
        }
-
 
142
        return this.firstIdTaxeAchat;
-
 
143
    }
-
 
144
 
126
    public synchronized Integer getIdFromTaux(Float tax) {
145
    public synchronized Integer getIdFromTaux(Float tax) {
127
        Set<Integer> s = mapTaux.keySet();
146
        Set<Integer> s = mapTaux.keySet();
128
        for (Integer integer : s) {
147
        for (Integer integer : s) {
129
            if (this.mapTaux.get(integer).equals(tax)) {
148
            if (this.mapTaux.get(integer).equals(tax)) {
130
                return integer;
149
                return integer;