Re-enabled Primary Pilot's payment file upload

This commit is contained in:
Rick Falkvinge
2014-11-06 22:25:36 +01:00
parent b8e37dfc4e
commit 3d9342e03f
3 changed files with 83 additions and 17 deletions
+9 -1
View File
@@ -542,4 +542,12 @@
<value>Tx#</value>
<comment>Keep VERY short.</comment>
</data>
</root>
<data name="UploadBankFiles_ResultsPayments" xml:space="preserve">
<value>&lt;br/&gt;&lt;p&gt;The payments file was &lt;strong&gt;successfully imported.&lt;/strong&gt; {1:N0} payment(s) in {0:N0} group(s), totalling {3} {2:N2}, were imported.&lt;/p&gt;</value>
<comment>Arguments 0-3 in order: 0 PaymentGroupCount, 1 PaymentCount, 2 PaymentAmountTotal, 3 Currency</comment>
</data>
<data name="UploadBankFiles_ResultsPaymentsWithDupes" xml:space="preserve">
<value>&lt;br/&gt;&lt;p&gt;The payments file was &lt;strong&gt;successfully imported.&lt;/strong&gt; {1:N0} payment(s) in {0:N0} group(s), totalling {3} {2:N2}, were imported.&lt;/p&gt;&lt;p&gt;(There were also {5:N0} duplicate payment(s) in {4:N0} group(s).)&lt;/p&gt;</value>
<comment>Arguments 0-5 in order: 0 PaymentGroupCount, 1 PaymentCount, 2 PaymentAmountTotal, 3 Currency, 4 DuplicatePaymentGroupCount, 5 DuplicatePaymentCount</comment>
</data>
</root>
+7 -4
View File
@@ -12,7 +12,7 @@
<style type="text/css">
/* custom styles were used in Telerik version of page */
/* add custom styles here */
</style>
@@ -95,6 +95,7 @@
$('#DivUploadResultsGood').hide();
$('#DivUploadResultsBad').hide();
$('#DivUploadResultsQuestionable').hide();
$('#DivUploadResultsPayments').hide();
$('#DivUploadResults' + msg2.d.Category + 'Text').html(msg2.d.Html);
$('#DivUploadResults' + msg2.d.Category).show();
@@ -168,6 +169,10 @@
<div style="float:left;margin-right:10px"><img src="/Images/Icons/iconshock-warning-96px.png" /></div><div id="DivUploadResultsQuestionableText"></div>
</div>
<div id="DivUploadResultsPayments" style="display:none">
<div style="float:left;margin-right:10px"><img src="/Images/Icons/iconshock-cashregister-96px.png" /></div><div id="DivUploadResultsPaymentsText"></div>
</div>
<br clear="all"/>
</div>
@@ -177,13 +182,11 @@
<div class="entryFields">
<asp:DropDownList runat="server" ID="DropAccounts"/>
(Account statement)<br/>
<span id="SpanInstructions"></span><br/>
<span id="SpanInstructions"></span>&thinsp;<br/>
<Swarmops5:FileUpload runat="server" ID="UploadFile" Filter="NoFilter" DisplayCount="8" HideTrigger="true" ClientUploadCompleteCallback="uploadCompletedCallback" /></div>
<div class="entryLabels">
<asp:Label runat="server" ID="LabelBankAccount" /><br/>
<asp:Label runat="server" ID="LabelFileType" /><br/>
<asp:Label runat="server" ID="LabelInstructions" /><br/>
<asp:Label runat="server" ID="LabelUploadBankFile" />
</div>
+67 -12
View File
@@ -60,7 +60,6 @@ namespace Swarmops.Site.Pages.Ledgers
this.InfoBoxLiteral = Resources.Pages_Ledgers.UploadBankFiles_Info;
this.LabelBankAccount.Text = Resources.Pages_Ledgers.UploadBankFiles_BankAccount;
this.LabelFileType.Text = Resources.Pages_Ledgers.UploadBankFiles_FileType;
this.LabelInstructions.Text = Resources.Pages_Ledgers.UploadBankFiles_Instructions;
this.LabelProcessing.Text = Resources.Pages_Ledgers.UploadBankFiles_Processing;
this.LabelProcessingComplete.Text = Resources.Pages_Ledgers.UploadBankFiles_ProcessingComplete;
@@ -206,7 +205,7 @@ namespace Swarmops.Site.Pages.Ledgers
AuthenticationData authData = GetAuthenticationDataAndCulture();
int accountId = Int32.Parse(accountIdString);
BankFileType fileType = BankFileType.AccountStatement;
BankFileType fileType = BankFileType.Unknown;
if (accountId < 0)
{
@@ -277,7 +276,9 @@ namespace Swarmops.Site.Pages.Ledgers
{
ReportedImportResults results = new ReportedImportResults();
ImportResultsCategory category = (ImportResultsCategory) GuidCache.Get(guid + "-Result");
ImportResults resultDetail = (ImportResults) GuidCache.Get(guid + "-ResultDetails");
ImportResults resultDetail = GuidCache.Get(guid + "-ResultDetails") as ImportResults;
ImportedPaymentData paymentsDetail = GuidCache.Get(guid + "-ResultDetails") as ImportedPaymentData;
string html = string.Empty;
switch (category)
@@ -295,6 +296,23 @@ namespace Swarmops.Site.Pages.Ledgers
case ImportResultsCategory.Bad:
html = Resources.Pages_Ledgers.UploadBankFiles_ResultsBad;
break;
case ImportResultsCategory.Payments:
if (paymentsDetail.DuplicatePaymentCount > 0)
{
html = String.Format(Resources.Pages_Ledgers.UploadBankFiles_ResultsPaymentsWithDupes,
paymentsDetail.PaymentGroupCount, paymentsDetail.PaymentCount,
paymentsDetail.PaymentCentsTotal/100.0,
paymentsDetail.Currency.Code, paymentsDetail.DuplicatePaymentGroupCount,
paymentsDetail.DuplicatePaymentCount);
}
else
{
html = String.Format(Resources.Pages_Ledgers.UploadBankFiles_ResultsPayments,
paymentsDetail.PaymentGroupCount, paymentsDetail.PaymentCount,
paymentsDetail.PaymentCentsTotal / 100.0,
paymentsDetail.Currency.Code);
}
break;
default:
throw new NotImplementedException("Unhandled ImportResultCategory");
}
@@ -314,8 +332,11 @@ namespace Swarmops.Site.Pages.Ledgers
{
string guid = ((ProcessThreadArguments) args).Guid;
BankFileType fileType = ((ProcessThreadArguments) args).FileType;
Person currentUser = ((ProcessThreadArguments) args).CurrentUser;
Organization organization = ((ProcessThreadArguments) args).Organization;
Documents documents = Documents.RecentFromDescription(guid);
GuidCache.Set(guid + "-Progress", 1); // to make sure results aren't repeated from last file
GuidCache.Set(guid + "-Result", ImportResultsCategory.Bad); // default - this is what happens if exception
if (documents.Count != 1)
@@ -332,6 +353,42 @@ namespace Swarmops.Site.Pages.Ledgers
ExternalBankData externalData = new ExternalBankData();
externalData.Profile = account.ExternalBankDataProfile;
if (fileType == BankFileType.Unknown)
{
using (StreamReader reader = uploadedDoc.GetReader(1252))
{
try
{
externalData.LoadData(reader, 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);
}
}
catch (Exception)
{
reader.BaseStream.Position = 0; // rewind stream to retry parse with different file type
// Try a payment file instead
ImportedPaymentData paymentData = ImportBankgiroSE(reader, currentUser, organization);
// Apparently, we were successful
GuidCache.Set(guid + "-Result", ImportResultsCategory.Payments);
GuidCache.Set(guid + "-ResultDetails", paymentData);
}
}
}
if (fileType == BankFileType.AccountStatement)
{
using (StreamReader reader = uploadedDoc.GetReader(1252))
@@ -721,7 +778,8 @@ namespace Swarmops.Site.Pages.Ledgers
Unknown = 0,
Good,
Questionable,
Bad
Bad,
Payments
}
@@ -770,13 +828,10 @@ namespace Swarmops.Site.Pages.Ledgers
}
protected ImportedPaymentData ImportBankgiroSE(Stream fileStream)
// ReSharper disable once InconsistentNaming
protected static ImportedPaymentData ImportBankgiroSE(StreamReader reader, Person currentUser, Organization organization)
{
string contents = string.Empty;
using (TextReader reader = new StreamReader(fileStream, Encoding.GetEncoding(1252)))
{
contents = reader.ReadToEnd();
}
string contents = reader.ReadToEnd();
string[] lines = contents.Split('\n');
@@ -902,13 +957,13 @@ namespace Swarmops.Site.Pages.Ledgers
// Dupe check
PaymentGroup dupe = PaymentGroup.FromTag(this.CurrentOrganization, tag);
PaymentGroup dupe = PaymentGroup.FromTag(organization, tag);
if (dupe == null)
{
// Commit all recorded payments
PaymentGroup newGroup = PaymentGroup.Create(this.CurrentOrganization, timestamp, currency, this.CurrentUser);
PaymentGroup newGroup = PaymentGroup.Create(organization, timestamp, currency, currentUser);
result.PaymentGroupCount++;
Int64 reportedAmountCents = Int64.Parse(line.Substring(50, 18), CultureInfo.InvariantCulture); // may differ because of duplicates