OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 94 | 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.supplychain.receipt.action;
15
 
16
import org.openconcerto.erp.action.CreateFrameAbstractAction;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
94 ilm 18
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
93 ilm 19
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
18 ilm 20
import org.openconcerto.erp.core.supplychain.receipt.element.BonReceptionSQLElement;
21
import org.openconcerto.sql.Configuration;
93 ilm 22
import org.openconcerto.sql.element.SQLElement;
94 ilm 23
import org.openconcerto.sql.model.FieldPath;
18 ilm 24
import org.openconcerto.sql.model.SQLRow;
94 ilm 25
import org.openconcerto.sql.model.SQLRowAccessor;
26
import org.openconcerto.sql.model.graph.Path;
27
import org.openconcerto.sql.model.graph.PathBuilder;
18 ilm 28
import org.openconcerto.sql.view.IListFrame;
29
import org.openconcerto.sql.view.ListeAddPanel;
94 ilm 30
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
31
import org.openconcerto.sql.view.list.IListe;
32
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
93 ilm 33
import org.openconcerto.ui.DefaultGridBagConstraints;
94 ilm 34
import org.openconcerto.ui.table.PercentTableCellRenderer;
35
import org.openconcerto.utils.CollectionUtils;
36
import org.openconcerto.utils.DecimalUtils;
18 ilm 37
 
93 ilm 38
import java.awt.GridBagConstraints;
18 ilm 39
import java.awt.event.ActionEvent;
40
import java.awt.event.MouseAdapter;
41
import java.awt.event.MouseEvent;
94 ilm 42
import java.math.BigDecimal;
43
import java.math.RoundingMode;
44
import java.util.Collection;
45
import java.util.Set;
18 ilm 46
 
47
import javax.swing.AbstractAction;
48
import javax.swing.Action;
49
import javax.swing.JFrame;
50
import javax.swing.JPopupMenu;
51
 
52
public class ListeDesBonsReceptionsAction extends CreateFrameAbstractAction {
53
 
54
    public ListeDesBonsReceptionsAction() {
55
        super();
56
        this.putValue(Action.NAME, "Liste des bons de réceptions");
57
    }
58
 
59
    public JFrame createFrame() {
93 ilm 60
        final SQLElement element = Configuration.getInstance().getDirectory().getElement("BON_RECEPTION");
94 ilm 61
        final SQLTableModelSourceOnline tableSource = element.getTableSource(true);
18 ilm 62
 
94 ilm 63
        BaseSQLTableModelColumn colAvancement = new BaseSQLTableModelColumn("Avancement facturation", BigDecimal.class) {
18 ilm 64
 
94 ilm 65
            @Override
66
            protected Object show_(SQLRowAccessor r) {
18 ilm 67
 
94 ilm 68
                return getAvancement(r);
69
            }
18 ilm 70
 
94 ilm 71
            @Override
72
            public Set<FieldPath> getPaths() {
73
                final Path p = new PathBuilder(element.getTable()).addTable("TR_BON_RECEPTION").addTable("FACTURE_FOURNISSEUR").build();
74
                return CollectionUtils.createSet(new FieldPath(p, "T_HT"));
75
            }
76
        };
77
        tableSource.getColumns().add(colAvancement);
78
        colAvancement.setRenderer(new PercentTableCellRenderer());
18 ilm 79
 
94 ilm 80
        final IListFrame frame = new IListFrame(new ListeAddPanel(element, new IListe(tableSource)));
18 ilm 81
 
93 ilm 82
        // Date panel
83
        IListFilterDatePanel datePanel = new IListFilterDatePanel(frame.getPanel().getListe(), element.getTable().getField("DATE"), IListFilterDatePanel.getDefaultMap());
84
        GridBagConstraints c = new DefaultGridBagConstraints();
85
        c.gridwidth = GridBagConstraints.REMAINDER;
86
        c.fill = GridBagConstraints.NONE;
87
        c.weightx = 0;
88
        c.gridy++;
89
        c.gridy++;
90
        c.anchor = GridBagConstraints.CENTER;
91
        datePanel.setFilterOnDefault();
92
        frame.getPanel().add(datePanel, c);
93
 
18 ilm 94
        return frame;
95
    }
96
 
174 ilm 97
    private BigDecimal bigDecimal100 = new BigDecimal(100);
98
 
94 ilm 99
    private BigDecimal getAvancement(SQLRowAccessor r) {
100
        Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("TR_BON_RECEPTION"));
101
        long totalFact = 0;
102
        long total = (r.getObject("TOTAL_HT") == null ? 0 : r.getLong("TOTAL_HT"));
103
        for (SQLRowAccessor row : rows) {
104
            if (!row.isForeignEmpty("ID_FACTURE_FOURNISSEUR")) {
105
                SQLRowAccessor rowFact = row.getForeign("ID_FACTURE_FOURNISSEUR");
106
                Long l = rowFact.getLong("T_HT");
107
                totalFact += l;
108
            }
109
        }
110
        if (total > 0) {
174 ilm 111
            return this.bigDecimal100.min(new BigDecimal(totalFact).divide(new BigDecimal(total), DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP));
94 ilm 112
        } else {
113
            return BigDecimal.ONE.movePointRight(2);
114
        }
115
    }
116
 
18 ilm 117
    /**
118
     * Transfert en Facture
119
     *
120
     * @param row
121
     */
122
    private void transfertFactureFournisseur(SQLRow row) {
123
        BonReceptionSQLElement elt = (BonReceptionSQLElement) Configuration.getInstance().getDirectory().getElement("BON_RECEPTION");
124
        elt.transfertFacture(row.getID());
125
    }
126
}