OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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