public void Save() { var invoice = new Invoice { DateTime = DateTimeOffset.Now, CustomerId = Customer.Id }; var invoiceItems = new List<InvoiceItem>(Items .Where(o => o.Quantity > 0) .Select((o,i) => new InvoiceItem { ItemNumber = i + 1, ProductId = o.Product.Id, Price = o.Product.Price, Quantity = o.Quantity })); InvoiceService.AddInvoice(invoice, invoiceItems, 0); Close(); }
public void AddInvoice(Invoice invoice, IEnumerable<InvoiceItem> items, decimal payment) { using (var transaction = new TransactionScope()) using (var connection = new ConnectionScope()) { // Insert Invoice. invoice.Insert(); foreach (var item in items) item.InvoiceId = invoice.Id; items.Insert(); // Update Inventory. foreach (var item in items) { var product = ProductManager.GetProduct(item.ProductId); if (product == null) throw new Exception("Product not found."); // Stock Correction? if (product.QuantityOnHand < item.Quantity) { ProductManager.AddMovement(new ProductMovement { Id = Guid.NewGuid(), ProductId = item.ProductId, DateTime = invoice.DateTime, MovementType = ProductMovementType.Correction, Quantity = item.Quantity - product.QuantityOnHand, SourceId = invoice.Id, SourceItemNumber = item.ItemNumber }); } // Movement. ProductManager.AddMovement(new ProductMovement { Id = Guid.NewGuid(), ProductId = item.ProductId, DateTime = invoice.DateTime, MovementType = ProductMovementType.Invoice, Quantity = item.Quantity * -1, SourceId = invoice.Id, SourceItemNumber = item.ItemNumber }); } // Add Customer Transaction. CustomerManager.AddTransaction(new CustomerTransaction() { Id = Guid.NewGuid(), CustomerId = invoice.CustomerId, DateTime = invoice.DateTime, Type = CustomerTransactionType.Invoice, Amount = items.Aggregate(0.0m, (total, item) => total += item.Quantity * Math.Round(item.Price * (100 - item.Discount) / 100, 2, MidpointRounding.AwayFromZero)), SourceId = invoice.Id }); // Payment? if (payment > 0) { CustomerManager.AddTransaction(new CustomerTransaction() { Id = Guid.NewGuid(), CustomerId = invoice.CustomerId, DateTime = invoice.DateTime, Type = CustomerTransactionType.Payment, Amount = payment * -1, SourceId = invoice.Id }); } transaction.Complete(); } }
public void AddReceipt(Invoice invoice, IEnumerable<InvoiceItem> items) { using (var transaction = new TransactionScope()) using (var connection = new ConnectionScope()) { if (invoice.Id == Guid.Empty) invoice.Id = Guid.NewGuid(); // Update Inventory. foreach (var item in items) { var product = ProductManager.GetProduct(item.ProductId); if (product == null) throw new Exception("Product not found."); // Stock Correction? // TODO. // Movement. ProductManager.AddMovement(new ProductMovement { Id = Guid.NewGuid(), ProductId = item.ProductId, DateTime = invoice.DateTime, MovementType = ProductMovementType.Receipt, Quantity = item.Quantity, SourceId = invoice.Id, SourceItemNumber = item.ItemNumber }); } // Add Customer Transaction. CustomerManager.AddTransaction(new CustomerTransaction() { Id = Guid.NewGuid(), CustomerId = invoice.CustomerId, DateTime = invoice.DateTime, Type = CustomerTransactionType.Payment, Amount = items.Aggregate(0.0m, (total, item) => total += item.Quantity * item.Price) * -1.0m, SourceId = invoice.Id }); transaction.Complete(); } }
public void AddReceipt(Invoice invoice, IEnumerable<InvoiceItem> items) { Manager.AddReceipt(invoice, items); }
public void AddInvoice(Invoice invoice, IEnumerable<InvoiceItem> items, decimal payment) { Manager.AddInvoice(invoice, items, payment); }
public void Checkout() { var processvm = IoC.Get<ProcessViewModel>(); processvm.Content = "Processing..."; processvm.ProcessAction = () => { var invoice = new Invoice { DateTime = DateTimeOffset.Now, CustomerId = Customer.Id }; var invoiceItems = new List<InvoiceItem>(Products .Where(o => o.Quantity > 0) .Select((o, i) => new InvoiceItem { ItemNumber = i + 1, ProductId = o.Product.Id, Quantity = o.Quantity, Price = o.Product.Price, Discount = o.Discount })); InvoiceService.AddInvoice(invoice, invoiceItems, IsCashAccount ? Total : 0.0m); Customer.Balance = CustomerService.GetCustomer(Customer.Id).Balance; }; processvm.CompleteAction = () => { var message = IoC.Get<MessageBoxViewModel>(); message.Content = new CustomerTransactionInfo { NewBalance = Customer.Balance }; message.DismissAction = () => ScreenCoordinator.NavigateToHome(); message.DismissTimeout = 2500; ScreenCoordinator.NavigateToScreen(message); }; ScreenCoordinator.NavigateToScreen(processvm); }