OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Rev 174 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 156
Line 62... Line 62...
62
import org.openconcerto.sql.sqlobject.ElementComboBox;
62
import org.openconcerto.sql.sqlobject.ElementComboBox;
63
import org.openconcerto.sql.sqlobject.JUniqueTextField;
63
import org.openconcerto.sql.sqlobject.JUniqueTextField;
64
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
64
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
65
import org.openconcerto.sql.sqlobject.SQLTextCombo;
65
import org.openconcerto.sql.sqlobject.SQLTextCombo;
66
import org.openconcerto.sql.users.UserManager;
66
import org.openconcerto.sql.users.UserManager;
-
 
67
import org.openconcerto.sql.users.rights.UserRightsManager;
67
import org.openconcerto.sql.view.EditFrame;
68
import org.openconcerto.sql.view.EditFrame;
68
import org.openconcerto.sql.view.EditPanel.EditMode;
69
import org.openconcerto.sql.view.EditPanel.EditMode;
69
import org.openconcerto.sql.view.list.RowValuesTable;
70
import org.openconcerto.sql.view.list.RowValuesTable;
70
import org.openconcerto.sql.view.list.RowValuesTableModel;
71
import org.openconcerto.sql.view.list.RowValuesTableModel;
71
import org.openconcerto.ui.DefaultGridBagConstraints;
72
import org.openconcerto.ui.DefaultGridBagConstraints;
72
import org.openconcerto.ui.FormLayouter;
73
import org.openconcerto.ui.FormLayouter;
73
import org.openconcerto.ui.JDate;
74
import org.openconcerto.ui.JDate;
74
import org.openconcerto.ui.TitledSeparator;
75
import org.openconcerto.ui.TitledSeparator;
75
import org.openconcerto.ui.component.ITextArea;
76
import org.openconcerto.ui.component.ITextArea;
-
 
77
import org.openconcerto.ui.component.InteractionMode;
76
import org.openconcerto.utils.ExceptionHandler;
78
import org.openconcerto.utils.ExceptionHandler;
77
import org.openconcerto.utils.GestionDevise;
79
import org.openconcerto.utils.GestionDevise;
78
import org.openconcerto.utils.ProductInfo;
-
 
79
import org.openconcerto.utils.cc.IFactory;
80
import org.openconcerto.utils.cc.IFactory;
80
import org.openconcerto.utils.text.SimpleDocumentListener;
81
import org.openconcerto.utils.text.SimpleDocumentListener;
81
 
82
 
82
import java.awt.GridBagConstraints;
83
import java.awt.GridBagConstraints;
83
import java.awt.GridBagLayout;
84
import java.awt.GridBagLayout;
84
import java.awt.event.ActionEvent;
85
import java.awt.event.ActionEvent;
85
import java.awt.event.ActionListener;
86
import java.awt.event.ActionListener;
86
import java.awt.event.MouseEvent;
-
 
