OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 144 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.finance.payment.ui;
14
 package org.openconcerto.erp.core.finance.payment.ui;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.finance.payment.element.ChequeAEncaisserSQLElement;
17
import org.openconcerto.erp.core.finance.payment.element.ChequeAEncaisserSQLElement;
18
import org.openconcerto.erp.rights.ComptaTotalUserRight;
18
import org.openconcerto.erp.rights.ComptaTotalUserRight;
19
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.Configuration;
20
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLRowValues;
21
import org.openconcerto.sql.model.SQLRowValues;
22
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
22
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
23
import org.openconcerto.sql.users.rights.UserRightsManager;
23
import org.openconcerto.sql.users.rights.UserRightsManager;
-
 
24
import org.openconcerto.sql.view.EditFrame;
-
 
25
import org.openconcerto.sql.view.EditPanel.EditMode;
24
import org.openconcerto.sql.view.list.IListe;
26
import org.openconcerto.sql.view.list.IListe;
25
import org.openconcerto.ui.JDate;
27
import org.openconcerto.ui.JDate;
26
import org.openconcerto.utils.GestionDevise;
28
import org.openconcerto.utils.GestionDevise;
27
 
29
 
28
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
31
import java.awt.event.ActionListener;
30
import java.sql.SQLException;
32
import java.sql.SQLException;
-
 
33
import java.util.List;
31
 
34
 
32
import javax.swing.AbstractAction;
35
import javax.swing.AbstractAction;
33
import javax.swing.JButton;
36
import javax.swing.JButton;
34
import javax.swing.JCheckBox;
37
import javax.swing.JCheckBox;
35
import javax.swing.JOptionPane;
38
import javax.swing.JOptionPane;
36
import javax.swing.JTextField;
39
import javax.swing.JTextField;
37
import javax.swing.text.JTextComponent;
40
import javax.swing.text.JTextComponent;
38
 
41
 
