OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 180 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 180 Rev 182
Line 1... Line 1...
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-2019 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.
Line 45... Line 45...
45
import org.openconcerto.sql.model.SQLBackgroundTableCache;
45
import org.openconcerto.sql.model.SQLBackgroundTableCache;
46
import org.openconcerto.sql.model.SQLInjector;
46
import org.openconcerto.sql.model.SQLInjector;
47
import org.openconcerto.sql.model.SQLRow;
47
import org.openconcerto.sql.model.SQLRow;
48
import org.openconcerto.sql.model.SQLRowAccessor;
48
import org.openconcerto.sql.model.SQLRowAccessor;
49
import org.openconcerto.sql.model.SQLRowValues;
49
import org.openconcerto.sql.model.SQLRowValues;
-
 
50
import org.openconcerto.sql.model.SQLSelect;
50
import org.openconcerto.sql.model.SQLTable;
51
import org.openconcerto.sql.model.SQLTable;
51
import org.openconcerto.sql.model.Where;
52
import org.openconcerto.sql.model.Where;
52
import org.openconcerto.sql.preferences.SQLPreferences;
53
import org.openconcerto.sql.preferences.SQLPreferences;
53
import org.openconcerto.sql.sqlobject.ElementComboBox;
54
import org.openconcerto.sql.sqlobject.ElementComboBox;
54
import org.openconcerto.sql.sqlobject.JUniqueTextField;
55
import org.openconcerto.sql.sqlobject.JUniqueTextField;
55
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
56
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
56
import org.openconcerto.sql.sqlobject.SQLTextCombo;
57
import org.openconcerto.sql.sqlobject.SQLTextCombo;
-
 
58
import org.openconcerto.sql.sqlobject.itemview.SimpleRowItemView;
57
import org.openconcerto.sql.users.UserManager;
59
import org.openconcerto.sql.users.UserManager;
58
import org.openconcerto.sql.view.EditFrame;
60
import org.openconcerto.sql.view.EditFrame;
59
import org.openconcerto.sql.view.list.RowValuesTable;
61
import org.openconcerto.sql.view.list.RowValuesTable;
60
import org.openconcerto.ui.DefaultGridBagConstraints;
62
import org.openconcerto.ui.DefaultGridBagConstraints;
61
import org.openconcerto.ui.FormLayouter;
63
import org.openconcerto.ui.FormLayouter;
62
import org.openconcerto.ui.JDate;
64
import org.openconcerto.ui.JDate;
63
import org.openconcerto.ui.TitledSeparator;
65
import org.openconcerto.ui.TitledSeparator;
64
import org.openconcerto.ui.component.ITextArea;
66
import org.openconcerto.ui.component.ITextArea;
-
 
67
import org.openconcerto.ui.valuewrapper.ValidatedValueWrapper;
65
import org.openconcerto.utils.ExceptionHandler;
68
import org.openconcerto.utils.ExceptionHandler;
-
 
69
import org.openconcerto.utils.cc.ITransformer;
-
 
70
import org.openconcerto.utils.checks.ValidState;
66
 
71
 
67
import java.awt.Color;
72
import java.awt.Color;
68
import java.awt.GridBagConstraints;
73
import java.awt.GridBagConstraints;
69
import java.awt.GridBagLayout;
74
import java.awt.GridBagLayout;
70
import java.beans.PropertyChangeEvent;
75
import java.beans.PropertyChangeEvent;
71
import java.beans.PropertyChangeListener;
76
import java.beans.PropertyChangeListener;
-
 
77
import java.math.BigDecimal;
72
import java.sql.SQLException;
78
import java.sql.SQLException;
73
import java.util.Date;
79
import java.util.Date;
74
import java.util.HashSet;
80
import java.util.HashSet;
75
import java.util.List;
81
import java.util.List;
76
import java.util.Set;
82
import java.util.Set;
Line 86... Line 92...
86
import javax.swing.event.DocumentEvent;
92
import javax.swing.event.DocumentEvent;
87
import javax.swing.event.DocumentListener;
93
import javax.swing.event.DocumentListener;
88
import javax.swing.event.TableModelEvent;
94
import javax.swing.event.TableModelEvent;
89
import javax.swing.event.TableModelListener;
95
import javax.swing.event.TableModelListener;
90
 
