Exemple #1
0
        public void printReceipt(Invoice invoice, bool openDrawer = false)
        {
            // return;
            setupPrinter();
            try
            {
                m_Printer.Open();

                //Get the exclusive control right for the opened device.
                //Then the device is disable from other application.
                m_Printer.Claim(1000);

                //Enable the device.
                bool result = m_Printer.DeviceEnabled = true;

                // this call also causes the "It is not initialized" error
                //string health = m_Printer.CheckHealth(HealthCheckLevel.External);
            }
            catch (PosControlException)
            {
                //  ChangeButtonStatus();
            }
            string receiptString = Receipt40Col.GetStandardReceipt(invoice);
            string barcodeString = invoice.Id ?? "";
            while (barcodeString.Length < 8)
            {
                barcodeString = " " + barcodeString;
            }
            // int test = m_Printer.JrnLineChars

            //var file = Path.GetFullPath("Resources/logo.bmp");
            // m_Printer.PrintNormal(PrinterStation.Receipt,((char)27).ToString() + "|cA" + receiptString);
            //m_Printer.PrintBitmap(PrinterStation.Receipt, file, 300, PosPrinter.PrinterBitmapCenter);

            var headerImage = Receipt40Col.GetInvoiceHeaderBitmap();
            if (headerImage != null)
            {
                m_Printer.PrintBitmap(PrinterStation.Receipt, headerImage, 400, PosPrinter.PrinterBitmapCenter);
            }
            //m_Printer.PrintMemoryBitmap(new BitmapData());
            m_Printer.PrintNormal(PrinterStation.Receipt, receiptString);

            var footerImage = Receipt40Col.GetInvoiceFooterBitmap();
            if (footerImage != null)
                m_Printer.PrintBitmap(PrinterStation.Receipt, footerImage, 400, PosPrinter.PrinterBitmapCenter);
            m_Printer.PrintNormal(PrinterStation.Receipt, Receipt40Col.extraLines(8));
            if (openDrawer)
                m_Printer.PrintNormal(PrinterStation.Receipt, ((char) 27).ToString() + "|\x07");
        }
Exemple #2
0
        private static string CreateInvoiceData(Invoice invoice)
        {
            string lineString = "<tr class=\"{0}\"><td>{1}</td><td>{2}</td><td>{3}</td></tr>";
            StringBuilder sb = new StringBuilder();
            foreach (var line in invoice.Lines)
            {
                bool even = invoice.Lines.IndexOf(line) % 2 == 0;
                sb.AppendLine(string.Format(lineString, even ? "even" : "odd", HttpUtility.HtmlEncode(line.Description), line.Qty, line.Price.ToString("C2")));
                if (line.Discount != 0)
                    sb.AppendLine(string.Format(lineString, even ? "even" : "odd", "", "*Clearance Item", "", line.Discount.ToString("C2")));
            }
            sb.AppendLine(string.Format(lineString, "even", "", "", "Sub Total:", invoice.SubTotal.ToString("C2")));
            sb.AppendLine(string.Format(lineString, "even", "", "", "Discount:", invoice.TotalDiscount.ToString("C2")));
            //sb.AppendLine(string.Format(lineString, "even", "", "", "Tax:", invoice.TotalTax.ToString("C2")));
            sb.AppendLine(string.Format(lineString, "odd", "", "", bold("Total:"), bold(invoice.Total.ToString("C2"))));

            sb.AppendLine("<tr/>");

            sb.AppendLine(string.Format(lineString, "even", "Payments Applied:", "", "", ""));

            foreach (var payment in invoice.Payments)
            {
                bool even = invoice.Payments.IndexOf(payment) % 2 == 0;
                sb.AppendLine(string.Format(lineString, even ? "even" : "odd", "", "", payment.PaymentType.Description, payment.Amount.ToString("C2")));
                var change = Math.Abs(payment.Change);
                if (change != 0)
                {
                    sb.AppendLine(string.Format(lineString, even ? "even" : "odd", "", "", "Change:", change.ToString("C2")));
                }
            }

            return sb.ToString();
        }
Exemple #3
0
 private static string GetPlainBody(Invoice invoice)
 {
     return "";// Receipt40Col.GetStandardReceipt(invoice);
 }
