public void controllItem() {
    if (getEntity() == null) return;

    try {
      if (getEntity().getId() != null) {
        if (getEntity().getDetails() != null && getEntity().getDetails().size() != 0) {
          for (PromissoryFromContactPayrollDetail items : getEntity().getDetails()) {

            if (items.getId() == null) {
              return;
            }

            PromissoryNote promissoryNote = items.getPromissory();

            if (promissoryNote.getLastStatus() != ChequeStatus.Portfoy) {

              isEditable = false;
              break;
            }
          }
        }
      } else {
        isEditable = true;
      }

    } catch (Exception e) {
      log.error("Hata :", e);
    }
  }
 public void createNewLine() {
   manualFlush();
   if (entity == null) {
     return;
   }
   PromissoryFromContactPayrollDetail detail = new PromissoryFromContactPayrollDetail();
   detail.setOwner(entity);
   entity.getDetails().add(detail);
   log.debug("yeni detay eklendi");
 }
  @Observer("promissoryFromContactPayrollHome:popupNotice:client.promissory")
  public void selectClientPromissory(PromissoryNote promissory) {
    manualFlush();

    if (entity == null) {
      return;
    }

    PromissoryFromContactPayrollDetail cpd = new PromissoryFromContactPayrollDetail();
    cpd.setOwner(entity);
    cpd.setPromissory(promissory);
    cpd.getPromissory().setMoney(promissory.getMoney());
    cpd.getPromissory().getMoney().setCurrency(promissory.getMoney().getCurrency());
    cpd.getPromissory().getMoney().setValue(promissory.getMoney().getValue());
    cpd.getPromissory().setInfo(promissory.getInfo());
    cpd.getPromissory().setReferenceNo(promissory.getReferenceNo());

    if (cpd.getPromissory().getId() != null && entity.getDetails().contains(cpd)) {
      facesMessages.add("Senet zaten mevcut");
      return;
    }

    entity.getDetails().add(cpd);

    log.debug("yeni item eklendi");
  }
  @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;
  }