/* * Copyright (C) 2014 GG-Net GmbH - Oliver Günther * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package eu.ggnet.dwoss.redtape.document.complaint; import java.util.ArrayList; import java.util.List; import javax.swing.JOptionPane; import eu.ggnet.saft.core.Client; import eu.ggnet.dwoss.mandator.MandatorSupporter; import eu.ggnet.dwoss.redtape.entity.Position; import eu.ggnet.dwoss.redtape.entity.PositionBuilder; import eu.ggnet.dwoss.rules.PositionType; import eu.ggnet.dwoss.redtape.document.AfterInvoicePosition; import eu.ggnet.dwoss.util.CloseType; import eu.ggnet.dwoss.util.IPreClose; import static eu.ggnet.dwoss.rules.PositionType.COMMENT; /** * * @author pascal.perau */ public class ComplaintView extends javax.swing.JPanel implements IPreClose{ private List<AfterInvoicePosition> complaintPositions; /** Creates new form ComplaintView */ public ComplaintView(List<AfterInvoicePosition> complaintPositions) { initComponents(); this.complaintPositions = complaintPositions; afterInvoiceTablePanel.setTableModel(new ComplaintTableModel(complaintPositions)); } public List<Position> getPositions() { List<Position> positions = new ArrayList<>(); for (AfterInvoicePosition afterInvoicePosition : complaintPositions) { if ( afterInvoicePosition.isParticipant() ) { positions.add(afterInvoicePosition.getPosition()); } } if ( afterInvoiceTablePanel.getComment() != null && !afterInvoiceTablePanel.getComment().trim().equals("") ) positions.add(new PositionBuilder().setType(PositionType.COMMENT).setName("Grund/Beschreibung") .setBookingAccount(Client.lookup(MandatorSupporter.class).loadPostLedger().get(COMMENT).orElse(-1)) .setDescription(afterInvoiceTablePanel.getComment()).createPosition()); return positions; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { afterInvoiceTablePanel = new eu.ggnet.dwoss.redtape.document.AfterInvoiceTablePanel(); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(afterInvoiceTablePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 684, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(afterInvoiceTablePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 395, javax.swing.GroupLayout.PREFERRED_SIZE)) ); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private eu.ggnet.dwoss.redtape.document.AfterInvoiceTablePanel afterInvoiceTablePanel; // End of variables declaration//GEN-END:variables @Override public boolean pre(CloseType type) { if ( type == CloseType.OK && getPositions().isEmpty() ) { JOptionPane.showMessageDialog(this, "keine Positionen zur Gutschrift gewählt"); return false; } return true; } }