OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 151 | 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.preferences;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
25 ilm 17
import org.openconcerto.erp.core.customerrelationship.customer.report.FicheClientXmlSheet;
142 ilm 18
import org.openconcerto.erp.core.edm.AttachmentSQLElement;
25 ilm 19
import org.openconcerto.erp.core.finance.accounting.report.BalanceSheet;
151 ilm 20
import org.openconcerto.erp.core.finance.accounting.report.GrandLivreSheetXML;
65 ilm 21
import org.openconcerto.erp.core.finance.accounting.report.JournauxSheetXML;
25 ilm 22
import org.openconcerto.erp.core.humanresources.payroll.report.EtatChargesPayeSheet;
91 ilm 23
import org.openconcerto.erp.core.humanresources.payroll.report.FichePayeSheetXML;
25 ilm 24
import org.openconcerto.erp.core.humanresources.payroll.report.LivrePayeSheet;
25
import org.openconcerto.erp.core.sales.invoice.report.ListeVenteXmlSheet;
26
import org.openconcerto.erp.core.sales.invoice.report.VenteComptoirSheet;
27
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet;
28
import org.openconcerto.erp.core.sales.order.report.CommandeClientXmlSheet;
29
import org.openconcerto.erp.core.sales.quote.report.DevisXmlSheet;
30
import org.openconcerto.erp.core.sales.shipment.report.BonLivraisonXmlSheet;
149 ilm 31
import org.openconcerto.erp.core.supplychain.order.element.DemandePrixSheetXML;
61 ilm 32
import org.openconcerto.erp.generationDoc.AbstractLocalTemplateProvider;
33
import org.openconcerto.erp.generationDoc.DefaultCloudTemplateProvider;
25 ilm 34
import org.openconcerto.erp.generationDoc.DefaultLocalTemplateProvider;
35
import org.openconcerto.erp.generationDoc.DocumentLocalStorageManager;
36
import org.openconcerto.erp.generationDoc.SheetXml;
37
import org.openconcerto.erp.generationDoc.TemplateManager;
38
import org.openconcerto.erp.generationDoc.gestcomm.AvoirClientXmlSheet;
39
import org.openconcerto.erp.generationDoc.gestcomm.AvoirFournisseurXmlSheet;
94 ilm 40
import org.openconcerto.erp.generationDoc.gestcomm.BonReceptionXmlSheet;
25 ilm 41
import org.openconcerto.erp.generationDoc.gestcomm.CommandeXmlSheet;
42
import org.openconcerto.erp.generationDoc.gestcomm.CourrierClientSheet;
43
import org.openconcerto.erp.generationDoc.gestcomm.EtatVentesXmlSheet;
94 ilm 44
import org.openconcerto.erp.generationDoc.gestcomm.FactureFournisseurXmlSheet;
132 ilm 45
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet;
25 ilm 46
import org.openconcerto.erp.generationDoc.gestcomm.FicheRelanceSheet;
47
import org.openconcerto.erp.generationDoc.gestcomm.PointageXmlSheet;
48
import org.openconcerto.erp.generationDoc.gestcomm.RelanceSheet;
49
import org.openconcerto.erp.generationDoc.gestcomm.ReleveChequeEmisSheet;
50
import org.openconcerto.erp.generationDoc.gestcomm.ReleveChequeSheet;
18 ilm 51
import org.openconcerto.sql.Configuration;
52
import org.openconcerto.sql.model.SQLRow;
53
import org.openconcerto.task.config.ComptaBasePropsConfiguration;
54
import org.openconcerto.ui.preferences.TemplateProps;
55
import org.openconcerto.utils.StreamUtils;
56
 
57
import java.io.File;
58
import java.io.IOException;
59
import java.io.InputStream;
60
 
61
import javax.swing.JOptionPane;
62
 
