Skip to content

Commit e9a51b9

Browse files
authored
fix title of asset balance report (#33)
* fix title of asset balance report * add test for remaining commands to create a report
1 parent 6bb2383 commit e9a51b9

19 files changed

Lines changed: 235 additions & 52 deletions

SimpleAccounting.sln.DotSettings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_FOR_STMT/@EntryValue">True</s:Boolean>
88
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_PARAMETER/@EntryValue">True</s:Boolean>
99
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_CASE_FROM_SWITCH/@EntryValue">False</s:Boolean>
10+
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
1011
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean>
1112

1213
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
@@ -268,6 +269,7 @@
268269
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
269270
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
270271
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
272+
<s:Boolean x:Key="/Default/UserDictionary/Words/=acml/@EntryIndexedValue">True</s:Boolean>
271273
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gr_00FCtzmacher/@EntryIndexedValue">True</s:Boolean>
272274
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lukas/@EntryIndexedValue">True</s:Boolean>
273275
<s:Boolean x:Key="/Default/UserDictionary/Words/=saldo/@EntryIndexedValue">True</s:Boolean>

src/SimpleAccounting/Presentation/ShellViewModel.cs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace lg2de.SimpleAccounting.Presentation
3636
"Major Code Smell",
3737
"S4055:Literals should not be passed as localized parameters",
3838
Justification = "pending translation")]
39+
[SuppressMessage("ReSharper", "LocalizableElement")]
3940
internal class ShellViewModel : Conductor<IScreen>, IDisposable
4041
{
4142
private const string GithubDomain = "github.com";
@@ -215,40 +216,42 @@ public AccountJournalViewModel SelectedAccountJournalEntry
215216
public ICommand TotalJournalReportCommand => new RelayCommand(
216217
_ =>
217218
{
218-
var report = new TotalJournalReport(
219+
var report = this.reportFactory.CreateTotalJournal(
219220
this.currentModelJournal,
220221
this.accountingData.Setup,
221222
CultureInfo.CurrentUICulture);
222-
report.CreateReport();
223-
report.ShowPreview("Journal");
223+
const string title = "Journal";
224+
report.CreateReport(title);
225+
report.ShowPreview(title);
224226
},
225227
_ => this.FullJournal.Any());
226228

227229
public ICommand AccountJournalReportCommand => new RelayCommand(
228230
_ =>
229231
{
230232
var report = this.reportFactory.CreateAccountJournal(
231-
this.accountingData.Accounts.SelectMany(a => a.Account),
232233
this.currentModelJournal,
233-
this.accountingData.Setup,
234-
CultureInfo.CurrentUICulture);
234+
this.accountingData.Accounts.SelectMany(a => a.Account),
235+
this.accountingData.Setup, CultureInfo.CurrentUICulture);
235236
report.PageBreakBetweenAccounts =
236237
this.accountingData.Setup?.Reports?.AccountJournalReport?.PageBreakBetweenAccounts ?? false;
237-
report.CreateReport();
238-
report.ShowPreview("Kontoblätter");
238+
const string title = "Kontoblätter";
239+
report.CreateReport(title);
240+
report.ShowPreview(title);
239241
},
240242
_ => this.FullJournal.Any());
241243

242244
public ICommand TotalsAndBalancesReportCommand => new RelayCommand(
243245
_ =>
244246
{
245-
var report = new TotalsAndBalancesReport(
247+
var report = this.reportFactory.CreateTotalsAndBalances(
246248
this.currentModelJournal,
247249
this.accountingData.Accounts,
248250
this.accountingData.Setup,
249251
CultureInfo.CurrentUICulture);
250-
report.CreateReport();
251-
report.ShowPreview("Summen und Salden");
252+
const string title = "Summen und Salden";
253+
report.CreateReport(title);
254+
report.ShowPreview(title);
252255
},
253256
_ => this.FullJournal.Any());
254257

@@ -269,27 +272,29 @@ public AccountJournalViewModel SelectedAccountJournalEntry
269272
accountGroups.Add(new AccountingDataAccountGroup { Name = group.Name, Account = assertAccounts });
270273
}
271274

272-
var report = new TotalsAndBalancesReport(
275+
var report = this.reportFactory.CreateTotalsAndBalances(
273276
this.currentModelJournal,
274277
accountGroups,
275278
this.accountingData.Setup,
276279
CultureInfo.CurrentUICulture);
277-
this.accountingData.Setup.Reports?.TotalsAndBalancesReport?.ForEach(report.Signatures.Add);
278-
report.CreateReport();
279-
report.ShowPreview("Bestandskontosalden");
280+
this.accountingData.Setup?.Reports?.TotalsAndBalancesReport?.ForEach(report.Signatures.Add);
281+
const string title = "Bestandskontosalden";
282+
report.CreateReport(title);
283+
report.ShowPreview(title);
280284
},
281285
_ => this.FullJournal.Any());
282286

