logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
alzini89  
#1 Posted : Friday, November 2, 2018 8:57:14 PM(UTC)
alzini89

Rank: Newbie

Groups: Registered
Joined: 11/2/2018(UTC)
Posts: 4
United States

I am attempting to post a new AP transaction with a few line items to CenterPoint and I am receiving an error. On the post using API.TransactionPresenter.PostNewTransaction(), I receive this exception:

Index was out of range. Must be non-negative and less than the size of the collection.

For the transaction I am only assigning a company, transactiondate, datedue, and transnumber. For each line item I am assigning an account, amount, creditamount, and debitamount.

Any idea what this error message means or what I can do to post my transactions successfully?
tony  
#2 Posted : Monday, November 5, 2018 4:33:10 PM(UTC)
tony

Rank: Advanced Member

Groups: Registered
Joined: 2/28/2018(UTC)
Posts: 65
United States
Location: Pennsylvani mostly

Was thanked: 9 time(s) in 9 post(s)
Hi,

Are you sure the error is happening on the PostNewTransaction line?

I noticed from the screen print, that the company is being set to a vendor (not a company) and the vendor is not being set at all. Plus, for an AP invoice, you need to assign an AP account (although it is possible that we are taking the AP account from the vendor screen.)

Here's an example written for our BusinessSample database. In a typical accounting system, this would be considered "header" information. The Name property in this case is the vendor.

api.TransactionPresenter.Company = api.LookupId(LookupFields.Company, LookupColumns.Name, "Alpine Sports");
api.TransactionPresenter.TransactionDate = DateTime.Today; //new DateTime( 2015, 1, 1 ); // DateTime.Today;
api.TransactionPresenter.Name = api.LookupId(LookupFields.Name, LookupColumns.NamesFirstLast, "Ice Man Supplies");
api.TransactionPresenter.Account = api.LookupId(LookupFields.Account, LookupColumns.Name, "Accounts Payable - Trade");

The other part of the invoice is the detail lines. Your screen print looks pretty good to me except that you should only need to set the Amount field as the credits and debits are taken care by the post. If your collection of line items (apit.lineitems) has both credits and debits that would be a problem if, for example, one line is an expense and the next line is the offset to the A/P account. If that's the case, you don't want to try to add the A/P side at all because that's taken care of during the post. Also, usually when I see "DocAmt", it refers the amount of the whole invoice, not a line item amount. If so, that is calculated and you don't need to set it on the detail line.

But I think the place to start is to verify what line is throwing the error. If it's the post, then get the Company, Name
alzini89  
#3 Posted : Friday, November 9, 2018 4:55:04 PM(UTC)
alzini89

Rank: Newbie

Groups: Registered
Joined: 11/2/2018(UTC)
Posts: 4
United States

