OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 181 Rev 183
Line 11... Line 11...
11
import javax.swing.ButtonGroup;
11
import javax.swing.ButtonGroup;
12
import javax.swing.JPanel;
12
import javax.swing.JPanel;
13
import javax.swing.JRadioButton;
13
import javax.swing.JRadioButton;
14
import javax.swing.JTextField;
14
import javax.swing.JTextField;
15
 
15
 
-
 
16
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
-
 
17
import org.openconcerto.erp.utils.ConvertDevise;
-
 
18
import org.openconcerto.sql.model.SQLField;
16
import org.openconcerto.sql.model.SQLRow;
19
import org.openconcerto.sql.model.SQLRow;
17
import org.openconcerto.sql.model.SQLRowAccessor;
20
import org.openconcerto.sql.model.SQLRowAccessor;
18
import org.openconcerto.sql.model.SQLRowValues;
21
import org.openconcerto.sql.model.SQLRowValues;
-
 
22
import org.openconcerto.sql.model.Where;
-
 
23
import org.openconcerto.sql.request.UpdateBuilder;
19
import org.openconcerto.ui.DefaultGridBagConstraints;
24
import org.openconcerto.ui.DefaultGridBagConstraints;
20
 
25
 
21
public class NumberProcessor extends JPanel implements BatchProcessor {
26
public class NumberProcessor extends JPanel implements BatchProcessor {
22
 
27
 
23
    private final BatchField batchfield;
28
    private final BatchField batchfield;
Line 104... Line 109...
104
            }
109
            }
105
        });
110
        });
106
    }
111
    }
107
 
112
 
108
    @Override
113
    @Override
109
    public void process(List<SQLRowValues> r) throws SQLException {
114
    public void process(List<SQLRowAccessor> r) throws SQLException {
110
        if (bReplace.isSelected()) {
115
        if (bReplace.isSelected()) {
111
            BigDecimal v = new BigDecimal(this.tReplace.getText().trim());
116
            BigDecimal v = new BigDecimal(this.tReplace.getText().trim());
-
 
117
            final SQLField fieldToMatch = batchfield.getFieldToMatch();
-
 
118
            if (fieldToMatch != null) {
-
 
119
 
-
 
120
                UpdateBuilder build = new UpdateBuilder(fieldToMatch.getTable());
-
 
121
                build.setObject(batchfield.getField().getName(), (BigDecimal) decimalToFieldType(v));
-
 
122
                build.setWhere(
-
 
123
                        Where.inValues(fieldToMatch.getTable().getField("ID_" + r.get(0).getTable().getName()), SQLRow.getIDs(r)).and(new Where(fieldToMatch, "=", batchfield.getMatchingValue())));
-
 
124
                fieldToMatch.getTable().getDBSystemRoot().getDataSource().execute(build.asString());
-
 
125
 
-
 
126
            } else {
112
            for (SQLRowAccessor sqlRowAccessor : r) {
127
                for (SQLRowAccessor sqlRowAccessor : r) {
113
 
128
 
114
                if (batchfield.getForeignLinkRow() != null) {
129
                    if (batchfield.getForeignLinkRow() != null) {
115
 
130
 
116
                    final List<SQLRow> referentRow = batchfield.getReferentRows(sqlRowAccessor);
131
                        final List<SQLRow> referentRow = batchfield.getReferentRows(sqlRowAccessor);
-
 
132
                        if (referentRow.isEmpty()) {
-
 
133
                            SQLRowValues rowVals = new SQLRowValues(batchfield.getField().getTable());
-
 
134
                            rowVals.put("ID_" + sqlRowAccessor.getTable().getName(), sqlRowAccessor.getID());
-
 
135
                            rowVals.put("ID_" + batchfield.getForeignLinkRow().getTable().getName(), batchfield.getForeignLinkRow().getID());
-
 
136
                            rowVals.put(batchfield.getField().getName(), decimalToFieldType(v));
-
 
137
                            final BigDecimal taux = BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(sqlRowAccessor.getForeignID("ID_TAXE")));
-
 
138
                            final BigDecimal ht = (BigDecimal) decimalToFieldType(v);
-
 
139
                            final BigDecimal ttc = ConvertDevise.getTtcFromHt(ht, taux, rowVals.getTable().getField("PV_TTC").getType().getDecimalDigits());
-
 
140
                            rowVals.put("PV_TTC", ttc);
-
 
141
                            rowVals.put("PRIX_METRIQUE_VT_1", decimalToFieldType(v));
-
 
142
                            rowVals.commit();
-
 
143
                        } else {
117
                    for (SQLRow sqlRowT : referentRow) {
144
                            for (SQLRow sqlRowT : referentRow) {
118
                        SQLRowValues rowValues = sqlRowT.createEmptyUpdateRow();
145
                                SQLRowValues rowValues = sqlRowT.createEmptyUpdateRow();
119
                        rowValues.put(batchfield.getField().getName(), decimalToFieldType(v));
146
                                rowValues.put(batchfield.getField().getName(), decimalToFieldType(v));
-
 
147
                                if (!batchfield.getField().getName().equals("QTE_MIN") && !batchfield.getField().getName().equals("POURCENT_REMISE")) {
120
                        processBeforeUpdate(sqlRowT, rowValues);
148
                                    // processBeforeUpdate(sqlRowT, rowValues);
-
 
149
                                    final BigDecimal taux = sqlRowT.isForeignEmpty("ID_TAXE") ? BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(sqlRowAccessor.getForeignID("ID_TAXE")))
-
 
150
                                            : BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(sqlRowT.getForeignID("ID_TAXE")));
-
 
151
                                    final BigDecimal ht = rowValues.getBigDecimal("PV_HT");
-
 
152
                                    final BigDecimal ttc = ConvertDevise.getTtcFromHt(ht, taux, rowValues.getTable().getField("PV_TTC").getType().getDecimalDigits());
-
 
153
                                    rowValues.put("PV_TTC", ttc);
-
 
154
                                    rowValues.put("PRIX_METRIQUE_VT_1", ht);
-
 
155
                                }
121
                        rowValues.update();
156
                                rowValues.update();
122
                    }
157
                            }
-
 
158
                        }
123
                } else {
159
                    } else {
124
                    final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
160
                        final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
125
                    rowValues.put(batchfield.getField().getName(), decimalToFieldType(v));
161
                        rowValues.put(batchfield.getField().getName(), decimalToFieldType(v));
126
                    processBeforeUpdate(sqlRowAccessor, rowValues);
162
                        processBeforeUpdate(sqlRowAccessor, rowValues);
127
                    rowValues.update();
163
                        rowValues.update();
128
                }
164
                    }
129
            }
165
                }
-
 
166
            }
130
        } else if (bAdd.isSelected()) {
167
        } else if (bAdd.isSelected()) {
131
 
168
 
132
            String t = this.tAdd.getText().trim();
169
            String t = this.tAdd.getText().trim();
133
            boolean isPercent = false;
170
            boolean isPercent = false;
134
            if (t.endsWith("%")) {
171
            if (t.endsWith("%")) {