63
public class TemplateNXProps extends TemplateProps {
64
 
65
    private static final String societeBaseName = ((ComptaPropsConfiguration) Configuration.getInstance()).getSocieteBaseName();
66
 
67
    @Override
68
    protected String getPropsFileName() {
69
        final File f = Configuration.getInstance().getConfDir();
70
        final File f2 = new File(f, "Configuration" + File.separator + "Template.properties");
71
 
72
        if (!f2.exists()) {
73
            final InputStream fConf = ComptaBasePropsConfiguration.getStreamStatic("/Configuration/Template.properties");
61 ilm 74
            if (fConf != null) {
18 ilm 75
                try {
76
                    StreamUtils.copy(fConf, f2);
77
                    fConf.close();
78
                } catch (IOException e) {
79
                    JOptionPane.showMessageDialog(null,
80
                            "Impossible de copier le fichier de configuration de l'emplacement des modéles\ndepuis le serveur, veuillez définir l'emplacement des modéles manuellement.");
81
                    e.printStackTrace();
82
                }
83
            }
84
        }
85
 
86
        if (f2.exists()) {
87
            return f2.getAbsolutePath();
88
        } else {
89
            try {
90
                f2.getParentFile().mkdirs();
91
                f2.createNewFile();
92
            } catch (IOException e) {
93
                System.err.println(f2);
94
                e.printStackTrace();
95
            }
96
            return f2.getAbsolutePath();
97
        }
98
    }
99
 
100
    @Override
101
    public String getPropertySuffix() {
102
        return societeBaseName;
103
    }
104
 
105
    @Override
106
    public String getDefaultStringValue() {
19 ilm 107
 
18 ilm 108
        final Configuration conf = ComptaPropsConfiguration.getInstance();
109
        final SQLRow rowSociete = ((ComptaPropsConfiguration) conf).getRowSociete();
110
        return conf.getWD().getAbsolutePath() + File.separator + rowSociete.getString("NOM") + "-" + rowSociete.getID();
111
    }
112
 
25 ilm 113
    public void initDocumentLocalStorage() {
114
        final DocumentLocalStorageManager storage = DocumentLocalStorageManager.getInstance();
115
        String propertyDefaultDirectory = getProperty(SheetXml.DEFAULT_PROPERTY_NAME + "OO");
116
        if (propertyDefaultDirectory == null) {
117
            System.out.println("Warning: no default directory stored for document output");
118
            propertyDefaultDirectory = getDefaultStringValue();
119
        }
120
        storage.setDocumentDefaultDirectory(new File(propertyDefaultDirectory));
121
        String propertyDefaultPDFDirectory = getProperty(SheetXml.DEFAULT_PROPERTY_NAME + "PDF");
122
        if (propertyDefaultPDFDirectory == null) {
123
            System.out.println("Warning: no default directory stored for PFD output");
124
            propertyDefaultPDFDirectory = propertyDefaultDirectory;
125
        }
126
 
142 ilm 127
        final String propertyAtt = getProperty(AttachmentSQLElement.DIRECTORY_PREFS);
128
        if (propertyAtt != null && propertyAtt.trim().length() > 0) {
129
            storage.addDocumentDirectory(AttachmentSQLElement.DIRECTORY_PREFS, new File(propertyAtt));
130
        }
131
 
25 ilm 132
        storage.setPDFDefaultDirectory(new File(propertyDefaultPDFDirectory));
83 ilm 133
 
149 ilm 134
            register(DemandePrixSheetXML.TEMPLATE_ID, DemandePrixSheetXML.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("DEMANDE_PRIX"));
83 ilm 135
            register(DevisXmlSheet.TEMPLATE_ID, DevisXmlSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("DEVIS"));
136
            register(VenteFactureXmlSheet.TEMPLATE_ID, VenteFactureXmlSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("SAISIE_VENTE_FACTURE"));
137
            register(CommandeClientXmlSheet.TEMPLATE_ID, CommandeClientXmlSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("COMMANDE_CLIENT"));
138
            register(BonLivraisonXmlSheet.TEMPLATE_ID, BonLivraisonXmlSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("BON_DE_LIVRAISON"));
139
            register(AvoirClientXmlSheet.TEMPLATE_ID, AvoirClientXmlSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("AVOIR_CLIENT"));
140
            register(AvoirFournisseurXmlSheet.TEMPLATE_ID, AvoirFournisseurXmlSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("AVOIR_FOURNISSEUR"));
144 ilm 141
            register(BonReceptionXmlSheet.TEMPLATE_ID, BonReceptionXmlSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("BON_RECEPTION"));
142
            register(FactureFournisseurXmlSheet.TEMPLATE_ID, FactureFournisseurXmlSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("FACTURE_FOURNISSEUR"));
83 ilm 143
            register(CommandeXmlSheet.TEMPLATE_ID, CommandeXmlSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("COMMANDE"));
149 ilm 144
            register(FicheArticleXmlSheet.TEMPLATE_ID, FicheArticleXmlSheet.TEMPLATE_PROPERTY_NAME, "Fiche article");
83 ilm 145
            register(EtatVentesXmlSheet.TEMPLATE_ID, EtatVentesXmlSheet.TEMPLATE_PROPERTY_NAME, null);
149 ilm 146
            register(FicheClientXmlSheet.TEMPLATE_ID, FicheClientXmlSheet.TEMPLATE_PROPERTY_NAME, "Fiche client");
83 ilm 147
            register(FicheRelanceSheet.TEMPLATE_ID, FicheRelanceSheet.TEMPLATE_PROPERTY_NAME, null);
148
            register(ReleveChequeSheet.TEMPLATE_ID, ReleveChequeSheet.TEMPLATE_PROPERTY_NAME, null);
149
            register(ListeVenteXmlSheet.TEMPLATE_ID, ListeVenteXmlSheet.TEMPLATE_PROPERTY_NAME, null);
150
            register(BalanceSheet.TEMPLATE_ID, BalanceSheet.TEMPLATE_PROPERTY_NAME, BalanceSheet.TEMPLATE_ID);
151 ilm 151
            register(GrandLivreSheetXML.TEMPLATE_ID, GrandLivreSheetXML.TEMPLATE_PROPERTY_NAME, GrandLivreSheetXML.TEMPLATE_ID);
83 ilm 152
            register(JournauxSheetXML.TEMPLATE_ID, JournauxSheetXML.TEMPLATE_PROPERTY_NAME, JournauxSheetXML.TEMPLATE_ID);
153
            register(EtatChargesPayeSheet.TEMPLATE_ID, EtatChargesPayeSheet.TEMPLATE_PROPERTY_NAME, "Etat des charges");
91 ilm 154
            register(FichePayeSheetXML.TEMPLATE_ID, FichePayeSheetXML.TEMPLATE_PROPERTY_NAME, "Fiche paye");
83 ilm 155
            register(LivrePayeSheet.TEMPLATE_ID, LivrePayeSheet.TEMPLATE_PROPERTY_NAME, "Livre paye");
156
            register(CourrierClientSheet.TEMPLATE_ID, CourrierClientSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("COMMANDE"));
157
            register(PointageXmlSheet.TEMPLATE_ID, PointageXmlSheet.TEMPLATE_PROPERTY_NAME, null);
158
            register(RelanceSheet.TEMPLATE_ID, RelanceSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("RELANCE"));
159
            register(VenteComptoirSheet.TEMPLATE_ID, VenteComptoirSheet.TEMPLATE_PROPERTY_NAME, AbstractGenerationDocumentPreferencePanel.getLabelFromTable("SAISIE_VENTE_COMPTOIR"));
160
            register(ReleveChequeEmisSheet.TEMPLATE_ID, ReleveChequeEmisSheet.TEMPLATE_PROPERTY_NAME, null);
25 ilm 161
        storage.dump();
162
 
163
    }
164
 
83 ilm 165
    public void preventecRegister(String path, String templateId, String defaultSubFolder) {
166
        if (templateId == null) {
167
            throw new IllegalArgumentException("null template id");
168
        }
169
 
170
        if (TemplateManager.getInstance().isKnwonTemplate(templateId)) {
171
            System.err.println("Warning: registering known template id : " + templateId);
172
        }
173
        final DocumentLocalStorageManager storage = DocumentLocalStorageManager.getInstance();
174
        if (defaultSubFolder != null) {
175
            storage.addDocumentDirectory(templateId, new File(path, defaultSubFolder));
176
            storage.addPDFDirectory(templateId, new File(path, defaultSubFolder));
177
        } else {
178
            storage.addDocumentDirectory(templateId, new File(path));
179
            storage.addPDFDirectory(templateId, new File(path));
180
        }
181
    }
182
 
61 ilm 183
    public void register(String templateId, String propertyBaseName, String defaultSubFolder) {
25 ilm 184
        if (templateId == null) {
185
            throw new IllegalArgumentException("null template id");
186
        }
187
        if (propertyBaseName == null) {
188
            throw new IllegalArgumentException("null propertyBaseName");
189
        }
190
        if (TemplateManager.getInstance().isKnwonTemplate(templateId)) {
191
            System.err.println("Warning: registering known template id : " + templateId + " with property base name: " + propertyBaseName);
192
        }
193
        final DocumentLocalStorageManager storage = DocumentLocalStorageManager.getInstance();
142 ilm 194
 
25 ilm 195
        final String propertyOO = getProperty(propertyBaseName + "OO");
196
        if (propertyOO != null) {
197
            storage.addDocumentDirectory(templateId, new File(propertyOO));
28 ilm 198
        } else {
199
            if (defaultSubFolder != null && defaultSubFolder.trim().length() > 0) {
200
                storage.addDocumentDirectory(templateId, new File(storage.getDocumentOutputDirectory("default"), defaultSubFolder));
201
            }
25 ilm 202
        }
203
        final String propertyPDF = getProperty(propertyBaseName + "PDF");
204
        if (propertyPDF != null) {
205
            storage.addPDFDirectory(templateId, new File(propertyPDF));
28 ilm 206
        } else {
207
            if (defaultSubFolder != null && defaultSubFolder.trim().length() > 0) {
208
                storage.addDocumentDirectory(templateId, new File(storage.getPDFOutputDirectory("default"), defaultSubFolder));
209
            }
25 ilm 210
        }
211
    }
212
 
18 ilm 213
    synchronized public static TemplateProps getInstance() {
214
        if (instance == null) {
215
            instance = new TemplateNXProps();
25 ilm 216
            ((TemplateNXProps) instance).initDocumentLocalStorage();
217
            ((TemplateNXProps) instance).initDefaulTemplateProvider();
18 ilm 218
        }
219
        return instance;
220
    }
25 ilm 221
 
222
    private void initDefaulTemplateProvider() {
223
        final String property = getProperty("LocationTemplate");
61 ilm 224
        final AbstractLocalTemplateProvider provider;
225
 
226
        final ComptaPropsConfiguration configuration = (ComptaPropsConfiguration) ComptaPropsConfiguration.getInstance();
227
        if (!configuration.isOnCloud()) {
228
            provider = new DefaultLocalTemplateProvider();
229
            if (property != null) {
83 ilm 230
                File storage = new File(property);
231
                ((DefaultLocalTemplateProvider) provider).setBaseDirectory(storage);
61 ilm 232
            }
233
        } else {
234
            provider = new DefaultCloudTemplateProvider(configuration.getSocieteID());
25 ilm 235
        }
61 ilm 236
 
25 ilm 237
        TemplateManager.getInstance().setDefaultProvider(provider);
238
        TemplateManager.getInstance().dump();
239
    }
18 ilm 240
}