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
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.config;
15
 
16
import static java.util.Arrays.asList;
17
import org.openconcerto.erp.core.common.component.SocieteCommonSQLElement;
18
import org.openconcerto.erp.core.common.element.AdresseCommonSQLElement;
19
import org.openconcerto.erp.core.common.element.AdresseSQLElement;
20
import org.openconcerto.erp.core.common.element.DepartementSQLElement;
19 ilm 21
import org.openconcerto.erp.core.common.element.LangueSQLElement;
18 ilm 22
import org.openconcerto.erp.core.common.element.MoisSQLElement;
23
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
24
import org.openconcerto.erp.core.common.element.PaysSQLElement;
25
import org.openconcerto.erp.core.common.element.StyleSQLElement;
26
import org.openconcerto.erp.core.common.element.TitrePersonnelSQLElement;
27
import org.openconcerto.erp.core.customerrelationship.customer.element.ClientNormalSQLElement;
28
import org.openconcerto.erp.core.customerrelationship.customer.element.ContactSQLElement;
29
import org.openconcerto.erp.core.customerrelationship.customer.element.CourrierClientSQLElement;
30
import org.openconcerto.erp.core.customerrelationship.customer.element.ModeleCourrierClientSQLElement;
31
import org.openconcerto.erp.core.customerrelationship.customer.element.ReferenceClientSQLElement;
32
import org.openconcerto.erp.core.customerrelationship.customer.element.RelanceSQLElement;
33
import org.openconcerto.erp.core.customerrelationship.customer.element.TypeLettreRelanceSQLElement;
21 ilm 34
import org.openconcerto.erp.core.customerrelationship.customer.element.ContactSQLElement.ContactFournisseurSQLElement;
18 ilm 35
import org.openconcerto.erp.core.finance.accounting.element.AnalytiqueSQLElement;
36
import org.openconcerto.erp.core.finance.accounting.element.AssociationAnalytiqueSQLElement;
37
import org.openconcerto.erp.core.finance.accounting.element.AssociationCompteAnalytiqueSQLElement;
38
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
39
import org.openconcerto.erp.core.finance.accounting.element.ComptePCGSQLElement;
40
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
41
import org.openconcerto.erp.core.finance.accounting.element.ExerciceCommonSQLElement;
42
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
43
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
44
import org.openconcerto.erp.core.finance.accounting.element.NatureCompteSQLElement;
45
import org.openconcerto.erp.core.finance.accounting.element.PieceSQLElement;
46
import org.openconcerto.erp.core.finance.accounting.element.PosteAnalytiqueSQLElement;
47
import org.openconcerto.erp.core.finance.accounting.element.RepartitionAnalytiqueSQLElement;
48
import org.openconcerto.erp.core.finance.accounting.element.SaisieKmItemSQLElement;
49
import org.openconcerto.erp.core.finance.accounting.element.SaisieKmSQLElement;
50
import org.openconcerto.erp.core.finance.accounting.element.TypeComptePCGSQLElement;
51
import org.openconcerto.erp.core.finance.payment.element.ChequeAEncaisserSQLElement;
52
import org.openconcerto.erp.core.finance.payment.element.ChequeAvoirClientSQLElement;
53
import org.openconcerto.erp.core.finance.payment.element.ChequeFournisseurSQLElement;
54
import org.openconcerto.erp.core.finance.payment.element.EncaisserMontantElementSQLElement;
55
import org.openconcerto.erp.core.finance.payment.element.EncaisserMontantSQLElement;
56
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
57
import org.openconcerto.erp.core.finance.payment.element.ReglerMontantSQLElement;
58
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
59
import org.openconcerto.erp.core.finance.tax.element.EcoTaxeSQLElement;
60
import org.openconcerto.erp.core.finance.tax.element.TaxeSQLElement;
61
import org.openconcerto.erp.core.humanresources.employe.SituationFamilialeSQLElement;
62
import org.openconcerto.erp.core.humanresources.employe.element.CommercialSQLElement;
63
import org.openconcerto.erp.core.humanresources.employe.element.EtatCivilSQLElement;
64
import org.openconcerto.erp.core.humanresources.payroll.element.AcompteSQLElement;
65
import org.openconcerto.erp.core.humanresources.payroll.element.CaisseCotisationSQLElement;
66
import org.openconcerto.erp.core.humanresources.payroll.element.ClassementConventionnelSQLElement;
67
import org.openconcerto.erp.core.humanresources.payroll.element.CodeCaractActiviteSQLElement;
68
import org.openconcerto.erp.core.humanresources.payroll.element.CodeContratTravailSQLElement;
69
import org.openconcerto.erp.core.humanresources.payroll.element.CodeDroitContratSQLElement;
70
import org.openconcerto.erp.core.humanresources.payroll.element.CodeEmploiSQLElement;
71
import org.openconcerto.erp.core.humanresources.payroll.element.CodeIdccSQLElement;
72
import org.openconcerto.erp.core.humanresources.payroll.element.CodeRegimeSQLElement;
73
import org.openconcerto.erp.core.humanresources.payroll.element.CodeStatutCategorielSQLElement;
74
import org.openconcerto.erp.core.humanresources.payroll.element.CodeStatutProfSQLElement;
75
import org.openconcerto.erp.core.humanresources.payroll.element.ContratSalarieSQLElement;
76
import org.openconcerto.erp.core.humanresources.payroll.element.CumulsCongesSQLElement;
77
import org.openconcerto.erp.core.humanresources.payroll.element.CumulsPayeSQLElement;
78
import org.openconcerto.erp.core.humanresources.payroll.element.FichePayeElementSQLElement;
79
import org.openconcerto.erp.core.humanresources.payroll.element.FichePayeSQLElement;
80
import org.openconcerto.erp.core.humanresources.payroll.element.ImpressionRubriqueSQLElement;
81
import org.openconcerto.erp.core.humanresources.payroll.element.InfosSalariePayeSQLElement;
82
import org.openconcerto.erp.core.humanresources.payroll.element.ModeReglementPayeSQLElement;
83
import org.openconcerto.erp.core.humanresources.payroll.element.PeriodeValiditeSQLElement;
84
import org.openconcerto.erp.core.humanresources.payroll.element.ProfilPayeElementSQLElement;
85
import org.openconcerto.erp.core.humanresources.payroll.element.ProfilPayeSQLElement;
86
import org.openconcerto.erp.core.humanresources.payroll.element.RegimeBaseSQLElement;
87
import org.openconcerto.erp.core.humanresources.payroll.element.ReglementPayeSQLElement;
88
import org.openconcerto.erp.core.humanresources.payroll.element.RubriqueBrutSQLElement;
89
import org.openconcerto.erp.core.humanresources.payroll.element.RubriqueCommSQLElement;
90
import org.openconcerto.erp.core.humanresources.payroll.element.RubriqueCotisationSQLElement;
91
import org.openconcerto.erp.core.humanresources.payroll.element.RubriqueNetSQLElement;
92
import org.openconcerto.erp.core.humanresources.payroll.element.SalarieSQLElement;
93
import org.openconcerto.erp.core.humanresources.payroll.element.TypeRubriqueBrutSQLElement;
94
import org.openconcerto.erp.core.humanresources.payroll.element.TypeRubriqueNetSQLElement;
95
import org.openconcerto.erp.core.humanresources.payroll.element.VariablePayeSQLElement;
96
import org.openconcerto.erp.core.humanresources.payroll.element.VariableSalarieSQLElement;
97
import org.openconcerto.erp.core.humanresources.timesheet.element.PointageSQLElement;
98
import org.openconcerto.erp.core.sales.credit.element.AvoirClientElementSQLElement;
99
import org.openconcerto.erp.core.sales.credit.element.AvoirClientSQLElement;
100
import org.openconcerto.erp.core.sales.invoice.element.EcheanceClientSQLElement;
101
import org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureItemSQLElement;
102
import org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureSQLElement;
25 ilm 103
import org.openconcerto.erp.core.sales.invoice.ui.SaisieVenteFactureItemTable;
18 ilm 104
import org.openconcerto.erp.core.sales.order.element.CommandeClientElementSQLElement;
105
import org.openconcerto.erp.core.sales.order.element.CommandeClientSQLElement;
106
import org.openconcerto.erp.core.sales.pos.element.CaisseTicketSQLElement;
107
import org.openconcerto.erp.core.sales.pos.element.SaisieVenteComptoirSQLElement;
108
import org.openconcerto.erp.core.sales.pos.element.TicketCaisseSQLElement;
19 ilm 109
import org.openconcerto.erp.core.sales.price.element.DeviseSQLElement;
18 ilm 110
import org.openconcerto.erp.core.sales.price.element.TarifSQLElement;
19 ilm 111
import org.openconcerto.erp.core.sales.product.element.ArticleDesignationSQLElement;
112
import org.openconcerto.erp.core.sales.product.element.ArticleTarifSQLElement;
18 ilm 113
import org.openconcerto.erp.core.sales.product.element.FamilleArticleSQLElement;
114
import org.openconcerto.erp.core.sales.product.element.MetriqueSQLElement;
115
import org.openconcerto.erp.core.sales.product.element.ModeVenteArticleSQLElement;
116
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
117
import org.openconcerto.erp.core.sales.quote.element.DevisItemSQLElement;
118
import org.openconcerto.erp.core.sales.quote.element.DevisSQLElement;
119
import org.openconcerto.erp.core.sales.quote.element.EtatDevisSQLElement;
120
import org.openconcerto.erp.core.sales.shipment.element.BonDeLivraisonItemSQLElement;
121
import org.openconcerto.erp.core.sales.shipment.element.BonDeLivraisonSQLElement;
122
import org.openconcerto.erp.core.supplychain.credit.element.AvoirFournisseurSQLElement;
123
import org.openconcerto.erp.core.supplychain.order.element.CommandeElementSQLElement;
124
import org.openconcerto.erp.core.supplychain.order.element.CommandeSQLElement;
125
import org.openconcerto.erp.core.supplychain.order.element.SaisieAchatSQLElement;
126
import org.openconcerto.erp.core.supplychain.receipt.element.BonReceptionElementSQLElement;
127
import org.openconcerto.erp.core.supplychain.receipt.element.BonReceptionSQLElement;
128
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
129
import org.openconcerto.erp.core.supplychain.stock.element.StockSQLElement;
130
import org.openconcerto.erp.core.supplychain.supplier.element.EcheanceFournisseurSQLElement;
131
import org.openconcerto.erp.core.supplychain.supplier.element.FournisseurSQLElement;
21 ilm 132
import org.openconcerto.erp.generationDoc.element.ModeleSQLElement;
133
import org.openconcerto.erp.generationDoc.element.TypeModeleSQLElement;
19 ilm 134
import org.openconcerto.erp.injector.ArticleCommandeEltSQLInjector;
18 ilm 135
import org.openconcerto.erp.injector.BonFactureSQLInjector;
136
import org.openconcerto.erp.injector.BrFactureAchatSQLInjector;
137
import org.openconcerto.erp.injector.CommandeBlEltSQLInjector;
138
import org.openconcerto.erp.injector.CommandeBlSQLInjector;
139
import org.openconcerto.erp.injector.CommandeBrSQLInjector;
19 ilm 140
import org.openconcerto.erp.injector.CommandeCliCommandeSQLInjector;
18 ilm 141
import org.openconcerto.erp.injector.CommandeFactureAchatSQLInjector;
142
import org.openconcerto.erp.injector.CommandeFactureClientSQLInjector;
19 ilm 143
import org.openconcerto.erp.injector.DevisCommandeFournisseurSQLInjector;
18 ilm 144
import org.openconcerto.erp.injector.DevisCommandeSQLInjector;
145
import org.openconcerto.erp.injector.DevisEltFactureEltSQLInjector;
146
import org.openconcerto.erp.injector.DevisFactureSQLInjector;
147
import org.openconcerto.erp.injector.EcheanceEncaisseSQLInjector;
148
import org.openconcerto.erp.injector.FactureAvoirSQLInjector;
19 ilm 149
import org.openconcerto.erp.injector.FactureBonSQLInjector;
150
import org.openconcerto.erp.injector.FactureCommandeSQLInjector;
18 ilm 151
import org.openconcerto.erp.preferences.DefaultNXProps;
25 ilm 152
import org.openconcerto.erp.preferences.TemplateNXProps;
18 ilm 153
import org.openconcerto.erp.rights.ComptaTotalUserRight;
154
import org.jopendocument.link.OOConnexion;
155
import org.openconcerto.sql.Configuration;
156
import org.openconcerto.sql.ShowAs;
25 ilm 157
import org.openconcerto.sql.element.ElementMapper;
18 ilm 158
import org.openconcerto.sql.element.SQLElementDirectory;
159
import org.openconcerto.sql.element.SharedSQLElement;
160
import org.openconcerto.sql.model.DBRoot;
161
import org.openconcerto.sql.model.DBSystemRoot;
162
import org.openconcerto.sql.model.SQLDataSource;
163
import org.openconcerto.sql.model.SQLRow;
164
import org.openconcerto.sql.model.SQLServer;
165
import org.openconcerto.sql.model.SQLTable;
166
import org.openconcerto.sql.request.SQLFieldTranslator;
167
import org.openconcerto.sql.users.rights.UserRightsManager;
168
import org.openconcerto.task.TacheActionManager;
169
import org.openconcerto.task.config.ComptaBasePropsConfiguration;
170
import org.openconcerto.utils.DesktopEnvironment;
171
import org.openconcerto.utils.ExceptionHandler;
172
 
