Search in sources :

Example 1 with BankStatementLineRow

use of de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow in project metasfresh-webui-api by metasfresh.

the class ReconcilePaymentsCommand method checkCanExecute.

public ProcessPreconditionsResolution checkCanExecute() {
    // 
    final BankStatementLineRow bankStatementLine = request.getSelectedBankStatementLine();
    if (bankStatementLine == null) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("no bank statement line selected");
    }
    if (bankStatementLine.isReconciled()) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("bank statement line was already reconciled");
    }
    // 
    final List<PaymentToReconcileRow> payments = request.getSelectedPaymentsToReconcile();
    if (payments.isEmpty()) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("no payment rows selected");
    }
    // 
    final ExplainedOptional<BankStatementLineMultiPaymentLinkRequest> optionalRequest = computeBankStatementLineReconcileRequest();
    if (!optionalRequest.isPresent()) {
        return ProcessPreconditionsResolution.reject(optionalRequest.getExplanation());
    }
    return ProcessPreconditionsResolution.accept();
}
Also used : BankStatementLineMultiPaymentLinkRequest(de.metas.banking.payment.BankStatementLineMultiPaymentLinkRequest) BankStatementLineRow(de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow) PaymentToReconcileRow(de.metas.ui.web.bankstatement_reconciliation.PaymentToReconcileRow)

Example 2 with BankStatementLineRow

use of de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow in project metasfresh-webui-api by metasfresh.

the class PaymentsToReconcileViewBasedProcess method getSingleSelectedBankStatementRowOrNull.

protected final BankStatementLineRow getSingleSelectedBankStatementRowOrNull() {
    final ViewRowIdsSelection selection = getParentViewRowIdsSelection();
    if (selection == null || selection.isEmpty()) {
        return null;
    }
    final ImmutableList<BankStatementLineRow> rows = getBanksStatementReconciliationView().streamByIds(selection).collect(ImmutableList.toImmutableList());
    return rows.size() == 1 ? rows.get(0) : null;
}
Also used : BankStatementLineRow(de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow) ViewRowIdsSelection(de.metas.ui.web.view.ViewRowIdsSelection)

Example 3 with BankStatementLineRow

use of de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow in project metasfresh-webui-api by metasfresh.

the class ReconcilePaymentsCommandTest method bankStatementLineIsLinkedToESRImportLine.

@Test
public void bankStatementLineIsLinkedToESRImportLine() {
    final BankStatementLineRow bankStatementLineRow = bankStatementLineRow().docStatus(DocStatus.Drafted).statementAmt(euro("1000")).build();
    final PaymentToReconcileRow paymentRow = paymentRow().inboundPayment(true).customerId(customerId).paymentAmt(euro("1000")).build();
    final PaymentId paymentId = paymentRow.getPaymentId();
    final I_ESR_ImportLine esrImportLine = createESRImportLine(paymentId);
    assertThat(esrImportLine.getC_Payment_ID()).isEqualTo(paymentId.getRepoId());
    assertThat(esrImportLine.getC_BankStatement_ID()).isLessThanOrEqualTo(0);
    assertThat(esrImportLine.getC_BankStatementLine_ID()).isLessThanOrEqualTo(0);
    assertThat(esrImportLine.getC_BankStatementLine_Ref_ID()).isLessThanOrEqualTo(0);
    executeReconcilePaymentsCommand(ReconcilePaymentsRequest.builder().selectedBankStatementLine(bankStatementLineRow).selectedPaymentToReconcile(paymentRow).build());
    InterfaceWrapperHelper.refresh(esrImportLine);
    assertThat(esrImportLine.getC_BankStatement_ID()).isGreaterThan(0);
    assertThat(esrImportLine.getC_BankStatementLine_ID()).isEqualTo(bankStatementLineRow.getBankStatementLineId().getRepoId());
    assertThat(esrImportLine.getC_BankStatementLine_Ref_ID()).isGreaterThan(0);
}
Also used : PaymentId(de.metas.payment.PaymentId) BankStatementLineRow(de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow) PaymentToReconcileRow(de.metas.ui.web.bankstatement_reconciliation.PaymentToReconcileRow) I_ESR_ImportLine(de.metas.payment.esr.model.I_ESR_ImportLine) Test(org.junit.jupiter.api.Test)

Example 4 with BankStatementLineRow

use of de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow in project metasfresh-webui-api by metasfresh.

the class ReconcilePaymentsCommandTest method bankStatementLineIsLinkedToPaySelection.

