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 CreateProductJPanel */
 public ViewProductDetailJPanel(JPanel upc, Product p) {
   initComponents();
   userProcessContainer = upc;
   product = p;
   nameField.setText(p.getProdName());
   idField.setText(convertInteger(p.getModelNumber()));
   priceField.setText(convertInteger(p.getPrice()));
 }
  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);
      }
    }
  }
 /** 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");
   }
 }
  private void saveButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_saveButtonActionPerformed
    // TODO add your handling code here:
    try {
      String productName = nameField.getText().trim();
      int price = Integer.parseInt(priceField.getText().trim());
      if (productName.length() == 0) {
        JOptionPane.showMessageDialog(
            null, "Please enter a Product Name", "Warning Message", JOptionPane.WARNING_MESSAGE);
      } else {
        product.setPrice(price);
        product.setProdName(productName);

        priceField.setEditable(false);
        nameField.setEditable(false);
        saveButton.setEnabled(false);
      }
    } catch (NumberFormatException nfe) {
      JOptionPane.showMessageDialog(
          null, "Please enter a valid Price", "Warning Message", JOptionPane.WARNING_MESSAGE);
    }
  } // GEN-LAST:event_saveButtonActionPerformed
  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);
    }
  }
  private void addCartjButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addCartjButtonActionPerformed
    // TODO add your handling code here:
    int selectedRow = tblProductTable.getSelectedRow();
    int quantity = (Integer) spnQtySpinner.getValue();
    if (selectedRow < 0) {
      JOptionPane.showMessageDialog(null, "Please select a row.!!");
      return;
    }
    Product product = (Product) tblProductTable.getValueAt(selectedRow, 0);
    if (quantity <= 0 || quantity > product.getAvailability()) {
      JOptionPane.showMessageDialog(null, "Sorry Not Available.!!");
      return;
    }

    Boolean isIncluded = false;

    for (OrderItem oi : order.getOrderItemList()) {
      if (oi.getProduct().getProdName().equals(product.getProdName())) {
        int oldQuantity = oi.getQuantity();
        int newQuantity = (Integer) spnQtySpinner.getValue();
        int availibility = product.getAvailability();
        int totalQuantity = oldQuantity + newQuantity;
        // System.out.println("oldquant :"+oldQuantity+"new quantity :"+newQuantity+"availibitliyt
        // :"+availibility+"totalquant :"+totalQuantity);
        oi.setQuantity(totalQuantity);
        int newAvailability = availibility - newQuantity;
        // System.out.println("newAvailibilty :"+newAvailability);
        product.setAvailability(newAvailability);
        isIncluded = true;
      }
    }
    if (!isIncluded) {
      OrderItem item = order.addOrderItem();
      item.setProduct(product);

      int quantity_notIncluded = (Integer) spnQtySpinner.getValue();
      item.setQuantity(quantity_notIncluded);
      int new_Availability = product.getAvailability() - quantity_notIncluded;
      product.setAvailability(new_Availability);
    }
    populateOrderItemTable();
    populateProductTable();
  } // GEN-LAST:event_addCartjButtonActionPerformed