87
import java.beans.PropertyChangeEvent;
87
import java.beans.PropertyChangeEvent;
88
import java.beans.PropertyChangeListener;
88
import java.beans.PropertyChangeListener;
89
import java.math.BigDecimal;
89
import java.math.BigDecimal;
90
import java.math.RoundingMode;
90
import java.math.RoundingMode;
91
import java.sql.SQLException;
91
import java.sql.SQLException;
Line 146... Line 146...
146
    private PropertyChangeListener listenerModeReglDefaut = new PropertyChangeListener() {
146
    private PropertyChangeListener listenerModeReglDefaut = new PropertyChangeListener() {
147
        public void propertyChange(PropertyChangeEvent arg0) {
147
        public void propertyChange(PropertyChangeEvent arg0) {
148
            int idCli = SaisieVenteFactureSQLComponent.this.comboClient.getWantedID();
148
            int idCli = SaisieVenteFactureSQLComponent.this.comboClient.getWantedID();
149
            if (idCli > 1) {
149
            if (idCli > 1) {
150
                SQLRow rowCli = SaisieVenteFactureSQLComponent.this.client.getTable().getRow(idCli);
150
                SQLRow rowCli = SaisieVenteFactureSQLComponent.this.client.getTable().getRow(idCli);
151
                if (!rowCli.isForeignEmpty("ID_COMMERCIAL")) {
151
                if (!isFilling() && !rowCli.isForeignEmpty("ID_COMMERCIAL")) {
152
                    comboCommercial.setValue(rowCli.getForeignID("ID_COMMERCIAL"));
152
                    comboCommercial.setValue(rowCli.getForeignID("ID_COMMERCIAL"));
153
                }
153
                }
154
 
154
 
-
 
155
                if (rowCli.getFields().contains("ID_CATEGORIE_COMPTABLE") && rowCli.getObject("ID_CATEGORIE_COMPTABLE") != null && !rowCli.isForeignEmpty("ID_CATEGORIE_COMPTABLE")) {
-
 
156
                    totalTTC.setCategorieComptable(rowCli.getForeign("ID_CATEGORIE_COMPTABLE"));
-
 
157
                    tableFacture.setRowCatComptable(rowCli.getForeign("ID_CATEGORIE_COMPTABLE"));
-
 
158
                } else {
-
 
159
                    totalTTC.setCategorieComptable(null);
-
 
160
                    tableFacture.setRowCatComptable(null);
-
 
161
                }
-
 
162
 
155
                if (getMode() == SQLComponent.Mode.INSERTION || !isFilling()) {
163
                if (getMode() == SQLComponent.Mode.INSERTION || !isFilling()) {
156
                    SQLElement sqleltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
164
                    SQLElement sqleltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
157
                    int idModeRegl = rowCli.getInt("ID_MODE_REGLEMENT");
165
                    int idModeRegl = rowCli.getInt("ID_MODE_REGLEMENT");
158
                    if (idModeRegl > 1) {
166
                    if (idModeRegl > 1) {
159
                        SQLRow rowModeRegl = sqleltModeRegl.getTable().getRow(idModeRegl);
167
                        SQLRow rowModeRegl = sqleltModeRegl.getTable().getRow(idModeRegl);
160
                        SQLRowValues rowValsModeRegl = rowModeRegl.createUpdateRow();
168
                        SQLRowValues rowValsModeRegl = rowModeRegl.createUpdateRow();
161
                        rowValsModeRegl.clearPrimaryKeys();
169
                        rowValsModeRegl.clearPrimaryKeys();
162
                        SaisieVenteFactureSQLComponent.this.eltModeRegl.setValue(rowValsModeRegl);
170
                        SaisieVenteFactureSQLComponent.this.eltModeRegl.setValue(rowValsModeRegl);
163
                    }
171
                    }
164
                }
172
                }
-
 
173
            } else {
-
 
174
                totalTTC.setCategorieComptable(null);
-
 
175
                tableFacture.setRowCatComptable(null);
165
            }
176
            }
166
 
177
 
167
            Where w = new Where(SaisieVenteFactureSQLComponent.this.tableAvoir.getField("SOLDE"), "=", Boolean.FALSE);
178
            Where w = new Where(SaisieVenteFactureSQLComponent.this.tableAvoir.getField("SOLDE"), "=", Boolean.FALSE);
168
            if (SaisieVenteFactureSQLComponent.this.comboClient.isEmpty()) {
179
            if (SaisieVenteFactureSQLComponent.this.comboClient.isEmpty()) {
169
                w = w.and(new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=", -1));
180
                w = w.and(new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=", -1));
Line 182... Line 193...
182
 
193
 
183
    private PropertyChangeListener changeCompteListener;
194
    private PropertyChangeListener changeCompteListener;
184
    private PropertyChangeListener changeClientListener;
195
    private PropertyChangeListener changeClientListener;
185
    private ISQLCompteSelector compteSelService;
196
    private ISQLCompteSelector compteSelService;
186
    private JLabel labelCompteServ;
197
    private JLabel labelCompteServ;
187
    private ElementComboBox comboCommercial;
198
    private ElementComboBox comboCommercial, comboPoleProduit;
188
    private ElementComboBox comboVerificateur = new ElementComboBox();;
199
    private ElementComboBox comboVerificateur = new ElementComboBox();;
189
    private SQLTable tableBanque = getTable().getTable(BanqueSQLElement.TABLENAME);
200
    private SQLTable tableBanque = getTable().getTable(BanqueSQLElement.TABLENAME);
190
 
201
 
191
    private final SQLRowAccessor defaultNum;
202
    private final SQLRowAccessor defaultNum;
192
 
203
 
Line 238... Line 249...
238
        this.add(addP, c);
249
        this.add(addP, c);
239
 
250
 
240
        c.gridy++;
251
        c.gridy++;
241
        c.gridwidth = 1;
252
        c.gridwidth = 1;
242
 
253
 
243
 
-
 
244
            if (getTable().contains("ID_POLE_PRODUIT")) {
-
 
245
                JLabel labelPole = new JLabel(getLabelFor("ID_POLE_PRODUIT"));
-
 
246
                labelPole.setHorizontalAlignment(SwingConstants.RIGHT);
-
 
247
                this.add(labelPole, c);
-
 
248
                c.gridx++;
-
 
249
                ElementComboBox pole = new ElementComboBox();
-
 
250
 
-
 
251
                this.add(pole, c);
-
 
252
                this.addSQLObject(pole, "ID_POLE_PRODUIT");
-
 
253
                c.gridy++;
-
 
254
                c.gridwidth = 1;
-
 
255
                c.gridx = 0;
-
 
256
            }
-
 
257
 
-
 
258
        /*******************************************************************************************
254
        /*******************************************************************************************
259
         * * RENSEIGNEMENTS
255
         * * RENSEIGNEMENTS
260
         ******************************************************************************************/
256
         ******************************************************************************************/
261
        // Ligne 1 : Numero de facture
257
        // Ligne 1 : Numero de facture
262
        JLabel labelNum = new JLabel(getLabelFor("NUMERO"));
258
        JLabel labelNum = new JLabel(getLabelFor("NUMERO"));
Line 337... Line 333...
337
 
333
 
338
        this.addSQLObject(textLibelle, "NOM");
334
        this.addSQLObject(textLibelle, "NOM");
339
        c.fill = GridBagConstraints.HORIZONTAL;
335
        c.fill = GridBagConstraints.HORIZONTAL;
340
        this.comboCommercial = new ElementComboBox(false);
336
        this.comboCommercial = new ElementComboBox(false);
341
        // Commercial
337
        // Commercial
342
        String field;
-
 
343
            field = "ID_COMMERCIAL";
338
            this.addRequiredSQLObject(this.comboCommercial, "ID_COMMERCIAL");
344
        c.gridx++;
339
        c.gridx++;
345
        c.weightx = 0;
340
        c.weightx = 0;
346
        c.fill = GridBagConstraints.HORIZONTAL;
341
        c.fill = GridBagConstraints.HORIZONTAL;
347
        this.add(new JLabel(getLabelFor(field), SwingConstants.RIGHT), c);
342
        this.add(new JLabel(getLabelFor("ID_COMMERCIAL"), SwingConstants.RIGHT), c);
348
 
343
 
349
        c.gridx++;
344
        c.gridx++;
350
        c.weightx = 1;
345
        c.weightx = 1;
351
        c.fill = GridBagConstraints.NONE;
346
        c.fill = GridBagConstraints.NONE;
352
 
347
 
353
        this.add(this.comboCommercial, c);
348
        this.add(this.comboCommercial, c);
354
        this.addRequiredSQLObject(this.comboCommercial, field);
-
 
-
 
349
 
355
        // Client
350
        // Client
356
        c.gridx = 0;
351
        c.gridx = 0;
357
        c.gridy++;
352
        c.gridy++;
358
        c.weightx = 0;
353
        c.weightx = 0;
359
        c.fill = GridBagConstraints.HORIZONTAL;
354
        c.fill = GridBagConstraints.HORIZONTAL;
Line 401... Line 396...
401
                }
396
                }
402
            });
397
            });
403
 
398
 
404
        }
399
        }