@Test
public void bankStatementLineIsLinkedToPaySelection() {
    final BankStatementLineRow bankStatementLineRow = bankStatementLineRow().docStatus(DocStatus.Drafted).statementAmt(euro("1000")).build();
    final PaymentToReconcileRow paymentRow = paymentRow().inboundPayment(true).customerId(customerId).paymentAmt(euro("1000")).build();
    final PaymentId paymentId = paymentRow.getPaymentId();
    final PaySelectionId paySelectionId = createPaySelection();
    final I_C_PaySelectionLine paySelectionLine = createPaySelectionLine(paySelectionId, paymentId);
    assertThat(paySelectionLine.getC_Payment_ID()).isEqualTo(paymentId.getRepoId());
    assertThat(paySelectionLine.getC_BankStatement_ID()).isLessThanOrEqualTo(0);
    assertThat(paySelectionLine.getC_BankStatementLine_ID()).isLessThanOrEqualTo(0);
    assertThat(paySelectionLine.getC_BankStatementLine_Ref_ID()).isLessThanOrEqualTo(0);
    assertReconciled(paySelectionId).isFalse();
    executeReconcilePaymentsCommand(ReconcilePaymentsRequest.builder().selectedBankStatementLine(bankStatementLineRow).selectedPaymentToReconcile(paymentRow).build());
    InterfaceWrapperHelper.refresh(paySelectionLine);
    assertThat(paySelectionLine.getC_BankStatement_ID()).isGreaterThan(0);
    assertThat(paySelectionLine.getC_BankStatementLine_ID()).isEqualTo(bankStatementLineRow.getBankStatementLineId().getRepoId());
    assertThat(paySelectionLine.getC_BankStatementLine_Ref_ID()).isGreaterThan(0);
    assertReconciled(paySelectionId).isTrue();
}
Also used : PaymentId(de.metas.payment.PaymentId) PaySelectionId(de.metas.banking.PaySelectionId) BankStatementLineRow(de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow) PaymentToReconcileRow(de.metas.ui.web.bankstatement_reconciliation.PaymentToReconcileRow) I_C_PaySelectionLine(org.compiere.model.I_C_PaySelectionLine) Test(org.junit.jupiter.api.Test)

Example 5 with BankStatementLineRow

use of de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow in project metasfresh-webui-api by metasfresh.

the class ReconcilePaymentsCommand method computeBankStatementLineReconcileRequest.

private ExplainedOptional<BankStatementLineMultiPaymentLinkRequest> computeBankStatementLineReconcileRequest() {
    final BankStatementLineRow bankStatementLineRow = request.getSelectedBankStatementLine();
    if (bankStatementLineRow == null) {
        return ExplainedOptional.emptyBecause("no bank statement line selected");
    }
    if (bankStatementLineRow.isReconciled()) {
        return ExplainedOptional.emptyBecause("bank statement line was already reconciled");
    }
    final List<PaymentToReconcileRow> paymentRows = request.getSelectedPaymentsToReconcile();
    if (paymentRows.isEmpty()) {
        return ExplainedOptional.emptyBecause("no payment rows selected");
    }
    final Amount statementLineAmt = bankStatementLineRow.getStatementLineAmt();
    final CurrencyCode currencyCode = statementLineAmt.getCurrencyCode();
    Amount statementLineAmtReconciled = Amount.zero(currencyCode);
    final ArrayList<PaymentToLink> paymentsToReconcile = new ArrayList<>();
    for (final PaymentToReconcileRow paymentRow : paymentRows) {
        if (paymentRow.isReconciled()) {
            return ExplainedOptional.emptyBecause("Payment `" + paymentRow.getDocumentNo() + "` was already reconciled");
        }
        final Amount payAmt = paymentRow.getPayAmtNegateIfOutbound();
        if (!payAmt.getCurrencyCode().equals(currencyCode)) {
            return ExplainedOptional.emptyBecause("Payment `" + paymentRow.getDocumentNo() + "` shall be in `" + currencyCode + "` instead of `" + payAmt.getCurrencyCode() + "`");
        }
        statementLineAmtReconciled = statementLineAmtReconciled.add(payAmt);
        paymentsToReconcile.add(PaymentToLink.builder().paymentId(paymentRow.getPaymentId()).statementLineAmt(payAmt).build());
    }
    final Amount statementLineAmtToReconcile = statementLineAmt.subtract(statementLineAmtReconciled);
    if (!statementLineAmtToReconcile.isZero()) {
        return ExplainedOptional.emptyBecause(msgBL.getTranslatableMsgText(MSG_StatementLineAmtToReconcileIs, statementLineAmtToReconcile));
    }
    return ExplainedOptional.of(BankStatementLineMultiPaymentLinkRequest.builder().bankStatementLineId(bankStatementLineRow.getBankStatementLineId()).paymentsToLink(paymentsToReconcile).build());
}
Also used : CurrencyCode(de.metas.currency.CurrencyCode) PaymentToLink(de.metas.banking.payment.BankStatementLineMultiPaymentLinkRequest.PaymentToLink) Amount(de.metas.currency.Amount) ArrayList(java.util.ArrayList) BankStatementLineRow(de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow) PaymentToReconcileRow(de.metas.ui.web.bankstatement_reconciliation.PaymentToReconcileRow)

Aggregations

BankStatementLineRow (de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow)5 PaymentToReconcileRow (de.metas.ui.web.bankstatement_reconciliation.PaymentToReconcileRow)4 PaymentId (de.metas.payment.PaymentId)2 Test (org.junit.jupiter.api.Test)2 PaySelectionId (de.metas.banking.PaySelectionId)1 BankStatementLineMultiPaymentLinkRequest (de.metas.banking.payment.BankStatementLineMultiPaymentLinkRequest)1 PaymentToLink (de.metas.banking.payment.BankStatementLineMultiPaymentLinkRequest.PaymentToLink)1 Amount (de.metas.currency.Amount)1 CurrencyCode (de.metas.currency.CurrencyCode)1 I_ESR_ImportLine (de.metas.payment.esr.model.I_ESR_ImportLine)1 ViewRowIdsSelection (de.metas.ui.web.view.ViewRowIdsSelection)1 ArrayList (java.util.ArrayList)1 I_C_PaySelectionLine (org.compiere.model.I_C_PaySelectionLine)1