Esempio n. 1
0
  public void updateCouponView(Discount coupon) {
    if (coupon == null) {
      tfName.setText(""); // $NON-NLS-1$
      tfNumber.setText(""); // $NON-NLS-1$
      tfType.setText(""); // $NON-NLS-1$
      tfValue.setText(""); // $NON-NLS-1$
      return;
    }

    btnEditValue.setEnabled(false);

    tfName.setText(coupon.getName());
    if (coupon.getType() == Discount.FREE_AMOUNT) {
      btnEditValue.setEnabled(true);
    }

    tfNumber.setText(String.valueOf(coupon.getId()));
    tfType.setText(Discount.COUPON_TYPE_NAMES[coupon.getType()]);
    tfValue.setText(NumberUtil.formatNumber(coupon.getValue()));

    double totalDiscount = 0;
    double subtotal = ticket.getSubtotalAmount();

    ticketCoupon.setDiscountId(coupon.getId());
    ticketCoupon.setName(coupon.getName());
    ticketCoupon.setType(coupon.getType());
    ticketCoupon.setValue(coupon.getValue());

    totalDiscount = ticket.calculateDiscountFromType(ticketCoupon, subtotal);
    ticketCoupon.setValue(totalDiscount);

    lblTotalDiscount.setText(NumberUtil.formatNumber(totalDiscount));
  }