OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 83 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21 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.sales.invoice.report;
15
 
16
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
17
import org.openconcerto.erp.generationDoc.AbstractListeSheetXml;
18
import org.openconcerto.erp.preferences.PrinterNXProps;
19
import org.openconcerto.sql.Configuration;
20
import org.openconcerto.sql.element.SQLElement;
21
import org.openconcerto.sql.model.SQLRow;
22
import org.openconcerto.sql.model.SQLRowListRSH;
23
import org.openconcerto.sql.model.SQLSelect;
80 ilm 24
import org.openconcerto.sql.model.SQLTable;
21 ilm 25
import org.openconcerto.sql.model.Where;
26
import org.openconcerto.utils.GestionDevise;
27
 
28
import java.text.DateFormat;
29
import java.text.SimpleDateFormat;
30
import java.util.ArrayList;
31
import java.util.HashMap;
32
import java.util.List;
33
import java.util.Map;
34
 
35
public class ListeDebiteursXmlSheet extends AbstractListeSheetXml {
36
 
142 ilm 37
    private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
21 ilm 38
 
39
    public ListeDebiteursXmlSheet() {
67 ilm 40
        super();
21 ilm 41
        this.printer = PrinterNXProps.getInstance().getStringProperty("BonPrinter");
42
    }
43
 
67 ilm 44
    @Override
45
    protected String getStoragePathP() {
46
        return "Autres";
47
    }
48
 
25 ilm 49
    public String getDefaultTemplateId() {
21 ilm 50
        return "ListeDebiteur";
51
    }
52
 
25 ilm 53
    @Override
54
    public String getName() {
55
        return "ListeDebiteurs";
56
    }
57
 
21 ilm 58
    SQLElement eltEch = Configuration.getInstance().getDirectory().getElement("ECHEANCE_CLIENT");
59
    SQLElement eltVf = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
60
    SQLElement eltMvt = Configuration.getInstance().getDirectory().getElement("MOUVEMENT");
61
    SQLElement eltEnc = Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT");
62
    SQLElement eltEncElt = Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT_ELEMENT");
63
 
64
    protected void createListeValues() {
65
 
66
        // On récupére les échéances en cours
80 ilm 67
        SQLSelect sel = new SQLSelect();
68
        final SQLTable echTable = eltEch.getTable();
69
        final SQLTable clientTable = echTable.getForeignTable("ID_CLIENT");
70
        sel.addSelectStar(echTable);
71
        Where w = new Where(echTable.getField("REGLE"), "=", Boolean.FALSE);
72
        w = w.and(new Where(echTable.getField("REG_COMPTA"), "=", Boolean.FALSE));
73
        w = w.and(new Where(clientTable.getKey(), "=", echTable.getField("ID_CLIENT")));
83 ilm 74
        final SQLTable vfTable = echTable.getForeignTable("ID_SAISIE_VENTE_FACTURE");
75
        w = w.and(new Where(vfTable.getKey(), "=", echTable.getField("ID_SAISIE_VENTE_FACTURE")));
21 ilm 76
        sel.setWhere(w);
83 ilm 77
 
78
        sel.addFieldOrder(vfTable.getField("NUMERO"));
79
 
21 ilm 80
        List<SQLRow> l = (List<SQLRow>) eltEch.getTable().getBase().getDataSource().execute(sel.asString(), SQLRowListRSH.createFromSelect(sel));
81
 
82
        List<Map<String, Object>> listValues = new ArrayList<Map<String, Object>>();
83
        Map<Integer, String> styleValues = new HashMap<Integer, String>();
84
        for (SQLRow sqlRow : l) {
85
            Map<String, Object> mValues = new HashMap<String, Object>();
86
            int idMouvement = MouvementSQLElement.getSourceId(sqlRow.getInt("ID_MOUVEMENT"));
87
            SQLRow rowMvt = eltMvt.getTable().getRow(idMouvement);
80 ilm 88
            mValues.put("DATE_ECHEANCE", dateFormat.format(sqlRow.getDate("DATE").getTime()));
21 ilm 89
            if (rowMvt.getString("SOURCE").equalsIgnoreCase(eltVf.getTable().getName())) {
90
                SQLRow rowVf = eltVf.getTable().getRow(rowMvt.getInt("IDSOURCE"));
91
                mValues.put("NUMERO_FACTURE", rowVf.getString("NUMERO"));
28 ilm 92
                mValues.put("REFERENCE", rowVf.getString("NOM"));
21 ilm 93
                mValues.put("DATE", dateFormat.format(rowVf.getDate("DATE").getTime()));
94
                mValues.put("MODE_REGLEMENT", "");
95
                mValues.put("MONTANT", GestionDevise.currencyToString(rowVf.getLong("T_TTC")));
96
            } else {
97
                mValues.put("NUMERO_FACTURE", "");
98
                mValues.put("REFERENCE", "");
99
                mValues.put("DATE", "");
100
                mValues.put("MODE_REGLEMENT", "");
101
                mValues.put("MONTANT", "");
102
            }
103
            SQLRow rowClient = sqlRow.getForeignRow("ID_CLIENT");
104
            mValues.put("NOM_CLIENT", rowClient.getString("NOM"));
105
            mValues.put("CODE_CLIENT", rowClient.getString("CODE"));
106
            mValues.put("TELEPHONE", rowClient.getString("TEL"));
107
            styleValues.put(listValues.size(), "Normal");
108
            listValues.add(mValues);
109
 
110
            List<SQLRow> enc = sqlRow.getReferentRows(eltEncElt.getTable());
111
 
112
            for (SQLRow sqlRow2 : enc) {
113
                Map<String, Object> mValuesEnc = new HashMap<String, Object>();
114
                SQLRow rowEnc = sqlRow2.getForeignRow("ID_ENCAISSER_MONTANT");
115
                SQLRow rowMdr = rowEnc.getForeignRow("ID_MODE_REGLEMENT");
116
                mValuesEnc.put("NUMERO_FACTURE", "");
117
                mValuesEnc.put("REFERENCE", rowMdr.getString("NOM"));
118
                mValuesEnc.put("DATE", dateFormat.format(rowEnc.getDate("DATE").getTime()));
119
                mValuesEnc.put("NOM_CLIENT", "");
120
                mValuesEnc.put("CODE_CLIENT", "");
121
                mValuesEnc.put("TELEPHONE", "");
122
                mValuesEnc.put("MODE_REGLEMENT", rowMdr.getForeignRow("ID_TYPE_REGLEMENT").getString("NOM"));
123
                mValuesEnc.put("MONTANT", GestionDevise.currencyToString(sqlRow2.getLong("MONTANT_REGLE")));
124
                styleValues.put(listValues.size(), "Titre 1");
125
                listValues.add(mValuesEnc);
126
 
127
            }
128
            if (enc != null && enc.size() > 0) {
129
                Map<String, Object> mValuesEnc = new HashMap<String, Object>();
130
                mValuesEnc.put("DATE", dateFormat.format(sqlRow.getDate("DATE").getTime()));
131
                mValuesEnc.put("MODE_REGLEMENT", "Restant à régler");
132
                mValuesEnc.put("MONTANT", GestionDevise.currencyToString(sqlRow.getLong("MONTANT")));
133
                styleValues.put(listValues.size(), "Titre 1");
134
                listValues.add(mValuesEnc);
135
            }
136
 
137
        }
138
 
139
        this.listAllSheetValues.put(0, listValues);
140
        this.styleAllSheetValues.put(0, styleValues);
25 ilm 141
 
21 ilm 142
    }
143
}