public void deleteItem(int i) {

    PaymentItem item = entity.getItems().get(i);

    try {
      // if (item instanceof PaymentItemCheque) {
      if (item.getLineType().equals(PaymentType.Cheque)) {
        Cheque cheque = ((PaymentItemCheque) item).getCheque();
        entityManager.remove(entityManager.getReference(PaymentItem.class, item.getId()));
        entityManager.remove(entityManager.getReference(Cheque.class, cheque.getId()));

      }
      // else if(item instanceof PaymentItemPromissoryNote) {
      else if (item.getLineType().equals(PaymentType.PromissoryNote)) {
        PromissoryNote promissory = ((PaymentItemPromissoryNote) item).getPromissoryNote();

        entityManager.remove(entityManager.getReference(PaymentItem.class, item.getId()));
        entityManager.remove(entityManager.getReference(PromissoryNote.class, promissory.getId()));
      } else {
        entityManager.remove(entityManager.getReference(PaymentItem.class, item.getId()));
      }

    } catch (Exception e) {
      facesMessages.add("Silmede hata!");
      // log.debug("silme hatası #0", e.getMessage());
      log.info("silme hatası #0 ", e);
      log.debug("hata sebeo #0 :", e);
    }
  }
  public void controllItem() {
    if (getEntity() == null) return;

    try {
      if (getEntity().getId() != null) {
        if (entity.getItems() != null && entity.getItems().size() != 0) {
          for (PaymentItem item : entity.getItems()) {

            if (item.getId() == null) {
              return;
            }
            if (item instanceof PaymentItemCheque) {

              Cheque cheque = ((PaymentItemCheque) item).getCheque();

              if (cheque.getLastStatus() != cheque.getPreviousStatus()) {

                isEditable = false;
                break;
              }

            } else if (item instanceof PaymentItemPromissoryNote) {

              PromissoryNote promissory = ((PaymentItemPromissoryNote) item).getPromissoryNote();

              if (promissory.getLastStatus() != promissory.getPreviousStatus()) {

                isEditable = false;
                break;
              }
            }
          }
        } else {
          isEditable = true;
        }
      }
    } catch (Exception e) {
      log.error("Hata :", e);
    }
  }