SendToKitchen() public method

Directs the API to send the order to the kitchen at this time. Only the items that have not previously been printed in the kitchen are printed.
public SendToKitchen ( Context context, long invoiceNumber ) : bool
context Context The store id, station id, and cashier id the information should be restricted to.
invoiceNumber long The number of the invoice that should be sent the kitchen
return bool
        static void TestSales()
        {
            try
            {
                SalesAPI api = new SalesAPI();

                DateTime startDateTime = DateTime.Parse("1/1/2010");
                DateTime endDateTime = DateTime.Parse("12/31/2010");

                SalesTotals totals = api.GetTotals(startDateTime, endDateTime);
                Console.WriteLine(
                    String.Format("Sales totals between {0}-{1} -- NetSales:{2} TotalTax:{3} GrandTotal:{4}",
                                  startDateTime, endDateTime, totals.NetSales, totals.TotalTax, totals.GrandTotal));

                List<ItemSale> sales = api.GetItemsSold(startDateTime, endDateTime);
                Console.WriteLine(String.Format("Between {0}-{1}, there are {2} records of items being sold",
                                                startDateTime, endDateTime, sales.Count));

                pcAmerica.DesktopPOS.API.Client.SalesService.Context context =
                    new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
                context.CashierID = "100101";
                context.StoreID = "1001";
                context.StationID = "01";

                // StartNewInvoice - this also automatically locks an invoice so it can't be opened by a terminal
                Invoice inv = api.StartNewInvoice(context, "ROB" + DateTime.Now.Second.ToString(), "XXOPEN TABS");
                Console.WriteLine(String.Format("Started new invoice with #: {0}", inv.InvoiceNumber));

                // Unlock Invoice
                if (api.UnLockInvoice(context, inv.InvoiceNumber))
                    Console.WriteLine(String.Format("Unlocked invoice # {0}", inv.InvoiceNumber));
                else
                    Console.WriteLine(String.Format("Failed to unlock invoice # {0}", inv.InvoiceNumber));

                // Lock Invoice
                if (api.LockInvoice(context, inv.InvoiceNumber))
                    Console.WriteLine(String.Format("Locked invoice # {0}", inv.InvoiceNumber));
                else
                    Console.WriteLine(String.Format("Failed to lock invoice # {0}", inv.InvoiceNumber));

                // GetInvoiceHeader
                inv = api.GetInvoiceHeader(context, inv.InvoiceNumber);
                Console.WriteLine(String.Format("GetInvoiceHeader with #: {0}", inv.InvoiceNumber));

                // GetInvoice
                inv = api.GetInvoice(context, inv.InvoiceNumber);
                Console.WriteLine(String.Format("GetInvoice with #: {0}", inv.InvoiceNumber));

                // ModifyItems
                inv.LineItems.Add(new LineItem()
                {
                    Id = Guid.NewGuid(),
                    ItemName = "Non Inventory",
                    ItemNumber = "Non_Inventory",
                    Price = 1,
                    Quantity = 1,
                    State = EntityState.Added
                });
                inv.LineItems.Add(new LineItem()
                {
                    Id = Guid.NewGuid(),
                    ItemName = "Non Inventory",
                    ItemNumber = "Non_Inventory",
                    Price = 2,
                    Quantity = 1,
                    State = EntityState.Added
                });
                inv.LineItems.Add(new LineItem()
                {
                    Id = Guid.NewGuid(),
                    ItemName = "Non Inventory",
                    ItemNumber = "Non_Inventory",
                    Price = 3,
                    Quantity = 1,
                    State = EntityState.Added,
                    ParentId = inv.LineItems[1].Id
                });
                inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
                Console.WriteLine(String.Format("ModifyItems new invoice value: {0}", inv.GrandTotal));
                inv.LineItems[0].State = EntityState.Deleted;
                inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
                Console.WriteLine(String.Format("ModifyItems DELETED 1st item, new invoice value: {0}", inv.GrandTotal));
                inv.LineItems[0].Quantity = 2;
                inv.LineItems[0].State = EntityState.Modified;
                inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
                Console.WriteLine(String.Format("ModifyItems CHANGED 1st item QUANTITY, new invoice value: {0}",
                                                inv.GrandTotal));
                inv.LineItems.Add(new LineItem()
                {
                    ItemNumber = "Non_Inventory",
                    ItemName = "Hot dog",
                    Price = 1,
                    Quantity = 1,
                    State = EntityState.Added
                });
                inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
                Console.WriteLine(String.Format("ModifyItems ADDED item # 1, new invoice value: {0}", inv.GrandTotal));

                // SendToKitchen
                if (api.SendToKitchen(context, inv.InvoiceNumber))
                    Console.WriteLine("Invoice was printed in kitchen");
                else
                    Console.WriteLine("***ERROR*** Invoice was NOT printed in kitchen");

                if (api.SendToKitchen(context, inv.InvoiceNumber))
                    Console.WriteLine(
                        "Invoice was printed in kitchen, it should not have printed anything out the 2nd time");
                else
                    Console.WriteLine("***ERROR*** Invoice was NOT printed in kitchen");

                // Splitcheck
                inv = api.SplitInvoice(context, inv.InvoiceNumber, 2);
                if (inv.SplitInfo.NumberOfSplitChecks == 2)
                    Console.WriteLine("Split invoice 2 ways");
                else
                    Console.WriteLine("***ERROR*** Invoice could be split");

                // CombineSplits
                inv = api.CombineSplits(context, inv.InvoiceNumber);
                if (inv.SplitInfo.NumberOfSplitChecks == 0)
                    Console.WriteLine("Combined split checks");
                else
                    Console.WriteLine("***ERROR*** Invoice could be split");

                // GetAllOnHoldInvoices
                List<OnHoldInfo> onHoldInfos = api.GetAllOnHoldInvoices(context);
                if (onHoldInfos == null)
                    Console.WriteLine("***ERROR*** Could not retrieve GetAllOnHoldInvoices");
                else
                {
                    Console.WriteLine(String.Format("Retrieved {0} OnHoldInfo from GetAllOnHoldInvoices",
                                                    onHoldInfos.Count));
                    foreach (OnHoldInfo onHoldInfo in onHoldInfos)
                    {
                        if (onHoldInfo.Locked == true)
                        {
                            Console.WriteLine(String.Format("Invoice {0} is locked by Station {1}",
                                                            onHoldInfo.InvoiceNumber, onHoldInfo.LockedByStation));
                        }
                    }
                }

                // GetOnHoldInvoicesForCashier
                onHoldInfos = api.GetOnHoldInvoicesForCashier(context);
                if (onHoldInfos == null)
                    Console.WriteLine("***ERROR*** Could not retrieve GetOnHoldInvoicesForCashier");
                else
                {
                    Console.WriteLine(String.Format("Retrieved {0} OnHoldInfo from GetOnHoldInvoicesForCashier",
                                                    onHoldInfos.Count));
                    foreach (OnHoldInfo onHoldInfo in onHoldInfos)
                    {
                        if (onHoldInfo.Locked == true)
                        {
                            Console.WriteLine(String.Format("Invoice {0} is locked by Station {1}", onHoldInfo.InvoiceNumber, onHoldInfo.LockedByStation));
                        }
                    }
                }

                // ApplyCashPayment - applying grand total minus 1 dollar
                AppliedPaymentResponse payResponse = api.ApplyCashPayment(context, inv.InvoiceNumber, -1, inv.GrandTotal - 1);
                if (payResponse.Success)
                    Console.WriteLine(String.Format("Applied cash payment, change due {0}", payResponse.ChangeAmount));
                else
                    Console.WriteLine("***ERROR*** Could not apply payment");

                // ApplyCardPayment - applying remaining 1 dollar as a credit card
                payResponse = api.ApplyCardPayment(context,
                    inv.InvoiceNumber,
                    -1,
                    new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse()
                    {
                        Amount = 1,
                        CardNumber = "4***********1",
                        ReferenceNumber = "123456",
                        Result = true,
                        TipAmount = 1,
                        TransactionNumber = 1234
                    }, -1);
                if (payResponse.Success)
                    Console.WriteLine(String.Format("Applied card payment, change due {0}", payResponse.ChangeAmount));
                else
                    Console.WriteLine("***ERROR*** Could not apply card payment");

                // EndInvoice
                if (api.EndInvoice(context, inv.InvoiceNumber))
                    Console.WriteLine("Ended invoice successfully");
                else
                    Console.WriteLine("***ERROR*** Could not end invoice");

                // PrintReceipt - providing -1 for the split check # when there are no split checks
                if (api.PrintReceipt(context, inv.InvoiceNumber, -1))
                    Console.WriteLine("Receipt was printed");
                else
                    Console.WriteLine("***ERROR*** Receive was NOT printed");

                // EmailReceipt - providing -1 for the split check # when there are no split checks
                if (api.EmailReceipt(context, inv.InvoiceNumber, -1, "*****@*****.**"))
                    Console.WriteLine("Receipt was emailed");
                else
                    Console.WriteLine("***ERROR*** Receipt was NOT emailed");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Console.WriteLine("PRESS ENTER TO CONTINUE...");
                Console.ReadLine();
            }
        }
        static void testSendToKitchen()
        {
            try
            {
                SalesAPI api = new SalesAPI();

                pcAmerica.DesktopPOS.API.Client.SalesService.Context context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
                context.CashierID = "100101";
                context.StoreID = "1001";
                context.StationID = "01";

                Random random = new Random();
                Invoice inv = api.StartNewInvoice(context, "Audry" + random.Next(0,10000) , "XXOPEN TABS");
                api.LockInvoice(context, inv.InvoiceNumber);
                inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 3, State = EntityState.Added, Guest = "1" });
                inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 3, State = EntityState.Added, Guest = "1" });
                inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 3, State = EntityState.Added, Guest = "1" });
                inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
                Console.WriteLine("Three Tripple Cheese Burgers added to invoice");

                Console.WriteLine("Needs to be sent to kitchen: {0}", inv.NeedsToBeSentToKitchen);
                DoItemsNeedToBeSentToKitchen(context, inv.InvoiceNumber);

                if (api.SendToKitchen(context, inv.InvoiceNumber))// should output items sent to kitchen
                {
                    Console.WriteLine("Items Sent To Kitchen");
                }
                else
                {
                    Console.WriteLine("Failed sending items to kitchen");
                }
                Console.WriteLine("");

                inv.LineItems[1].State = EntityState.Deleted;
                inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
                Console.WriteLine("Tripple Cheese Burger in position 1 deletd");
                Console.WriteLine("Needs to be sent to kitchen: {0}",inv.NeedsToBeSentToKitchen);
                DoItemsNeedToBeSentToKitchen(context, inv.InvoiceNumber);
                if (api.SendToKitchen(context, inv.InvoiceNumber))
                {
                    Console.WriteLine("Items Sent To Kitchen");
                }
                else
                {
                    Console.WriteLine("Failed sending items to kitchen");
                }
                Console.WriteLine("");

                Console.WriteLine("Did nothing checking for false");
                inv = api.GetInvoice(context, inv.InvoiceNumber);
                Console.WriteLine("Needs to be sent to kitchen: {0}", inv.NeedsToBeSentToKitchen);
                DoItemsNeedToBeSentToKitchen(context, inv.InvoiceNumber);
                if (api.SendToKitchen(context, inv.InvoiceNumber))
                {
                    Console.WriteLine("Items Sent To Kitchen");
                }
                else
                {
                    Console.WriteLine("Failed sending items to kitchen");
                }

                api.VoidInvoice(context, inv.InvoiceNumber, true);

            }
            catch (Exception ex)
            {

                Console.WriteLine(ex);
            }
            finally
            {
                Console.WriteLine("PRESS ENTER TO CONTINUE...");
                Console.ReadLine();
            }
        }
        // more examples to work specificly with the sample database Burger Express that comes bundled with Resturant Pro Express
        // shows getting list of all inventory items, adding items two different ways, selecting a modifier for an item and splitting a check by guest
        static void TestBurgerExpress()
        {
            try
            {
                SalesAPI api = new SalesAPI();

                DateTime startDateTime = DateTime.Parse("1/1/2010");
                DateTime endDateTime = DateTime.Parse("12/31/2010");

                SalesTotals totals = api.GetTotals(startDateTime, endDateTime);
                Console.WriteLine(String.Format("Sales totals between {0}-{1} -- NetSales:{2} TotalTax:{3} GrandTotal:{4}", startDateTime, endDateTime, totals.NetSales, totals.TotalTax, totals.GrandTotal));

                List<ItemSale> sales = api.GetItemsSold(startDateTime, endDateTime);
                Console.WriteLine(String.Format("Between {0}-{1}, there are {2} records of items being sold", startDateTime, endDateTime, sales.Count));

                pcAmerica.DesktopPOS.API.Client.SalesService.Context context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
                context.CashierID = "100101";
                context.StoreID = "1001";
                context.StationID = "01";

                // StartNewInvoice - this also automatically locks an invoice so it can't be opened by a terminal
                Invoice inv = api.StartNewInvoice(context, "Dan" + DateTime.Now.Second.ToString(), "XXOPEN TABS");
                Console.WriteLine(String.Format("Started new invoice with #: {0}", inv.InvoiceNumber));

                // Unlock Invoice
                if (api.UnLockInvoice(context, inv.InvoiceNumber))
                    Console.WriteLine(String.Format("Unlocked invoice # {0}", inv.InvoiceNumber));
                else
                    Console.WriteLine(String.Format("Failed to unlock invoice # {0}", inv.InvoiceNumber));

                // Lock Invoice
                if (api.LockInvoice(context, inv.InvoiceNumber))
                    Console.WriteLine(String.Format("Locked invoice # {0}", inv.InvoiceNumber));
                else
                    Console.WriteLine(String.Format("Failed to lock invoice # {0}", inv.InvoiceNumber));

                // GetInvoiceHeader
                inv = api.GetInvoiceHeader(context, inv.InvoiceNumber);
                Console.WriteLine(String.Format("GetInvoiceHeader with #: {0}", inv.InvoiceNumber));

                // GetInvoice
                inv = api.GetInvoice(context, inv.InvoiceNumber);
                Console.WriteLine(String.Format("GetInvoice with #: {0}", inv.InvoiceNumber));

                InventoryAPI InvApi = new InventoryAPI();

                pcAmerica.DesktopPOS.API.Client.InventoryService.Context InvContext = new pcAmerica.DesktopPOS.API.Client.InventoryService.Context();
                InvContext.CashierID = "100101";
                InvContext.StationID = "01";
                InvContext.StoreID = "1001";

                api.SetPartySizeForInvoice(context, inv.InvoiceNumber, 2);

                List<InventoryItem> items = InvApi.GetItemListExtended(InvContext);

                Console.WriteLine("*******************All Inventory Items************************");
                foreach (InventoryItem singleItem in items)
                {
                    Console.WriteLine(String.Format("Item#: {0} ItemName:{1}", singleItem.ItemNumber, singleItem.ItemName));
                }
                Console.WriteLine("***************************************************************");

                // ModifyItems
                inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "1" });

                InventoryItem itemToAdd = InvApi.GetItem(InvContext, "SALAD3");
                Guid itemToAddID = Guid.NewGuid();
                LineItem LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" };
                inv.LineItems.Add(LineItemToAdd);

                itemToAdd.ModifierGroups = InvApi.GetModiferGroupsForItem(InvContext, itemToAdd.ItemNumber);
                foreach (ModifierGroup ModGroup in itemToAdd.ModifierGroups)
                {
                    Console.WriteLine("ModifierGroup:{0}", ModGroup.ItemName);
                    Console.WriteLine("{0}", ModGroup.Prompt);
                    int i = 1;
                    if (ModGroup.Forced == false)
                    {
                        Console.WriteLine("{0} - NONE", i);
                        i++;
                    }
                    //NOTE THIS HAS CHANGED Modifier Items for Groups now are retrieved by calling GetModiferItemsForModiferGroups
                    ModGroup.ModifierItems = InvApi.GetModifierItemsForModifierGroup(InvContext, ModGroup.ItemNumber);
                    foreach (ModifierItem ModItem in ModGroup.ModifierItems)
                    {
                        Console.WriteLine("{0} - {1} : {2}", i, ModItem.ItemNumber, ModItem.ItemName);
                        i++;
                    }
                    string answer = Console.ReadLine();
                    if (answer.Length > 1)
                    {
                        Console.WriteLine("Invalid answer i Choose option 1 is chosen by default");
                        answer = "1";
                    }
                    else if (char.IsDigit(answer[0]) == false)
                    {
                        Console.WriteLine("Invalid answer i Choose option 1 chosen by defualt");
                        answer = "1";
                    }
                    InventoryItem dressing = InvApi.GetItem(InvContext, ModGroup.ModifierItems[Convert.ToInt32(answer) - 1].ItemNumber);
                    decimal Price = 0;
                    if (ModGroup.Charged == true) { Price = dressing.Price; }
                    inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = dressing.ItemName, ItemNumber = dressing.ItemNumber, Price = dressing.Price, Quantity = 1, State = EntityState.Added, Guest = "2" });
                }

                itemToAdd = InvApi.GetItem(InvContext, "DaveBurger");
                itemToAddID = Guid.NewGuid();
                LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" };
                inv.LineItems.Add(LineItemToAdd);
                itemToAdd.ModifierItems = InvApi.GetIndividualModifiers(InvContext, itemToAdd.ItemNumber);
                if (itemToAdd.ModifierItems.Count > 0)
                    inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = itemToAdd.ModifierItems[0].ItemName, ItemNumber = itemToAdd.ModifierItems[0].ItemNumber, Price = 0.00M, Quantity = 1, State = EntityState.Added, Guest = "1" });

                // This is a sample Kit Item I made that i added some items to you just have to ring up the base item(test) and the kit items will add along with it automaticly
                itemToAdd = InvApi.GetItem(InvContext, "test");
                itemToAddID = Guid.NewGuid();
                LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" };
                inv.LineItems.Add(LineItemToAdd);

                itemToAdd = InvApi.GetItem(InvContext, "test");
                itemToAddID = Guid.NewGuid();
                LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" };
                inv.LineItems.Add(LineItemToAdd);

                itemToAdd = InvApi.GetItem(InvContext, "DRINKCHOICE");
                int j = 1;
                Console.WriteLine(itemToAdd.ItemName2);
                InventoryItem Choice;
                foreach (String choiceItemNumber in itemToAdd.ChoiceItems)
                {
                    Choice = InvApi.GetItem(InvContext, choiceItemNumber);
                    Console.WriteLine(string.Format("{0}: ", Choice.ItemName));
                    j++;
                }
                int choiceItemSelection = Convert.ToInt32(Console.ReadLine()) - 1;
                itemToAdd = InvApi.GetItem(InvContext, itemToAdd.ChoiceItems[choiceItemSelection]);
                itemToAddID = Guid.NewGuid();
                LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "1" };
                inv.LineItems.Add(LineItemToAdd);

                inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
                Console.WriteLine(String.Format("ModifyItems new invoice value: {0}", inv.GrandTotal));

                inv.LineItems[0].Quantity = 2;
                inv.LineItems[0].State = EntityState.Modified;
                inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
                Console.WriteLine(String.Format("ModifyItems CHANGED 1st item QUANTITY, new invoice value: {0}", inv.GrandTotal));

                // SendToKitchen
                if (api.SendToKitchen(context, inv.InvoiceNumber))
                    Console.WriteLine("Invoice was printed in kitchen");
                else
                    Console.WriteLine("***ERROR*** Invoice was NOT printed in kitchen");

                // Splitcheck
                inv = api.SplitInvoiceByGuest(context, inv.InvoiceNumber);
                if (inv.SplitInfo.NumberOfSplitChecks == 2)
                    Console.WriteLine("Split invoice by guest");
                else
                    Console.WriteLine("***ERROR*** Invoice could be split");

                // ApplyCashPayment - applying grand total minus 1 dollar (NOTE SPLITS Starts counting at 0 not 1)
                AppliedPaymentResponse payResponse = api.ApplyCashPayment(context, inv.InvoiceNumber, 0, inv.SplitInfo.GrandTotalForSplit[0] - 1);
                if (payResponse.Success)
                    Console.WriteLine(String.Format("Applied cash payment to split 1, change due {0}", payResponse.ChangeAmount));
                else
                    Console.WriteLine("***ERROR*** Could not apply payment");

                // ApplyCardPayment - applying remaining 1 dollar as a credit card
                payResponse = api.ApplyCardPayment(context,
                    inv.InvoiceNumber,
                    0,
                    new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse()
                    {
                        Amount = 1,
                        CardNumber = "4***********1",
                        ReferenceNumber = "123456",
                        Result = true,
                        TipAmount = 1,
                        TransactionNumber = 1234
                    }, -1);
                if (payResponse.Success)
                    Console.WriteLine(String.Format("Applied card payment to split 1, change due {0}", payResponse.ChangeAmount));
                else
                    Console.WriteLine("***ERROR*** Could not apply card payment");

                payResponse = api.ApplyCashPayment(context, inv.InvoiceNumber, 1, inv.SplitInfo.GrandTotalForSplit[1] + 13);
                if (payResponse.Success)
                    Console.WriteLine(String.Format("Applied cash payment to split 2, change due {0}", payResponse.ChangeAmount));
                else
                    Console.WriteLine("***ERROR*** Could not apply payment");

                // EndInvoice
                if (api.EndInvoice(context, inv.InvoiceNumber))
                    Console.WriteLine("Ended invoice successfully");
                else
                    Console.WriteLine("***ERROR*** Could not end invoice");

                // looping and printing receipt for all splits
                for (int i = 0; i < inv.SplitInfo.NumberOfSplitChecks; i++)
                {
                    if (api.PrintReceipt(context, inv.InvoiceNumber, i))
                        Console.WriteLine("Receipt was printed");
                    else
                        Console.WriteLine("***ERROR*** Receive was NOT printed");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Console.WriteLine("PRESS ENTER TO CONTINUE...");
                Console.ReadLine();
            }
        }
        static void TestSaleWithCreditCardPayment()
        {
            try
            {
                var api = new SalesAPI();

                var context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context
                    {
                        CashierID = "100101",
                        StoreID = "1001",
                        StationID = "01"
                    };

                // StartNewInvoice - this also automatically locks an invoice so it can't be opened by a terminal
                var inv = api.StartNewInvoice(context, "ROB" + DateTime.Now.Second.ToString(), "XXOPEN TABS");
                Console.WriteLine(String.Format("Started new invoice with #: {0}", inv.InvoiceNumber));

                inv.LineItems.Add(new LineItem()
                {
                    ItemNumber = "Non_Inventory",
                    ItemName = "Hot dog",
                    Price = 1,
                    Quantity = 1,
                    State = EntityState.Added
                });
                inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
                Console.WriteLine(String.Format("ModifyItems ADDED item # 1, new invoice value: {0}", inv.GrandTotal));

                // SendToKitchen
                if (api.SendToKitchen(context, inv.InvoiceNumber))
                    Console.WriteLine("Invoice was printed in kitchen");
                else
                    Console.WriteLine("***ERROR*** Invoice was NOT printed in kitchen");

                if (api.SendToKitchen(context, inv.InvoiceNumber))
                    Console.WriteLine(
                        "Invoice was printed in kitchen, it should not have printed anything out the 2nd time");
                else
                    Console.WriteLine("***ERROR*** Invoice was NOT printed in kitchen");

                // ApplyCardPayment - applying remaining 1 dollar as a credit card
                var payResponse = api.ApplyCardPayment(context,
                    inv.InvoiceNumber,
                    -1,
                    new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse()
                    {
                        Amount = inv.GrandTotal,
                        CardNumber = "4***********1",
                        ReferenceNumber = "123456",
                        Result = true,
                        TipAmount = 1,
                        TransactionNumber = 1234
                    }, -1);
                if (payResponse.Success)
                    Console.WriteLine(String.Format("Applied card payment, change due {0}", payResponse.ChangeAmount));
                else
                    Console.WriteLine("***ERROR*** Could not apply card payment");

                // EndInvoice
                if (api.EndInvoice(context, inv.InvoiceNumber))
                    Console.WriteLine("Ended invoice successfully");
                else
                    Console.WriteLine("***ERROR*** Could not end invoice");

                // PrintReceipt - providing -1 for the split check # when there are no split checks
                if (api.PrintReceipt(context, inv.InvoiceNumber, -1))
                    Console.WriteLine("Receipt was printed");
                else
                    Console.WriteLine("***ERROR*** Receive was NOT printed");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Console.WriteLine("PRESS ENTER TO CONTINUE...");
                Console.ReadLine();
            }
        }