Skip to Content
0
Former Member
May 13, 2013 at 05:46 PM

Draw AR Down Payment to Invoice

433 Views

Hi, I have seen several threads on this topic but we are still unable to successfully post a new AR invoice from a completed Sales Order that includes Down Payments. The following code will correctly draw the data (at least it appears that way when stepping through the code), but when we attempt to post the invoice with the DP added we get the following error:

-10 - 480000045 - Down payment cannot be copied because it is already closed

Could something else need to be defined/assigned here? For context, baseDocument is a SalesOrder and in deliveryDocument is actually an Invoice.

DataTable dpInvoices = CompanyConfig.Instance.SBODatabaseConnection.ExecuteDataTableQuery(@"

select distinct DocEntry from DPI1 where BaseRef = '{0}'", baseDocument.DocEntry);


if (dpInvoices.Rows.Count > 0)

{

Documents dpDocument =

CompanyConfig.Instance.SBOConnection.SBOCompany.GetBusinessObject(BoObjectTypes.oDownPayments) as Documents;

DownPaymentsToDraw dp2d = deliveryDocument.DownPaymentsToDraw;

int dpCounter = 0;

foreach (DataRow row in dpInvoices.Rows)

{

if (!dpDocument.GetByKey(int.Parse(row["DocEntry"].ToString())))

continue;

if (dpCounter != 0)

dp2d.Add();

dp2d.SetCurrentLine(dpCounter++);

dp2d.DocEntry = dpDocument.DocEntry;

dp2d.AmountToDraw = dpDocument.DownPaymentAmount;

}

if (Marshal.IsComObject(dpDocument))

Marshal.ReleaseComObject(dpDocument);

dpDocument = null;

}

This is occurring in both 8.81 and 8.82 and we verified the DLLs are the correct version.

Many TIA...

Mike