OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 180 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.supplychain.purchase.importer;
14
 package org.openconcerto.erp.core.supplychain.purchase.importer;
15
 
15
 
-
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
17
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
-
 
18
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.model.DBRoot;
19
import org.openconcerto.sql.model.DBRoot;
18
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRow;
19
import org.openconcerto.sql.model.SQLRowAccessor;
21
import org.openconcerto.sql.model.SQLRowAccessor;
20
import org.openconcerto.sql.model.SQLRowValues;
22
import org.openconcerto.sql.model.SQLRowValues;
21
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
23
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
22
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.sql.model.SQLTable;
23
import org.openconcerto.sql.model.Where;
25
import org.openconcerto.sql.model.Where;
24
 
26
 
25
import java.math.BigDecimal;
27
import java.math.BigDecimal;
-
 
28
import java.math.RoundingMode;
26
import java.text.DecimalFormat;
29
import java.text.DecimalFormat;
27
import java.text.DecimalFormatSymbols;
30
import java.text.DecimalFormatSymbols;
28
import java.text.SimpleDateFormat;
31
import java.text.SimpleDateFormat;
29
import java.util.Collection;
32
import java.util.Collection;
30
import java.util.Date;
33
import java.util.Date;
Line 88... Line 91...
88
        SQLRowValues rowValsToFetch = new SQLRowValues(factureTable);
91
        SQLRowValues rowValsToFetch = new SQLRowValues(factureTable);
89
        rowValsToFetch.putNulls("NUMERO", "DATE", "NOM", "T_TVA", "T_HT", "T_TTC", "NET_A_PAYER");
92
        rowValsToFetch.putNulls("NUMERO", "DATE", "NOM", "T_TVA", "T_HT", "T_TTC", "NET_A_PAYER");
90
        rowValsToFetch.putRowValues("ID_MODE_REGLEMENT").putNulls("COMPTANT", "AJOURS", "LENJOUR", "DATE_FACTURE", "FIN_MOIS").putRowValues("ID_TYPE_REGLEMENT").putNulls("NOM");
93
        rowValsToFetch.putRowValues("ID_MODE_REGLEMENT").putNulls("COMPTANT", "AJOURS", "LENJOUR", "DATE_FACTURE", "FIN_MOIS").putRowValues("ID_TYPE_REGLEMENT").putNulls("NOM");
91
        SQLRowValues putRowValuesClient = rowValsToFetch.putRowValues("ID_CLIENT");
94
        SQLRowValues putRowValuesClient = rowValsToFetch.putRowValues("ID_CLIENT");
92
        putRowValuesClient.putNulls("NOM", "RESPONSABLE", "SIRET", "NUMERO_TVA", "MAIL", "TEL");
95
        putRowValuesClient.putNulls("NOM", "RESPONSABLE", "SIRET", "NUMERO_TVA", "MAIL", "TEL");
93
        if (putRowValuesClient.getTable().contains("ID_CLIENT")) {
-
 
94
            this.useCommonClient = true;
-
 
95
            putRowValuesClient.putRowValues("ID_CLIENT").putNulls("NOM", "RESPONSABLE", "SIRET", "NUMERO_TVA", "MAIL", "TEL").putRowValues("ID_ADRESSE").putNulls("RUE", "VILLE", "CODE_POSTAL",
-
 
96
                    "PAYS");
-
 
97
        }
96
 
98
        putRowValuesClient.putRowValues("ID_ADRESSE").putNulls("RUE", "VILLE", "CODE_POSTAL", "PAYS");
97
        putRowValuesClient.putRowValues("ID_ADRESSE").putNulls("RUE", "VILLE", "CODE_POSTAL", "PAYS");
99
        putRowValuesClient.putRowValues("ID_ADRESSE_F").putNulls("RUE", "VILLE", "CODE_POSTAL", "PAYS");
98
        putRowValuesClient.putRowValues("ID_ADRESSE_F").putNulls("RUE", "VILLE", "CODE_POSTAL", "PAYS");