405
 
400
 
-
 
401
        if (getTable().contains("ID_POLE_PRODUIT")) {
-
 
402
            JLabel labelPole = new JLabel(getLabelFor("ID_POLE_PRODUIT"));
-
 
403
            labelPole.setHorizontalAlignment(SwingConstants.RIGHT);
-
 
404
            c.gridx++;
-
 
405
            this.add(labelPole, c);
-
 
406
 
-
 
407
            c.gridx++;
-
 
408
            this.comboPoleProduit = new ElementComboBox();
-
 
409
            this.add(this.comboPoleProduit, c);
-
 
410
            this.addSQLObject(this.comboPoleProduit, "ID_POLE_PRODUIT");
-
 
411
            DefaultGridBagConstraints.lockMinimumSize(this.comboPoleProduit);
-
 
412
        }
-
 
413
 
406
        if (
414
        if (
407
 
415
 
408
        getTable().contains("ID_ECHEANCIER_CCI")) {
416
        getTable().contains("ID_ECHEANCIER_CCI")) {
409
            // Echeancier
417
            // Echeancier
410
            c.gridy++;
418
            c.gridy++;
Line 430... Line 438...
430
                    if (selAffaire.getSelectedRow() != null) {
438
                    if (selAffaire.getSelectedRow() != null) {
431
                        echeancier.getRequest().setWhere(new Where(contactElement.getTable().getField("ID_AFFAIRE"), "=", selAffaire.getSelectedRow().getID()));
439
                        echeancier.getRequest().setWhere(new Where(contactElement.getTable().getField("ID_AFFAIRE"), "=", selAffaire.getSelectedRow().getID()));
432
 
440
 
433
                        if (!isFilling()) {
441
                        if (!isFilling()) {
434
                            SQLRow rowPole = selAffaire.getSelectedRow().getForeignRow("ID_POLE_PRODUIT");
442
                            SQLRow rowPole = selAffaire.getSelectedRow().getForeignRow("ID_POLE_PRODUIT");
435
                            comboCommercial.setValue(rowPole);
443
                            comboPoleProduit.setValue(rowPole);
436
                        }
444
                        }
437
                    } else {
445
                    } else {
438
                        echeancier.getRequest().setWhere(null);
446
                        echeancier.getRequest().setWhere(null);
439
                    }
447
                    }
440
                }
448
                }
