Integrated cash advances into expense claim payout
This commit is contained in:
@@ -41,6 +41,10 @@ namespace Swarmops.Basic.Enums
|
||||
/// <summary>
|
||||
/// A cash advance (prior payment, rather than doing an expense claim post purchase)
|
||||
/// </summary>
|
||||
CashAdvance
|
||||
CashAdvance,
|
||||
/// <summary>
|
||||
/// A payback for a previous cash advance
|
||||
/// </summary>
|
||||
CashAdvancePayback
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,31 @@ namespace Swarmops.Logic.Financial
|
||||
}
|
||||
}
|
||||
|
||||
public CashAdvances WherePaid
|
||||
{
|
||||
get
|
||||
{
|
||||
CashAdvances result = new CashAdvances();
|
||||
result.AddRange(this.Where(cashAdvance => cashAdvance.PaidOut));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public CashAdvances WhereUnpaid
|
||||
{
|
||||
get
|
||||
{
|
||||
CashAdvances result = new CashAdvances();
|
||||
result.AddRange(this.Where(cashAdvance => !cashAdvance.PaidOut));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public Int64 TotalAmountCents
|
||||
{
|
||||
get { return this.Sum(cashAdvance => cashAdvance.AmountCents); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,8 +368,6 @@ namespace Swarmops.Logic.Financial
|
||||
|
||||
nominalTransaction[debtAccountId] = -AmountCents;
|
||||
nominalTransaction[BudgetId] = AmountCents;
|
||||
|
||||
// TODO: Balance cost account, too
|
||||
}
|
||||
|
||||
this.FinancialTransaction.RecalculateTransaction(nominalTransaction, updatingPerson);
|
||||
|
||||
+62
-27
@@ -47,7 +47,8 @@ namespace Swarmops.Logic.Financial
|
||||
DependentInvoices = new InboundInvoices();
|
||||
DependentSalariesNet = new Salaries();
|
||||
DependentSalariesTax = new Salaries();
|
||||
DependentCashAdvances = new CashAdvances();
|
||||
DependentCashAdvancesPayout = new CashAdvances();
|
||||
DependentCashAdvancesPayback = new CashAdvances();
|
||||
|
||||
BasicFinancialDependency[] dependencies = SwarmDb.GetDatabaseForReading().GetPayoutDependencies(this.Identity);
|
||||
|
||||
@@ -74,7 +75,11 @@ namespace Swarmops.Logic.Financial
|
||||
break;
|
||||
|
||||
case FinancialDependencyType.CashAdvance:
|
||||
DependentCashAdvances.Add(CashAdvance.FromIdentity(dependency.ForeignId));
|
||||
DependentCashAdvancesPayout.Add(CashAdvance.FromIdentity(dependency.ForeignId));
|
||||
break;
|
||||
|
||||
case FinancialDependencyType.CashAdvancePayback:
|
||||
DependentCashAdvancesPayback.Add(CashAdvance.FromIdentity(dependency.ForeignId));
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -100,7 +105,8 @@ namespace Swarmops.Logic.Financial
|
||||
public ExpenseClaims DependentExpenseClaims;
|
||||
public Salaries DependentSalariesNet;
|
||||
public Salaries DependentSalariesTax;
|
||||
public CashAdvances DependentCashAdvances;
|
||||
public CashAdvances DependentCashAdvancesPayout;
|
||||
public CashAdvances DependentCashAdvancesPayback;
|
||||
|
||||
public decimal Amount
|
||||
{
|
||||
@@ -206,7 +212,7 @@ namespace Swarmops.Logic.Financial
|
||||
amountCents += advance.AmountCents;
|
||||
|
||||
advance.PaidOut = true;
|
||||
advance.Open = false;
|
||||
//advance.Open = false; // isn't this closed only when settling the debt? Serious bug here?
|
||||
}
|
||||
|
||||
string referenceString = string.Empty;
|
||||
@@ -233,51 +239,64 @@ namespace Swarmops.Logic.Financial
|
||||
}
|
||||
else if (components [0][0] == 'C')
|
||||
{
|
||||
// Expense claims.
|
||||
// Expense claims, possibly followed up by cash advance paybacks
|
||||
|
||||
string bank = string.Empty;
|
||||
string account = string.Empty;
|
||||
List<int> identityList = new List<int>();
|
||||
List<int> claimIdentityList = new List<int>();
|
||||
List<int> advancePaybackIdentityList = new List<int>();
|
||||
Int64 amountCents = 0;
|
||||
int organizationId = 0;
|
||||
|
||||
foreach (string component in components)
|
||||
{
|
||||
int claimId = Int32.Parse(component.Substring(1));
|
||||
ExpenseClaim claim = ExpenseClaim.FromIdentity(claimId);
|
||||
identityList.Add(claimId);
|
||||
int foreignId = Int32.Parse(component.Substring(1));
|
||||
|
||||
if (bank.Length < 1)
|
||||
if (component[0] == 'C')
|
||||
{
|
||||
Person claimer = claim.Claimer;
|
||||
bank = claimer.BankName;
|
||||
account = claimer.BankAccount;
|
||||
organizationId = claim.OrganizationId;
|
||||
ExpenseClaim claim = ExpenseClaim.FromIdentity(foreignId);
|
||||
claimIdentityList.Add(foreignId);
|
||||
|
||||
if (bank.Length < 1)
|
||||
{
|
||||
Person claimer = claim.Claimer;
|
||||
bank = claimer.BankName;
|
||||
account = claimer.BankAccount;
|
||||
organizationId = claim.OrganizationId;
|
||||
}
|
||||
|
||||
amountCents += claim.AmountCents;
|
||||
|
||||
claim.Repaid = true;
|
||||
claim.Close();
|
||||
}
|
||||
else if (component[0] == 'a')
|
||||
{
|
||||
CashAdvance advancePayback = CashAdvance.FromIdentity(foreignId);
|
||||
advancePaybackIdentityList.Add(foreignId);
|
||||
|
||||
amountCents += claim.AmountCents;
|
||||
|
||||
claim.Repaid = true;
|
||||
claim.Close();
|
||||
amountCents -= advancePayback.AmountCents;
|
||||
advancePayback.Open = false;
|
||||
}
|
||||
}
|
||||
|
||||
string referenceString = string.Empty;
|
||||
|
||||
if (identityList.Count == 1)
|
||||
if (claimIdentityList.Count == 1)
|
||||
{
|
||||
referenceString = "Expense Claim #" + identityList[0].ToString(CultureInfo.InvariantCulture);
|
||||
referenceString = "Expense Claim #" + claimIdentityList[0].ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
identityList.Sort();
|
||||
referenceString = "Expense Claims " + Formatting.GenerateRangeString(identityList);
|
||||
claimIdentityList.Sort();
|
||||
referenceString = "Expense Claims " + Formatting.GenerateRangeString(claimIdentityList);
|
||||
}
|
||||
|
||||
payoutId = SwarmDb.GetDatabaseForWriting().CreatePayout(organizationId, bank, account,
|
||||
referenceString, amountCents, DateTime.Today.AddDays(1),
|
||||
creator.Identity);
|
||||
|
||||
foreach (int claimId in identityList)
|
||||
foreach (int claimId in claimIdentityList)
|
||||
{
|
||||
SwarmDb.GetDatabaseForWriting().CreatePayoutDependency(payoutId, FinancialDependencyType.ExpenseClaim,
|
||||
claimId);
|
||||
@@ -403,7 +422,12 @@ namespace Swarmops.Logic.Financial
|
||||
result += "|C" + claim.Identity.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
foreach (CashAdvance advance in DependentCashAdvances)
|
||||
foreach (CashAdvance advancePayback in DependentCashAdvancesPayback)
|
||||
{
|
||||
result += "|a" + advancePayback.Identity.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
foreach (CashAdvance advance in DependentCashAdvancesPayout)
|
||||
{
|
||||
result += "|A" + advance.Identity.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
@@ -448,9 +472,9 @@ namespace Swarmops.Logic.Financial
|
||||
{
|
||||
return this.DependentExpenseClaims[0].ClaimerCanonical;
|
||||
}
|
||||
else if (this.DependentCashAdvances.Count > 0)
|
||||
else if (this.DependentCashAdvancesPayout.Count > 0)
|
||||
{
|
||||
return this.DependentCashAdvances[0].Person.Canonical;
|
||||
return this.DependentCashAdvancesPayout[0].Person.Canonical;
|
||||
}
|
||||
else if (this.DependentSalariesNet.Count > 0)
|
||||
{
|
||||
@@ -483,6 +507,7 @@ namespace Swarmops.Logic.Financial
|
||||
accountDebitLookup[organization.FinancialAccounts.DebtsInboundInvoices.Identity] = 0;
|
||||
accountDebitLookup[organization.FinancialAccounts.DebtsSalary.Identity] = 0;
|
||||
accountDebitLookup[organization.FinancialAccounts.DebtsTax.Identity] = 0;
|
||||
accountDebitLookup[organization.FinancialAccounts.AssetsOutstandingCashAdvances.Identity] = 0;
|
||||
|
||||
if (this.DependentExpenseClaims.Count > 0)
|
||||
{
|
||||
@@ -504,6 +529,16 @@ namespace Swarmops.Logic.Financial
|
||||
accountDebitLookup[organization.FinancialAccounts.DebtsTax.Identity] +=
|
||||
this.DependentSalariesTax.TotalAmountCentsTax;
|
||||
}
|
||||
if (this.DependentCashAdvancesPayout.Count > 0)
|
||||
{
|
||||
accountDebitLookup[organization.FinancialAccounts.AssetsOutstandingCashAdvances.Identity] +=
|
||||
this.DependentCashAdvancesPayout.TotalAmountCents;
|
||||
}
|
||||
if (this.DependentCashAdvancesPayback.Count > 0)
|
||||
{
|
||||
accountDebitLookup[organization.FinancialAccounts.AssetsOutstandingCashAdvances.Identity] -= // observe the minus
|
||||
this.DependentCashAdvancesPayback.TotalAmountCents;
|
||||
}
|
||||
|
||||
foreach (int financialAccountId in accountDebitLookup.Keys)
|
||||
{
|
||||
@@ -570,7 +605,7 @@ namespace Swarmops.Logic.Financial
|
||||
claim.Open = true;
|
||||
}
|
||||
|
||||
foreach (CashAdvance advance in this.DependentCashAdvances)
|
||||
foreach (CashAdvance advance in this.DependentCashAdvancesPayout)
|
||||
{
|
||||
advance.PaidOut = false;
|
||||
advance.Open = true;
|
||||
|
||||
@@ -89,6 +89,24 @@ namespace Swarmops.Logic.Financial
|
||||
}
|
||||
}
|
||||
|
||||
// At this point, all the expense claims have been added - but we need to add the open
|
||||
// cash advances and deduct them.
|
||||
|
||||
CashAdvances cashAdvances = CashAdvances.ForOrganization(Organization.FromIdentity(organizationId));
|
||||
cashAdvances = cashAdvances.WherePaid;
|
||||
|
||||
// At this point, only open and paid cash advances are in the list: they're debts to the org
|
||||
|
||||
foreach (CashAdvance cashAdvance in cashAdvances)
|
||||
{
|
||||
if (payoutLookup.ContainsKey(cashAdvance.PersonId))
|
||||
{
|
||||
// there's a payout prepared to this person - we need to deduct the cash advance from it.
|
||||
|
||||
payoutLookup[cashAdvance.PersonId].DependentCashAdvancesPayback.Add(cashAdvance);
|
||||
}
|
||||
}
|
||||
|
||||
// We now have the list of payouts and the associated claims, but the amounts aren't set on the
|
||||
// payouts. This will be the next step, as we assemble the list.
|
||||
|
||||
@@ -103,16 +121,25 @@ namespace Swarmops.Logic.Financial
|
||||
claimIds.Add(claim.Identity);
|
||||
}
|
||||
|
||||
foreach (CashAdvance previousAdvance in payout.DependentCashAdvancesPayback)
|
||||
{
|
||||
newAmountCents -= previousAdvance.AmountCents;
|
||||
}
|
||||
|
||||
string lessAdvancesIndicator = payout.DependentCashAdvancesPayback.Count > 0
|
||||
? "LessAdvances"
|
||||
: string.Empty;
|
||||
|
||||
payout.AmountCents = newAmountCents;
|
||||
|
||||
if (claimIds.Count == 1)
|
||||
{
|
||||
payout.Reference = "[Loc]Financial_ExpenseClaimSpecification|" + claimIds[0].ToString(CultureInfo.InvariantCulture);
|
||||
payout.Reference = "[Loc]Financial_ExpenseClaimSpecification" + lessAdvancesIndicator + "|" + claimIds[0].ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
claimIds.Sort();
|
||||
payout.Reference = "[Loc]Financial_ExpenseClaimsSpecification|" + Formatting.GenerateRangeString(claimIds);
|
||||
payout.Reference = "[Loc]Financial_ExpenseClaimsSpecification" + lessAdvancesIndicator + "|" + Formatting.GenerateRangeString(claimIds);
|
||||
}
|
||||
|
||||
if (newAmountCents > 0)
|
||||
@@ -129,6 +156,7 @@ namespace Swarmops.Logic.Financial
|
||||
{
|
||||
CashAdvances advances = CashAdvances.ForOrganization(Organization.FromIdentity(organizationId));
|
||||
advances = advances.WhereAttested;
|
||||
advances = advances.WhereUnpaid;
|
||||
|
||||
Dictionary<int, Payout> payoutLookup = new Dictionary<int, Payout>();
|
||||
|
||||
@@ -145,7 +173,7 @@ namespace Swarmops.Logic.Financial
|
||||
{
|
||||
// Yes. Add claim to list.
|
||||
|
||||
payoutLookup[advance.PersonId].DependentCashAdvances.Add(advance);
|
||||
payoutLookup[advance.PersonId].DependentCashAdvancesPayout.Add(advance);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -156,7 +184,7 @@ namespace Swarmops.Logic.Financial
|
||||
DateTime.MinValue, false, DateTime.Now, 0);
|
||||
Payout payout = Payout.FromBasic(basicPayout);
|
||||
|
||||
payout.DependentCashAdvances.Add(advance);
|
||||
payout.DependentCashAdvancesPayout.Add(advance);
|
||||
|
||||
payoutLookup[advance.PersonId] = payout;
|
||||
}
|
||||
@@ -170,7 +198,7 @@ namespace Swarmops.Logic.Financial
|
||||
Int64 newAmountCents = 0;
|
||||
List<int> advanceIds = new List<int>();
|
||||
|
||||
foreach (CashAdvance advance in payout.DependentCashAdvances)
|
||||
foreach (CashAdvance advance in payout.DependentCashAdvancesPayout)
|
||||
{
|
||||
newAmountCents += advance.AmountCents;
|
||||
advanceIds.Add(advance.Identity);
|
||||
|
||||
@@ -336,4 +336,16 @@
|
||||
<value>Related</value>
|
||||
<comment>List of shortcuts to related actions to current one</comment>
|
||||
</data>
|
||||
<data name="Financial_ExpenseClaimSpecificationLessAdvance" xml:space="preserve">
|
||||
<value>Expense #{0} (minus advance #{1})</value>
|
||||
</data>
|
||||
<data name="Financial_ExpenseClaimSpecificationLessAdvances" xml:space="preserve">
|
||||
<value>Expense #{0} (minus advances)</value>
|
||||
</data>
|
||||
<data name="Financial_ExpenseClaimsSpecificationLessAdvance" xml:space="preserve">
|
||||
<value>Expenses {0} (minus advance #{1})</value>
|
||||
</data>
|
||||
<data name="Financial_ExpenseClaimsSpecificationLessAdvances" xml:space="preserve">
|
||||
<value>Expenses {0} (minus advances)</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -5,7 +5,8 @@
|
||||
<Swarmops5:ExternalScripts ID="ExternalScripts1" Package="easyui" Control="datagrid" runat="server" />
|
||||
<script type="text/javascript" src="/Scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
|
||||
<script type="text/javascript" src="/Scripts/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/Scripts/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
|
||||
<link rel="stylesheet" type="text/css" href="/Scripts/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
function preload(arrayOfImages) {
|
||||
|
||||
Reference in New Issue
Block a user