OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Go to most recent revision | Blame | Compare with Previous | 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.
 */
 
 /*
 * Créé le 23 avr. 2012
 */
package org.openconcerto.erp.core.supplychain.stock.element;

import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.JDate;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.util.Date;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class EtatStockCreationPanel extends JPanel {

    public EtatStockCreationPanel(final SQLElement depotElt) {
        super(new GridBagLayout());

        final SQLRequestComboBox boxDepot = new SQLRequestComboBox(false);
        boxDepot.uiInit(depotElt.createComboRequest());

        GridBagConstraints c = new DefaultGridBagConstraints();
        JLabel labelCom = new JLabel("Dépôt ");
        this.add(labelCom, c);
        c.gridx++;
        this.add(boxDepot, c);

        c.gridx++;
        JLabel labelD = new JLabel("au");
        this.add(labelD, c);
        final JDate dateDebut = new JDate(true);
        c.gridx++;
        this.add(dateDebut, c);

        final JCheckBox box = new JCheckBox("intégrer uniquement les articles du dépôt");
        box.setSelected(true);
        c.gridx++;
        this.add(box, c);

        final JButton buttonValid = new JButton(new AbstractAction("Valider") {

            @Override
            public void actionPerformed(ActionEvent e) {
                SQLRowAccessor row = boxDepot.getSelectedRow();
                final SQLRowAccessor rowDepot;
                if (row != null && !row.isUndefined()) {
                    rowDepot = boxDepot.getSelectedRow();
                } else {
                    rowDepot = depotElt.getTable().getRow(DepotStockSQLElement.DEFAULT_ID);
                }

                Date d = dateDebut.getDate() == null ? new Date() : dateDebut.getDate();

                EtatStockSnapshotCreator creator = new EtatStockSnapshotCreator(rowDepot, d, depotElt.getTable().getDBRoot(), !box.isSelected());
                creator.create();
            }

        });
        c.gridx++;
        // buttonValid.setEnabled(false);
        this.add(buttonValid, c);

    }

}