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
  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