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();
}
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;
}
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);
}
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();
}
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());
}
Aggregations