@Override
  // @Transactional
  public String delete() {

    financeTxnAction.deletePayment(entity);
    accountTxnAction.deletePayment(entity);

    getMatchProvider().delete(getMatchModels());

    for (int i = 0; i < entity.getItems().size(); i++) {
      deleteItem(i);
    }

    if (entity == null) {
      return BaseConsts.FAIL;
    }

    try {
      getEntityManager().remove(getReference());
      getEntityManager().flush();
    } catch (Exception e) {
      log.debug("Hata : #0", e);
      facesMessages.add("#{messages['general.message.record.DeleteFaild']}");
      return BaseConsts.FAIL;
    }

    log.debug("Entity Removed : {0} ", entity);
    entity = null;
    facesMessages.add("#{messages['general.message.record.DeleteSuccess']}");

    raiseRefreshBrowserEvent();
    endCurrentConversation();
    return BaseConsts.SUCCESS;
  }
  @Override
  @Transactional
  public String delete() {

    financeTxnAction.deletePromissoryFromContactPayroll(entity);

    return super.delete();
  }
  @Transactional
  public String save() {
    String res = null;

    try {

      if (entity.getDetails().size() <= 0) {
        facesMessages.add("Senet Bilgisi Girilmedi!");
        return BaseConsts.FAIL;
      }

      res = super.save();

      if (res.equals(BaseConsts.SUCCESS)) {

        for (PromissoryFromContactPayrollDetail cpd : entity.getDetails()) {
          PromissoryNote promissory = cpd.getPromissory();
          // senedin carisini kaydet metodunda da kaydedelim. popupPromissoryCreate metodunda master
          // da cari seçmeden senet eklenirse senedin carisi null oluyordu.
          promissory.setContact(entity.getContact());
          if (!promissoryAction.alreadySaved(
              promissory, DocumentType.PromissoryFromContactPayroll, entity.getId())) {

            PromissoryParamModel cpm = new PromissoryParamModel();
            cpm.setPromissory(promissory);
            cpm.setNewStatus(ChequeStatus.Portfoy);
            cpm.setDocumentId(entity.getId());
            cpm.setDocumentType(DocumentType.PromissoryFromContactPayroll);
            promissoryAction.changePosition(cpm);

            entityManager.merge(promissory);
          }
        }
        financeTxnAction.savePromissoryFromContactPayroll(entity);

        entityManager.flush();
      }

    } catch (Exception e) {
      log.error("Hata :", e);
      e.printStackTrace();
      res = BaseConsts.FAIL;
    }
    return res;
  }
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public String save() {
    String res = BaseConsts.FAIL;
    manualFlush();
    recalculate();
    // TODO: Çoklu dil desteği.

    try {
      makeValidations();

      res = super.save();

      if (res.equals(BaseConsts.SUCCESS)) {

        saveMatches();

        // FIXME: bu kodlar burada ne arıyor?
        for (PaymentItem pItem : entity.getItems()) {

          if (pItem instanceof PaymentItemCheque) {

            Cheque pic = ((PaymentItemCheque) pItem).getCheque();
            ChequeParamModel cpm;

            if (pic != null) {

              pic.setContact(entity.getContact());

              if (!chequeAction.alreadySaved(pic, DocumentType.Collection, entity.getId())) {

                cpm = new ChequeParamModel();
                cpm.setCheque(pic);
                cpm.setDocumentId(entity.getId());
                cpm.setDocumentType(DocumentType.Collection);
                cpm.setNewStatus(ChequeStatus.Portfoy);
                cpm.setWorkBunch(pItem.getWorkBunch());
                cpm.setDocumentSerial(entity.getSerial());
                cpm.setToAccount(entity.getAccount());
                cpm.setToContact(entity.getContact());
                chequeAction.changePosition(cpm);

                entityManager.merge(pic);
              }
            }

          } else if (pItem instanceof PaymentItemPromissoryNote) {

            PromissoryNote pipn = ((PaymentItemPromissoryNote) pItem).getPromissoryNote();
            PromissoryParamModel cpm;

            if (pipn != null) {

              pipn.setContact(entity.getContact());

              if (!promissoryAction.alreadySaved(pipn, DocumentType.Collection, entity.getId())) {

                cpm = new PromissoryParamModel();
                cpm.setPromissory(pipn);
                cpm.setDocumentId(entity.getId());
                cpm.setDocumentType(DocumentType.Collection);
                cpm.setNewStatus(ChequeStatus.Portfoy);
                cpm.setWorkBunch(pItem.getWorkBunch());
                cpm.setDocumentSerial(entity.getSerial());
                cpm.setToContact(entity.getContact());
                cpm.setToAccount(entity.getAccount());
                promissoryAction.changePosition(cpm);

                entityManager.merge(pipn);
              }
            }
          }
        }

        financeTxnAction.savePayment(entity);
        accountTxnAction.savePayment(entity);

        if (entity.getItems() != null && entity.getItems().size() != 0) {

          for (PaymentItem pItem : entity.getItems()) {

            if (pItem.getLineType() != PaymentType.Cash) {

              financeTxnAction.savePaymentItem(pItem);
            }
          }
        }
        entityManager.flush();
      }

    } catch (Exception e) {
      FacesMessages.afterPhase();
      facesMessages.clear();
      facesMessages.add(e.getMessage());
      log.error("Hata :", e);
      res = BaseConsts.FAIL;
    }
    return res;
  }