use of org.compiere.model.MDunningRunLine in project adempiere by adempiere.
the class DunningRunCreate method addFees.
// createPaymentLine
/**
* Add Fees for every line
*/
private void addFees(MDunningLevel level) {
// Only add a fee if it contains InvoiceLines and is not a statement
boolean onlyInvoices = level.isStatement();
MDunningRunEntry[] entries = m_run.getEntries(true, onlyInvoices);
if (entries != null && entries.length > 0) {
for (MDunningRunEntry element : entries) {
if (level.isShowAllDue() && level.isShowNotDue() && element.getAmt().compareTo(Env.ZERO) < 0)
// showing all the invoices and the amount of the entry is negative - don't generate a fee
continue;
MDunningRunLine line = new MDunningRunLine(element);
line.setFee(p_C_Currency_ID, level.getFeeAmt());
if (!line.save())
throw new IllegalStateException("Cannot save MDunningRunLine");
element.setQty(element.getQty().subtract(new BigDecimal(1)));
}
}
}
use of org.compiere.model.MDunningRunLine in project adempiere by adempiere.
the class DunningRunCreate method checkDunningEntry.
// addFees
/**
* Check the dunning run
* 1) Check for following Rule: ShowAll should produce only a record if at least one new line is found
*/
private void checkDunningEntry(MDunningLevel level) {
// Check rule 1)
if (level.isShowAllDue()) {
MDunningRunEntry[] entries = m_run.getEntries(true);
if (entries != null && entries.length > 0) {
for (MDunningRunEntry element : entries) {
// We start with saying we delete this entry as long as we don't find something new
boolean entryDelete = true;
MDunningRunLine[] lines = element.getLines(true);
for (int j = 0; j < lines.length; j++) {
if (lines[j].getTimesDunned() < 0) {
// We clean up the *-1 from line 255
lines[j].setTimesDunned(lines[j].getTimesDunned() * -1);
if (!lines[j].save())
throw new IllegalStateException("Cannot save MDunningRunLine");
} else {
// We found something new, so we would not save anything...
entryDelete = false;
}
}
if (entryDelete)
element.delete(false);
}
}
}
}
use of org.compiere.model.MDunningRunLine in project adempiere by adempiere.
the class DunningRunCreate method createPaymentLine.
// addPayments
/**
* Create Payment Line
* @param C_Payment_ID
* @param C_Currency_ID
* @param PayAmt
* @param OpenAmt
* @param C_BPartner_ID
* @param c_DunningLevel_ID
*/
private boolean createPaymentLine(int C_Payment_ID, int C_Currency_ID, BigDecimal PayAmt, BigDecimal OpenAmt, int C_BPartner_ID, int c_DunningLevel_ID) {
MDunningRunEntry entry = null;
try {
entry = m_run.getEntry(C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID, c_DunningLevel_ID);
} catch (BPartnerNoAddressException e) {
MPayment payment = new MPayment(getCtx(), C_Payment_ID, null);
String msg = "@Skip@ @C_Payment_ID@ " + payment.getDocumentInfo() + ", @C_BPartner_ID@ " + MBPartner.get(getCtx(), C_BPartner_ID).getName() + " @No@ @IsActive@ @C_BPartner_Location_ID@";
getProcessInfo().addLog(getProcessInfo().getAD_PInstance_ID(), null, null, msg);
return false;
}
if (entry.get_ID() == 0)
if (!entry.save())
throw new IllegalStateException("Cannot save MDunningRunEntry");
//
MDunningRunLine line = new MDunningRunLine(entry);
line.setPayment(C_Payment_ID, C_Currency_ID, PayAmt, OpenAmt);
if (!line.save())
throw new IllegalStateException("Cannot save MDunningRunLine");
return true;
}
use of org.compiere.model.MDunningRunLine in project adempiere by adempiere.
the class DunningRunCreate method createInvoiceLine.
// addInvoices
/**
* Create Invoice Line
* @param C_Invoice_ID
* @param C_Currency_ID
* @param GrandTotal
* @param Open
* @param DaysDue
* @param IsInDispute
* @param C_BPartner_ID
* @param TimesDunned
* @param DaysAfterLast
* @param c_DunningLevel_ID
*/
private boolean createInvoiceLine(int C_Invoice_ID, int C_InvoicePaySchedule_ID, int C_Currency_ID, BigDecimal GrandTotal, BigDecimal Open, int DaysDue, boolean IsInDispute, int C_BPartner_ID, int TimesDunned, int DaysAfterLast, int c_DunningLevel_ID) {
MDunningRunEntry entry = null;
try {
entry = m_run.getEntry(C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID, c_DunningLevel_ID);
} catch (BPartnerNoAddressException e) {
String msg = "@Skip@ @C_Invoice_ID@ " + MInvoice.get(getCtx(), C_Invoice_ID).getDocumentInfo() + ", @C_BPartner_ID@ " + MBPartner.get(getCtx(), C_BPartner_ID).getName() + " @No@ @IsActive@ @C_BPartner_Location_ID@";
getProcessInfo().addLog(getProcessInfo().getAD_PInstance_ID(), null, null, msg);
return false;
}
if (entry.get_ID() == 0) {
if (!entry.save())
throw new IllegalStateException("Cannot save MDunningRunEntry");
}
//
MDunningRunLine line = new MDunningRunLine(entry);
line.setInvoice(C_Invoice_ID, C_Currency_ID, GrandTotal, Open, new BigDecimal(0), DaysDue, IsInDispute, TimesDunned, DaysAfterLast);
line.setC_InvoicePaySchedule_ID(C_InvoicePaySchedule_ID);
if (!line.save())
throw new IllegalStateException("Cannot save MDunningRunLine");
return true;
}
Aggregations