/// <summary> /// Set Statement Line /// </summary> /// <param name="payment">Payment</param> /// <returns>Message</returns> public string SetPayments(MPayment payment) { SetC_Payment_ID(payment.GetC_Payment_ID()); //SetC_Currency_ID(payment.GetC_Currency_ID()); Decimal amt = payment.GetPayAmt(true); //Currency Conversion to BankStatementLine Currency if (GetC_Currency_ID() != payment.GetC_Currency_ID()) { int conversionType = Get_ColumnIndex("C_ConversionType_ID") > 0 ? Get_ValueAsInt("C_ConversionType_ID") : payment.GetC_ConversionType_ID(); amt = MConversionRate.Convert(GetCtx(), amt, payment.GetC_Currency_ID(), GetC_Currency_ID(), GetValutaDate(), conversionType, GetAD_Client_ID(), GetAD_Org_ID()); } if (amt != 0) { SetTrxAmt(amt); if (GetStmtAmt() == 0) { SetStmtAmt(amt); } else // Incase of Uncociled StatementLine have existing Amount { decimal _diffAmt = GetStmtAmt() - GetTrxAmt(); SetChargeAmt(_diffAmt - GetInterestAmt()); } SetDescription(payment.GetDescription()); } else { return(Msg.GetMsg(GetCtx(), "NoCurrencyConversion")); } //Set VA012_VoucherType if (Env.IsModuleInstalled("VA012_")) { bool _IsPaymentAllocate = false; int _InvCount; //When Payment have Multiple InvoicePaySchedules if (payment.Get_ColumnIndex("IsPaymentAllocate") > 0) { _IsPaymentAllocate = Util.GetValueOfBool(payment.Get_Value("IsPaymentAllocate")); } if (_IsPaymentAllocate) { _InvCount = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(C_PaymentAllocate_ID) FROM C_PaymentAllocate WHERE IsActive='Y' AND C_Payment_ID=" + payment.GetC_Payment_ID(), null, null)); } else { _InvCount = payment.GetC_Invoice_ID(); } if (_InvCount > 0 || payment.GetC_Order_ID() > 0) { SetVA012_VoucherType("M"); // 'M' indicates VA012_VoucherType as Payment } else if (payment.GetC_Charge_ID() > 0) { SetVA012_VoucherType("V"); // 'V' indicates VA012_VoucherType as Voucher } } return(""); }
/// <summary> /// Set Payment /// </summary> /// <param name="payment">Payment</param> public void SetPayment(MPayment payment) { SetC_Payment_ID(payment.GetC_Payment_ID()); SetC_Currency_ID(payment.GetC_Currency_ID()); Decimal amt = payment.GetPayAmt(true); SetTrxAmt(amt); SetStmtAmt(amt); SetDescription(payment.GetDescription()); }
/// <summary> /// Set Payment /// </summary> /// <param name="payment"></param> public void SetPayment(MPayment payment) { _payment = payment; if (payment != null) { _C_CurrencyFrom_ID = payment.GetC_Currency_ID(); SetAmt(payment.GetPayAmt()); // need to reverse SetOpenAmt(GetAmt()); // not correct SetConvertedAmt(MConversionRate.Convert(GetCtx(), GetOpenAmt(), GetC_CurrencyFrom_ID(), GetC_CurrencyTo_ID(), GetAD_Client_ID(), GetAD_Org_ID())); } else { _C_CurrencyFrom_ID = 0; SetAmt(Env.ZERO); SetConvertedAmt(Env.ZERO); } }
/// <summary> /// Create Payment for Import /// </summary> /// <param name="ibs">import bank statement</param> /// <returns></returns> private String CreatePayment(X_I_BankStatement ibs) { if (ibs == null || ibs.GetC_Payment_ID() != 0) { return("--"); } log.Fine(ibs.ToString()); if (ibs.GetC_Invoice_ID() == 0 && ibs.GetC_BPartner_ID() == 0) { throw new Exception("@NotFound@ @C_Invoice_ID@ / @C_BPartner_ID@"); } if (ibs.GetC_BankAccount_ID() == 0) { throw new Exception("@NotFound@ @C_BankAccount_ID@"); } // MPayment payment = CreatePayment(ibs.GetC_Invoice_ID(), ibs.GetC_BPartner_ID(), ibs.GetC_Currency_ID(), ibs.GetStmtAmt(), ibs.GetTrxAmt(), ibs.GetC_BankAccount_ID(), Utility.Util.GetValueOfDateTime(ibs.GetStatementLineDate() == null ? ibs.GetStatementDate() : ibs.GetStatementLineDate()), Utility.Util.GetValueOfDateTime(ibs.GetDateAcct()), ibs.GetDescription(), ibs.GetAD_Org_ID(), 0, 0); //Used Zero's as parameters to Avoid throw Error if (payment == null) { throw new SystemException("Could not create Payment"); } ibs.SetC_Payment_ID(payment.GetC_Payment_ID()); ibs.SetC_Currency_ID(payment.GetC_Currency_ID()); ibs.SetTrxAmt(payment.GetPayAmt()); ibs.Save(); // String retString = "@C_Payment_ID@ = " + payment.GetDocumentNo(); if (Env.Signum(payment.GetOverUnderAmt()) != 0) { retString += " - @OverUnderAmt@=" + payment.GetOverUnderAmt(); } return(retString); }
} // doIt /// <summary> /// Write Off /// </summary> /// <param name="C_Invoice_ID"></param> /// <param name="DocumentNo"></param> /// <param name="DateInvoiced"></param> /// <param name="C_Currency_ID"></param> /// <param name="OpenAmt"></param> /// <returns>true if written off</returns> private Boolean writeOff(int C_Invoice_ID, String DocumentNo, DateTime?DateInvoiced, int C_Currency_ID, Decimal OpenAmt) { // Nothing to do if (Env.Signum(OpenAmt) == 0) { return(false); } if (Math.Abs(OpenAmt).CompareTo(_MaxInvWriteOffAmt) >= 0) { return(false); } // if (_IsSimulation) { AddLog(C_Invoice_ID, DateInvoiced, OpenAmt, DocumentNo); return(true); } // Invoice MInvoice invoice = new MInvoice(GetCtx(), C_Invoice_ID, Get_TrxName()); if (!invoice.IsSOTrx()) { OpenAmt = Decimal.Negate(OpenAmt); } // Allocation if (_m_alloc == null || C_Currency_ID != _m_alloc.GetC_Currency_ID()) { ProcessAllocation(); _m_alloc = new MAllocationHdr(GetCtx(), true, _DateAcct, C_Currency_ID, GetProcessInfo().GetTitle() + " #" + GetAD_PInstance_ID(), Get_TrxName()); _m_alloc.SetAD_Org_ID(invoice.GetAD_Org_ID()); if (!_m_alloc.Save()) { log.Log(Level.SEVERE, "Cannot create allocation header"); return(false); } } // Payment if (_CreatePayment && (_m_payment == null || invoice.GetC_BPartner_ID() != _m_payment.GetC_BPartner_ID() || C_Currency_ID != _m_payment.GetC_Currency_ID())) { ProcessPayment(); _m_payment = new MPayment(GetCtx(), 0, Get_TrxName()); _m_payment.SetAD_Org_ID(invoice.GetAD_Org_ID()); _m_payment.SetC_BankAccount_ID(_C_BankAccount_ID); _m_payment.SetTenderType(MPayment.TENDERTYPE_Check); _m_payment.SetDateTrx(_DateAcct); _m_payment.SetDateAcct(_DateAcct); _m_payment.SetDescription(GetProcessInfo().GetTitle() + " #" + GetAD_PInstance_ID()); _m_payment.SetC_BPartner_ID(invoice.GetC_BPartner_ID()); _m_payment.SetIsReceipt(true); // payments are negative _m_payment.SetC_Currency_ID(C_Currency_ID); if (!_m_payment.Save()) { log.Log(Level.SEVERE, "Cannot create payment"); return(false); } } // Line MAllocationLine aLine = null; if (_CreatePayment) { aLine = new MAllocationLine(_m_alloc, OpenAmt, Env.ZERO, Env.ZERO, Env.ZERO); _m_payment.SetPayAmt(Decimal.Add(_m_payment.GetPayAmt(), OpenAmt)); aLine.SetC_Payment_ID(_m_payment.GetC_Payment_ID()); } else { aLine = new MAllocationLine(_m_alloc, Env.ZERO, Env.ZERO, OpenAmt, Env.ZERO); } aLine.SetC_Invoice_ID(C_Invoice_ID); if (aLine.Save()) { AddLog(C_Invoice_ID, DateInvoiced, OpenAmt, DocumentNo); return(true); } // Error log.Log(Level.SEVERE, "Cannot create allocation line for C_Invoice_ID=" + C_Invoice_ID); return(false); } // writeOff
} // allocateBPartnerAll /// <summary> /// Allocate Oldest First using Accounting currency /// </summary> /// <returns>allocations</returns> private int AllocateBPOldestFirst() { int _C_Currency_ID = MClient.Get(GetCtx()).GetC_Currency_ID(); DateTime?_dateAcct = null; // Payments Decimal _totalPayments = Env.ZERO; for (int p = 0; p < _payments.Length; p++) { MPayment _payment = _payments[p]; if (_payment.IsAllocated()) { continue; } if (_payment.GetC_Currency_ID() != _C_Currency_ID) { continue; } Decimal _allocatedAmt = Utility.Util.GetValueOfDecimal(_payment.GetAllocatedAmt()); log.Info(_payment + ", Allocated=" + _allocatedAmt); Decimal _availableAmt = Decimal.Add(Decimal.Add(Decimal.Add(_payment.GetPayAmt(), _payment.GetDiscountAmt()), _payment.GetWriteOffAmt()), _payment.GetOverUnderAmt()); if (!_payment.IsReceipt()) { _availableAmt = Decimal.Negate(_availableAmt); } log.Fine("Available=" + _availableAmt); if (_dateAcct == null || _payment.GetDateAcct() > (_dateAcct)) { _dateAcct = Utility.Util.GetValueOfDateTime(_payment.GetDateAcct()); } _totalPayments = Decimal.Add(_totalPayments, (_availableAmt)); } // Invoices Decimal _totalInvoices = Env.ZERO; for (int i = 0; i < _invoices.Length; i++) { MInvoice _invoice = _invoices[i]; if (_invoice.IsPaid()) { continue; } if (_invoice.GetC_Currency_ID() != _C_Currency_ID) { continue; } Decimal _openAmt = Utility.Util.GetValueOfDecimal(_invoice.GetOpenAmt(true, null)); log.Fine("" + _invoice); if (!_invoice.IsSOTrx()) { _openAmt = Decimal.Negate(_openAmt); } // Foreign currency log.Fine("Open=" + _openAmt); if (_dateAcct == null || _invoice.GetDateAcct() > (_dateAcct)) { _dateAcct = _invoice.GetDateAcct(); } _totalInvoices = Decimal.Add(_totalInvoices, _openAmt); } // must be either AP or AR balance if (Env.Signum(_totalInvoices) != Env.Signum(_totalPayments)) { log.Fine("Signum - Invoices=" + Env.Signum(_totalInvoices) + " <> Payments=" + Env.Signum(_totalPayments)); return(0); } Decimal _difference = Decimal.Subtract(_totalInvoices, _totalPayments); //Decimal _maxAmt = _totalInvoices.abs().min(_totalPayments.abs()); Decimal _maxAmt = Math.Min(Math.Abs(_totalInvoices), Math.Abs(_totalPayments)); if (Env.Signum(_totalInvoices) < 0) { _maxAmt = Decimal.Negate(_maxAmt); } log.Info("= Invoices=" + _totalInvoices + " - Payments=" + _totalPayments + " = Difference=" + _difference + " - Max=" + _maxAmt); // Allocate Payments up to max Decimal _allocatedPayments = Env.ZERO; for (int p = 0; p < _payments.Length; p++) { MPayment _payment = _payments[p]; if (_payment.IsAllocated()) { continue; } if (_payment.GetC_Currency_ID() != _C_Currency_ID) { continue; } Decimal _allocatedAmt = Utility.Util.GetValueOfDecimal(_payment.GetAllocatedAmt()); if (Env.Signum(_allocatedAmt) != 0) { continue; } Decimal _availableAmt = Decimal.Add(Decimal.Add(Decimal.Add(_payment.GetPayAmt(), _payment.GetDiscountAmt()), _payment.GetWriteOffAmt()), _payment.GetOverUnderAmt()); if (!_payment.IsReceipt()) { _availableAmt = Decimal.Negate(_availableAmt); } _allocatedPayments = Decimal.Add(_allocatedPayments, _availableAmt); if ((Env.Signum(_totalInvoices) > 0 && _allocatedPayments.CompareTo(_maxAmt) > 0) || (Env.Signum(_totalInvoices) < 0 && _allocatedPayments.CompareTo(_maxAmt) < 0)) { Decimal _diff = Decimal.Subtract(_allocatedPayments, _maxAmt); _availableAmt = Decimal.Subtract(_availableAmt, _diff); _allocatedPayments = Decimal.Subtract(_allocatedPayments, _diff); } log.Fine("Payment Allocated=" + _availableAmt); if (!CreateAllocation(_C_Currency_ID, "BP Oldest (" + Math.Abs(_difference) + ")", _dateAcct, _availableAmt, null, null, null, _payment.GetC_BPartner_ID(), _payment.GetC_Payment_ID(), 0, _payment.GetAD_Org_ID())) { throw new Exception("Cannot create Allocation"); } if (_allocatedPayments.CompareTo(_maxAmt) == 0) { break; } } // for all payments // Allocated Invoices up to max Decimal _allocatedInvoices = Env.ZERO; for (int i = 0; i < _invoices.Length; i++) { MInvoice _invoice = _invoices[i]; if (_invoice.IsPaid()) { continue; } if (_invoice.GetC_Currency_ID() != _C_Currency_ID) { continue; } Decimal _openAmt = Utility.Util.GetValueOfDecimal(_invoice.GetOpenAmt(true, null)); if (!_invoice.IsSOTrx()) { _openAmt = Decimal.Negate(_openAmt); } _allocatedInvoices = Decimal.Add(_allocatedInvoices, _openAmt); if ((Env.Signum(_totalInvoices) > 0 && _allocatedInvoices.CompareTo(_maxAmt) > 0) || (Env.Signum(_totalInvoices) < 0 && _allocatedInvoices.CompareTo(_maxAmt) < 0)) { Decimal _diff = Decimal.Subtract(_allocatedInvoices, _maxAmt); _openAmt = Decimal.Subtract(_openAmt, _diff); _allocatedInvoices = Decimal.Subtract(_allocatedInvoices, _diff); } if (Env.Signum(_openAmt) == 0) { break; } log.Fine("Invoice Allocated=" + _openAmt); if (!CreateAllocation(_C_Currency_ID, "BP Oldest (" + Math.Abs(_difference) + ")", _dateAcct, _openAmt, null, null, null, _invoice.GetC_BPartner_ID(), 0, _invoice.GetC_Invoice_ID(), _invoice.GetAD_Org_ID())) { throw new Exception("Cannot create Allocation"); } if (_allocatedInvoices.CompareTo(_maxAmt) == 0) { break; } } // for all invoices if (_allocatedPayments.CompareTo(_allocatedInvoices) != 0) { throw new Exception("Allocated Payments=" + _allocatedPayments + " <> Invoices=" + _allocatedInvoices); } ProcessAllocation(); return(1); } // allocateOldestFirst
} // allocateOneToOne /// <summary> /// Allocate all Payments/Invoices using Accounting currency /// </summary> /// <returns>allocations</returns> private int AllocateBPartnerAll() { int _C_Currency_ID = MClient.Get(GetCtx()).GetC_Currency_ID(); DateTime?_dateAcct = null; // Payments Decimal _totalPayments = Env.ZERO; for (int p = 0; p < _payments.Length; p++) { MPayment _payment = _payments[p]; if (_payment.IsAllocated()) { continue; } Decimal _allocatedAmt = Utility.Util.GetValueOfDecimal(_payment.GetAllocatedAmt()); // log.info("allocateBPartnerAll - " + _payment + ", Allocated=" + _allocatedAmt); if (Env.Signum(_allocatedAmt) != 0) { continue; } Decimal _availableAmt = Decimal.Add(Decimal.Add(Decimal.Add(_payment.GetPayAmt(), _payment.GetDiscountAmt()), _payment.GetWriteOffAmt()), _payment.GetOverUnderAmt()); if (!_payment.IsReceipt()) { _availableAmt = Decimal.Negate(_availableAmt); } // Foreign currency if (_payment.GetC_Currency_ID() != _C_Currency_ID) { continue; } // log.fine("allocateBPartnerAll - Available=" + _availableAmt); if (_dateAcct == null || _payment.GetDateAcct() > (_dateAcct)) { _dateAcct = _payment.GetDateAcct(); } _totalPayments = Decimal.Add(_totalPayments, _availableAmt); } // Invoices Decimal _totalInvoices = Env.ZERO; for (int i = 0; i < _invoices.Length; i++) { MInvoice _invoice = _invoices[i]; if (_invoice.IsPaid()) { continue; } // log.info("allocateBPartnerAll - " + _invoice); Decimal _openAmt = Utility.Util.GetValueOfDecimal(_invoice.GetOpenAmt(true, null)); if (!_invoice.IsSOTrx()) { _openAmt = Decimal.Negate(_openAmt); } // Foreign currency if (_invoice.GetC_Currency_ID() != _C_Currency_ID) { continue; } // log.fine("allocateBPartnerAll - Open=" + _openAmt); if (_dateAcct == null || _invoice.GetDateAcct() > (_dateAcct)) { _dateAcct = _invoice.GetDateAcct(); } _totalInvoices = Decimal.Add(_totalInvoices, _openAmt); } Decimal _difference = Decimal.Subtract(_totalInvoices, _totalPayments); log.Info("= Invoices=" + _totalInvoices + " - Payments=" + _totalPayments + " = Difference=" + _difference); if (Env.Signum(_difference) == 0) { for (int p = 0; p < _payments.Length; p++) { MPayment _payment = _payments[p]; if (_payment.IsAllocated()) { continue; } Decimal _allocatedAmt = Utility.Util.GetValueOfDecimal(_payment.GetAllocatedAmt()); if (Env.Signum(_allocatedAmt) != 0) { continue; } Decimal _availableAmt = Decimal.Add(Decimal.Add(Decimal.Add(_payment.GetPayAmt(), _payment.GetDiscountAmt()), _payment.GetWriteOffAmt()), _payment.GetOverUnderAmt()); if (!_payment.IsReceipt()) { _availableAmt = Decimal.Negate(_availableAmt); } // Foreign currency if (_payment.GetC_Currency_ID() != _C_Currency_ID) { continue; } if (!CreateAllocation(_C_Currency_ID, "BP All", _dateAcct, _availableAmt, null, null, null, _payment.GetC_BPartner_ID(), _payment.GetC_Payment_ID(), 0, _payment.GetAD_Org_ID())) { throw new Exception("Cannot create Allocation"); } } // for all payments // for (int i = 0; i < _invoices.Length; i++) { MInvoice _invoice = _invoices[i]; if (_invoice.IsPaid()) { continue; } Decimal _openAmt = Utility.Util.GetValueOfDecimal(_invoice.GetOpenAmt(true, null)); if (!_invoice.IsSOTrx()) { _openAmt = Decimal.Negate(_openAmt); } // Foreign currency if (_invoice.GetC_Currency_ID() != _C_Currency_ID) { continue; } if (!CreateAllocation(_C_Currency_ID, "BP All", _dateAcct, _openAmt, null, null, null, _invoice.GetC_BPartner_ID(), 0, _invoice.GetC_Invoice_ID(), _invoice.GetAD_Org_ID())) { throw new Exception("Cannot create Allocation"); } } // for all invoices ProcessAllocation(); return(1); } // Difference OK return(0); } // allocateBPartnerAll
} // allocateIndividualPayments /// <summary> ///Allocate Payment:Invoice 1:1 /// </summary> /// <returns>allocations</returns> private int AllocateBPOneToOne() { int _count = 0; for (int p = 0; p < _payments.Length; p++) { MPayment _payment = _payments[p]; if (_payment.IsAllocated()) { continue; } Decimal _allocatedAmt = Utility.Util.GetValueOfDecimal(_payment.GetAllocatedAmt()); log.Info(_payment + ", Allocated=" + _allocatedAmt); if (Env.Signum(_allocatedAmt) != 0) { continue; } Decimal _availableAmt = Decimal.Add(Decimal.Add(Decimal.Add(_payment.GetPayAmt() , _payment.GetDiscountAmt()) , _payment.GetWriteOffAmt()) , _payment.GetOverUnderAmt()); if (!_payment.IsReceipt()) { _availableAmt = Decimal.Negate(_availableAmt); } log.Fine("Available=" + _availableAmt); for (int i = 0; i < _invoices.Length; i++) { MInvoice _invoice = _invoices[i]; if (_invoice == null || _invoice.IsPaid()) { continue; } if (_payment.GetC_Currency_ID() == _invoice.GetC_Currency_ID()) { // log.fine("allocateBPartnerAll - " + _invoice); Decimal _openAmt = Utility.Util.GetValueOfDecimal(_invoice.GetOpenAmt(true, null)); if (!_invoice.IsSOTrx()) { _openAmt = Decimal.Negate(_openAmt); } Decimal _difference = Decimal.Subtract(_availableAmt, Math.Abs((_openAmt))); log.Fine(_invoice + ", Open=" + _openAmt + " - Difference=" + _difference); if (Env.Signum(_difference) == 0) { DateTime?_dateAcct = _payment.GetDateAcct(); if (_invoice.GetDateAcct() > _dateAcct) { _dateAcct = _invoice.GetDateAcct(); } if (!CreateAllocation(_payment.GetC_Currency_ID(), "1:1 (" + _availableAmt + ")", _dateAcct, _availableAmt, null, null, null, _invoice.GetC_BPartner_ID(), _payment.GetC_Payment_ID(), _invoice.GetC_Invoice_ID(), _invoice.GetAD_Org_ID())) { throw new Exception("Cannot create Allocation"); } ProcessAllocation(); _count++; _invoices[i] = null; // remove _invoice _payments[p] = null; _payment = null; break; } } else // Multi-Currency { } } // for all invoices } // for all payments return(_count); } // allocateOneToOne
/// <summary> /// Allocate Individual Payments with _payment references /// </summary> /// <returns>number of allocations</returns> private int allocateBPPaymentWithInfo() { int _count = 0; //**** See if there is a direct link (Invoice or Pay Selection) for (int p = 0; p < _payments.Length; p++) { MPayment _payment = _payments[p]; if (_payment.IsAllocated()) { continue; } Decimal _allocatedAmt = Utility.Util.GetValueOfDecimal(_payment.GetAllocatedAmt()); log.Info(_payment + ", Allocated=" + _allocatedAmt); if (Env.Signum(_allocatedAmt) != 0) { continue; } Decimal _availableAmt = Decimal.Add(Decimal.Add(Decimal.Add(_payment.GetPayAmt(), _payment.GetDiscountAmt()), _payment.GetWriteOffAmt()), _payment.GetOverUnderAmt()); if (!_payment.IsReceipt()) { _availableAmt = Decimal.Negate(_availableAmt); } log.Fine("Available=" + _availableAmt); // if (_payment.GetC_Invoice_ID() != 0) { for (int i = 0; i < _invoices.Length; i++) { MInvoice _invoice = _invoices[i]; if (_invoice.IsPaid()) { continue; } // log.fine("allocateIndividualPayments - " + _invoice); if (_payment.GetC_Invoice_ID() == _invoice.GetC_Invoice_ID()) { if (_payment.GetC_Currency_ID() == _invoice.GetC_Currency_ID()) { Decimal _openAmt = Utility.Util.GetValueOfDecimal(_invoice.GetOpenAmt(true, null)); if (!_invoice.IsSOTrx()) { _openAmt = Decimal.Negate(_openAmt); } log.Fine(_invoice + ", Open=" + _openAmt); // With Discount, etc. if (_availableAmt.CompareTo(_openAmt) == 0) { if (_payment.AllocateIt()) { AddLog(0, _payment.GetDateAcct(), _openAmt, _payment.GetDocumentNo() + " [1]"); _count++; } break; } } else // Mixed Currency { } } // _invoice found } // for all invoices } // _payment has _invoice else // No direct _invoice { MPaySelectionCheck psCheck = MPaySelectionCheck.GetOfPayment(GetCtx(), _payment.GetC_Payment_ID(), Get_Trx()); if (psCheck == null) { continue; } // Decimal _totalInvoice = Env.ZERO; MPaySelectionLine[] _psLines = psCheck.GetPaySelectionLines(false); for (int i = 0; i < _psLines.Length; i++) { MPaySelectionLine _line = _psLines[i]; MInvoice _invoice = _line.GetInvoice(); if (_payment.GetC_Currency_ID() == _invoice.GetC_Currency_ID()) { Decimal _invoiceAmt = Utility.Util.GetValueOfDecimal((_invoice.GetOpenAmt(true, null))); Decimal _overUnder = Decimal.Subtract(Decimal.Subtract(Decimal.Subtract(_line.GetOpenAmt(), _line.GetPayAmt()), _line.GetDiscountAmt()), _line.GetDifferenceAmt()); _invoiceAmt = Decimal.Subtract(Decimal.Subtract(Decimal.Subtract(_invoiceAmt, _line.GetDiscountAmt()), _line.GetDifferenceAmt()), _overUnder); if (!_invoice.IsSOTrx()) { _invoiceAmt = Decimal.Negate(_invoiceAmt); } log.Fine(_invoice + ", Invoice=" + _invoiceAmt); _totalInvoice = Decimal.Add(_totalInvoice, _invoiceAmt); } else // Multi-Currency { } } if (_availableAmt.CompareTo(_totalInvoice) == 0) { if (_payment.AllocateIt()) { AddLog(0, _payment.GetDateAcct(), _availableAmt, _payment.GetDocumentNo() + " [n]"); _count++; } } } // No direct _invoice } // See if there is a direct link return(_count); } // allocateIndividualPayments