Changing the sales order freight GL account  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Changing the sales order freight GL account

Postby DannyC » Wed Feb 27, 2019 4:43 pm

Currently when a sales order is processed the freight values from the freight grid get posted to the Debtor Freight GL account from the debtor.

I want to change the freight account based on the physical warehouse, kind of like pseudo warehouse masking.
I am using the SetupBeforeHandlers so I can intercept the debtor accounts before the sales order gets processed.
Code: Select all
    public void SetupBeforeHandlers(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
      JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm soForm = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm) JiwaForm;
      soForm.SalesOrder.ProcessingStart += ChangeDebtorFreight;
    }


Then I use the debtor entity to try to change the freight code which isn't working. It just uses the configured debtor freight GL account
Code: Select all
public void ChangeDebtorFreight(object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesOrder = (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)sender;   
   switch (salesOrder.LogicalWarehouseResidingIn.PhysicalWarehouse.Description.Trim())
      {
         case "Adelaide":
            salesOrder.Debtor.LedgerDebtorFreight.ReadRecordFromAccountNo("146000-04-00");
            break;
         case "Brisbane":
            salesOrder.Debtor.LedgerDebtorFreight.ReadRecordFromAccountNo("146000-03-00");
            break;
         case "Sydney":
            salesOrder.Debtor.LedgerDebtorFreight.ReadRecordFromAccountNo("146000-02-00");
            break;
      }
}


I thought there may be something wrong with the entity, so I used the full debtor object but that still didn't work.

Code: Select all
   public void ChangeDebtorFreight(object sender, System.EventArgs e)
   {
      JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesOrder = (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)sender;   
      JiwaFinancials.Jiwa.JiwaDebtors.Debtor debtor = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaDebtors.Debtor>(null);
      debtor.Read(salesOrder.Debtor.DebtorID);
      foreach (JiwaFinancials.Jiwa.JiwaDebtors.DebtorLedger debtorledger in debtor.DebtorLedgers)
      {
         if (debtorledger.LedgerName == "Debtor Freight")
         {
            switch (salesOrder.LogicalWarehouseResidingIn.PhysicalWarehouse.Description.Trim())
            {
               case "Adelaide":
                  debtorledger.Ledger.ReadRecordFromAccountNo("146000-04-00");
                  break;
               case "Brisbane":
                  debtorledger.Ledger.ReadRecordFromAccountNo("146000-03-00");
                  break;
               case "Sydney":
                  debtorledger.Ledger.ReadRecordFromAccountNo("146000-02-00");
                  break;
}
}
}


Can you help me with some valid code to change the debtor frieight GL account? This is for version 7.0.175, but happy to use 7.2 code & tweak it accordingly.
User avatar
DannyC
Senpai
Senpai
 
Posts: 640
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Changing the sales order freight GL account

Postby SBarnes » Thu Feb 28, 2019 6:33 am

Hi Danny,

If you are happy to use Jiwa 7.2 why not use

Code: Select all
salesorder.Process_DebtorTransactionsStart += Process_DebtorTransactionsStart;

public void Process_DebtorTransactionsStart(JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder SalesOrder, ref List<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder.DebtorTransaction> DebtorTransactions, ref List<JournalSet> JournalSets)


You've got the actual journal set, the debtor transaction and sales order which you can change right before the processing of the order is done?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1627
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 176

Re: Changing the sales order freight GL account

Postby DannyC » Thu Feb 28, 2019 9:36 am

Client is running 7.0.175
User avatar
DannyC
Senpai
Senpai
 
Posts: 640
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Changing the sales order freight GL account  Topic is solved

Postby Scott.Pearce » Thu Feb 28, 2019 9:58 am

You may have to manipulate the parent debtor ledger accounts. Here is what happens when the journal line is being produced:

Code: Select all
            ' Add the cartage 1
            JournalLine = New JiwaJournalSets.Line
            If SystemSettings.ChildDebtorsUseChildGLAccounts = True OrElse Debtor.ParentDebtor.DebtorID = "" Then
                JournalLine.GLAccount.ReadRecord(Debtor.LedgerDebtorFreight.GLLedgerID)
            Else
                JournalLine.GLAccount.ReadRecord(Debtor.ParentDebtor.LedgerDebtorFreight.GLLedgerID)
            End If


So in some cases you may need to do this:

Code: Select all
salesOrder.Debtor.ParentDebtor.LedgerDebtorFreight.ReadRecordFromAccountNo("146000-04-00");


I guess you could just do some checks on whether .ParentDebtor is nothing and just always read replacement gl accounts for both salesOrder.Debtor AND salesOrder.Debtor.ParentDebtor.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 743
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 56 guests

cron