2010-03-02 17:56:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using System.Windows.Forms;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
using Tanshu.Accounts.Contracts;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Entities;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using Tanshu.Accounts.Repository;
|
2011-04-11 12:55:45 +00:00
|
|
|
|
using System.Diagnostics;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
using Tanshu.Common.Helpers;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Print
|
|
|
|
|
{
|
|
|
|
|
|
2011-12-05 09:41:02 +00:00
|
|
|
|
public static partial class Thermal
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
private const string DrawLine = "\n\r------------------------------------------";
|
|
|
|
|
private const string DrawEqual = "\n\r==========================================";
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-12-05 09:41:02 +00:00
|
|
|
|
private static string DesignKot(Voucher voucher, Kot kot, IEnumerable<Inventory> billItems, int copyNumber)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
var billText = "\n\r" + "KOT / BOT".Center42();
|
|
|
|
|
billText += "\n\r" + string.Format("Copy No. {0}", copyNumber).Center42();
|
2011-03-11 18:49:48 +00:00
|
|
|
|
billText += DrawLine;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
billText += string.Format("\n\rKOT ID : K-{0,-5}/S-{1,-5} {2:dd-MMM-yyyy HH:mm}", voucher.KotID, kot.Code, kot.Date);
|
2016-01-18 10:43:43 +00:00
|
|
|
|
billText += string.Format("\n\rTable No.: {0}", voucher.Table.Name);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
billText += DrawLine;
|
|
|
|
|
billText += "\n\r Qty. x Name ";
|
|
|
|
|
billText += DrawLine;
|
|
|
|
|
foreach (var item in billItems)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2016-04-11 07:01:52 +00:00
|
|
|
|
billText += string.Format("\n\r{0,6:#,##0.00} x {1,-33}", item.Quantity, item.EffectiveName);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
foreach (var mod in item.InventoryModifier)
|
|
|
|
|
billText += string.Format("\n\r --- {0,-32}", mod.Modifier.Name);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
billText += DrawLine;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
if (voucher.Narration != "")
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
billText += "\n\r" + FormatText(voucher.Narration, 42, Align.Centre);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
billText += DrawLine;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
return billText;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-12-05 09:41:02 +00:00
|
|
|
|
private static string FormatText(string inputString, int width, Align alignment)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (inputString.Length > width)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
return inputString.Substring(0, width);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (alignment == Align.Left)
|
|
|
|
|
return string.Format("{0,-" + width + "}", inputString);
|
|
|
|
|
if (alignment == Align.Centre)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
int left = Convert.ToInt32(Math.Ceiling(Convert.ToDouble((width - inputString.Length) / 2))) +
|
|
|
|
|
inputString.Length;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
inputString = string.Format("{0,-" + left + "}", inputString);
|
|
|
|
|
return string.Format("{0," + width + "}", inputString);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (alignment == Align.Right)
|
|
|
|
|
return string.Format("{0," + width + "}", inputString);
|
|
|
|
|
return inputString;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 18:49:48 +00:00
|
|
|
|
private static string FormatBillNum(decimal amount, int length)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
var temp = String.Format("{0:#,##0.00;(#,##0.00);0}", amount);
|
|
|
|
|
return string.Format("{0," + length + "}", temp);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 18:49:48 +00:00
|
|
|
|
private static bool PrintRaw(PrintLocation printer, string text, string documentName)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-02-04 19:30:55 +00:00
|
|
|
|
#if (DEBUG)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
MessageBox.Show(text);
|
2011-02-04 19:30:55 +00:00
|
|
|
|
return true;
|
|
|
|
|
#else
|
2011-07-12 07:00:48 +00:00
|
|
|
|
text += printer.CutCode;
|
|
|
|
|
if (!ThermalPrinter.Printer.Print(printer.Printer, documentName, text))
|
|
|
|
|
MessageBox.Show("Error in PrintRAW Function. Please Report immediately");
|
2010-03-02 17:56:21 +00:00
|
|
|
|
return true;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
#endif
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-17 14:55:43 +00:00
|
|
|
|
public static Boolean PrintClosing(CheckoutBI details)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-10-12 09:41:45 +00:00
|
|
|
|
var billText = FormatText(string.Format("{0} Checkout By {1}", details.Cashier.Name, details.Manager), 42, Align.Centre);
|
|
|
|
|
billText += string.Format("\n\r{0:dd-MMM-yy} To {1:dd-MMM-yy} @ {2:dd-MMM-yyyy HH:mm}",
|
|
|
|
|
details.StartDate, details.FinishDate, DateTime.Now);
|
|
|
|
|
billText += DrawLine;
|
2014-11-06 10:39:11 +00:00
|
|
|
|
foreach (var item in details.amounts)
|
|
|
|
|
{
|
|
|
|
|
billText += string.Format("\n\r{0} : {1,26:#,##0.00}", item.Key.Display(), item.Value);
|
|
|
|
|
}
|
2014-10-12 09:41:45 +00:00
|
|
|
|
billText += DrawEqual;
|
|
|
|
|
billText += string.Format("\n\rActive Cashiers : {0}", details.Cashiers);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
2014-11-06 10:39:11 +00:00
|
|
|
|
foreach (var item in details.info.Where(x => x.Key.Print()))
|
|
|
|
|
{
|
|
|
|
|
billText += item.Value;
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
2014-11-02 08:03:31 +00:00
|
|
|
|
return PrintRaw(Cache.BasePrinter, billText, "Closing");
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 18:49:48 +00:00
|
|
|
|
public static string FormatPrintNum(string inputString)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
return inputString == "" ? "0.00" : FormatText(inputString, 24, Align.Right);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
//return FormatText(FormatNumber(InputString.Trim, 2, TriState.UseDefault, TriState.True, TriState.True), 24, False, Align.Right);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-12 09:41:45 +00:00
|
|
|
|
public static void PrintBill(Guid voucherID)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-11-02 08:03:31 +00:00
|
|
|
|
PrintRaw(Cache.BasePrinter, DesignBill(voucherID), "Bill");
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-12 09:41:45 +00:00
|
|
|
|
public static void PrintKot(Guid voucherID, Guid kotID)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-04-11 12:55:45 +00:00
|
|
|
|
var stopwatch = new Stopwatch();
|
|
|
|
|
stopwatch.Start();
|
2011-06-29 20:27:07 +00:00
|
|
|
|
Voucher voucher;
|
2014-10-12 09:41:45 +00:00
|
|
|
|
using (var bi = new VoucherBI())
|
2011-12-05 09:41:02 +00:00
|
|
|
|
voucher = bi.Get(x => x.VoucherID == voucherID);
|
2014-11-02 08:03:31 +00:00
|
|
|
|
var dict = new Dictionary<PrintLocation, List<Inventory>>();
|
2011-08-23 07:10:05 +00:00
|
|
|
|
var kot = voucher.Kots.SingleOrDefault(x => x.KotID == kotID);
|
|
|
|
|
if (kot == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var inventory in kot.Inventories)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-08-23 07:10:05 +00:00
|
|
|
|
var type = inventory.Product.ProductGroup.ProductGroupID;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
var printer = Cache.KotPrinter(type);
|
|
|
|
|
if (!dict.ContainsKey(printer))
|
2014-10-12 09:41:45 +00:00
|
|
|
|
{
|
2014-11-02 08:03:31 +00:00
|
|
|
|
dict.Add(printer, new List<Inventory>());
|
2014-10-12 09:41:45 +00:00
|
|
|
|
}
|
2014-11-02 08:03:31 +00:00
|
|
|
|
dict[printer].Add(inventory);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-04-11 12:55:45 +00:00
|
|
|
|
stopwatch.Stop();
|
2011-06-23 12:47:48 +00:00
|
|
|
|
Trace.TraceWarning("kot and printers built in {0} ms", stopwatch.ElapsedMilliseconds);
|
2011-04-11 12:55:45 +00:00
|
|
|
|
stopwatch.Reset();
|
2011-01-17 14:55:43 +00:00
|
|
|
|
foreach (var item in dict)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2014-11-02 08:03:31 +00:00
|
|
|
|
for (var i = 0; i < item.Key.Copies; i++)
|
2011-01-17 14:55:43 +00:00
|
|
|
|
{
|
2011-04-11 12:55:45 +00:00
|
|
|
|
stopwatch.Start();
|
2014-11-02 08:03:31 +00:00
|
|
|
|
PrintRaw(item.Key, DesignKot(voucher, kot, item.Value, i), "KOT");
|
2011-04-11 12:55:45 +00:00
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
Trace.TraceWarning("kot designed and printed in {0} ms", stopwatch.ElapsedMilliseconds);
|
|
|
|
|
stopwatch.Reset();
|
2011-01-17 14:55:43 +00:00
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
|
|
|
|
#region Print Cash Total
|
|
|
|
|
|
|
|
|
|
public static Boolean PrintCash(Dictionary<int, int> amount, string user)
|
|
|
|
|
{
|
|
|
|
|
string printText;
|
|
|
|
|
int total = 0;
|
2014-10-12 09:41:45 +00:00
|
|
|
|
printText = FormatText(user, 42, Align.Centre);
|
|
|
|
|
printText += DrawLine;
|
|
|
|
|
printText += "\n\r" +
|
|
|
|
|
FormatText(string.Format("{0:dd-MMM-yyyy HH:mm:ss}", DateTime.Now), 42, Align.Centre);
|
|
|
|
|
foreach (int key in amount.Keys.OrderByDescending(k => k))
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
2014-10-12 09:41:45 +00:00
|
|
|
|
printText += CashLine(amount, key);
|
|
|
|
|
total += amount[key] * key;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
2014-10-12 09:41:45 +00:00
|
|
|
|
printText += "\n\r" + DrawEqual;
|
|
|
|
|
printText += string.Format("\n\r Total = {0,10:#,##0}", total);
|
|
|
|
|
printText += DrawLine;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
return PrintRaw(Cache.BasePrinter, printText, "Closing/Opening for " + user);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean PrintSale(string user, IList<SalesAnalysis> det, DateTime startDate, DateTime endDate)
|
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
var printText = FormatText(user, 42, Align.Centre);
|
|
|
|
|
printText += DrawLine;
|
|
|
|
|
printText += "\n\r" +
|
|
|
|
|
FormatText(string.Format("{0:dd-MMM-yyyy HH:mm:ss}", DateTime.Now), 42, Align.Centre);
|
|
|
|
|
printText += "\n\r" +
|
|
|
|
|
FormatText(string.Format("{0:dd-MMM-yyyy} to {1:dd-MMM-yyyy}", startDate, endDate), 42, Align.Centre);
|
|
|
|
|
printText += DrawLine;
|
|
|
|
|
foreach (SalesAnalysis d in det)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
printText += string.Format("\n\r {0,-22} {1,9:#,##0}", d.GroupType, d.Amount);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
2011-12-05 09:41:02 +00:00
|
|
|
|
printText += DrawEqual;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
return PrintRaw(Cache.BasePrinter, printText, "Sale Detail " + user);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Boolean PrintSale(string user, IList<SalesAnalysisDetail> list, DateTime startDate,
|
|
|
|
|
DateTime endDate)
|
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
var printText = FormatText(user, 42, Align.Centre);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
printText += DrawLine;
|
|
|
|
|
printText += "\n\r" +
|
2011-12-05 09:41:02 +00:00
|
|
|
|
FormatText(string.Format("{0:dd-MMM-yyyy HH:mm:ss}", DateTime.Now), 42, Align.Centre);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
printText += "\n\r" +
|
2011-12-05 09:41:02 +00:00
|
|
|
|
FormatText(string.Format("{0:dd-MMM-yyyy} to {1:dd-MMM-yyyy}", startDate, endDate), 42, Align.Centre);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
printText += DrawLine;
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
2016-04-11 07:01:52 +00:00
|
|
|
|
printText += string.Format("\n\r{0,-22} {1,9:#,##0.00} {2,9:#,##0.00}", item.Name, item.Sale, item.NC);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
|
|
|
|
printText += DrawEqual;
|
2014-11-02 08:03:31 +00:00
|
|
|
|
return PrintRaw(Cache.BasePrinter, printText, "Sale Detail " + user);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string CashLine(IDictionary<int, int> amount, int key)
|
|
|
|
|
{
|
|
|
|
|
return amount.ContainsKey(key) ? string.Format("\n\r{0,5:#,##0} x {1,10:#,##0} = {2,10:#,##0}", key, amount[key], key * amount[key]) : string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|