Line 713... Line 721...
713
                    // TODO Raccord de méthode auto-généré
721
                    // TODO Raccord de méthode auto-généré
714
                    totalTTC.updateTotal();
722
                    totalTTC.updateTotal();
715
                }
723
                }
716
            });
724
            });
717
        }
725
        }
-
 
726
        final DeviseField textFraisDocHT = new DeviseField();
-
 
727
        final SQLRequestComboBox boxTaxeFraisDoc = new SQLRequestComboBox(false, 8);
-
 
728
 
-
 
729
        SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
-
 
730
        final boolean showFrais = prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.FRAIS_DOCUMENT, false);
-
 
731
        if (showFrais) {
-
 
732
 
-
 
733
            JLabel labelFraisDocHT = new JLabel(getLabelFor("FRAIS_DOCUMENT_HT"));
-
 
734
            labelFraisDocHT.setHorizontalAlignment(SwingConstants.RIGHT);
-
 
735
            cFrais.gridx = 1;
-
 
736
            cFrais.gridy++;
-
 
737
            panelFrais.add(labelFraisDocHT, cFrais);
-
 
738
            cFrais.gridx++;
-
 
739
            panelFrais.add(textFraisDocHT, cFrais);
-
 
740
            addView(textFraisDocHT, "FRAIS_DOCUMENT_HT");
-
 
741
 
-
 
742
            JLabel labelTaxeFraisDocHT = new JLabel(getLabelFor("ID_TAXE_FRAIS_DOCUMENT"));
-
 
743
            labelTaxeFraisDocHT.setHorizontalAlignment(SwingConstants.RIGHT);
-
 
744
            cFrais.gridx = 1;
-
 
745
            cFrais.gridy++;
-
 
746
            panelFrais.add(labelTaxeFraisDocHT, cFrais);
-
 
747
            cFrais.gridx++;
-
 
748
            panelFrais.add(boxTaxeFraisDoc, cFrais);
-
 
749
            this.addView(boxTaxeFraisDoc, "ID_TAXE_FRAIS_DOCUMENT", REQ);
-
 
750
 
-
 
751
            boxTaxeFraisDoc.addValueListener(new PropertyChangeListener() {
-
 
752
 
-
 
753
                @Override
-
 
754
                public void propertyChange(PropertyChangeEvent evt) {
-
 
755
                    totalTTC.updateTotal();
-
 
756
                }
-
 
757
            });
-
 
758
 
-
 
759
            textFraisDocHT.getDocument().addDocumentListener(new SimpleDocumentListener() {
-
 
760
 
-
 
761
                @Override
-
 
762
                public void update(final DocumentEvent e) {
-
 
763
                    totalTTC.updateTotal();
-
 
764
                }
-
 
765
            });
-
 
766
 
-
 
767
            comboClient.addModelListener("wantedID", new PropertyChangeListener() {
-
 
768
 
-
 
769
                @Override
-
 
770
                public void propertyChange(PropertyChangeEvent evt) {
-
 
771
                    if (!isFilling()) {
-
 
772
                        final int wantedID = comboClient.getWantedID();
-
 
773
                        long l = 0;
-
 
774
                        if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) {
-
 
775
 
-
 
776
                            final SQLRow rowClient = getTable().getForeignTable("ID_CLIENT").getRow(wantedID);
-
 
777
                            SQLRow rowFrais = rowClient.getForeign("ID_FRAIS_DOCUMENT");
-
 
778
                            if (rowFrais != null && !rowFrais.isUndefined()) {
-
 
779
                                l = rowFrais.getLong("MONTANT_HT");
-
 
780
                                boxTaxeFraisDoc.setValue(rowFrais.getForeignID("ID_TAXE"));
-
 
781
                            }
-
 
782
                            textFraisDocHT.setValue(l);
-
 
783
                        }
-
 
784
                    }
-
 
785
                }
-
 
786
            });
