OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
18 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.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
18
import org.openconcerto.erp.generationDoc.AbstractListeSheetXml;
19
import org.openconcerto.erp.generationDoc.SheetXml;
20
import org.openconcerto.erp.preferences.PrinterNXProps;
21
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.element.SQLElement;
23
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.utils.Tuple2;
25
 
25 ilm 26
import java.io.File;
18 ilm 27
import java.text.DateFormat;
28
import java.text.SimpleDateFormat;
29
import java.util.ArrayList;
30
import java.util.Date;
31
import java.util.HashMap;
32
import java.util.Iterator;
33
import java.util.List;
34
import java.util.Map;
35
 
36
public class ListeFactureXmlSheet extends AbstractListeSheetXml {
25 ilm 37
    public static final String TEMPLATE_ID = "ListeFacture";
38
    public static final String TEMPLATE_PROPERTY_NAME = DEFAULT_PROPERTY_NAME;
18 ilm 39
 
40
    private List<Map<String, Object>> listValues;
41
    private static final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
25 ilm 42
 
18 ilm 43
    private List<Integer> listeIds;
44
 
45
    public ListeFactureXmlSheet(List<Integer> listeIds) {
46
        this.printer = PrinterNXProps.getInstance().getStringProperty("BonPrinter");
47
        this.listeIds = listeIds;
48
    }
49
 
21 ilm 50
    @Override
25 ilm 51
    public String getDefaultTemplateId() {
52
        return TEMPLATE_ID;
53
    }
54
 
55
    @Override
56
    public String getName() {
21 ilm 57
        return "ListeFacture";
58
    }
59
 
18 ilm 60
    protected void createListeValues() {
61
        SQLElement eltFacture = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE");
62
        SQLElement eltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
63
        SQLElement eltTypeRegl = Configuration.getInstance().getDirectory().getElement("TYPE_REGLEMENT");
64
 
65
        if (this.listeIds == null) {
66
            return;
67
        }
68
        this.listValues = new ArrayList<Map<String, Object>>(this.listeIds.size());
69
        for (Iterator<Integer> i = this.listeIds.iterator(); i.hasNext();) {
70
            Map<String, Object> mValues = new HashMap<String, Object>();
71
            SQLRow rowFacture = eltFacture.getTable().getRow(i.next());
72
            mValues.put("DATE", dateFormat.format((Date) rowFacture.getObject("DATE")));
73
            mValues.put("NUMERO", rowFacture.getObject("NUMERO"));
74
            mValues.put("MONTANT_HT", new Double(((Number) rowFacture.getObject("T_HT")).longValue() / 100.0));
75
            mValues.put("MONTANT_TTC", new Double(((Number) rowFacture.getObject("T_TTC")).longValue() / 100.0));
76
            mValues.put("INFOS", rowFacture.getString("INFOS"));
77
 
78
            // Client
79
            SQLRow rowCli;
80
                rowCli = rowFacture.getForeignRow("ID_CLIENT");
81
            String libClient = rowCli.getString("FORME_JURIDIQUE") + " " + rowCli.getString("NOM");
82
            mValues.put("CLIENT", libClient.trim());
83
 
84
 
85
            // Mode de reglement
86
            int idModeRegl = rowFacture.getInt("ID_MODE_REGLEMENT");
87
            if (idModeRegl > 1) {
88
                SQLRow rowModeRegl = eltModeRegl.getTable().getRow(idModeRegl);
89
                Date ech = ModeDeReglementSQLElement.calculDate(rowModeRegl.getInt("AJOURS"), rowModeRegl.getInt("LENJOUR"), (Date) rowFacture.getObject("DATE"));
90
                mValues.put("DATE_ECHEANCE", dateFormat.format(ech));
91
 
92
                int idTypeRegl = rowModeRegl.getInt("ID_TYPE_REGLEMENT");
93
                if (idTypeRegl > 1) {
94
                    SQLRow rowTypeRegl = eltTypeRegl.getTable().getRow(idTypeRegl);
95
                    mValues.put("TYPE_REGLEMENT", rowTypeRegl.getString("NOM"));
96
                }
97
            }
98
 
99
            this.listValues.add(mValues);
100
        }
101
 
102
        this.listAllSheetValues.put(0, this.listValues);
103
    }
104
 
105
}