Beispiel #1
0
        public async Task CreateVat(Guid subscriptionId, string country, decimal rate, string description)
        {
            if (subscriptionId == Guid.Empty)
            {
                throw new ArgumentException("value cannot be empty", nameof(subscriptionId));
            }

            if (string.IsNullOrWhiteSpace(country))
            {
                throw new ArgumentException("value cannot be empty", nameof(country));
            }

            if (rate < 0)
            {
                throw new ArgumentException("value cannot be less than zero", nameof(rate));
            }

            if (string.IsNullOrWhiteSpace(description))
            {
                throw new ArgumentException("value cannot be empty", nameof(description));
            }

            var vat = new Vat
            {
                Id             = Guid.NewGuid(),
                SubscriptionId = subscriptionId,
                Country        = country,
                Description    = description,
                Rate           = rate,
                Unlisted       = false
            };

            _context.Add(vat);
            await _context.SaveChangesAsync();
        }
        public async Task SaveSettingsDefaults(Guid subscriptionId, bool minimumTaxPayerRegime, bool electronicInvoiceEnabled, bool splitPaymentApplied, Guid?vatId, Guid?providenceFundId, Guid?withholdingTaxId)
        {
            var defaults = _context.SettingsDefaults
                           .BySubscriptionId(subscriptionId)
                           .Include(s => s.Vat)
                           .Include(s => s.WithholdingTax)
                           .Include(s => s.ProvidenceFund)
                           .SingleOrDefault();

            Vat vat = null;

            if (vatId.HasValue)
            {
                vat = _context.Vats.SingleOrDefault(v => v.Id == vatId.Value);
            }

            ProvidenceFund providenceFund = null;

            if (providenceFundId.HasValue)
            {
                providenceFund = _context.ProvidenceFunds.SingleOrDefault(p => p.Id == providenceFundId.Value);
            }

            WithholdingTax withholdingTax = null;

            if (withholdingTaxId.HasValue)
            {
                withholdingTax = _context.WithholdingTaxes.SingleOrDefault(w => w.Id == withholdingTaxId.Value);
            }

            if (defaults == null)
            {
                CreateSettingsDefaults(
                    subscriptionId,
                    minimumTaxPayerRegime,
                    electronicInvoiceEnabled,
                    splitPaymentApplied,
                    vat,
                    providenceFund,
                    withholdingTax);
            }
            else
            {
                EditSettingsDefaults(
                    defaults,
                    minimumTaxPayerRegime,
                    electronicInvoiceEnabled,
                    splitPaymentApplied,
                    vat,
                    providenceFund,
                    withholdingTax);
            }

            await _context.SaveChangesAsync();
        }