public async Task Handle(JobOrderRegisteredEvent message)
        {
            var jobOrder = new JobOrder();

            jobOrder.OriginalId         = message.JobOrderId;
            jobOrder.CustomerId         = message.CustomerId;
            jobOrder.CustomerName       = message.CustomerName;
            jobOrder.Description        = message.Description;
            jobOrder.ManagerId          = message.ManagerId;
            jobOrder.DateOfRegistration = message.DateOfRegistration;
            jobOrder.DateOfStart        = message.DateOfStart;
            jobOrder.DueDate            = message.DueDate;
            jobOrder.Name                = message.JobOrderName;
            jobOrder.Number              = message.JobOrderNumber;
            jobOrder.Price               = message.Price;
            jobOrder.Currency            = message.Currency;
            jobOrder.PurchaseOrderNumber = message.PurchaseOrderNumber;
            jobOrder.IsCompleted         = false;
            jobOrder.IsTimeAndMaterial   = false;

            using (var db = new AccountancyDbContext(Options))
            {
                db.JobOrders.Add(jobOrder);
                try
                {
                    await db.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    System.Threading.Thread.Sleep(1);
                }
            }
        }
 public async Task Handle(OutgoingInvoiceLinkedToJobOrderEvent message)
 {
     using (var ctx = new AccountancyDbContext(Options))
     {
         var invoice = ctx.OutgoingInvoices.Where(i => i.OriginalId == message.InvoiceId).Single();
         invoice.JobOrderId = message.JobOrderId;
         await ctx.SaveChangesAsync();
     }
 }
 public async Task Handle(IncomingCreditNoteLinkedToJobOrderEvent message)
 {
     using (var ctx = new AccountancyDbContext(Options))
     {
         var creditNote = ctx.IncomingCreditNotes.Where(i => i.OriginalId == message.CreditNoteId).Single();
         creditNote.JobOrderId = message.JobOrderId;
         await ctx.SaveChangesAsync();
     }
 }
 public async Task Handle(JobOrderExtendedEvent message)
 {
     using (var db = new AccountancyDbContext(Options))
     {
         var jobOrder = db.JobOrders.OfType <JobOrder>().Where(jo => jo.OriginalId == message.JobOrderId).Single();
         jobOrder.DueDate = message.NewDueDate;
         jobOrder.Price   = message.Price;
         await db.SaveChangesAsync();
     }
 }
Exemple #5
0
        protected AccountancyDbContext GetDbContext()
        {
            var readModelConnectionString = ConfigurationManager.ConnectionStrings["Merp-Accountancy-ReadModel"].ConnectionString;
            var optionsBuilder            = new DbContextOptionsBuilder <AccountancyDbContext>();

            optionsBuilder.UseSqlServer(readModelConnectionString);
            var context = new AccountancyDbContext(optionsBuilder.Options);

            return(context);
        }
 public async Task Handle(OutgoingInvoiceGotOverdueEvent message)
 {
     using (var ctx = new AccountancyDbContext(Options))
     {
         var invoice = ctx.OutgoingInvoices
                       .Where(i => i.OriginalId == message.InvoiceId)
                       .Single();
         invoice.IsOverdue = true;
         await ctx.SaveChangesAsync();
     }
 }
 public async Task Handle(IncomingInvoicePaidEvent message)
 {
     using (var ctx = new AccountancyDbContext(Options))
     {
         var invoice = ctx.IncomingInvoices
                       .Where(i => i.OriginalId == message.InvoiceId)
                       .Single();
         invoice.IsPaid      = true;
         invoice.IsOverdue   = false;
         invoice.PaymentDate = message.PaymentDate;
         await ctx.SaveChangesAsync();
     }
 }
 public async Task Handle(JobOrderCompletedEvent message)
 {
     using (var db = new AccountancyDbContext(Options))
     {
         var jobOrder = db.JobOrders
                        .OfType <JobOrder>()
                        .Where(jo => jo.OriginalId == message.JobOrderId)
                        .Single();
         jobOrder.DateOfCompletion = message.DateOfCompletion;
         jobOrder.IsCompleted      = true;
         await db.SaveChangesAsync();
     }
 }
        public async Task Handle(OutgoingInvoiceIssuedEvent message)
        {
            var invoice = new OutgoingInvoice();

            invoice.TaxableAmount       = message.TaxableAmount;
            invoice.Currency            = message.Currency;
            invoice.Date                = message.InvoiceDate;
            invoice.DueDate             = message.DueDate;
            invoice.Description         = message.Description;
            invoice.Number              = message.InvoiceNumber;
            invoice.OriginalId          = message.InvoiceId;
            invoice.PurchaseOrderNumber = message.PurchaseOrderNumber;
            invoice.Taxes               = message.Taxes;
            invoice.TotalPrice          = message.TotalPrice;
            invoice.IsOverdue           = false;
            invoice.IsPaid              = false;
            invoice.Customer            = new Invoice.PartyInfo()
            {
                City    = message.Customer.City,
                Country = message.Customer.Country,
                Name    = message.Customer.Name,
                NationalIdentificationNumber = message.Customer.NationalIdentificationNumber,
                OriginalId = message.Customer.Id,
                PostalCode = message.Customer.PostalCode,
                StreetName = message.Customer.StreetName,
                VatIndex   = message.Customer.VatIndex
            };
            invoice.Supplier = new Invoice.PartyInfo()
            {
                City    = message.Supplier.City,
                Country = message.Supplier.Country,
                Name    = message.Supplier.Name,
                NationalIdentificationNumber = message.Supplier.NationalIdentificationNumber,
                OriginalId = message.Supplier.Id,
                PostalCode = message.Supplier.PostalCode,
                StreetName = message.Supplier.StreetName,
                VatIndex   = message.Supplier.VatIndex
            };
            using (var ctx = new AccountancyDbContext(Options))
            {
                ctx.OutgoingInvoices.Add(invoice);
                await ctx.SaveChangesAsync();
            }
        }
