OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Rev 180 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 177
Line 17... Line 17...
17
import org.openconcerto.erp.core.edm.AttachmentAction;
17
import org.openconcerto.erp.core.edm.AttachmentAction;
18
import org.openconcerto.erp.core.supplychain.order.component.FactureFournisseurSQLComponent;
18
import org.openconcerto.erp.core.supplychain.order.component.FactureFournisseurSQLComponent;
19
import org.openconcerto.erp.generationDoc.gestcomm.FactureFournisseurXmlSheet;
19
import org.openconcerto.erp.generationDoc.gestcomm.FactureFournisseurXmlSheet;
20
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
20
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
21
import org.openconcerto.sql.element.SQLComponent;
21
import org.openconcerto.sql.element.SQLComponent;
-
 
22
import org.openconcerto.sql.model.FieldPath;
22
import org.openconcerto.sql.model.SQLRowAccessor;
23
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
24
import org.openconcerto.sql.model.graph.Path;
23
import org.openconcerto.sql.view.EditFrame;
25
import org.openconcerto.sql.view.EditFrame;
24
import org.openconcerto.sql.view.EditPanel;
26
import org.openconcerto.sql.view.EditPanel;
-
 
27
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
25
import org.openconcerto.sql.view.list.IListe;
28
import org.openconcerto.sql.view.list.IListe;
26
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
-
 
27
import org.openconcerto.sql.view.list.RowAction;
29
import org.openconcerto.sql.view.list.RowAction;
-
 
30
import org.openconcerto.sql.view.list.SQLTableModelSource;
-
 
31
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
28
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
32
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
-
 
33
import org.openconcerto.ui.table.PercentTableCellRenderer;
-
 
34
import org.openconcerto.utils.CollectionUtils;
-
 
35
import org.openconcerto.utils.DecimalUtils;
29
import org.openconcerto.utils.ListMap;
36
import org.openconcerto.utils.ListMap;
30
 
37
 
31
import java.awt.event.ActionEvent;
38
import java.awt.event.ActionEvent;
-
 
39
import java.math.BigDecimal;
-
 
40
import java.math.RoundingMode;
32
import java.util.ArrayList;
41
import java.util.ArrayList;
-
 
42
import java.util.Collection;
33
import java.util.HashSet;
43
import java.util.HashSet;
34
import java.util.List;
44
import java.util.List;
35
import java.util.Set;
45
import java.util.Set;
36
 
46
 
37
import javax.swing.AbstractAction;
47
import javax.swing.AbstractAction;
Line 80... Line 90...
80
        l.add("DATE");
90
        l.add("DATE");
81
        l.add("ID_FOURNISSEUR");
91
        l.add("ID_FOURNISSEUR");
82
        l.add("T_HT");
92
        l.add("T_HT");
83
        l.add("T_TTC");
93
        l.add("T_TTC");
84
        l.add("INFOS");
94
        l.add("INFOS");
-
 
95
        l.add("DATE_REGLEMENT");
85
        return l;
96
        return l;
86
    }
97
    }
87
 
98
 
88
    @Override
99
    @Override
89
    public ListMap<String, String> getShowAs() {
100
    public ListMap<String, String> getShowAs() {
Line 98... Line 109...
98
        l.add("NOM");
109
        l.add("NOM");
99
        l.add("DATE");
110
        l.add("DATE");
100
        return l;
111
        return l;
101
    }
112
    }
102
 
113
 
-
 
114
    @Override
-
 
115
    protected void _initTableSource(SQLTableModelSource res) {
-
 
116
        super._initTableSource(res);
-
 
117
 
-
 
118
        final BaseSQLTableModelColumn colAvancement = new BaseSQLTableModelColumn("Avancement réglement", BigDecimal.class) {
-
 
119
 
-
 
120
            @Override
-
 
121
            protected Object show_(SQLRowAccessor r) {
-
 
122
 
-
 
123
                return getAvancement(r);
-
 
124
            }
-
 
125
 
-
 
126
            @Override
-
 
127
            public Set<FieldPath> getPaths() {
-
 
128
                Path p = new Path(getTable());
-
 
129
                p = p.add(getTable().getTable("ECHEANCE_FOURNISSEUR"));
-
 
130
 
-
 
131
                Path p2 = new Path(getTable());
-
 
132
                p2 = p2.add(getTable().getField("ID_AVOIR_FOURNISSEUR"));
-
 
133
 
-
 
134
                return CollectionUtils.createSet(new FieldPath(p, "MONTANT"), new FieldPath(p, "REG_COMPTA"), new FieldPath(p, "REGLE"), new FieldPath(p2, "MONTANT_TTC"));
-
 
135
            }
-
 
136
        };
-
 
137
        res.getColumns().add(colAvancement);
-
 
138
        colAvancement.setRenderer(new PercentTableCellRenderer());
-
 
139
 
-
 
140
    }
-
 
141
 
-
 
142
    private BigDecimal getAvancement(SQLRowAccessor r) {
-
 
143
        Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("ECHEANCE_FOURNISSEUR"));
-
 
144
        long totalEch = 0;
-
 
145
 
-
 
146
        for (SQLRowAccessor row : rows) {
-
 
147
            if (!row.getBoolean("REGLE") && !row.getBoolean("REG_COMPTA")) {
-
 
148
                totalEch += row.getLong("MONTANT");
-
 
149
            }
-
 
150
        }
-
 
151
 
-
 
152
        SQLRowAccessor avoir = r.getForeign("ID_AVOIR_FOURNISSEUR");
-
 
153
        BigDecimal avoirTTC = BigDecimal.ZERO;
-
 
154
        if (avoir != null && !avoir.isUndefined()) {
-
 
155
            avoirTTC = new BigDecimal(avoir.getLong("MONTANT_TTC"));
-
 
156
        }
-
 
157
 
-
 
158
        final BigDecimal totalAregler = new BigDecimal(r.getLong("T_TTC")).subtract(avoirTTC);
-
 
159
        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);
-
 
161
        } else {
-
 
162
            return BigDecimal.ONE.movePointRight(2);
-
 
163
        }
-
 
164
    }
-
 
165
 
103
    /*
166
    /*
104
     * (non-Javadoc)
167
     * (non-Javadoc)
105
     * 
168
     * 
106
     * @see org.openconcerto.devis.SQLElement#getComponent()
169
     * @see org.openconcerto.devis.SQLElement#getComponent()
107
     */
170
     */