OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 177 Rev 180
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.order.element;
14
 package org.openconcerto.erp.core.supplychain.order.element;
15
 
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
-
 
17
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
17
import org.openconcerto.erp.core.edm.AttachmentAction;
18
import org.openconcerto.erp.core.edm.AttachmentAction;
18
import org.openconcerto.erp.core.supplychain.order.component.FactureFournisseurSQLComponent;
19
import org.openconcerto.erp.core.supplychain.order.component.FactureFournisseurSQLComponent;
19
import org.openconcerto.erp.generationDoc.gestcomm.FactureFournisseurXmlSheet;
20
import org.openconcerto.erp.generationDoc.gestcomm.FactureFournisseurXmlSheet;
20
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
21
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
21
import org.openconcerto.sql.element.SQLComponent;
22
import org.openconcerto.sql.element.SQLComponent;
22
import org.openconcerto.sql.model.FieldPath;
23
import org.openconcerto.sql.model.FieldPath;
23
import org.openconcerto.sql.model.SQLRowAccessor;
24
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
25
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.sql.model.graph.Path;
26
import org.openconcerto.sql.model.graph.Path;
25
import org.openconcerto.sql.view.EditFrame;
27
import org.openconcerto.sql.view.EditFrame;
26
import org.openconcerto.sql.view.EditPanel;
28
import org.openconcerto.sql.view.EditPanel;
27
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
29
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
28
import org.openconcerto.sql.view.list.IListe;
30
import org.openconcerto.sql.view.list.IListe;
29
import org.openconcerto.sql.view.list.RowAction;
31
import org.openconcerto.sql.view.list.RowAction;
30
import org.openconcerto.sql.view.list.SQLTableModelSource;
32
import org.openconcerto.sql.view.list.SQLTableModelSource;
31
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
33
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
32
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
34
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
33
import org.openconcerto.ui.table.PercentTableCellRenderer;
35
import org.openconcerto.ui.table.PercentTableCellRenderer;
34
import org.openconcerto.utils.CollectionUtils;
36
import org.openconcerto.utils.CollectionUtils;
35
import org.openconcerto.utils.DecimalUtils;
37
import org.openconcerto.utils.DecimalUtils;
36
import org.openconcerto.utils.ListMap;
38
import org.openconcerto.utils.ListMap;
37
 
39
 
38
import java.awt.event.ActionEvent;
40
import java.awt.event.ActionEvent;
39
import java.math.BigDecimal;
41
import java.math.BigDecimal;
40
import java.math.RoundingMode;
42
import java.math.RoundingMode;
41
import java.util.ArrayList;
43
import java.util.ArrayList;
42
import java.util.Collection;
44
import java.util.Collection;
43
import java.util.HashSet;
45
import java.util.HashSet;
44
import java.util.List;
46
import java.util.List;
45
import java.util.Set;
47
import java.util.Set;
46
 
48
 
47
import javax.swing.AbstractAction;
49
import javax.swing.AbstractAction;
48
 
50
 
