OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 132 Rev 174
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.sales.invoice.report;
14
 package org.openconcerto.erp.core.sales.invoice.report;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
-
 
17
import org.openconcerto.erp.core.customerrelationship.mail.EmailTemplate;
17
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
18
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
18
import org.openconcerto.erp.preferences.MailRelancePreferencePanel;
-
 
19
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.Configuration;
20
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.preferences.SQLPreferences;
-
 
22
import org.openconcerto.sql.users.UserManager;
21
import org.openconcerto.sql.users.UserManager;
23
import org.openconcerto.utils.GestionDevise;
22
import org.openconcerto.utils.GestionDevise;
24
 
23
 
25
import java.text.DateFormat;
24
import java.text.DateFormat;
26
import java.text.SimpleDateFormat;
25
import java.text.SimpleDateFormat;
Line 28... Line 27...
28
import java.util.HashMap;
27
import java.util.HashMap;
29
import java.util.Map;
28
import java.util.Map;
30
 
29
 
31
public class MailRelanceCreator {
30
public class MailRelanceCreator {
32
 
31
 
-
 
32
    private final EmailTemplate template;
33
    SQLRow rowEcheance;
33
    private final SQLRow rowEcheance;
-
 
34
    private final Map<String, String> map;
34
 
35
 
-
 
36
    public MailRelanceCreator(EmailTemplate template, SQLRow row) {
35
    public MailRelanceCreator() {
37
        if (template == null) {
-
 
38
            template = new EmailTemplate("defautl", getDefaultObject(), getDefaultValue(), true, "dd/MM/yyyy");
-
 
39
        }
-
 
40
        this.template = template;
-
 
41
        this.rowEcheance = row;
36
 
42
 
-
 
43
        this.map = getMapValues();
37
    }
44
    }
38
 
45
 
39
    public String getDefaultObject() {
46
    public String getDefaultObject() {
40
        return "Relance {FactureNumero}";
47
        return "Relance {FactureNumero}";
41
    }
48
    }
Line 48... Line 55...
48
                + "Dans l'attente d’un prompt règlement,\n\n" + "Nous vous prions d\'agréer, Madame, Monsieur, l\'expression de nos sentiments distingués.";
55
                + "Dans l'attente d’un prompt règlement,\n\n" + "Nous vous prions d\'agréer, Madame, Monsieur, l\'expression de nos sentiments distingués.";
49
 
56
 
50
        return value;
57
        return value;
51
    }
58
    }
52
 
59
 
53
    public Map<String, String> getMapValues(SQLRow rowEch, String datePattern) {
60
    private Map<String, String> getMapValues() {
-
 
61
        String datePattern = this.template.getDateFormat();
-
 
62
        if (datePattern == null || datePattern.trim().isEmpty()) {
-
 
63
            datePattern = "dd/MM/yyyy";
-
 
64
        }
-
 
65
 
54
        final Map<String, String> map = new HashMap<String, String>();
66
        final Map<String, String> map = new HashMap<>();
55
 
67
 
56
        final SQLRow rowSoc = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
68
        final SQLRow rowSoc = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
57
        final SQLRow rowSocAdresse = rowSoc.getForeignRow("ID_ADRESSE_COMMON");
69
        final SQLRow rowSocAdresse = rowSoc.getForeignRow("ID_ADRESSE_COMMON");
58
        SQLRow rowUser = rowSoc.getTable().getDBRoot().findTable("USER_COMMON").getRow(UserManager.getUser().getId());
70
        SQLRow rowUser = rowSoc.getTable().getDBRoot().findTable("USER_COMMON").getRow(UserManager.getUser().getId());
59
        map.put("UserName", rowUser.getString("NOM"));
71
        map.put("UserName", rowUser.getString("NOM"));
Line 82... Line 94...
82
        }
94
        }
83
 
95
 
84
        map.put("SocieteVille", ville);
96
        map.put("SocieteVille", ville);
85
 
97
 
86
        SQLRow rowClient;
98
        SQLRow rowClient;
87
        final SQLRow clientRowNX = rowEch.getForeignRow("ID_CLIENT");
99
        final SQLRow clientRowNX = this.rowEcheance.getForeignRow("ID_CLIENT");
88
            rowClient = clientRowNX;
100
            rowClient = clientRowNX;
89
        SQLRow rowAdresse = rowClient.getForeignRow("ID_ADRESSE");
101
        SQLRow rowAdresse = rowClient.getForeignRow("ID_ADRESSE");
90
        if (!clientRowNX.isForeignEmpty("ID_ADRESSE_F")) {
102
        if (!clientRowNX.isForeignEmpty("ID_ADRESSE_F")) {
91
            rowAdresse = clientRowNX.getForeign("ID_ADRESSE_F");
103
            rowAdresse = clientRowNX.getForeign("ID_ADRESSE_F");
92
        }
104
        }
Line 116... Line 128...
116
        // Date relance
128
        // Date relance
117
        Date d = new Date();
