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