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