Skip to content

Commit

Permalink
Add callout for C_BankStatementLine.C_Invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestPessimist committed May 4, 2020
1 parent feda50d commit 0482e08
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,66 +1,45 @@
package de.metas.banking.callout;

import java.math.BigDecimal;

/*
* #%L
* de.metas.banking.base
* %%
* Copyright (C) 2015 metas GmbH
* Copyright (C) 2020 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

import org.adempiere.ad.callout.annotations.Callout;
import org.adempiere.ad.callout.annotations.CalloutMethod;
import org.adempiere.service.ClientId;
import org.compiere.model.I_C_BankStatementLine;
import org.compiere.util.TimeUtil;
package de.metas.banking.callout;

import de.metas.banking.BankStatementLineId;
import de.metas.banking.service.IBankStatementBL;
import de.metas.currency.ConversionTypeMethod;
import de.metas.currency.CurrencyConversionContext;
import de.metas.currency.CurrencyRate;
import de.metas.currency.ICurrencyBL;
import de.metas.invoice.InvoiceId;
import de.metas.money.CurrencyId;
import de.metas.organization.OrgId;
import de.metas.util.Services;
import lombok.NonNull;
import org.adempiere.ad.callout.annotations.Callout;
import org.adempiere.ad.callout.annotations.CalloutMethod;
import org.adempiere.service.ClientId;
import org.compiere.model.I_C_BankStatementLine;
import org.compiere.util.TimeUtil;

/*
* #%L
* de.metas.banking.base
* %%
* Copyright (C) 2017 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
import java.math.BigDecimal;

@Callout(I_C_BankStatementLine.class)
public class C_BankStatementLine
Expand All @@ -72,14 +51,14 @@ private C_BankStatementLine()
}

@CalloutMethod(columnNames = I_C_BankStatementLine.COLUMNNAME_StmtAmt)
public void onStmtAmtChanged(final I_C_BankStatementLine bsl)
public void onStmtAmtChanged(final @NonNull I_C_BankStatementLine bsl)
{
final BigDecimal trxAmt = bsl.getStmtAmt();
bsl.setTrxAmt(trxAmt);
}

@CalloutMethod(columnNames = I_C_BankStatementLine.COLUMNNAME_ChargeAmt)
public void onChargeAmtChanged(final I_C_BankStatementLine bsl)
public void onChargeAmtChanged(final @NonNull I_C_BankStatementLine bsl)
{
final BigDecimal stmtAmt = bsl.getStmtAmt();
final BigDecimal trxAmt = bsl.getTrxAmt();
Expand All @@ -89,7 +68,7 @@ public void onChargeAmtChanged(final I_C_BankStatementLine bsl)
}

@CalloutMethod(columnNames = I_C_BankStatementLine.COLUMNNAME_InterestAmt)
public void onInterestAmtChanged(final I_C_BankStatementLine bsl)
public void onInterestAmtChanged(final @NonNull I_C_BankStatementLine bsl)
{
final BigDecimal stmtAmt = bsl.getStmtAmt();
final BigDecimal trxAmt = bsl.getTrxAmt();
Expand All @@ -99,7 +78,7 @@ public void onInterestAmtChanged(final I_C_BankStatementLine bsl)
}

@CalloutMethod(columnNames = I_C_BankStatementLine.COLUMNNAME_Link_BankStatementLine_ID)
public void onLink_BankStatement_IDChangedResetAmounts(final I_C_BankStatementLine bsl)
public void onLink_BankStatement_IDChangedResetAmounts(final @NonNull I_C_BankStatementLine bsl)
{
final BankStatementLineId linkedBankStatementLineId = BankStatementLineId.ofRepoIdOrNull(bsl.getLink_BankStatementLine_ID());
if (linkedBankStatementLineId == null)
Expand All @@ -110,7 +89,7 @@ public void onLink_BankStatement_IDChangedResetAmounts(final I_C_BankStatementLi

final IBankStatementBL bankStatementBL = Services.get(IBankStatementBL.class);
final ICurrencyBL currencyConversionBL = Services.get(ICurrencyBL.class);

final I_C_BankStatementLine bslFrom = bankStatementBL.getLineById(linkedBankStatementLineId);

final BigDecimal trxAmtFrom = bslFrom.getTrxAmt();
Expand All @@ -136,11 +115,24 @@ public void onLink_BankStatement_IDChangedResetAmounts(final I_C_BankStatementLi
}

@CalloutMethod(columnNames = I_C_BankStatementLine.COLUMNNAME_C_BP_BankAccountTo_ID)
public void onC_BP_BankAccountTo_IDChanged(final I_C_BankStatementLine bsl)
public void onC_BP_BankAccountTo_IDChanged(final @NonNull I_C_BankStatementLine bsl)
{
if (bsl.getC_BP_BankAccountTo_ID() <= 0)
{
bsl.setLink_BankStatementLine_ID(0);
}
}

@CalloutMethod(columnNames = I_C_BankStatementLine.COLUMNNAME_C_Invoice_ID)
public void onC_Invoice_ID_Changed(@NonNull final I_C_BankStatementLine bsl)
{
final InvoiceId invoiceId = InvoiceId.ofRepoIdOrNull(bsl.getC_Invoice_ID());
if (invoiceId == null)
{
return;
}

final IBankStatementBL bankStatementBL = Services.get(IBankStatementBL.class);
bankStatementBL.updateLineFromInvoice(bsl, invoiceId);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
package de.metas.banking.service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Set;
/*
* #%L
* de.metas.banking.base
* %%
* Copyright (C) 2020 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

import org.compiere.model.I_C_BankStatement;
import org.compiere.model.I_C_BankStatementLine;
package de.metas.banking.service;

import com.google.common.collect.ImmutableSet;

import de.metas.banking.BankStatementId;
import de.metas.banking.BankStatementLineId;
import de.metas.invoice.InvoiceId;
import de.metas.payment.PaymentId;
import de.metas.util.ISingletonService;
import lombok.NonNull;
import org.compiere.model.I_C_BankStatement;
import org.compiere.model.I_C_BankStatementLine;

import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

public interface IBankStatementBL extends ISingletonService
{
Expand Down Expand Up @@ -48,4 +69,6 @@ public interface IBankStatementBL extends ISingletonService

@NonNull
ImmutableSet<PaymentId> getLinesPaymentIds(@NonNull final BankStatementId bankStatementId);

void updateLineFromInvoice(final @NonNull I_C_BankStatementLine bsl, @NonNull InvoiceId invoiceId);
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
package de.metas.banking.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.adempiere.model.InterfaceWrapperHelper;
import org.compiere.model.I_C_BankStatement;
import org.compiere.model.I_C_BankStatementLine;
import org.compiere.model.MPeriod;
import org.compiere.model.X_C_DocType;

import com.google.common.collect.ImmutableSet;

/*
* #%L
* de.metas.banking.base
* %%
* Copyright (C) 2015 metas GmbH
* Copyright (C) 2020 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Expand All @@ -36,17 +20,34 @@
* #L%
*/

