Example #1
0
        public static void Run()
        {
            Organizations economyEnabledOrgs = Organizations.EconomyEnabled;

            foreach (Organization organization in economyEnabledOrgs)
            {
                FinancialTransactions unbalancedTransactions = FinancialTransactions.GetUnbalanced(organization);
                PaymentGroups         groups = PaymentGroups.ForOrganization(organization);
                FinancialAccount      assetsOutboundInvoices = organization.FinancialAccounts.AssetsOutboundInvoices;

                // This is an N^2 search. Don't care. It runs background.

                foreach (PaymentGroup group in groups)
                {
                    foreach (FinancialTransaction tx in unbalancedTransactions)
                    {
                        if (group.Open && tx.Description.EndsWith(group.Tag.Substring(4)) && tx.DateTime.Date == group.DateTime.Date && tx.Rows.AmountCentsTotal == group.AmountCents)
                        {
                            // Match!

                            tx.Dependency = group;
                            tx.AddRow(assetsOutboundInvoices, -group.AmountCents, null);
                            group.Open = false;
                        }
                    }
                }
            }
        }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        this.PageAccessRequired = new Access(this.CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Write);

        this.PageTitle = "Debug Ledgers";
        this.PageIcon  = "iconshock-tester";

        // Initialize by mapping all

        // TODO: If this O(n^2) matching becomes teh suckage, optimize using hashtables over amounts

        Payouts.AutomatchAgainstUnbalancedTransactions(this.CurrentOrganization);

        // Iterate over all open payment groups and try to map them to unbalanced transactions

        FinancialTransactions unbalancedTransactions = FinancialTransactions.GetUnbalanced(this.CurrentOrganization); // TODO: this fn should move to Organization
        PaymentGroups         openGroups             = PaymentGroups.ForOrganization(this.CurrentOrganization, false);

        foreach (PaymentGroup openGroup in openGroups)
        {
            openGroup.MapTransaction(unbalancedTransactions);
        }
    }
 protected void PopulatePaymentGroups(int organizationId)
 {
     this.GridPaymentGroups.DataSource = PaymentGroups.ForOrganization(Organization.FromIdentity(organizationId));
 }