diff --git a/Backend/Program.cs b/Backend/Program.cs index 6ab2ddba..278114d0 100644 --- a/Backend/Program.cs +++ b/Backend/Program.cs @@ -465,7 +465,6 @@ namespace Swarmops.Backend private static void OnEveryHour() { - DateTime startTime = DateTime.Now; try { BotLog.Write (0, "MainCycle", "One-hour entry"); diff --git a/Common/Enums/ObjectOptionalDataType.cs b/Common/Enums/ObjectOptionalDataType.cs index 4097fb8b..67727d6a 100644 --- a/Common/Enums/ObjectOptionalDataType.cs +++ b/Common/Enums/ObjectOptionalDataType.cs @@ -8,7 +8,8 @@ namespace Swarmops.Common.Enums Organization, OutboundInvoice, InboundInvoice, - FinancialTransaction + FinancialTransaction, + FinancialTransactionRow } public enum ObjectOptionalDataType @@ -335,21 +336,31 @@ namespace Swarmops.Common.Enums /// /// If there's a hotwallet, its private root key (encrypted with file and db keys) /// - BudgetBitcoinPrivateRoot, + FinancialAccountBitcoinPrivateRoot, /// /// If there's another wallet, its public root key (encrypted with db key) /// - BudgetBitcoinPublicRoot, + FinancialAccountBitcoinPublicRoot, /// /// For cold wallets, we may prefer listing the public addresses directly /// - BudgetBitcoinPublicAddress, + FinancialAccountBitcoinPublicAddress, /// /// For a bitcoin transaction, its hash on the blockchain /// - FinancialTransactionBlockchainHash + FinancialTransactionBlockchainHash, + + /// + /// For a financial account, the native currency (typically bitcoin). Used for multi-currency accounting. + /// + FinancialAccountNativeCurrency, + + /// + /// For a hotwallet transaction, the complete derivation path used for this address + /// + FinancialTransactionRowBitcoinDerivationPath } } \ No newline at end of file diff --git a/Database/Configuration.cs b/Database/Configuration.cs index 620c7603..c3116f3f 100644 --- a/Database/Configuration.cs +++ b/Database/Configuration.cs @@ -14,7 +14,7 @@ namespace Swarmops.Database /// public static int DbVersionExpected { - get { return 32; } + get { return 33; } } diff --git a/Database/Database-Financials.cs b/Database/Database-Financials.cs index fe40226b..cfd641d5 100644 --- a/Database/Database-Financials.cs +++ b/Database/Database-Financials.cs @@ -949,27 +949,8 @@ namespace Swarmops.Database } } - public void CreateFinancialTransactionRow (int financialTransactionId, int financialAccountId, double amount, - int personId) - { - using (DbConnection connection = GetMySqlDbConnection()) - { - connection.Open(); - DbCommand command = GetDbCommand ("CreateFinancialTransactionRow", connection); - command.CommandType = CommandType.StoredProcedure; - - AddParameterWithName (command, "financialTransactionId", financialTransactionId); - AddParameterWithName (command, "financialAccountId", financialAccountId); - AddParameterWithName (command, "amount", amount); - AddParameterWithName (command, "dateTime", DateTime.Now); - AddParameterWithName (command, "personId", personId); - - command.ExecuteNonQuery(); - } - } - - public void CreateFinancialTransactionRow (int financialTransactionId, int financialAccountId, Int64 amountCents, + public int CreateFinancialTransactionRow (int financialTransactionId, int financialAccountId, Int64 amountCents, int personId) { using (DbConnection connection = GetMySqlDbConnection()) @@ -985,7 +966,7 @@ namespace Swarmops.Database AddParameterWithName (command, "dateTime", DateTime.Now); AddParameterWithName (command, "personId", personId); - command.ExecuteNonQuery(); + return Convert.ToInt32(command.ExecuteScalar()); } } @@ -1048,35 +1029,37 @@ namespace Swarmops.Database { connection.Open(); - DbCommand command = GetDbCommand("SetFinancialTransactionForeignId", connection); - command.CommandType = CommandType.StoredProcedure; + using (DbCommand command = GetDbCommand ("SetFinancialTransactionForeignId", connection)) + { + command.CommandType = CommandType.StoredProcedure; - AddParameterWithName(command, "financialTransactionId", financialTransactionId); - AddParameterWithName(command, "financialTransactionForeignIdType", (int) foreignIdType); - AddParameterWithName(command, "foreignId", foreignId); + AddParameterWithName (command, "financialTransactionId", financialTransactionId); + AddParameterWithName (command, "financialTransactionForeignIdType", (int) foreignIdType); + AddParameterWithName (command, "foreignId", foreignId); - command.ExecuteNonQuery(); + command.ExecuteNonQuery(); + } } } - public Int64 GetFinancialTransactionFromForeignId(FinancialForeignIdType foreignIdType, string foreignId) + public int GetFinancialTransactionFromForeignId(FinancialForeignIdType foreignIdType, string foreignId) { using (DbConnection connection = GetMySqlDbConnection()) { connection.Open(); - DbCommand command = + using (DbCommand command = GetDbCommand( - "Select FinancialTransactionId from FinancialTransactionForeignIds WHERE FinancialTransactionForeignIdType=" + (int) foreignIdType + - " AND ForeignId='" + SqlSanitize (foreignId) + "';", connection); + "Select FinancialTransactionId from FinancialTransactionForeignIds WHERE FinancialTransactionForeignIdType=" + (int)foreignIdType + + " AND ForeignId='" + SqlSanitize(foreignId) + "';", connection)) using (DbDataReader reader = command.ExecuteReader()) { if (reader.Read()) { - return reader.GetInt32 (0); + return reader.GetInt32(0); } return 0; // none found. Todo: throw exception instead? This behavior is inconsistent @@ -1086,7 +1069,53 @@ namespace Swarmops.Database - public DateTime GetFinancialAccountFirstTransactionDate (int financialAccountId) + public Int64 GetFinancialTransactionRowNativeAmountCents(int financialTransactionRowId, int currencyId) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + using (DbCommand command = + GetDbCommand( + "Select NativeAmountCents from FinancialTransactionRows WHERE FinancialTransactionRowId=" + financialTransactionRowId + + " AND CurrencyId =" + currencyId + ";", connection)) + + using (DbDataReader reader = command.ExecuteReader()) + { + if (reader.Read()) + { + return reader.GetInt64(0); + } + + return 0; // none found. Todo: throw exception instead? This behavior is inconsistent + } + } + } + + + + public void SetFinancialTransactionRowNativeAmountCents(int financialTransactionRowId, int currencyId, Int64 nativeAmountCents) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + using (DbCommand command = GetDbCommand("SetFinancialTransactionRowNativeCurrency", connection)) + { + command.CommandType = CommandType.StoredProcedure; + + AddParameterWithName(command, "financialTransactionRowId", financialTransactionRowId); + AddParameterWithName(command, "currencyId", currencyId); + AddParameterWithName(command, "nativeAmountCents", nativeAmountCents); + + command.ExecuteNonQuery(); + } + } + } + + + + public DateTime GetFinancialAccountFirstTransactionDate(int financialAccountId) { using (DbConnection connection = GetMySqlDbConnection()) { diff --git a/Database/Schemata/revisions.txt b/Database/Schemata/revisions.txt index 8b4dcc26..8baeb4f8 100644 --- a/Database/Schemata/revisions.txt +++ b/Database/Schemata/revisions.txt @@ -29,4 +29,5 @@ 0029 - Added unspent satoshis to hotaddress on create unspent [RF] 0030 - Added flexibility for Resolver classes for OutboundComms [RF] 0031 - Added foreign ID tables, procs for transactions, to track blockchain [RF] -0032 - Added native currency to transaction rows, for multi-currency accounting [RF] \ No newline at end of file +0032 - Added native currency to transaction rows, for multi-currency accounting [RF] +0033 - Added transaction row identity return, necessary for 0032 [RF] \ No newline at end of file diff --git a/Database/Schemata/upgrade-0033.sql b/Database/Schemata/upgrade-0033.sql new file mode 100644 index 00000000..73fbca6e --- /dev/null +++ b/Database/Schemata/upgrade-0033.sql @@ -0,0 +1,21 @@ +DROP procedure IF EXISTS `CreateFinancialTransactionRowPrecise` + + +# + + +CREATE PROCEDURE `CreateFinancialTransactionRowPrecise`( + IN financialTransactionId INTEGER, + IN financialAccountId INTEGER, + IN amountCents BIGINT, + IN dateTime DATETIME, + IN personId INTEGER +) +BEGIN + + INSERT INTO FinancialTransactionRows (FinancialAccountId, FinancialTransactionId, Amount, AmountCents, CreatedDateTime, CreatedByPersonId) + VALUES (financialAccountId, financialTransactionid, amountCents/100.0, amountCents, dateTime, personId); + + SELECT LAST_INSERT_ID() AS Identity; + +END diff --git a/Logic/Communications/Payload/NotificationPayload.cs b/Logic/Communications/Payload/NotificationPayload.cs index a156577e..9c6816a0 100644 --- a/Logic/Communications/Payload/NotificationPayload.cs +++ b/Logic/Communications/Payload/NotificationPayload.cs @@ -86,8 +86,11 @@ namespace Swarmops.Logic.Communications.Payload { // TODO: Check if string ends in Float, and if so, parse and culturize it - input = input.Replace ("[" + notificationString /* this is an enum converted to string */+ "]", - Strings[notificationString]); + if (!String.IsNullOrEmpty (Strings[notificationString])) + { + input = input.Replace ("[" + notificationString /* this is an enum converted to string */+ "]", + Strings[notificationString]); + } } } @@ -95,10 +98,13 @@ namespace Swarmops.Logic.Communications.Payload { foreach (string notificationCustomString in CustomStrings.Keys) { - input = - input.Replace ( - "[" + notificationCustomString /* this is a System.String as opposed to above */+ "]", - CustomStrings[notificationCustomString]); + if (!String.IsNullOrEmpty (CustomStrings[notificationCustomString])) + { + input = + input.Replace ( + "[" + notificationCustomString /* this is a System.String as opposed to above */+ "]", + CustomStrings[notificationCustomString]); + } } } @@ -174,7 +180,10 @@ namespace Swarmops.Logic.Communications.Payload BitcoinPayoutAddress_Bad, BitcoinPayoutAddress_PleaseSet, BitcoinPayoutAddress_OfficerNotify, - BitcoinPayoutAddress_Changed + BitcoinPayoutAddress_Changed, + Salary_MonthlyStatement, + Salary_Paid, + Salary_LastYearSummary } // ReSharper restore InconsistentNaming diff --git a/Logic/Financial/BitcoinUtility.cs b/Logic/Financial/BitcoinUtility.cs index 9cec1e6f..5e72844f 100644 --- a/Logic/Financial/BitcoinUtility.cs +++ b/Logic/Financial/BitcoinUtility.cs @@ -194,8 +194,6 @@ namespace Swarmops.Logic.Financial } } - // https://blockchain.info/address/1Axd4QQhRSCMAuHe93uVKRjNSFj6WypcZa?format=json&api_key=I_am_testing_the_format_please_ignore - static private void CheckColdStorageRecurse (FinancialAccount parent) { foreach (FinancialAccount child in parent.Children) @@ -216,6 +214,8 @@ namespace Swarmops.Logic.Financial catch (Exception e) { // the name wasn't an address, so return + + return; } var addressData = @@ -225,6 +225,17 @@ namespace Swarmops.Logic.Financial // TODO: PARSE (awaiting functions for native currency to be added to FinancialTransactionRows) + int transactionCount = (int)(addressData["n_tx"]); + + foreach (var tx in addressData["txs"]) + { + string blockchainTransactionId = (string) tx["hash"]; + + FinancialTransaction ourTx = FinancialTransaction.FromBlockchainHash (parent.Organization, blockchainTransactionId); + } + + // TODO: CONTINUE HERE + } diff --git a/Logic/Financial/FinancialAccount.cs b/Logic/Financial/FinancialAccount.cs index 8dbf78c1..6b52c07f 100644 --- a/Logic/Financial/FinancialAccount.cs +++ b/Logic/Financial/FinancialAccount.cs @@ -114,6 +114,21 @@ namespace Swarmops.Logic.Financial } } + + public Currency NativeCurrency + { + get + { + int currencyId = OptionalData.GetOptionalDataInt (ObjectOptionalDataType.FinancialAccountNativeCurrency); + return (currencyId != 0 ? Currency.FromIdentity (currencyId) : null); + } + set + { + OptionalData.SetOptionalDataInt (ObjectOptionalDataType.FinancialAccountNativeCurrency, value.Identity); + } + } + + public ExternalBankDataProfile ExternalBankDataProfile { get diff --git a/Logic/Financial/FinancialTransaction.cs b/Logic/Financial/FinancialTransaction.cs index 5f6a1878..2df9e42f 100644 --- a/Logic/Financial/FinancialTransaction.cs +++ b/Logic/Financial/FinancialTransaction.cs @@ -159,6 +159,28 @@ namespace Swarmops.Logic.Financial } } + public static FinancialTransaction FromBlockchainHash (Organization organization, string blockchainTransactionHash) + { + int[] transactionIds = + SwarmDb.GetDatabaseForReading() + .GetObjectsByOptionalData (ObjectType.FinancialTransaction, + ObjectOptionalDataType.FinancialTransactionBlockchainHash, blockchainTransactionHash); + + // There may be multiple transactions in this Swarmops installation referring to this transaction on the blockchain, but only + // one per organization. So find the transaction that matches the org we want. + + foreach (int transactionId in transactionIds) + { + FinancialTransaction potentialResult = FinancialTransaction.FromIdentity (transactionId); + if (potentialResult.OrganizationId == organization.Identity) + { + return potentialResult; + } + } + + throw new ArgumentException("No match for supplied blockchain tx hash and organization"); + } + public IHasIdentity Dependency { set @@ -229,18 +251,20 @@ namespace Swarmops.Logic.Financial AddRow (account, (Int64) (amount*100), person); } - public void AddRow (FinancialAccount account, Int64 amountCents, Person person) + public FinancialTransactionRow AddRow (FinancialAccount account, Int64 amountCents, Person person) { - AddRow (account.Identity, amountCents, person != null ? person.Identity : 0); + return AddRow (account.Identity, amountCents, person != null ? person.Identity : 0); } - private void AddRow (int financialAccountId, Int64 amountCents, int personId) + private FinancialTransactionRow AddRow (int financialAccountId, Int64 amountCents, int personId) { if (DateTime.Year <= FinancialAccount.FromIdentity (financialAccountId).Organization.Parameters.FiscalBooksClosedUntilYear) { // Recurse down into continuation transactions to write row in first nonclosed year + FinancialTransactionRow newRow = null; + FinancialTransaction transactionContinued = ContinuedTransaction; if (transactionContinued == null) @@ -249,21 +273,21 @@ namespace Swarmops.Logic.Financial transactionContinued = Create (OrganizationId, DateTime.Now, "Continued Tx #" + Identity); - transactionContinued.AddRow (financialAccountId, amountCents, personId); + newRow = transactionContinued.AddRow (financialAccountId, amountCents, personId); transactionContinued.Dependency = this; } else { // Recurse - transactionContinued.AddRow (financialAccountId, amountCents, personId); + newRow = transactionContinued.AddRow (financialAccountId, amountCents, personId); } - return; + return newRow; } - SwarmDb.GetDatabaseForWriting() - .CreateFinancialTransactionRow (Identity, financialAccountId, amountCents, personId); + return FinancialTransactionRow.FromIdentityAggressive (SwarmDb.GetDatabaseForWriting() + .CreateFinancialTransactionRow (Identity, financialAccountId, amountCents, personId)); } public void AddDocument (string serverFileName, string originalFileName, Int64 fileSize, string description, diff --git a/Logic/Financial/FinancialTransactionRow.cs b/Logic/Financial/FinancialTransactionRow.cs index f58100ca..f54c986e 100644 --- a/Logic/Financial/FinancialTransactionRow.cs +++ b/Logic/Financial/FinancialTransactionRow.cs @@ -59,6 +59,21 @@ namespace Swarmops.Logic.Financial } } + public Money NativeAmountCents + { + get + { + Currency currency = this.Account.NativeCurrency; + int currencyId = currency.Identity; + Int64 nativeCents = SwarmDb.GetDatabaseForReading().GetFinancialTransactionRowNativeAmountCents (this.Identity, currencyId); + return new Money(nativeCents, currency, this.CreatedDateTime); // includes the valuation datetime, as it's a non-org currency + } + set + { + SwarmDb.GetDatabaseForWriting().SetFinancialTransactionRowNativeAmountCents (this.Identity, value.Currency.Identity, value.Cents); + } + } + [Obsolete ("Do not use. Use Int64 AmountCents.", true)] public decimal Amount { @@ -70,9 +85,14 @@ namespace Swarmops.Logic.Financial return new FinancialTransactionRow (basic); } - public static FinancialTransactionRow FromIdentity (int identity) + public static FinancialTransactionRow FromIdentity(int identity) { - return FromBasic (SwarmDb.GetDatabaseForReading().GetFinancialTransactionRow (identity)); + return FromBasic(SwarmDb.GetDatabaseForReading().GetFinancialTransactionRow(identity)); + } + + public static FinancialTransactionRow FromIdentityAggressive(int identity) + { + return FromBasic(SwarmDb.GetDatabaseForWriting().GetFinancialTransactionRow(identity)); // "For writing" is intentional } } } \ No newline at end of file diff --git a/Logic/Financial/Payroll.cs b/Logic/Financial/Payroll.cs index 6fc1f0be..85cd41b1 100644 --- a/Logic/Financial/Payroll.cs +++ b/Logic/Financial/Payroll.cs @@ -92,6 +92,10 @@ namespace Swarmops.Logic.Financial // TODO: CREATE SALARY SPECIFICATION, SEND TO PERSON } + + // If this is January, also send the annual statements for last year + + Salaries.CreateAnnualStatements (today.Year-1); } } } \ No newline at end of file diff --git a/Logic/Financial/Salaries.cs b/Logic/Financial/Salaries.cs index ef91c1c8..5d9cfd01 100644 --- a/Logic/Financial/Salaries.cs +++ b/Logic/Financial/Salaries.cs @@ -1,10 +1,15 @@ using System; +using System.Collections.Generic; +using System.Globalization; using System.Linq; using Swarmops.Basic.Types; using Swarmops.Basic.Types.Financial; using Swarmops.Database; +using Swarmops.Logic.Communications; +using Swarmops.Logic.Communications.Payload; using Swarmops.Logic.Structure; using Swarmops.Logic.Support; +using Swarmops.Logic.Swarm; namespace Swarmops.Logic.Financial { @@ -64,5 +69,95 @@ namespace Swarmops.Logic.Financial return FromArray (SwarmDb.GetDatabaseForReading().GetSalaries (organization, includeClosed ? DatabaseCondition.None : DatabaseCondition.OpenTrue)); } + + public static void CreateAnnualStatements (int year) + { + // This function is supposed to be running once a year, and summarize the past year of salaries. + + // Get all organizations. + + Organizations organizations = Organizations.GetAll(); + + foreach (Organization organization in organizations) + { + // Get all salaries for this organization (filter year in logic - this function is allowed to be expensive, rather than + // adding a custom database query for this particular operation) + + Salaries allSalaries = ForOrganization (organization, true); + + Salaries yearSalaries = new Salaries(); + yearSalaries.AddRange (allSalaries.Where (salary => salary.PayoutDate.Year == year)); + + Dictionary> personSalaryLookup = new Dictionary>(); + + // Go through the salaries and store them in the dictionary, so we can process the statement by person later + + foreach (Salary salary in yearSalaries) + { + int personId = salary.PayrollItem.PersonId; + + if (!personSalaryLookup.ContainsKey (personId)) + { + personSalaryLookup[personId] = new Dictionary(); + } + + personSalaryLookup[personId][salary.PayoutDate.Month] = salary; + } + + // Once here, salaries are arranged by person and month. Iterate over people, create statements. + + foreach (int personId in personSalaryLookup.Keys) + { + Person person = Person.FromIdentity (personId); + Int64 grossTotal = 0; + Int64 subTaxTotal = 0; + Int64 addTaxTotal = 0; + Int64 netTotal = 0; + + string preFormattedStatement = string.Empty; + + for (int monthNumber = 1; monthNumber <= 12; monthNumber++) + { + string monthName = new DateTime (year, monthNumber, 1).ToString ("MMM", + new CultureInfo (person.PreferredCulture)); + string lineItem = " " + monthName; + + if (personSalaryLookup[personId].ContainsKey (monthNumber) && personSalaryLookup[personId][monthNumber].GrossSalaryCents > 0) + { + Salary monthSalary = personSalaryLookup[personId][monthNumber]; + + // TODO: replace "bitcoin" with actual payout method - this is just for show at the moment + + lineItem += String.Format (" {0,8:N2} {1,9:N2} {2,8:N2} bitcoin", + monthSalary.GrossSalaryCents/100.0, -monthSalary.SubtractiveTaxCents/100.0, + monthSalary.NetSalaryCents/100.0); + + grossTotal += monthSalary.GrossSalaryCents; + addTaxTotal += monthSalary.AdditiveTaxCents; + subTaxTotal += monthSalary.SubtractiveTaxCents; + netTotal += monthSalary.NetSalaryCents; + } + + preFormattedStatement += lineItem + "\r\n"; + } + + NotificationStrings notificationStrings = new NotificationStrings(); + NotificationCustomStrings customStrings = new NotificationCustomStrings(); + + notificationStrings[NotificationString.CurrencyCode] = organization.Currency.DisplayCode; + notificationStrings[NotificationString.EmbeddedPreformattedText] = preFormattedStatement; + customStrings["LastYear"] = year.ToString(CultureInfo.InvariantCulture); + customStrings["GrossSalaryTotal"] = String.Format("{0:N2,8}", grossTotal / 100.0); + customStrings["TaxDeductedTotal"] = String.Format("{0:N2,9}", -subTaxTotal / 100.0); + customStrings["NetSalaryTotal"] = String.Format("{0:N2,8}", netTotal / 100.0); + customStrings["TaxAdditiveTotalUnpadded"] = String.Format("{0:N2}", addTaxTotal / 100.0); + + // Send notification + + OutboundComm.CreateNotification (organization, NotificationResource.Salary_LastYearSummary, + notificationStrings, customStrings, People.FromSingle (Person.FromIdentity (1))); + } + } + } } } \ No newline at end of file diff --git a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs index df7967f7..bba692d5 100644 --- a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs +++ b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs @@ -685,6 +685,28 @@ namespace Swarmops.Logic.Resources { } } + /// + /// Looks up a localized string similar to This is your summary salary statement for [LastYear]. It is not a statement of a new salary, but a statement of the monthly salaries paid to you over the course of the last year as well as any taxes deducted. The purpose of this statement is to serve as data for your records and/or for tax declaration purposes for last year. + /// + ///Gross salary for [LastYear]: [CurrencyCode] [GrossSalaryTotal] + ///Tax deducted therefrom: [CurrencyCode] [TaxDeductedTotal] + ///Net salary paid out: [CurrencyCode] [NetSalaryTotal] [rest of string was truncated]";. + /// + internal static string Salary_LastYearSummary_Body { + get { + return ResourceManager.GetString("Salary_LastYearSummary_Body", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to [[OrganizationName]] Salary summary statement for [LastYear]. + /// + internal static string Salary_LastYearSummary_Subject { + get { + return ResourceManager.GetString("Salary_LastYearSummary_Subject", resourceCulture); + } + } + /// /// Looks up a localized string similar to Swarmops Backend [SwarmopsVersion] on host [HostName] has successfully upgraded the Swarmops database schema to revision [DbVersion]. /// diff --git a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx index 7fb7e922..abb8cf13 100644 --- a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx +++ b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx @@ -382,6 +382,27 @@ Please log on to [InstallationName] at [ExternalUrl]Financial/ValidateReceipts t [[OrganizationName] - ACTION ITEM] Receipts Filed - Validation Needed ACTION ITEM should be translated. + + This is your summary salary statement for [LastYear]. It is not a statement of a new salary, but a statement of the monthly salaries paid to you over the course of the last year as well as any taxes deducted. The purpose of this statement is to serve as data for your records and/or for tax declaration purposes for last year. + +Gross salary for [LastYear]: [CurrencyCode] [GrossSalaryTotal] +Tax deducted therefrom: [CurrencyCode] [TaxDeductedTotal] +Net salary paid out: [CurrencyCode] [NetSalaryTotal] + + +Month Gross Deducted Net Paid using +----- ---------- ----------- ---------- ----------- +[EmbeddedPreformattedText] + +TOTAL [GrossSalaryTotal] [TaxDeductedTotal] [NetSalaryTotal] + + +In addition, [CurrencyCode] [TaxAdditiveTotalUnpadded] have been paid in taxes by the organization for your employment. This is also a tax on your salary, even if its nature as such has been bureaucratically concealed. + Note the hard spacing - maintain character count to align columns and elements. + + + [[OrganizationName]] Salary summary statement for [LastYear] + Swarmops Backend [SwarmopsVersion] on host [HostName] has successfully upgraded the Swarmops database schema to revision [DbVersion]. diff --git a/Site5/Master-v5.master.cs b/Site5/Master-v5.master.cs index 6430f335..1212e84c 100644 --- a/Site5/Master-v5.master.cs +++ b/Site5/Master-v5.master.cs @@ -36,6 +36,10 @@ namespace Swarmops Response.Redirect("/", true); } + // Test code + + // Salaries.CreateAnnualStatements (2015); + // Ugly ugly UGLY legacy: Do not allow Sandbox logins on first pilot - it's broken if (this._authority.Organization.Identity == 3 && diff --git a/Site5/Pages/v5/Financial/Donate.aspx.cs b/Site5/Pages/v5/Financial/Donate.aspx.cs index 96429b4d..0b56a009 100644 --- a/Site5/Pages/v5/Financial/Donate.aspx.cs +++ b/Site5/Pages/v5/Financial/Donate.aspx.cs @@ -98,6 +98,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial { HotBitcoinAddressUnspents unspents = HotBitcoinAddress.FromAddress (bitcoinAddress).Unspents; + // TODO: Update the HotBitcoinAddress with the new amount? + Int64 satoshisReceived = unspents.Last().AmountSatoshis; if (unspents.Last().TransactionHash != txHash && txHash.Length > 0) @@ -106,9 +108,12 @@ namespace Swarmops.Frontend.Pages.v5.Financial Debugger.Break(); } - Swarmops.Logic.Financial.Money moneyReceived = new Swarmops.Logic.Financial.Money (satoshisReceived, + Swarmops.Logic.Financial.Money moneyReceived = new Swarmops.Logic.Financial.Money(satoshisReceived, Currency.Bitcoin); + // Make sure that the hotwallet native currency is bitcoin + authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot.NativeCurrency = Currency.Bitcoin; + // Create success message and ledger transaction string successMessage = string.Empty; @@ -137,15 +142,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial { // The ledger is NOT native bitcoin, so we'll need to convert currencies - long nativeCents = moneyReceived.ToCurrency (authData.CurrentOrganization.Currency).Cents; + long orgNativeCents = moneyReceived.ToCurrency (authData.CurrentOrganization.Currency).Cents; FinancialTransaction ledgerTx = FinancialTransaction.Create(authData.CurrentOrganization, DateTime.UtcNow, "Donation (bitcoin to hotwallet)"); - ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.IncomeDonations, -nativeCents, authData.CurrentUser); - ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, nativeCents, authData.CurrentUser); + ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.IncomeDonations, -orgNativeCents, authData.CurrentUser); + ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, orgNativeCents, authData.CurrentUser).NativeAmountCents = new Swarmops.Logic.Financial.Money(satoshisReceived, Currency.Bitcoin); ledgerTx.BlockchainHash = txHash; successMessage = string.Format (Resources.Pages.Financial.Donate_FundsReceived, - authData.CurrentOrganization.Currency.DisplayCode, nativeCents/100.0, satoshisReceived/100.0); + authData.CurrentOrganization.Currency.DisplayCode, orgNativeCents/100.0, satoshisReceived/100.0); } return new AjaxCallResult() {DisplayMessage = successMessage, Success = true};