OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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