Exemple #10
0
 public NetIncomeIntentWorker(AccountancyDbContext context)
 {
     ActiveDbContext = context ?? throw new ArgumentNullException(nameof(context));
 }
        public async Task Handle(IncomingInvoiceRegisteredEvent message)
        {
            var invoice = new IncomingInvoice();

            invoice.TaxableAmount       = message.TaxableAmount;
            invoice.Currency            = message.Currency;
            invoice.Date                = message.InvoiceDate;
            invoice.DueDate             = message.DueDate;
            invoice.Description         = message.Description;
            invoice.Number              = message.InvoiceNumber;
            invoice.OriginalId          = message.InvoiceId;
            invoice.PurchaseOrderNumber = message.PurchaseOrderNumber;
            invoice.Taxes               = message.Taxes;
            invoice.TotalPrice          = message.TotalPrice;
            invoice.IsOverdue           = false;
            invoice.IsPaid              = false;
            invoice.Customer            = new Invoice.PartyInfo()
            {
                City    = message.Customer.City,
                Country = message.Customer.Country,
                Name    = message.Customer.Name,
                NationalIdentificationNumber = message.Customer.NationalIdentificationNumber,
                OriginalId = message.Customer.Id,
                PostalCode = message.Customer.PostalCode,
                StreetName = message.Customer.StreetName,
                VatIndex   = message.Customer.VatIndex
            };
            invoice.Supplier = new Invoice.PartyInfo()
            {
                City    = message.Supplier.City,
                Country = message.Supplier.Country,
                Name    = message.Supplier.Name,
                NationalIdentificationNumber = message.Supplier.NationalIdentificationNumber,
                OriginalId = message.Supplier.Id,
                PostalCode = message.Supplier.PostalCode,
                StreetName = message.Supplier.StreetName,
                VatIndex   = message.Supplier.VatIndex
            };
            if (message.LineItems != null && message.LineItems.Count() > 0)
            {
                invoice.InvoiceLineItems = message.LineItems.Select(i => new InvoiceLineItem
                {
                    Code        = i.Code,
                    Description = i.Description,
                    Quantity    = i.Quantity,
                    TotalPrice  = i.TotalPrice,
                    UnitPrice   = i.UnitPrice,
                    Vat         = i.Vat
                }).ToList();
            }
            if (message.PricesByVat != null && message.PricesByVat.Count() > 0)
            {
                invoice.PricesByVat = message.PricesByVat.Select(p => new PriceByVat
                {
                    TaxableAmount = p.TaxableAmount,
                    TotalPrice    = p.TotalPrice,
                    VatAmount     = p.VatAmount,
                    VatRate       = p.VatRate
                }).ToList();
            }
            if (message.NonTaxableItems != null && message.NonTaxableItems.Count() > 0)
            {
                invoice.NonTaxableItems = message.NonTaxableItems.Select(t => new NonTaxableItem
                {
                    Description = t.Description,
                    Amount      = t.Amount
                }).ToList();
            }

            invoice.PricesAreVatIncluded = message.PricesAreVatIncluded;

            using (var ctx = new AccountancyDbContext(Options))
            {
                ctx.IncomingInvoices.Add(invoice);
                await ctx.SaveChangesAsync();
            }
        }
