private void btnModifyActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnModifyActionPerformed
    // TODO add your handling code here:
    if (txtModifyQuantity.getText().trim().length() == 0) {
      JOptionPane.showMessageDialog(null, "Please enter some value.!!");
      return;
    }
    try {

      int selectedRow = orderJTable.getSelectedRow();

      if (selectedRow < 0) {
        JOptionPane.showMessageDialog(null, "Please select a row.!!");
        return;
      }

      int modifyQuantity = Integer.parseInt(txtModifyQuantity.getText());
      if (modifyQuantity < 0) {
        JOptionPane.showMessageDialog(null, "Please enter a valid quantity.!!");
        return;
      }

      OrderItem oi = (OrderItem) orderJTable.getValueAt(selectedRow, 0);
      if (modifyQuantity == oi.getQuantity()) {
        JOptionPane.showMessageDialog(null, "Entered value is same as designated quantity.!!");
        return;
      }
      for (Employee person : employeeDirectory.getEmployeeList()) {
        Supplier supplier = (Supplier) person;
        for (Product product : supplier.getProductCatalog().getProductCatalog()) {
          if (product.getProdName().equalsIgnoreCase(oi.getProduct().getProdName())) {
            int oldAvailabilty = product.getAvailability();
            int orderedQuantity = oi.getQuantity();
            int totalQuantity = oldAvailabilty + orderedQuantity;
            if (modifyQuantity <= totalQuantity) {
              oi.setQuantity(modifyQuantity);
              product.setAvailability(totalQuantity - modifyQuantity);
              //                        if(oi.getQuantity()==0){
              //                        order.removeOrderItem(oi);
              //                        }
            } else {
              JOptionPane.showMessageDialog(null, "Sorry quantity not available.!!");
              return;
            }
          }
        }
      }
      txtModifyQuantity.setText("");
      populateProductTable();
      populateOrderItemTable();
    } catch (NumberFormatException nfe) {
      JOptionPane.showMessageDialog(null, "Please enter a valid quantity.!!");
    }
  } // GEN-LAST:event_btnModifyActionPerformed
  public void populateProductTable() {
    Supplier supplier = (Supplier) cmbSupplierJComboBox.getSelectedItem();
    DefaultTableModel tableModel = (DefaultTableModel) tblProductTable.getModel();
    tableModel.setRowCount(0);
    if (supplier != null) {
      for (Product product : supplier.getProductCatalog().getProductCatalog()) {
        Object rows[] = new Object[3];
        rows[0] = product;
        rows[1] = product.getPrice();
        rows[2] = product.getAvailability();

        tableModel.addRow(rows);
      }
    }
  }
  private void btnPictorialViewActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnPictorialViewActionPerformed
    // TODO add your handling code here:
    DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();

    for (Product product : supplier.getProductCatalog().getProductCatalog()) {
      categoryDataset.setValue(product.getSoldQuantity(), "Units", product.getProdName());
    }
    JFreeChart freeChart =
        ChartFactory.createBarChart(
            "Sales Report",
            "Product",
            "Units",
            categoryDataset,
            PlotOrientation.VERTICAL,
            false,
            true,
            false);

    CategoryPlot categoryPlot = freeChart.getCategoryPlot();
    categoryPlot.setRangeGridlinePaint(Color.BLACK);
    ChartFrame cf = new ChartFrame("Sales Report", freeChart);
    cf.setVisible(true);
    cf.setSize(450, 300);
  } // GEN-LAST:event_btnPictorialViewActionPerformed
 /** Creates new form ReviewProductPerformance */
 public ProductReportJPanel(JPanel userProcessContainer, Supplier supplier) {
   initComponents();
   this.userProcessContainer = userProcessContainer;
   this.supplier = supplier;
   supplierName.setText(supplier.getName() + "-- Sales Performance");
   try {
     Product product = supplier.getProductsSorted(supplier);
     productName.setText(product.getProdName());
     quanitytxt.setText(String.valueOf(product.getSoldQuantity()));
     populateProducts();
   } catch (IndexOutOfBoundsException ai) {
     errorMsg.setText("Sales Report Not Generated...!!!");
     JOptionPane.showMessageDialog(
         null, "The Sales Report will only be generated after the customer's checkout");
   }
 }
  public void populateProductTable(String prodName) {

    DefaultTableModel tableModel = (DefaultTableModel) tblProductTable.getModel();
    tableModel.setRowCount(0);
    boolean found = false;
    for (Employee person : employeeDirectory.getEmployeeList()) {
      Supplier supplier = (Supplier) person;
      for (Product product : supplier.getProductCatalog().getProductCatalog()) {
        if (prodName.equalsIgnoreCase(product.getProdName())) {
          Object rows[] = new Object[3];
          rows[0] = product;
          rows[1] = product.getPrice();
          rows[2] = product.getAvailability();

          tableModel.addRow(rows);
          found = true;
        }
      }
    }
    if (!found) {
      JOptionPane.showMessageDialog(null, "No Search Results..!!!");
    }
  }
  private void populateProducts() {

    //        Collections.sort(supplier.getProductCatalog().getProductCatalog(), new
    // Comparator<Product>(){
    //
    //            public int compare(Product o1, Product o2) {
    //                if(o1.getSoldQuantity() < o2.getSoldQuantity())
    //                    return 1;
    //                else if(o1.getSoldQuantity() > o2.getSoldQuantity())
    //                    return -1;
    //                return 0;
    //            }
    //        });
    DefaultTableModel dtm = (DefaultTableModel) salestbl.getModel();
    dtm.setRowCount(0);
    for (Product p : supplier.getProductCatalog().getProductCatalog()) {
      Object row[] = new Object[4];
      row[0] = p;
      row[1] = p.getSoldQuantity();
      row[2] = p.getPrice();
      row[3] = (p.getSoldQuantity() * p.getPrice());
      dtm.addRow(row);
    }
  }