OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 57 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
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
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.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.customerrelationship.customer.element;
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
18
import org.openconcerto.erp.core.common.ui.DeviseField;
19
import org.openconcerto.erp.generationDoc.gestcomm.RelanceSheet;
20
import org.openconcerto.erp.preferences.PrinterNXProps;
21
import org.openconcerto.sql.element.BaseSQLComponent;
22
import org.openconcerto.sql.element.SQLComponent;
23
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.model.SQLRowAccessor;
25
import org.openconcerto.sql.model.SQLRowValues;
26
import org.openconcerto.sql.model.SQLTable;
27
import org.openconcerto.sql.sqlobject.ElementComboBox;
28
import org.openconcerto.sql.sqlobject.JUniqueTextField;
29
import org.openconcerto.sql.view.EditFrame;
30
import org.openconcerto.ui.DefaultGridBagConstraints;
31
import org.openconcerto.ui.JDate;
32
import org.openconcerto.ui.component.ITextArea;
33
import org.openconcerto.utils.ExceptionHandler;
34
 
35
import java.awt.GridBagConstraints;
36
import java.awt.GridBagLayout;
37
import java.sql.SQLException;
38
import java.util.ArrayList;
39
import java.util.List;
40
 
41
import javax.swing.JCheckBox;
42
import javax.swing.JLabel;
43
import javax.swing.JPanel;
44
import javax.swing.JSeparator;
45
import javax.swing.SwingUtilities;
46
 