Exemple #12
0
        public async Task Handle(OutgoingCreditNoteIssuedEvent message)
        {
            var creditNote = new OutgoingCreditNote();

            creditNote.TaxableAmount       = message.TaxableAmount;
            creditNote.Currency            = message.Currency;
            creditNote.Date                = message.CreditNoteDate;
            creditNote.Description         = message.Description;
            creditNote.Number              = message.CreditNoteNumber;
            creditNote.OriginalId          = message.CreditNoteId;
            creditNote.PurchaseOrderNumber = message.PurchaseOrderNumber;
            creditNote.Taxes               = message.Taxes;
            creditNote.TotalPrice          = message.TotalPrice;
            creditNote.TotalToPay          = message.TotalToPay;
            creditNote.IsOverdue           = false;
            creditNote.IsPaid              = false;
            creditNote.Customer            = new Invoice.PartyInfo()
            {
                City    = message.Customer.City,
                Country = message.Customer.Country,
                Name    = message.Customer.Name,
                NationalIdentificationNumber = message.Customer.NationalIdentificationNumber,
                OriginalId = message.Customer.Id,
                PostalCode = message.Customer.PostalCode,
                StreetName = message.Customer.StreetName,
                VatIndex   = message.Customer.VatIndex
            };
            creditNote.Supplier = new Invoice.PartyInfo()
            {
                City    = message.Supplier.City,
                Country = message.Supplier.Country,
                Name    = message.Supplier.Name,
                NationalIdentificationNumber = message.Supplier.NationalIdentificationNumber,
                OriginalId = message.Supplier.Id,
                PostalCode = message.Supplier.PostalCode,
                StreetName = message.Supplier.StreetName,
                VatIndex   = message.Supplier.VatIndex
            };

            if (message.LineItems != null && message.LineItems.Count() > 0)
            {
                creditNote.InvoiceLineItems = message.LineItems.Select(i => new InvoiceLineItem
                {
                    Code           = i.Code,
                    Description    = i.Description,
                    Quantity       = i.Quantity,
                    TotalPrice     = i.TotalPrice,
                    UnitPrice      = i.UnitPrice,
                    Vat            = i.Vat,
                    VatDescription = i.VatDescription
                }).ToList();
            }

            if (message.PricesByVat != null && message.PricesByVat.Count() > 0)
            {
                creditNote.PricesByVat = message.PricesByVat.Select(p => new PriceByVat
                {
                    TaxableAmount = p.TaxableAmount,
                    TotalPrice    = p.TotalPrice,
                    VatAmount     = p.VatAmount,
                    VatRate       = p.VatRate
                }).ToList();
            }

            if (message.NonTaxableItems != null && message.NonTaxableItems.Count() > 0)
            {
                creditNote.NonTaxableItems = message.NonTaxableItems.Select(t => new NonTaxableItem
                {
                    Description = t.Description,
                    Amount      = t.Amount
                }).ToList();
            }

            creditNote.PricesAreVatIncluded = message.PricesAreVatIncluded;

            if (!string.IsNullOrWhiteSpace(message.ProvidenceFundDescription) && message.ProvidenceFundRate.HasValue && message.ProvidenceFundAmount.HasValue)
            {
                creditNote.ProvidenceFund = new ProvidenceFund
                {
                    Amount      = message.ProvidenceFundAmount.Value,
                    Description = message.ProvidenceFundDescription,
                    Rate        = message.ProvidenceFundRate.Value
                };
            }

            if (!string.IsNullOrWhiteSpace(message.WithholdingTaxDescription) && message.WithholdingTaxRate.HasValue && message.WithholdingTaxTaxableAmountRate.HasValue && message.WithholdingTaxAmount.HasValue)
            {
                creditNote.WithholdingTax = new WithholdingTax
                {
                    Amount            = message.WithholdingTaxAmount.Value,
                    Description       = message.WithholdingTaxDescription,
                    Rate              = message.WithholdingTaxRate.Value,
                    TaxableAmountRate = message.WithholdingTaxTaxableAmountRate.Value
                };
            }

            using (var ctx = new AccountancyDbContext(Options))
            {
                ctx.OutgoingCreditNotes.Add(creditNote);
                await ctx.SaveChangesAsync();
            }
        }
Exemple #13
0
 public OutgoingInvoicePaymentCheckWorker(AccountancyDbContext context)
 {
     ActiveDbContext = context ?? throw new ArgumentNullException(nameof(context));
 }