100
        rowValsToFetch.putRowValues("ID_ADRESSE").putNulls("RUE", "VILLE", "CODE_POSTAL", "PAYS");
99
        rowValsToFetch.putRowValues("ID_ADRESSE").putNulls("RUE", "VILLE", "CODE_POSTAL", "PAYS");
101
 
100
 
102
        SQLTable factureItemtable = dbRoot.getTable("SAISIE_VENTE_FACTURE_ELEMENT");
101
        SQLTable factureItemtable = dbRoot.getTable("SAISIE_VENTE_FACTURE_ELEMENT");
Line 184... Line 183...
184
            String productCode = rowItem.getString("CODE");
183
            String productCode = rowItem.getString("CODE");
185
            String productName = rowItem.getString("NOM").trim().length() == 0 ? "Ligne" : rowItem.getString("NOM");
184
            String productName = rowItem.getString("NOM").trim().length() == 0 ? "Ligne" : rowItem.getString("NOM");
186
 
185
 
187
            final BigDecimal pHT, pTTC, totalHTLigne, totalTTCLigne;
186
            final BigDecimal pHT, pTTC, totalHTLigne, totalTTCLigne;
188
            SQLRowAccessor taxeItem = rowItem.getForeign("ID_TAXE");
187
            SQLRowAccessor taxeItem = rowItem.getForeign("ID_TAXE");
189
            BigDecimal taxValue = new BigDecimal(taxeItem.getFloat("TAUX")).setScale(2);
188
            BigDecimal taxValue = new BigDecimal(taxeItem.getFloat("TAUX")).setScale(2, RoundingMode.HALF_UP);
190
            if (rowItem.getInt("NIVEAU") != 1) {
189
            if (rowItem.getInt("NIVEAU") != 1) {
191
                pHT = BigDecimal.ZERO;
190
                pHT = BigDecimal.ZERO;
192
                pTTC = BigDecimal.ZERO;
191
                pTTC = BigDecimal.ZERO;
193
                totalHTLigne = BigDecimal.ZERO;
192
                totalHTLigne = BigDecimal.ZERO;
194
                totalTTCLigne = BigDecimal.ZERO;
193
                totalTTCLigne = BigDecimal.ZERO;
Line 669... Line 668...
669
 
668
 
670
    boolean checkEAN13(String code) {
669
    boolean checkEAN13(String code) {
671
        if (code == null || code.length() != 13) {
670
        if (code == null || code.length() != 13) {
672
            return false;
671
            return false;
673
        }
672
        }
-
 
673
        try {
674
        int checkdigit = 0;
674
            int checkdigit = 0;
675
        for (int i = 1; i < 12; i += 2) {
675
            for (int i = 1; i < 12; i += 2) {
676
            checkdigit += Integer.valueOf(code.substring(i, i + 1));
676
                checkdigit += Integer.valueOf(code.substring(i, i + 1));
677
        }
677
            }
678
        checkdigit *= 3;
678
            checkdigit *= 3;
Line 682... Line 682...
682
        checkdigit %= 10;
682
            checkdigit %= 10;
683
        if (checkdigit != 0) {
683
            if (checkdigit != 0) {
684
            checkdigit = 10 - checkdigit;
684
                checkdigit = 10 - checkdigit;
685
        }
685
            }
686
        return Integer.valueOf(code.substring(12, 13)).intValue() == checkdigit;
686
            return Integer.valueOf(code.substring(12, 13)).intValue() == checkdigit;
-
 
687
        } catch (Exception e) {
-
 
688
            // if not digits, parse error
-
 
689
            return false;
-
 
690
        }
687
    }
691
    }
688
 
692
 
689
    private String resolveCountryCode(String pays) {
693
    private String resolveCountryCode(String pays) {
690
        if (pays == null || pays.trim().length() == 0) {
694
        if (pays == null || pays.trim().length() == 0) {
691
            return "FR";
695
            return "FR";