283287
public ICommand AnnualBalanceReportCommand => new RelayCommand(
284288
_ =>
285289
{
286-
var report = new AnnualBalanceReport(
290+
var report = this.reportFactory.CreateAnnualBalance(
287291
this.currentModelJournal,
288292
this.accountingData.AllAccounts,
289293
this.accountingData.Setup,
290294
CultureInfo.CurrentUICulture);
291-
report.CreateReport();
292-
report.ShowPreview("Jahresbilanz");
295+
const string title = "Jahresbilanz";
296+
report.CreateReport(title);
297+
report.ShowPreview(title);
293298
},
294299
_ => this.FullJournal.Any());
295300

@@ -645,6 +650,12 @@ internal async void OnCheckForUpdate(object _)
645650

646651
var stream = this.GetType().Assembly.GetManifestResourceStream(
647652
"lg2de.SimpleAccounting.UpdateApplication.ps1");
653+
if (stream == null)
654+
{
655+
// script not found :(
656+
return;
657+
}
658+
648659
using var reader = new StreamReader(stream);
649660
var script = reader.ReadToEnd();
650661
string scriptPath = Path.Combine(Path.GetTempPath(), "UpdateApplication.ps1");

src/SimpleAccounting/Reports/AccountJournalReport.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ internal class AccountJournalReport : ReportBase, IAccountJournalReport
2828
private bool firstAccount;
2929

3030
public AccountJournalReport(
31-
IEnumerable<AccountDefinition> accounts,
3231
AccountingDataJournal yearData,
32+
IEnumerable<AccountDefinition> accounts,
3333
AccountingDataSetup setup,
3434
CultureInfo culture)
3535
: base(ResourceName, setup, yearData, culture)
@@ -43,9 +43,9 @@ public AccountJournalReport(
4343
/// </summary>
4444
public bool PageBreakBetweenAccounts { get; set; }
4545

46-
public void CreateReport()
46+
public void CreateReport(string title)
4747
{
48-
this.PreparePrintDocument();
48+
this.PreparePrintDocument(title);
4949

5050
XmlNode tableNode = this.PrintDocument.SelectSingleNode("//table");
5151

src/SimpleAccounting/Reports/AnnualBalanceReport.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace lg2de.SimpleAccounting.Reports
1818
Justification = "pending translation")]
1919
[SuppressMessage("ReSharper", "StringLiteralTypo")]
2020
[SuppressMessage("ReSharper", "CommentTypo")]
21-
internal class AnnualBalanceReport : ReportBase
21+
internal class AnnualBalanceReport : ReportBase, IAnnualBalanceReport
2222
{
2323
public const string ResourceName = "AnnualBalance.xml";
2424
private const string FourthColumnExpression = "../columns/column[position()=4]";
@@ -37,9 +37,9 @@ public AnnualBalanceReport(
3737
this.culture = culture;
3838
}
3939

40-
public void CreateReport()
40+
public void CreateReport(string title)
4141
{
42-
this.PreparePrintDocument();
42+
this.PreparePrintDocument(title);
4343

4444
// income / Einnahmen
4545
this.ProcessIncome(out var totalIncome);

src/SimpleAccounting/Reports/IAccountJournalReport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal interface IAccountJournalReport
88
{
99
bool PageBreakBetweenAccounts { get; set; }
1010

11-
void CreateReport();
11+
void CreateReport(string title);
1212

1313
void ShowPreview(string documentName);
1414
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// <copyright>
2+
// Copyright (c) Lukas Grützmacher. All rights reserved.
3+
// </copyright>
4+
5+
namespace lg2de.SimpleAccounting.Reports
6+
{
7+
internal interface IAnnualBalanceReport
8+
{
9+
void CreateReport(string title);
10+
11+
void ShowPreview(string documentName);
12+
}
13+
}

src/SimpleAccounting/Reports/IReportFactory.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,25 @@ namespace lg2de.SimpleAccounting.Reports
1111
internal interface IReportFactory
1212
{
1313
IAccountJournalReport CreateAccountJournal(
14+
AccountingDataJournal journal,
1415
IEnumerable<AccountDefinition> accounts,
16+
AccountingDataSetup setup,
17+
CultureInfo culture);
18+
19+
ITotalJournalReport CreateTotalJournal(
20+
AccountingDataJournal journal,
21+
AccountingDataSetup setup,
22+
CultureInfo culture);
23+
24+
IAnnualBalanceReport CreateAnnualBalance(
25+
AccountingDataJournal journal,
26+
IEnumerable<AccountDefinition> accounts,
27+
AccountingDataSetup setup,
28+
CultureInfo culture);
29+
30+
ITotalsAndBalancesReport CreateTotalsAndBalances(
1531
AccountingDataJournal journal,
32+
IEnumerable<AccountingDataAccountGroup> accounts,
1633
AccountingDataSetup setup,
1734
CultureInfo culture);
1835
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// <copyright>
2+
// Copyright (c) Lukas Grützmacher. All rights reserved.
3+
// </copyright>
4+
5+
namespace lg2de.SimpleAccounting.Reports
6+
{
7+
internal interface ITotalJournalReport
8+
{
9+
void CreateReport(string title);
10+
11+
void ShowPreview(string documentName);
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// <copyright>
2+
// Copyright (c) Lukas Grützmacher. All rights reserved.
3+
// </copyright>
4+
5+
namespace lg2de.SimpleAccounting.Reports
6+
{
7+
using System.Collections.Generic;
8+
9+
internal interface ITotalsAndBalancesReport
10+
{
11+
List<string> Signatures { get; }
12+
13+
void CreateReport(string title);
14+
15+
void ShowPreview(string documentName);
16+
}
17+
}

src/SimpleAccounting/Reports/ReportBase.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,22 @@ public void ShowPreview(string documentName)
4545
this.Printer.PrintDocument($"{this.PrintingDate:yyyy-MM-dd} {documentName} {this.YearData.Year}");
4646
}
4747

48-
protected void PreparePrintDocument()
48+
protected void PreparePrintDocument(string title)
4949
{
50-
var textNode = this.PrintDocument.SelectSingleNode("//text[@ID=\"firm\"]");
51-
textNode.InnerText = this.setup.Name;
50+
var textNode = this.PrintDocument.SelectSingleNode("//text[@ID=\"title\"]");
51+
if (textNode != null)
52+
{
53+
textNode.InnerText = title;
54+
}
55+
56+
textNode = this.PrintDocument.SelectSingleNode("//text[@ID=\"pageTitle\"]");
57+
if (textNode != null)
58+
{
59+
textNode.InnerText = $"- {title} -";
60+
}
61+
62+
textNode = this.PrintDocument.SelectSingleNode("//text[@ID=\"firm\"]");
63+
textNode.InnerText = this.setup?.Name;
5264

5365
textNode = this.PrintDocument.SelectSingleNode("//text[@ID=\"yearName\"]");
5466
if (textNode != null)
@@ -65,7 +77,7 @@ protected void PreparePrintDocument()
6577
}
6678

6779
textNode = this.PrintDocument.SelectSingleNode("//text[@ID=\"date\"]");
68-
textNode.InnerText = this.setup.Location + ", " + DateTime.Now.ToString("D", this.culture);
80+
textNode.InnerText = this.setup?.Location + ", " + DateTime.Now.ToString("D", this.culture);
6981
}
7082
}
7183
}

0 commit comments

Comments
 (0)