From 171aa91eb6231d46622d42dd7e918413a9eda49a Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Thu, 28 Feb 2019 11:07:10 +0100 Subject: [PATCH] Added OCR availability column --- Logic/Financial/PaymentTransferInfo.cs | 29 ++++++++++++++++++- .../v5/Financial/Json-PayableCosts.aspx.cs | 8 +++-- Site/Pages/v5/Financial/PayOutMoney.aspx | 10 ++++--- Site/Site.csproj | 1 + 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/Logic/Financial/PaymentTransferInfo.cs b/Logic/Financial/PaymentTransferInfo.cs index 34b64276..050c5486 100644 --- a/Logic/Financial/PaymentTransferInfo.cs +++ b/Logic/Financial/PaymentTransferInfo.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Resources; using System.Text; @@ -9,6 +10,7 @@ using Swarmops.Common.Interfaces; using Swarmops.Logic.Swarm; using Swarmops.Logic.Structure; using Swarmops.Logic.Resources; +using Swarmops.Logic.Support; namespace Swarmops.Logic.Financial { @@ -27,6 +29,8 @@ namespace Swarmops.Logic.Financial public string CurrencyAmount { get; set; } public PaymentTargetType TargetType { get; set; } public string LocalizedPaymentMethodName { get; set; } + public bool OcrAvailable { get; set; } // defaults to false which is fine + public string[] OcrData { get; set; } public Dictionary LocalizedPaymentInformation { get; set; } public static PaymentTransferInfo FromObject(IHasIdentity financialObject, Money amountToPay = null) @@ -93,7 +97,30 @@ namespace Swarmops.Logic.Financial result.TargetType = PaymentTargetType.DomesticBankGiro; // for now result.LocalizedPaymentInformation[ Logic_Financial_PaymentTransferInfo.PaymentTargetField_GiroNumber] = - invoice.PayToAccount.Substring(5); + invoice.PayToAccount.Substring(5); + + // Check for SEBG OCR availability + + if (invoice.InvoiceReference.Length > 2 && Formatting.CheckLuhnChecksum(invoice.InvoiceReference) && + Formatting.CheckLuhnChecksum(invoice.PayToAccount)) + { + result.OcrAvailable = true; + result.OcrData = new string[3]; + result.OcrData[0] = invoice.InvoiceReference + " #"; + result.OcrData[1] = string.Format("{0} {1:00}   {2} >", // three spaces between the cents and the checksum + invoice.AmountCents / 100, invoice.AmountCents % 100, + Formatting.GetLuhnChecksum(invoice.AmountCents.ToString(CultureInfo.InvariantCulture))); + result.OcrData[2] = Formatting.CleanNumber(invoice.PayToAccount); + } + } + else + { + // Assume domestic giro in lack of other information + + result.TargetType = PaymentTargetType.DomesticBankGiro; + result.LocalizedPaymentInformation[ + Logic_Financial_PaymentTransferInfo.PaymentTargetField_GiroNumber] = + invoice.PayToAccount; // the whole string, as opposed to case above } result.LocalizedPaymentMethodName = diff --git a/Site/Pages/v5/Financial/Json-PayableCosts.aspx.cs b/Site/Pages/v5/Financial/Json-PayableCosts.aspx.cs index 0f735e2e..0d0bcc4d 100644 --- a/Site/Pages/v5/Financial/Json-PayableCosts.aspx.cs +++ b/Site/Pages/v5/Financial/Json-PayableCosts.aspx.cs @@ -68,8 +68,9 @@ namespace Swarmops.Frontend.Pages.Financial "\"recipient\":\"{2}\"," + "\"transferInfo\":\"{3}\"," + "\"amount\":\"{6}\"," + + "\"ocrAvailable\":\"{4}\"," + "\"action\":\"" + - "" + + "" + "" + "" + "" + @@ -82,11 +83,12 @@ namespace Swarmops.Frontend.Pages.Financial : payout.ExpectedTransactionDate.ToShortDateString()), JsonSanitize (TryLocalize (payout.Recipient)), transferInfo.Currency.Code + ", " + JsonSanitize (transferInfo.LocalizedPaymentMethodName), - JsonSanitize (payout.Account), + transferInfo.OcrAvailable? "": string.Empty, JsonSanitize (TryLocalize (payout.Reference)), payout.HasNativeAmount? payout.NativeAmountString : (payout.AmountCents/100.0).ToString("N2"), payout.ProtoIdentity.Replace ("|", ""), - transferInfo.LocalizedPaymentInformation.Count); + transferInfo.LocalizedPaymentInformation.Count, + transferInfo.OcrAvailable? "yes": "no"); result.Append ("},"); } diff --git a/Site/Pages/v5/Financial/PayOutMoney.aspx b/Site/Pages/v5/Financial/PayOutMoney.aspx index 5f3d6889..2f2a4d39 100644 --- a/Site/Pages/v5/Financial/PayOutMoney.aspx +++ b/Site/Pages/v5/Financial/PayOutMoney.aspx @@ -23,7 +23,8 @@ '/Images/Icons/iconshock-red-cross-circled-128x96px.png', '/Images/Icons/iconshock-balloon-undo-128x96px.png', '/Images/Icons/iconshock-balloon-yes-128x96px.png', - '/Images/Icons/iconshock-balloon-no-128x96px-disabled.png' + '/Images/Icons/iconshock-balloon-no-128x96px-disabled.png', + '/Images/Icons/iconshock-barcode-128x96px.png' ]); $(document).ready(function () { @@ -60,13 +61,13 @@ if (gridsLoaded == 2) { // onLoadSuccess is triggered _twice_ per grid for some arcane reason - $('#divOcrView').hide(); - $(".LocalIconApproval").attr("src", "/Images/Icons/iconshock-balloon-yes-128x96px.png"); $(".LocalIconApproved").attr("src", "/Images/Icons/iconshock-green-tick-128x96px.png").css("opacity", 0.5); $(".LocalIconDenied").attr("src", "/Images/Icons/iconshock-red-cross-circled-128x96px.png"); $(".LocalIconWait").attr("src", "/Images/Abstract/ajaxloader-48x36px.gif").hide(); $(".LocalIconUndo").attr("src", "/Images/Icons/iconshock-balloon-undo-128x96px.png"); + $(".LocalIconOcr").attr("src", "/Images/Icons/iconshock-barcode-128x96px.png"); + $(".LocalIconApproved.LocalPrototype, .LocalIconUndo.LocalPrototype, .LocalIconDenied.LocalPrototype, .LocalIconApproval.LocalPaid, .LocalIconDenial.LocalPaid, .LocalIconDenied.LocalPaid").hide(); $(".LocalIconDenial").attr("src", "/Images/Icons/iconshock-balloon-no-128x96px-disabled.png"); $(".LocalIconApproval, .LocalIconUndo, .LocalIconDenial").css("cursor", "pointer"); @@ -342,8 +343,9 @@ - + + diff --git a/Site/Site.csproj b/Site/Site.csproj index 81feff0d..34a1f7ee 100644 --- a/Site/Site.csproj +++ b/Site/Site.csproj @@ -1587,6 +1587,7 @@ +