Exemple #4
0
 private static string GetHtmlBody(Invoice invoice)
 {
     string filePath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath,"Content", "invoice.htm");// Server.MapPath(Url.Content("~/Content/Images/Image.jpg"));
     var customer = invoice.Customer;
     //CustomerDatabase.RefreshCustomer(ref customer);
     var content = File.ReadAllText(filePath);
     content = content.Replace("[SalesPerson]", invoice.SalesPersonId);
     content = content.Replace("[InvoiceID]", invoice.Id);
     content = content.Replace("[Date]", DateTime.Now.ToString());
     content = content.Replace("[CustomerName]", invoice.Customer.ToString());
     content = content.Replace("[Email]", invoice.Customer.Email);
     content = content.Replace("[OnAccountAmt]", invoice.Customer.OnAccount.ToString("C2"));
     content = content.Replace("[DATA]", CreateInvoiceData(invoice));
     //content = content.Replace("[Points]", customer.LoyaltyPoints.ToString());
     return content;
 }
Exemple #5
0
        //public static void SetContent(Buyback buyback, StringBuilder sb)
        //{
        //    sb.AppendLine("Customer:");
        //    sb.AppendLine(buyback.Customer.ToString());
        //    if(!string.IsNullOrEmpty(buyback.Customer.Email))
        //        sb.AppendLine(buyback.Customer.Email);
        //    sb.AppendLine();
        //    //foreach (var item in invoice.BuybackItems)
        //    //{
        //    //    sb.AppendLine(padLine(item.ItemId,item.Description,item.BuyAmount.ToString("C2")));
        //    //}
        //    sb.AppendLine(padLine(string.Format("Today you sold us {0} items.", buyback.ItemsQty)));
        //    sb.AppendLine();
        //    if (buyback.OnAccountAmount > 0)
        //    {
        //        sb.AppendLine(
        //            Bold(
        //            padLine(string.Format("{0} has been applied to your account.",
        //                                  buyback.OnAccountAmount.ToString("C2")))));
        //    }
        //    else
        //        sb.AppendLine(
        //            Bold(padLine(string.Format("For a Cash total of: {0}", buyback.PostedAmount.Value.ToString("C2")))));
        //    sb.AppendLine();
        //    sb.AppendLine();
        //}
        public static void SetContent(Invoice invoice, StringBuilder sb)
        {
            sb.AppendLine("Customer:");
            sb.AppendLine(invoice.Customer.ToString());
            if (!string.IsNullOrEmpty(invoice.Customer.Email))
                sb.AppendLine(invoice.Customer.Email);
            sb.AppendLine();
            sb.AppendLine();

            foreach (var item in invoice.Lines)
            {
                sb.AppendLine(padLine(item.ItemId,item.Description,item.Price.ToString("C2")));
                if (item.Discount != 0)
                    sb.AppendLine(padLine("", "*Discounted","-" + item.Discount.ToString("C2")));
            }
            sb.AppendLine();
            sb.AppendLine(padLine(string.Format("Sub Total: {0}", invoice.SubTotal.ToString("C2")),Alignment.Right));
            if(invoice.TotalDiscount != 0)
                sb.AppendLine(padLine(string.Format("Discount: {0}", invoice.TotalDiscount.ToString("C2")), Alignment.Right));
               // sb.AppendLine(padLine(string.Format("Tax: {0}", invoice.TotalTax.ToString("C2")), Alignment.Right));
            sb.AppendLine(Bold(padLine(string.Format("Total: {0}", (invoice.Total).ToString("C2")), Alignment.Right)));
            sb.AppendLine();
            sb.AppendLine("Tender:");
            foreach (var payment in invoice.Payments.Where(x=> x.Amount != 0))
            {
                sb.AppendLine(string.Format("{0}: {1}", payment.PaymentType.Description, payment.Amount.ToString("C2")));
                var change = Math.Abs(payment.Change);
                if (change != 0)
                {
                    //sb.AppendLine(string.Format("Received: {0}", (payment.Amount).ToString("C2")));
                    sb.AppendLine(string.Format("Change: {0}", change.ToString("C2")));
                }
            }
            sb.AppendLine();
            sb.AppendLine();
        }
Exemple #6
0
 public static string GetStandardReceipt(Invoice invoice)
 {
     var sb = new StringBuilder();
     try
     {
         getStandardHeader(sb);
         SetContent(invoice, sb);
         var customer = invoice.Customer;
         SetInvoiceFooter(customer, sb);
         AddPointBalance(customer, sb);
         AddDisclaimer(sb);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
     return sb.ToString();
 }