Dépôt officiel du code source de l'ERP OpenConcerto
Rev 177 | 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.
*/
package org.openconcerto.erp.core.supplychain.stock.element;
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
import org.openconcerto.erp.core.sales.invoice.report.EtatStockInventaireXmlSheet;
import org.openconcerto.sql.element.GroupSQLComponent;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.view.IListFrame;
import org.openconcerto.sql.view.list.IListe;
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
import org.openconcerto.sql.view.list.SQLTableModelSource;
import org.openconcerto.ui.FrameUtil;
import org.openconcerto.ui.PanelFrame;
import org.openconcerto.utils.ExceptionHandler;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JTextField;
public class EtatStockSQLElement extends ComptaSQLConfElement {
public EtatStockSQLElement() {
super("ETAT_STOCK");
setDefaultGroup(new EtatStockGroup());
{
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Créer un état de stock") {
@Override
public void actionPerformed(ActionEvent e) {
PanelFrame frame = new PanelFrame(new EtatStockCreationPanel(getDirectory().getElement(DepotStockSQLElement.class)), "Création état de stock");
FrameUtil.showPacked(frame);
}
}, true);
action.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
getRowActions().add(action);
}
{
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Voir les articles") {
@Override
public void actionPerformed(ActionEvent e) {
final SQLElement element = getDirectory().getElement("ETAT_STOCK_ELEMENT");
SQLTableModelSource source = element.createTableSource(new Where(element.getTable().getField("ID_ETAT_STOCK"), "=", IListe.get(e).getSelectedId()));
final ListeViewPanel panel = new ListeViewPanel(element, new IListe(source));
IListFrame frame = new IListFrame(panel);
FrameUtil.show(frame);
}
}, true);
action.setPredicate(IListeEvent.getSingleSelectionPredicate());
getRowActions().add(action);
}
{
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Export pour inventaire") {
@Override
public void actionPerformed(ActionEvent e) {
EtatStockInventaireXmlSheet sheet = new EtatStockInventaireXmlSheet(IListe.get(e).getSelectedRow().asRow());
try {
sheet.createDocument();
sheet.showPrintAndExport(true, false, false, false, false, Collections.emptyList());
} catch (Exception e1) {
ExceptionHandler.handle("Erreur lors de la création de l'inventaire", e1);
}
}
}, true);
action.setPredicate(IListeEvent.getSingleSelectionPredicate());
getRowActions().add(action);
}
{
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Import Inventaire") {
@Override
public void actionPerformed(ActionEvent e) {
PanelFrame frame = new PanelFrame(new ImportInventairePanel(getDirectory().getElement(DepotStockSQLElement.class)), "Import inventaire");
FrameUtil.showPacked(frame);
}
}, true);
action.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
getRowActions().add(action);
}
}
@Override
protected List<String> getListFields() {
final List<String> l = new ArrayList<>(3);
l.add("DATE");
l.add("MONTANT_HA");
l.add("INVENTAIRE");
return l;
}
@Override
protected List<String> getComboFields() {
final List<String> l = new ArrayList<>(2);
l.add("DATE");
l.add("MONTANT_HA");
return l;
}
/*
* (non-Javadoc)
*
* @see org.openconcerto.devis.SQLElement#getComponent()
*/
public SQLComponent createComponent() {
return new GroupSQLComponent(this) {
@Override
public JComponent createEditor(String id) {
if (id.equals("supplychain.stock.state.items")) {
return new EtatStockTable((JTextField) getEditor("MONTANT_HA"));
} else {
return super.createEditor(id);
}
}
@Override
public void select(SQLRowAccessor r) {
super.select(r);
EtatStockTable table = (EtatStockTable) getEditor("supplychain.stock.state.items");
if (r != null) {
table.insertFrom("ID_ETAT_STOCK", r.getID());
}
}
@Override
public void update() {
super.update();
EtatStockTable table = (EtatStockTable) getEditor("supplychain.stock.state.items");
table.updateField("ID_ETAT_STOCK", getSelectedID());
}
};
}
@Override
protected String createCode() {
return createCodeOfPackage() + ".state";
}
}