-
 
787
        }
718
 
788
 
719
        // Remise
789
        // Remise
720
        JLabel labelRemiseHT = new JLabel(getLabelFor("REMISE_HT"));
790
        JLabel labelRemiseHT = new JLabel(getLabelFor("REMISE_HT"));
721
        labelRemiseHT.setHorizontalAlignment(SwingConstants.RIGHT);
791
        labelRemiseHT.setHorizontalAlignment(SwingConstants.RIGHT);
722
        cFrais.gridy++;
792
        cFrais.gridy++;
Line 765... Line 835...
765
        this.allowEditable("T_SERVICE", false);
835
        this.allowEditable("T_SERVICE", false);
766
        this.allowEditable("T_POIDS", false);
836
        this.allowEditable("T_POIDS", false);
767
 
837
 
768
        totalTTC = new TotalPanel(this.tableFacture, fieldTEco, fieldHT, fieldTVA, this.fieldTTC, this.textPortHT, this.textRemiseHT, fieldService, fieldTHA, fieldDevise, poids, null,
838
        totalTTC = new TotalPanel(this.tableFacture, fieldTEco, fieldHT, fieldTVA, this.fieldTTC, this.textPortHT, this.textRemiseHT, fieldService, fieldTHA, fieldDevise, poids, null,
769
                (getTable().contains("ID_TAXE_PORT") ? boxTaxePort : null), null);
839
                (getTable().contains("ID_TAXE_PORT") ? boxTaxePort : null), null);
