Works, looks good. Now for testing with live data

This commit is contained in:
Rick Falkvinge
2014-08-19 09:34:19 +00:00
parent 69cb35a311
commit 6b110dea22
6 changed files with 188 additions and 53 deletions
+18 -1
View File
@@ -166,7 +166,24 @@ namespace Swarmops.Database
}
public void SetDocumentForeignObject (int documentId, DocumentType newDocumentType, int newForeignId)
public void SetDocumentDescription(int documentId, string newDescription)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetDocumentDescription", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "documentId", documentId);
AddParameterWithName(command, "newDescription", newDescription);
command.ExecuteNonQuery();
}
}
public void SetDocumentForeignObject(int documentId, DocumentType newDocumentType, int newForeignId)
{
using (DbConnection connection = GetMySqlDbConnection())
{
+21
View File
@@ -794,6 +794,26 @@ namespace Swarmops.Logic.Structure
}
}
public FinancialAccounts FinancialAccountsExternal
{
get
{
// HACK: MUST FETCH THIS FROM ACTUAL ACCOUNTS
// HACK HACK HACK HACK HACK HACK
if (Organization.FromIdentity(1).Name == "Piratpartiet SE") // also, fetch that from installation id instead
{
FinancialAccounts result = new FinancialAccounts();
result.Add(FinancialAccount.FromIdentity(1));
result.Add(FinancialAccount.FromIdentity(2));
return result;
}
throw new NotImplementedException();
}
}
public static Organization Create (int parentOrganizationId, string nameInternational, string name, string nameShort, string domain, string mailPrefix, int anchorGeographyId, bool acceptsMembers, bool autoAssignNewMembers, int defaultCountryId)
{
@@ -851,6 +871,7 @@ namespace Swarmops.Logic.Structure
public string IncomingPaymentTag
{
// HACK: REmove this property altogether - should be per account
get { return "bg 451-0061 "; } // TODO: Per organization, of course
}
+3
View File
@@ -134,6 +134,9 @@ namespace Swarmops.Logic.Support
// Unlink, actually
SetForeignObject(new TemporaryIdentity(0));
File.Delete(StorageRoot + ServerFileName);
SwarmDb.GetDatabaseForWriting().SetDocumentDescription(this.Identity, "Deleted");
}
protected static string StorageRoot
+3 -3
View File
@@ -354,12 +354,12 @@
<comment>Displayed when the input file can't be parsed, before import attempt.</comment>
</data>
<data name="UploadBankFiles_ResultsGood" xml:space="preserve">
<value>&lt;p&gt;The file has been &lt;strong&gt;successfully imported.&lt;/strong&gt; {0:N} new transactions imported; {1:N} discarded as duplicates of what was already in Swarmops. The account balance in Swarmops matches that of the bank.&lt;/p&gt;&lt;p&gt;The file contained transactions from {2:yyyy-MMM-dd} to {3:yyyy-MMM-dd}.&lt;/p&gt;</value>
<value>&lt;p&gt;The file has been &lt;strong&gt;successfully imported.&lt;/strong&gt; {0:N0} new transactions imported; {1:N0} discarded as duplicates of what was already in Swarmops. The account balance in Swarmops matches that of the bank.&lt;/p&gt;&lt;p&gt;The file contained transactions from {2:yyyy-MMM-dd} to {3:yyyy-MMM-dd}.&lt;/p&gt;</value>
<comment>Zero is new transaction count, one is duplicate transaction count, two and three are lowest and highest dates found in file. Pay attention to date format and adjust to culture.</comment>
</data>
<data name="UploadBankFiles_ResultsQuestionable" xml:space="preserve">
<value>&lt;p&gt;The file was imported, but the &lt;strong&gt;resulting account balance mismatches.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;After importing {0:N} transactions (and discarding {1:N} duplicates), the entire file has been processed. However, the resulting account balance in Swarmops is not the same as that of the bank statement.&lt;/p&gt;
&lt;p&gt;Please try uploading a fresh account statement. If that still produces a mismatch, you may need to try &lt;a href="/Pages/v5/Ledgers/ResyncExternalAccount.aspx"&gt;resynchronizing&lt;/a&gt;the bank account with a comprehensive account statement file.&lt;/p&gt;</value>
<value>&lt;p&gt;The file was imported, but the &lt;strong&gt;resulting account balance mismatches.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;After importing {0:N0} transactions (and discarding {1:N0} duplicates), the entire file has been processed. However, the resulting account balance in Swarmops is not the same as that of the bank statement.&lt;/p&gt;
&lt;p&gt;Please try uploading a fresh account statement. If that still produces a mismatch, you may need to try &lt;a href="/Pages/v5/Ledgers/ResyncExternalAccount.aspx"&gt;resynchronizing&lt;/a&gt; the bank account with a comprehensive account statement file.&lt;/p&gt;</value>
<comment>Displayed on successful import, but the resulting balance is off compared to the account statement file that was just uploaded.</comment>
</data>
<data name="UploadBankFiles_SelectAccount" xml:space="preserve">
+51 -41
View File
@@ -29,6 +29,17 @@
if (selectedAccountId != 0) {
$('#<%=this.UploadFile.ClientID %>_ButtonUploadVisible').fadeIn();
$.ajax({
type: "POST",
url: "UploadBankFiles.aspx/GetAccountUploadInstructions",
data: "{'guid': '<%= this.UploadFile.GuidString %>', 'accountIdString':'" + $('#<%= this.DropAccounts.ClientID %>').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$('#SpanInstructions').text(msg.d);
}
});
} else {
$('#<%=this.UploadFile.ClientID %>_ButtonUploadVisible').fadeOut();
}
@@ -41,6 +52,7 @@
$('#DivProgressProcessing').progressbar({ value: 0, max: 100 });
$('#DivProgressFake').progressbar({ value: 0, max: 100 });
$('#DivProgressFake').progressbar({ value: 100 }); // this guy is swapped in on completion
$('#DivProcessingFake').slideUp(); // in case second, third... file
halfway = false;
$.ajax({
@@ -70,13 +82,40 @@
width: "100%"
}, { queue: false });
$('#DivProcessing').hide();
$('#DivProcessingFake').show();
$('#DivProgressProcessingFake').show();
$('#DivProcessingFake').show();
// Add processing results here
$.ajax({
type: "POST",
url: "UploadBankFiles.aspx/GetReportedImportResults",
data: "{'guid': '<%= this.UploadFile.GuidString %>'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg2) {
$('#DivUploadResultsGood').hide();
$('#DivUploadResultsBad').hide();
$('#DivUploadResultsQuestionable').hide();
$('#DivUploadResults' + msg2.d.Category + 'Text').html(msg2.d.Html);
$('#DivUploadResults' + msg2.d.Category).show();
$('#<%=this.UploadFile.ClientID %>_ButtonUploadVisible').hide();
$('#SpanUploadMore').show();
$('#SpanUploadFirst').hide();
$('#<%=DropAccounts.ClientID %>').val('0');
$('#SpanInstructions').text('');
setTimeout("$('#DivProgressFake').slideUp().fadeOut();", 1000);
setTimeout("$('#DivUploadBankFile').slideDown();", 1000);
}
});
} else {
if (msg.d > 50 && !halfway) {
halfway = true;
$('#DivProgressFake').show(); // hidden if 2nd, 3rd... file
$('#DivUploadBankFile').slideUp().fadeOut();
}
@@ -93,18 +132,6 @@
if (msg.d > 0 && !progressReceived) {
progressReceived = true;
$.ajax({
type: "POST",
url: "UploadBankFiles.aspx/GetProcessingStatistics",
data: "{'guid': '<%= this.UploadFile.GuidString %>'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg2) {/*
$('#SpanFirstTx').text(msg2.d.FirstTransaction);
$('#SpanLastTx').text(msg2.d.LastTransaction);
$('#SpanTxCount').text(msg2.d.TransactionCount);*/
}
});
}
setTimeout('updateProgressProcessing();', 1000);
@@ -123,31 +150,31 @@
</script>
<div id="DivProcessingFake" style="display:none">
<div id="DivProcessingFake" style="display:none; margin-bottom:10px">
<h2><asp:Label ID="LabelProcessingComplete" runat="server" /></h2>
<div id="DivProgressFake" style="width:100%"></div>
<div id="DivUploadResultsGood">
</div>
<div id="DivUploadResultsGood" style="display:none"><div id="DivUploadResultsGoodText"></div></div>
<div id="DivUploadResultsBad">
<div float="left"><img src="/Images/Icons/iconshock-cross-96px.png" /></div><div id="DivUploadResultsBadText"></div>
<div id="DivUploadResultsBad" style="display:none">
<div style="float:left;margin-right:10px"><img src="/Images/Icons/iconshock-cross-96px.png" /></div><div id="DivUploadResultsBadText"></div>
</div>
<div id="DivUploadResultsQuestionable">
<div float="left"><img src="/Images/Icons/iconshock-warning-96px.png" /></div><div id="DivUploadResultsQuestionableText"></div>
<div id="DivUploadResultsQuestionable" style="display:none">
<div style="float:left;margin-right:10px"><img src="/Images/Icons/iconshock-warning-96px.png" /></div><div id="DivUploadResultsQuestionableText"></div>
</div>
<br clear="all"/>
</div>
<div id="DivUploadBankFile">
<h2><asp:Label runat="server" ID="LabelUploadBankFileHeader" /></h2>
<h2><span id="SpanUploadFirst"><asp:Label runat="server" ID="LabelUploadBankFileHeader" /></span><span id="SpanUploadMore" style="display:none"><asp:Label runat="server" ID="LabelUploadMore" /></span></h2>
<div id="DivPrepData">
<div class="entryFields">
<asp:DropDownList runat="server" ID="DropAccounts"/>
(Account statement)<br/>
(Instructions - TODO)<br/>
<span id="SpanInstructions"></span><br/>
<Swarmops5:FileUpload runat="server" ID="UploadFile" Filter="NoFilter" DisplayCount="8" HideTrigger="true" ClientUploadCompleteCallback="uploadCompletedCallback" /></div>
<div class="entryLabels">
@@ -166,23 +193,6 @@
<div id="DivProgressProcessing" style="width:100%"></div>
</div>
<div id="DivStepSuccessComplete" style="display:none">
<h2>Resynchronization complete</h2>
<p>All Swarmops records (<span id="SpanRecordsTotal">[...]</span>) have been successfully resynchronized with the master file.</p>
<p>You may <a href="/">return to dashboard</a> if you like.</p>
</div>
<div id="DivStepSuccessPartial" style="display:none">
<h2>Resynchronization partially complete</h2>
<p>Most Swarmops records (<span id="SpanRecordsSuccess">[...]</span>) have been successfully resynchronized with the master file. <strong>Some (<span id="SpanRecordsFail">[...]</span>) have not.</strong></p>
<p>Due to dependencies, manual action is required for the remaining records. Run resynchronization <a href="#" onclick="location.reload();">again</a> to see which records could not be automatically resynchronized.</p>
</div>
<div id="DivStepFailure" style="display:none">
<h2>Resynchronization partially complete</h2>
<p>Most Swarmops records (<span id="Span1">[...]</span>) have been successfully resynchronized with the master file. <strong>Some (<span id="Span2">[...]</span>) have not.</strong></p>
<p>Due to dependencies, manual action is required for the remaining records. Run resynchronization <a href="#" onclick="location.reload();">again</a> to see which records could not be automatically resynchronized.</p>
</div>
<br/>
</asp:Content>
+92 -8
View File
@@ -7,6 +7,7 @@ using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.UI;
using System.Web.UI.WebControls;
using Swarmops.Logic.Cache;
@@ -42,6 +43,7 @@ namespace Swarmops.Site.Pages.Ledgers
this.LabelProcessing.Text = Resources.Pages.Ledgers.UploadBankFiles_Processing;
this.LabelProcessingComplete.Text = Resources.Pages.Ledgers.UploadBankFiles_ProcessingComplete;
this.LabelUploadBankFile.Text = Resources.Pages.Ledgers.UploadBankFiles_UploadBankFile;
this.LabelUploadMore.Text = Resources.Pages.Ledgers.UploadBankFiles_UploadAnother;
this.LabelUploadBankFileHeader.Text = Resources.Pages.Ledgers.UploadBankFiles_UploadBankFile;
// Populate the asset account dropdown, if needed for file type
@@ -158,17 +160,17 @@ namespace Swarmops.Site.Pages.Ledgers
private void PopulateAccountDropDown()
{
FinancialAccounts accounts = FinancialAccounts.ForOrganization(this.CurrentOrganization,
FinancialAccountType.Asset);
FinancialAccounts accounts = this.CurrentOrganization.FinancialAccountsExternal;
this.DropAccounts.Items.Clear();
this.DropAccounts.Items.Add(Resources.Global.Global_DropInits_SelectFinancialAccount);
this.DropAccounts.Items.Add(new ListItem(Resources.Global.Global_DropInits_SelectFinancialAccount, "0"));
foreach (FinancialAccount account in accounts)
{
// TODO: If connected to a bank asset, ...
this.DropAccounts.Items.Add(new ListItem(account.Name, account.Identity.ToString()));
if (account.AccountType == FinancialAccountType.Asset)
{
this.DropAccounts.Items.Add(new ListItem(account.Name, account.Identity.ToString()));
}
}
}
@@ -227,12 +229,71 @@ namespace Swarmops.Site.Pages.Ledgers
PaymentDetails
}
[WebMethod]
static public string GetAccountUploadInstructions(string guid, string accountIdString)
{
int accountId = Int32.Parse(accountIdString);
// HACK HACK RELENTLESS HACK TODO
switch (accountId)
{
case 0:
return string.Empty;
case 1:
return "(Instruct Stock-SE-SEB)";
case 2:
return "(Instruct Stock-Global-Paypal)";
default:
throw new NotImplementedException();
}
}
[WebMethod]
static public ReportedImportResults GetReportedImportResults(string guid)
{
ReportedImportResults results = new ReportedImportResults();
ImportResultsCategory category = (ImportResultsCategory) GuidCache.Get(guid + "-Result");
ImportResults resultDetail = (ImportResults) GuidCache.Get(guid + "-ResultDetails");
string html = string.Empty;
switch (category)
{
case ImportResultsCategory.Good:
html = String.Format(Resources.Pages.Ledgers.UploadBankFiles_ResultsGood,
resultDetail.TransactionsImported, resultDetail.DuplicateTransactions,
resultDetail.EarliestTransaction, resultDetail.LatestTransaction);
break;
case ImportResultsCategory.Questionable:
html = String.Format(Resources.Pages.Ledgers.UploadBankFiles_ResultsQuestionable,
resultDetail.TransactionsImported, resultDetail.DuplicateTransactions,
resultDetail.EarliestTransaction, resultDetail.LatestTransaction);
break;
case ImportResultsCategory.Bad:
html = Resources.Pages.Ledgers.UploadBankFiles_ResultsBad;
break;
default:
throw new NotImplementedException("Unhandled ImportResultCategory");
}
results.Html = html;
results.Category = category.ToString();
return results;
}
public class ReportedImportResults
{
public string Category { get; set; }
public string Html { get; set; }
}
private static void ProcessUploadThread(object args)
{
string guid = ((ProcessThreadArguments) args).Guid;
BankFileType fileType = ((ProcessThreadArguments) args).FileType;
Documents documents = Documents.RecentFromDescription(guid);
GuidCache.Set(guid + "-Result", ImportResultsCategory.Bad); // default - this is what happens if exception
if (documents.Count != 1)
{
@@ -253,7 +314,18 @@ namespace Swarmops.Site.Pages.Ledgers
using (StreamReader reader = uploadedDoc.GetReader(1252))
{
externalData.LoadData(reader, ((ProcessThreadArguments) args).Organization);
// catch here and set result to BAD
ImportResults results = ProcessImportedData(externalData, (ProcessThreadArguments) args);
GuidCache.Set(guid + "-ResultDetails", results);
if (results.AccountBalanceMatchesBank)
{
GuidCache.Set(guid + "-Result", ImportResultsCategory.Good);
}
else
{
GuidCache.Set(guid + "-Result", ImportResultsCategory.Questionable);
}
}
}
else if (fileType == BankFileType.PaymentDetails)
@@ -266,8 +338,13 @@ namespace Swarmops.Site.Pages.Ledgers
// then read
}
}
catch (Exception e)
{
GuidCache.Set(guid + "-Exception", e.ToString());
}
finally
{
GuidCache.Set(guid + "-Progress", 100); // only here may the caller fetch the results
uploadedDoc.Delete(); // document no longer needed after processing, no matter the result
}
}
@@ -576,8 +653,6 @@ namespace Swarmops.Site.Pages.Ledgers
}
}
GuidCache.Set(args.Guid + "-Progress", 100); // Mark complete
// Import complete. Return true if the bookkeeping account matches the bank data.
Int64 databaseAccountBalanceCents = assetAccount.BalanceTotalCents;
@@ -612,6 +687,15 @@ namespace Swarmops.Site.Pages.Ledgers
}*/
public enum ImportResultsCategory
{
Unknown = 0,
Good,
Questionable,
Bad
}
protected class ImportedPaymentData
{