Enough code (and hacks) to bring ledgers UTD
This commit is contained in:
@@ -54,7 +54,7 @@ namespace Swarmops.Logic.Financial
|
||||
}
|
||||
}
|
||||
|
||||
public decimal BalanceCentsDelta
|
||||
public long BalanceCentsDelta
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -15,12 +15,17 @@ namespace Swarmops.Logic.Financial
|
||||
// empty ctor
|
||||
}
|
||||
|
||||
public static PaymentGroup FromIdentity (int paymentGroupId)
|
||||
public static PaymentGroup FromIdentity(int paymentGroupId)
|
||||
{
|
||||
return FromBasic(SwarmDb.GetDatabaseForReading().GetPaymentGroup(paymentGroupId));
|
||||
}
|
||||
|
||||
public static PaymentGroup FromBasic (BasicPaymentGroup basic)
|
||||
private static PaymentGroup FromIdentityAggressive(int paymentGroupId)
|
||||
{
|
||||
return FromBasic(SwarmDb.GetDatabaseForWriting().GetPaymentGroup(paymentGroupId)); // "For writing" intentional - solves race conditions on create
|
||||
}
|
||||
|
||||
public static PaymentGroup FromBasic(BasicPaymentGroup basic)
|
||||
{
|
||||
return new PaymentGroup(basic);
|
||||
}
|
||||
@@ -28,9 +33,9 @@ namespace Swarmops.Logic.Financial
|
||||
public static PaymentGroup Create (Organization organization, DateTime timestamp, Currency currency, Person createdByPerson)
|
||||
{
|
||||
return
|
||||
FromIdentity(SwarmDb.GetDatabaseForWriting().CreatePaymentGroup(organization.Identity, timestamp,
|
||||
FromIdentityAggressive(SwarmDb.GetDatabaseForWriting().CreatePaymentGroup(organization.Identity, timestamp,
|
||||
currency.Identity,
|
||||
System.DateTime.Now, createdByPerson.Identity));
|
||||
System.DateTime.Now, createdByPerson == null? 0: createdByPerson.Identity));
|
||||
}
|
||||
|
||||
public static PaymentGroup FromTag (Organization organization, string tag)
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Swarmops.Basic.Enums;
|
||||
using Swarmops.Basic.Types;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Support;
|
||||
using Swarmops.Logic.Support.LogEntries;
|
||||
|
||||
namespace Swarmops.Logic.Financial
|
||||
{
|
||||
@@ -50,5 +55,41 @@ namespace Swarmops.Logic.Financial
|
||||
{
|
||||
return FromArray(SwarmDb.GetDatabaseForReading().GetPayroll(includeClosed? DatabaseCondition.None : DatabaseCondition.OpenTrue));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes all payroll for all organizations system-wide. Should run on the 1st of every month.
|
||||
/// </summary>
|
||||
public static void ProcessMonthly()
|
||||
{
|
||||
DateTime today = DateTime.UtcNow;
|
||||
|
||||
string lastRun = Persistence.Key["LastSalaryRun"];
|
||||
|
||||
string expectedLastRun = today.ToString("yyyyMM", CultureInfo.InvariantCulture);
|
||||
|
||||
if (lastRun != null && String.Compare(lastRun, expectedLastRun, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase) >= 0)
|
||||
{
|
||||
// nothing to do, return
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Persistence.Key["LastSalaryRun"] = expectedLastRun;
|
||||
|
||||
// Process the payroll for all organizations. Assume payday is 25th.
|
||||
// TODO: Different payday per organization?
|
||||
|
||||
Payroll payroll = Payroll.GetAll();
|
||||
DateTime payday = new DateTime(today.Year, today.Month, 25);
|
||||
|
||||
foreach (PayrollItem payrollItem in payroll)
|
||||
{
|
||||
Salary salary = Salary.Create(payrollItem, payday);
|
||||
SwarmopsLog.CreateEntry(payrollItem.Person, new SalaryCreatedLogEntry(salary));
|
||||
|
||||
// TODO: CREATE SALARY SPECIFICATION, SEND TO PERSON
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,6 +224,7 @@
|
||||
<Compile Include="Support\Imagery.cs" />
|
||||
<Compile Include="Support\IXmlPayload.cs" />
|
||||
<Compile Include="Support\LogEntries\CashAdvanceRequestedLogEntry.cs" />
|
||||
<Compile Include="Support\LogEntries\SalaryCreatedLogEntry.cs" />
|
||||
<Compile Include="Support\LogEntries\InboundInvoiceCreatedLogEntry.cs" />
|
||||
<Compile Include="Support\LogEntries\ExpenseClaimFiledLogEntry.cs" />
|
||||
<Compile Include="Support\LogEntries\FinancialActionBase.cs" />
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Swarmops.Logic.Financial;
|
||||
|
||||
namespace Swarmops.Logic.Support.LogEntries
|
||||
{
|
||||
[Serializable]
|
||||
public class SalaryCreatedLogEntry: FinancialActionBase
|
||||
{
|
||||
[Obsolete("Do not call this constructor directly.", true)]
|
||||
public SalaryCreatedLogEntry()
|
||||
{
|
||||
// empty ctor needed for serializability; should not be called
|
||||
}
|
||||
|
||||
public SalaryCreatedLogEntry(Salary salary)
|
||||
{
|
||||
this.ActingPersonId = 0;
|
||||
this.BeneficiaryPersonId = salary.PayrollItem.PersonId;
|
||||
this.Amount = salary.NetSalaryCents/100.0;
|
||||
this.Currency = salary.Budget.Organization.Currency.Code;
|
||||
this.DateTime = DateTime.UtcNow;
|
||||
this.FinancialAccountId = salary.Budget.Identity;
|
||||
this.FinancialAccountName = salary.Budget.Name;
|
||||
this.OrganizationId = salary.PayrollItem.OrganizationId;
|
||||
this.OwnerPersonId = salary.PayrollItem.ReportsToPersonId;
|
||||
this.OwnerPersonName = salary.PayrollItem.ReportsToPerson.Canonical;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,6 +181,7 @@ public partial class Pages_Public_Handlers_PaysonIpnListener : System.Web.UI.Pag
|
||||
Payment payment = Payment.CreateSingle(invoice.Organization, DateTime.Now, invoice.Currency,
|
||||
expectedNetCents, invoice, null); // HACK HACK HACK: says we always received the expected amount
|
||||
transaction.Dependency = payment.Group;
|
||||
payment.Group.Open = false;
|
||||
}
|
||||
else if (fee > 0.0)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TemporaryHack.aspx.cs" Inherits="Pages_v5_Admin_Hacks_TemporaryHack" %>
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head runat="server">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<form id="form1" runat="server">
|
||||
<div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
// This page executes code on page load. Used for various tests of logic. Not supposed to ever be linked from something.
|
||||
using Swarmops.Logic.Financial;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
public partial class Pages_v5_Admin_Hacks_TemporaryHack : System.Web.UI.Page
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
FinancialAccount bankAccount = FinancialAccount.FromIdentity(29);
|
||||
Organization euroPirates = Organization.FromIdentity(7);
|
||||
|
||||
FinancialTransactions unbalancedTransactions = FinancialTransactions.GetUnbalanced(euroPirates);
|
||||
|
||||
// assume all in bank account
|
||||
|
||||
foreach (FinancialTransaction transaction in unbalancedTransactions)
|
||||
{
|
||||
if (transaction.Description[0] == 'H' && Char.IsDigit(transaction.Description[1]) && transaction.Rows.BalanceCentsDelta > 0)
|
||||
{
|
||||
// outbound intl invoice. Add an untracked intl invoice 10 days prior, map it to this
|
||||
|
||||
OutboundInvoice newInvoice = OutboundInvoice.Create(euroPirates, Person.FromIdentity(1),
|
||||
transaction.DateTime, euroPirates.FinancialAccounts.IncomeSales, "Untracked",
|
||||
"untracked@example.com", string.Empty, euroPirates.Currency, false, string.Empty);
|
||||
newInvoice.AddItem("Untracked item", transaction.Rows.BalanceCentsDelta);
|
||||
|
||||
// Doesn't close
|
||||
|
||||
// Add transaction
|
||||
|
||||
// Create the financial transaction with rows
|
||||
|
||||
FinancialTransaction invoiceTransaction =
|
||||
FinancialTransaction.Create(euroPirates.Identity, transaction.DateTime.AddDays(-10),
|
||||
"Outbound Invoice #" + newInvoice.Identity);
|
||||
|
||||
invoiceTransaction.AddRow(euroPirates.FinancialAccounts.AssetsOutboundInvoices, newInvoice.AmountCents, null);
|
||||
invoiceTransaction.AddRow(euroPirates.FinancialAccounts.IncomeSales, -newInvoice.AmountCents, null);
|
||||
invoiceTransaction.Dependency = newInvoice;
|
||||
|
||||
transaction.AddRow(euroPirates.FinancialAccounts.AssetsOutboundInvoices, -newInvoice.AmountCents, null);
|
||||
|
||||
Payment payment = Payment.CreateSingle(euroPirates, transaction.DateTime, euroPirates.Currency,
|
||||
newInvoice.AmountCents, newInvoice, null);
|
||||
|
||||
transaction.Dependency = payment.Group;
|
||||
payment.Group.Open = false;
|
||||
|
||||
}
|
||||
|
||||
if (transaction.Description == "Kostnad" && transaction.Rows.BalanceCentsDelta < 0 &&
|
||||
transaction.Rows.BalanceCentsDelta > -10000)
|
||||
{
|
||||
// Bank fee.
|
||||
|
||||
transaction.AddRow(euroPirates.FinancialAccounts.CostsBankFees, -transaction.Rows.BalanceCentsDelta,
|
||||
null);
|
||||
}
|
||||
|
||||
if (transaction.Description.StartsWith("Paypal "))
|
||||
{
|
||||
// Bank fee.
|
||||
|
||||
transaction.AddRow(euroPirates.FinancialAccounts.CostsBankFees, -transaction.Rows.BalanceCentsDelta,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
Payouts.AutomatchAgainstUnbalancedTransactions(euroPirates);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user