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);
}