Package Interface

Source Code of Interface.TotaalOmzet

package Interface;

import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Graphics2D;

import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.JScrollPane;
import java.awt.Color;
import javax.swing.JButton;

import com.itextpdf.awt.geom.Shape;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPTableHeader;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.collection.PdfTargetDictionary;

import Logica.DecimalPlaces;
import Logica.Kassa;
import Logica.rekeningItem;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Vector;

public class TotaalOmzet extends JPanel {

  /**
   * Create the panel.
   */
 
  private KassaGUI fGUI;
  private Kassa fKassa;
  private JTable table;
  private Vector<rekeningItem> fData;
  private double totaal;
  private double subtotaal;
  private double albetaald;
  private int hoeveel;
  private int alBetaald;
 
  public TotaalOmzet(KassaGUI gui, Kassa kassa) {
    fGUI = gui;
    fKassa = kassa;
    fData = fKassa.getTotaalOmzet();
   
    table = new JTable(new TotaalTable(fData));
    table.setGridColor(Color.LIGHT_GRAY);
    table.setBackground(Color.WHITE);
    table.setAutoCreateRowSorter(true);
   
    totaal = getTotaal();
    subtotaal = getSubTotaal();
    albetaald = totaal - subtotaal;
   
    setLayout(new BorderLayout(0, 0));
   
    JLabel lblTotaalomzet = new JLabel("Totaal omzet");
    lblTotaalomzet.setHorizontalAlignment(SwingConstants.CENTER);
    lblTotaalomzet.setFont(new Font("Lucida Grande", Font.BOLD, 17));
    add(lblTotaalomzet, BorderLayout.NORTH);
   
    JPanel panel = new JPanel();
    add(panel, BorderLayout.CENTER);
    panel.setLayout(null);
   
    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setBounds(49, 21, 703, 371);
    panel.add(scrollPane);
   
    JLabel lblTotaal = new JLabel("Totaal:");
    lblTotaal.setBounds(49, 418, 58, 16);
    panel.add(lblTotaal);
   
    JLabel label = new JLabel("€" + DecimalPlaces.set2decimals(totaal));
    label.setForeground(Color.RED);
    label.setFont(new Font("Lucida Grande", Font.BOLD, 16));
    label.setBounds(49, 432, 114, 27);
    panel.add(label);
   
    JLabel lblAlBetaald = new JLabel("Al betaald:");
    lblAlBetaald.setBounds(175, 418, 100, 16);
    panel.add(lblAlBetaald);
   
    JLabel label_1 = new JLabel("€" + DecimalPlaces.set2decimals(albetaald));
    label_1.setForeground(Color.RED);
    label_1.setFont(new Font("Lucida Grande", Font.BOLD, 16));
    label_1.setBounds(175, 432, 114, 27);
    panel.add(label_1);
   
    JLabel lblNogTeBetalen = new JLabel("Nog te betalen:");
    lblNogTeBetalen.setBounds(301, 418, 100, 16);
    panel.add(lblNogTeBetalen);
   
    JLabel label_2 = new JLabel("€" + DecimalPlaces.set2decimals(subtotaal));
    label_2.setForeground(Color.RED);
    label_2.setFont(new Font("Lucida Grande", Font.BOLD, 16));
    label_2.setBounds(301, 432, 114, 27);
    panel.add(label_2);
   
    JButton btnTerug = new JButton("Terug");
    btnTerug.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        fGUI.open(new ChoiseTable(fKassa, fGUI));
      }
    });
    btnTerug.setBounds(635, 404, 117, 29);
    panel.add(btnTerug);
   
    JButton btnNewButton = new JButton("Refresh");
    btnNewButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        fGUI.open(new TotaalOmzet(fGUI, fKassa));
      }
    });
    btnNewButton.setBounds(635, 433, 117, 29);
    panel.add(btnNewButton);
   
    JButton btnPrintToPdf = new JButton("Print to PDF");
    btnPrintToPdf.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        print();
      }
    });
    btnPrintToPdf.setBounds(506, 418, 117, 29);
    panel.add(btnPrintToPdf);

  }
 
  private double getTotaal(){
    double toRet = 0;
    hoeveel = 0;
    for(int i = 0; i < fData.size(); i++){
      hoeveel += fData.get(i).getHoeveelheid();
      toRet += fData.get(i).getTotaal();
    }
   
    return toRet;
  }
 
  private double getSubTotaal(){
    double toRet = 0;
    alBetaald = 0;
    for(int i = 0; i < fData.size(); i++){
      alBetaald += fData.get(i).getAfgerekend();
      toRet += fData.get(i).getSubTotaal();
    }
   
    return toRet;
  }
 
  public void print() {
    Document document = new Document();
        try {
            PdfWriter.getInstance(document,new FileOutputStream("Totaal.pdf"));
            document.open();
            PdfPTable pdfTable = new PdfPTable(table.getColumnCount());
            pdfTable.setLockedWidth(false);
            PdfPCell cell = new PdfPCell();
            Phrase phrase = null;
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell.setBorderWidthLeft(1);
            for(int i=0;i<table.getColumnCount();i++)
            {
                phrase = new Phrase(table.getColumnName(i));
                cell = new PdfPCell(phrase);
                cell.setBackgroundColor(new BaseColor(220, 220, 220));
                pdfTable.addCell(cell);
            }
            for(int i=0;i<table.getRowCount();++i)
            {
                for(int j=0;j<table.getColumnCount();++j)
                {
                    phrase = new Phrase(String.valueOf(table.getValueAt(i, j)));
                    cell = new PdfPCell(phrase);
                    pdfTable.addCell(cell);
                }
            }
            pdfTable.addCell("Totaal");
            pdfTable.addCell("");
            pdfTable.addCell(hoeveel + "");
            pdfTable.addCell("€" + DecimalPlaces.set2decimals(totaal));
            pdfTable.addCell(alBetaald + "");
            pdfTable.addCell("€" + DecimalPlaces.set2decimals(albetaald));
            pdfTable.addCell("€" + DecimalPlaces.set2decimals(subtotaal));
            pdfTable.setHeaderRows(1);
            pdfTable.normalizeHeadersFooters();
            document.add(pdfTable);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return;
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return;
        }
        document.close();
        JOptionPane.showMessageDialog(null, "PDF 'Totaal.pdf' aangemaakt");
  }
}
TOP

Related Classes of Interface.TotaalOmzet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.