Skip to content

Commit

Permalink
Start na implementação da versão 2.0 da geração e leitura de arquivos…
Browse files Browse the repository at this point in the history
… SPED
  • Loading branch information
orochasamuel committed Aug 25, 2023
1 parent 422b0f6 commit c79a3c1
Show file tree
Hide file tree
Showing 28 changed files with 1,428 additions and 106 deletions.
42 changes: 39 additions & 3 deletions src/FiscalBr.Common/Constantes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,49 @@

namespace FiscalBr.Common
{
public class Constantes
public static class Constantes
{
public const decimal VZero = 0.00M;
public const string StructuralError = "|ERRO_NA_ESTRUTURA|";

public const string EFDFiscal = "EFDFiscal";
public const string EFDContribuicoes = "EFDContribuicoes";
public static class ArquivoDigital
{
public static class Sped
{
public const string ECD = "ECD";
public const string ECF = "ECF";
public const string EFDContribuicoes = "EFDContribuicoes";
public const string EFDFiscal = "EFDFiscal";

public static class Bloco
{
public static class D
{
public const string D001 = "D001";

public const string D100 = "D100";
public const string D300 = "D300";

public const string D990 = "D990";
}
}

public static class TipoInformacao
{
public const string CodeOrNumber = "CODNUM";
public const string DateTime = "DATA";
public const string NullableDateTime = "NDATA";
public const string Decimal = "DECIMAL";
public const string NullableDecimal = "NDECIMAL";
public const string GenericData = "GENERIC";
public const string Hour = "HORA";
public const string LiteralEnum = "LENUM";
public const string MonthAndYear = "MESANO";
}
}

public const string Dimob = "Dimob";
public const string Sintegra = "Sintegra";
}
}
}
7 changes: 7 additions & 0 deletions src/FiscalBr.Common/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ public enum CodigoEntidade

#endregion ECD

public enum LeiauteArquivoSped
{
[DefaultValue("EFD Contrib")] EFDContrib,
[DefaultValue("EFD Fiscal")] EFDFiscal,
[DefaultValue("ECD")] ECD,
[DefaultValue("ECF")] ECF,
}

public enum CodigoVersaoLeiaute
{
Expand Down
107 changes: 107 additions & 0 deletions src/FiscalBr.Common/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Text.RegularExpressions;

namespace FiscalBr.Common
{
public static class EnumHelpers
{
private static T GetAttribute<T>(this Enum value) where T : Attribute
{
var type = value.GetType();
var memberInfo = type.GetMember(value.ToString());
var attributes = memberInfo[0].GetCustomAttributes(typeof(T), false);
return (T)attributes[0];
}

public static string GetEnumDefaultValueByType(Type type, object value)
{
/*
* https://stackoverflow.com/questions/50604295/how-to-get-default-value-of-an-enum-from-a-type-variable
*/
var enumObj = Enum.ToObject(type, value) as Enum;

return enumObj.ToDefaultValue();
}

public static string ToDefaultValue(this Enum value)
{
var attribute = value.GetAttribute<DefaultValueAttribute>();
return attribute == null ? value.ToStringSafe() : attribute.Value.ToStringSafe();
}
}

public static class StringHelpers
{
public static bool HasValue(this string @this)
{
return
!string.IsNullOrEmpty(@this) &&
!string.IsNullOrWhiteSpace(@this);
}

public static bool IsAlphaNumeric(this string @this)
{
return !Regex.IsMatch(@this, "[^a-zA-Z0-9]");
}

public static bool IsEmpty(this string @this)
{
return @this == "";
}

public static bool IsNotEmpty(this string @this)
{
return @this != "";
}

public static bool IsNotNullOrEmpty(this string @this)
{
return !string.IsNullOrEmpty(@this);
}

public static bool IsNotNullOrWhiteSpace(this string @this)
{
return !string.IsNullOrWhiteSpace(@this);
}

public static bool IsNumeric(this string @this)
{
return !Regex.IsMatch(@this, "[^0-9]");
}

public static TEnum ToEnum<TEnum>(this string @this)
{
Type enumType = typeof(TEnum);
return (TEnum)Enum.Parse(enumType, @this);
}

public static TEnum ToEnum<TEnum>(this string @this, TEnum defaultValue)
{
if (@this.IsNotNullOrEmpty())
return (TEnum)Enum.Parse(typeof(TEnum), @this, true);

return defaultValue;
}
}

public static class TypeHelpers
{
public static string GetEnumDefaultValueByType(this Type @this, object value)
{
/*
* https://stackoverflow.com/questions/50604295/how-to-get-default-value-of-an-enum-from-a-type-variable
*/
var enumObj = Enum.ToObject(@this, value) as Enum;

return enumObj.ToDefaultValue();
}

public static bool IsEnumProperty(this Type @this)
{
return @this.IsEnum;
}
}
}
30 changes: 15 additions & 15 deletions src/FiscalBr.Common/MetodosAuxiliares.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,20 +299,20 @@ public static DateTime ObterUltimoDiaMesAtual(this DateTime date)

// This extension method is broken out so you can use a similar pattern with
// other MetaData elements in the future. This is your base method for each.
private static T GetAttribute<T>(this Enum value) where T : Attribute
{
var type = value.GetType();
var memberInfo = type.GetMember(value.ToString());
var attributes = memberInfo[0].GetCustomAttributes(typeof(T), false);
return (T)attributes[0];
}

// This method creates a specific call to the above method, requesting the
// Description MetaData attribute.
public static string ToDefaultValue(this Enum value)
{
var attribute = value.GetAttribute<DefaultValueAttribute>();
return attribute == null ? value.ToStringSafe() : attribute.Value.ToStringSafe();
}
//private static T GetAttribute<T>(this Enum value) where T : Attribute
//{
// var type = value.GetType();
// var memberInfo = type.GetMember(value.ToString());
// var attributes = memberInfo[0].GetCustomAttributes(typeof(T), false);
// return (T)attributes[0];
//}

//// This method creates a specific call to the above method, requesting the
//// Description MetaData attribute.
//public static string ToDefaultValue(this Enum value)
//{
// var attribute = value.GetAttribute<DefaultValueAttribute>();
// return attribute == null ? value.ToStringSafe() : attribute.Value.ToStringSafe();
//}
}
}
Loading

0 comments on commit c79a3c1

Please sign in to comment.