Ejemplo n.º 1
0
  public void testSuccessfulPreview() throws Exception {
    CollectionSheetEntryGridDto bulkEntry = getSuccessfulBulkEntry();
    Calendar meetinDateCalendar = new GregorianCalendar();
    int year = meetinDateCalendar.get(Calendar.YEAR);
    int month = meetinDateCalendar.get(Calendar.MONTH);
    int day = meetinDateCalendar.get(Calendar.DAY_OF_MONTH);
    meetinDateCalendar = new GregorianCalendar(year, month, day);

    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    SessionUtils.setAttribute(CollectionSheetEntryConstants.BULKENTRY, bulkEntry, request);
    setRequestPathInfo("/collectionsheetaction.do");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("method", "preview");
    addRequestParameter("attendanceSelected[0]", "1");
    addRequestParameter("enteredAmount[0][0]", "212.0");
    addRequestParameter("enteredAmount[1][1]", "212.0");
    addRequestParameter("enteredAmount[0][1]", "212.0");
    addRequestParameter("enteredAmount[1][0]", "212.0");
    addRequestParameter("withDrawalAmountEntered[2][2]", "100.0");
    addRequestParameter("depositAmountEntered[2][2]", "100.0");
    addRequestParameter("withDrawalAmountEntered[0][0]", "100.0");
    addRequestParameter("depositAmountEntered[0][0]", "100.0");
    addRequestDateParameter("transactionDate", day + "/" + (month + 1) + "/" + year);
    performNoErrors();
    verifyForward("preview_success");

    groupAccount = TestObjectFactory.getObject(LoanBO.class, groupAccount.getAccountId());
    clientAccount = TestObjectFactory.getObject(LoanBO.class, clientAccount.getAccountId());
    centerSavingsAccount =
        TestObjectFactory.getObject(SavingsBO.class, centerSavingsAccount.getAccountId());
    clientSavingsAccount =
        TestObjectFactory.getObject(SavingsBO.class, clientSavingsAccount.getAccountId());
    groupSavingsAccount =
        TestObjectFactory.getObject(SavingsBO.class, groupSavingsAccount.getAccountId());
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    client = TestObjectFactory.getClient(client.getCustomerId());
  }
Ejemplo n.º 2
0
  @TransactionDemarcate(validateAndResetToken = true)
  @CloseSession
  public ActionForward update(
      final ActionMapping mapping,
      final ActionForm form,
      final HttpServletRequest request,
      @SuppressWarnings("unused") final HttpServletResponse response)
      throws Exception {

    LoanDisbursementActionForm actionForm = (LoanDisbursementActionForm) form;

    UserContext uc = getUserContext(request);
    Date trxnDate = getDateFromString(actionForm.getTransactionDate(), uc.getPreferredLocale());
    trxnDate = DateUtils.getDateWithoutTimeStamp(trxnDate.getTime());
    Date receiptDate = getDateFromString(actionForm.getReceiptDate(), uc.getPreferredLocale());

    Integer loanAccountId = Integer.valueOf(actionForm.getAccountId());
    AccountBO accountBO = new AccountBusinessService().getAccount(loanAccountId);

    createGroupQuestionnaire.saveResponses(request, actionForm, loanAccountId);

    try {
      String paymentTypeIdStringForDisbursement = actionForm.getPaymentTypeId();
      Short paymentTypeIdForDisbursement =
          StringUtils.isEmpty(paymentTypeIdStringForDisbursement)
              ? PaymentTypes.CASH.getValue()
              : Short.valueOf(paymentTypeIdStringForDisbursement);

      Short paymentTypeId = Short.valueOf(paymentTypeIdForDisbursement);
      final String comment = "";
      final BigDecimal disbursalAmount = new BigDecimal(actionForm.getLoanAmount());
      CustomerDto customerDto = null;

      PaymentTypeDto paymentType = null;
      AccountPaymentParametersDto loanDisbursement =
          new AccountPaymentParametersDto(
              new UserReferenceDto(uc.getId()),
              new AccountReferenceDto(loanAccountId),
              disbursalAmount,
              new LocalDate(trxnDate),
              paymentType,
              comment,
              new LocalDate(receiptDate),
              actionForm.getReceiptId(),
              customerDto);

      monthClosingServiceFacade.validateTransactionDate(trxnDate);

      // GLIM
      List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(loanAccountId);
      for (LoanBO individual : individualLoans) {
        if (!loanAccountServiceFacade.isTrxnDateValid(
            Integer.valueOf(individual.getAccountId()), trxnDate)) {
          throw new BusinessRuleException("errors.invalidTxndateOfDisbursal");
        }
      }

      this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId);

      for (LoanBO individual : individualLoans) {
        loanDisbursement =
            new AccountPaymentParametersDto(
                new UserReferenceDto(uc.getId()),
                new AccountReferenceDto(individual.getAccountId()),
                individual.getLoanAmount().getAmount(),
                new LocalDate(trxnDate),
                paymentType,
                comment,
                new LocalDate(receiptDate),
                actionForm.getReceiptId(),
                customerDto);

        this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId);
      }
    } catch (BusinessRuleException e) {
      throw new AccountException(e.getMessage());
    } catch (MifosRuntimeException e) {
      if (e.getCause() != null && e.getCause() instanceof AccountException) {
        throw new AccountException(e.getCause().getMessage());
      }
      String msg = "errors.cannotDisburseLoan.because.disburseFailed";
      logger.error(msg, e);
      throw new AccountException(msg);
    } catch (Exception e) {
      String msg = "errors.cannotDisburseLoan.because.disburseFailed";
      logger.error(msg, e);
      throw new AccountException(msg);
    }

    return mapping.findForward(Constants.UPDATE_SUCCESS);
  }
