Search in sources :

Example 1 with CurrencyCode

use of de.metas.currency.CurrencyCode in project metasfresh-webui-api by metasfresh.

the class BankStatementLineAndPaymentsToReconcileRepository method toPaymentToReconcileRow.

private PaymentToReconcileRow toPaymentToReconcileRow(@NonNull final I_C_Payment record, @NonNull final ImmutableSetMultimap<PaymentId, String> invoiceDocumentNosByPaymentId) {
    final CurrencyId currencyId = CurrencyId.ofRepoId(record.getC_Currency_ID());
    final CurrencyCode currencyCode = currencyRepository.getCurrencyCodeById(currencyId);
    final Amount payAmt = Amount.of(record.getPayAmt(), currencyCode);
    final PaymentId paymentId = PaymentId.ofRepoId(record.getC_Payment_ID());
    String invoiceDocumentNos = joinInvoiceDocumentNos(invoiceDocumentNosByPaymentId.get(paymentId));
    return PaymentToReconcileRow.builder().paymentId(paymentId).inboundPayment(record.isReceipt()).documentNo(record.getDocumentNo()).dateTrx(TimeUtil.asLocalDate(record.getDateTrx())).bpartner(bpartnerLookup.findById(record.getC_BPartner_ID())).invoiceDocumentNos(invoiceDocumentNos).payAmt(payAmt).reconciled(record.isReconciled()).build();
}
Also used : CurrencyCode(de.metas.currency.CurrencyCode) Amount(de.metas.currency.Amount) PaymentId(de.metas.payment.PaymentId) CurrencyId(de.metas.money.CurrencyId)

Example 2 with CurrencyCode

use of de.metas.currency.CurrencyCode in project metasfresh-webui-api by metasfresh.

the class PaymentAndInvoiceRowsRepo method prepareInvoiceToAllocateQuery.

private InvoiceToAllocateQueryBuilder prepareInvoiceToAllocateQuery(final PaymentToAllocate paymentToAllocate) {
    final CurrencyCode currencyCode = paymentToAllocate.getOpenAmt().getCurrencyCode();
    final CurrencyId currencyId = currenciesRepo.getCurrencyIdByCurrencyCode(currencyCode);
    return InvoiceToAllocateQuery.builder().bpartnerId(paymentToAllocate.getBpartnerId()).currencyId(currencyId).clientAndOrgId(paymentToAllocate.getClientAndOrgId());
}
Also used : CurrencyCode(de.metas.currency.CurrencyCode) CurrencyId(de.metas.money.CurrencyId)

Example 3 with CurrencyCode

use of de.metas.currency.CurrencyCode in project metasfresh-webui-api by metasfresh.

the class BankStatementLineAndPaymentsToReconcileRepository method extractStatementLineAmt.

private Amount extractStatementLineAmt(final I_C_BankStatementLine record) {
    final CurrencyId currencyId = CurrencyId.ofRepoId(record.getC_Currency_ID());
    final CurrencyCode currencyCode = currencyRepository.getCurrencyCodeById(currencyId);
    final Amount statementLineAmt = Amount.of(record.getStmtAmt(), currencyCode);
    return statementLineAmt;
}
Also used : CurrencyCode(de.metas.currency.CurrencyCode) Amount(de.metas.currency.Amount) CurrencyId(de.metas.money.CurrencyId)

Example 4 with CurrencyCode

use of de.metas.currency.CurrencyCode in project metasfresh-webui-api by metasfresh.

the class BoardDescriptorRepository method createBoardCardFieldDescriptor.

