I am trying to obtain the related invoice number from a billing transaction (as seen in the code below).
string BillingTransactionID = “XXXXXX”;
BillingTransaction damaged = null;
Guid ID = Guid.Parse (BillingTransactionID);
Invoice inv;
damaged = BillingTransaction.GetBillingTransaction (ID);
inv = Invoice.GetInvoice(damaged.InvoiceDateTime, damaged.CustomerID, damaged.JobSiteID, damaged.OrderID);
This does in fact return an invoice number, but not the correct one (as there are other invoices for the same customer/jobiste/order).
Looking at the data, I noticed that the problem is that the damaged.InvoiceDateTime is blank, even though there is an Invoice Date (looked directly at the database).
Is there something I am doing wrong here? Is there another way to obtain the invoice number of a billing transaction?
Please advise.
Hello Mario. Really sorry for the delay in responding. Could you give me a bit more detail on what it is you’re trying to do? It sounds like you’re trying to get the invoice number for a part that has been billed for being damaged.
Hi,
I was trying to obtain the invoice object to get some data off it, mainly the invoice date. The problem that I have found is that the invoice date on that particular billing transaction record was blank, so the invoice I am getting from the API is not the invoice that is related to the billing transaction.
Also, it seems the invoice date inside the billing transaction object defaults to the Period End invoice date and not the actual invoice date of when the billing transaction is created, which is also disconcerting.
Please advise.
Why aren’t you fetching the invoice? The invoice has a collection of product charges and you can iterate through to get the damaged charges (and sales, etc.). Also, there are properties on invoices that aren’t exposed to end-users that you can use to ignore them once they’ve already been processed so that you’re not loading all of them all the time.
I would avoid using BillingTransactions in the API (and the database FWIW). These contain the underlying data used to generate invoices and oftentimes don’t reflect what’s on an invoice. Example is a product that has a partial return, it would be split into two BillingTransactions when the invoice is created. Partial returns and other odd shipment cases can happen all over the place and you won’t know it unless you know the specifics of how our engine creates invoices.
So, overall, what is it that you’re trying to accomplish?
I am trying to integrate the damaged transactions into another system (Epicor), so that people do not have to manually create the transaction.
So for example when they bill a Return and product XYZ has was damaged A units, I create a transaction in the external system for A units at B invoice date.
This for the most part works, only that B invoice date is not accurate because it is not accurate on the BillingTransaction record.
Ah, yes, there’s a much easier way to do this.
There’s a property in the invoice that you can set that tracks if an invoice has been exported before. This is used for our file-based accounting software integration for packages that don’t have an API. I’m assuming that this is turned off for your end-users (global options, billing tab, the accounting integration should probably be blank for you).
-
Fetch a list of invoices that haven’t been exported (there’s an overload for this)
// Get Invoices
InvoiceList invoices = InvoiceList.GetInvoiceList(InvoiceExportStatus.NotExported);
-
Process the invoices, grab the data that you need, then set the field to ‘Exported’. Once it’s been set to exported then it won’t be included in fetch in step 1.
// Get the product charge
foreach (InvoiceProductCharge charge in inv.InvoiceProductChargeCollection)
{
// Determine if damaged and process
if (charge.ChargeType == BillingTransactionType.SellDamaged) // there are several of these
{
// Do something here
}
}
// Set to not exported and save
inv.ExportStatus = InvoiceExportStatus.Exported;
inv = inv.Save();
You’ll also want to write a bit of code that sets the invoices to exported that have already been processed.
Does that make sense?