OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 156
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.core.sales.order.element;
14
 package org.openconcerto.erp.core.sales.order.element;
15
 
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.ui.DeviseTableCellRenderer;
17
import org.openconcerto.erp.core.common.ui.DeviseTableCellRenderer;
18
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet;
18
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet;
19
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeCellRenderer;
19
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeCellRenderer;
20
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeClient;
20
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeClient;
21
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeClientComboBox;
21
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeClientComboBox;
22
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeRowItemView;
22
import org.openconcerto.erp.core.sales.order.ui.TypeFactureCommandeRowItemView;
23
import org.openconcerto.sql.element.BaseSQLComponent;
23
import org.openconcerto.sql.element.BaseSQLComponent;
24
import org.openconcerto.sql.element.SQLComponent;
24
import org.openconcerto.sql.element.SQLComponent;
25
import org.openconcerto.sql.element.UISQLComponent;
25
import org.openconcerto.sql.element.UISQLComponent;
26
import org.openconcerto.sql.model.FieldPath;
26
import org.openconcerto.sql.model.FieldPath;
27
import org.openconcerto.sql.model.SQLRow;
27
import org.openconcerto.sql.model.SQLRow;
28
import org.openconcerto.sql.model.SQLRowAccessor;
28
import org.openconcerto.sql.model.SQLRowAccessor;
29
import org.openconcerto.sql.model.SQLRowValues;
29
import org.openconcerto.sql.model.SQLRowValues;
30
import org.openconcerto.sql.model.graph.Path;
30
import org.openconcerto.sql.model.graph.Path;
31
import org.openconcerto.sql.view.EditFrame;
31
import org.openconcerto.sql.view.EditFrame;
32
import org.openconcerto.sql.view.EditPanelListener;
32
import org.openconcerto.sql.view.EditPanelListener;
33
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
33
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
34
import org.openconcerto.sql.view.list.IListe;
34
import org.openconcerto.sql.view.list.IListe;
35
import org.openconcerto.sql.view.list.RowAction;
35
import org.openconcerto.sql.view.list.RowAction;
36
import org.openconcerto.sql.view.list.SQLTableModelSource;
36
import org.openconcerto.sql.view.list.SQLTableModelSource;
37
import org.openconcerto.utils.CollectionUtils;
37
import org.openconcerto.utils.CollectionUtils;
38
import org.openconcerto.utils.DecimalUtils;
38
import org.openconcerto.utils.DecimalUtils;
39
import org.openconcerto.utils.ExceptionHandler;
39
import org.openconcerto.utils.ExceptionHandler;
40
 
40
 
41
import java.awt.event.ActionEvent;
41
import java.awt.event.ActionEvent;
42
import java.math.BigDecimal;
42
import java.math.BigDecimal;
43
import java.sql.SQLException;
43
import java.sql.SQLException;
44
import java.util.ArrayList;
44
import java.util.ArrayList;
45
import java.util.Arrays;
45
import java.util.Arrays;
46
import java.util.HashSet;
46
import java.util.HashSet;
47
import java.util.List;
47
import java.util.List;
48
import java.util.Set;
48
import java.util.Set;
49
 
49
 
50
import javax.swing.AbstractAction;
50
import javax.swing.AbstractAction;
51
 
51
 
