SEB Bank Import debugged and operational. Deploying to import financial data to production system.
This commit is contained in:
@@ -192,7 +192,8 @@ namespace Activizr.Database
|
||||
}
|
||||
}
|
||||
|
||||
public double GetFinancialAccountBalanceTotal (int financialAccountId)
|
||||
[Obsolete("This method uses floating point for financials. Deprecated. Do not use.")]
|
||||
public double GetFinancialAccountBalanceTotal(int financialAccountId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
@@ -215,7 +216,30 @@ namespace Activizr.Database
|
||||
}
|
||||
}
|
||||
|
||||
public Int64 GetFinancialAccountBalanceDeltaCents (int financialAccountId, DateTime startDate, DateTime endDate)
|
||||
public Int64 GetFinancialAccountBalanceTotalCents(int financialAccountId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"SELECT Sum(AmountCents) FROM FinancialTransactionRows WHERE FinancialAccountId=" +
|
||||
financialAccountId + ";", connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return reader.GetInt64(0);
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unknown Account Id");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Int64 GetFinancialAccountBalanceDeltaCents(int financialAccountId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
@@ -281,6 +305,7 @@ namespace Activizr.Database
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("This method uses floating point for financials. Deprecated. Do not use.")]
|
||||
public decimal GetFinancialAccountBalanceDelta(int financialAccountId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
return GetFinancialAccountBalanceDeltaCents(financialAccountId, startDate, endDate)/100.0m;
|
||||
|
||||
@@ -16,11 +16,17 @@ namespace Activizr.Logic.Financial
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("This method uses floating point for financials. Deprecated. Do not use.")]
|
||||
public double BalanceTotal
|
||||
{
|
||||
get { return PirateDb.GetDatabase().GetFinancialAccountBalanceTotal(Identity); }
|
||||
}
|
||||
|
||||
public Int64 BalanceTotalCents
|
||||
{
|
||||
get { return PirateDb.GetDatabase().GetFinancialAccountBalanceTotalCents(Identity); }
|
||||
}
|
||||
|
||||
public static FinancialAccount FromIdentity (int identity)
|
||||
{
|
||||
return FromBasic(PirateDb.GetDatabase().GetFinancialAccount(identity));
|
||||
@@ -31,6 +37,7 @@ namespace Activizr.Logic.Financial
|
||||
return new FinancialAccount(basic);
|
||||
}
|
||||
|
||||
[Obsolete("This method uses floating point for financials. Deprecated. Do not use.")]
|
||||
public decimal GetDelta(DateTime start, DateTime end)
|
||||
{
|
||||
return PirateDb.GetDatabase().GetFinancialAccountBalanceDelta(Identity, start, end);
|
||||
@@ -53,7 +60,8 @@ namespace Activizr.Logic.Financial
|
||||
return FinancialAccountRows.FromArray(basicRows);
|
||||
}
|
||||
|
||||
public double GetBudget (int year)
|
||||
[Obsolete("This method uses floating point for financials. Deprecated. Do not use.")]
|
||||
public double GetBudget(int year)
|
||||
{
|
||||
return PirateDb.GetDatabase().GetFinancialAccountBudget(this.Identity, year);
|
||||
}
|
||||
@@ -68,7 +76,8 @@ namespace Activizr.Logic.Financial
|
||||
return PirateDb.GetDatabase().GetFinancialAccountBudgetMonthly(this.Identity, year);
|
||||
}
|
||||
|
||||
public void SetBudget (int year, double amount)
|
||||
[Obsolete("This method uses floating point for financials. Deprecated. Do not use.")]
|
||||
public void SetBudget(int year, double amount)
|
||||
{
|
||||
PirateDb.GetDatabase().SetFinancialAccountBudget(this.Identity, year, amount);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Activizr.Logic.Financial
|
||||
{
|
||||
public class ImportedBankData
|
||||
{
|
||||
public double CurrentBalance;
|
||||
public Int64 CurrentBalanceCents;
|
||||
public List<ImportedBankRow> Rows;
|
||||
}
|
||||
|
||||
public class ImportedBankRow
|
||||
{
|
||||
public DateTime DateTime;
|
||||
public string HashBase;
|
||||
public string SuppliedTransactionId;
|
||||
public Int64 CurrentBalanceCents;
|
||||
public double CurrentBalance;
|
||||
public Int64 AmountCentsNet;
|
||||
public Int64 AmountCentsGross;
|
||||
public double Fee;
|
||||
public string Comment;
|
||||
};
|
||||
}
|
||||
@@ -64,6 +64,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Financial\ImportedBankData.cs" />
|
||||
<Compile Include="Security\Accesses.cs" />
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Cache\MailTemplateCache.cs" />
|
||||
|
||||
@@ -117,6 +117,10 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="UploadBankFiles_BankScreenshot" xml:space="preserve">
|
||||
<value>Bank Screenshot</value>
|
||||
<comment>Displayed as header above modally zoomed screenshot</comment>
|
||||
</data>
|
||||
<data name="UploadBankFiles_DownloadDataSince" xml:space="preserve">
|
||||
<value></p><p>(The most recent data in Activizr in <em>{0}</em> is from {1:yyyy-MMM-dd}. You should download bank data from at least <strong>{2:yyyy-MMM-dd}.</strong>)</value>
|
||||
<comment>Displayed to help user determine scope of bank download</comment>
|
||||
@@ -130,9 +134,29 @@
|
||||
<comment>Header above instructions for generation of the bank file type selected.</comment>
|
||||
</data>
|
||||
<data name="UploadBankFiles_DownloadInstructions_SebAccountFile" xml:space="preserve">
|
||||
<value>Open SEB's internet bank. Go to <strong>your account</strong>, and enter the date span you wish to download in the search box. Press <strong>filter</strong>. After that, click the link to <strong>save the account history</strong>. A popup will appear. Choose <strong>csv</strong> and <strong>tab separated</strong>, then <strong>save</strong>. The downloaded file will be named <em>kontohandelser.csv</em>.</value>
|
||||
<value>Open SEB's internet bank. Go to <strong>your account</strong>, and enter the date span you wish to download in the search box. Press <strong>filter</strong>. After that, click the link to <strong>save the account history</strong>. A popup will appear. Choose <strong>csv</strong> and <strong>tab separated</strong>, then <strong>save</strong>. The downloaded file will be named <em>Kontohändelser.csv</em>.</value>
|
||||
<comment>Only translate to languages where SEB is active.</comment>
|
||||
</data>
|
||||
<data name="UploadBankFiles_ErrorBalance" xml:space="preserve">
|
||||
<value><p>The file contained {0:N0} transactions. <strong>{1:N0} transactions</strong> have been successfully imported into the <em>{2}</em> bookkeeping account. ({3:N0} transactions were duplicates.)</p><p><strong>However, the bank balance does not match the records in Activizr.</strong> This is usually due to missing transactions. Please upload a transaction list with a larger time span to make sure that Activizr sees all transactions.</p><p>Activizr's bookkeeping account is currently <strong>not in sync</strong> with that of the bank.</p></value>
|
||||
</data>
|
||||
<data name="UploadBankFiles_ErrorInterpretation" xml:space="preserve">
|
||||
<value><h3>The bank file could not be imported.</h3><p>This has one of three reasons: you missed some detail in the download instructions, the bank has changed its format, or you accidentally uploaded the wrong file entirely (like a photo from your last party instead of the transactions list). No transactions were imported at all. <strong>Please retry.</strong></value>
|
||||
</data>
|
||||
<data name="UploadBankFiles_FileImportedHeader" xml:space="preserve">
|
||||
<value>File Successfully Imported</value>
|
||||
<comment>Displayed as header after successful processing</comment>
|
||||
</data>
|
||||
<data name="UploadBankFiles_FileImportedHeader_ErrorBalance" xml:space="preserve">
|
||||
<value>File Imported, But Data Out Of Sync</value>
|
||||
</data>
|
||||
<data name="UploadBankFiles_ImportError" xml:space="preserve">
|
||||
<value>Error on importing file</value>
|
||||
<comment>Displayed as header on import failure</comment>
|
||||
</data>
|
||||
<data name="UploadBankFiles_ImportResults" xml:space="preserve">
|
||||
<value><p>The file contained {0:N0} transactions. <strong>{1:N0} transactions</strong> have been successfully imported into the <em>{2}</em> bookkeeping account. ({3:N0} transactions were duplicates.)</p><p>After import, the account balance in Activizr matches that of the bank.</p></value>
|
||||
</data>
|
||||
<data name="UploadBankFiles_Info" xml:space="preserve">
|
||||
<value>Here, you can upload files from your bank or payment provider into your organization's bookkeeping. Examples include account history and payments received.</value>
|
||||
<comment>Displayed in sidebar on page.</comment>
|
||||
@@ -152,6 +176,10 @@
|
||||
<value>Select Bank File Type</value>
|
||||
<comment>Header above several bank logos, prompting a selection of bank.</comment>
|
||||
</data>
|
||||
<data name="UploadBankFiles_UploadAnother" xml:space="preserve">
|
||||
<value>Upload another bank file?</value>
|
||||
<comment>Displayed as link</comment>
|
||||
</data>
|
||||
<data name="UploadBankFiles_UploadBankFile" xml:space="preserve">
|
||||
<value>Upload Bank File</value>
|
||||
<comment>Displayed as header above download instructions / upload form</comment>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.4 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
@@ -133,8 +133,12 @@ div.BankUploadInstructionsImage
|
||||
</asp:UpdatePanel>
|
||||
|
||||
<asp:Panel ID="PanelResults" Visible="false" runat="server">
|
||||
<h2><asp:Label ID="LabelProcessingResults" Text="Imported a Bank File LOC" runat="server" /></h2>
|
||||
<p>Todo...</p>
|
||||
<h2><asp:Label ID="LabelImportResultsHeader" Text="Imported a Bank File LOC" runat="server" /></h2>
|
||||
<asp:Panel ID="PanelErrorImage" Visible="false" runat="server">
|
||||
<asp:Image ImageUrl="~/Images/Icons/iconshock-cross-96px.png" ImageAlign="Left" runat="server" />
|
||||
</asp:Panel>
|
||||
<asp:Literal ID="LiteralImportResults" Text="Import Results [LOC]" runat="server" />
|
||||
<p><asp:HyperLink runat="server" NavigateUrl="UploadBankFiles.aspx" ID="LinkUploadAnother" Text="Upload Another? [LOC]" />
|
||||
</asp:Panel>
|
||||
|
||||
<div style="opacity:0;display:none" id="DivUploadProgress">
|
||||
@@ -145,7 +149,7 @@ div.BankUploadInstructionsImage
|
||||
<asp:UpdatePanel ID="PanelInstructions" UpdateMode="Conditional" runat="server">
|
||||
<ContentTemplate>
|
||||
<br/><h2><asp:Label ID="LabelUploadH2Header" Text="Upload Bank File LOC" runat="server" /></h2>
|
||||
<div style="float:right;padding-left:10px;text-align:center"><a rel="leanModal" name="ModalDownloadInstructions" id="go" href="#ModalDownloadInstructions"><asp:Image ID="ImageDownloadInstructions" ImageUrl="~/Images/Ledgers/uploadbankfiles-seb-kontoutdrag-small.png" ImageAlign="Right" runat="server" /></a><small><br style="padding-bottom:2px"/><em><asp:Label ID="LabelClickImage" runat="server" /></em></small></div>
|
||||
<div style="float:right;padding-left:10px;text-align:center;padding-top:5px"><a rel="leanModal" name="ModalDownloadInstructions" id="go" href="#ModalDownloadInstructions"><asp:Image ID="ImageDownloadInstructions" ImageUrl="~/Images/Ledgers/uploadbankfiles-seb-kontoutdrag-small.png" ImageAlign="Right" runat="server" /></a><small><br style="padding-bottom:2px"/><em><asp:Label ID="LabelClickImage" runat="server" /></em></small></div>
|
||||
<h3><asp:Label ID="LabelDownloadInstructions" Text="Download File From Bank LOC" runat="server" /></h3>
|
||||
<p><asp:Literal ID="LiteralDownloadInstructions" runat="server" Text="LOC" /><asp:Literal ID="LiteralLastAccountRecord" runat="server" /></p>
|
||||
<div style="clear:both"></div>
|
||||
@@ -172,7 +176,7 @@ div.BankUploadInstructionsImage
|
||||
<div id="ModalDownloadInstructions">
|
||||
<asp:UpdatePanel ID="PanelModalInstructions" runat="server" UpdateMode="Conditional">
|
||||
<ContentTemplate>
|
||||
<h2><asp:Label ID="LabelModalInstructionHeader" Text="Bank Screenshot" runat="server" /></h2>
|
||||
<h2><asp:Label ID="LabelModalInstructionHeader" Text="Bank Screenshot LOC" runat="server" /></h2>
|
||||
<span style="text-align:center"><asp:Image runat="server" ID="ImageDownloadInstructionsFull" /></span><br /><br /><hr /><br />
|
||||
<asp:Literal ID="LiteralDownloadInstructionsModal" runat="server" />
|
||||
</ContentTemplate>
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Activizr.Basic.Enums;
|
||||
using Activizr.Logic.Financial;
|
||||
using Activizr.Logic.Pirates;
|
||||
using Activizr.Logic.Security;
|
||||
using Activizr.Logic.Structure;
|
||||
using Telerik.Web.UI;
|
||||
using Telerik.Web.UI.Upload;
|
||||
|
||||
@@ -22,22 +28,29 @@ namespace Activizr.Site.Pages.Ledgers
|
||||
this.PageIcon = "iconshock-bank";
|
||||
this.PageAccessRequired = new Access(_currentOrganization, AccessAspect.Bookkeeping, AccessType.Write);
|
||||
|
||||
this.LabelSidebarInfo.Text = Resources.Pages.Global.Sidebar_Information;
|
||||
this.LabelSidebarActions.Text = Resources.Pages.Global.Sidebar_Actions;
|
||||
this.LabelSidebarTodo.Text = Resources.Pages.Global.Sidebar_Todo;
|
||||
this.LabelDownloadInstructions.Text = Resources.Pages.Ledgers.UploadBankFiles_DownloadInstructions;
|
||||
this.LabelClickImage.Text = Resources.Pages.Global.Global_ClickImageToEnlarge;
|
||||
if (!IsPostBack)
|
||||
{
|
||||
// Localize
|
||||
|
||||
this.LabelUploadBankFilesInfo.Text = Resources.Pages.Ledgers.UploadBankFiles_Info;
|
||||
this.LabelActionItemsHere.Text = Resources.Pages.Global.Sidebar_Todo_Placeholder;
|
||||
this.LabelSidebarInfo.Text = Resources.Pages.Global.Sidebar_Information;
|
||||
this.LabelSidebarActions.Text = Resources.Pages.Global.Sidebar_Actions;
|
||||
this.LabelSidebarTodo.Text = Resources.Pages.Global.Sidebar_Todo;
|
||||
this.LabelDownloadInstructions.Text = Resources.Pages.Ledgers.UploadBankFiles_DownloadInstructions;
|
||||
this.LabelClickImage.Text = Resources.Pages.Global.Global_ClickImageToEnlarge;
|
||||
|
||||
this.LabelSelectBankAndAccount.Text = Resources.Pages.Ledgers.UploadBankFiles_SelectBankAndAccount;
|
||||
this.LabelSelectFileType.Text = Resources.Pages.Ledgers.UploadBankFiles_SelectBankFileType;
|
||||
this.LabelSelectAccount.Text = Resources.Pages.Ledgers.UploadBankFiles_SelectAccount;
|
||||
this.LabelUploadH2Header.Text = Resources.Pages.Ledgers.UploadBankFiles_UploadBankFile;
|
||||
this.LabelUploadH3Header.Text = Resources.Pages.Global.Global_UploadFileToActivizr;
|
||||
this.Upload.Text = Resources.Pages.Global.Global_UploadFile;
|
||||
this.LabelProcessing.Text = Resources.Pages.Global.Global_ProcessingFile;
|
||||
this.LabelUploadBankFilesInfo.Text = Resources.Pages.Ledgers.UploadBankFiles_Info;
|
||||
this.LabelActionItemsHere.Text = Resources.Pages.Global.Sidebar_Todo_Placeholder;
|
||||
|
||||
this.LabelSelectBankAndAccount.Text = Resources.Pages.Ledgers.UploadBankFiles_SelectBankAndAccount;
|
||||
this.LabelSelectFileType.Text = Resources.Pages.Ledgers.UploadBankFiles_SelectBankFileType;
|
||||
this.LabelSelectAccount.Text = Resources.Pages.Ledgers.UploadBankFiles_SelectAccount;
|
||||
this.LabelUploadH2Header.Text = Resources.Pages.Ledgers.UploadBankFiles_UploadBankFile;
|
||||
this.LabelUploadH3Header.Text = Resources.Pages.Global.Global_UploadFileToActivizr;
|
||||
this.Upload.Text = Resources.Pages.Global.Global_UploadFile;
|
||||
this.LabelProcessing.Text = Resources.Pages.Global.Global_ProcessingFile;
|
||||
this.LinkUploadAnother.Text = Resources.Pages.Ledgers.UploadBankFiles_UploadAnother;
|
||||
this.LabelModalInstructionHeader.Text = Resources.Pages.Ledgers.UploadBankFiles_BankScreenshot;
|
||||
}
|
||||
|
||||
if (!IsPostBack)
|
||||
{
|
||||
@@ -133,36 +146,61 @@ namespace Activizr.Site.Pages.Ledgers
|
||||
|
||||
// TODO: PROCESS
|
||||
// file.SaveAs("c:\\temp\\" + file.GetName());
|
||||
RadProgressContext progress = RadProgressContext.Current;
|
||||
progress.Speed = "N/A";
|
||||
|
||||
const int total = 100;
|
||||
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
progress["PrimaryPercent"] = i.ToString();
|
||||
progress["PrimaryTotal"] = total.ToString();
|
||||
progress["PrimaryValue"] = i.ToString();
|
||||
|
||||
progress["SecondaryTotal"] = total.ToString();
|
||||
progress["SecondaryValue"] = i.ToString();
|
||||
progress["SecondaryPercent"] = i.ToString();
|
||||
progress["PrimaryProgressBar"] = i.ToString();
|
||||
progress["CurrentOperationText"] = "File is being processed...";
|
||||
|
||||
if (!Response.IsClientConnected)
|
||||
{
|
||||
//Cancel button was clicked or the browser was closed, so stop processing
|
||||
break;
|
||||
}
|
||||
|
||||
//Stall the current thread for 0.1 seconds
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
|
||||
this.PanelFileTypeAccount.Visible = false;
|
||||
this.PanelResults.Visible = true;
|
||||
fileWasUploaded = true;
|
||||
|
||||
// Interpret and then import the data
|
||||
|
||||
ImportedBankData bankData = null;
|
||||
|
||||
try
|
||||
{
|
||||
// Set initial progress to light up progress box.
|
||||
|
||||
UpdateImportProgressBar(1);
|
||||
|
||||
// Assume SEB. Later, parameterize to filters.
|
||||
|
||||
bankData = ImportSebText(file.InputStream);
|
||||
this.LabelProcessing.Text = bankData.Rows.Count.ToString();
|
||||
ImportResults results = ProcessImportedData(bankData);
|
||||
|
||||
if (results.AccountBalanceMatchesBank)
|
||||
{
|
||||
this.LiteralImportResults.Text =
|
||||
String.Format(Resources.Pages.Ledgers.UploadBankFiles_ImportResults,
|
||||
results.DuplicateTransactions + results.TransactionsImported,
|
||||
results.TransactionsImported,
|
||||
FinancialAccount.FromIdentity(Int32.Parse(this.DropAccounts.SelectedValue))
|
||||
.Name,
|
||||
results.DuplicateTransactions);
|
||||
this.LabelImportResultsHeader.Text = Resources.Pages.Ledgers.UploadBankFiles_FileImportedHeader;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.LiteralImportResults.Text =
|
||||
String.Format(Resources.Pages.Ledgers.UploadBankFiles_ErrorBalance,
|
||||
results.DuplicateTransactions + results.TransactionsImported,
|
||||
results.TransactionsImported,
|
||||
FinancialAccount.FromIdentity(Int32.Parse(this.DropAccounts.SelectedValue))
|
||||
.Name,
|
||||
results.DuplicateTransactions);
|
||||
this.LabelImportResultsHeader.Text = Resources.Pages.Ledgers.UploadBankFiles_FileImportedHeader_ErrorBalance;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
this.LiteralDownloadInstructionsModal.Text = exception.ToString(); // For debug purposes -- will not be shown to user
|
||||
this.PanelErrorImage.Visible = true;
|
||||
this.LabelImportResultsHeader.Text = Resources.Pages.Ledgers.UploadBankFiles_ImportError;
|
||||
this.LiteralImportResults.Text = Resources.Pages.Ledgers.UploadBankFiles_ErrorInterpretation;
|
||||
}
|
||||
|
||||
// Import the data to database
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -180,5 +218,307 @@ namespace Activizr.Site.Pages.Ledgers
|
||||
this.LiteralDivInstructionsStyle.Text = @"style='display:none'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected class ImportResults
|
||||
{
|
||||
public int TransactionsImported;
|
||||
public int DuplicateTransactions;
|
||||
public bool AccountBalanceMatchesBank;
|
||||
}
|
||||
|
||||
|
||||
protected ImportResults ProcessImportedData(ImportedBankData import)
|
||||
{
|
||||
FinancialAccount assetAccount = FinancialAccount.FromIdentity(Int32.Parse(this.DropAccounts.SelectedValue));
|
||||
FinancialAccount autoDepositAccount = _currentOrganization.FinancialAccounts.IncomeDonations;
|
||||
int autoDepositLimit = 1000; // TODO: _currentOrganization.Parameters.AutoDonationLimit;
|
||||
|
||||
ImportResults result = new ImportResults();
|
||||
int count = 0;
|
||||
int progressUpdateInterval = import.Rows.Count/40;
|
||||
|
||||
if (progressUpdateInterval > 100)
|
||||
{
|
||||
progressUpdateInterval = 100;
|
||||
}
|
||||
|
||||
foreach (ImportedBankRow row in import.Rows)
|
||||
{
|
||||
// Update progress.
|
||||
|
||||
count++;
|
||||
if (progressUpdateInterval < 2 || count % progressUpdateInterval == 0)
|
||||
{
|
||||
int percent = (count*99)/import.Rows.Count;
|
||||
UpdateImportProgressBar(percent);
|
||||
}
|
||||
|
||||
// Each row is at least a stub, probably more.
|
||||
|
||||
string importKey = row.SuppliedTransactionId;
|
||||
|
||||
// If importKey is empty, construct a hash from the data fields.
|
||||
|
||||
if (string.IsNullOrEmpty(importKey))
|
||||
{
|
||||
string commentKey = row.Comment;
|
||||
if (row.DateTime.Year >= 2012)
|
||||
{
|
||||
commentKey = commentKey.ToLowerInvariant();
|
||||
}
|
||||
|
||||
string hashKey = row.HashBase + commentKey + (row.AmountCentsNet / 100.0).ToString(CultureInfo.InvariantCulture) + row.CurrentBalance.ToString(CultureInfo.InvariantCulture) +
|
||||
row.DateTime.ToString("yyyy-MM-dd-hh-mm-ss");
|
||||
|
||||
importKey = SHA1.Hash(hashKey).Replace(" ", "");
|
||||
}
|
||||
|
||||
if (importKey.Length > 30)
|
||||
{
|
||||
importKey = importKey.Substring(0, 30);
|
||||
}
|
||||
|
||||
Int64 amountCents = row.AmountCentsNet;
|
||||
|
||||
if (amountCents == 0)
|
||||
{
|
||||
amountCents = row.AmountCentsGross;
|
||||
}
|
||||
|
||||
FinancialTransaction transaction = FinancialTransaction.ImportWithStub(_currentOrganization.Identity, row.DateTime,
|
||||
assetAccount.Identity, amountCents,
|
||||
row.Comment, importKey,
|
||||
_currentUser.Identity);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
// The transaction was created. Examine if the autobook criteria are true.
|
||||
|
||||
result.TransactionsImported++;
|
||||
|
||||
FinancialAccounts accounts = FinancialAccounts.FromBankTransactionTag(row.Comment);
|
||||
|
||||
if (accounts.Count == 1)
|
||||
{
|
||||
// This is a labelled local donation.
|
||||
|
||||
Geography geography = accounts[0].AssignedGeography;
|
||||
FinancialAccount localAccount = accounts[0];
|
||||
|
||||
transaction.AddRow(_currentOrganization.FinancialAccounts.IncomeDonations, -amountCents, _currentUser);
|
||||
transaction.AddRow(_currentOrganization.FinancialAccounts.CostsLocalDonationTransfers,
|
||||
amountCents, _currentUser);
|
||||
transaction.AddRow(localAccount, -amountCents, _currentUser);
|
||||
|
||||
Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.LocalDonationReceived,
|
||||
_currentUser.Identity, _currentOrganization.Identity,
|
||||
geography.Identity, 0,
|
||||
transaction.Identity, localAccount.Identity.ToString());
|
||||
}
|
||||
else if (row.Comment.ToLowerInvariant().StartsWith("bg 451-0061 ")) // TODO: Organization.Parameters.FinancialTrackedTransactionPrefix
|
||||
{
|
||||
// Check for previously imported payment group
|
||||
|
||||
PaymentGroup group = PaymentGroup.FromTag(_currentOrganization,
|
||||
"SEBGM" + DateTime.Today.Year.ToString() + // TODO: Get tagging from org
|
||||
row.Comment.Substring(11));
|
||||
|
||||
if (group != null)
|
||||
{
|
||||
// There was a previously imported and not yet closed payment group matching this transaction
|
||||
// Close the payment group and match the transaction against accounts receivable
|
||||
|
||||
transaction.Dependency = group;
|
||||
group.Open = false;
|
||||
transaction.AddRow(_currentOrganization.FinancialAccounts.AssetsOutboundInvoices, -amountCents, _currentUser);
|
||||
}
|
||||
}
|
||||
else if (amountCents < 0)
|
||||
{
|
||||
// Autowithdrawal mechanisms removed, condition kept because of downstream else-if conditions
|
||||
}
|
||||
else if (amountCents > 0)
|
||||
{
|
||||
if (row.Fee < 0)
|
||||
{
|
||||
// This is always an autodeposit, if there is a fee (which is never > 0.0)
|
||||
|
||||
transaction.AddRow(_currentOrganization.FinancialAccounts.CostsBankFees, -row.Fee, _currentUser);
|
||||
transaction.AddRow(autoDepositAccount, -row.AmountCentsGross, _currentUser);
|
||||
}
|
||||
else if (amountCents < autoDepositLimit * 100)
|
||||
{
|
||||
// Book against autoDeposit account.
|
||||
|
||||
transaction.AddRow(autoDepositAccount, -amountCents, _currentUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Transaction was not imported; assume duplicate
|
||||
|
||||
result.DuplicateTransactions++;
|
||||
}
|
||||
}
|
||||
|
||||
// Import complete. Return true if the bookkeeping account matches the bank data.
|
||||
|
||||
Int64 databaseAccountBalanceCents = assetAccount.BalanceTotalCents;
|
||||
|
||||
if (databaseAccountBalanceCents == import.CurrentBalanceCents)
|
||||
{
|
||||
Payouts.AutomatchAgainstUnbalancedTransactions(_currentOrganization);
|
||||
result.AccountBalanceMatchesBank = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.AccountBalanceMatchesBank = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected void UpdateImportProgressBar (int percentDone)
|
||||
{
|
||||
RadProgressContext progress = RadProgressContext.Current;
|
||||
progress["PrimaryPercent"] = percentDone.ToString();
|
||||
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// These Functions Copied From PWv4 -- may need adaptation and/or modernization
|
||||
|
||||
|
||||
protected ImportedBankData ImportSebText(Stream fileStream)
|
||||
{
|
||||
TextReader reader = new StreamReader(fileStream, Encoding.GetEncoding(1252));
|
||||
string contents = reader.ReadToEnd();
|
||||
|
||||
string[] lines = contents.Split('\n');
|
||||
|
||||
if (lines[0].Trim() != "Bokföringsdatum\tValutadatum\tVerifikationsnummer\tText/mottagare\tBelopp\tSaldo")
|
||||
{
|
||||
throw new ArgumentException("Unable to parse");
|
||||
}
|
||||
|
||||
List<ImportedBankRow> rows = new List<ImportedBankRow>();
|
||||
ImportedBankData result = new ImportedBankData();
|
||||
|
||||
string[] firstLineParts = lines[1].Split('\t');
|
||||
|
||||
string stringBalance = firstLineParts[5].Trim().Replace(",", "");
|
||||
result.CurrentBalanceCents = Int64.Parse(stringBalance, CultureInfo.InvariantCulture);
|
||||
result.CurrentBalance = result.CurrentBalanceCents/100.0;
|
||||
|
||||
int rowCount = lines.Length;
|
||||
|
||||
for (int lineIndex = 1; lineIndex < rowCount; lineIndex++) // Skip first row on purpose - is header row
|
||||
{
|
||||
string[] lineParts = lines[lineIndex].Split('\t');
|
||||
|
||||
if (lineParts.Length < 2)
|
||||
{
|
||||
// Assume empty line, probably last line; do not process
|
||||
continue;
|
||||
}
|
||||
|
||||
string amountString = lineParts[4].Replace(".", "").Replace(",", "");
|
||||
|
||||
ImportedBankRow row = new ImportedBankRow();
|
||||
row.DateTime = DateTime.Parse(lineParts[0]);
|
||||
row.Comment = lineParts[3].Replace(" ", " ").Trim();
|
||||
row.CurrentBalanceCents = Int64.Parse(lineParts[5].Trim().Replace(",", ""), CultureInfo.InvariantCulture);
|
||||
row.CurrentBalance = row.CurrentBalanceCents/100.0;
|
||||
row.AmountCentsNet = Int64.Parse(amountString);
|
||||
row.HashBase = lineParts[2];
|
||||
|
||||
rows.Add(row);
|
||||
}
|
||||
|
||||
result.Rows = rows;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected ImportedBankData ImportPaypal(string contents)
|
||||
{
|
||||
string[] lines = contents.Split('\n');
|
||||
ImportedBankData result = new ImportedBankData();
|
||||
List<ImportedBankRow> rows = new List<ImportedBankRow>();
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string[] parts = line.Split('\t');
|
||||
|
||||
if (parts.Length < 30)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (StripQuotes(parts[6]) != "SEK")
|
||||
{
|
||||
continue; // HACK: Need to fix currency support at some time
|
||||
}
|
||||
|
||||
// Get current balance from the first line in the file
|
||||
|
||||
if (result.CurrentBalance == 0.0)
|
||||
{
|
||||
result.CurrentBalance = Double.Parse(StripQuotes(parts[34]), CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
ImportedBankRow row = new ImportedBankRow();
|
||||
|
||||
row.SuppliedTransactionId = StripQuotes(parts[12]);
|
||||
row.Comment = StripQuotes(parts[4]);
|
||||
row.DateTime = DateTime.Parse(StripQuotes(parts[0]) + " " + StripQuotes(parts[1]), CultureInfo.InvariantCulture);
|
||||
row.AmountCentsGross = Int64.Parse(StripQuotes(parts[7]).Replace(".", ""));
|
||||
row.Fee = Double.Parse(StripQuotes(parts[8]), CultureInfo.InvariantCulture);
|
||||
row.AmountCentsNet = Int64.Parse(StripQuotes(parts[9]).Replace(".", ""));
|
||||
|
||||
rows.Add(row);
|
||||
}
|
||||
|
||||
result.Rows = rows;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected string StripHtml(string input)
|
||||
{
|
||||
// Doesn't really strip HTML -- what it does is strip a link markup (<a...> and </a>)
|
||||
|
||||
if (input.ToLower().EndsWith("</a>"))
|
||||
{
|
||||
input = input.Substring(0, input.Length - 4);
|
||||
|
||||
int indexOfLastGT = input.LastIndexOf('>');
|
||||
input = input.Substring(indexOfLastGT + 1);
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
protected string StripQuotes(string input)
|
||||
{
|
||||
if (input.StartsWith("\""))
|
||||
{
|
||||
input = input.Substring(1);
|
||||
}
|
||||
|
||||
if (input.EndsWith("\""))
|
||||
{
|
||||
input = input.Substring(0, input.Length - 1);
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user