public RegisterSale[] GetRegisterSales(Guid?outletId, string tag, string[] status) { var result = new RegisterSale[0]; var sb = new StringBuilder(); if (outletId.HasValue) { sb.Append("outlet_id=" + outletId + "&"); } if (!string.IsNullOrEmpty(tag)) { sb.Append("tag=" + tag + "&"); } if (status != null && status.Length > 0) { sb.Append("status=" + status.Join(',') + "&"); } var paramString = sb.ToString().TrimEnd('&'); var response = new VendRequest(this.Url, this.Username, this.Password).Get("/api/register_sales?" + paramString); if (!string.IsNullOrEmpty(response)) { var registerSaleList = response.FromJson <RegisterSaleList>(); result = registerSaleList.RegisterSales; } return(result); }
private void PrintToKitchen(RegisterSale registerSale, string tableName, List <Product> printList) { var printString = new StringBuilder(); printString.Append(Encoding.ASCII.GetString(headerPrintMode)); printString.Append(tableName + "\n\n"); printString.Append(Encoding.ASCII.GetString(normalPrintMode)); printString.Append(" Created Date: " + registerSale.SaleDate + "\n"); printString.Append(Encoding.ASCII.GetString(menuPrintMode)); printString.Append(" Printed Date: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "\n\n"); printString.Append(Encoding.ASCII.GetString(underlinePrintModeOn)); printString.Append("Foor Order\n\n"); printString.Append(Encoding.ASCII.GetString(underlinePrintModeOff)); printString.Append(Encoding.ASCII.GetString(menuPrintMode)); foreach (var product in printList) { if (product.PrintQuantity > 1) { printString.Append("\t " + product.Name + "\n"); } else { printString.Append("\t" + product.PrintQuantity + " X " + product.PrintQuantity + product.Name + "\n"); } } printString.Append("\n\n"); printString.Append(Encoding.ASCII.GetString(normalPrintMode)); if (!string.IsNullOrEmpty(registerSale.Note)) { printString.Append(Encoding.ASCII.GetString(underlinePrintModeOn)); printString.Append("Notes:\n\n"); printString.Append(Encoding.ASCII.GetString(underlinePrintModeOff)); printString.Append(Encoding.ASCII.GetString(normalPrintMode)); printString.Append(registerSale.Note + "\n"); } if (!string.IsNullOrEmpty(registerSale.UserName)) { printString.Append("User: "******"\n\n"); var performCut = new byte[] { 29, 86, 66, 240 }; printString.Append(Encoding.ASCII.GetString(performCut)); PrintThroughDriver.SendStringToPrinter(ConfigurationManager.AppSettings["KitchenPrinter"], printString.ToString()); }
public RegisterSale SaveRegisterSale(RegisterSale registerSale) { RegisterSale result = null; var vendRequest = new VendRequest(this.Url, this.Username, this.Password); var response = vendRequest.Post("/api/register_sales", registerSale.ToJson()); if (!string.IsNullOrEmpty(response)) { var responseRegisterSale = response.FromJson <RegisterSaleWrapper>(); result = responseRegisterSale.RegisterSale; } return(result); }
public void ShouldBeAbleToCreateRegisterSale() { var register = new VendApi(this.Url, this.Username, this.Password).GetRegisters().First(r => r.Name == "Main Register"); var products = new VendApi(this.Url, this.Username, this.Password).GetProducts(Product.OrderBy.name, false, true); var product1 = products.First(p => p.Handle == this.Product1); var product2 = products.First(p => p.Handle == this.Product2); var registerSale = new RegisterSale { RegisterId = register.Id, CustomerId = "null", SaleDate = DateTime.UtcNow.ToString("u"), UserName = "******", TotalPrice = product1.Price + (product2.Price * 2), TotalTax = product1.Tax + (product2.Tax * 2), TaxName = "GST", Status = "SAVED", InvoiceNumber = "102", InvoiceSequence = 102, Note = null, RegisterSaleProducts = new[] { new RegisterSaleProduct { ProductId = product1.Id, Quantity = 1, Price = product1.Price, Tax = product1.Tax, TaxId = product1.TaxId, TaxTotal = product1.Tax }, new RegisterSaleProduct { ProductId = product2.Id, Quantity = 2, Price = product2.Price, Tax = product2.Tax, TaxTotal = product2.Tax * 2 } } }; var savedRegisterSale = new VendApi(this.Url, this.Username, this.Password).SaveRegisterSale(registerSale); Assert.IsNotNull(savedRegisterSale); Assert.AreNotEqual(Guid.Empty, savedRegisterSale.Id); }
private void ProcessRegisterSale(RegisterSale registerSale) { lock (this) { var api = new VendAPI.VendApi( ConfigurationManager.AppSettings["Url"], ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"]); var printList = new List <Product>(); foreach (var registerSaleProduct in registerSale.RegisterSaleProducts) { var product = this.Products.FirstOrDefault(p => p.Id == registerSaleProduct.ProductId); if (product != null && product.Type == "Food" && !this.PrintedRegisterSales.ContainsKey(registerSaleProduct.Id)) { printList.Add(product); product.PrintQuantity = registerSaleProduct.Quantity; this.PrintedRegisterSales.Add(registerSaleProduct.Id, registerSaleProduct.Id); } } if (printList.Count > 0) { var tableName = "Counter Sale"; if (!string.IsNullOrEmpty(registerSale.CustomerName)) { tableName = registerSale.CustomerName; } else if (!string.IsNullOrEmpty(registerSale.CustomerId) && registerSale.CustomerId != Guid.Empty.ToString()) { var customer = api.GetCustomer(registerSale.CustomerId); if (customer != null && customer.ContactFirstName != null && customer.ContactLastName != null) { tableName = customer.ContactFirstName + " " + customer.ContactLastName; } else { tableName = "WALKIN"; } } this.PrintToKitchen(registerSale, tableName, printList); } } }