96
 
-
 
97
import org.apache.commons.dbutils.handlers.ArrayListHandler;
-
 
98
 
91
public class CommandeClientSQLComponent extends TransfertBaseSQLComponent {
99
public class CommandeClientSQLComponent extends TransfertBaseSQLComponent {
92
 
100
 
93
    private CommandeClientItemTable table;
101
    private CommandeClientItemTable table;
94
    private FacturationCommandeTable tableFacturationItem;
102
    private FacturationCommandeTable tableFacturationItem;
95
    private ChiffrageCommandeTable tableChiffrageItem;
103
    private ChiffrageCommandeTable tableChiffrageItem;
Line 216... Line 224...
216
        c.gridy++;
224
        c.gridy++;
217
        c.weightx = 0;
225
        c.weightx = 0;
218
        c.fill = GridBagConstraints.HORIZONTAL;
226
        c.fill = GridBagConstraints.HORIZONTAL;
219
        this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
227
        this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
220
 
228
 
-
 
229
        final ValidatedValueWrapper<Integer> clientValidatedValueWrapper = ValidatedValueWrapper.add(new ElementComboBox(), new ITransformer<Integer, ValidState>() {
-
 
230
            @Override
-
 
231
            public ValidState transformChecked(Integer t) {
-
 
232
                ElementComboBox boxClient = (ElementComboBox) getView("ID_CLIENT").getComp();
-
 
233
                if (getMode() == Mode.INSERTION && boxClient != null && !boxClient.isEmpty() && boxClient.getSelectedRow().getBoolean("BLOQUE")) {
-
 
234
                    return ValidState.create(false, "Les intéractions avec ce client sont verrouillées.");
-
 
235
                } else {
-
 
236
                    return ValidState.getTrueInstance();
-
 
237
                }
-
 
238
            }
-
 
239
        });
221
        this.comboClient = new ElementComboBox();
240
        this.comboClient = (ElementComboBox) clientValidatedValueWrapper.getComp();
-
 
241
 
-
 
242
        addView(new SimpleRowItemView<Integer>(clientValidatedValueWrapper), "ID_CLIENT", REQ);
222
        c.gridx++;
243
        c.gridx++;
223
        c.gridwidth = 1;
244
        c.gridwidth = 1;
224
        c.weightx = 1;
245
        c.weightx = 1;
225
        c.weighty = 0;
246
        c.weighty = 0;
226
        c.fill = GridBagConstraints.NONE;
247
        c.fill = GridBagConstraints.NONE;
Line 234... Line 255...
234
                    Integer id = comboClient.getValue();
255
                    Integer id = comboClient.getValue();
235
 
256
 
236
                    if (id > 1) {
257
                    if (id > 1) {
237
 
258
 
238
                        SQLRow row = comboClient.getElement().getTable().getRow(id);
259
                        SQLRow row = comboClient.getElement().getTable().getRow(id);
-
 
260
                        String alerte = row.getString("ALERTE");
-
 
261
                        if (alerte != null && alerte.trim().length() > 0) {
-
 
262
                            JOptionPane.showMessageDialog(comboClient, alerte);
-
 
263
                        }
239
                        if (comboClient.getElement().getTable().getFieldsName().contains("ID_TARIF")) {
264
                        if (comboClient.getElement().getTable().getFieldsName().contains("ID_TARIF")) {
240
 
265
 
241
                            SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
266
                            SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
242
                            if (!foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID())
267
                            if (!foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID())
243
                                    && JOptionPane.showConfirmDialog(null, TM.tr("apply.associated.pricelist.to.customer")) == JOptionPane.YES_OPTION) {
268
                                    && JOptionPane.showConfirmDialog(null, TM.tr("apply.associated.pricelist.to.customer")) == JOptionPane.YES_OPTION) {
Line 266... Line 291...
266
                    }
291
                    }
267
                }
292
                }
268
 
293
 
269
            }
294
            }