-
 
840
        totalTTC.setTextFraisDoc(textFraisDocHT, boxTaxeFraisDoc);
770
        DefaultGridBagConstraints.lockMinimumSize(totalTTC);
841
        DefaultGridBagConstraints.lockMinimumSize(totalTTC);
771
        cBottom.gridx++;
842
        cBottom.gridx++;
772
        cBottom.weightx = 1;
843
        cBottom.weightx = 1;
773
        cBottom.anchor = GridBagConstraints.EAST;
844
        cBottom.anchor = GridBagConstraints.EAST;
774
        cBottom.fill = GridBagConstraints.HORIZONTAL;
845
        cBottom.fill = GridBagConstraints.HORIZONTAL;
Line 1154... Line 1225...
1154
    public int insert(SQLRow order) {
1225
    public int insert(SQLRow order) {
1155
        return commit(order);
1226
        return commit(order);
1156
    }
1227
    }
1157
 
1228
 
1158
    private void createCompteServiceAuto(int id) throws SQLException {
1229
    private void createCompteServiceAuto(int id) throws SQLException {
1159
        SQLRow rowPole = this.comboCommercial.getSelectedRow();
1230
        SQLRow rowPole = this.comboPoleProduit.getSelectedRow();
1160
        SQLRow rowVerif = this.comboVerificateur.getSelectedRow();
1231
        SQLRow rowVerif = this.comboVerificateur.getSelectedRow();
1161
        String verifInitiale = getInitialesFromVerif(rowVerif);
1232
        String verifInitiale = getInitialesFromVerif(rowVerif);
1162
        int idCpt = ComptePCESQLElement.getId("706" + rowPole.getString("CODE") + verifInitiale, "Service " + rowPole.getString("NOM") + " " + rowVerif.getString("NOM"));
1233
        int idCpt = ComptePCESQLElement.getId("706" + rowPole.getString("CODE") + verifInitiale, "Service " + rowPole.getString("NOM") + " " + rowVerif.getString("NOM"));
1163
        SQLRowValues rowVals = this.getTable().getRow(id).createEmptyUpdateRow();
1234
        SQLRowValues rowVals = this.getTable().getRow(id).createEmptyUpdateRow();
1164
        rowVals.put("ID_COMPTE_PCE_SERVICE", idCpt);
1235
        rowVals.put("ID_COMPTE_PCE_SERVICE", idCpt);
Line 1742... Line 1813...
1742
        }
1813
        }
1743
        if (getTable().contains("ID_TAXE_PORT")) {
1814
        if (getTable().contains("ID_TAXE_PORT")) {
1744
            SQLRow taxeDefault = TaxeCache.getCache().getFirstTaxe();
1815
            SQLRow taxeDefault = TaxeCache.getCache().getFirstTaxe();
1745
            vals.put("ID_TAXE_PORT", taxeDefault.getID());
1816
            vals.put("ID_TAXE_PORT", taxeDefault.getID());
1746
        }
1817
        }
-
 
1818
        if (getTable().contains("ID_TAXE_FRAIS_DOCUMENT")) {
-
 
1819
            SQLRow taxeDefault = TaxeCache.getCache().getFirstTaxe();
-
 
1820
            vals.put("ID_TAXE_FRAIS_DOCUMENT", taxeDefault.getID());
-
 
1821
        }
1747
        vals.put("ID_COMPTE_PCE_SERVICE", idCompteVenteService);
1822
        vals.put("ID_COMPTE_PCE_SERVICE", idCompteVenteService);
1748
        System.err.println("Defaults " + vals);
1823
        System.err.println("Defaults " + vals);
1749
        return vals;
1824
        return vals;
1750
    }
1825
    }
1751
 
1826