OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | 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.finance.payment.ui;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
80 ilm 17
import org.openconcerto.erp.core.finance.payment.element.ChequeAEncaisserSQLElement;
18 ilm 18
import org.openconcerto.erp.rights.ComptaTotalUserRight;
19
import org.openconcerto.sql.Configuration;
20
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLRowValues;
144 ilm 22
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
23
import org.openconcerto.sql.users.rights.UserRightsManager;
156 ilm 24
import org.openconcerto.sql.view.EditFrame;
25
import org.openconcerto.sql.view.EditPanel.EditMode;
80 ilm 26
import org.openconcerto.sql.view.list.IListe;
18 ilm 27
import org.openconcerto.ui.JDate;
28
import org.openconcerto.utils.GestionDevise;
29
 
30
import java.awt.event.ActionEvent;
31
import java.awt.event.ActionListener;
32
import java.sql.SQLException;
156 ilm 33
import java.util.List;
18 ilm 34
 
35
import javax.swing.AbstractAction;
36
import javax.swing.JButton;
37
import javax.swing.JCheckBox;
38
import javax.swing.JOptionPane;
39
import javax.swing.JTextField;
80 ilm 40
import javax.swing.text.JTextComponent;
18 ilm 41
 
80 ilm 42
public class ListeDesChequesAEncaisserPanel extends ChequeListPanel {
156 ilm 43
    private JTextField fieldLabel;
18 ilm 44
 
80 ilm 45
    public ListeDesChequesAEncaisserPanel(final ChequeAEncaisserSQLElement elem) {
46
        super(elem);
47
    }
18 ilm 48
 
80 ilm 49
    @Override
50
    protected JButton createPreviewBtn() {
51
        return new JButton("Aperçu du relevé");
52
    }
18 ilm 53
 
80 ilm 54
    @Override
55
    protected JTextComponent createLabelText() {
156 ilm 56
        if (fieldLabel == null) {
57
            this.fieldLabel = new JTextField();
58
        }
59
        return fieldLabel;
80 ilm 60
    }
18 ilm 61
 
80 ilm 62
    @Override
144 ilm 63
    protected JButton createSubmitBtn(final SQLRequestComboBox banqueSelect, final JDate dateDepot, final JCheckBox checkImpression, final JTextComponent text) {
80 ilm 64
        final JButton res = new JButton("Valider le dépôt");
65
        res.addActionListener(new ActionListener() {
18 ilm 66
            @Override
67
            public void actionPerformed(ActionEvent e) {
68
                final String s = text.getText();
156 ilm 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) {
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);
18 ilm 102
                text.setText("");
103
            }
104
        });
80 ilm 105
        return res;
18 ilm 106
    }
107
 
80 ilm 108
    @Override
109
    protected void actionDroitTable() {
110
        super.actionDroitTable();
144 ilm 111
        if (UserRightsManager.getCurrentUserRights().haveRight(ComptaTotalUserRight.MENU)) {
18 ilm 112
 
80 ilm 113
            getListe().addRowAction(new AbstractAction("Régularisation en comptabilité") {
18 ilm 114
 
115
                public void actionPerformed(ActionEvent e) {
80 ilm 116
                    final SQLRow rowCheque = IListe.get(e).fetchSelectedRow();
18 ilm 117
 
118
                    String price = GestionDevise.currencyToString(rowCheque.getLong("MONTANT"));
119
                    SQLRow rowClient = rowCheque.getForeignRow("ID_CLIENT");
156 ilm 120
                    String nomClient = rowClient == null ? rowCheque.getString("TIERS") : rowClient.getString("NOM");
18 ilm 121
                    String piece = "";
122
                    SQLRow rowMvt = rowCheque.getForeignRow("ID_MOUVEMENT");
123
                    if (rowMvt != null) {
124
                        SQLRow rowPiece = rowMvt.getForeignRow("ID_PIECE");
125
                        piece = rowPiece.getString("NOM");
126
                    }
127
                    int answer = JOptionPane.showConfirmDialog(ListeDesChequesAEncaisserPanel.this, "Etes vous sûr de vouloir régulariser ce cheque de " + nomClient + " d'un montant de " + price
128
                            + "€ avec une saisie au kilometre?\nNom de la piéce : " + piece + "\nAttention, cette opération est irréversible.");
129
                    if (answer == JOptionPane.YES_OPTION) {
130
 
131
                        SQLRowValues rowVals = rowCheque.asRowValues();
132
                        rowVals.put("REG_COMPTA", Boolean.TRUE);
133
                        try {
134
                            rowVals.commit();
135
                        } catch (SQLException e1) {
136
                            e1.printStackTrace();
137
                        }
138
                    }
139
                }
140
            });
141
        }
142
    }
143
 
80 ilm 144
    @Override
145
    protected String getDepositLabel() {
146
        return "Sélectionner les chéques à déposer, en date du ";
18 ilm 147
    }
148
}