OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 94 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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