Committing bugfixes to account matching; added a template debug page

This commit is contained in:
Rick Falkvinge
2012-01-12 11:32:00 +00:00
parent 2470fc23af
commit bc9e8cc3cd
8 changed files with 109 additions and 23 deletions
+47 -8
View File
@@ -92,6 +92,7 @@ namespace Activizr.Logic.Financial
}
public bool MapTransaction()
{
// This function attempts to find a transaction that matches the payment group, a transaction that is currently unbalanced.
@@ -99,18 +100,56 @@ namespace Activizr.Logic.Financial
FinancialTransactions transactions = FinancialTransactions.GetUnbalanced(this.Organization);
string lookfor = "bg 451-0061 " + this.Tag.Substring(7); // TODO: Set string and tag start to org dependent
return this.MapTransaction(transactions);
}
public bool MapTransaction(FinancialTransactions transactions)
{
int namespaceLength = 4; // typically, transactions are tagged to be unique per year, so the year is added to tag to make unique
switch (Char.ToLowerInvariant(this.Tag[5]))
{
case 'm':
namespaceLength = 6; // unique per year and month
break;
case 'd':
namespaceLength = 8; // unique per year, month, day
break;
default:
// do nothing -- assume year, namespace length 4 as declared on init
break;
}
string lookfor = this.Tag.Substring(5 + namespaceLength).ToLowerInvariant().Trim();
int year = Int32.Parse(this.Tag.Substring(5, 4));
if (Char.IsDigit(this.Tag[0]))
{
lookfor = this.Tag.Substring(namespaceLength); // temp - remove after PPSE books closed for 2011
year = Int32.Parse(this.Tag.Substring(0, 4));
}
foreach (FinancialTransaction transaction in transactions)
{
if (transaction.Description.ToLower() == lookfor && transaction.Rows.AmountCentsTotal == this.AmountCents)
if (transaction.Description.Length >= this.Organization.IncomingPaymentTag.Length + lookfor.Length &&
transaction.Description.ToLowerInvariant().StartsWith(this.Organization.IncomingPaymentTag) &&
transaction.Description.Trim().ToLowerInvariant().EndsWith(lookfor))
{
// match!
transaction.AddRow(Organization.FinancialAccounts.AssetsOutboundInvoices, -AmountCents, null);
transaction.Dependency = this;
this.Open = false;
return true;
if (transaction.Rows.AmountCentsTotal == this.AmountCents)
{
if (transaction.DateTime.Year == year)
{
// TODO: Prep for matching month/date too, when those namespaces appear
// match!
transaction.AddRow(Organization.FinancialAccounts.AssetsOutboundInvoices, -AmountCents, null);
transaction.Dependency = this;
this.Open = false;
return true;
}
}
}
}
+5
View File
@@ -675,5 +675,10 @@ namespace Activizr.Logic.Structure
}
public string IncomingPaymentTag
{
get { return "bg 451-0061 "; } // TODO: Per organization, of course
}
}
}
+5 -5
View File
@@ -240,14 +240,14 @@
<data name="Menu5_Ledgers_AccountPlan" xml:space="preserve">
<value>Account Plan</value>
</data>
<data name="Menu5_Ledgers_AuditLedgers" xml:space="preserve">
<value>Audit Ledgers</value>
</data>
<data name="Menu5_Ledgers_BalanceSheet" xml:space="preserve">
<value>Balance Sheet</value>
</data>
<data name="Menu5_Ledgers_DebugBookkeeping" xml:space="preserve">
<value>Debug Bookkeeping</value>
</data>
<data name="Menu5_Ledgers_GeneralLedger" xml:space="preserve">
<value>General Ledger</value>
<data name="Menu5_Ledgers_DebugLedgers" xml:space="preserve">
<value>Debug Ledger, Accounts</value>
</data>
<data name="Menu5_Ledgers_ImportBankData" xml:space="preserve">
<value>Import Bank Data</value>
+5 -5
View File
@@ -240,14 +240,14 @@
<data name="Menu5_Ledgers_AccountPlan" xml:space="preserve">
<value>Kontoplan</value>
</data>
<data name="Menu5_Ledgers_AuditLedgers" xml:space="preserve">
<value>Granska Huvudbok</value>
</data>
<data name="Menu5_Ledgers_BalanceSheet" xml:space="preserve">
<value>Balansräkning</value>
</data>
<data name="Menu5_Ledgers_DebugBookkeeping" xml:space="preserve">
<value>Felsök Bokföring</value>
</data>
<data name="Menu5_Ledgers_GeneralLedger" xml:space="preserve">
<value>Huvudbok</value>
<data name="Menu5_Ledgers_DebugLedgers" xml:space="preserve">
<value>Felsök Bokföring/Reskontra</value>
</data>
<data name="Menu5_Ledgers_ImportBankData" xml:space="preserve">
<value>Importera Bankdata</value>
+2 -3
View File
@@ -117,14 +117,13 @@
<telerik:RadMenuItem runat="server" Text="XYZ Balance Sheet" Permission="All" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_BalanceSheet" />
<telerik:RadMenuItem runat="server" Text="XYZ Result Sheet" Permission="All" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_ResultSheet" />
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="3" />
<telerik:RadMenuItem runat="server" Text="XYZ General Ledger" Permission="EconomyDetail:Read" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_GeneralLedger" />
<telerik:RadMenuItem runat="server" Text="XYZ Audit Ledgers" Permission="EconomyDetail:Read" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_AuditLedgers" />
<telerik:RadMenuItem runat="server" Text="XYZ Account Plan" Permission="Economy:Read" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_AccountPlan" />
<telerik:RadMenuItem runat="server" Text="XYZ Set Budget" Permission="Economy:Read" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_SetBudgets" />
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="3" />
<telerik:RadMenuItem runat="server" Text="XYZ Import Bank Data" Permission="Economy:Write" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_ImportBankData" />
<telerik:RadMenuItem runat="server" Text="XYZ Upload Bank Files" NavigateUrl="~/Pages/v5/Ledgers/UploadBankFiles.aspx" ImageUrl="~/Images/PageIcons/iconshock-bank-16px.png" Permission="Economy:Write" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_UploadBankFiles" />
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="3" />
<telerik:RadMenuItem runat="server" Text="XYZ Debug Bookkeeping" Permission="EconomyDetail:Read" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_DebugBookkeeping" />
<telerik:RadMenuItem runat="server" Text="XYZ Debug Ledgers" NavigateUrl="~/Pages/v5/Ledgers/DebugLedgers.aspx" ImageUrl="~/Images/PageIcons/iconshock-tester-16px.png" Permission="EconomyDetail:Read" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_DebugLedgers" />
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="3" />
<telerik:RadMenuItem runat="server" Text="XYZ Payroll" Permission="Payroll:Read" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_Payroll" />
</Items>
+11
View File
@@ -0,0 +1,11 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="DebugLedgers.aspx.cs" Inherits="Pages_v5_Ledgers_DebugLedgers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
<p>This page is a placeholder. Accounts were automatically matched on entry to the page.</p>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
</asp:Content>
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Activizr.Logic.Financial;
using Activizr.Logic.Security;
public partial class Pages_v5_Ledgers_DebugLedgers : PageV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
this.PageAccessRequired = new Access(_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
// Iterate over all open payment groups and try to map them to unbalanced transactions
FinancialTransactions unbalancedTransactions = FinancialTransactions.GetUnbalanced(_currentOrganization); // TODO: this fn should move to Organization
PaymentGroups openGroups = PaymentGroups.ForOrganization(_currentOrganization, false);
foreach (PaymentGroup openGroup in openGroups)
{
openGroup.MapTransaction(unbalancedTransactions);
}
}
}
@@ -464,13 +464,13 @@ namespace Activizr.Site.Pages.Ledgers
geography.Identity, 0,
transaction.Identity, localAccount.Identity.ToString());
}
else if (row.Comment.ToLowerInvariant().StartsWith("bg 451-0061 ")) // TODO: Organization.Parameters.FinancialTrackedTransactionPrefix
else if (row.Comment.ToLowerInvariant().StartsWith(_currentOrganization.IncomingPaymentTag))
{
// Check for previously imported payment group
PaymentGroup group = PaymentGroup.FromTag(_currentOrganization,
"SEBGM" + DateTime.Today.Year.ToString() + // TODO: Get tags from org
row.Comment.Substring(11));
row.Comment.Substring(_currentOrganization.IncomingPaymentTag.Length).Trim());
if (group != null && group.Open)
{