Cash Book Receipts, getting the InvRemitNo  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Cash Book Receipts, getting the InvRemitNo

Postby DannyC » Mon Mar 06, 2023 4:19 pm

When a cash book receipt is done for a debtor transaction, the users allocate the receipt to whatever invoice is relevant.

I know that the CashBookTransaction has a property, Allocations - which is a collection of allocation records - the allocation has a property, DebtorCreditorTransactionKey - which is the index key into the DebtorTransactions.

I assume that is how I can get the InvRemitNo(s) for the allocated invoices?

I can't work out the syntax to use the DebtorCreditorTransactionKey.
And can't see which event is the most applicable?
Would it be
Code: Select all
cashbkRctsForm.CashBook.CashBookTransactions.Changed

or
Code: Select all
cashbkRctsForm.CashBook.CashBookTransactions.AllocationChanged


My goal is to get all the allocated invoices listed (just a comma or space separated string is fine) in the Remark property, therefore when the cash book is activated that remark should flow through to the debtor trans. Credit pane.

EDIT: So I have nutted out the attached plugin.
It almost works but when I have a multi line receipt batch, different debtors on each row, the allocated invoices from every row populates.
Attachments
Plugin Cash Book Allocated Invoices.xml
(25.82 KiB) Downloaded 52 times
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Cash Book Receipts, getting the InvRemitNo

Postby SBarnes » Mon Mar 06, 2023 7:06 pm

If at the end of the day you are trying to save it to the cashbook tables why couldn't you do this, and if you have the right property the below code will get you the trans ids you would just need to convert it to invoice numbers where I have commented


Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
      if (JiwaForm is JiwaFinancials.Jiwa.JiwaCashBookUI.frmCashBookReceipts)
      {
         JiwaFinancials.Jiwa.JiwaCashBookUI.frmCashBookReceipts cashbkRctsForm = (JiwaFinancials.Jiwa.JiwaCashBookUI.frmCashBookReceipts )JiwaForm;
         cashbkRctsForm.CashBook.SaveStart +=  delegate (object sender, EventArgs e)
         {
            foreach(JiwaFinancials.Jiwa.JiwaCashBook.CashBookTransaction trans in cashbkRctsForm.CashBook.CashBookTransactions)
            {
               List<string> AllocKeys = new List<string>();
               foreach(JiwaFinancials.Jiwa.JiwaCashBook.Allocation alloc in trans.Allocations)
               {
   
                  AllocKeys.Add(alloc.DebtorCreditorTransactionKey);
                  
                  
               }
               
               //You now have all the trans ids for the allocations so look up the inv remit nos
            }
         };
      }
    }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Cash Book Receipts, getting the InvRemitNo

Postby DannyC » Mon Mar 06, 2023 9:53 pm

at the end of the day you are trying to save it to the cashbook tables why couldn't you do this


I could and I was about to do it much like you suggest, but I figure it's better for the user to see it in the grid before saving.
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Cash Book Receipts, getting the InvRemitNo

Postby SBarnes » Tue Mar 07, 2023 9:55 am

Then I suggest you take a look at DoAllocations in the form that is what is driving it the code is below as it does more that just change it.


Code: Select all
public void DoAllocations(string CashBookTranKey, CashBook.CashBookAllocationTypes AllocationType)
        {
            clsAllocatedTransaction current;
            IEnumerator enumerator = null;
            IEnumerator enumerator1 = null;
            object[] cashBookTranKey = new object[] { this._CashBook, CashBookTranKey, AllocationType, this };
            frmAllocations frmAllocation = (frmAllocations)this.Manager.StartDialog(20, cashBookTranKey, this, "");
            if (frmAllocation.ShowDialog(this) == DialogResult.OK)
            {
                if (!this._CashBook.Activated)
                {
                    try
                    {
                        enumerator = frmAllocation.AllocatedTransactionCollection.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            current = (clsAllocatedTransaction)enumerator.Current;
                            if (Strings.Trim(current.CashBook_AllocationKey).Trim().Length > 0)
                            {
                                this._CashBook.CashBookTransactions[CashBookTranKey].Allocations[current.CashBook_AllocationKey].AllocatedAmount = decimal.Zero;
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator is IDisposable)
                        {
                            (enumerator as IDisposable).Dispose();
                        }
                    }
                    int count = frmAllocation.AllocatedTransactionCollection.RemovedAllocations.Count;
                    for (int i = 1; i <= count; i = checked(i + 1))
                    {
                        this._CashBook.CashBookTransactions[CashBookTranKey].Allocations.Remove(this._CashBook.CashBookTransactions[CashBookTranKey].Allocations[i]);
                    }
                    try
                    {
                        enumerator1 = frmAllocation.AllocatedTransactionCollection.GetEnumerator();
                        while (enumerator1.MoveNext())
                        {
                            current = (clsAllocatedTransaction)enumerator1.Current;
                            if (Operators.CompareString(Strings.Trim(current.CashBook_AllocationKey), "", false) == 0)
                            {
                                if (decimal.Compare(current.ThisAllocationAmount, decimal.Zero) != 0)
                                {
                                    this._CashBook.AddAllocation(CashBookTranKey, current.CashBook_DebtorCreditorTransactionKey, current.ThisAllocationAmount, AllocationType);
                                }
                            }
                            else if (decimal.Compare(current.ThisAllocationAmount, decimal.Zero) == 0)
                            {
                                this._CashBook.CashBookTransactions[CashBookTranKey].Allocations.Remove(this._CashBook.CashBookTransactions[CashBookTranKey].Allocations[current.CashBook_AllocationKey]);
                            }
                            else
                            {
                                this._CashBook.CashBookTransactions[CashBookTranKey].Allocations[current.CashBook_AllocationKey].AllocatedAmount = current.ThisAllocationAmount;
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator1 is IDisposable)
                        {
                            (enumerator1 as IDisposable).Dispose();
                        }
                    }
                }
            }
        }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Cash Book Receipts, getting the InvRemitNo  Topic is solved

Postby DannyC » Tue Mar 07, 2023 3:47 pm

I gave up trying to use the cashbook objects. Spent too long on this wretched plugin.

Instead I ended up using SQL firing from the SaveEnd event.

Final plugin attached for anyone who cares to peruse.
Attachments
Plugin Cash Book Allocated Invoices.xml
(28.48 KiB) Downloaded 55 times
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Cash Book Receipts, getting the InvRemitNo

Postby SBarnes » Tue Mar 07, 2023 4:01 pm

Um WriteInvoices is kind of redundant given you have the cashbookTrans right there, you could also wait until the end of looping and call save on the collection as it would mean you would be using the Jiwa objects to actually update the the Jiwa tables.

You would just need to detach you handler and then reattach it but that's easy.

I always avoid writing to the Jiwa tables with direct SQL for data integrity reasons.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Cash Book Receipts, getting the InvRemitNo

Postby DannyC » Wed Mar 08, 2023 7:56 am

I always avoid writing to the Jiwa tables with direct SQL for data integrity reasons.


So do I.

The problem with the cashbook object is that the allocations from the previous line would somehow be kept on the current line.
That is where I spent the bulk of my time - trying to eliminate irrelevant data from irrelevant lines. If you can write a plugin using the objects, go for it.

In the end I basically gave up. Once I know the Save is done (and therefore data is in SQL) then I can just pull the required info and write it where I need to.
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 22 guests

cron