Skip to content

Commit 1e2e31e

Browse files
committed
Merge branch 'v0.1'
2 parents 38802de + 090d622 commit 1e2e31e

File tree

11 files changed

+9184
-24
lines changed

11 files changed

+9184
-24
lines changed

DebitExpress.VatRelief/DebitExpress.VatRelief.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net6.0-windows</TargetFramework>
5+
<TargetFramework>net7.0-windows</TargetFramework>
66
<Nullable>enable</Nullable>
77
<UseWPF>true</UseWPF>
88
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
@@ -18,10 +18,11 @@
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="ClosedXML" Version="0.96.0" />
22-
<PackageReference Include="DebitExpress.Controls" Version="2.1.16" />
23-
<PackageReference Include="DebitExpress.DialogService" Version="2.1.7" />
24-
<PackageReference Include="DebitExpress.Extensions" Version="1.0.10" />
21+
<PackageReference Include="ClosedXML" Version="0.97.0" />
22+
<PackageReference Include="DebitExpress.Controls" Version="2.1.24" />
23+
<PackageReference Include="DebitExpress.DialogService" Version="2.1.8" />
24+
<PackageReference Include="DebitExpress.Extensions" Version="1.0.11" />
25+
<PackageReference Include="DebitExpress.StringBuilders" Version="1.0.5" />
2526
</ItemGroup>
2627

2728
<ItemGroup>

DebitExpress.VatRelief/MainWindow.xaml.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Linq;
55
using System.Reflection;
66
using System.Windows;
7+
using DebitExpress.Controls.Dialogs;
8+
using DebitExpress.DialogService;
79
using DebitExpress.VatRelief.Models;
810
using DebitExpress.VatRelief.Utils;
911
using MaterialDesignThemes.Wpf;
@@ -15,6 +17,7 @@ namespace DebitExpress.VatRelief;
1517
/// </summary>
1618
public partial class MainWindow
1719
{
20+
private readonly IDialog _dialog = new Dialog();
1821
private string _filePath = string.Empty;
1922
private readonly SnackbarMessageQueue _messageQueue;
2023
private readonly SnackbarMessageQueue _errorQueue;
@@ -33,8 +36,8 @@ public MainWindow()
3336

3437
GenerateButton.Click += OnGenerate;
3538
DownloadButton.Click += OnDownload;
36-
GithubButton.Click+= OnGithub;
37-
Loaded+= OnLoaded;
39+
GithubButton.Click += OnGithub;
40+
Loaded += OnLoaded;
3841
}
3942

4043
private void OnLoaded(object sender, RoutedEventArgs e)
@@ -89,6 +92,7 @@ private void OnDragOver(object sender, DragEventArgs e)
8992

