Page 1 of 1

Cash Book Receipt. How to get the debtor?

PostPosted: Thu Aug 18, 2022 5:14 pm
by DannyC
I'm wanting to import a cash receipt batch sort of like the Bendigo Bank sample plugin but somewhat simpler.

I am adding a new line using this code from the above plugin
Code: Select all
CashBookForm.CashBook.AddNewTransaction(JiwaFinancials.Jiwa.JiwaCashBook.CashBookTransactionCollection.TransactionTypes.Other, "", ref newTransactionKey);

but really, I want it to be a debtor transaction.
The only value I am supplied with is a debtor accountno. Aside from the value, a reference/InvRemitNo and date. But key to my question is the debtor accountno.

Just not sure of the correct syntax if I use
Code: Select all
CashBookForm.CashBook.AddNewTransaction(JiwaFinancials.Jiwa.JiwaCashBook.CashBookTransactionCollection.TransactionTypes.Debtor, "", ref newTransactionKey);

(Note the difference is the transaction type).

Maybe I need to use
Code: Select all
cashBook.ReadDebtor(param, param, param and so on)

but all I can give ReadDebtor is the accountno. I know the last parameter is a bool UseDebtorAccountNoAsSeed which would be true.

I've fiddled about with a few various syntaxes but I'm stabbing in the dark and not getting anywhere.

When I go
Code: Select all
cashBook.ReadDebtor("1001", true)

I get a compile error No overload method for ReadDebtor takes 2 arguments.

Re: Cash Book Receipt. How to get the debtor?  Topic is solved

PostPosted: Thu Aug 18, 2022 5:26 pm
by Mike.Sheen
The ReadDebtor method of CashBook wants a bunch of parameters passed in by reference and it sets those.

The method definition is:
Code: Select all
Public Sub ReadDebtor(ByRef DebtorID As String, ByRef DebtorAccountNo As String, ByRef DebtorAccountName As String, ByRef PeriodType As CashBookTransactionCollection.DebtorCreditorPeriodTypes, ByRef TermsType As CashBookTransactionCollection.TermsTypes, ByRef TermsDays As Integer, ByRef CurrentBalance As Decimal, ByRef Period1Balance As Decimal, ByRef Period2Balance As Decimal, ByRef Period3Balance As Decimal, ByRef Period4Balance As Decimal, Optional ByVal UseDebtorAccountNoAsSeed As Boolean = False)


So to use that, you need to declare some variables and pass those - and in C# you need to annotate those when you pass them as ref parameters.

The hint for it is shown in the editor:
ReadDebtorMethodHint.png


So you'd need code like this:
Code: Select all
string DebtorID = null;
string DebtorAccountNo = "1001";
string DebtorAccountName = null;
JiwaFinancials.Jiwa.JiwaCashBook.CashBookTransactionCollection.DebtorCreditorPeriodTypes PeriodType = JiwaFinancials.Jiwa.JiwaCashBook.CashBookTransactionCollection.DebtorCreditorPeriodTypes.Monthly;
JiwaFinancials.Jiwa.JiwaCashBook.CashBookTransactionCollection.TermsTypes TermsType = JiwaFinancials.Jiwa.JiwaCashBook.CashBookTransactionCollection.TermsTypes.Invoice;
int TermsDays = 0;
decimal CurrentBalance = 0;
decimal Period1Balance = 0;
decimal Period2Balance = 0;
decimal Period3Balance = 0;
decimal Period4Balance = 0;

cashBook.ReadDebtor(ref DebtorID, ref DebtorAccountNo, ref DebtorAccountName, ref PeriodType, ref TermsType, ref TermsDays, ref CurrentBalance, ref Period1Balance, ref Period2Balance, ref Period3Balance, ref Period4Balance,  true);


Personally, because that looks like an old crufty awful legacy Vb3 method, I'd instead create a debtor entity and use that to get what I want - it includes all the above fields, I believe - and you can read it using the debtor account no. or debtor id.
Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Entities.Debtor.Debtor debtor = cashBook.Manager.EntityFactory.CreateEntity<JiwaFinancials.Jiwa.JiwaApplication.Entities.Debtor.Debtor>();
debtor.ReadRecordFromAccountNo("1001");

Re: Cash Book Receipt. How to get the debtor?

PostPosted: Thu Aug 18, 2022 5:47 pm
by Scott.Pearce
DannyC wrote:
Maybe I need to use
Code: Select all
cashBook.ReadDebtor(param, param, param and so on)

but all I can give ReadDebtor is the accountno. I know the last parameter is a bool UseDebtorAccountNoAsSeed which would be true.

I've fiddled about with a few various syntaxes but I'm stabbing in the dark and not getting anywhere.

When I go
Code: Select all
cashBook.ReadDebtor("1001", true)

I get a compile error No overload method for ReadDebtor takes 2 arguments.


You need to go and learn about parameter passing, i.e. what byval and byref means. And specifically, how parameters can be used as a way of *returning* values. Further, you cannot omit parameters unless they are prefixed with the *optional* keyword (in VB parlance).

Re: Cash Book Receipt. How to get the debtor?

PostPosted: Thu Aug 18, 2022 5:55 pm
by DannyC
You need to go and learn about parameter passing

Quite right!

And cheers Mike - armed with that info I reckon I can take it from here...until the next issue!

EDIT:
So it ended up being waaaay easier than using ReadDebtor.

Based on the hint to create a debtor entity, it's as simple as
Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Entities.Debtor.Debtor debtor = cashBook.Manager.EntityFactory.CreateEntity<JiwaFinancials.Jiwa.JiwaApplication.Entities.Debtor.Debtor>();
debtor.ReadRecordFromAccountNo("1001");
CashBookForm.CashBook.AddNewTransaction(JiwaFinancials.Jiwa.JiwaCashBook.CashBookTransactionCollection.TransactionTypes.Debtor, debtor.DebtorID, ref newTransactionKey);


I didn't know that the second parameter in AddNewTransaction would be the debtorID.
Anyway, all good & didn't have to use ReadDebtor.