diff --git a/Logic/Financial/PaymentGroup.cs b/Logic/Financial/PaymentGroup.cs index 8b12ba71..9e5b4fbd 100644 --- a/Logic/Financial/PaymentGroup.cs +++ b/Logic/Financial/PaymentGroup.cs @@ -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; + } + } } } diff --git a/Logic/Structure/Organization.cs b/Logic/Structure/Organization.cs index c5416fb2..f2102225 100644 --- a/Logic/Structure/Organization.cs +++ b/Logic/Structure/Organization.cs @@ -675,5 +675,10 @@ namespace Activizr.Logic.Structure } + public string IncomingPaymentTag + { + get { return "bg 451-0061 "; } // TODO: Per organization, of course + } + } } \ No newline at end of file diff --git a/Site5/App_GlobalResources/Menu5.resx b/Site5/App_GlobalResources/Menu5.resx index a65aeab3..d2007876 100644 --- a/Site5/App_GlobalResources/Menu5.resx +++ b/Site5/App_GlobalResources/Menu5.resx @@ -240,14 +240,14 @@ Account Plan + + Audit Ledgers + Balance Sheet - - Debug Bookkeeping - - - General Ledger + + Debug Ledger, Accounts Import Bank Data diff --git a/Site5/App_GlobalResources/Menu5.sv-SE.resx b/Site5/App_GlobalResources/Menu5.sv-SE.resx index 4772ea2f..9ebe523e 100644 --- a/Site5/App_GlobalResources/Menu5.sv-SE.resx +++ b/Site5/App_GlobalResources/Menu5.sv-SE.resx @@ -240,14 +240,14 @@ Kontoplan + + Granska Huvudbok + Balansräkning - - Felsök Bokföring - - - Huvudbok + + Felsök Bokföring/Reskontra Importera Bankdata diff --git a/Site5/Master-v5.master b/Site5/Master-v5.master index 552f654d..976c0a40 100644 --- a/Site5/Master-v5.master +++ b/Site5/Master-v5.master @@ -117,14 +117,13 @@ - + - - + diff --git a/Site5/Pages/v5/Ledgers/DebugLedgers.aspx b/Site5/Pages/v5/Ledgers/DebugLedgers.aspx new file mode 100644 index 00000000..14363bb7 --- /dev/null +++ b/Site5/Pages/v5/Ledgers/DebugLedgers.aspx @@ -0,0 +1,11 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="DebugLedgers.aspx.cs" Inherits="Pages_v5_Ledgers_DebugLedgers" %> + + + + + +This page is a placeholder. Accounts were automatically matched on entry to the page. + + + + diff --git a/Site5/Pages/v5/Ledgers/DebugLedgers.aspx.cs b/Site5/Pages/v5/Ledgers/DebugLedgers.aspx.cs new file mode 100644 index 00000000..9c78ec8a --- /dev/null +++ b/Site5/Pages/v5/Ledgers/DebugLedgers.aspx.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx.cs b/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx.cs index e763f463..fc23f522 100644 --- a/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx.cs +++ b/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx.cs @@ -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) {
This page is a placeholder. Accounts were automatically matched on entry to the page.