Skip to content

Commit

Permalink
Merge pull request #661 from FastReports/sync_branch_2024.1.2
Browse files Browse the repository at this point in the history
FastReport.OpenSource 2024.1.2
  • Loading branch information
0legK authored Dec 19, 2023
2 parents f05b4bf + 4473ccd commit e9dfb47
Show file tree
Hide file tree
Showing 57 changed files with 7,656 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Import Project="..\Connections.props" />

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="[11.0.2,)" />
<PackageReference Include="Newtonsoft.Json" Version="[13.0.3,)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="[2.11.0,)" />
<PackageReference Include="MongoDB.Driver" Version="[2.11.0,)" />
<PackageReference Include="MongoDB.Driver.Core" Version="[2.11.0,)" />
<PackageReference Include="MongoDB.Bson" Version="[2.20.0,)" />
<PackageReference Include="MongoDB.Driver" Version="[2.20.0,)" />
<PackageReference Include="MongoDB.Driver.Core" Version="[2.20.0,)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Import Project="..\Connections.props" />

<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.4.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Extras/Core/FastReport.Data/WPF.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<FastReportWPFProj>..\..\..\..\FastReport.WPF\FastReport.WPF.csproj</FastReportWPFProj>
<FastReportWPFPackage>FastReport.WPF.Demo</FastReportWPFPackage>

<FastReportFormsWPFProj>..\..\..\..\..\FastReport.Forms.WPF\src\FastReport.Forms.WPF.csproj</FastReportFormsWPFProj>
<FastReportFormsWPFProj>..\..\..\..\FastReport.Forms.WPF\src\FastReport.Forms.WPF.csproj</FastReportFormsWPFProj>
<FastReportFormsWPFPackage>FastReport.Forms.WPF.Demo</FastReportFormsWPFPackage>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Import Project="..\Plugins.props" />

<ItemGroup>
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
</ItemGroup>

<ItemGroup>
Expand Down
31 changes: 26 additions & 5 deletions FastReport.Base/Barcode/BarcodeObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,33 @@ public override void GetData()
}
}

// without the second condition Text.StartsWith("SPC") the method will be executed for any QR
// according to my observations, this does not break anything
if (Barcode is BarcodeQR)
{
//QRData.Parse(Text);

//QRSwiss qRSwiss = new QRSwiss(Text);
//Text = qRSwiss.Pack();

QRData qr = QRData.Parse(Text);

if (Barcode is BarcodeQR/* && Text.StartsWith("SPC")*/)
{
QRData.Parse(Text);
if (qr is QRSwiss)
{
QRSwiss _qr = qr as QRSwiss;

QRSwissParameters parameters = new QRSwissParameters();
parameters.Iban = _qr._Iban;
parameters.Creditor = _qr.Creditor;
parameters.Reference = _qr._Reference;
parameters.AlternativeProcedure1 = _qr.AlternativeProcedure1;
parameters.AlternativeProcedure2 = _qr.AlternativeProcedure2;
parameters.AdditionalInformation = _qr._AdditionalInformation;
parameters.Amount = _qr.Amount;
parameters.Currency = _qr._Currency;
parameters.Debitor = _qr.Debitor;
QRSwiss swissQR = new QRSwiss(parameters);

Text = swissQR.Pack();
}
}
}
#endregion
Expand Down
119 changes: 93 additions & 26 deletions FastReport.Base/Barcode/QRCode/QRData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using FastReport.Utils;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -704,7 +706,7 @@ class QRSwiss : QRData
private Iban iban;
private string amount;
private Contact creditor, ultimateCreditor, debitor;
private Currency currency;
private string currency;
private Reference reference;
private AdditionalInformation additionalInformation;
private MyRes res;
Expand All @@ -713,7 +715,7 @@ class QRSwiss : QRData
public Contact Creditor { get { return creditor; } set { creditor = value; } }
public Contact Debitor { get { return debitor; } set { debitor = value; } }
public string Amount { get { return amount; } }
public Currency _Currency { get { return currency; } set { currency = value; } }
public string _Currency { get { return currency; } set { currency = value; } }
public Reference _Reference { get { return reference; } set { reference = value; } }
public AdditionalInformation _AdditionalInformation { get { return additionalInformation; } set { additionalInformation = value; } }
public string AlternativeProcedure1 { get { return alternativeProcedure1; } set { alternativeProcedure1 = value; } }
Expand Down Expand Up @@ -743,11 +745,53 @@ public QRSwiss(QRSwissParameters parameters)

if (!String.IsNullOrEmpty(parameters.Amount))
if (!parameters.Amount.StartsWith("[") || !parameters.Amount.EndsWith("]"))
if (parameters.Amount.Length > 12)
throw new SwissQrCodeException(res.Get("SwissAmountLength"));
{
//Amount has to use . as decimal separator in any case. See https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf page 27.
decimal.TryParse(parameters.Amount, NumberStyles.Number, CultureInfo.InvariantCulture, out decimal decAmount);
decimal roundedAmount = decimal.Round(decAmount, 2, MidpointRounding.AwayFromZero);

// if the parameters.Amount contains "0", or "0.", or ".0"
if (Regex.IsMatch(parameters.Amount, @"^0(\.0+)?$"))
{
roundedAmount = 0m;
}
else
{
// If the rounded number is less than or equal to 0, then set it to the minimum allowed value
if (roundedAmount <= 0)
{
roundedAmount = 0.01m;
}

// If the rounded number is greater than 999999999.99, then set it to the maximum allowed value
if (roundedAmount > 999999999.99m)
{
roundedAmount = 999999999.99m;
}
}

parameters.Amount = roundedAmount.ToString("0.00", CultureInfo.InvariantCulture);

// in theory, this check is no longer needed
// if (parameters.Amount.Length > 12)
// throw new SwissQrCodeException(res.Get("SwissAmountLength"));
}
this.amount = parameters.Amount;

