Ejemplo n.º 1
0
        private IEnumerable <SelectListItem> ComputeDropdownSource(BreakdownAnnuitiesModel model)
        {
            var isFirstPayment = model.FillingDate.HasValue && model.GrantDate.HasValue;
            var result         = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text  = "Total Annuity",
                    Value = "TotalAnnuities"
                },
                new SelectListItem()
                {
                    Text     = "First Grant Payment",
                    Value    = "FirstGrantPayment",
                    Disabled = !isFirstPayment
                }
            };

            if (!isFirstPayment)
            {
                return(result);
            }
            int payableYear    = 0;
            int protectionYear = model.GrantDate.Value.Year - model.FillingDate.Value.Year;

            if (model.GrantDate.Value.Month > model.FillingDate.Value.Month ||
                (model.GrantDate.Value.Month == model.FillingDate.Value.Month &&
                 model.GrantDate.Value.Day >= model.FillingDate.Value.Day))
            {
                protectionYear++;
            }
            payableYear = protectionYear + 1;

            if (payableYear > 0)
            {
                for (int i = 1; i <= payableYear; ++i)
                {
                    result.Add(new SelectListItem()
                    {
                        Text  = $"Annuity year {i}",
                        Value = i.ToString()
                    });
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public BreakdownAnnuitiesModel CalculatePatentFees(CalculationRequest request)
        {
            // Display value by report type "Total Calculation" or "First Payment Calculation"
            int payableYear = 0;

            if (request.ReportTypeId == ReportType.FirstGrantPayment && request.FilingDate.HasValue &&
                request.GrantDate.HasValue)
            {
                int protectionYear = request.GrantDate.Value.Year - request.FilingDate.Value.Year;
                if (request.GrantDate.Value.Month > request.FilingDate.Value.Month ||
                    (request.GrantDate.Value.Month == request.FilingDate.Value.Month &&
                     request.GrantDate.Value.Day >= request.FilingDate.Value.Day))
                {
                    protectionYear++;
                }

                payableYear = protectionYear + 1;
            }

            var country      = CountryRepository.GetByID(request.CountryCode);
            var patentFees   = new List <Models.PatentFee>();
            var officialFees = OfficialFeeRepository
                               .GetOfficialFees(request.CountryCode, request.PatentTypeId, payableYear).ToList();

            var hasAgencyFeeWithCurrency =
                AgencyFeeRepository.HasFeeWithCurrencyCode(request.CountryCode, request.PatentTypeId,
                                                           request.CurrencyCode);

            var agencyFees = hasAgencyFeeWithCurrency
                ? AgencyFeeRepository.GetAgencyFees(request.CountryCode, request.PatentTypeId, request.CurrencyCode, payableYear).ToList()
                : AgencyFeeRepository.GetAgencyFees(request.CountryCode, request.PatentTypeId, payableYear).ToList();

            string agencyCurrencyCode =
                agencyFees.Any() ? agencyFees.FirstOrDefault().CurrencyCode : country.DefaultCurrency;

            if (string.IsNullOrEmpty(agencyCurrencyCode))
            {
                agencyCurrencyCode = request.CurrencyCode;
            }

            int maxYear = Math.Max(officialFees.Any() ? officialFees.Max(o => o.Year) : 0,
                                   agencyFees.Any() ? agencyFees.Max(o => o.Year) : 0);

            if (maxYear > 0)
            {
                var expectedYear = request.ExpectedPayableYear;
                if (expectedYear > 0)
                {
                    var index     = expectedYear - 1;
                    var patentFee = new Models.PatentFee();
                    patentFee.PatentTypeId       = (byte)request.PatentTypeId;
                    patentFee.Year               = (byte)(expectedYear);
                    patentFee.CountryCode        = request.CountryCode;
                    patentFee.AgencyCurrencyCode = agencyCurrencyCode;
                    patentFee.BasicFee           = index < officialFees.Count && officialFees[index] != null
                        ? officialFees[index].BasicFee
                        : 0;
                    patentFee.ClaimFee = index < officialFees.Count && officialFees[index] != null
                        ? officialFees[index].ClaimFee
                        : 0;
                    patentFee.AgencyFee = index < agencyFees.Count && agencyFees[index] != null
                        ? agencyFees[index].Fee
                        : 0;
                    patentFees.Add(patentFee);
                }
                else
                {
                    for (int i = 0; i < maxYear; i++)
                    {
                        var patentFee = new Models.PatentFee();
                        patentFee.PatentTypeId       = (byte)request.PatentTypeId;
                        patentFee.Year               = (byte)(i + 1);
                        patentFee.CountryCode        = request.CountryCode;
                        patentFee.AgencyCurrencyCode = agencyCurrencyCode;
                        patentFee.BasicFee           = i < officialFees.Count && officialFees[i] != null
                            ? officialFees[i].BasicFee
                            : 0;
                        patentFee.ClaimFee = i < officialFees.Count && officialFees[i] != null
                            ? officialFees[i].ClaimFee
                            : 0;
                        patentFee.AgencyFee = i < agencyFees.Count && agencyFees[i] != null ? agencyFees[i].Fee : 0;
                        patentFees.Add(patentFee);
                    }
                }
            }

            if (patentFees != null && patentFees.Count > 0)
            {
                var result = new BreakdownAnnuitiesModel()
                {
                    ApplicationPatentNo   = request.ApplicationPatentNo,
                    PatentType            = ((PatentTypes)request.PatentTypeId).ToString(),
                    NumberOfClaim         = request.NoOfClaim,
                    AnnuitiesData         = new List <AnnuityModel>(),
                    FillingDate           = request.FilingDate,
                    GrantDate             = request.GrantDate,
                    PayableYear           = payableYear,
                    AgencyFeeDiscountRate = request.AgencyFeeDiscount,
                    CreateCountry         = CountryRepository.GetByID(request.CountryCode)?.Name
                };

                decimal rateForAgencyFee   = 1;
                decimal rateForOfficialFee = 1;
                // Calculate by currency
                if (!string.IsNullOrEmpty(request.CurrencyCode))
                {
                    result.DefaultCurrencyCode = country.DefaultCurrency;
                    result.CurrencyCode        = request.CurrencyCode;
                    if (!hasAgencyFeeWithCurrency)
                    {
                        var requestCurrency = CurrencyRepository.GetByID(request.CurrencyCode);
                        if (requestCurrency != null && requestCurrency.Rate.HasValue)
                        {
                            var currency = CurrencyRepository.GetByID(agencyCurrencyCode);
                            if (currency.Rate.HasValue)
                            {
                                rateForAgencyFee = requestCurrency.Rate.Value / currency.Rate.Value;
                            }
                        }
                    }
                    if (country.DefaultCurrency != request.CurrencyCode)
                    {
                        var requestCurrency = CurrencyRepository.GetByID(request.CurrencyCode);
                        if (requestCurrency != null && requestCurrency.Rate.HasValue)
                        {
                            var currency = CurrencyRepository.GetByID(country.DefaultCurrency);
                            if (currency.Rate.HasValue)
                            {
                                rateForOfficialFee = requestCurrency.Rate.Value / currency.Rate.Value;
                                result.FXRate      = rateForOfficialFee;
                            }
                        }
                    }
                }

                result.AnnuitiesData = patentFees.Select(p => new AnnuityModel()
                {
                    AnnuityNo   = p.Year,
                    NoOfClaim   = request.NoOfClaim,
                    BasicFee    = p.BasicFee,
                    ClaimFee    = p.ClaimFee * request.NoOfClaim,
                    AgencyFee   = p.AgencyFee * rateForAgencyFee,
                    OfficialFee = (p.BasicFee + p.ClaimFee * request.NoOfClaim)
                }).ToList();

                result.SubTotalOfficialFees = result.AnnuitiesData.Sum(a => a.OfficialFee) * rateForOfficialFee;
                result.SubTotalAgencyFees   = result.AnnuitiesData.Sum(a => a.AgencyFee);
                result.AgencyFeeDiscount    = result.SubTotalAgencyFees * request.AgencyFeeDiscount / 100;
                result.TotalFees            = result.SubTotalAgencyFees + result.SubTotalOfficialFees - result.AgencyFeeDiscount;

                var tax = context.Taxes.FirstOrDefault(t => t.CountryCode == request.CountryCode && !t.Deleted);
                if (tax != null)
                {
                    result.TaxRate = tax.Percentage;
                    result.Taxes   = result.TotalFees * tax.Percentage / 100;
                }
                result.TotalCostEstimation = result.TotalFees + result.Taxes;


                return(result);
            }
            return(null);
        }