Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbl committed May 29, 2024
1 parent e403b23 commit 864ef5a
Show file tree
Hide file tree
Showing 22 changed files with 144 additions and 120 deletions.
4 changes: 2 additions & 2 deletions Core/BillFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public bool Equals(BillFormat other)
FontFamily == other.FontFamily &&
GraphicsFormat == other.GraphicsFormat &&
Resolution == other.Resolution &&
MarginLeft == other.MarginLeft &&
MarginRight == other.MarginRight &&
MathUtil.AreClose(MarginLeft, other.MarginLeft) &&
MathUtil.AreClose(MarginRight, other.MarginRight) &&
LocalCountryCode == other.LocalCountryCode;
}

Expand Down
25 changes: 25 additions & 0 deletions Core/MathUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace Codecrete.SwissQRBill.Generator
{
internal static class MathUtil
{
/// <summary>
/// Tests if two floating-point numbers are equal or almost equal.
/// </summary>
/// <param name="value1">first number</param>
/// <param name="value2">second number</param>
/// <returns><c>true</c> if they are equal or almost equal, <c>false</c> otherwise</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Bug", "S1244:Floating point numbers should not be tested for equality", Justification = "Quick check; full check follows thereafter")]
public static bool AreClose(double value1, double value2)
{
if (value1 == value2)
return true;
double num1 = (Math.Abs(value1) + Math.Abs(value2) + 10.0) * 2.22044604925031E-16;
double num2 = value1 - value2;
if (-num1 < num2)
return num1 > num2;
return false;
}
}
}
3 changes: 1 addition & 2 deletions Core/Payments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
//

using System;
using System.Globalization;
using System.Text;
using static System.Net.Mime.MediaTypeNames;