this.currency = parameters.Currency.Value;
switch (parameters.Currency)
{
case nameof(Currency.EUR):
parameters.Currency = Currency.EUR.ToString();
break;
case nameof(Currency.CHF):
parameters.Currency = Currency.CHF.ToString();
break;
default:
if (!parameters.Currency.StartsWith("[") || !parameters.Currency.EndsWith("]"))
parameters.Currency = Currency.EUR.ToString();
break;
}
this.currency = parameters.Currency;
this.debitor = parameters.Debitor;

if (iban.IsQrIban && parameters.Reference.RefType != Reference.ReferenceType.QRR)
Expand Down Expand Up @@ -799,17 +843,30 @@ public override void Unpack(string data)
}
counter += 7;
if (!datas[counter].StartsWith("[") || !datas[counter].EndsWith("]"))
amount = datas[counter] == String.Empty ? amount = null : Decimal.Parse(datas[counter].Replace('.', ',')).ToString();
{
//Amount has to use . as decimal separator in any case. See https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf page 27.
string invariantSeparator = CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator;
string clearQRSwissAmount = datas[counter].Replace(",", invariantSeparator).Replace("/", invariantSeparator);

decimal.TryParse(clearQRSwissAmount, NumberStyles.Number, CultureInfo.InvariantCulture, out decimal decAmount);
amount = datas[counter] == String.Empty ? amount = null : decAmount.ToString(CultureInfo.InvariantCulture);
}
else amount = datas[counter] == String.Empty ? amount = null : datas[counter];
counter++;

switch (datas[counter])
{
case "EUR":
this.currency = Currency.EUR;
case nameof(Currency.EUR):
this.currency = Currency.EUR.ToString();
break;
case nameof(Currency.CHF):
this.currency = Currency.CHF.ToString();
break;
case "CHF":
this.currency = Currency.CHF;
default:
if (datas[counter].StartsWith("[") && datas[counter].EndsWith("]"))
currency = datas[counter];
else
currency = Currency.EUR.ToString();
break;
}
counter++;
Expand Down Expand Up @@ -837,10 +894,20 @@ public override void Unpack(string data)
iban.TypeIban = Iban.IbanType.Iban;
if (!String.IsNullOrEmpty(reference.ReferenceText))
{
if (reference.ChecksumMod10(reference.ReferenceText))
reference._ReferenceTextType = Reference.ReferenceTextType.QrReference;
else if (Regex.IsMatch(reference.ReferenceText, "^[a-zA-Z0-9 ]+$"))
reference._ReferenceTextType = Reference.ReferenceTextType.CreditorReferenceIso11649;
if (reference.ReferenceText.StartsWith("[") && reference.ReferenceText.EndsWith("]"))
{
if (reference.RefType == Reference.ReferenceType.QRR)
reference._ReferenceTextType = Reference.ReferenceTextType.QrReference;
else
reference._ReferenceTextType = Reference.ReferenceTextType.CreditorReferenceIso11649;
}
else
{
if (reference.ChecksumMod10(reference.ReferenceText))
reference._ReferenceTextType = Reference.ReferenceTextType.QrReference;
else if (Regex.IsMatch(reference.ReferenceText, "^[a-zA-Z0-9 ]+$"))
reference._ReferenceTextType = Reference.ReferenceTextType.CreditorReferenceIso11649;
}
}

if (!iban._Iban.StartsWith("[") || !iban._Iban.EndsWith("]"))
Expand Down Expand Up @@ -892,18 +959,8 @@ public override string Pack()


//CcyAmtDate "logical" element
//Amoutn has to use . as decimal seperator in any case. See https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf page 27.
//SwissQrCodePayload += (amount != null ? amount.ToString().Replace(",", ".") : string.Empty) + br; //Amt
if (amount != null)
{
string strAmount = amount;
if (!strAmount.StartsWith("[") || !strAmount.EndsWith("]"))
if (!strAmount.Contains("."))
strAmount = amount.ToString().Replace(",", ".");
else
strAmount += ".00";
SwissQrCodePayload += strAmount;
}
SwissQrCodePayload += amount;
else
SwissQrCodePayload += string.Empty;
SwissQrCodePayload += br;
Expand All @@ -922,7 +979,17 @@ public override string Pack()

//RmtInf "logical" element
SwissQrCodePayload += reference.RefType.ToString() + br; //Tp
SwissQrCodePayload += (!string.IsNullOrEmpty(reference.ReferenceText) ? reference.ReferenceText : string.Empty) + br; //Ref
if (!string.IsNullOrEmpty(reference.ReferenceText))
{
if (reference.ReferenceText.StartsWith("[") && reference.ReferenceText.EndsWith("]"))
SwissQrCodePayload += reference.ReferenceText + br;
else
SwissQrCodePayload += new string(reference.ReferenceText.Where(c => char.IsLetterOrDigit(c)).ToArray()).ToUpper() + br; //Ref
}
else
{
SwissQrCodePayload += string.Empty + br; //Ref
}


//AddInf "logical" element
Expand Down
Loading

0 comments on commit e9dfb47

Please sign in to comment.