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 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.core.sales.invoice.ui;

import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.erp.core.sales.invoice.report.ReportingStockXmlSheet;
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
import org.openconcerto.sql.request.ComboSQLRequest;
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
import org.openconcerto.ui.component.InteractionMode;
import org.openconcerto.utils.ExceptionHandler;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

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

public class RapportEtatDeStockDepotSelectionPanel extends JPanel {

    JPanel pnlMain = new JPanel();
    JPanel pnlBottom = new JPanel();
    JLabel labDepots = new JLabel("Dépôts");
    JButton butReport = new JButton("Générer le rapport");
    JCheckBox chkTous = new JCheckBox("Séléctionner tous les dépôts");

    SQLRequestComboBox sqlreqDepots = new SQLRequestComboBox(false, 20);

    public RapportEtatDeStockDepotSelectionPanel(ComptaPropsConfiguration conf) {
        GridBagLayout layThis = new GridBagLayout();
        this.setLayout(layThis);

        GridBagLayout layMain = new GridBagLayout();
        this.pnlMain.setLayout(layMain);

        GridBagLayout layBottom = new GridBagLayout();
        this.pnlBottom.setLayout(layBottom);

        GridBagConstraints gbcThis = new GridBagConstraints();
        gbcThis.weightx = 1;
        gbcThis.weighty = 1;
        gbcThis.gridheight = 1;
        gbcThis.gridwidth = 1;
        gbcThis.fill = GridBagConstraints.BOTH;

        GridBagConstraints gbcBottom = new GridBagConstraints();
        gbcBottom.weightx = 1;
        gbcBottom.weighty = 1;
        gbcBottom.gridheight = 1;
        gbcBottom.gridwidth = 2;
        gbcBottom.fill = GridBagConstraints.BOTH;

        GridBagConstraints gbcDefault = new GridBagConstraints();
        gbcDefault.weightx = 1;
        gbcDefault.gridheight = 1;
        gbcDefault.gridwidth = 1;
        gbcDefault.insets = new Insets(0, 4, 4, 4);
        gbcDefault.fill = GridBagConstraints.HORIZONTAL;

        GridBagConstraints gbcButton = new GridBagConstraints();
        gbcButton.weightx = 1;
        gbcButton.weighty = 1;
        gbcButton.gridheight = 1;
        gbcButton.gridwidth = 1;
        gbcButton.insets = new Insets(0, 4, 4, 4);
        gbcButton.anchor = GridBagConstraints.SOUTHEAST;

        this.setBackground(Color.DARK_GRAY);
        this.add(this.pnlMain, gbcThis);

        // Label.
        gbcDefault.gridx = 0;
        gbcDefault.gridy = 0;
        this.pnlMain.add(this.labDepots, gbcDefault);
        this.labDepots.setHorizontalAlignment(SwingConstants.RIGHT);

        // SQLRequestComboBox.
        List<String> fields = new ArrayList<>();
        fields.add("NOM");
        ComboSQLRequest request = new ComboSQLRequest(conf.getDirectory().getElement("DEPOT_STOCK").getTable(), fields, null, conf.getDirectory());

        gbcDefault.gridx = 1;
        gbcDefault.gridy = 0;
        this.sqlreqDepots.uiInit(request);
        this.sqlreqDepots.setValue(DepotStockSQLElement.DEFAULT_ID);
        this.pnlMain.add(this.sqlreqDepots, gbcDefault);

        // CheckBox.
        gbcDefault.gridx = 1;
        gbcDefault.gridy = 1;
        this.chkTous.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (RapportEtatDeStockDepotSelectionPanel.this.chkTous.isSelected()) {
                    RapportEtatDeStockDepotSelectionPanel.this.sqlreqDepots.setEnabled(InteractionMode.DISABLED);
                } else {
                    RapportEtatDeStockDepotSelectionPanel.this.sqlreqDepots.setEnabled(InteractionMode.READ_WRITE);
                }
            }
        });

        this.pnlMain.add(this.chkTous, gbcDefault);

        // Ajout du panel du bas.
        gbcBottom.gridx = 0;
        gbcBottom.gridy = 2;
        this.pnlMain.add(this.pnlBottom, gbcBottom);

        // Button.
        gbcButton.gridx = 0;
        gbcButton.gridy = 0;
        this.butReport.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Integer intIDDepot = RapportEtatDeStockDepotSelectionPanel.this.sqlreqDepots.getValue();
                boolean bTousLesDepots = RapportEtatDeStockDepotSelectionPanel.this.chkTous.isSelected();

                try {
                    ReportingStockXmlSheet sheet = new ReportingStockXmlSheet(conf, intIDDepot, bTousLesDepots);
                    sheet.createDocumentAsynchronous().get();
                    sheet.openDocument(false);

                } catch (Exception excep) {
                    ExceptionHandler.handle("Erreur de traitement", excep);
                }
            }
        });

        this.pnlBottom.add(this.butReport, gbcButton);
    }

}