Page 1 of 1

Doing debtor allocations from spreadsheet

PostPosted: Mon Dec 07, 2020 2:56 pm
by DannyC
version 7.2.1

Scenario:
Debtor credit/payment transactions already exists with unallocated amount.
Likewise there is heaps of debit/invoices unallocated.

Client will provide a 2 column spreadsheet thus. First column is credit remitno, second column is the invoice remitno:
Code: Select all
CREDIT Remit No   InvoiceNo
payment 0001   0000327345-D01
payment 0001   0000127663-D01
payment 0001   0000127670-D01
payment 0001   0000344109-D01


I'm wanting to knock up a piece of plugin code which will read the cell value and find the credit remitno based on that value (say in my example payment 0001).
Then it reads the next cell to the right and allocates the full invoice value against the payment.
Then move to the next line & do it all over again. Up until there's no more unallocated amount on the credit/payment.

I'm having trouble finding any relevant code in Jiwa's objects to read the transaction based on the InvRemitNo, and then perform the allocation. I think the closest I can find is
Code: Select all
JiwaFinancials.Jiwa.JiwaDebtors.DebtorTransaction creditTrans = debtor.Transactions.GetItem("InvRemitNo", System.Convert.ToString(worksheet.Cells[row, 1].Value));
but I don't know the kosher syntax for GetItem.

Out of the realm of this question is how to read the spreadsheet and cells (that bit I can already do). It's just finding the transactions & allocating which I am having trouble with. I've seen a few similar questions on the forums from time to time but they seem to be related to cash book allocations. In my case, the debits and credits already exist against the debtor unallocated. I'm just looking for a speedy way to allocate payments to a large list of invoices.

Re: Doing debtor allocations from spreadsheet

PostPosted: Tue Dec 08, 2020 6:22 am
by SBarnes
There is an automatic allocation that can be done on the debtor maintenance screen which calls AutomaticAllocation on the Debtor Business Logic object, I would suggest you have a look at that.

Basically what it does is cycle over debtor transactions and looks at each credit transaction that can have money allocated to it and then looks at the debit transaction and uses them up to allocate things out.

If you want to convert the Transaction Collection to a list and use linq for the look up the following will convert the transactions to a list

Code: Select all
 List<JiwaFinancials.Jiwa.JiwaDebtors.DebtorTransaction> trans =   debtor.Transactions.Cast<JiwaFinancials.Jiwa.JiwaDebtors.DebtorTransaction>().ToList();

Re: Doing debtor allocations from spreadsheet

PostPosted: Tue Dec 08, 2020 9:12 am
by DannyC
I'd already studied the AutomaticAllocation method via JustDecompile prior to posting.
I'm mostly stuck with how to find specific transactions from the InvRemitNo.

Re: Doing debtor allocations from spreadsheet  Topic is solved

PostPosted: Thu Dec 17, 2020 8:27 pm
by Mike.Sheen
DannyC wrote:I'd already studied the AutomaticAllocation method via JustDecompile prior to posting.
I'm mostly stuck with how to find specific transactions from the InvRemitNo.


Well that's easy enough you can just iterate and look for a transaction with the InvRemitNo property matching the value you are looking for.

One way to do that is to cast our JiwaCollection and use Linq to match that - so

Code: Select all
JiwaFinancials.Jiwa.JiwaDebtors.DebtorTransaction matchedTrans = Debtor.Transactions.Cast<JiwaFinancials.Jiwa.JiwaDebtors.DebtorTransaction>().Where(x => x.CreditTransaction && x.InvRemitNo == "valueIAmLookingFor").FirstOrDefault();


in the above, we return the first credit transaction with the InvRemitNo of "valueIAmLookingFor". If it doesn't find one, then it returns null.

You can partial match using the String namespaces methods - so x.InvRemitNo.StartsWith("valueIAmLookingFor") or x.InvRemitNo.Contains("valueIAmLookingFor") and so on.

If you want to get a list of transactions matching, then just get rid of the FirstOrDefault() - and you'll have a list of matching values:

Code: Select all
var matchedTrans = Debtor.Transactions.Cast<JiwaFinancials.Jiwa.JiwaDebtors.DebtorTransaction>().Where(x => x.CreditTransaction && x.InvRemitNo == "valueIAmLookingFor");


And remember - to be able to use the Linq methods, you need to import the Linq namespace :
Code: Select all
using System.Linq;

Re: Doing debtor allocations from spreadsheet

PostPosted: Fri Dec 18, 2020 7:57 am
by SBarnes
Thanks Mike, I think between Danny and I after a discussion with the client largely have this sorted, they actually want to be able to do this with the Debtor Allocations screen which near as I can tell is using the debtor behind the scenes along with a collection of debtor transactions.