Page 1 of 1

Changing the sales order freight GL account

PostPosted: Wed Feb 27, 2019 4:43 pm
by DannyC
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.

Re: Changing the sales order freight GL account

PostPosted: Thu Feb 28, 2019 6:33 am
by SBarnes
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?

Re: Changing the sales order freight GL account

PostPosted: Thu Feb 28, 2019 9:36 am
by DannyC
Client is running 7.0.175

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

PostPosted: Thu Feb 28, 2019 9:58 am
by Scott.Pearce
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.