47
public class RelanceSQLElement extends ComptaSQLConfElement {
48
 
49
    public RelanceSQLElement() {
50
        super("RELANCE", "relance client", "relances clients");
51
    }
52
 
53
    protected List<String> getListFields() {
54
        final List<String> l = new ArrayList<String>();
55
        l.add("NUMERO");
56
        l.add("ID_CLIENT");
57
        l.add("ID_SAISIE_VENTE_FACTURE");
58
        l.add("DATE");
59
        l.add("ID_TYPE_LETTRE_RELANCE");
60
        l.add("MONTANT");
61
        l.add("INFOS");
62
        return l;
63
    }
64
 
65
    protected List<String> getComboFields() {
66
        final List<String> l = new ArrayList<String>();
67
        l.add("NUMERO");
68
        return l;
69
    }
70
 
71
    /*
72
     * (non-Javadoc)
73
     *
74
     * @see org.openconcerto.devis.SQLElement#getComponent()
75
     */
76
    public SQLComponent createComponent() {
77
        return new BaseSQLComponent(this) {
78
 
79
            ElementComboBox comboFacture = new ElementComboBox();
80
            ElementComboBox comboClient = new ElementComboBox();
81
            ElementComboBox comboTypeLettre;
82
            JUniqueTextField textNumero = new JUniqueTextField();
83
            JCheckBox checkImpression = new JCheckBox("Impression");
84
            JCheckBox checkVisu = new JCheckBox("Visualisation");
85
 
86
            public void addViews() {
87
 
88
                this.setLayout(new GridBagLayout());
89
                final GridBagConstraints c = new DefaultGridBagConstraints();
90
 
91
                // Type lettre
92
                JLabel labelTypeLettre = new JLabel(getLabelFor("ID_TYPE_LETTRE_RELANCE"));
93
                labelTypeLettre.setHorizontalAlignment(JLabel.RIGHT);
94
                this.add(labelTypeLettre, c);
95
 
96
                c.gridx++;
97
                // SQLElement typeLettreElt =
98
                // Configuration.getInstance().getDirectory().getElement("TYPE_LETTRE_RELANCE");
99
                this.comboTypeLettre = new ElementComboBox(false);
100
 
101
                this.add(this.comboTypeLettre, c);
102
 
103
                // Date
104
                c.gridx++;
105
                JLabel labelDate = new JLabel(getLabelFor("DATE"));
106
                labelDate.setHorizontalAlignment(JLabel.RIGHT);
107
                this.add(labelDate, c);
108
 
109
                JDate date = new JDate(true);
110
                c.gridx++;
111
                this.add(date, c);
112
 
113
                // Numero
114
                c.gridx = 0;
115
                c.gridy++;
116
                JLabel labelNumero = new JLabel(getLabelFor("NUMERO"));
117
                labelNumero.setHorizontalAlignment(JLabel.RIGHT);
118
                this.add(labelNumero, c);
119
 
120
                c.gridx++;
121
                this.add(this.textNumero, c);
122
 
123
                // Client
124
                c.gridy++;
125
                c.gridx = 0;
126
 
127
                JLabel labelClient = new JLabel(getLabelFor("ID_CLIENT"));
128
                labelClient.setHorizontalAlignment(JLabel.RIGHT);
129
                this.add(labelClient, c);
130
                c.gridx++;
131
                c.gridwidth = GridBagConstraints.REMAINDER;
132
                this.add(this.comboClient, c);
133
 
134
                // Facture
135
                c.gridy++;
136
                c.gridx = 0;
137
                c.gridwidth = 1;
138
                JLabel labelFacture = new JLabel(getLabelFor("ID_SAISIE_VENTE_FACTURE"));
139
                labelFacture.setHorizontalAlignment(JLabel.RIGHT);
140
                this.add(labelFacture, c);
141
                c.gridx++;
142
                // c.gridwidth = GridBagConstraints.REMAINDER;
143
                this.add(this.comboFacture, c);
144
 
145
                // Montant
146
                c.gridx++;
147
                JLabel labelMontant = new JLabel(getLabelFor("MONTANT"));
148
                labelMontant.setHorizontalAlignment(JLabel.RIGHT);
149
                this.add(labelMontant, c);
150
 
151
                c.gridx++;
152
                DeviseField textMontant = new DeviseField();
153
                this.add(textMontant, c);
154
 
155
                // Commentaires
156
                c.gridx = 0;
157
                c.gridy++;
158
                this.add(new JLabel(getLabelFor("INFOS")), c);
159
 
160
                c.gridx++;
161
                c.gridwidth = GridBagConstraints.REMAINDER;
162
                c.fill = GridBagConstraints.HORIZONTAL;
163
                c.weightx = 1;
164
                this.add(new JSeparator(JSeparator.HORIZONTAL), c);
165
 
166
                c.gridx = 0;
167
                c.gridy++;
168
                c.weighty = 1;
169
                c.fill = GridBagConstraints.BOTH;
170
                ITextArea textInfos = new ITextArea();
171
                this.add(textInfos, c);
172
 
173
                JPanel panelCheck = new JPanel();
174
                panelCheck.setBorder(null);
175
                panelCheck.add(this.checkVisu);
176
                panelCheck.add(this.checkImpression);
177
                c.fill = GridBagConstraints.NONE;
178
                c.weighty = 0;
179
                c.gridy++;
180
                this.add(panelCheck, c);
181
 
182
                this.addRequiredSQLObject(textMontant, "MONTANT");
183
                this.addRequiredSQLObject(date, "DATE");
184
                this.addRequiredSQLObject(this.comboTypeLettre, "ID_TYPE_LETTRE_RELANCE");
185
                this.addRequiredSQLObject(this.comboClient, "ID_CLIENT");
186
                this.addRequiredSQLObject(this.comboFacture, "ID_SAISIE_VENTE_FACTURE");
187
                this.addSQLObject(textInfos, "INFOS");
188
                this.addRequiredSQLObject(this.textNumero, "NUMERO");
189
                this.comboTypeLettre.setButtonsVisible(false);
190
 
191
                this.textNumero.setText(NumerotationAutoSQLElement.getNextNumero(RelanceSQLElement.class));
192
                this.checkVisu.setSelected(true);
193
            }
194
 
195
            @Override
196
            public int insert(SQLRow order) {
197
 
198
                if (this.textNumero.checkValidation()) {
199
                    // incrémentation du numéro auto
200
                    if (NumerotationAutoSQLElement.getNextNumero(RelanceSQLElement.class).equalsIgnoreCase(this.textNumero.getText().trim())) {
201
                        SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
202
                        SQLRowValues rowVals = new SQLRowValues(tableNum);
203
                        int val = tableNum.getRow(2).getInt("RELANCE_START");
204
                        val++;
205
                        rowVals.put("RELANCE_START", Integer.valueOf(val));
206
 
207
                        try {
208
                            rowVals.update(2);
209
                        } catch (SQLException e) {
210
 
211
                            e.printStackTrace();
212
                        }
213
                    }
214
 
215
                    // insertion
216
                    int id = super.insert(order);
217
 
218
                    // génération du document
219
                    RelanceSheet s = new RelanceSheet(getTable().getRow(id));
220
                    String printer = PrinterNXProps.getInstance().getStringProperty("RelancePrinter");
221
                    s.generate(this.checkImpression.isSelected(), this.checkVisu.isSelected(), printer, true);
222
 
223
                    return id;
224
                } else {
225
                    ExceptionHandler.handle("Impossible d'ajouter, numéro de relance existant.");
226
                    Object root = SwingUtilities.getRoot(this);
227
                    if (root instanceof EditFrame) {
228
                        EditFrame frame = (EditFrame) root;
229
                        frame.getPanel().setAlwaysVisible(true);
230
                    }
231
                    return getSelectedID();
232
                }
233
            }
234
 
235
            @Override
236
            public void select(SQLRowAccessor r) {
237
                if (r != null) {
238
                    this.textNumero.setIdSelected(r.getID());
239
                }
240
                super.select(r);
241
 
242
                // numero de facture et client figé
243
                this.comboFacture.setEditable(false);
244
                this.comboClient.setEditable(false);
245
                this.fireValidChange();
246
            }
247
 
248
            @Override
249
            public void update() {
250
                if (!this.textNumero.checkValidation()) {
251
                    ExceptionHandler.handle("Impossible d'ajouter, numéro de relance existant.");
252
                    Object root = SwingUtilities.getRoot(this);
253
                    if (root instanceof EditFrame) {
254
                        EditFrame frame = (EditFrame) root;
255
                        frame.getPanel().setAlwaysVisible(true);
256
                    }
257
                    return;
258
                }
259
 
260
                super.update();
261
 
262
                // regénération du document
263
                RelanceSheet s = new RelanceSheet(getTable().getRow(getSelectedID()));
264
                String printer = PrinterNXProps.getInstance().getStringProperty("RelancePrinter");
265
                s.generate(this.checkImpression.isSelected(), this.checkVisu.isSelected(), printer);
266
            }
267
 
268
        };
269
    }
270
}