コード例 #1
0
        ///<inheritdoc/>
        public async Task <CalculateInssResult> CalculateInss(InssType type, decimal revenue, DateTime?date, CancellationToken cancellationToken = default)
        {
            CalculateInssResult result = null;

            InssTax inss = await _inssRepository.GetActive(type, date, cancellationToken);

            if (inss != null)
            {
                InssTaxRange range = inss
                                     .Range
                                     .OrderByDescending(o => o.EndValue)
                                     .FirstOrDefault(x => (revenue >= x.StartValue && revenue <= x.EndValue) || revenue >= x.EndValue);

                if (range != null)
                {
                    result = new CalculateInssResult();
                    decimal value = (revenue * range.Rate / 100);
                    value -= range.DeductedAmount;
                    if (value > inss.Limit)
                    {
                        value          = inss.Limit;
                        result.IsLimit = true;
                    }
                    value = Math.Round(value, 2);

                    result.Rate   = range.Rate;
                    result.Amount = value;
                }
            }

            return(result);
        }
コード例 #2
0
 /// <summary>
 /// Convert grpc inss type to enum inss type
 /// </summary>
 /// <param name="inssType">Grpc inss request type</param>
 private static InssBusinessType ConvertInssType(InssType inssType)
 {
     return(inssType switch
     {
         InssType.Worker => InssBusinessType.Worker,
         InssType.Individual => InssBusinessType.Individual,
         InssType.ManagingPartner => InssBusinessType.ManagingPartner,
         _ => InssBusinessType.Individual,
     });
コード例 #3
0
        /// <summary>
        /// Map inss type
        /// </summary>
        /// <param name="inssType">Inss type to map</param>
        private InssType MapInssType(Contract.Enums.InssType inssType)
        {
            InssType inssResultType = inssType switch
            {
                Contract.Enums.InssType.Worker => InssType.Worker,
                Contract.Enums.InssType.Individual => InssType.Individual,
                Contract.Enums.InssType.ManagingPartner => InssType.ManagingPartner,
                _ => InssType.Individual,
            };

            return(inssResultType);
        }
コード例 #4
0
        ///<inheritdoc/>
        public async Task <CalculateNetRevenueResult> CalculateNetRevenue(InssType type, decimal revenue, byte dependentsNumber, DateTime?date, CancellationToken cancellationToken = default)
        {
            CalculateNetRevenueResult result = new()
            {
                Inss = await CalculateInss(type, revenue, date, cancellationToken)
            };

            if (result.Inss == null)
            {
                return(null);
            }

            result.Irpf = await CalculateIrpf(revenue, result.Inss.Amount, dependentsNumber, date, cancellationToken);

            result.NetRevenue = revenue - (result.Inss?.Amount ?? 0M) - (result.Irpf?.Amount ?? 0M);
            return(result);
        }
    }
コード例 #5
0
        ///<inheritdoc/>
        public async Task <InssTax> GetActive(InssType type, DateTime?date, CancellationToken cancellationToken = default)
        {
            FilterDefinitionBuilder <InssTax> builder = Builders <InssTax> .Filter;
            FilterDefinition <InssTax>        filter  = builder.Eq(nameof(InssTax.Type).ToCamelCase(), type);

            if (date.HasValue)
            {
                filter = filter
                         & builder.Lte(nameof(InssTax.DateStart).ToCamelCase(), date.Value)
                         & (
                    builder.Gte(nameof(InssTax.DateEnd).ToCamelCase(), date.Value)
                    | builder.Eq(nameof(InssTax.DateEnd).ToCamelCase(), BsonNull.Value)
                    );
            }
            else
            {
                filter &= builder.Eq(nameof(InssTax.Inactive).ToCamelCase(), false);
            }

            InssTax result = await Collection.Find(filter).FirstOrDefaultAsync(cancellationToken);

            return(result);
        }