Ejemplo n.º 3
0
  public void testSuccessfulCreate() throws Exception {
    CollectionSheetEntryGridDto bulkEntry = getSuccessfulBulkEntry();
    Calendar meetingDateCalendar = new GregorianCalendar();
    int year = meetingDateCalendar.get(Calendar.YEAR);
    int month = meetingDateCalendar.get(Calendar.MONTH);
    int day = meetingDateCalendar.get(Calendar.DAY_OF_MONTH);
    meetingDateCalendar = new GregorianCalendar(year, month, day);

    Date meetingDate = new Date(meetingDateCalendar.getTimeInMillis());
    HashMap<Integer, ClientAttendanceDto> clientAttendance =
        new HashMap<Integer, ClientAttendanceDto>();
    clientAttendance.put(1, getClientAttendanceDto(1, meetingDate));
    clientAttendance.put(2, getClientAttendanceDto(2, meetingDate));
    clientAttendance.put(3, getClientAttendanceDto(3, meetingDate));

    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("attendanceSelected[0]", "2");

    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    SessionUtils.setAttribute(CollectionSheetEntryConstants.BULKENTRY, bulkEntry, request);
    setRequestPathInfo("/collectionsheetaction.do");
    addRequestParameter("method", "preview");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestDateParameter("transactionDate", day + "/" + (month + 1) + "/" + year);

    if (SUPPLY_ENTERED_AMOUNT_PARAMETERS) {
      addParametersForEnteredAmount();
      addParametersForDisbursalEnteredAmount();
    }

    performNoErrors();

    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    setRequestPathInfo("/collectionsheetaction.do");
    addRequestParameter("method", "create");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("attendanceSelected[0]", "2");
    addRequestDateParameter("transactionDate", day + "/" + (month + 1) + "/" + year);
    addRequestParameter("customerId", "1");

    performNoErrors();
    verifyForward("create_success");
    Assert.assertNotNull(request.getAttribute(CollectionSheetEntryConstants.CENTER));
    Assert.assertEquals(
        request.getAttribute(CollectionSheetEntryConstants.CENTER), center.getDisplayName());

    groupAccount = TestObjectFactory.getObject(LoanBO.class, groupAccount.getAccountId());
    clientAccount = TestObjectFactory.getObject(LoanBO.class, clientAccount.getAccountId());
    centerSavingsAccount =
        TestObjectFactory.getObject(SavingsBO.class, centerSavingsAccount.getAccountId());
    clientSavingsAccount =
        TestObjectFactory.getObject(SavingsBO.class, clientSavingsAccount.getAccountId());
    groupSavingsAccount =
        TestObjectFactory.getObject(SavingsBO.class, groupSavingsAccount.getAccountId());
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    client = TestObjectFactory.getClient(client.getCustomerId());

    Assert.assertEquals(1, client.getClientAttendances().size());
    Assert.assertEquals(
        AttendanceType.ABSENT,
        client
            .getClientAttendanceForMeeting(new java.sql.Date(meetingDateCalendar.getTimeInMillis()))
            .getAttendanceAsEnum());
  }