using System; using System.Collections.Generic; using System.Linq; using System.Text; using Tanshu.Accounts.Contracts; using Tanshu.Accounts.BI; using Tanshu.Accounts.Helpers; namespace Tanshu.Accounts.Print { enum Align { None = 0, Left = 1, Centre = 2, Right = 4 } public static class Thermal { private static string CutPrinter = System.Configuration.ConfigurationManager.AppSettings["Printer"].ToString().Trim().EndsWith("Epson") ? "\n\r\n\r\n\r\n\r\n\r\n\r" + (char)29 + (char)86 + (char)49 : "\n\r" + (char)29 + (char)86 + (char)49; private const string DrawLine = "\n\r------------------------------------------"; private const string DrawEqual = "\n\r=========================================="; private static string DesignWaiterKot(SaleVoucherBO trans, List billItems) { WaiterBO waiter = new WaiterBI().GetWaiter(trans.WaiterID); string BillText; try { BillText = string.Format("\n\rWAITER WAITER WAITER WAITER WAITER"); BillText += string.Format("\n\rWAITER WAITER WAITER WAITER WAITER"); BillText += DrawLine; BillText += string.Format("\n\rKOT ID : {0,-13} {1:dd-MMM-yyyy HH:mm}", trans.KotID, trans.Date); BillText += string.Format("\n\rTable No.: {0} / {1}", trans.TableID, waiter.Name); BillText += DrawLine; BillText += "\n\r Qty. x Name "; BillText += DrawLine; foreach (SalesBillItemBO item in billItems) { Decimal additional = item.Quantity - item.Printed; if (additional > 0) { BillText += string.Format("\n\r{0,6} x {1,-33}", additional, item.Name); } } BillText += DrawLine; if (trans.Narration != "") { BillText += "\n\r" + FormatText(trans.Narration, 42, false, Align.Centre); BillText += DrawLine; } BillText += CutPrinter; return BillText; } catch (Exception ex) { throw ex; } } private static string DesignPickupKot(SaleVoucherBO trans, List billItems) { WaiterBO waiter = new WaiterBI().GetWaiter(trans.WaiterID); string BillText; try { BillText = string.Format("\n\rPICK-UP PICK-UP PICK-UP PICK-UP PICK-UP"); BillText += string.Format("\n\rPICK-UP PICK-UP PICK-UP PICK-UP PICK-UP"); BillText += DrawLine; BillText += string.Format("\n\rBill No: {0,-13}{0:dd-MMM-yyyy HH:mm}" + trans.KotID, trans.Date); BillText += string.Format("\n\rTable No.: {0} / {1}", trans.TableID, waiter.Name); BillText += DrawLine; BillText += "\n\r Qty. x Name "; BillText += DrawLine; foreach (SalesBillItemBO item in billItems) { Decimal additional = item.Quantity - item.Printed; if (additional > 0) { BillText += string.Format("\n\r{0,6} x {1,-33}", additional, item.Name); } } BillText += DrawLine; if (trans.Narration != "") { BillText += "\n\r" + FormatText(trans.Narration, 42, false, Align.Centre); BillText += DrawLine; } BillText += CutPrinter; return BillText; } catch (Exception ex) { throw ex; } } private static string DesignCustomerKot(SaleVoucherBO trans, List billItems) { WaiterBO waiter = new WaiterBI().GetWaiter(trans.WaiterID); string BillText; try { BillText = string.Format("\n\r Counter / Order Slip "); BillText += DrawLine; BillText += string.Format("\n\rBill No: {0,-13}{0:dd-MMM-yyyy HH:mm}" + trans.KotID, trans.Date); BillText += string.Format("\n\rTable No.: {0} / {1}", trans.TableID, waiter.Name); BillText += DrawLine; BillText += "\n\r Qty. x Name "; BillText += DrawLine; foreach (SalesBillItemBO item in billItems) { Decimal additional = item.Quantity - item.Printed; if (additional > 0) { BillText += string.Format("\n\r{0,6} x {1,-33}", additional, item.Name); } } BillText += DrawLine; if (trans.Narration != "") { BillText += "\n\r" + FormatText(trans.Narration, 42, false, Align.Centre); BillText += DrawLine; } BillText += CutPrinter; return BillText; } catch (Exception ex) { throw ex; } } private static string DesignBill(SaleVoucherBO trans, List billItems) { UserBO cashier = new UserBI().GetUser(trans.UserID); WaiterBO waiter = new WaiterBI().GetWaiter(trans.WaiterID); CustomerBO customer = new CustomerBI().GetCustomer(trans.CustomerID); String billNo = trans.BillID.Substring(trans.BillID.IndexOf("-") + 1); String BillText = ""; BillText = "\n\r" + FormatText("V2C Multi Cuisine Restaurant", 42, false, Align.Centre); BillText += "\n\r" + FormatText(" + Bengali Sweets", 42, false, Align.Centre); BillText += "\n\r" + FormatText("SCO 399, Sector 20, Panchkula", 42, false, Align.Centre); BillText += "\n\r" + FormatText("A Unit of AA Herbal Biotech Pvt. Ltd.", 42, false, Align.Centre); BillText += "\n\r" + FormatText("TIN: 06892504733", 42, false, Align.Centre); BillText += "\n\r" + FormatText("Retail Invoice", 42, false, Align.Centre); BillText += "\n\r"; BillText += "\n\r" + "Bill No: " + FormatText(billNo, 13, false, Align.Centre) + string.Format("{0:dd-MMM-yyyy HH:mm:ss}", trans.Date); BillText += "\n\r" + "Table No.: " + trans.TableID; BillText += "\n\r" + "------------------------------------------"; BillText += "\n\r" + "Qty. Particulars Price Amount"; BillText += "\n\r" + "------------------------------------------"; foreach (SalesBillItemBO item in billItems) { if (Math.Round((item.Price * (1 + item.Tax)), 0) == 1) { BillText += "\n\r" + " "; BillText += FormatText(item.Name, 22, false, Align.Left) + " "; BillText += " "; BillText += FormatBillNum(item.Price * item.Quantity, 6); } else { BillText += "\n\r" + FormatBillNum(item.Quantity, 5) + " "; BillText += FormatText(item.Name, 22, false, Align.Left) + " "; BillText += FormatBillNum(item.Price, 6) + " "; BillText += FormatBillNum(item.Price * item.Quantity, 6); } } BillText += "\n\r" + "------------------------------------------"; if (billItems.Sum(b => b.TaxAmount) != 0) { BillText += "\n\r" + FormatText("VAT (incl. surcharge) : ", 33, false, Align.Right) + FormatBillNum(billItems.Sum(b => b.TaxAmount), 9); } if (billItems.Sum(b => b.DiscountAmount) != 0) { BillText += "\n\r" + FormatText("Discount : ", 33, false, Align.Right) + FormatBillNum(billItems.Sum(b => b.DiscountAmount), 9); } BillText += string.Format("\n\r Final Amount : {0,9:#,##0.00;(#,##0.00);0}", Math.Round(billItems.Sum(b => b.Value), 0)); BillText += DrawLine; if (trans.Narration != "") { BillText += "\n\r" + FormatText(trans.Narration, 42, false, Align.Centre); BillText += DrawLine; } if (customer.Name != "Cash") { BillText += "\n\r" + customer.Name; BillText += string.Format("\n\r{0}\n\r{1}", customer.Phone, customer.Address); BillText += DrawLine; } BillText += "\n\r" + "Cashier : " + cashier.Name + " / " + waiter.Name; BillText += "\n\r" + " For Home Delivery: 0172-3242030, 3243040 "; BillText += CutPrinter; return BillText; } private static string FormatText(string inputString, int width, Boolean multiline, Align alignment) { if ((multiline) && (inputString.Length > width)) { string newString = ""; int lines = Convert.ToInt32(Math.Floor(Convert.ToDecimal(inputString.Length / width))); for (int i = 0; i < lines; i++) newString += inputString.Substring(i * width, width) + "\n\r"; newString += FormatText(inputString.Substring(lines * width), width, multiline, alignment); return newString; } else if (inputString.Length > width) return inputString.Substring(0, width); else if (alignment == Align.None) return inputString; else if (alignment == Align.Left) return string.Format("{0,-" + width.ToString() + "}", inputString); else if (alignment == Align.Centre) { int left; left = Convert.ToInt32(Math.Ceiling(Convert.ToDouble((width - inputString.Length) / 2))) + inputString.Length; inputString = string.Format("{0,-" + left.ToString() + "}", inputString); return string.Format("{0," + width.ToString() + "}", inputString); } else if (alignment == Align.Right) return string.Format("{0," + width.ToString() + "}", inputString); else return inputString; } private static string FormatBillNum(decimal Amount, int Length) { string Temp = String.Format("{0:#,##0.00;(#,##0.00);0}", Amount); return string.Format("{0," + Length.ToString() + "}", Temp); } private static bool PrintRAW(string printer, string Text, string DocumentName) { try { if (!RawPrinterHelper.PrintString(printer, DocumentName, Text, new char[] { ';' })) { GC.Collect(); System.Windows.Forms.MessageBox.Show("Error in PrintRAW Function. Please Report immediately"); } } catch (Exception ex) { throw ex; } return true; } #region Print Cash Total public static Boolean PrintCash(string printer, Dictionary amount, string user) { string printText; int total = 0; try { printText = FormatText(user, 42, false, Align.Centre); printText += DrawLine; printText += "\n\r" + FormatText(string.Format("{0:dd-MMM-yyyy HH:mm:ss}", DateTime.Now), 42, false, Align.Centre); foreach (int key in amount.Keys.OrderByDescending(k => k)) { printText += CashLine(amount, key); total += amount[key] * key; } printText += "\n\r" + DrawEqual; printText += string.Format("\n\r Total = {0,10:#,##0}", total); printText += DrawLine; printText += CutPrinter; return PrintRAW(printer,printText, "Closing/Opening for " + user); } catch (Exception ex) { throw ex; } } public static Boolean PrintSale(string printer, string user, List det, DateTime startDate, DateTime endDate) { string printText; try { printText = FormatText(user, 42, false, Align.Centre); printText += DrawLine; printText += "\n\r" + FormatText(string.Format("{0:dd-MMM-yyyy HH:mm:ss}", DateTime.Now), 42, false, Align.Centre); printText += "\n\r" + FormatText(string.Format("{0:dd-MMM-yyyy} to {1:dd-MMM-yyyy}", startDate, endDate), 42, false, Align.Centre); printText += DrawLine; foreach (SalesAnalysisBO d in det) { if (d.Section.Length > 30) d.Section = d.Section.Substring(0, 30); printText += string.Format("\n\r{0,-22} {1,9:#,##0} {2,9:#,##0}", d.Section, d.Net, d.Gross); printText += DrawLine; } printText += DrawEqual; printText += CutPrinter; return PrintRAW(printer, printText, "Sale Detail " + user); } catch (Exception ex) { throw ex; } } private static string CashLine(Dictionary amount, int key) { if (amount.ContainsKey(key)) return string.Format("\n\r{0,5:#,##0} x {1,10:#,##0} = {2,10:#,##0}", key, amount[key], key * amount[key]); else return string.Empty; } #endregion public static Boolean PrintAdvance(string printer, string user, string Advance, string Narration) { String BillText; try { BillText = "\n\r" + FormatText("Bengali Sweet House", 42, false, Align.Centre); BillText += "\n\r" + FormatText("+ V2C Multi Cuisine", 42, false, Align.Centre); BillText += "\n\r" + FormatText("SCO 1, Pocket 1, Manimajra, Chandigarh", 42, false, Align.Centre); BillText += "\n\r" + FormatText("A Unit of AA Herbal Biotech Pvt. Ltd.", 42, false, Align.Centre); BillText += DrawLine; BillText += "\n\r" + FormatText(string.Format("{0:dd-MMM-yyyy HH:mm:ss}", DateTime.Now), 42, false, Align.Centre); BillText += "\n\r" + FormatText("Received Rs. " + Advance + " as advance.", 42, false, Align.Centre); BillText += DrawLine; if (Narration != "") BillText += "\n\r" + FormatText(Narration, 42, false, Align.Centre); BillText += DrawLine; BillText += "\n\r" + FormatText("Thanking you " + user, 42, false, Align.Left); BillText += "\n\r"; BillText += "\n\r"; BillText += "\n\r"; BillText += "\n\r"; BillText += "\n\r"; BillText += "Signed" + "\n\r"; BillText += "\n\r"; BillText += CutPrinter; BillText += "\n\r" + BillText; return PrintRAW(printer, BillText, "Closing/Opening for " + user); } catch (Exception ex) { throw ex; } } public static Boolean PrintClosing(string printer, CheckoutBI details) { string BillText; try { BillText = FormatText(string.Format("{0} Checkout By {1}", details.Cashier, details.Manager), 42, false, Align.Centre); BillText += string.Format("{0:dd-MMM-yy} To {1:dd-MMM-yy} @ {2:dd-MMM-yyyy HH:mm}", details.StartDate, details.FinishDate, DateTime.Now); BillText += DrawLine; BillText += string.Format("\n\rOpening : {0,26:#,##0.00}", details.Opening); BillText += string.Format("\n\rReceipts : {0,26:#,##0.00}", details.Receipts); BillText += string.Format("\n\rAdvance Rcv. : {0,26:#,##0.00}", details.AdvanceReceipts); BillText += string.Format("\n\rCC Receipts : {0,26:#,##0.00}", details.CCReceipts); BillText += string.Format("\n\rAdvance Adj. : {0,26:#,##0.00}", details.AdvanceAdjusted); BillText += string.Format("\n\rPayments : {0,26:#,##0.00}", details.CashPayments); BillText += string.Format("\n\rAddl. Voids : {0,26:#,##0.00}", details.AdditionalVoids); BillText += string.Format("\n\rVoids in Sys. : {0,26:#,##0.00}", details.VoidsInSystem); BillText += string.Format("\n\rPending Bills : {0,26:#,##0.00}", details.PendingBills); BillText += string.Format("\n\rNet Sales : {0,26:#,##0.00}", details.NetSales); BillText += string.Format("\n\rClosing Bal. : {0,26:#,##0.00}", details.ClosingBalance); BillText += string.Format("\n\rCash Dep. : {0,26:#,##0.00}", details.CashDeposited); BillText += DrawLine; BillText += string.Format("\n\rOld Pending : {0,26:#,##0.00}", details.OldPending); BillText += string.Format("\n\rOld Receipts : {0,26:#,##0.00}", details.OldReceipts); BillText += string.Format("\n\rOld Voided : {0,26:#,##0.00}", details.OldVoided); BillText += DrawEqual; BillText += "\n\r" + FormatText(details.Status, 42, false, Align.Centre); BillText += DrawEqual; BillText += string.Format("\n\rActive Cashiers : {0}", details.Cashiers); if (details.PendingString.Length > 0) BillText += details.PendingString; if (details.CCString.Length > 0) BillText += details.CCString; if (details.VoidsString.Length > 0) BillText += details.VoidsString; if (details.PaymentString.Length > 0) BillText += details.PaymentString; if (details.DiscountString.Length > 0) BillText += details.DiscountString; BillText += CutPrinter; return PrintRAW(printer, BillText, "Closing"); } catch (Exception ex) { throw ex; } } public static string FormatPrintNum(string InputString) { if (InputString == "") return "0.00"; //return FormatText(FormatNumber(InputString.Trim, 2, TriState.UseDefault, TriState.True, TriState.True), 24, False, Align.Right); return FormatText(InputString, 24, false, Align.Right); } public static void PrintBill(string printer, bool bill, Guid voucherID, List list) { SaleVoucherBO trans = new SaleVoucherBO(); List iList = new List(); new SaleVoucherBI().GetSaleVoucher(voucherID, ref trans, ref iList); PrintRAW(printer, DesignBill(trans, list), "Bill"); } public static void PrintWaiterKot(string printer, Guid voucherID, List list) { SaleVoucherBO trans = new SaleVoucherBO(); List iList = new List(); new SaleVoucherBI().GetSaleVoucher(voucherID, ref trans, ref iList); if (list.Count(i => (i.Quantity - i.Printed) > 0) > 0) { PrintRAW(printer, DesignWaiterKot(trans, list), "KOT"); PrintRAW(printer, DesignPickupKot(trans, list), "KOT"); } } public static void PrintCustomerKot(string printer, Guid voucherID, List list) { SaleVoucherBO trans = new SaleVoucherBO(); List iList = new List(); new SaleVoucherBI().GetSaleVoucher(voucherID, ref trans, ref iList); if (list.Count(i => (i.Quantity - i.Printed) > 0) > 0) { PrintRAW(printer, DesignCustomerKot(trans, list), "KOT"); } } } }