270
        });
295
        });
271
        addRequiredSQLObject(this.comboClient, "ID_CLIENT");
-
 
272
 
296
 
273
        if (this.displayDpt) {
297
        if (this.displayDpt) {
274
            c.gridx++;
298
            c.gridx++;
275
            c.gridwidth = 1;
299
            c.gridwidth = 1;
276
            final JLabel labelDpt = new JLabel(getLabelFor("ID_CLIENT_DEPARTEMENT"));
300
            final JLabel labelDpt = new JLabel(getLabelFor("ID_CLIENT_DEPARTEMENT"));
Line 682... Line 706...
682
        cFrais.gridy++;
706
        cFrais.gridy++;
683
        cFrais.gridx = 0;
707
        cFrais.gridx = 0;
684
        panel.add(labelRemiseHT, cFrais);
708
        panel.add(labelRemiseHT, cFrais);
685
        cFrais.gridx++;
709
        cFrais.gridx++;
686
        panel.add(textRemiseHT, cFrais);
710
        panel.add(textRemiseHT, cFrais);
-
 
711
        if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ACOMPTE_DEVIS, false) && getTable().contains("T_ACOMPTE")) {
-
 
712
            // Acompte
-
 
713
            cFrais.gridy++;
-
 
714
            cFrais.gridx = 0;
-
 
715
            cFrais.weightx = 0;
-
 
716
            cFrais.weighty = 0;
-
 
717
            cFrais.gridwidth = 1;
-
 
718
            JLabel compAcompte = new JLabel(getLabelFor("T_ACOMPTE"), SwingConstants.RIGHT);
-
 
719
            panel.add(compAcompte, cFrais);
-
 
720
            cFrais.gridx++;
-
 
721
            cFrais.gridwidth = GridBagConstraints.REMAINDER;
-
 
722
            DeviseField fieldAcompte = new DeviseField();
-
 
723
            fieldAcompte.setEnabled(false);
-
 
724
            cFrais.weightx = 1;
-
 
725
            panel.add(fieldAcompte, cFrais);
-
 
726
            this.addView(fieldAcompte, "T_ACOMPTE");
-
 
727
        }
687
 
728
 
688
        c.gridx = 2;
729
        c.gridx = 2;
689
        c.weightx = 0;
730
        c.weightx = 0;
690
        c.weighty = 0;
731
        c.weighty = 0;
691
        c.gridwidth = 1;
732
        c.gridwidth = 1;
Line 758... Line 799...
758
                textPoidsTotal.setText(String.valueOf(CommandeClientSQLComponent.this.table.getPoidsTotal()));
799
                textPoidsTotal.setText(String.valueOf(CommandeClientSQLComponent.this.table.getPoidsTotal()));
759
            }
800
            }
760
        });
801
        });
761
 
802
 
762
        this.addView(this.table.getRowValuesTable(), "");
803
        this.addView(this.table.getRowValuesTable(), "");
-
 
804
 
-
 
805
        comboClient.addModelListener("wantedID", new PropertyChangeListener() {
-
 
806
 
-
 
807
            @Override
-
 
808
            public void propertyChange(PropertyChangeEvent arg0) {
-
 
809
 
-
 
810
                Integer id = comboClient.getWantedID();
-
 
811
 
-
 
812
                if (id > 1) {
-
 
813
 
-
 
814
                    SQLRow rowClient = comboClient.getElement().getTable().getRow(id);
-
 
815
                    if (rowClient.getObject("ID_CATEGORIE_COMPTABLE") != null && !rowClient.isForeignEmpty("ID_CATEGORIE_COMPTABLE")) {
-
 
816
                        totalTTC.setCategorieComptable(rowClient.getForeign("ID_CATEGORIE_COMPTABLE"));
-
 
817
                        table.setRowCatComptable(rowClient.getForeign("ID_CATEGORIE_COMPTABLE"));
-
 
818
                    } else {
-
 
819
                        totalTTC.setCategorieComptable(null);
-
 
820
                        table.setRowCatComptable(null);
-
 
821
                    }
-
 
822
                }
-
 
823
            }
-
 
824
        });