package de.metas.banking.service.impl;

import com.google.common.collect.ImmutableSet;
import de.metas.acct.api.IFactAcctDAO;
import de.metas.banking.BankStatementId;
import de.metas.banking.BankStatementLineId;
import de.metas.banking.BankStatementLineReferenceList;
import de.metas.banking.service.IBankStatementBL;
import de.metas.banking.service.IBankStatementDAO;
import de.metas.banking.service.IBankStatementListenerService;
import de.metas.invoice.InvoiceId;
import de.metas.payment.PaymentId;
import de.metas.payment.api.IPaymentBL;
import de.metas.util.Services;
import lombok.NonNull;
import org.adempiere.invoice.service.IInvoiceDAO;
import org.adempiere.model.InterfaceWrapperHelper;
import org.compiere.model.I_C_BankStatement;
import org.compiere.model.I_C_BankStatementLine;
import org.compiere.model.I_C_Invoice;
import org.compiere.model.MPeriod;
import org.compiere.model.X_C_DocType;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Set;

public class BankStatementBL implements IBankStatementBL
{
Expand Down Expand Up @@ -137,8 +138,8 @@ public BigDecimal computeStmtAmtExcludingChargeAmt(final I_C_BankStatementLine l
{
return line.getTrxAmt()
.add(line.getInterestAmt())
// .add(line.getChargeAmt())
;
// .add(line.getChargeAmt())
;
}

@Override
Expand Down Expand Up @@ -222,4 +223,15 @@ public ImmutableSet<PaymentId> getLinesPaymentIds(@NonNull final BankStatementId
return bankStatementDAO.getLinesPaymentIds(bankStatementId);
}

@Override
public void updateLineFromInvoice(final @NonNull I_C_BankStatementLine bankStatementLine, @NonNull final InvoiceId invoiceId)
{
final IInvoiceDAO invoiceDAO = Services.get(IInvoiceDAO.class);
final I_C_Invoice invoice = invoiceDAO.getByIdInTrx(invoiceId);

bankStatementLine.setC_BPartner_ID(invoice.getC_BPartner_ID());
bankStatementLine.setStmtAmt(invoice.getGrandTotal());
bankStatementLine.setTrxAmt(invoice.getGrandTotal());
}

}

0 comments on commit 0482e08

Please sign in to comment.