49
public class FactureFournisseurSQLElement extends ComptaSQLConfElement {
51
public class FactureFournisseurSQLElement extends ComptaSQLConfElement {
50
 
52
 
51
    public FactureFournisseurSQLElement() {
53
    public FactureFournisseurSQLElement() {
52
        super("FACTURE_FOURNISSEUR", "une facture fournisseur", "factures fournisseur");
54
        super("FACTURE_FOURNISSEUR", "une facture fournisseur", "factures fournisseur");
53
        MouseSheetXmlListeListener mouseSheetXmlListeListener = new MouseSheetXmlListeListener(FactureFournisseurXmlSheet.class);
55
        MouseSheetXmlListeListener mouseSheetXmlListeListener = new MouseSheetXmlListeListener(FactureFournisseurXmlSheet.class);
54
        mouseSheetXmlListeListener.setGenerateHeader(true);
56
        mouseSheetXmlListeListener.setGenerateHeader(true);
55
        mouseSheetXmlListeListener.setShowHeader(true);
57
        mouseSheetXmlListeListener.setShowHeader(true);
56
        getRowActions().addAll(mouseSheetXmlListeListener.getRowActions());
58
        getRowActions().addAll(mouseSheetXmlListeListener.getRowActions());
57
        if (getTable().contains("ATTACHMENTS")) {
59
        if (getTable().contains("ATTACHMENTS")) {
58
            PredicateRowAction actionAttachment = new PredicateRowAction(new AttachmentAction().getAction(), true);
60
            PredicateRowAction actionAttachment = new PredicateRowAction(new AttachmentAction().getAction(), true);
59
            actionAttachment.setPredicate(IListeEvent.getSingleSelectionPredicate());
61
            actionAttachment.setPredicate(IListeEvent.getSingleSelectionPredicate());
60
            getRowActions().add(actionAttachment);
62
            getRowActions().add(actionAttachment);
61
        }
63
        }
62
        RowAction actionClone = new RowAction(new AbstractAction() {
64
        RowAction actionClone = new RowAction(new AbstractAction() {
63
            public void actionPerformed(ActionEvent e) {
65
            public void actionPerformed(ActionEvent e) {
64
 
66
 
65
                EditFrame editFrame = new EditFrame(FactureFournisseurSQLElement.this, EditPanel.CREATION);
67
                EditFrame editFrame = new EditFrame(FactureFournisseurSQLElement.this, EditPanel.CREATION);
66
 
68
 
67
                ((FactureFournisseurSQLComponent) editFrame.getSQLComponent()).loadFactureExistante(IListe.get(e).getSelectedId());
69
                ((FactureFournisseurSQLComponent) editFrame.getSQLComponent()).loadFactureExistante(IListe.get(e).getSelectedId());
68
                editFrame.setVisible(true);
70
                editFrame.setVisible(true);
69
            }
71
            }
70
        }, true, "supplychain.invoice.clone") {
72
        }, true, "supplychain.invoice.clone") {
71
            public boolean enabledFor(IListeEvent evt) {
73
            public boolean enabledFor(IListeEvent evt) {
72
                List<? extends SQLRowAccessor> l = evt.getSelectedRows();
74
                List<? extends SQLRowAccessor> l = evt.getSelectedRows();
73
                return (l != null && l.size() == 1);
75
                return (l != null && l.size() == 1);
74
            }
76
            }
75
        };
77
        };
76
        getRowActions().add(actionClone);
78
        getRowActions().add(actionClone);
-
 
79
        final SQLTable tableNum = getTable().getTable("NUMEROTATION_AUTO");
-
 
80
        // incrémentation du numéro auto
-
 
81
        if (tableNum.contains("FACTURE_FOURNISSEUR_START")) {
-
 
82
            NumerotationAutoSQLElement.addClass(this.getClass(), "FACTURE_FOURNISSEUR");
-
 
83
        }
77
    }
84
    }
78
 
85
 
79
    @Override
86
    @Override
80
    public Set<String> getReadOnlyFields() {
87
    public Set<String> getReadOnlyFields() {
81
        Set<String> s = new HashSet<>();
88
        Set<String> s = new HashSet<>();
82
        s.add("NET_A_PAYER");
89
        s.add("NET_A_PAYER");
83
        return s;
90
        return s;
84
    }
91
    }
85
 
92
 
86
    protected List<String> getListFields() {
93
    protected List<String> getListFields() {
87
        final List<String> l = new ArrayList<String>();
94
        final List<String> l = new ArrayList<String>();
88
        l.add("NUMERO");
95
        l.add("NUMERO");
89
        l.add("NOM");
96
        l.add("NOM");
90
        l.add("DATE");
97
        l.add("DATE");
91
        l.add("ID_FOURNISSEUR");
98
        l.add("ID_FOURNISSEUR");
92
        l.add("T_HT");
99
        l.add("T_HT");
93
        l.add("T_TTC");
100
        l.add("T_TTC");
94
        l.add("INFOS");
101
        l.add("INFOS");
95
        l.add("DATE_REGLEMENT");
102
        l.add("DATE_REGLEMENT");
96
        return l;
103
        return l;
97
    }
104
    }
98
 
105
 
99
    @Override
106
    @Override
100
    public ListMap<String, String> getShowAs() {
107
    public ListMap<String, String> getShowAs() {
101
        ListMap<String, String> map = new ListMap<String, String>();
108
        ListMap<String, String> map = new ListMap<String, String>();
102
        map.putCollection(null, "NUMERO", "DATE");
109
        map.putCollection(null, "NUMERO", "DATE");
103
        return map;
110
        return map;
104
    }
111
    }
105
 
112
 
106
    protected List<String> getComboFields() {
113
    protected List<String> getComboFields() {
107
        final List<String> l = new ArrayList<String>();
114
        final List<String> l = new ArrayList<String>();
108
        l.add("NUMERO");
115
        l.add("NUMERO");
109
        l.add("NOM");
116
        l.add("NOM");
110
        l.add("DATE");
117
        l.add("DATE");
111
        return l;
118
        return l;
112
    }
119
    }
113
 
120
 
114
    @Override
121
    @Override
115
    protected void _initTableSource(SQLTableModelSource res) {
122
    protected void _initTableSource(SQLTableModelSource res) {
116
        super._initTableSource(res);
123
        super._initTableSource(res);
117
 
124
 
118
        final BaseSQLTableModelColumn colAvancement = new BaseSQLTableModelColumn("Avancement réglement", BigDecimal.class) {
125
        final BaseSQLTableModelColumn colAvancement = new BaseSQLTableModelColumn("Avancement réglement", BigDecimal.class) {
119
 
126
 
120
            @Override
127
            @Override
121
            protected Object show_(SQLRowAccessor r) {
128
            protected Object show_(SQLRowAccessor r) {
122
 
129
 
123
                return getAvancement(r);
130
                return getAvancement(r);
124
            }
131
            }
125
 
132
 
126
            @Override
133
            @Override
127
            public Set<FieldPath> getPaths() {
134
            public Set<FieldPath> getPaths() {
128
                Path p = new Path(getTable());
135
                Path p = new Path(getTable());
129
                p = p.add(getTable().getTable("ECHEANCE_FOURNISSEUR"));
136
                p = p.add(getTable().getTable("ECHEANCE_FOURNISSEUR"));
130
 
137
 
131
                Path p2 = new Path(getTable());
138
                Path p2 = new Path(getTable());
132
                p2 = p2.add(getTable().getField("ID_AVOIR_FOURNISSEUR"));
139
                p2 = p2.add(getTable().getField("ID_AVOIR_FOURNISSEUR"));
133
 
140
 
134
                return CollectionUtils.createSet(new FieldPath(p, "MONTANT"), new FieldPath(p, "REG_COMPTA"), new FieldPath(p, "REGLE"), new FieldPath(p2, "MONTANT_TTC"));
141
                return CollectionUtils.createSet(new FieldPath(p, "MONTANT"), new FieldPath(p, "REG_COMPTA"), new FieldPath(p, "REGLE"), new FieldPath(p2, "MONTANT_TTC"));
135
            }
142
            }
136
        };
143
        };
137
        res.getColumns().add(colAvancement);
144
        res.getColumns().add(colAvancement);
138
        colAvancement.setRenderer(new PercentTableCellRenderer());
145
        colAvancement.setRenderer(new PercentTableCellRenderer());
139
 
146
 
140
    }
147
    }
141
 
148
 
142
    private BigDecimal getAvancement(SQLRowAccessor r) {
149
    private BigDecimal getAvancement(SQLRowAccessor r) {
143
        Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("ECHEANCE_FOURNISSEUR"));
150
        Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("ECHEANCE_FOURNISSEUR"));
144
        long totalEch = 0;
151
        long totalEch = 0;
145
 
152
 
146
        for (SQLRowAccessor row : rows) {
153
        for (SQLRowAccessor row : rows) {
147
            if (!row.getBoolean("REGLE") && !row.getBoolean("REG_COMPTA")) {
154
            if (!row.getBoolean("REGLE") && !row.getBoolean("REG_COMPTA")) {
148
                totalEch += row.getLong("MONTANT");
155
                totalEch += row.getLong("MONTANT");
149
            }
156
            }
150
        }
157
        }
151
 
158
 
152
        SQLRowAccessor avoir = r.getForeign("ID_AVOIR_FOURNISSEUR");
159
        SQLRowAccessor avoir = r.getForeign("ID_AVOIR_FOURNISSEUR");
153
        BigDecimal avoirTTC = BigDecimal.ZERO;
160
        BigDecimal avoirTTC = BigDecimal.ZERO;
154
        if (avoir != null && !avoir.isUndefined()) {
161
        if (avoir != null && !avoir.isUndefined()) {
155
            avoirTTC = new BigDecimal(avoir.getLong("MONTANT_TTC"));
162
            avoirTTC = new BigDecimal(avoir.getLong("MONTANT_TTC"));
156
        }
163
        }
157
 
164
 
158
        final BigDecimal totalAregler = new BigDecimal(r.getLong("T_TTC")).subtract(avoirTTC);
165
        final BigDecimal totalAregler = new BigDecimal(r.getLong("T_TTC")).subtract(avoirTTC);
159
        if (totalAregler.signum() > 0 && totalEch > 0) {
166
        if (totalAregler.signum() > 0 && totalEch > 0) {
160
            return totalAregler.subtract(new BigDecimal(totalEch)).divide(totalAregler, DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP);
167
            return totalAregler.subtract(new BigDecimal(totalEch)).divide(totalAregler, DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP);
161
        } else {
168
        } else {
162
            return BigDecimal.ONE.movePointRight(2);
169
            return BigDecimal.ONE.movePointRight(2);
163
        }
170
        }
164
    }
171
    }
165
 
172
 
166
    /*
173
    /*
167
     * (non-Javadoc)
174
     * (non-Javadoc)
168
     * 
175
     * 
169
     * @see org.openconcerto.devis.SQLElement#getComponent()
176
     * @see org.openconcerto.devis.SQLElement#getComponent()
170
     */
177
     */
171
    public SQLComponent createComponent() {
178
    public SQLComponent createComponent() {
172
        return new FactureFournisseurSQLComponent();
179
        return new FactureFournisseurSQLComponent();
173
    }
180
    }
174
 
181
 
175
    @Override
182
    @Override
176
    protected String createCode() {
183
    protected String createCode() {
177
        return createCodeOfPackage() + ".invoice.purchase";
184
        return createCodeOfPackage() + ".invoice.purchase";
178
    }
185
    }
179
}
186
}