Ejemplo n.º 1
0
  @Override
  public void createCustomerNote(CustomerNoteFormDto customerNoteForm) {

    MifosUser user =
        (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);

    CustomerBO customer = this.customerDao.findCustomerBySystemId(customerNoteForm.getGlobalNum());
    customer.updateDetails(userContext);

    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());

    CustomerNoteEntity customerNote =
        new CustomerNoteEntity(
            customerNoteForm.getComment(),
            new DateTimeService().getCurrentJavaSqlDate(),
            loggedInUser,
            customer);
    customer.addCustomerNotes(customerNote);

    try {
      this.transactionHelper.startTransaction();
      this.customerDao.save(customer);
      this.transactionHelper.commitTransaction();
    } catch (Exception e) {
      this.transactionHelper.rollbackTransaction();
      throw new BusinessRuleException(customer.getCustomerAccount().getAccountId().toString(), e);
    } finally {
      this.transactionHelper.closeSession();
    }
  }
Ejemplo n.º 2
0
  @Override
  public void revertLastChargesPayment(String globalCustNum, String adjustmentNote) {

    MifosUser user =
        (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);

    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    CustomerBO customerBO = this.customerDao.findCustomerBySystemId(globalCustNum);
    customerBO.updateDetails(userContext);

    if (customerBO.getCustomerAccount().findMostRecentNonzeroPaymentByPaymentDate() != null) {
      customerBO.getCustomerAccount().updateDetails(userContext);

      try {
        if (customerBO.getPersonnel() != null) {
          new AccountBusinessService()
              .checkPermissionForAdjustment(
                  AccountTypes.CUSTOMER_ACCOUNT,
                  customerBO.getLevel(),
                  userContext,
                  customerBO.getOffice().getOfficeId(),
                  customerBO.getPersonnel().getPersonnelId());
        } else {
          new AccountBusinessService()
              .checkPermissionForAdjustment(
                  AccountTypes.CUSTOMER_ACCOUNT,
                  customerBO.getLevel(),
                  userContext,
                  customerBO.getOffice().getOfficeId(),
                  userContext.getId());
        }

        this.transactionHelper.startTransaction();
        customerBO.adjustPmnt(adjustmentNote, loggedInUser);
        this.customerDao.save(customerBO);
        this.transactionHelper.commitTransaction();
      } catch (SystemException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
      } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
      }
    }
  }