OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Blame | Last modification | View Log | RSS feed

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * 
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
 * 
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
 * language governing permissions and limitations under the License.
 * 
 * When distributing the software, include this License Header Notice in each file.
 */
 
 package org.openconcerto.erp.generationDoc.provider;

import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
import org.openconcerto.sql.model.SQLRowAccessor;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collection;

public class BatchListProvider extends UserInitialsValueProvider {

    private final String refTable;

    public BatchListProvider(String refTable) {
        this.refTable = refTable;
    }

    @Override
    public Object getValue(SpreadSheetCellValueContext context) {
        final DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
        final SQLRowAccessor row = context.getRow();

        final Collection<? extends SQLRowAccessor> cols = row.asRow().getReferentRows(row.getTable().getTable(this.refTable));
        final StringBuilder res = new StringBuilder();
        for (SQLRowAccessor sqlRowAccessor : cols) {
            final Calendar dluo = sqlRowAccessor.getDate("DLUO");
            final Calendar dlc = sqlRowAccessor.getDate("DLC");
            final String lot = sqlRowAccessor.getString("NUMERO_LOT");
            final String serie = sqlRowAccessor.getString("NUMERO_SERIE");
            if (res.length() > 0) {
                res.append("\n");
            }
            if (serie != null && serie.trim().length() > 0) {
                res.append("N° Série : " + serie);
            }
            if (lot != null && lot.trim().length() > 0) {
                if (res.length() > 0) {
                    res.append(", ");
                }
                res.append("N° Lot : " + lot);
            }
            if (dlc != null) {
                if (res.length() > 0) {
                    res.append(", ");
                }
                res.append("DLC : " + format.format(dlc.getTime()));
            }
            if (dluo != null) {
                if (res.length() > 0) {
                    res.append(", ");
                }
                res.append("DLUO : " + format.format(dluo.getTime()));
            }

        }

        return res.toString();
    }

    public static void register() {
        SpreadSheetCellValueProviderManager.put("sales.batch.list", new BatchListProvider("LOT_LIVRAISON"));
        SpreadSheetCellValueProviderManager.put("purchase.batch.list", new BatchListProvider("LOT_RECEPTION"));

    }
}