-
 
825
 
763
        DefaultGridBagConstraints.lockMinimumSize(comboClient);
826
        DefaultGridBagConstraints.lockMinimumSize(comboClient);
764
        DefaultGridBagConstraints.lockMinimumSize(comboCommercial);
827
        DefaultGridBagConstraints.lockMinimumSize(comboCommercial);
765
        DefaultGridBagConstraints.lockMinimumSize(comboDevis);
828
        DefaultGridBagConstraints.lockMinimumSize(comboDevis);
766
        DefaultGridBagConstraints.lockMinimumSize(totalTTC);
829
        DefaultGridBagConstraints.lockMinimumSize(totalTTC);
767
        DefaultGridBagConstraints.lockMaximumSize(totalTTC);
830
        DefaultGridBagConstraints.lockMaximumSize(totalTTC);
Line 813... Line 876...
813
            }
876
            }
814
            // Création des articles
877
            // Création des articles
815
            this.table.createArticle(idCommande, this.getElement());
878
            this.table.createArticle(idCommande, this.getElement());
816
            // generation du document
879
            // generation du document
817
 
880
 
-
 
881
            SQLRow row = this.getElement().getTable().getRow(idCommande);
818
            try {
882
            try {
819
                CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(getTable().getRow(idCommande));
883
                CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(getTable().getRow(idCommande));
820
                sheet.createDocumentAsynchronous();
884
                sheet.createDocumentAsynchronous();
821
                sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
885
                sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true,
-
 
886
                        this.getElement(), row);
822
            } catch (Exception e) {
887
            } catch (Exception e) {
823
                ExceptionHandler.handle("Impossible de créer la commande", e);
888
                ExceptionHandler.handle("Impossible de créer la commande", e);
824
            }
889
            }
825
 
890
 
826
            // incrémentation du numéro auto
891
            // incrémentation du numéro auto
Line 841... Line 906...
841
                    public void run() {
906
                    public void run() {
842
                        JOptionPane.showMessageDialog(null, "Le numéro a été actualisé en " + num);
907
                        JOptionPane.showMessageDialog(null, "Le numéro a été actualisé en " + num);
843
                    }
908
                    }
844
                });
909
                });
845
            }
910
            }
-
 
911
            ((CommandeClientSQLElement) getElement()).fireInsertedCmdListener(row);
-
 
912
 
846
        }
913
        }
847
 
914
 
848
        return idCommande;
915
        return idCommande;
849
    }
916
    }
850
 
917
 
Line 916... Line 983...
916
 
983
 
917
        // generation du document
984
        // generation du document
918
        try {
985
        try {
919
            CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(row);
986
            CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(row);
920
            sheet.createDocumentAsynchronous();
987
            sheet.createDocumentAsynchronous();
921
            sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
988
            sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true, getElement(),
-
 
989
                    row);
922
        } catch (Exception e) {
990
        } catch (Exception e) {
923
            ExceptionHandler.handle("Impossible de créer la commande", e);
991
            ExceptionHandler.handle("Impossible de créer la commande", e);
924
        }
992
        }
925
 
993
 
926
    }
994
    }
Line 935... Line 1003...
935
     * @throws SQLException
1003
     * @throws SQLException
936
     */
1004
     */
