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 (19.22 KiB) Viewed 3995 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.