diff --git a/Logic/Financial/Payouts.cs b/Logic/Financial/Payouts.cs index ec1ab3f7..3416afdc 100644 --- a/Logic/Financial/Payouts.cs +++ b/Logic/Financial/Payouts.cs @@ -332,23 +332,8 @@ namespace Swarmops.Logic.Financial { // Add the summarized tax line, too - string referenceString = string.Empty; - - if (identityList.Count == 1) - { - referenceString = "[Loc]Financial_TaxSpecification|" + identityList[0]; - } - else - { - identityList.Sort(); - referenceString = "[Loc]Financial_TaxesSpecification|" + - Formatting.GenerateRangeString (identityList); - } - - - BasicPayout basicPayout = new BasicPayout (0, organization.Identity, "[Loc]Financial_TheTaxMan", - string.Empty, referenceString, - taxTotalCents, payDay, false, DateTime.Now, 0); + BasicPayout basicPayout = new BasicPayout (0, organization.Identity, "[Loc]Financial_TheTaxMan", "SEBG 5050-1055", // HACK: Get tax account from something + organization.TaxPaymentOcr, taxTotalCents, payDay, false, DateTime.Now, 0); Payout payout = Payout.FromBasic (basicPayout); foreach (int salaryId in identityList) diff --git a/Logic/Support/Formatting.cs b/Logic/Support/Formatting.cs index 8872993d..c41c7fbc 100644 --- a/Logic/Support/Formatting.cs +++ b/Logic/Support/Formatting.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Text; using System.Text.RegularExpressions; @@ -167,16 +168,38 @@ namespace Swarmops.Logic.Support } public static string AddLuhnChecksum (string number) + { + return number + GetLuhnChecksum (number); + } + + public static string GetLuhnChecksum (string number) { int sum = 0; for (int i = 0; i < number.Length; i++) { - int temp = (number[i] - '0')*(((number.Length - i)%2) == 1 ? 2 : 1); + int temp = (number[i] - '0') * (((number.Length - i) % 2) == 1 ? 2 : 1); if (temp > 9) temp -= 9; sum += temp; } - return number + ((10 - (sum%10))%10); + return ((10 - (sum % 10)) % 10).ToString(CultureInfo.InvariantCulture); + } + + public static bool CheckLuhnChecksum (string number) + { + number = CleanNumber (number); + + if (number.Length < 2) + { + return false; // requires at least data and checksum + } + + if (!number.EndsWith (GetLuhnChecksum (number.Substring (0, number.Length - 1)))) + { + return false; + } + + return true; } diff --git a/Site5/Master-v5.master b/Site5/Master-v5.master index d0802183..039e52fa 100644 --- a/Site5/Master-v5.master +++ b/Site5/Master-v5.master @@ -214,6 +214,10 @@ + + + + diff --git a/Site5/Pages/v5/Admin/OrgSettings.aspx b/Site5/Pages/v5/Admin/OrgSettings.aspx index a759a8e8..e6567690 100644 --- a/Site5/Pages/v5/Admin/OrgSettings.aspx +++ b/Site5/Pages/v5/Admin/OrgSettings.aspx @@ -235,9 +235,9 @@

Regulatory stuff (optional)

- ​
+ ​
​
- ​
+ ​
Org registration #
diff --git a/Site5/Pages/v5/Admin/OrgSettings.aspx.cs b/Site5/Pages/v5/Admin/OrgSettings.aspx.cs index 452814a7..442b56ed 100644 --- a/Site5/Pages/v5/Admin/OrgSettings.aspx.cs +++ b/Site5/Pages/v5/Admin/OrgSettings.aspx.cs @@ -427,6 +427,18 @@ namespace Swarmops.Frontend.Pages.v5.Admin authenticationData.CurrentOrganization.PaypalAccountMailAddress = result.NewData; break; + case "GovernmentRegistrationId": + result.NewData = newValue.Trim(); + result.ResultCode = AjaxTextBox.CodeSuccess; + authenticationData.CurrentOrganization.GovernmentRegistrationId = result.NewData; + break; + + case "TaxPaymentOcr": + result.NewData = newValue.Trim(); + result.ResultCode = AjaxTextBox.CodeSuccess; + authenticationData.CurrentOrganization.TaxPaymentOcr = result.NewData; + break; + default: throw new NotImplementedException("Unknown cookie in StoreCallback"); } diff --git a/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs b/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs index 3c191e69..236dfa06 100644 --- a/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs +++ b/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs @@ -69,11 +69,11 @@ namespace Swarmops.Frontend.Pages.Financial "\"reference\":\"{5}\"," + "\"amount\":\"{6:N2}\"," + "\"action\":\"" + - "" + - "" + - "" + - "" + - "" + + "" + + "" + + "" + + "" + + "" + "\"", payout.ProtoIdentity, (payout.ExpectedTransactionDate <= today @@ -115,11 +115,11 @@ namespace Swarmops.Frontend.Pages.Financial "\"reference\":\"{5}\"," + "\"amount\":\"{6:N2}\"," + "\"action\":\"" + - "" + - "" + - "" + - "" + - "" + + "" + + "" + + "" + + "" + + "" + "\"", payout.ProtoIdentity, payout.ExpectedTransactionDate.ToShortDateString(), diff --git a/Site5/Pages/v5/Financial/Json-PayableCostsOcr.aspx b/Site5/Pages/v5/Financial/Json-PayableCostsOcr.aspx new file mode 100644 index 00000000..bc8230e2 --- /dev/null +++ b/Site5/Pages/v5/Financial/Json-PayableCostsOcr.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-PayableCostsOcr.aspx.cs" Inherits="Swarmops.Frontend.Pages.Financial.JsonPayableCostsOcr" %> diff --git a/Site5/Pages/v5/Financial/Json-PayableCostsOcr.aspx.cs b/Site5/Pages/v5/Financial/Json-PayableCostsOcr.aspx.cs new file mode 100644 index 00000000..29051433 --- /dev/null +++ b/Site5/Pages/v5/Financial/Json-PayableCostsOcr.aspx.cs @@ -0,0 +1,126 @@ +using System; +using System.Globalization; +using System.Text; +using Resources; +using Swarmops.Logic.Financial; +using Swarmops.Logic.Security; + +namespace Swarmops.Frontend.Pages.Financial +{ + public partial class JsonPayableCostsOcr : DataV5Base + { + protected void Page_Load (object sender, EventArgs e) + { + // Access required is change access to financials + + PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Financials, AccessType.Write); + + // Get all payable items + + Payouts prototypePayouts = Payouts.Construct (CurrentOrganization); + Payouts previousPayouts = Payouts.ForOrganization (CurrentOrganization); // gets all currently open payouts - enabled for undoing + + // Format as JSON and return + + string elements = FormatPrototypesAsJson (prototypePayouts); + + Response.ContentType = "application/json"; + string json = "{\"rows\":[" + elements + "]}"; + Response.Output.WriteLine (json); + Response.End(); + } + + private string FormatPrototypesAsJson (Payouts payouts) + { + StringBuilder result = new StringBuilder (16384); + + DateTime today = DateTime.Today; + bool bitcoinHotWalletActive = (this.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot != null + ? true + : false); + + foreach (Payout payout in payouts) + { + if (bitcoinHotWalletActive && payout.RecipientPerson != null && payout.RecipientPerson.BitcoinPayoutAddress.Length > 0 && payout.Account.Length < 4) // 4 because an empty account will be " / ", length 3 + { + // This is a person who will be paid in bitcoin per personal preferences, so don't show for manual payout + + continue; + } + + if (bitcoinHotWalletActive && payout.Account.StartsWith ("bitcoin:")) + { + // This is a payout registered to be paid in bitcoin, so don't show for manual payout + + continue; + } + + if (payout.Reference.Length < 2) + { + continue; // must have at least a reference and a checksum - two digits minimum + } + + if (!Swarmops.Logic.Support.Formatting.CheckLuhnChecksum (payout.Reference)) + { + // invalid checksum + + continue; + } + + if (!Swarmops.Logic.Support.Formatting.CheckLuhnChecksum (payout.Account)) + { + continue; + } + + result.Append ("{"); + result.AppendFormat ( + "\"itemId\":\"{0}\"," + + "\"due\":\"{1}\"," + + "\"reference\":\"{2}\"," + + "\"amount\":\"{3}\"," + + "\"account\":\"{4}\"," + + "\"action\":\"" + + "" + + "" + + "" + + "" + + "" + + "\"" , + payout.ProtoIdentity, + (payout.ExpectedTransactionDate <= today + ? Global.Global_ASAP + : payout.ExpectedTransactionDate.ToShortDateString()), + GetReferenceOcr (payout), + GetAmountOcr (payout), + GetAccountOcr (payout), + payout.ProtoIdentity.Replace ("|", "")); + result.Append ("},"); + } + + if (result.Length > 0) + { + result.Remove (result.Length - 1, 1); // remove last comma, if there are any elements + } + + return result.ToString(); + } + + private string GetReferenceOcr (Payout payout) + { + return payout.Reference + " # "; + } + + private string GetAmountOcr (Payout payout) + { + return string.Format ("{0} {1:00}   {2} >", + payout.AmountCents/100, payout.AmountCents %100, + Swarmops.Logic.Support.Formatting.GetLuhnChecksum ( + payout.AmountCents.ToString (CultureInfo.InvariantCulture))); + } + + private string GetAccountOcr (Payout payout) + { + return Swarmops.Logic.Support.Formatting.CleanNumber (payout.Account) + "#41#"; + } + } +} \ No newline at end of file diff --git a/Site5/Pages/v5/Financial/PayOutMoney.aspx b/Site5/Pages/v5/Financial/PayOutMoney.aspx index f700af9c..5236f536 100644 --- a/Site5/Pages/v5/Financial/PayOutMoney.aspx +++ b/Site5/Pages/v5/Financial/PayOutMoney.aspx @@ -2,6 +2,12 @@ + + + + + + -

- - - - - - - - - - - - -
+
+

+ + + + + + + + + + + + +
+
+
+

+ + + + + + + + + + +
+
@@ -219,6 +270,9 @@ +