OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 180 | 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
 *
185 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
18 ilm 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.generationEcritures;
15
 
16
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
180 ilm 17
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProvider;
18
import org.openconcerto.erp.generationEcritures.provider.AccountingRecordsProviderManager;
18 ilm 19
import org.openconcerto.sql.Configuration;
20
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLRowValues;
22
import org.openconcerto.sql.model.SQLTable;
23
 
24
import java.sql.SQLException;
25
import java.util.Date;
26
import java.util.List;
27
 
28
public class GenerationMvtSaisieKm extends GenerationEcritures {
29
 
30
    private int idSaisieKm;
31
    private static final String source = "SAISIE_KM";
32
 
180 ilm 33
    public static final String ID = "accounting.records.km";
34
 
18 ilm 35
    public GenerationMvtSaisieKm(int idSaisieKm) {
36
        this.idSaisieKm = idSaisieKm;
37
    }
38
 
73 ilm 39
    public int genereMouvement() throws SQLException {
18 ilm 40
 
93 ilm 41
        final SQLTable table = base.getTable("SAISIE_KM");
42
        SQLRow saisieRow = table.getRow(this.idSaisieKm);
18 ilm 43
 
44
        // iniatilisation des valeurs de la map
45
        this.date = (Date) saisieRow.getObject("DATE");
93 ilm 46
        final String labelSaisie = saisieRow.getObject("NOM").toString();
47
        this.nom = labelSaisie;
149 ilm 48
        this.putValue("DATE", this.date);
49
        this.putValue("NOM", this.nom);
50
        this.putValue("ID_JOURNAL", saisieRow.getObject("ID_JOURNAL"));
51
        this.putValue("ID_MOUVEMENT", new Integer(1));
18 ilm 52
 
53
        // on calcule le nouveau numero de mouvement
180 ilm 54
        AccountingRecordsProvider provider = AccountingRecordsProviderManager.get(ID);
55
        SQLRowValues rowValsPiece = new SQLRowValues(pieceTable);
56
        rowValsPiece.put("NOM", (labelSaisie.length() == 0 ? "Saisie au km " : labelSaisie));
57
        if (provider != null) {
58
            provider.putPieceLabel(saisieRow, rowValsPiece);
59
        }
18 ilm 60
 
180 ilm 61
        getNewMouvement(GenerationMvtSaisieKm.source, this.idSaisieKm, 1, rowValsPiece);
62
 
18 ilm 63
        // gnération des ecritures
185 ilm 64
        SQLTable tableElt = table.getDBRoot().findTable("SAISIE_KM_ELEMENT");
18 ilm 65
        List<SQLRow> set = saisieRow.getReferentRows(tableElt);
66
 
83 ilm 67
        SQLTable tableAssoc = Configuration.getInstance().getRoot().findTable("ASSOCIATION_ANALYTIQUE");
18 ilm 68
 
73 ilm 69
        for (SQLRow rowElement : set) {
18 ilm 70
 
73 ilm 71
            int idCpt = ComptePCESQLElement.getId(rowElement.getString("NUMERO"), rowElement.getString("NOM"));
18 ilm 72
 
185 ilm 73
            if (ecritureTable.contains("DATE_ECHEANCE") && table.getDBRoot().findTable("SAISIE_KM_ELEMENT").contains("DATE_ECHEANCE")) {
74
                this.putValue("DATE_ECHEANCE", rowElement.getObject("DATE_ECHEANCE"));
75
            }
73 ilm 76
            // Ajout de l'écriture
149 ilm 77
            this.putValue("ID_COMPTE_PCE", new Integer(idCpt));
78
            this.putValue("NOM", rowElement.getString("NOM_ECRITURE"));
79
            this.putValue("DEBIT", rowElement.getObject("DEBIT"));
80
            this.putValue("CREDIT", rowElement.getObject("CREDIT"));
93 ilm 81
            if (tableElt.contains("NOM_PIECE")) {
149 ilm 82
                this.putValue("NOM_PIECE", rowElement.getObject("NOM_PIECE"));
93 ilm 83
            }
83 ilm 84
            SQLRow rowEcr = ajoutEcriture();
85
 
93 ilm 86
            // List<SQLRow> assocs = rowElement.getReferentRows(tableAssoc);
87
            // for (SQLRow sqlRow : assocs) {
88
            // if (!sqlRow.isUndefined()) {
89
            // addAssocAnalytique(rowEcr, sqlRow.getInt("ID_POSTE_ANALYTIQUE"));
90
            // }
91
            // }
83 ilm 92
 
73 ilm 93
            // Mise à jour de la clef étrangère écriture de l'élément saisie au km
83 ilm 94
            if (rowEcr != null && !rowEcr.isUndefined()) {
73 ilm 95
                SQLRowValues vals = rowElement.createEmptyUpdateRow();
83 ilm 96
                vals.put("ID_ECRITURE", rowEcr.getID());
73 ilm 97
                vals.update();
18 ilm 98
            }
99
        }
100
 
101
        return this.idMvt;
102
    }
103
}