Exemplo n.º 1
0
  // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
  private void initComponents() {
    reportConstraintPanel = new com.floreantpos.swing.TransparentPanel();
    jLabel1 = new javax.swing.JLabel();
    cbReportType = new javax.swing.JComboBox();
    jLabel2 = new javax.swing.JLabel();
    dpStartDate = UiUtil.getCurrentMonthStart();
    dpEndDate = UiUtil.getCurrentMonthEnd();
    jLabel3 = new javax.swing.JLabel();
    btnRefresh = new javax.swing.JButton();
    reportPanel = new com.floreantpos.swing.TransparentPanel();

    setLayout(new java.awt.BorderLayout(5, 5));

    jLabel1.setText(Messages.getString("ReportViewer.0") + ":"); // $NON-NLS-1$ //$NON-NLS-2$

    cbReportType.setModel(
        new javax.swing.DefaultComboBoxModel(
            new String[] {
              com.floreantpos.POSConstants.PREVIOUS_SALE_AFTER_DRAWER_RESET_,
              com.floreantpos.POSConstants.SALE_BEFORE_DRAWER_RESET
            }));

    jLabel2.setText(com.floreantpos.POSConstants.START_DATE + ":"); // $NON-NLS-1$

    jLabel3.setText(com.floreantpos.POSConstants.END_DATE + ":"); // $NON-NLS-1$

    btnRefresh.setText(com.floreantpos.POSConstants.REFRESH);
    btnRefresh.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            doRefreshReport(evt);
          }
        });

    org.jdesktop.layout.GroupLayout reportConstraintPanelLayout =
        new org.jdesktop.layout.GroupLayout(reportConstraintPanel);
    reportConstraintPanel.setLayout(reportConstraintPanelLayout);
    reportConstraintPanelLayout.setHorizontalGroup(
        reportConstraintPanelLayout
            .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(
                reportConstraintPanelLayout
                    .createSequentialGroup()
                    .addContainerGap()
                    .add(
                        reportConstraintPanelLayout
                            .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(
                                reportConstraintPanelLayout
                                    .createSequentialGroup()
                                    .add(
                                        reportConstraintPanelLayout
                                            .createParallelGroup(
                                                org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(jLabel2)
                                            .add(jLabel1))
                                    .add(15, 15, 15)
                                    .add(
                                        reportConstraintPanelLayout
                                            .createParallelGroup(
                                                org.jdesktop.layout.GroupLayout.LEADING, false)
                                            .add(
                                                cbReportType,
                                                0,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE)
                                            .add(
                                                dpStartDate,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE))
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(jLabel3)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(
                                        dpEndDate,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, btnRefresh))
                    .addContainerGap()));
    reportConstraintPanelLayout.setVerticalGroup(
        reportConstraintPanelLayout
            .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(
                reportConstraintPanelLayout
                    .createSequentialGroup()
                    .addContainerGap()
                    .add(
                        reportConstraintPanelLayout
                            .createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel1)
                            .add(
                                cbReportType,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(
                        reportConstraintPanelLayout
                            .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(
                                dpEndDate,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel3)
                            .add(
                                reportConstraintPanelLayout
                                    .createSequentialGroup()
                                    .add(
                                        reportConstraintPanelLayout
                                            .createParallelGroup(
                                                org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(
                                                dpStartDate,
                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(jLabel2))
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                    .add(btnRefresh)))
                    .addContainerGap(
                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    reportConstraintPanelLayout.linkSize(
        new java.awt.Component[] {dpEndDate, dpStartDate, jLabel2, jLabel3},
        org.jdesktop.layout.GroupLayout.VERTICAL);

    add(reportConstraintPanel, java.awt.BorderLayout.NORTH);

    reportPanel.setLayout(new java.awt.BorderLayout());

    add(reportPanel, java.awt.BorderLayout.CENTER);
  } // </editor-fold>//GEN-END:initComponents
public class MenuUsageReportView extends JPanel {
  private JXDatePicker fromDatePicker = UiUtil.getCurrentMonthStart();
  private JXDatePicker toDatePicker = UiUtil.getCurrentMonthEnd();
  private JButton btnGo = new JButton(com.floreantpos.POSConstants.GO);
  private JPanel reportContainer;

  public MenuUsageReportView() {
    super(new BorderLayout());

    JPanel topPanel = new JPanel(new MigLayout());

    topPanel.add(new JLabel(com.floreantpos.POSConstants.FROM + ":"), "grow");
    //		topPanel.add(fromDatePicker,"wrap");
    topPanel.add(fromDatePicker);
    topPanel.add(new JLabel(com.floreantpos.POSConstants.TO + ":"), "grow");
    //		topPanel.add(toDatePicker,"wrap");
    topPanel.add(toDatePicker);
    //		topPanel.add(btnGo, "skip 1, al right");
    topPanel.add(new JLabel("  "));
    topPanel.add(btnGo);
    add(topPanel, BorderLayout.NORTH);

    JPanel centerPanel = new JPanel(new BorderLayout());
    centerPanel.setBorder(new EmptyBorder(0, 10, 10, 10));
    centerPanel.add(new JSeparator(), BorderLayout.NORTH);

    reportContainer = new JPanel(new BorderLayout());
    centerPanel.add(reportContainer);

    add(centerPanel);

    btnGo.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            try {
              viewReport();
            } catch (Exception e1) {
              POSMessageDialog.showError(MenuUsageReportView.this, POSConstants.ERROR_MESSAGE, e1);
            }
          }
        });
  }

  private void viewReport() throws Exception {
    Date fromDate = fromDatePicker.getDate();
    Date toDate = toDatePicker.getDate();

    if (fromDate.after(toDate)) {
      POSMessageDialog.showError(
          BackOfficeWindow.getInstance(),
          com.floreantpos.POSConstants.FROM_DATE_CANNOT_BE_GREATER_THAN_TO_DATE_);
      return;
    }

    fromDate = DateUtil.startOfDay(fromDate);
    toDate = DateUtil.endOfDay(toDate);

    ReportService reportService = new ReportService();
    MenuUsageReport report = reportService.getMenuUsageReport(fromDate, toDate);

    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("reportTitle", "========= LAPORAN PENJUALAN PER MENU ==========");
    map.put("fromDate", ReportService.formatShortDate(fromDate));
    map.put("toDate", ReportService.formatShortDate(toDate));
    map.put("reportTime", ReportService.formatFullDate(new Date()));

    JasperReport jasperReport =
        (JasperReport)
            JRLoader.loadObject(
                getClass().getResource("/com/floreantpos/ui/report/menu_usage_report.jasper"));
    JasperPrint jasperPrint =
        JasperFillManager.fillReport(
            jasperReport, map, new JRTableModelDataSource(report.getTableModel()));
    JRViewer viewer = new JRViewer(jasperPrint);
    reportContainer.removeAll();
    reportContainer.add(viewer);
    reportContainer.revalidate();
  }
}
public class CreditCardReportView extends JPanel {
  private JXDatePicker fromDatePicker = UiUtil.getCurrentMonthStart();
  private JXDatePicker toDatePicker = UiUtil.getCurrentMonthEnd();
  private JButton btnGo = new JButton(com.floreantpos.POSConstants.GO);
  private JPanel reportContainer;

  public CreditCardReportView() {
    super(new BorderLayout());

    JPanel topPanel = new JPanel(new MigLayout());

    topPanel.add(new JLabel(com.floreantpos.POSConstants.FROM + ":"), "grow");
    topPanel.add(fromDatePicker);
    topPanel.add(new JLabel(com.floreantpos.POSConstants.TO + ":"), "grow");
    topPanel.add(toDatePicker);
    topPanel.add(new JLabel("  "));
    topPanel.add(btnGo);
    add(topPanel, BorderLayout.NORTH);

    JPanel centerPanel = new JPanel(new BorderLayout());
    centerPanel.setBorder(new EmptyBorder(0, 10, 10, 10));
    centerPanel.add(new JSeparator(), BorderLayout.NORTH);

    reportContainer = new JPanel(new BorderLayout());
    centerPanel.add(reportContainer);

    add(centerPanel);

    btnGo.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            try {
              viewReport();
            } catch (Exception e1) {
              POSMessageDialog.showError(CreditCardReportView.this, POSConstants.ERROR_MESSAGE, e1);
            }
          }
        });
  }

  private void viewReport() throws Exception {
    Date fromDate = fromDatePicker.getDate();
    Date toDate = toDatePicker.getDate();

    if (fromDate.after(toDate)) {
      POSMessageDialog.showError(
          BackOfficeWindow.getInstance(),
          com.floreantpos.POSConstants.FROM_DATE_CANNOT_BE_GREATER_THAN_TO_DATE_);
      return;
    }

    fromDate = DateUtil.startOfDay(fromDate);
    toDate = DateUtil.endOfDay(toDate);

    ReportService reportService = new ReportService();
    CreditCardReport report = reportService.getCreditCardReport(fromDate, toDate);

    HashMap<String, Object> map = new HashMap<String, Object>();
    ReportUtil.populateRestaurantProperties(map);
    map.put(
        "reportTitle",
        "========= " + Messages.getString("PosMessage.142").toUpperCase() + " ==========");
    map.put("fromDate", ReportService.formatShortDate(fromDate));
    map.put("toDate", ReportService.formatShortDate(toDate));
    map.put("reportTime", ReportService.formatFullDate(new Date()));

    map.put("salesCount", String.valueOf(report.getTotalSalesCount()));
    map.put("totalSales", NumberUtil.formatNumber(report.getTotalSales()));
    map.put("netTips", NumberUtil.formatNumber(report.getNetTips()));
    map.put("netTipsPaid", NumberUtil.formatNumber(report.getTipsPaid()));
    map.put("netCharge", NumberUtil.formatNumber(report.getNetCharge()));

    JasperReport jasperReport =
        (JasperReport)
            JRLoader.loadObject(
                getClass().getResource("/com/floreantpos/ui/report/credit_card_report.jasper"));
    JasperPrint jasperPrint =
        JasperFillManager.fillReport(
            jasperReport, map, new JRTableModelDataSource(report.getTableModel()));
    JRViewer viewer = new JRViewer(jasperPrint);
    reportContainer.removeAll();
    reportContainer.add(viewer);
    reportContainer.revalidate();
  }

  //	public static void main(String[] args) {
  //		PanelTester.width = 800;
  //		PanelTester.height = 500;
  //		PanelTester.test(new CreditCardReportView());
  //	}
}