39
public class ListeDesChequesAEncaisserPanel extends ChequeListPanel {
42
public class ListeDesChequesAEncaisserPanel extends ChequeListPanel {
-
 
43
    private JTextField fieldLabel;
40
 
44
 
41
    public ListeDesChequesAEncaisserPanel(final ChequeAEncaisserSQLElement elem) {
45
    public ListeDesChequesAEncaisserPanel(final ChequeAEncaisserSQLElement elem) {
42
        super(elem);
46
        super(elem);
43
    }
47
    }
44
 
48
 
45
    @Override
49
    @Override
46
    protected JButton createPreviewBtn() {
50
    protected JButton createPreviewBtn() {
47
        return new JButton("Aperçu du relevé");
51
        return new JButton("Aperçu du relevé");
48
    }
52
    }
49
 
53
 
50
    @Override
54
    @Override
51
    protected JTextComponent createLabelText() {
55
    protected JTextComponent createLabelText() {
-
 
56
        if (fieldLabel == null) {
-
 
57
            this.fieldLabel = new JTextField();
-
 
58
        }
52
        return new JTextField();
59
        return fieldLabel;
53
    }
60
    }
54
 
61
 
55
    @Override
62
    @Override
56
    protected JButton createSubmitBtn(final SQLRequestComboBox banqueSelect, final JDate dateDepot, final JCheckBox checkImpression, final JTextComponent text) {
63
    protected JButton createSubmitBtn(final SQLRequestComboBox banqueSelect, final JDate dateDepot, final JCheckBox checkImpression, final JTextComponent text) {
57
        final JButton res = new JButton("Valider le dépôt");
64
        final JButton res = new JButton("Valider le dépôt");
58
        res.addActionListener(new ActionListener() {
65
        res.addActionListener(new ActionListener() {
59
            @Override
66
            @Override
60
            public void actionPerformed(ActionEvent e) {
67
            public void actionPerformed(ActionEvent e) {
61
                final String s = text.getText();
68
                final String s = text.getText();
-
 
69
                SQLRowValues rowValsDepot = new SQLRowValues(element.getTable().getTable("DEPOT_CHEQUE"));
-
 
70
                rowValsDepot.put("DATE", dateDepot.getValue());
-
 
71
                rowValsDepot.put("NOM", fieldLabel.getText());
-
 
72
                final SQLRow selectedBanque = banqueSelect.getSelectedRow();
-
 
73
                if (selectedBanque != null) {
62
                getModel().valideDepot(banqueSelect.getSelectedRow(), dateDepot.getDate(), checkImpression.isSelected(), s);
74
                    rowValsDepot.put("ID_" + selectedBanque.getTable().getName(), selectedBanque.getID());
-
 
75
                }
-
 
76
                List<SQLRowValues> chq = getListe().getSelectedRows();
-
 
77
                for (SQLRowValues sqlRowValues : chq) {
-
 
78
                    SQLRow rowChq = sqlRowValues.asRow();
-
 
79
                    rowChq.fetchValues();
-
 
80
                    SQLRowValues rowValsDepotElt = new SQLRowValues(element.getTable().getTable("DEPOT_CHEQUE_ELEMENT"));
-
 
81
                    rowValsDepotElt.put("ID_DEPOT_CHEQUE", rowValsDepot);
-
 
82
                    if (rowChq.getObject("ID_CLIENT") != null && !rowChq.isForeignEmpty("ID_CLIENT")) {
-
 
83
                        rowValsDepotElt.put("ID_CLIENT", rowChq.getForeignID("ID_CLIENT"));
-
 
84
                    }
-
 
85
                    rowValsDepotElt.put("TIERS", rowChq.getString("TIERS"));
-
 
86
                    rowValsDepotElt.put("ID_CHEQUE_A_ENCAISSER", rowChq.getID());
-
 
87
                    if (rowChq.getObject("DATE") != null) {
-
 
88
                        rowValsDepotElt.put("DATE", rowChq.getObject("DATE"));
-
 
89
                    } else if (rowChq.getObject("DATE_VENTE") != null) {
-
 
90
                        rowValsDepotElt.put("DATE", rowChq.getObject("DATE_VENTE"));
-
 
91
                    }
-
 
92
                    rowValsDepotElt.put("BANQUE", (rowChq.getObject("ETS") == null ? "" : rowChq.getObject("ETS")));
-
 
93
                    if (rowChq.getObject("ID_MOUVEMENT") != null && !rowChq.isForeignEmpty("ID_MOUVEMENT")) {
-
 
94
                        rowValsDepotElt.put("PIECE", rowChq.getForeign("ID_MOUVEMENT").getForeign("ID_PIECE").getString("NOM"));
-
 
95
                    }
-
 
96
                    rowValsDepotElt.put("NUMERO", (rowChq.getObject("NUMERO") == null ? "" : rowChq.getObject("NUMERO")));
-
 
97
                    rowValsDepotElt.put("MONTANT", rowChq.getObject("MONTANT"));
-
 
98
                }
-
 
99
                EditFrame frame = new EditFrame(element.getDirectory().getElement("DEPOT_CHEQUE"), EditMode.CREATION);
-
 
100
                frame.getSQLComponent().select(rowValsDepot);
-
 
101
                frame.setVisible(true);
63
                text.setText("");
102
                text.setText("");
64
            }
103
            }
65
        });
104
        });
66
        return res;
105
        return res;
67
    }
106
    }
68
 
107
 
69
    @Override
108
    @Override
70
    protected void actionDroitTable() {
109
    protected void actionDroitTable() {
71
        super.actionDroitTable();
110
        super.actionDroitTable();
72
        if (UserRightsManager.getCurrentUserRights().haveRight(ComptaTotalUserRight.MENU)) {
111
        if (UserRightsManager.getCurrentUserRights().haveRight(ComptaTotalUserRight.MENU)) {
73
 
112
 
74
            getListe().addRowAction(new AbstractAction("Régularisation en comptabilité") {
113
            getListe().addRowAction(new AbstractAction("Régularisation en comptabilité") {
75
 
114
 
76
                public void actionPerformed(ActionEvent e) {
115
                public void actionPerformed(ActionEvent e) {
77
                    final SQLRow rowCheque = IListe.get(e).fetchSelectedRow();
116
                    final SQLRow rowCheque = IListe.get(e).fetchSelectedRow();
78
 
117
 
79
                    String price = GestionDevise.currencyToString(rowCheque.getLong("MONTANT"));
118
                    String price = GestionDevise.currencyToString(rowCheque.getLong("MONTANT"));
80
                    SQLRow rowClient = rowCheque.getForeignRow("ID_CLIENT");
119
                    SQLRow rowClient = rowCheque.getForeignRow("ID_CLIENT");
81
                    String nomClient = rowClient.getString("NOM");
120
                    String nomClient = rowClient == null ? rowCheque.getString("TIERS") : rowClient.getString("NOM");
82
                    String piece = "";
121
                    String piece = "";
83
                    SQLRow rowMvt = rowCheque.getForeignRow("ID_MOUVEMENT");
122
                    SQLRow rowMvt = rowCheque.getForeignRow("ID_MOUVEMENT");
84
                    if (rowMvt != null) {
123
                    if (rowMvt != null) {
85
                        SQLRow rowPiece = rowMvt.getForeignRow("ID_PIECE");
124
                        SQLRow rowPiece = rowMvt.getForeignRow("ID_PIECE");
86
                        piece = rowPiece.getString("NOM");
125
                        piece = rowPiece.getString("NOM");
87
                    }
126
                    }
88
                    int answer = JOptionPane.showConfirmDialog(ListeDesChequesAEncaisserPanel.this, "Etes vous sûr de vouloir régulariser ce cheque de " + nomClient + " d'un montant de " + price
127
                    int answer = JOptionPane.showConfirmDialog(ListeDesChequesAEncaisserPanel.this, "Etes vous sûr de vouloir régulariser ce cheque de " + nomClient + " d'un montant de " + price
89
                            + "€ avec une saisie au kilometre?\nNom de la piéce : " + piece + "\nAttention, cette opération est irréversible.");
128
                            + "€ avec une saisie au kilometre?\nNom de la piéce : " + piece + "\nAttention, cette opération est irréversible.");
90
                    if (answer == JOptionPane.YES_OPTION) {
129
                    if (answer == JOptionPane.YES_OPTION) {
91
 
130
 
92
                        SQLRowValues rowVals = rowCheque.asRowValues();
131
                        SQLRowValues rowVals = rowCheque.asRowValues();
93
                        rowVals.put("REG_COMPTA", Boolean.TRUE);
132
                        rowVals.put("REG_COMPTA", Boolean.TRUE);
94
                        try {
133
                        try {
95
                            rowVals.commit();
134
                            rowVals.commit();
96
                        } catch (SQLException e1) {
135
                        } catch (SQLException e1) {
97
                            e1.printStackTrace();
136
                            e1.printStackTrace();
98
                        }
137
                        }
99
                    }
138
                    }
100
                }
139
                }
101
            });
140
            });
102
        }
141
        }
103
    }
142
    }
104
 
143
 
105
    @Override
144
    @Override
106
    protected String getDepositLabel() {
145
    protected String getDepositLabel() {
107
        return "Sélectionner les chéques à déposer, en date du ";
146
        return "Sélectionner les chéques à déposer, en date du ";
108
    }
147
    }
109
}
148
}