Ejemplo n.º 1
0
        public static InvoiceManager CreateNew(uint companyID, uint locationID, DateTime periodFrom, DateTime periodTo)
        {
            var db      = DB.GetContext();
            var invoice = InvoiceRepository.CreateInvoice(db, companyID, locationID, periodFrom, periodTo);

            return(new InvoiceManager(invoice));
        }
        public async Task Handle(OrderCreatedIntegrationEvent @event)
        {
            _logger.LogDebug($"Handling the `Order Created` event from Ordering service");
            var invoice = new Invoice();

            invoice.OrderId = @event.OrderId;

            var productItems = new List <ProductItem>();

            foreach (var item in @event.Products)
            {
                productItems.Add(new ProductItem {
                    ProductName = item.ProductName, Quantity = item.Quantity, UnitPrice = item.UnitPrice
                });
            }
            invoice.ProductsItems = productItems;

            // both saving to repo and publish to event bus should be an atomic transaction.
            // code is only for POC, not fit for production
            // save the invoice to repository
            await _invoiceRepository.CreateInvoice(invoice);

            //build the integration event
            var invoiceProcessedEvent = new InvoiceProcessedIntegrationEvent()
            {
                InvoiceId     = invoice.Id,
                OrderId       = invoice.OrderId,
                InvoiceAmount = invoice.InvoicePrice
            };
            //publish the event to event bus
            await _eventBus.PublishAsync(invoiceProcessedEvent);
        }
Ejemplo n.º 3
0
        public ServiceResult Payment(long orderID, string taxInfo, decimal tax, decimal serviceFee, PaymentMethod paymentMethod)
        {
            var order = Repository.GetByID(orderID);

            if (order == null)
            {
                return(ServiceResult.CreateFailResult());
            }

            InvoiceRepository.CreateInvoice(order, SmsCache.UserContext.UserID, SmsCache.BranchConfigs.Current.Currency, tax, serviceFee, taxInfo, paymentMethod);

            order.OrderProgressStatus = OrderProgressStatus.Done;
            Repository.Save(order);

            return(ServiceResult.CreateSuccessResult());
        }
        public void GenerateInvoices(uint[] companies, uint[] locations, DateTime periodFrom, DateTime periodTo)
        {
            Task.Run(() =>
            {
                try
                {
                    using (var db = DB.GetContext())
                    {
                        float index   = 0.0f;
                        KeyBinder key = new KeyBinder();
                        foreach (uint l in locations)
                        {
                            var loc     = LocationRepository.GetLocation(db, l);
                            var invoice = InvoiceRepository.CreateInvoice(db, loc.CompanyID, loc.LocationID, periodFrom, periodTo);
                            if (invoice.TotalAmount == 0.00m)
                            {
                                continue;
                            }

                            int percent = (int)((index / (float)locations.Length) * 100.0f);
                            RaiseProgress(percent, new ProgressItem(ProgressStatus.OK,
                                                                    string.Format("Generating invoice, Location: {0}", loc.LocationName)));

                            index++;

                            InvoiceRepository.SaveInvoice(db, key, invoice);
                        }

                        db.SaveChanges();
                        key.BindKeys();
                        RaiseComplete(new ProgressItem(ProgressStatus.OK, "Invoice generation complete!"));
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex, "InvoiceCatalogManager.GenerateInvoices()");
                    RaiseComplete(new ProgressItem(ProgressStatus.Error, ex.ToString()));
                }
            });
        }