namespace Codecrete.SwissQRBill.Generator
{
Expand All @@ -17,6 +15,7 @@ namespace Codecrete.SwissQRBill.Generator
/// </summary>
public static class Payments
{
/// <summary>
/// Cleans a string value to make it viable for the Swiss Payment Standards 2018.
/// <para>
/// Unsupported characters (according to Swiss Payment Standards 2018, ch. 2.4.1 and appendix D) are
Expand Down
1 change: 1 addition & 0 deletions Core/QRCodeText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ private static string FormatAmountForCode(decimal amount)
/// <param name="text">The text to decode.</param>
/// <returns>The decoded bill data.</returns>
/// <exception cref="QRBillValidationException">The text is in an invalid format.</exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S1066:Mergeable \"if\" statements should be combined", Justification = "Easier to read the way it is")]
public static Bill Decode(string text)
{
var lines = SplitLines(text);
Expand Down
2 changes: 2 additions & 0 deletions Core/SwicoBillInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Codecrete.SwissQRBill.Generator
/// (in the field StrdBkgInf).
/// </para>
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S4035:Classes implementing \"IEquatable<T>\" should be sealed", Justification = "Will seal class in next major release")]
public class SwicoBillInformation : IEquatable<SwicoBillInformation>
{
/// <summary>
Expand Down Expand Up @@ -131,6 +132,7 @@ public class SwicoBillInformation : IEquatable<SwicoBillInformation>
/// The due date is calculated from the invoice date and the payment condition with a discount of 0.
/// </para>
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Bug", "S1751:Loops with at most one iteration should be refactored", Justification = "Alternatives are more difficult to understand")]
public DateTime? DueDate
{
get
Expand Down
4 changes: 2 additions & 2 deletions Core/ValidationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public bool HasWarnings
get
{
return _validationMessages != null
&& _validationMessages.Any(message => message.Type == ValidationMessage.MessageType.Warning);
&& _validationMessages.Exists(message => message.Type == ValidationMessage.MessageType.Warning);
}
}

Expand All @@ -58,7 +58,7 @@ public bool HasErrors
get
{
return _validationMessages != null
&& _validationMessages.Any(message => message.Type == ValidationMessage.MessageType.Error);
&& _validationMessages.Exists(message => message.Type == ValidationMessage.MessageType.Error);
}
}

Expand Down
1 change: 1 addition & 0 deletions Core/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ private void ValidateCreditor()
_billOut.Creditor = creditor;
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S1066:Mergeable \"if\" statements should be combined", Justification = "Easier to read the way it is")]
private void ValidateReference()
{
var account = _billOut.Account;
Expand Down
12 changes: 5 additions & 7 deletions Core/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ Open-source .NET library to generate Swiss QR bills. Try it yourself and [create

## Introduction

The Swiss QR bill is the new QR code based payment format that started on 30 June, 2020. The old payment slip will no longer be accepted after 30 September 2022.
The Swiss QR bill is the QR code based payment format that started on 30 June, 2020. The payment slip is sent electronically in most cases. But it can still be printed at the bottom of an invoice or added to the invoice on a separate sheet. The payer scans the QR code with his/her mobile banking app to initiate the payment. The payment just needs to be confirmed.

The new payment slip will be sent electronically in most cases. But it can still be printed at the bottom of an invoice or added to the invoice on a separate sheet. The payer scans the QR code with his/her mobile banking app to initiate the payment. The payment just needs to be confirmed.

If the invoicing party adds structured bill information (VAT rates, payment conditions etc.) to the QR bill, posting in accounts payable can be automated. The invoicing party can also automate the accounts receivable processing as the payment includes all relevant data including a reference number. The Swiss QR bill is convenient for the payer and payee.
If the invoicing party adds structured bill information (VAT rates, payment conditions etc.) to the QR bill, the payer can automate booking in accounts payable. The invoicing party can also automate the accounts receivable processing as the payment includes all relevant data including a reference number. The Swiss QR bill is convenient for the payer and payee.

![QR Bill](https://raw.githubusercontent.com/wiki/manuelbl/SwissQRBill/images/qr-invoice-e1.svg?sanitize=true)

Expand Down Expand Up @@ -43,7 +41,7 @@ The Swiss QR bill library:
Or by running a command in the Package Manager Console

```
Install-Package Codecrete.SwissQRBill.Core -Version 3.1.1
Install-Package Codecrete.SwissQRBill.Core -Version 3.3.0
```

3. Add the code:
Expand Down Expand Up @@ -113,14 +111,14 @@ namespace Codecrete.SwissQRBill.Examples.Basic

4. Run it

## API documention
## API documentation

See DocFX [API Documentation](https://codecrete.net/SwissQRBill.NET/api/index.html)

## Further topics

- [PNG generation](https://github.com/manuelbl/SwissQRBill.NET#png-generation)
- [More PDF generation options](https://github.com/manuelbl/SwissQRBill.NET#pdf-generation)
- [PDF generation](https://github.com/manuelbl/SwissQRBill.NET#pdf-generation)
- [Code examples](https://github.com/manuelbl/SwissQRBill.NET#code-examples)
- [Wiki](https://github.com/manuelbl/SwissQRBill/wiki)
- [Java version](https://github.com/manuelbl/SwissQRBill)
4 changes: 2 additions & 2 deletions Core/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"Net.Codecrete.QrCodeGenerator": {
"type": "Direct",
"requested": "[2.*, )",
"resolved": "2.0.4",
"contentHash": "l9W56N41fVWKu81Im2achTdGty29PgVOYRC07iZgmWJ2rdCqpOLc/p2mjTJvtH4gQggWe3Js23+vNv9xRvqcTg=="
"resolved": "2.0.5",
"contentHash": "jH8i2g7liqxMVyY8WsNzJwMpwHqeWvGRl0f2GMW+C2CLT8vyIT72fdN+HfZeVFdDG0AMLxbvMPrpavXsL76LGQ=="
},
"NETStandard.Library": {
"type": "Direct",
Expand Down
14 changes: 7 additions & 7 deletions CoreTest/AlternativeSchemeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ public class AlternativeSchemeTest
[Fact]
public void DefaultConstructorTest()
{
AlternativeScheme scheme = new AlternativeScheme();
var scheme = new AlternativeScheme();
Assert.Null(scheme.Name);
Assert.Null(scheme.Instruction);
}

[Fact]
public void ConstructorTest()
{
AlternativeScheme scheme = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
var scheme = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
Assert.Equal("Paymit", scheme.Name);
Assert.Equal("PM,12341234,1241234", scheme.Instruction);
}

[Fact]
public void TestEqualsTrivial()
{
AlternativeScheme scheme = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
var scheme = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
Assert.Equal(scheme, scheme);
AlternativeScheme nullScheme = null;
Assert.NotEqual(scheme, nullScheme);
Expand All @@ -42,8 +42,8 @@ public void TestEqualsTrivial()
[Fact]
public void TestEquals()
{
AlternativeScheme scheme1 = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
AlternativeScheme scheme2 = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
var scheme1 = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
var scheme2 = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
Assert.Equal(scheme1, scheme2);
Assert.Equal(scheme1, scheme2);

Expand All @@ -54,8 +54,8 @@ public void TestEquals()
[Fact]
public void TestHashCode()
{
AlternativeScheme scheme1 = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
AlternativeScheme scheme2 = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
var scheme1 = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
var scheme2 = new AlternativeScheme { Name = "Paymit", Instruction = "PM,12341234,1241234" };
Assert.Equal(scheme1.GetHashCode(), scheme2.GetHashCode());
}
}
Expand Down
1 change: 1 addition & 0 deletions CoreTest/EncodedTextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void CreateTextEmptyReference(Bill.QrDataSeparator separator, string newL

private class NewLineTheoryData : TheoryData<Bill.QrDataSeparator, string>
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S1144:Unused private types or members should be removed", Justification = "false positive")]
public NewLineTheoryData()
{
Add(Bill.QrDataSeparator.Lf, "\n");
Expand Down
34 changes: 17 additions & 17 deletions CoreTest/SampleData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

namespace Codecrete.SwissQRBill.CoreTest
{
public class SampleData
public static class SampleData
{
public static Bill CreateExample1()
{
Address creditor = new Address
var creditor = new Address
{
Name = "Robert Schneider AG",
Street = "Rue du Lac",
Expand All @@ -24,7 +24,7 @@ public static Bill CreateExample1()
Town = "Biel",
CountryCode = "CH"
};
Address debtor = new Address
var debtor = new Address
{
Name = "Pia-Maria Rutschmann-Schnyder",
Street = "Grosse Marktgasse",
Expand All @@ -33,7 +33,7 @@ public static Bill CreateExample1()
Town = " Rorschach",
CountryCode = "CH"
};
Bill bill = new Bill
var bill = new Bill
{
Account = "CH44 3199 9123 0008 89012",
Creditor = creditor,
Expand All @@ -44,7 +44,7 @@ public static Bill CreateExample1()
UnstructuredMessage = "Instruction of 15.09.2019",
BillInformation =
"//S1/10/10201409/11/190512/20/1400.000-53/30/106017086/31/180508/32/7.7/40/2:10;0:30",
AlternativeSchemes = new List<AlternativeScheme>
AlternativeSchemes = new()
{
new AlternativeScheme {Name = "Ultraviolet", Instruction = "UV;UltraPay005;12345"},
new AlternativeScheme {Name = "Xing Yong", Instruction = "XY;XYService;54321"}
Expand All @@ -56,7 +56,7 @@ public static Bill CreateExample1()

public static Bill CreateExample2()
{
Address creditor = new Address
var creditor = new Address
{
Name = "Salvation Army Foundation Switzerland",
Street = null,
Expand All @@ -65,7 +65,7 @@ public static Bill CreateExample2()
Town = "Berne",
CountryCode = "CH"
};
Bill bill = new Bill
var bill = new Bill
{
Account = "CH3709000000304442225",
Creditor = creditor,
Expand All @@ -81,7 +81,7 @@ public static Bill CreateExample2()

public static Bill CreateExample3()
{
Address creditor = new Address
var creditor = new Address
{
Name = "Robert Schneider AG",
Street = "Rue du Lac",
Expand All @@ -90,7 +90,7 @@ public static Bill CreateExample3()
Town = "Biel",
CountryCode = "CH"
};
Address debtor = new Address
var debtor = new Address
{
Name = "Pia-Maria Rutschmann-Schnyder",
Street = "Grosse Marktgasse",
Expand All @@ -99,7 +99,7 @@ public static Bill CreateExample3()
Town = "Rorschach",
CountryCode = "CH"
};
Bill bill = new Bill
var bill = new Bill
{
Account = "CH74 0070 0110 0061 1600 2",
Creditor = creditor,
Expand All @@ -115,7 +115,7 @@ public static Bill CreateExample3()

public static Bill CreateExample4()
{
Address creditor = new Address
var creditor = new Address
{
Name = "ABC AG",
Street = null,
Expand All @@ -124,7 +124,7 @@ public static Bill CreateExample4()
Town = "Bern",
CountryCode = "CH"
};
Bill bill = new Bill
var bill = new Bill
{
Account = "CH3709000000304442225",
Creditor = creditor,
Expand All @@ -140,21 +140,21 @@ public static Bill CreateExample4()

public static Bill CreateExample5()
{
Address creditor = new Address
var creditor = new Address
{
Name = "Herrn und Frau Ambikaipagan & Deepshikha Thirugnanasampanthamoorthy",
AddressLine1 = "c/o Pereira De Carvalho, Conrad-Ferdinand-Meyer-Strasse 317 Wohnung 7B",
AddressLine2 = "9527 Niederhelfenschwil bei Schönholzerswilen im Kanton St. Gallen",
CountryCode = "CH"
};
Address debtor = new Address
var debtor = new Address
{
Name = "Annegret Karin & Hansruedi Frischknecht-Bernhardsgrütter",
AddressLine1 = "1503 South New Hampshire Avenue, Lower East-side Bellvue",
AddressLine2 = "Poughkeepsie NY 12601-1233",
CountryCode = "US"
};
Bill bill = new Bill
var bill = new Bill
{
Account = "CH44 3199 9123 0008 89012",
Creditor = creditor,
Expand All @@ -171,14 +171,14 @@ public static Bill CreateExample5()

public static Bill CreateExample6()
{
Address creditor = new Address
var creditor = new Address
{
Name = "Herrn und Frau Ambikaipagan & Deepshikha Thirugnanasampanthamoorthy",
AddressLine1 = "c/o Pereira De Carvalho, Conrad-Ferdinand-Meyer-Strasse 317 Wohnung 7B",
AddressLine2 = "9527 Niederhelfenschwil bei Schönholzerswilen im Kanton St. Gallen",
CountryCode = "CH"
};
Bill bill = new Bill
var bill = new Bill
{
Account = "CH44 3199 9123 0008 89012",
Creditor = creditor,
Expand Down
Loading

0 comments on commit 864ef5a

Please sign in to comment.