private final BoardCardFieldDescriptor createBoardCardFieldDescriptor(final I_WEBUI_Board_CardField cardFieldPO, final DocumentEntityDescriptor documentEntityDescriptor) {
    // TODO: might be not so performant, we just need the ColumnName
    final String fieldName = cardFieldPO.getAD_Column().getColumnName();
    final DocumentFieldDescriptor documentField = documentEntityDescriptor.getField(fieldName);
    final SqlDocumentFieldDataBindingDescriptor fieldBinding = documentField.getDataBindingNotNull(SqlDocumentFieldDataBindingDescriptor.class);
    final DocumentFieldWidgetType widgetType = documentField.getWidgetType();
    final boolean isDisplayColumnAvailable = fieldBinding.getSqlSelectDisplayValue() != null;
    final ImmutableSet<String> sqlSelectValues;
    final BoardFieldLoader fieldLoader;
    if (widgetType == DocumentFieldWidgetType.Amount && documentEntityDescriptor.hasField(WindowConstants.FIELDNAME_C_Currency_ID)) {
        sqlSelectValues = ImmutableSet.of(fieldBinding.getSqlSelectValue().toSqlStringWithColumnNameAlias(), WindowConstants.FIELDNAME_C_Currency_ID);
        fieldLoader = (rs, adLanguage) -> {
            final BigDecimal valueBD = rs.getBigDecimal(fieldBinding.getColumnName());
            if (valueBD == null) {
                return null;
            }
            final CurrencyId currencyId = CurrencyId.ofRepoIdOrNull(rs.getInt(WindowConstants.FIELDNAME_C_Currency_ID));
            if (currencyId == null) {
                return valueBD;
            }
            final CurrencyCode currencyCode = currenciesRepo.getCurrencyCodeById(currencyId);
            return Amount.of(valueBD, currencyCode);
        };
    } else {
        sqlSelectValues = ImmutableSet.of(fieldBinding.getSqlSelectValue().toSqlStringWithColumnNameAlias());
        final DocumentFieldValueLoader documentFieldValueLoader = fieldBinding.getDocumentFieldValueLoader();
        final LookupDescriptor lookupDescriptor = documentField.getLookupDescriptor().orElse(null);
        fieldLoader = (rs, adLanguage) -> documentFieldValueLoader.retrieveFieldValue(rs, isDisplayColumnAvailable, adLanguage, lookupDescriptor);
    }
    return BoardCardFieldDescriptor.builder().caption(documentField.getCaption()).fieldName(fieldBinding.getColumnName()).widgetType(widgetType).sqlSelectValues(sqlSelectValues).usingDisplayColumn(isDisplayColumnAvailable).sqlSelectDisplayValue(fieldBinding.getSqlSelectDisplayValue()).sqlOrderBy(fieldBinding.getSqlOrderBy()).fieldLoader(fieldLoader).build();
}
Also used : CurrencyCode(de.metas.currency.CurrencyCode) SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) BoardFieldLoader(de.metas.ui.web.board.BoardCardFieldDescriptor.BoardFieldLoader) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) DocumentFieldValueLoader(de.metas.ui.web.window.descriptor.sql.DocumentFieldValueLoader) ToString(lombok.ToString) ITranslatableString(de.metas.i18n.ITranslatableString) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) BigDecimal(java.math.BigDecimal) CurrencyId(de.metas.money.CurrencyId)

Example 5 with CurrencyCode

use of de.metas.currency.CurrencyCode 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

CurrencyCode (de.metas.currency.CurrencyCode)5 CurrencyId (de.metas.money.CurrencyId)4 Amount (de.metas.currency.Amount)3 PaymentToLink (de.metas.banking.payment.BankStatementLineMultiPaymentLinkRequest.PaymentToLink)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 PaymentId (de.metas.payment.PaymentId)1 BankStatementLineRow (de.metas.ui.web.bankstatement_reconciliation.BankStatementLineRow)1 PaymentToReconcileRow (de.metas.ui.web.bankstatement_reconciliation.PaymentToReconcileRow)1 BoardFieldLoader (de.metas.ui.web.board.BoardCardFieldDescriptor.BoardFieldLoader)1 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)1 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)1 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)1 DocumentFieldValueLoader (de.metas.ui.web.window.descriptor.sql.DocumentFieldValueLoader)1 SqlDocumentFieldDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor)1 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 ToString (lombok.ToString)1