Page 1 of 1

SO line Ledger override wont work

PostPosted: Wed Sep 25, 2024 11:54 pm
by Riyaz
Hi There

We have a requirement to override ledger account for SO line items if a certain criteria is met, using the attached plugin, but it wont seem to work. There is also no other plugin interference. Can you pls advise on whats wrong with this plugin. Thanks

Re: SO line Ledger override wont work

PostPosted: Thu Sep 26, 2024 10:56 am
by Mike.Sheen
My first problem was the plugin file not being able to be imported.

Some weird characters at the start of the file caused the import to fail with an error - once I removed those I could then import it.
Junk.png
Junk.png (19.22 KiB) Viewed 4003 times


Looking at your plugin, you're setting the SalesOrderLine.LedgerInventorySales.AccountNo and SalesOrderLine.LedgerInvMovement.AccountNo properties in the SalesOrder_ProcessingStart - that was a good guess to go about overriding the accounts used, but those accounts are only used for non-inventory lines on the order. For inventory items we use the accounts in the IN_Main table.

You can override the accounts the sales order processing uses, by adding a handler to the Process_JournalSetsLineAddBefore event and inspecting what type of journal line is being to the journal and setting the journal line properties then.

The Process_JournalSetsLineAddBefore event has a parameter, ProcessJournalLineType which is a bit mask of the ProcessJournalLineTypes enumeration indicating what type of journal line is being added - it can be one or more of the following values:
Code: Select all
Public Enum ProcessJournalLineTypes
   SalesOrderLine = 1
   Debtor = 2
   JobCosting = 4
   ReversePrevious = 8
   Cartage = 16
   InventorySales = 32
   InventoryMovement = 64
   InventoryValue = 128
   InventoryAssignedValue = 256
   InventoryShipComplete = 512
   Tax = 1024
   JobCostWriteOnOff = 2048
   JobCostWIP = 4096
   JobCostRevenue = 8192
   DebtorSales = 16384
   CostOfGoodsSold = 32768
End Enum


So for the inventory InventoryMovement account for a sales order line, you need to bit mask InventoryMovement AND SalesOrderLine for your comparison.

You were also calling the SalesOrder.Save inside the ProcessingStart event handler - that's a big no-no - the sales order will be saved for you when the event returns - saving it in there I'm surprised you didn't get an error because the subsequent save it performs after the event returns should fail due to the optimistic concurrency check we do in save.

You also didn't need to show a messagebox on exception - in fact that will cause issues on exception because after showing the message box you do not throw the exception so effectively you swallow any error and processing continues as though there was not a problem.

You also were performing all this in the FormPlugin class - not the business logic class - so your overriding of the journals lines would only occur when processing from the sales order entry form - other places can process sales orders and so the best place to do this is in a BusinessLogic plugin.

I've re-done your plugin (attached) using with my recommended method - I've not got any data with the same debtor classifications or GL Accounts as this plugin requires, so I was unable to test it - so there may be some issues, but I believe it should work and at least point you in the right direction and avoids all the potentially serious problems your plugin originally had.

Re: SO line Ledger override wont work

PostPosted: Thu Sep 26, 2024 10:59 am
by Riyaz
Hi Mike

Thanks heaps, will follow your instructions for future plugins as well

Re: SO line Ledger override wont work

PostPosted: Thu Sep 26, 2024 11:15 am
by Mike.Sheen
Riyaz wrote:Hi Mike

Thanks heaps, will follow your instructions for future plugins as well


You should also take a look at our Plugin Development Guidelines.

Re: SO line Ledger override wont work

PostPosted: Thu Sep 26, 2024 11:16 am
by Riyaz
Thanks Mike

Re: SO line Ledger override wont work

PostPosted: Fri Sep 27, 2024 3:08 am
by Riyaz
Hi Mike

Further to this, still having troubles setting the ledger account, but was able to drill down where to feed the values

Identified using MessageBoxes that 65 was relating to Cost of Sales, etc , and when the respective ledger account is assigned as below, it wont reflect when the Journal sets are created.

JournalSetLine.GLAccount.ReadRecordFromAccountNo("100060-15");

Re: SO line Ledger override wont work

PostPosted: Fri Sep 27, 2024 11:04 am
by Mike.Sheen
Riyaz wrote:Hi Mike

Further to this, still having troubles setting the ledger account, but was able to drill down where to feed the values

Identified using MessageBoxes that 65 was relating to Cost of Sales, etc , and when the respective ledger account is assigned as below, it wont reflect when the Journal sets are created.

JournalSetLine.GLAccount.ReadRecordFromAccountNo("100060-15");



Code: Select all
if (ProcessJournalLineType.ToString() == "65") // COGS


Yeah, don't do that. 65 is 1 AND 64 which is SalesOrderLine AND InventoryMovement from the enumeration.

As per our plugin development guidelines, you need to make your code readable and 65 means nothing to someone looking at the code, but SalesOrderLine & InventoryMovement does.

Re: SO line Ledger override wont work

PostPosted: Fri Sep 27, 2024 12:07 pm
by Riyaz
Hi Mike

Thanks, Got it, will alter the code to replace 65 with SalesOrderLine & InventoryMovement but then again the below doesnt replace the ledger, if I have a messagebox inside that if block it definitely reaches there.

JournalSetLine.GLAccount.ReadRecordFromAccountNo("100060-15");

Re: SO line Ledger override wont work  Topic is solved

PostPosted: Fri Sep 27, 2024 12:43 pm
by Mike.Sheen
Riyaz wrote:Hi Mike

Thanks, Got it, will alter the code to replace 65 with SalesOrderLine & InventoryMovement but then again the below doesnt replace the ledger, if I have a messagebox inside that if block it definitely reaches there.

JournalSetLine.GLAccount.ReadRecordFromAccountNo("100060-15");


Yeah it does.

I did find a mistake with my masking, however - I didn't cast the enum values to int and I needed to OR in some of the mask tests.

But that wouldn't have caused your problem - I chopped the plugin back to not be dependent on custom classifications or GL Accounts and ran it against Demo data and the override worked - but because of the mistake with my masking it meant EVERY line on the journal was replaced.

Attached is a fixed version which works on demo data - this is a NEW plugin with a different RecID - so don't have the old one and this one enabled in the same database.

If this works for you also on demo data, then there must be something else in your environment controlling the GL accounts on the journal - perhaps another plugin. Try copy-pasting the bitmask test conditions from this new plugin to the last one I gave you.

It's always a good idea to provide us with something we can use on demo data, as you need to remember we want to spend a bunch of time creating GL accounts and debtor classifications and the like just to get your plugin to work before we start troubleshooting it.

Re: SO line Ledger override wont work

PostPosted: Fri Sep 27, 2024 6:30 pm
by Riyaz
Thanks Mike

I think its working now, will have to make some adjustments. Thanks again