129
        Date d = new Date();
118
        DateFormat dateFormat = new SimpleDateFormat(datePattern);
130
        DateFormat dateFormat = new SimpleDateFormat(datePattern);
119
        map.put("RelanceDate", dateFormat.format(d));
131
        map.put("RelanceDate", dateFormat.format(d));
120
 
132
 
121
        SQLRow rowFacture = rowEch.getForeignRow("ID_SAISIE_VENTE_FACTURE");
133
        SQLRow rowFacture = this.rowEcheance.getForeignRow("ID_SAISIE_VENTE_FACTURE");
122
 
134
 
123
 
135
 
124
        // Infos facture
136
        // Infos facture
125
        Long lTotal = (Long) rowFacture.getObject("T_TTC");
137
        Long lTotal = (Long) rowFacture.getObject("T_TTC");
126
        Long lRestant = (Long) rowEch.getObject("MONTANT");
138
        Long lRestant = (Long) this.rowEcheance.getObject("MONTANT");
127
        Long lVerse = new Long(lTotal.longValue() - lRestant.longValue());
139
        Long lVerse = Long.valueOf(lTotal.longValue() - lRestant.longValue());
128
        map.put("FactureNumero", rowFacture.getString("NUMERO"));
140
        map.put("FactureNumero", rowFacture.getString("NUMERO"));
129
        map.put("FactureReference", rowFacture.getString("NOM"));
141
        map.put("FactureReference", rowFacture.getString("NOM"));
130
        map.put("FactureTotal", GestionDevise.currencyToString(lTotal.longValue(), true));
142
        map.put("FactureTotal", GestionDevise.currencyToString(lTotal.longValue(), true));
131
        map.put("FactureRestant", GestionDevise.currencyToString(lRestant.longValue(), true));
143
        map.put("FactureRestant", GestionDevise.currencyToString(lRestant.longValue(), true));
132
        map.put("FactureVerse", GestionDevise.currencyToString(lVerse.longValue(), true));
144
        map.put("FactureVerse", GestionDevise.currencyToString(lVerse.longValue(), true));
Line 134... Line 146...
134
 
146
 
135
        Date dFacture = (Date) rowFacture.getObject("DATE");
147
        Date dFacture = (Date) rowFacture.getObject("DATE");
136
        SQLRow modeRegRow = rowFacture.getForeignRow("ID_MODE_REGLEMENT");
148
        SQLRow modeRegRow = rowFacture.getForeignRow("ID_MODE_REGLEMENT");
137
        Date dateEch = ModeDeReglementSQLElement.calculDate(modeRegRow.getInt("AJOURS"), modeRegRow.getInt("LENJOUR"), dFacture);
149
        Date dateEch = ModeDeReglementSQLElement.calculDate(modeRegRow.getInt("AJOURS"), modeRegRow.getInt("LENJOUR"), dFacture);
138
        map.put("FactureDateEcheance", dateFormat.format(dateEch));
150
        map.put("FactureDateEcheance", dateFormat.format(dateEch));
139
 
-
 
-
 
151
        map.put("message", "");
140
        return map;
152
        return map;
141
    }
153
    }
142
 
154
 
143
    public String getObject(SQLRow rowEch) {
155
    public String getObject() {
144
        SQLPreferences prefs = new SQLPreferences(rowEch.getTable().getDBRoot());
-
 
145
        String object = prefs.get(MailRelancePreferencePanel.MAIL_RELANCE_OBJET, getDefaultObject());
-
 
146
        String date = prefs.get(MailRelancePreferencePanel.MAIL_RELANCE_DATE_PATTERN, "dd/MM/yyyy");
-
 
147
        return fill(rowEch, date, object);
156
        return fill(this.template.getTitle());
148
    }
157
    }
149
 
158
 
150
    public String getValue(SQLRow rowEch) {
159
    public String getValue() {
151
        SQLPreferences prefs = new SQLPreferences(rowEch.getTable().getDBRoot());
-
 
152
        String value = prefs.get(MailRelancePreferencePanel.MAIL_RELANCE, getDefaultValue());
-
 
153
        String date = prefs.get(MailRelancePreferencePanel.MAIL_RELANCE_DATE_PATTERN, "dd/MM/yyyy");
-
 
154
        return fill(rowEch, date, value);
160
        return fill(this.template.getText());
155
    }
161
    }
156
 
162
 
157
    private String fill(SQLRow rowEch, String datePattern, String string) {
163
    private String fill(String string) {
158
 
-
 
159
        Map<String, String> map = getMapValues(rowEch, datePattern);
-
 
160
        String result = string;
164
        String result = string;
161
        for (String key : map.keySet()) {
165
        for (String key : this.map.keySet()) {
162
            result = result.replace("{" + key + "}", map.get(key));
166
            result = result.replace("{" + key + "}", this.map.get(key));
163
        }
167
        }
164
        return result;
168
        return result;
165
    }
169
    }
166
 
170
 
167
}
171
}