52
public class FacturationCommandeClientSQLElement extends ComptaSQLConfElement {
52
public class FacturationCommandeClientSQLElement extends ComptaSQLConfElement {
53
 
53
 
54
    public static final String TABLENAME = "FACTURATION_COMMANDE_CLIENT";
54
    public static final String TABLENAME = "FACTURATION_COMMANDE_CLIENT";
55
 
55
 
56
    public FacturationCommandeClientSQLElement() {
56
    public FacturationCommandeClientSQLElement() {
57
        super(TABLENAME, "une terme de facturation de commande client", "termes de facturation commandes clients");
57
        super(TABLENAME, "un terme de facturation de commande client", "termes de facturation commandes clients");
58
        {
58
        {
59
            RowAction action = new RowAction(new AbstractAction("Facturer") {
59
            RowAction action = new RowAction(new AbstractAction("Facturer") {
60
 
60
 
61
                @Override
61
                @Override
62
                public void actionPerformed(ActionEvent e) {
62
                public void actionPerformed(ActionEvent e) {
63
                    final SQLRow sel = IListe.get(e).getSelectedRow().asRow();
63
                    final SQLRow sel = IListe.get(e).getSelectedRow().asRow();
64
                    sel.fetchValues();
64
                    sel.fetchValues();
65
                    CommandeClientSQLElement eltCmd = (CommandeClientSQLElement) getForeignElement("ID_COMMANDE_CLIENT");
65
                    CommandeClientSQLElement eltCmd = (CommandeClientSQLElement) getForeignElement("ID_COMMANDE_CLIENT");
66
                    int typeFacture = sel.getInt("TYPE_FACTURE");
66
                    int typeFacture = sel.getInt("TYPE_FACTURE");
67
                    final SQLRow asRow = sel.getForeign("ID_COMMANDE_CLIENT").asRow();
67
                    final SQLRow asRow = sel.getForeign("ID_COMMANDE_CLIENT").asRow();
68
                    asRow.fetchValues();
68
                    asRow.fetchValues();
69
                    List<SQLRowValues> l = Arrays.asList(asRow.asRowValues());
69
                    List<SQLRowValues> l = Arrays.asList(asRow.asRowValues());
70
                    final EditFrame f;
70
                    final EditFrame f;
71
                    if (typeFacture == TypeFactureCommandeClient.SITUATION.getId()) {
71
                    if (typeFacture == TypeFactureCommandeClient.SITUATION.getId()) {
72
                        f = eltCmd.transfertAcompteClient(l);
72
                        f = eltCmd.transfertAcompteClient(l);
73
                        SQLRowValues rowValues = new SQLRowValues(getForeignElement("ID_SAISIE_VENTE_FACTURE").getTable());
73
                        SQLRowValues rowValues = new SQLRowValues(getForeignElement("ID_SAISIE_VENTE_FACTURE").getTable());
74
                        rowValues.put("POURCENT_FACTURABLE", sel.getObject("POURCENT"));
74
                        rowValues.put("POURCENT_FACTURABLE", sel.getObject("POURCENT"));
75
                        rowValues.put("MONTANT_FACTURABLE", null);
75
                        rowValues.put("MONTANT_FACTURABLE", null);
76
                        ((BaseSQLComponent) f.getSQLComponent()).getView("MONTANT_FACTURABLE,POURCENT_FACTURABLE").show(rowValues);
76
                        ((BaseSQLComponent) f.getSQLComponent()).getView("MONTANT_FACTURABLE,POURCENT_FACTURABLE").show(rowValues);
77
                        ;
77
                        ;
78
 
78
 
79
                    } else if (typeFacture == TypeFactureCommandeClient.SOLDE.getId()) {
79
                    } else if (typeFacture == TypeFactureCommandeClient.SOLDE.getId()) {
80
                        f = eltCmd.transfertSoldeClient(l);
80
                        f = eltCmd.transfertSoldeClient(l);
81
 
81
 
82
                    } else {
82
                    } else {
83
                        f = eltCmd.transfertFactureClient(l);
83
                        f = eltCmd.transfertFactureClient(l);
84
                    }
84
                    }
85
 
85
 
86
                    SQLRowValues rowValues = new SQLRowValues(eltCmd.getTable().getTable("MODE_REGLEMENT").getTable());
86
                    SQLRowValues rowValues = new SQLRowValues(eltCmd.getTable().getTable("MODE_REGLEMENT").getTable());
87
                    rowValues.put("ID_TYPE_REGLEMENT", sel.getForeignID("ID_TYPE_REGLEMENT"));
87
                    rowValues.put("ID_TYPE_REGLEMENT", sel.getForeignID("ID_TYPE_REGLEMENT"));
88
                    rowValues.put("FIN_MOIS", Boolean.FALSE);
88
                    rowValues.put("FIN_MOIS", Boolean.FALSE);
89
                    if (sel.getBoolean("COMPTANT")) {
89
                    if (sel.getBoolean("COMPTANT")) {
90
                        rowValues.put("AJOURS", 0);
90
                        rowValues.put("AJOURS", 0);
91
                        rowValues.put("LENJOUR", 0);
91
                        rowValues.put("LENJOUR", 0);
92
                        rowValues.put("DATE_FACTURE", Boolean.TRUE);
92
                        rowValues.put("DATE_FACTURE", Boolean.TRUE);
93
                        rowValues.put("COMPTANT", Boolean.TRUE);
93
                        rowValues.put("COMPTANT", Boolean.TRUE);
94
                    } else {
94
                    } else {
95
                        rowValues.put("AJOURS", sel.getObject("AJOURS"));
95
                        rowValues.put("AJOURS", sel.getObject("AJOURS"));
96
                        int lenjour = sel.getInt("LENJOUR");
96
                        int lenjour = sel.getInt("LENJOUR");
97
                        if (sel.getBoolean("FIN_MOIS")) {
97
                        if (sel.getBoolean("FIN_MOIS")) {
98
                            lenjour = 31;
98
                            lenjour = 31;
99
                        }
99
                        }
100
                        rowValues.put("LENJOUR", lenjour);
100
                        rowValues.put("LENJOUR", lenjour);
101
                        rowValues.put("COMPTANT", Boolean.FALSE);
101
                        rowValues.put("COMPTANT", Boolean.FALSE);
102
                        rowValues.put("FIN_MOIS", lenjour == 31);
102
                        rowValues.put("FIN_MOIS", lenjour == 31);
103
                        rowValues.put("DATE_FACTURE", lenjour == 0);
103
                        rowValues.put("DATE_FACTURE", lenjour == 0);
104
                    }
104
                    }
105
 
105
 
106
                    ((BaseSQLComponent) f.getSQLComponent()).getView("ID_MODE_REGLEMENT").show(rowValues);
106
                    ((BaseSQLComponent) f.getSQLComponent()).getView("ID_MODE_REGLEMENT").show(rowValues);
107
                    ;
107
                    ;
108
 
108
 
109
                    f.addEditPanelListener(new EditPanelListener() {
109
                    f.addEditPanelListener(new EditPanelListener() {
110
 
110
 
111
                        @Override
111
                        @Override
112
                        public void modified() {
112
                        public void modified() {
113
 
113
 
114
                        }
114
                        }
115
 
115
 
116
                        @Override
116
                        @Override
117
                        public void inserted(int id) {
117
                        public void inserted(int id) {
118
                            try {
118
                            try {
119
                                sel.createEmptyUpdateRow().put("ID_SAISIE_VENTE_FACTURE", id).commit();
119
                                sel.createEmptyUpdateRow().put("ID_SAISIE_VENTE_FACTURE", id).commit();
120
                            } catch (SQLException e) {
120
                            } catch (SQLException e) {
121
                                ExceptionHandler.handle("Erreur lors de l'affectation de la facture", e);
121
                                ExceptionHandler.handle("Erreur lors de l'affectation de la facture", e);
122
                            }
122
                            }
123
                        }
123
                        }
124
 
124
 
125
                        @Override
125
                        @Override
126
                        public void deleted() {
126
                        public void deleted() {
127
                        }
127
                        }
128
 
128
 
129
                        @Override
129
                        @Override
130
                        public void cancelled() {
130
                        public void cancelled() {
131
 
131
 
132
                        }
132
                        }
133
                    });
133
                    });
134
                }
134
                }
135
            }, true) {
135
            }, true) {
136
                @Override
136
                @Override
137
                public boolean enabledFor(List<SQLRowValues> selection) {
137
                public boolean enabledFor(List<SQLRowValues> selection) {
138
 
138
 
139
                    if (selection != null && selection.size() == 1) {
139
                    if (selection != null && selection.size() == 1) {
140
                        SQLRowAccessor sel = selection.get(0);
140
                        SQLRowAccessor sel = selection.get(0);
141
                        return sel.isForeignEmpty("ID_SAISIE_VENTE_FACTURE");
141
                        return sel.isForeignEmpty("ID_SAISIE_VENTE_FACTURE");
142
                    }
142
                    }
143
                    return false;
143
                    return false;
144
                }
144
                }
145
            };
145
            };
146
 
146
 
147
            getRowActions().add(action);
147
            getRowActions().add(action);
148
        }
148
        }
149
 
149
 
150
        {
150
        {
151
            RowAction action = new RowAction(new AbstractAction("Voir la facture") {
151
            RowAction action = new RowAction(new AbstractAction("Voir la facture") {
152
 
152
 
153
                @Override
153
                @Override
154
                public void actionPerformed(ActionEvent e) {
154
                public void actionPerformed(ActionEvent e) {
155
                    final SQLRowAccessor sel = IListe.get(e).getSelectedRow();
155
                    final SQLRowAccessor sel = IListe.get(e).getSelectedRow();
156
                    SQLRowAccessor fact = sel.getForeign("ID_SAISIE_VENTE_FACTURE");
156
                    SQLRowAccessor fact = sel.getForeign("ID_SAISIE_VENTE_FACTURE");
157
                    VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(fact.asRow());
157
                    VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(fact.asRow());
158
                    try {
158
                    try {
159
                        sheet.showPreviewDocument();
159
                        sheet.showPreviewDocument();
160
                    } catch (Exception e1) {
160
                    } catch (Exception e1) {
161
                        // TODO Auto-generated catch block
161
                        // TODO Auto-generated catch block
162
                        e1.printStackTrace();
162
                        e1.printStackTrace();
163
                    }
163
                    }
164
                }
164
                }
165
            }, true) {
165
            }, true) {
166
                @Override
166
                @Override
167
                public boolean enabledFor(List<SQLRowValues> selection) {
167
                public boolean enabledFor(List<SQLRowValues> selection) {
168
 
168
 
169
                    if (selection != null && selection.size() == 1) {
169
                    if (selection != null && selection.size() == 1) {
170
                        SQLRowAccessor sel = selection.get(0);
170
                        SQLRowAccessor sel = selection.get(0);
171
                        return !sel.isForeignEmpty("ID_SAISIE_VENTE_FACTURE");
171
                        return !sel.isForeignEmpty("ID_SAISIE_VENTE_FACTURE");
172
                    }
172
                    }
173
                    return false;
173
                    return false;
174
                }
174
                }
175
            };
175
            };
176
 
176
 
177
            getRowActions().add(action);
177
            getRowActions().add(action);
178
        }
178
        }
179
    }
179
    }
180
 
180
 
181
    /*
181
    /*
182
     * (non-Javadoc)
182
     * (non-Javadoc)
183
     * 
183
     * 
184
     * @see org.openconcerto.devis.BaseSQLElement#getComboFields()
184
     * @see org.openconcerto.devis.BaseSQLElement#getComboFields()
185
     */
185
     */
186
    protected List<String> getComboFields() {
186
    protected List<String> getComboFields() {
187
        final List<String> l = new ArrayList<>(1);
187
        final List<String> l = new ArrayList<>(1);
188
        l.add("NOM");
188
        l.add("NOM");
189
        return l;
189
        return l;
190
    }
190
    }
191
 
191
 
192
    @Override
192
    @Override
193
    public Set<String> getReadOnlyFields() {
193
    public Set<String> getReadOnlyFields() {
194
        Set<String> s = new HashSet<>(1);
194
        Set<String> s = new HashSet<>(1);
195
        s.add("CHOICE");
195
        s.add("CHOICE");
196
        return s;
196
        return s;
197
    }
197
    }
198
 
198
 
199
    @Override
199
    @Override
200
    protected String getParentFFName() {
200
    protected String getParentFFName() {
201
        return "ID_COMMANDE_CLIENT";
201
        return "ID_COMMANDE_CLIENT";
202
    }
202
    }
203
 
203
 
204
    /*
204
    /*
205
     * (non-Javadoc)
205
     * (non-Javadoc)
206
     * 
206
     * 
207
     * @see org.openconcerto.devis.BaseSQLElement#getListFields()
207
     * @see org.openconcerto.devis.BaseSQLElement#getListFields()
208
     */
208
     */
209
    protected List<String> getListFields() {
209
    protected List<String> getListFields() {
210
        final List<String> l = new ArrayList<>(7);
210
        final List<String> l = new ArrayList<>(7);
211
        l.add("NOM");
211
        l.add("NOM");
212
        l.add("TYPE_FACTURE");
212
        l.add("TYPE_FACTURE");
213
        l.add("ID_TYPE_REGLEMENT");
213
        l.add("ID_TYPE_REGLEMENT");
214
        l.add("POURCENT");
214
        l.add("POURCENT");
215
        l.add("DATE_PREVISIONNELLE");
215
        l.add("DATE_PREVISIONNELLE");
216
        l.add("ID_COMMANDE_CLIENT");
216
        l.add("ID_COMMANDE_CLIENT");
217
        l.add("ID_SAISIE_VENTE_FACTURE");
217
        l.add("ID_SAISIE_VENTE_FACTURE");
218
        return l;
218
        return l;
219
    }
219
    }
220
 
220
 
221
    @Override
221
    @Override
222
    protected void _initTableSource(SQLTableModelSource res) {
222
    protected void _initTableSource(SQLTableModelSource res) {
223
        res.init();
223
        res.init();
224
        res.getColumn(getTable().getField("POURCENT")).setRenderer(new DeviseTableCellRenderer());
224
        res.getColumn(getTable().getField("POURCENT")).setRenderer(new DeviseTableCellRenderer());
225
        res.getColumn(getTable().getField("TYPE_FACTURE")).setRenderer(new TypeFactureCommandeCellRenderer());
225
        res.getColumn(getTable().getField("TYPE_FACTURE")).setRenderer(new TypeFactureCommandeCellRenderer());
226
        final BaseSQLTableModelColumn pourcentFact = new BaseSQLTableModelColumn("Montant facturé", BigDecimal.class) {
226
        final BaseSQLTableModelColumn pourcentFact = new BaseSQLTableModelColumn("Montant facturé", BigDecimal.class) {
227
 
227
 
228
            @Override
228
            @Override
229
            protected Object show_(SQLRowAccessor r) {
229
            protected Object show_(SQLRowAccessor r) {
230
                long ht = r.getForeign("ID_COMMANDE_CLIENT").getLong("T_TTC");
230
                long ht = r.getForeign("ID_COMMANDE_CLIENT").getLong("T_TTC");
231
                BigDecimal percent = r.getBigDecimal("POURCENT");
231
                BigDecimal percent = r.getBigDecimal("POURCENT");
232
                return percent.movePointLeft(2).multiply(new BigDecimal(ht).movePointLeft(2), DecimalUtils.HIGH_PRECISION);
232
                return percent.movePointLeft(2).multiply(new BigDecimal(ht).movePointLeft(2), DecimalUtils.HIGH_PRECISION);
233
            }
233
            }
234
 
234
 
235
            @Override
235
            @Override
236
            public Set<FieldPath> getPaths() {
236
            public Set<FieldPath> getPaths() {
237
                Path p = new Path(getTable());
237
                Path p = new Path(getTable());
238
                Path p2 = p.add(p.getFirst().getField("ID_COMMANDE_CLIENT"));
238
                Path p2 = p.add(p.getFirst().getField("ID_COMMANDE_CLIENT"));
239
                return CollectionUtils.createSet(new FieldPath(p, "POURCENT"), new FieldPath(p2, "T_TTC"));
239
                return CollectionUtils.createSet(new FieldPath(p, "POURCENT"), new FieldPath(p2, "T_TTC"));
240
            }
240
            }
241
        };
241
        };
242
        pourcentFact.setRenderer(new DeviseTableCellRenderer());
242
        pourcentFact.setRenderer(new DeviseTableCellRenderer());
243
        res.getColumns().add(pourcentFact);
243
        res.getColumns().add(pourcentFact);
244
        super._initTableSource(res);
244
        super._initTableSource(res);
245
    }
245
    }
246
 
246
 
247
    /*
247
    /*
248
     * (non-Javadoc)
248
     * (non-Javadoc)
249
     * 
249
     * 
250
     * @see org.openconcerto.devis.SQLElement#getComponent()
250
     * @see org.openconcerto.devis.SQLElement#getComponent()
251
     */
251
     */
252
    public SQLComponent createComponent() {
252
    public SQLComponent createComponent() {
253
        return new UISQLComponent(this) {
253
        return new UISQLComponent(this) {
254
            public void addViews() {
254
            public void addViews() {
255
                this.addView("NOM");
255
                this.addView("NOM");
256
                this.addView("POURCENT");
256
                this.addView("POURCENT");
257
                this.addView("ID_TYPE_REGLEMENT");
257
                this.addView("ID_TYPE_REGLEMENT");
258
                this.addView("AJOURS");
258
                this.addView("AJOURS");
259
                this.addView("COMPTANT");
259
                this.addView("COMPTANT");
260
                this.addView("CHOICE");
260
                this.addView("CHOICE");
261
 
261
 
262
                TypeFactureCommandeClientComboBox box = new TypeFactureCommandeClientComboBox();
262
                TypeFactureCommandeClientComboBox box = new TypeFactureCommandeClientComboBox();
263
 
263
 
264
                this.addView(new TypeFactureCommandeRowItemView(box), "TYPE_FACTURE", REQ);
264
                this.addView(new TypeFactureCommandeRowItemView(box), "TYPE_FACTURE", REQ);
265
                this.addView("ID_MODELE");
265
                this.addView("ID_MODELE");
266
            }
266
            }
267
 
267
 
268
            @Override
268
            @Override
269
            protected SQLRowValues createDefaults() {
269
            protected SQLRowValues createDefaults() {
270
                SQLRowValues rowVals = new SQLRowValues(getTable());
270
                SQLRowValues rowVals = new SQLRowValues(getTable());
271
                rowVals.put("CHOICE", Boolean.TRUE);
271
                rowVals.put("CHOICE", Boolean.TRUE);
272
                return rowVals;
272
                return rowVals;
273
            }
273
            }
274
        };
274
        };
275
    }
275
    }
276
 
276
 
277
    @Override
277
    @Override
278
    protected String createCode() {
278
    protected String createCode() {
279
        return createCodeFromPackage() + ".facturation";
279
        return createCodeOfPackage() + ".facturation";
280
    }
280
    }
281
 
281
 
282
}
282
}