Ledger Generation

Discussions related to custom development with Select.
Post Reply
lukewautier
Posts: 9
Joined: Tue May 11, 2021 4:53 pm

Ledger Generation

Post by lukewautier » Wed May 12, 2021 9:42 am

I'm attempting to create an standalone application to automate ledger generation on a monthly basis. I'm using the code snippet below and am encountering an error on the the ledger creation routine:

Operation is not valid due to the current state of the object.
SoftPro.Accounting.Client.Ledgers.LedgersManager.SoftPro.Accounting.Client.Ledgers.ILedgersManager.NewLedger[T](ITrustAccountInfo trustAccount, String name, Object[] args)


Permissions appear okay, although I'm open to suggestions, and I can create a ledger fine manually when logging into this account.

Code: Select all

                //setup your softpro credentials
                NetworkCredential MyCredentials = new NetworkCredential(strUsername, strPassword, "[SERVER]");
                // Log into mid-tier with Windows credentials.
                using (SelectServer ss = new SelectServer(new Uri("http://amzkbtspapp01:8081"), MyCredentials))
                {
                    string reason;

                    if (!ss.TryAuthenticate(out reason))
                    {
                        Console.WriteLine(reason);
                        return;
                    }

                    string IDName = "Luke Wautier";
                    string TAName = "TEST - WI";
                    
                    //setup the security manager
                    ISecurityManager sm = ss.GetService<ISecurityManager>();
                    //find craig's identity 
                    ISecurityIdentity ResParty = sm.Identities.Where(v => v.FullName == IDName).FirstOrDefault();
                   
                    //setup the account manager
                    IAccountsManager am = ss.GetService<IAccountsManager>();
                    //search for the account on this order
                    ITrustAccountInfo MatchedAccount = am.TrustAccounts.Where(t => t.Code == TAName).FirstOrDefault();

                    //setup the ledger manager
                    ILedgersManager lm = ss.GetService<ILedgersManager>();
                    
                    //create the base ledger 
                    ILedger automatedLedger = lm.NewLedger<ILedger>(MatchedAccount, "TEST Ledger");
                    //apply all changes to the ledger
                    lm.ApplyChanges(automatedLedger);

                    //change the kind to revenue
                    lm.ChangeLedgerKind(automatedLedger.ToInfo(), LedgerKind.Revenue);
                    //apply all changes to the ledger
                    lm.ApplyChanges(automatedLedger);

                    //update any further details
                    automatedLedger.Comment = "First test of the automated ledger generation.";
                    automatedLedger.ResponsibleParty = ResParty;
                    automatedLedger.ThreeWayReconciliation = ThreeWayReconciliationKind.Guaranty;
                    //apply all changes to the ledger
                    lm.ApplyChanges(automatedLedger);
                    
                }

BobRichards
Posts: 1121
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Ledger Generation

Post by BobRichards » Wed May 12, 2021 10:46 am

When you create a new ledger, you are expected to pass the specific type of ledger desired and the method will create it and pass it back. I have modified part of your code to create a revenue ledger. The possible options are:
  • IFeeLedger
  • IRevenueLedger
  • ITransferLedger
  • IOrderLedger (will need to pass order guid as string in args list)

Code: Select all

//setup the ledger manager
ILedgersManager lm = ss.GetService<ILedgersManager>();

// Create new ledger options:
//    IFeeLedger
//    IRevenueLedger
//    ITransferLedger
IRevenueLedger automatedLedger = lm.NewLedger<IRevenueLedger>(MatchedAccount, "TEST Ledger");
//apply all changes to the ledger
lm.ApplyChanges(automatedLedger);

//update any further details
automatedLedger.Comment = "First test of the automated ledger generation.";
automatedLedger.ResponsibleParty = ResParty;
automatedLedger.ThreeWayReconciliation = ThreeWayReconciliationKind.Guaranty;
//apply all changes to the ledger
lm.ApplyChanges(automatedLedger);
Bob Richards, Senior Software Developer, SoftPro

lukewautier
Posts: 9
Joined: Tue May 11, 2021 4:53 pm

Re: Ledger Generation

Post by lukewautier » Wed May 12, 2021 10:53 am

Worked beautifully, thanks so much for the assist Bob!

lukewautier
Posts: 9
Joined: Tue May 11, 2021 4:53 pm

Re: Ledger Generation

Post by lukewautier » Thu Sep 23, 2021 11:20 am

Hey Bob,

I have hit a little snag and I could use some guidance. When generating ledgers via the SDK I'm noticing that the following ledger property is not added, whereas this is always auto generated when creating a new ledger manually.

Image

This is causing issues with our book balance report that uses an inner join on the ledger properties, therefore excluding the auto-generated holding ledgers from report, creating what looks to be an imbalance.

Do you have any suggestions on why this property is not getting generated and how I can go about remedying this?

Thanks!

lukewautier
Posts: 9
Joined: Tue May 11, 2021 4:53 pm

Re: Ledger Generation

Post by lukewautier » Thu Sep 23, 2021 12:16 pm

As a follow up, I see that a tag is most likely needed to set this property:

Image

Can you confirm this diagnosis and let me know if it is standard to apply any other tags or meta information when creating a ledger?

BobRichards
Posts: 1121
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Ledger Generation

Post by BobRichards » Thu Sep 23, 2021 3:43 pm

Please send me the code you use to create a ledger. You would hope the API would do the heavy lifting but that is certainly not always the case.
Bob Richards, Senior Software Developer, SoftPro

Post Reply