937
    private void updateStock(int id) throws SQLException {
1005
    private void updateStock(int id) throws SQLException {
938
 
1006
 
939
        SQLRow row = getTable().getRow(id);
1007
        SQLRow row = getTable().getRow(id);
-
 
1008
 
-
 
1009
        if (row.getInt("ETAT_COMMANDE") != EtatCommandeClient.ANNULEE.getId()) {
940
        StockItemsUpdater stockUpdater = new StockItemsUpdater(new StockLabel() {
1010
            StockItemsUpdater stockUpdater = new StockItemsUpdater(new StockLabel() {
941
            @Override
1011
                @Override
942
            public String getLabel(SQLRowAccessor rowOrigin, SQLRowAccessor rowElt) {
1012
                public String getLabel(SQLRowAccessor rowOrigin, SQLRowAccessor rowElt) {
943
                return getLibelleStock(rowOrigin, rowElt);
1013
                    return getLibelleStock(rowOrigin, rowElt);
944
            }
1014
                }
945
        }, row, row.getReferentRows(getTable().getTable("COMMANDE_CLIENT_ELEMENT")), TypeStockUpdate.VIRTUAL_DELIVER);
1015
            }, row, row.getReferentRows(getTable().getTable("COMMANDE_CLIENT_ELEMENT")), TypeStockUpdate.VIRTUAL_DELIVER);
946
 
1016
 
947
        stockUpdater.update();
1017
            stockUpdater.update();
-
 
1018
        } else {
-
 
1019
            // Suppression des stocks si commande annulée
-
 
1020
            SQLElement eltMvtStock = getDirectory().getElement("MOUVEMENT_STOCK");
-
 
1021
            SQLSelect sel = new SQLSelect();
-
 
1022
            sel.addSelect(eltMvtStock.getTable().getField("ID"));
-
 
1023
            Where w = new Where(eltMvtStock.getTable().getField("IDSOURCE"), "=", row.getID());
-
 
1024
            Where w2 = new Where(eltMvtStock.getTable().getField("SOURCE"), "=", getTable().getName());
-
 
1025
            sel.setWhere(w.and(w2));
-
 
1026
 
-
 
1027
            @SuppressWarnings("rawtypes")
-
 
1028
            List l = (List) eltMvtStock.getTable().getBase().getDataSource().execute(sel.asString(), new ArrayListHandler());
-
 
1029
            if (l != null) {
-
 
1030
                for (int i = 0; i < l.size(); i++) {
-
 
1031
                    Object[] tmp = (Object[]) l.get(i);
-
 
1032
                    eltMvtStock.archive(((Number) tmp[0]).intValue());
-
 
1033
                }
-
 
1034
            }
-
 
1035
        }
948
    }
1036
    }
949
 
1037
 
950
    public void setDefaults() {
1038
    public void setDefaults() {
951
        this.resetValue();
1039
        this.resetValue();
952
        this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()));
1040
        this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()));
Line 1052... Line 1140...
1052
 
1140
 
1053
            for (final SQLRow rowElt : myListItem) {
1141
            for (final SQLRow rowElt : myListItem) {
1054
 
1142
 
1055
                final SQLRowValues rowVals = rowElt.createUpdateRow();
1143
                final SQLRowValues rowVals = rowElt.createUpdateRow();
1056
                rowVals.clearPrimaryKeys();
1144
                rowVals.clearPrimaryKeys();
-
 
1145
                if (rowVals.getTable().contains("ID_DEVIS_ELEMENT")) {
-
 
1146
                    rowVals.putEmptyLink("ID_DEVIS_ELEMENT");
-
 
1147
                }
-
 
1148
                rowVals.put("QTE_LIVREE", BigDecimal.ZERO);
-
 
1149
                rowVals.put("LIVRE", Boolean.FALSE);
-
 
1150
                rowVals.put("LIVRE_FORCED", Boolean.FALSE);
-
 
1151
 
1057
                this.table.getModel().addRow(rowVals);
1152
                this.table.getModel().addRow(rowVals, false);
1058
                final int rowIndex = this.table.getModel().getRowCount() - 1;
1153
                final int rowIndex = this.table.getModel().getRowCount() - 1;
1059
                this.table.getModel().fireTableModelModified(rowIndex);
1154
                this.table.getModel().fireTableModelModified(rowIndex);
1060
            }
1155
            }
1061
        } else {
1156
        } else {
1062
            this.table.getModel().clearRows();
1157
            this.table.getModel().clearRows();