EmailReceipt() public method

Emails a receipt for the specified invoice or split check to the specified email address
public EmailReceipt ( Context context, long invoiceNumber, int splitCheckNumber, string emailAddress ) : 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 emailed
splitCheckNumber int The split check number, 0-based. Provide -1 if there are no split checks.
emailAddress string The email address to send the receipt to
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();
            }
        }