OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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