173
import java.io.File;
174
import java.io.FileInputStream;
175
import java.io.IOException;
176
import java.io.InputStream;
177
import java.lang.reflect.InvocationTargetException;
178
import java.sql.SQLException;
179
import java.util.ArrayList;
180
import java.util.Arrays;
181
import java.util.List;
182
import java.util.Properties;
183
 
184
import javax.swing.JOptionPane;
185
import javax.swing.SwingUtilities;
186
 
187
/***************************************************************************************************
188
 * Configuration de la gestion: Une base commune "Common" --> société, user, tasks. Une base
189
 * par défaut pour créer une société "Default". Un fichier mapping.xml pour la base commune.
190
 * Un fichier mappingCompta.xml pour les bases sociétés.
191
 **************************************************************************************************/
192
// final so we can use setupLogging(), see the constructor comment
193
public final class ComptaPropsConfiguration extends ComptaBasePropsConfiguration {
194
 
19 ilm 195
    public static final String APP_NAME = "OpenConcerto";
18 ilm 196
    private static final String DEFAULT_ROOT = "Common";
197
    // the properties path from this class
198
    private static final String PROPERTIES = "main.properties";
199
 
200
    public static final String DATA_DIR_VAR = "${data.dir}";
201
 
202
    // private Logger rootLogger;
203
 
204
    private String version = "";
205
    private static OOConnexion conn;
206
 
207
    public static OOConnexion getOOConnexion() {
208
        if (conn == null || conn.isClosed()) {
209
            try {
210
                conn = OOConnexion.create();
211
 
212
                if (conn == null) {
213
                    SwingUtilities.invokeLater(new Runnable() {
214
 
215
                        @Override
216
                        public void run() {
217
                            JOptionPane.showMessageDialog(null, "Impossible de trouver une installation d'OpenOffice sur votre ordinateur.\nMerci d'installer OpenOffice (http://fr.openoffice.org).");
218
                        }
219
                    });
220
                }
221
 
222
            } catch (IllegalStateException e) {
223
                JOptionPane.showMessageDialog(null, "Impossible d'obtenir une connexion avec openoffice. Contactez votre revendeur.");
224
                e.printStackTrace();
225
                conn = null;
226
            }
227
        }
228
 
229
        return conn;
230
    }
231
 
232
    public static void closeOOConnexion() {
233
        if (conn != null) {
234
            conn.closeConnexion();
235
        }
236
    }
237
 
238
    static File getConfFile() {
239
        return getConfFile(APP_NAME);
240
    }
241
 
242
    public static ComptaPropsConfiguration create() {
243
        return create(false);
244
    }
245
 
246
    public static ComptaPropsConfiguration create(final boolean nullAllowed) {
247
        return create(nullAllowed, getConfFile());
248
    }
249
 
250
    public static ComptaPropsConfiguration create(final boolean nullAllowed, final File confFile) {
251
        // Log pour debug demarrage
252
        System.out.println("Loading configuration from:" + (confFile == null ? "null" : confFile.getAbsolutePath()));
253
        final boolean inWebStart = Gestion.inWebStart();
254
        final Properties defaults = new Properties();
255
        defaults.setProperty("base.root", DEFAULT_ROOT);
256
        // Ordre de recherche:
257
        // a/ fichier de configuration
258
        // b/ dans le jar
259
        try {
260
            final Properties props;
261
            // webstart should be self-contained, e.g. if a user launches from the web it shoudln't
262
            // read an old preference file but should always read its own configuration.
263
            if (confFile.exists() && !inWebStart) {
264
                props = create(new FileInputStream(confFile), defaults);
265
            } else {
266
                final InputStream stream = ComptaPropsConfiguration.class.getResourceAsStream(PROPERTIES);
267
                if (stream != null)
268
                    props = create(stream, defaults);
269
                else if (nullAllowed)
270
                    return null;
271
                else
272
                    throw new IOException("found neither " + confFile + " nor embedded " + PROPERTIES);
273
            }
274
            return new ComptaPropsConfiguration(props, inWebStart);
275
        } catch (final IOException e) {
276
            e.printStackTrace();
277
 
278
            try {
279
                SwingUtilities.invokeAndWait(new Runnable() {
280
                    public void run() {
281
                        ExceptionHandler.die("Impossible de lire le fichier de configuration.", e);
282
                    }
283
                });
284
            } catch (InterruptedException e1) {
285
                e1.printStackTrace();
286
            } catch (InvocationTargetException e1) {
287
                e1.printStackTrace();
288
            }
289
            // never reached since we're already dead
290
            return null;
291
        }
292
 
293
    }
294
 
295
    // *** instance
296
 
297
    private final boolean inWebstart;
298
    private final boolean isServerless;
299
 
300
    ComptaPropsConfiguration(Properties props, final boolean inWebstart) {
301
        super(props, APP_NAME);
302
        this.inWebstart = inWebstart;
303
        this.setProperty("wd", DesktopEnvironment.getDE().getDocumentsFolder().getAbsolutePath() + File.separator + this.getAppName());
304
        if (this.getProperty("version.date") != null) {
305
            this.version = this.getProperty("version.date");
306
        }
307
        this.isServerless = getProperty("server.ip", "").contains(DATA_DIR_VAR);
308
        if (this.isServerless) {
309
            this.setProperty("server.ip", getProperty("server.ip").replace(DATA_DIR_VAR, getDataDir().getPath()));
310
        }
311
 
312
        // ATTN this works because this is executed last (i.e. if you put this in a superclass
313
        // this won't work since e.g. app.name won't have its correct value)
314
        this.setupLogging("logs");
315
 
316
        UserRightsManager.getInstance().register(new ComptaTotalUserRight());
317
    }
318
 
319
    @Override
320
    public void destroy() {
321
        // since we used setupLogging() in the constructor (allows to remove confDir)
322
        this.tearDownLogging(true);
323
        super.destroy();
324
    }
325
 
326
    public final boolean isServerless() {
327
        return this.isServerless;
328
    }
329
 
330
    public final String getVersion() {
331
        return this.version;
332
    }
333
 
334
    @Override
335
    protected String getLogin() {
336
        return "openconcerto";
337
    }
338
 
339
    @Override
340
    protected String getPassword() {
341
        return "openconcerto";
342
    }
343
 
344
    @Override
345
    protected String getAppIDSuffix() {
346
        if (inWebstart())
25 ilm 347
            // so we don't remove files of a normal GestionNX
18 ilm 348
            return super.getAppIDSuffix() + "-webstart";
349
        else
350
            return super.getAppIDSuffix();
351
    }
352
 
353
    @Override
354
    public File getConfDir() {
355
        return Gestion.MAC_OS_X ? new File(System.getProperty("user.home") + "/Library/Application Support/" + getAppID()) : super.getConfDir();
356
    }
357
 
358
    private boolean inWebstart() {
359
        return this.inWebstart;
360
    }
361
 
362
    public File getDataDir() {
363
        return new File(this.getConfDir(), "DBData");
364
    }
365
 
366
    private final void createDB() {
367
        if (!this.isServerless())
368
            return;
369
        // super to avoid infinite recursion, and so we can close it afterwards
370
        final SQLServer tmpServer = super.createServer();
371
        try {
372
            // H2 create the database on connection
373
            final DBSystemRoot sysRoot = tmpServer.getSystemRoot(this.getSystemRootName());
374
            if (!sysRoot.contains(getRootName())) {
19 ilm 375
                String createScript = null;
376
                try {
377
                    createScript = this.getResource("/webstart/create.sql");
378
                } catch (Exception e) {
379
                    e.printStackTrace();
380
                }
18 ilm 381
                if (createScript == null)
382
                    throw new IllegalStateException("Couldn't find database creation script");
383
                final SQLDataSource ds = sysRoot.getDataSource();
384
                ds.execute("RUNSCRIPT from '" + createScript + "' ;");
385
            }
386
        } finally {
387
            tmpServer.destroy();
388
        }
389
    }
390
 
391
    @Override
392
    protected DBSystemRoot createSystemRoot() {
393
        this.createDB();
394
        return super.createSystemRoot();
395
    }
396
 
397
    @Override
398
    public String getDefaultBase() {
399
        return super.getDefaultBase();
400
 
401
    }
402
 
403
    protected File getMappingFile() {
404
        return new File("mapping.xml");
405
    }
406
 
407
    @Override
408
    protected ShowAs createShowAs() {
409
        final ShowAs showAs = super.createShowAs();
410
 
411
        showAs.show("ADRESSE_COMMON", SQLRow.toList("RUE,VILLE"));
412
 
413
        showAs.show("CAISSE_COTISATION", "NOM");
414
 
415
        showAs.show("EXERCICE_COMMON", SQLRow.toList("NUMERO,DATE_DEB,DATE_FIN"));
416
 
417
        showAs.show("IMPRESSION_RUBRIQUE", "NOM");
418
 
419
        showAs.show("OBJET", "NOM");
420
        showAs.show("PERIODE_VALIDITE", "JANVIER");
421
        showAs.show("PROFIL_PAYE", "NOM");
422
 
423
        showAs.show("RUBRIQUE_COTISATION", "CODE", "NOM");
424
        showAs.show("RUBRIQUE_NET", "CODE", "NOM");
425
        showAs.show("RUBRIQUE_BRUT", "CODE", "NOM");
426
 
427
        showAs.show("TYPE_RUBRIQUE_BRUT", "NOM");
428
        showAs.show("TYPE_RUBRIQUE_NET", "NOM");
429
 
430
        return showAs;
431
    }
432
 
433
    @Override
434
    protected SQLElementDirectory createDirectory() {
435
        final SQLElementDirectory dir = super.createDirectory();
436
        dir.addSQLElement(new AdresseCommonSQLElement());
437
        dir.addSQLElement(new ExerciceCommonSQLElement());
19 ilm 438
        dir.addSQLElement(DeviseSQLElement.class);
21 ilm 439
        dir.addSQLElement(TypeModeleSQLElement.class);
18 ilm 440
        dir.addSQLElement(new SocieteCommonSQLElement());
441
        return dir;
442
    }
443
 
444
    private void setSocieteDirectory() {
445
        SQLElementDirectory dir = Configuration.getInstance().getDirectory();
19 ilm 446
        dir.addSQLElement(ArticleTarifSQLElement.class);
447
        dir.addSQLElement(ArticleDesignationSQLElement.class);
21 ilm 448
        dir.addSQLElement(ContactFournisseurSQLElement.class);
18 ilm 449
        dir.addSQLElement(new TitrePersonnelSQLElement());
450
        dir.addSQLElement(new ContactSQLElement());
451
        dir.addSQLElement(new SaisieKmItemSQLElement());
452
        dir.addSQLElement(new EcritureSQLElement());
453
 
454
        dir.addSQLElement(new SharedSQLElement("EMPLOYEUR_MULTIPLE"));
455
        dir.addSQLElement(PosteAnalytiqueSQLElement.class);
456
        dir.addSQLElement(new SharedSQLElement("CLASSE_COMPTE"));
457
 
458
        dir.addSQLElement(new CaisseCotisationSQLElement());
459
        dir.addSQLElement(CaisseTicketSQLElement.class);
460
 
461
        dir.addSQLElement(new ImpressionRubriqueSQLElement());
462
 
21 ilm 463
        dir.addSQLElement(ModeleSQLElement.class);
464
 
18 ilm 465
        dir.addSQLElement(new ProfilPayeSQLElement());
466
        dir.addSQLElement(new ProfilPayeElementSQLElement());
467
        dir.addSQLElement(new PeriodeValiditeSQLElement());
468
 
469
        dir.addSQLElement(new RubriqueCotisationSQLElement());
470
        dir.addSQLElement(new RubriqueCommSQLElement());
471
        dir.addSQLElement(new RubriqueNetSQLElement());
472
        dir.addSQLElement(new RubriqueBrutSQLElement());
473
 
474
        dir.addSQLElement(new TypeRubriqueBrutSQLElement());
475
        dir.addSQLElement(new TypeRubriqueNetSQLElement());
476
 
477
        dir.addSQLElement(new VariablePayeSQLElement());
478
 
479
        dir.addSQLElement(new AdresseSQLElement());
480
 
481
        dir.addSQLElement(ReferenceArticleSQLElement.class);
482
 
483
        dir.addSQLElement(new AssociationCompteAnalytiqueSQLElement());
484
        dir.addSQLElement(new AvoirClientSQLElement());
485
        dir.addSQLElement(new AvoirClientElementSQLElement());
486
        dir.addSQLElement(AvoirFournisseurSQLElement.class);
487
        dir.addSQLElement(new AcompteSQLElement());
488
 
489
        dir.addSQLElement(new AnalytiqueSQLElement());
490
 
491
        dir.addSQLElement(new BonDeLivraisonItemSQLElement());
492
        dir.addSQLElement(new BonDeLivraisonSQLElement());
493
        dir.addSQLElement(new BonReceptionElementSQLElement());
494
        dir.addSQLElement(new BonReceptionSQLElement());
495
 
496
        dir.addSQLElement(new ChequeAEncaisserSQLElement());
497
        dir.addSQLElement(new ChequeAvoirClientSQLElement());
498
        dir.addSQLElement(new ChequeFournisseurSQLElement());
499
            dir.addSQLElement(new ClientNormalSQLElement());
500
        dir.addSQLElement(new CourrierClientSQLElement());
501
 
502
        dir.addSQLElement(new ClassementConventionnelSQLElement());
503
 
504
        dir.addSQLElement(new CommandeSQLElement());
505
        dir.addSQLElement(new CommandeElementSQLElement());
506
        dir.addSQLElement(new CommandeClientSQLElement());
507
        dir.addSQLElement(new CommandeClientElementSQLElement());
508
 
509
            dir.addSQLElement(new CommercialSQLElement());
510
 
511
        dir.addSQLElement(new ComptePCESQLElement());
512
        dir.addSQLElement(new ComptePCGSQLElement());
513
 
514
        dir.addSQLElement(new ContratSalarieSQLElement());
515
 
516
        dir.addSQLElement(new CodeRegimeSQLElement());
517
        dir.addSQLElement(new CodeEmploiSQLElement());
518
        dir.addSQLElement(new CodeContratTravailSQLElement());
519
        dir.addSQLElement(new CodeDroitContratSQLElement());
520
        dir.addSQLElement(new CodeCaractActiviteSQLElement());
521
 
522
        dir.addSQLElement(new CodeStatutCategorielSQLElement());
523
        dir.addSQLElement(new CodeStatutProfSQLElement());
524
        dir.addSQLElement(new CumulsCongesSQLElement());
525
        dir.addSQLElement(new CumulsPayeSQLElement());
526
 
527
        dir.addSQLElement(new DepartementSQLElement());
528
        dir.addSQLElement(new DevisSQLElement());
529
        dir.addSQLElement(new DevisItemSQLElement());
530
 
531
        dir.addSQLElement(new EcheanceClientSQLElement());
532
        dir.addSQLElement(new EcheanceFournisseurSQLElement());
533
        dir.addSQLElement(EncaisserMontantSQLElement.class);
534
        dir.addSQLElement(EncaisserMontantElementSQLElement.class);
535
        dir.addSQLElement(EcoTaxeSQLElement.class);
536
 
537
        dir.addSQLElement(new EtatCivilSQLElement());
538
        dir.addSQLElement(new EtatDevisSQLElement());
539
 
540
        dir.addSQLElement(new FamilleArticleSQLElement());
541
        dir.addSQLElement(new FichePayeSQLElement());
542
        dir.addSQLElement(new FichePayeElementSQLElement());
543
 
544
        dir.addSQLElement(new FournisseurSQLElement());
545
 
546
        dir.addSQLElement(new CodeIdccSQLElement());
547
 
548
        dir.addSQLElement(new InfosSalariePayeSQLElement());
549
 
550
        dir.addSQLElement(new JournalSQLElement());
551
 
19 ilm 552
        dir.addSQLElement(LangueSQLElement.class);
553
 
18 ilm 554
        dir.addSQLElement(new MetriqueSQLElement());
555
        dir.addSQLElement(new ModeleCourrierClientSQLElement());
556
        dir.addSQLElement(new ModeVenteArticleSQLElement());
557
        dir.addSQLElement(new ModeDeReglementSQLElement());
558
        dir.addSQLElement(new ModeReglementPayeSQLElement());
559
        dir.addSQLElement(new MoisSQLElement());
560
        dir.addSQLElement(new MouvementSQLElement());
561
        dir.addSQLElement(new MouvementStockSQLElement());
562
 
563
        dir.addSQLElement(new NatureCompteSQLElement());
564
 
565
        dir.addSQLElement(new NumerotationAutoSQLElement());
566
 
567
        dir.addSQLElement(new PaysSQLElement());
568
 
569
        dir.addSQLElement(new PieceSQLElement());
570
 
571
        dir.addSQLElement(new ProfilPayeElementSQLElement());
572
 
573
        dir.addSQLElement(ReferenceClientSQLElement.class);
574
        dir.addSQLElement(new RegimeBaseSQLElement());
575
        dir.addSQLElement(new RelanceSQLElement());
576
        dir.addSQLElement(new ReglementPayeSQLElement());
577
        dir.addSQLElement(new ReglerMontantSQLElement());
578
        dir.addSQLElement(RepartitionAnalytiqueSQLElement.class);
579
 
580
        dir.addSQLElement(new SaisieAchatSQLElement());
581
        dir.addSQLElement(new SaisieKmSQLElement());
582
        dir.addSQLElement(new SaisieVenteComptoirSQLElement());
583
        dir.addSQLElement(new SaisieVenteFactureSQLElement());
584
            dir.addSQLElement(new SaisieVenteFactureItemSQLElement());
585
 
586
        dir.addSQLElement(SituationFamilialeSQLElement.class);
587
        dir.addSQLElement(new StockSQLElement());
588
        dir.addSQLElement(new StyleSQLElement());
589
 
590
        dir.addSQLElement(new SalarieSQLElement());
591
 
592
        dir.addSQLElement(TarifSQLElement.class);
593
        dir.addSQLElement(new TaxeSQLElement());
594
        dir.addSQLElement(TicketCaisseSQLElement.class);
595
 
596
        dir.addSQLElement(new TypeComptePCGSQLElement());
597
        dir.addSQLElement(new TypeLettreRelanceSQLElement());
598
        dir.addSQLElement(new TypeReglementSQLElement());
599
 
600
        dir.addSQLElement(new VariableSalarieSQLElement());
601
    }
602
 
603
    private void setSocieteSQLInjector() {
604
        final DBRoot rootSociete = getRootSociete();
19 ilm 605
        new ArticleCommandeEltSQLInjector(rootSociete);
606
        new CommandeCliCommandeSQLInjector(rootSociete);
18 ilm 607
        new FactureAvoirSQLInjector(rootSociete);
19 ilm 608
        new FactureBonSQLInjector(rootSociete);
609
        new FactureCommandeSQLInjector(rootSociete);
18 ilm 610
        new DevisFactureSQLInjector(rootSociete);
611
        new DevisCommandeSQLInjector(rootSociete);
19 ilm 612
        new DevisCommandeFournisseurSQLInjector(rootSociete);
18 ilm 613
        new CommandeBlEltSQLInjector(rootSociete);
614
        new CommandeBlSQLInjector(rootSociete);
615
        new BonFactureSQLInjector(rootSociete);
616
        new CommandeFactureClientSQLInjector(rootSociete);
617
        new CommandeBrSQLInjector(rootSociete);
618
        new CommandeFactureAchatSQLInjector(rootSociete);
619
        new EcheanceEncaisseSQLInjector(rootSociete);
620
        new BrFactureAchatSQLInjector(rootSociete);
621
        new DevisEltFactureEltSQLInjector(rootSociete);
622
 
623
    }
624
 
625
 
626
    private void setSocieteShowAs() {
19 ilm 627
        final ShowAs showAs = this.getShowAs();
18 ilm 628
        showAs.setRoot(getRootSociete());
629
        showAs.show("ARTICLE", "NOM");
630
        showAs.show("ACTIVITE", "CODE_ACTIVITE");
631
        showAs.show("ADRESSE", SQLRow.toList("RUE,VILLE"));
19 ilm 632
        final DBRoot root = this.getRootSociete();
18 ilm 633
        showAs.show("AXE_ANALYTIQUE", "NOM");
634
 
635
        showAs.show("CHEQUE_A_ENCAISSER", "MONTANT", "ID_CLIENT");
636
                showAs.show("CLIENT", "FORME_JURIDIQUE", "NOM");
637
 
638
        showAs.show("CLASSEMENT_CONVENTIONNEL", "NIVEAU", "COEFF");
639
        showAs.show("CODE_EMPLOI", SQLRow.toList("CODE,NOM"));
640
        showAs.show("CODE_CONTRAT_TRAVAIL", SQLRow.toList("CODE,NOM"));
641
        showAs.show("CODE_DROIT_CONTRAT", SQLRow.toList("CODE,NOM"));
642
        showAs.show("CODE_CARACT_ACTIVITE", SQLRow.toList("CODE,NOM"));
643
        showAs.show("CODE_STATUT_PROF", SQLRow.toList("CODE,NOM"));
644
        showAs.show("CODE_STATUT_CATEGORIEL", SQLRow.toList("CODE,NOM"));
645
        showAs.show("CODE_REGIME", SQLRow.toList("CODE,NOM"));
646
        showAs.show("COMMANDE", "NOM");
647
        showAs.show("COMMERCIAL", "NOM");
648
        showAs.show("COMMANDE_CLIENT", "NOM");
649
        showAs.show("COMPTE_PCE", "NUMERO", "NOM");
650
        showAs.show("COMPTE_PCG", "NUMERO", "NOM");
651
        showAs.show("CONTACT", "NOM");
652
        showAs.show("CONTRAT_SALARIE", "NATURE");
653
 
654
        showAs.show("DEVIS", "NUMERO", "OBJET");
655
        showAs.show("DEPARTEMENT", "NUMERO", "NOM");
656
 
657
        showAs.show("ECRITURE", SQLRow.toList("NOM,DATE,ID_COMPTE_PCE,DEBIT,CREDIT"));
658
        showAs.show("ECHEANCE_CLIENT", SQLRow.toList("ID_CLIENT,ID_MOUVEMENT"));
659
 
660
        showAs.show("ECHEANCE_FOURNISSEUR", SQLRow.toList("ID_FOURNISSEUR,ID_MOUVEMENT"));
661
        showAs.show("FAMILLE_ARTICLE", "NOM");
662
        showAs.show("FICHE_PAYE", SQLRow.toList("ID_MOIS,ANNEE"));
19 ilm 663
        showAs.show("FOURNISSEUR", "NOM");
18 ilm 664
 
665
        showAs.show("IDCC", "NOM");
666
 
667
        showAs.show("JOURNAL", "NOM");
668
        showAs.show("MOIS", "NOM");
669
        showAs.show("MOUVEMENT", "NUMERO", "ID_PIECE");
670
        showAs.show("MODE_VENTE_ARTICLE", "NOM");
671
        showAs.show("MODE_REGLEMENT", "ID_TYPE_REGLEMENT", "AJOURS");
672
        showAs.show("MODE_REGLEMENT_PAYE", "NOM");
673
        showAs.show("MODELE_COURRIER_CLIENT", "NOM", "CONTENU");
674
 
675
        showAs.show("NATURE_COMPTE", "NOM");
676
 
677
        showAs.show("POSTE_ANALYTIQUE", "NOM");
678
        showAs.show("PAYS", "CODE", "NOM");
679
        showAs.show("PIECE", "ID", "NOM");
680
 
19 ilm 681
        final SQLElementDirectory directory = this.getDirectory();
18 ilm 682
        showAs.show("REPARTITION_ANALYTIQUE", "NOM");
683
        showAs.show("REGIME_BASE", "ID_CODE_REGIME_BASE");
684
        showAs.show("REGLEMENT_PAYE", "NOM_BANQUE", "RIB");
685
 
686
        List<String> listFieldModReglMontant = new ArrayList<String>();
687
        listFieldModReglMontant.add("ID_TYPE_REGLEMENT");
688
 
689
        showAs.showField("REGLER_MONTANT.ID_MODE_REGLEMENT", listFieldModReglMontant);
690
        showAs.showField("ENCAISSER_MONTANT.ID_MODE_REGLEMENT", listFieldModReglMontant);
691
 
692
        showAs.show("SAISIE_VENTE_FACTURE", SQLRow.toList("NUMERO"));
693
 
694
        List<String> listFieldFactureElt = new ArrayList<String>();
695
        listFieldFactureElt.add("NUMERO");
696
        listFieldFactureElt.add("DATE");
697
        listFieldFactureElt.add("ID_CLIENT");
698
        showAs.showField("SAISIE_VENTE_FACTURE_ELEMENT.ID_SAISIE_VENTE_FACTURE", listFieldFactureElt);
699
 
700
        showAs.show("SALARIE", SQLRow.toList("CODE,NOM,PRENOM"));
701
 
702
        showAs.show("SITUATION_FAMILIALE", "NOM");
703
        showAs.show("STOCK", "QTE_REEL");
704
        showAs.show("STYLE", "NOM");
705
 
706
        showAs.show("TAXE", "TAUX");
707
 
708
        showAs.show(directory.getElement("TITRE_PERSONNEL").getTable(), asList("NOM"));
709
 
710
        showAs.show("TYPE_COMPTE_PCG", "NOM");
711
        showAs.show("TYPE_LETTRE_RELANCE", "NOM");
712
        showAs.show("TYPE_REGLEMENT", "NOM");
713
 
714
    }
715
 
716
    public void setUpSocieteDataBaseConnexion(int base) {
717
        setRowSociete(base);
718
 
719
        // find customer
720
        String customerName = "openconcerto";
721
        final DBRoot rootSociete = this.getRootSociete();
722
        final String dbMD = rootSociete.getMetadata("CUSTOMER");
723
        if (dbMD != null && !dbMD.equals(customerName))
724
            throw new IllegalStateException("customer is '" + customerName + "' but db says '" + dbMD + "'");
725
        closeSocieteConnexion();
726
        setSocieteDirectory();
727
        NumerotationAutoSQLElement.addListeners();
728
        final SQLFieldTranslator trans = Configuration.getInstance().getTranslator();
729
        trans.load(rootSociete, ComptaPropsConfiguration.class.getResourceAsStream("mappingCompta.xml"));
730
        final InputStream in = ComptaPropsConfiguration.class.getResourceAsStream("mapping-" + customerName + ".xml");
731
        if (in != null) {
732
            trans.load(rootSociete, in);
733
        }
734
        setSocieteShowAs();
735
        setSocieteSQLInjector();
25 ilm 736
        setMapper();
18 ilm 737
        String sfe = DefaultNXProps.getInstance().getStringProperty("ArticleSFE");
738
        Boolean bSfe = Boolean.valueOf(sfe);
739
        boolean isSFE = bSfe != null && bSfe.booleanValue();
740
        if (isSFE) {
741
            final InputStream inSFE = ComptaPropsConfiguration.class.getResourceAsStream("mapping-SFE.xml");
742
            if (inSFE != null) {
743
                trans.load(rootSociete, inSFE);
744
            }
745
        }
25 ilm 746
        TemplateNXProps.getInstance();
18 ilm 747
        // Chargement du graphe
748
        new Thread() {
749
            public void run() {
750
                Configuration.getInstance().getSystemRoot().getGraph();
751
 
752
            }
753
        }.start();
754
    }
755
 
25 ilm 756
    private void setMapper() {
757
        ElementMapper mapper = ElementMapper.getInstance();
758
        mapper.map("customerrelationship.name", "Relation client");
759
        mapper.map("customerrelationship.customer.list.table", "CLIENT");
760
        mapper.map("customerrelationship.contact.list.table", "CONTACT");
761
        mapper.map("accounting.name", "Comptabilité");
762
        mapper.map("sales.name", "Gestion commerciale");
763
        mapper.map("sales.invoice.name", "Factures client");
764
        mapper.map("sales.invoice.list.table", "SAISIE_VENTE_FACTURE");
765
        mapper.map("sales.quote.name", "Devis client");
766
        mapper.map("sales.quote.list.table", "DEVIS");
767
        mapper.map("sales.invoice.list.table.editor", SaisieVenteFactureItemTable.class);
768
        mapper.dump();
769
    }
770
 
18 ilm 771
    private void closeSocieteConnexion() {
772
 
773
    }
774
 
775
    public String getServerIp() {
776
        return getProperty("server.ip");
777
    }
19 ilm 778
 
18 ilm 779
}