9093
private async void OnGenerate(object sender, RoutedEventArgs e)
9194
{
95+
var loader = await _dialog.ShowLoadingAsync();
9296
try
9397
{
9498
if (!File.Exists(_filePath))
@@ -120,7 +124,7 @@ private async void OnGenerate(object sender, RoutedEventArgs e)
120124
}
121125

122126
var reconWriter = new ExcelReconWriter();
123-
var writeResult = reconWriter.WriteReconciliationReport(data, path);
127+
var writeResult = await reconWriter.WriteReconciliationReportAsync(data, path);
124128

125129
if (writeResult.IsFaulted)
126130
{
@@ -135,6 +139,7 @@ private async void OnGenerate(object sender, RoutedEventArgs e)
135139
finally
136140
{
137141
GenerateButton.IsEnabled = true;
142+
await _dialog.CloseLoadingAsync(loader);
138143
}
139144
}
140145

DebitExpress.VatRelief/Models/Purchases.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using DebitExpress.StringBuilders;
23

34
namespace DebitExpress.VatRelief.Models;
45

@@ -15,7 +16,11 @@ public struct Purchases
1516

1617
public string MiddleName { get; set; }
1718

18-
public string FullName => $"{LastName}, {FirstName} {MiddleName}";
19+
public string FullName => new NameBuilder()
20+
.LastName(LastName)
21+
.WithFirstName(FirstName)
22+
.WithMiddleName(MiddleName)
23+
.ToString() ?? string.Empty;
1924
public string Street { get; set; }
2025

2126
public string City { get; set; }

DebitExpress.VatRelief/Models/Sales.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using DebitExpress.StringBuilders;
23

34
namespace DebitExpress.VatRelief.Models;
45

@@ -10,7 +11,12 @@ public struct Sales
1011
public string LastName { get; set; }
1112
public string FirstName { get; set; }
1213
public string MiddleName { get; set; }
13-
public string FullName => $"{LastName}, {FirstName} {MiddleName}";
14+
15+
public string FullName => new NameBuilder()
16+
.LastName(LastName)
17+
.WithFirstName(FirstName)
18+
.WithMiddleName(MiddleName)
19+
.ToString() ?? string.Empty;
1420
public string Street { get; set; }
1521
public string City { get; set; }
1622
public decimal Exempt { get; set; }

DebitExpress.VatRelief/Unidecode/Characters.cs

Lines changed: 8987 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace DebitExpress.VatRelief.Unidecode;
2+
3+
public enum UnidecodeOptions
4+
{
5+
Default,
6+
ToLower,
7+
ToUpper,
8+
RemoveSpace,
9+
RemoveSpaceAndToLower,
10+
RemoveSpaceAndToUpper
11+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
COPYRIGHT
3+
Character transliteration tables:
4+
Copyright 2001, Sean M. Burke <[email protected]>, all rights reserved.
5+
Python code:
6+
Copyright 2009, Tomaz Solc <[email protected]>
7+
CSharp code:
8+
Copyright 2010, Oleg Usanov <[email protected]>
9+
Refactorings (2015) - Nikolay Eremin <[email protected]>
10+
The programs and documentation in this dist are distributed in the
11+
hope that they will be useful, but without any warranty; without even
12+
the implied warranty of merchantability or fitness for a particular
13+
purpose.
14+
This library is free software; you can redistribute it and/or modify
15+
it under the same terms as Perl.
16+
*/
17+
18+
using System.Text;
19+
20+
namespace DebitExpress.VatRelief.Unidecode;
21+
22+
public static partial class Unidecoder
23+
{
24+
/// <summary>
25+
/// Transliterate an Unicode object into an ASCII string
26+
/// </summary>
27+
/// <remarks>
28+
/// unidecode(u"\u5317\u4EB0") == "Bei Jing "
29+
/// </remarks>
30+
/// <param name="input">The input.</param>
31+
/// <param name="options"></param>
32+
/// <returns>ASCII encoded string.</returns>
33+
public static string Unidecode(this string input, UnidecodeOptions options = UnidecodeOptions.Default)
34+
{
35+
if (string.IsNullOrWhiteSpace(input)) return "";
36+
37+
var output = new StringBuilder(input.Length * 2);
38+
39+
foreach (var symbol in input)
40+
{
41+
var result = Unidecode(symbol);
42+
if (string.IsNullOrEmpty(result)) continue;
43+
output.Append(result);
44+
}
45+
46+
switch (options)
47+
{
48+
case UnidecodeOptions.ToLower:
49+
return output.ToString().Trim(' ').ToLower();
50+
case UnidecodeOptions.ToUpper:
51+
return output.ToString().Trim(' ').ToUpper();
52+
case UnidecodeOptions.RemoveSpace:
53+
return output.ToString().Trim(' ').Replace(" ", "");
54+
case UnidecodeOptions.RemoveSpaceAndToLower:
55+
return output.ToString().Trim(' ').Replace(" ", "").ToLower();
56+
case UnidecodeOptions.RemoveSpaceAndToUpper:
57+
return output.ToString().Trim(' ').Replace(" ", "").ToUpper();
58+
case UnidecodeOptions.Default:
59+
return output.ToString().Trim(' ');
60+
default:
61+
return output.ToString().Trim(' ');
62+
}
63+
}
64+
65+
/// <summary>
66+
/// Transliterate Unicode character to ASCII string.
67+
/// </summary>
68+
/// <param name="c">Character you want to transliterate into ASCII</param>
69+
/// <returns>
70+
/// ASCII string. Unknown(?) unicode characters will return [?] (3 characters).
71+
/// It is this way in Python code as well.
72+
/// </returns>
73+
public static string Unidecode(this char c)
74+
{
75+
string result;
76+
if (c < 0x80)
77+
{
78+
result = new string(c, 1);
79+
}
80+
else
81+
{
82+
var high = c >> 8;
83+
var low = c & 0xff;
84+
result = Characters.Value.TryGetValue(high, out var values) ? values.Value[low] : "";
85+
}
86+
87+
return result;
88+
}
89+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
3+
namespace DebitExpress.VatRelief.Unidecode;
4+
5+
public abstract class WeakLazy<T> where T : class
6+
{
7+
protected readonly Func<T> ValueFactory = null!;
8+
9+
protected internal WeakLazy(Func<T>? valueFactory)
10+
{
11+
if (valueFactory != null) ValueFactory = valueFactory;
12+
}
13+
14+
public abstract T Value { get; }
15+
}
16+
17+
public sealed class StaticWeakLazy<T> : WeakLazy<T> where T : class
18+
{
19+
private readonly WeakReference<T> _reference = null!;
20+
21+
public StaticWeakLazy(Func<T>? valueFactory) : base(valueFactory)
22+
{
23+
if (valueFactory != null) _reference = new WeakReference<T>(null);
24+
}
25+
26+
public override T Value
27+
{
28+
get
29+
{
30+
if (!_reference.TryGetTarget(out var value))
31+
{
32+
value = ValueFactory();
33+
_reference.SetTarget(value);
34+
}
35+
return value;
36+
}
37+
}
38+
}

DebitExpress.VatRelief/Utils/ExcelReconWriter.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Threading.Tasks;
56
using ClosedXML.Excel;
7+
using DebitExpress.StringBuilders;
68
using DebitExpress.VatRelief.Models;
79

810
namespace DebitExpress.VatRelief.Utils;
911

1012
public class ExcelReconWriter
1113
{
14+
public Task<Result> WriteReconciliationReportAsync(ExcelData data, string path)
15+
{
16+
return Task.Factory.StartNew(() => WriteReconciliationReport(data, path));
17+
}
18+
1219
public Result WriteReconciliationReport(ExcelData data, string path)
1320
{
1421
try
@@ -101,7 +108,13 @@ private void WriteSalesData(IXLWorksheet sheet, Info info, List<Sales> sales)
101108
sheet.Cell("A2").Value = "RECONCILIATION OF LISTING FOR ENFORCEMENT";
102109
sheet.Cell("A6").Value = $"TIN : {info.Tin.Strip()}";
103110

104-
var name = info.NonIndividual ? info.RegName : $"{info.LastName}, {info.FirstName} {info.MiddleName}";
111+
var taxPayer = new NameBuilder()
112+
.LastName(info.LastName)
113+
.WithFirstName(info.FirstName)
114+
.WithMiddleName(info.MiddleName)
115+
.ToString();
116+
117+
var name = info.NonIndividual ? info.RegName : taxPayer;
105118
sheet.Cell("A7").Value = $"OWNER'S NAME: {name}";
106119

107120
sheet.Cell("A8").Value = $"OWNER'S TRADE NAME : {info.TradeName}";
@@ -195,7 +208,13 @@ private void WritePurchasesData(IXLWorksheet sheet, Info info, List<Purchases> p
195208
sheet.Cell("A2").Value = "RECONCILIATION OF LISTING FOR ENFORCEMENT";
196209
sheet.Cell("A6").Value = $"TIN : {info.Tin.Strip()}";
197210

198-
var name = info.NonIndividual ? info.RegName : $"{info.LastName}, {info.FirstName} {info.MiddleName}";
211+
var taxPayer = new NameBuilder()
212+
.LastName(info.LastName)
213+
.WithFirstName(info.FirstName)
214+
.WithMiddleName(info.MiddleName)
215+
.ToString();
216+
217+
var name = info.NonIndividual ? info.RegName : taxPayer;
199218
sheet.Cell("A7").Value = $"OWNER'S NAME: {name}";
200219

201220
sheet.Cell("A8").Value = $"OWNER'S TRADE NAME : {info.TradeName}";

DebitExpress.VatRelief/Utils/Extensions.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text.RegularExpressions;
4+
using DebitExpress.VatRelief.Unidecode;
45

56
namespace DebitExpress.VatRelief.Utils;
67

@@ -9,7 +10,7 @@ internal static class Extensions
910
public static string CleanUp(this string str)
1011
{
1112
if (string.IsNullOrWhiteSpace(str)) return string.Empty;
12-
return Regex.Replace(str, "[,$`&\"']", string.Empty).NormalizeWhiteSpace().Trim().ToUpper();
13+
return Regex.Replace(str, "[,$`&\"']", string.Empty).NormalizeWhiteSpace().Trim().ToUpper().Unidecode();
1314
}
1415

1516
public static string NormalizeWhiteSpace(this string input)
@@ -68,7 +69,7 @@ public static string Strip(this string str)
6869
if (string.IsNullOrWhiteSpace(str)) return string.Empty;
6970

7071
var num = Regex.Replace(str, "[^0-9]", "");
71-
return num.PadRight(9, '0')[..9];
72+
return num.PadRight(9, '0')[..9].Unidecode();
7273
}
7374

7475
public static string ToValue(this decimal val)
@@ -93,13 +94,6 @@ public static bool IsTrue(this string? str)
9394
return upper is "YES" or "Y" or "TRUE" or "T" or "1";
9495
}
9596

96-
public static bool IsValidTin(this string? str)
97-
{
98-
if (string.IsNullOrEmpty(str)) return false;
99-
100-
return new Regex("^[0-9]\\d{2}-[0-9]\\d{2}-[0-9]\\d{2}-[0-9]\\d{2,4}$").IsMatch(str);
101-
}
102-
10397
public static string QuarterRangeString(int startingMonth, int year)
10498
{
10599
var startingDate = GetEndOfMonth(year, startingMonth);

0 commit comments

Comments
 (0)