Skip to content

Commit

Permalink
Fixed #54: "first" and "last" posting dates are now handled correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenate committed Sep 27, 2011
1 parent a3f97eb commit 162f8af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
16 changes: 8 additions & 8 deletions src/Fab.Client/ServiceReferences.ClientConfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
<binding name="BasicHttpBinding_IUserService"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
closeTimeout="00:01:00">
openTimeout="01:01:00"
receiveTimeout="01:10:00"
sendTimeout="01:01:00"
closeTimeout="01:01:00">
<security mode="None" />
</binding>
<binding name="BasicHttpBinding_IMoneyService"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
closeTimeout="00:01:00">
openTimeout="01:01:00"
receiveTimeout="01:10:00"
sendTimeout="01:01:00"
closeTimeout="01:01:00">
<security mode="None" />
</binding>
</basicHttpBinding>
Expand Down
36 changes: 21 additions & 15 deletions src/Fab.Server/Core/ModelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static Account GetSystemAccount(ModelContainer mc, int assetTypeId)
/// </summary>
/// <param name="account">Account to check.</param>
/// <param name="date">New posting date.</param>
private static void CheckAccountPeriod(Account account, DateTime date)
private static void UpdateAccountPeriodAfterNewPosting(Account account, DateTime date)
{
if (!account.FirstPostingDate.HasValue || account.FirstPostingDate > date)
{
Expand All @@ -121,7 +121,7 @@ private static void CheckAccountPeriod(Account account, DateTime date)
/// <param name="mc">Entity Framework model container.</param>
/// <param name="account">Account to check.</param>
/// <param name="date">Deleted posting date.</param>
private static void UpdateAccountPeriod(ModelContainer mc, Account account, DateTime date)
private static void UpdateAccountPeriodAfterDeletePosting(ModelContainer mc, Account account, DateTime date)
{
if (account.FirstPostingDate.HasValue && account.FirstPostingDate == date)
{
Expand Down Expand Up @@ -305,7 +305,7 @@ internal static void DeleteJournal(ModelContainer mc, int journalId)
// Update cached postings count
posting.Account.PostingsCount--;

UpdateAccountPeriod(mc, posting.Account, posting.Date);
UpdateAccountPeriodAfterDeletePosting(mc, posting.Account, posting.Date);

// Delete original postings
mc.Postings.DeleteObject(posting);
Expand Down Expand Up @@ -396,8 +396,8 @@ internal static Journal CreateTransaction(ModelContainer mc, int accountId, Jour
creditAccount.PostingsCount++;
debitAccount.PostingsCount++;

CheckAccountPeriod(creditAccount, date);
CheckAccountPeriod(debitAccount, date);
UpdateAccountPeriodAfterNewPosting(creditAccount, date);
UpdateAccountPeriodAfterNewPosting(debitAccount, date);

return journal;
}
Expand Down Expand Up @@ -468,6 +468,12 @@ internal static void UpdateTransaction(ModelContainer mc, int accountId, int tra
cashAccount.Balance += amount;
}

// Update account cached "first" and "last" posting dates
UpdateAccountPeriodAfterDeletePosting(mc, targetAccount, targetAccountPosting.Date);
UpdateAccountPeriodAfterDeletePosting(mc, cashAccount, cashAccountPosting.Date);
UpdateAccountPeriodAfterNewPosting(targetAccount, date);
UpdateAccountPeriodAfterNewPosting(cashAccount, date);

targetAccountPosting.Date = date;
cashAccountPosting.Date = date;

Expand All @@ -487,9 +493,6 @@ internal static void UpdateTransaction(ModelContainer mc, int accountId, int tra
journal.Category = category;
}

CheckAccountPeriod(targetAccount, date);
CheckAccountPeriod(cashAccount, date);

mc.SaveChanges();
}

Expand Down Expand Up @@ -555,8 +558,8 @@ internal static Journal CreateTransfer(ModelContainer mc, DateTime date, int fro
targetAccount.PostingsCount++;
sourceAccount.PostingsCount++;

CheckAccountPeriod(sourceAccount, date);
CheckAccountPeriod(targetAccount, date);
UpdateAccountPeriodAfterNewPosting(sourceAccount, date);
UpdateAccountPeriodAfterNewPosting(targetAccount, date);

return journal;
}
Expand Down Expand Up @@ -623,15 +626,18 @@ internal static void UpdateTransfer(ModelContainer mc, int transactionId, int fr
sourceAccountPosting.Account = sourceAccount;
targetAccountPosting.Account = targetAccount;

sourceAccountPosting.Date = date;
targetAccountPosting.Date = date;

journal.Rate = rate;
journal.Quantity = quantity;
journal.Comment = comment;

CheckAccountPeriod(sourceAccount, date);
CheckAccountPeriod(targetAccount, date);
// Update account cached "first" and "last" posting dates
UpdateAccountPeriodAfterDeletePosting(mc, targetAccount, targetAccountPosting.Date);
UpdateAccountPeriodAfterDeletePosting(mc, sourceAccount, sourceAccountPosting.Date);
UpdateAccountPeriodAfterNewPosting(targetAccount, date);
UpdateAccountPeriodAfterNewPosting(sourceAccount, date);

sourceAccountPosting.Date = date;
targetAccountPosting.Date = date;

mc.SaveChanges();
}
Expand Down

0 comments on commit 162f8af

Please sign in to comment.