[img=https://imgur.com/jEOSq3K]Example Data[/img]

This is the example data I am working with. I have made adjustments per your suggestions and still receiving the error.

I am not 100% certain what you mean by "you should only need to set the Amount field as the credits and debits are taken care by the post". The numbers are not negative in the data, so how will CenterPoint know whether it's a credit/debit if I only include the amount per line? I am guessing I will have to handle when to add it into the detail line as a positive negative in response to it being a debit/credit?

Here is my current code for building the AP Item and detail lines:

For Each apit As cpAPObject In apItems
Try
With API.TransactionPresenter
.Company = API.LookupId(LookupFields.Company, LookupColumns.Name, "Ringneck Energy")
.Name = API.LookupId(LookupFields.Vendor, LookupColumns.Abbreviation, Trim(apit.vendorID))
.TransactionDate = apit.docDate
.DateDue = apit.dueDate
.TransNumber = apit.docNo
.NewTransaction(TransactionTypeTypes.ApInvoice)
For Each ln As cpLineItem In apit.lineItems
If (ln.credit <> 0) Then
.AddAccountLine(API.LookupId(LookupFields.Account, LookupColumns.AccountNumber, ln.distAcct), ln.credit)
Else
.AddAccountLine(API.LookupId(LookupFields.Account, LookupColumns.AccountNumber, ln.distAcct), ln.debit)
End If
' line.LineValues.AddReplace(InputFieldTypes.TaxAmount, ln.taxAmt)
Next
.MemoLine1 = apit.poNo
.PostNewTransaction()
End With

tony  
#4 Posted : Saturday, November 10, 2018 2:42:14 AM(UTC)
tony

Rank: Advanced Member

Groups: Registered
Joined: 2/28/2018(UTC)
Posts: 65
United States
Location: Pennsylvani mostly

Was thanked: 9 time(s) in 9 post(s)
Sorry for the delay, I lost power at my house and still don't have it back so I've gone some place with power and am using a non-development laptop to answer this (so I'm having to go by memory on some things.)

Anyway, I still see two problems:

1. .Account is still not being set. Based on your screen print, you'd need something like this: api.TransactionPresenter.Account = api.LookupId(LookupFields.Account, LookupColumns.AccountNumber, "2000-00")
2. You are adding the AP amount as a detail line. AP Invoices in CenterPoint are single entry. You enter the A/P account once along with the vendor, transaction date, TransNumber, etc. and then you enter the detail lines. You should skip all the A/P accounts in your for-loop (I'm guessing the AP account is 2000-00). The second part of that is the if ln.credit <> 0 then you should have -ln.credit

Code:

For Each ln As cpLineItem In apit.lineItems
  If ln.distAcct is not an AP account Then (I don't know enough about your system to know how'd you write this condition)
    If (ln.credit <> 0) Then
      .AddAccountLine(API.LookupId(LookupFields.Account, LookupColumns.AccountNumber, ln.distAcct), -ln.credit)
    Else
      .AddAccountLine(API.LookupId(LookupFields.Account, LookupColumns.AccountNumber, ln.distAcct), ln.debit)
    End If
  End if 
Next


Note: it looks like BBCodes work in this message board so I used the "code" to keep the indentation and stuff. Also, it looks like we only let 32,768 characters in a post - I hope you didn't run into that because I did and it pretty much said, "Hey, you've got too many characters, why don't you completely redo your post from scratch but use fewer characters this time?" which is not awesome.)

Edited by user Saturday, November 10, 2018 2:47:23 AM(UTC)  | Reason: Not specified

alzini89  
#5 Posted : Monday, November 12, 2018 4:18:20 PM(UTC)
alzini89

Rank: Newbie

Groups: Registered
Joined: 11/2/2018(UTC)
Posts: 4
United States

Oh I was unaware that I needed to set the account for the entire transaction. From the data I have, there is only 1 account field, the Dist Acct, and it differs from line to line. Can the account be looked up in some way based on defaults? Or are you confident that APs will all have the default account # of 2000-00? Or should I input each of these as a separate transaction with the account # listed?

tony  
#6 Posted : Tuesday, November 13, 2018 3:08:06 PM(UTC)
tony

Rank: Advanced Member

Groups: Registered
Joined: 2/28/2018(UTC)
Posts: 65
United States
Location: Pennsylvani mostly

Was thanked: 9 time(s) in 9 post(s)
I don't know where you are getting your data from, but, no, I don't think it would be safe to assume that 2000-00 would always be the A/P account unless you are always getting the data from a single source and it only has one A/P account.

We did see that there was an Dist Type column in the data you are getting. The values in your screen print are either 2 or 6. While I can't say what other values you might get in the column (only the people giving you the data could say), it does look like that might be indicating an account type. In fact, in CenterPoint an account type of 2 is Liabilities and 6 is Other Expenses. This might just be a coincidence, but assuming that Dist Type 2 indicates an A/P account, you could look through the apit.lineItems for the first account with Dist Type = 2 and use that in your A/P account for the invoice. Then when problems apit.lineitems, you'd want to skip all the lines with Dist Type = 2.

Again, I'm sorry for the delay, I just got my power back last night.
alzini89  
#7 Posted : Wednesday, November 14, 2018 10:29:27 PM(UTC)
alzini89

Rank: Newbie

Groups: Registered
Joined: 11/2/2018(UTC)
Posts: 4
United States

Oh it's quite alright. So an update: I was able to get the AP records to transfer correctly. I am now working on getting the General Journal Entries to transfer over. I followed the example from the TestTransactionPresenter project to add 4 lines to the GeneralJournalPresenter object, the credit/debit amounts are changing successfully, but if I try to post the transaction I receive the error "You must have at least two journal entry rows in the grid before you can continue".

I added the rows using .AddLineItem(AccountID, Amount, true/false) but the only collection that might be correct inside the GeneralJournalPresenter is "TransactionLinesKeys" which even after adding new line items still turns up with 0.

The data I am inputting are 2 different entries with 2 offsets. Do I need to ignore the offsets, I'm guessing?

Edit:

Nevermind I have figured it out. I was doing a .NewTransaction after adding the line items which was deleting the line items. Both the AP and GL entries are now showing up in CenterPoint correctly! Thanks so much for your help!

Edited by user Wednesday, November 14, 2018 10:52:40 PM(UTC)  | Reason: Not specified

Users browsing this topic
Guest (3)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.