2011-12-05 09:41:02 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
|
|
|
|
using Tanshu.Common.Helpers;
|
2014-10-12 09:41:45 +00:00
|
|
|
|
using Tanshu.Accounts.Contracts;
|
2014-10-16 11:11:55 +00:00
|
|
|
|
using Tanshu.Accounts.Repository;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Print
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public static partial class Thermal
|
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
private static string DesignBill(Guid voucherID)
|
2011-12-05 09:41:02 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
using (var bi = new VoucherBI())
|
2014-10-12 09:41:45 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
Voucher voucher = bi.Get(x => x.VoucherID == voucherID);
|
|
|
|
|
var list = new Dictionary<int, Inventory>();
|
|
|
|
|
foreach (var item in voucher.Kots.SelectMany(kot => kot.Inventories))
|
|
|
|
|
{
|
|
|
|
|
int hash = item.Product.ProductID.GetHashCode();
|
2016-04-11 07:01:52 +00:00
|
|
|
|
hash = hash ^ item.IsHappyHour.GetHashCode();
|
2014-10-16 11:11:55 +00:00
|
|
|
|
foreach (var mod in item.InventoryModifier.Where(x => x.Modifier.ShowInBill))
|
|
|
|
|
{
|
|
|
|
|
hash = hash ^ mod.Modifier.ModifierID.GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
if (list.ContainsKey(hash))
|
|
|
|
|
list[hash].Quantity += item.Quantity;
|
|
|
|
|
else
|
|
|
|
|
list.Add(hash, item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var billText = "";
|
|
|
|
|
billText += Header(voucher);
|
|
|
|
|
billText += Products(voucher, list.Values.ToList());
|
|
|
|
|
|
|
|
|
|
decimal amount;
|
2016-04-11 07:01:52 +00:00
|
|
|
|
amount = list.Values.Sum(item => item.Quantity * item.Price);
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (amount != 0)
|
|
|
|
|
billText += "\n\r" + FormatText("Total : ", 33, Align.Right) + FormatBillNum(amount, 9);
|
|
|
|
|
|
2016-04-11 07:01:52 +00:00
|
|
|
|
amount = list.Values.Where(x=>x.IsHappyHour == true).Sum(item => item.Quantity * item.Price);
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (amount != 0)
|
|
|
|
|
billText += "\n\r" + FormatText("Happy Hour Discount : ", 33, Align.Right) + FormatBillNum(amount, 9);
|
|
|
|
|
|
2016-04-11 07:01:52 +00:00
|
|
|
|
amount = list.Values.Sum(item => item.Quantity * item.EffectivePrice * item.Discount);
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (amount != 0)
|
|
|
|
|
billText += "\n\r" + FormatText("Discount : ", 33, Align.Right) + FormatBillNum(amount, 9);
|
|
|
|
|
|
2016-04-11 07:01:52 +00:00
|
|
|
|
amount = list.Values.Sum(item => item.Quantity * item.EffectivePrice * (1 - item.Discount));
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (amount != 0)
|
|
|
|
|
{
|
|
|
|
|
billText += "\n\r" + FormatText(" : ", 33, Align.Right) + "---------";
|
|
|
|
|
billText += "\n\r" + FormatText("Net : ", 33, Align.Right) + FormatBillNum(amount, 9);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-11 07:01:52 +00:00
|
|
|
|
amount = list.Values.Sum(item => item.Quantity * item.EffectivePrice * (1 - item.Discount) * item.ServiceCharge);
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (amount != 0)
|
|
|
|
|
billText += "\n\r" + FormatText("Service Charge : ", 33, Align.Right) + FormatBillNum(amount, 9);
|
|
|
|
|
|
|
|
|
|
var vatList = from i in list.Values
|
|
|
|
|
group i by i.Vat into vat
|
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
|
Tax = vat.Key,
|
2016-04-11 07:01:52 +00:00
|
|
|
|
Amount = vat.Sum(x => x.VatAmount)
|
2014-10-16 11:11:55 +00:00
|
|
|
|
};
|
|
|
|
|
foreach (var item in vatList)
|
|
|
|
|
if (item.Amount != 0)
|
|
|
|
|
billText += "\n\r" + FormatText(item.Tax.Name, 33, Align.Right) + FormatBillNum(item.Amount, 9);
|
|
|
|
|
|
|
|
|
|
var stList = from i in list.Values
|
|
|
|
|
group i by i.ServiceTax into serviceTax
|
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
|
Tax = serviceTax.Key,
|
2016-04-11 07:01:52 +00:00
|
|
|
|
Amount = serviceTax.Sum(x => x.ServiceTaxAmount)
|
2014-10-16 11:11:55 +00:00
|
|
|
|
};
|
|
|
|
|
foreach (var item in stList)
|
|
|
|
|
if (item.Amount != 0)
|
|
|
|
|
billText += "\n\r" + FormatText(item.Tax.Name, 33, Align.Right) + FormatBillNum(item.Amount, 9);
|
|
|
|
|
|
|
|
|
|
amount = list.Values.Sum(item => item.Amount);
|
|
|
|
|
if (amount != 0)
|
|
|
|
|
billText += string.Format("\n\r{0,33}{1,9:#,##0.00;(#,##0.00);0}", "Final Amount : ", Math.Round(amount, 0));
|
2011-12-05 09:41:02 +00:00
|
|
|
|
|
|
|
|
|
billText += DrawLine;
|
2014-10-16 11:11:55 +00:00
|
|
|
|
|
|
|
|
|
if (voucher.VoucherType == VoucherType.NoCharge || voucher.VoucherType == VoucherType.Staff)
|
|
|
|
|
{
|
|
|
|
|
billText += "\n\r" + "THIS IS NOT A BILL - DON'T PAY".Center42();
|
|
|
|
|
billText += DrawLine;
|
|
|
|
|
}
|
|
|
|
|
if (voucher.Narration != "")
|
|
|
|
|
{
|
|
|
|
|
billText += "\n\r" + FormatText(voucher.Narration, 42, Align.Centre);
|
|
|
|
|
billText += DrawLine;
|
|
|
|
|
}
|
|
|
|
|
if (voucher.Customer.CustomerID != Constants.CASH_CUSTOMER)
|
|
|
|
|
{
|
|
|
|
|
billText += "\n\r" + voucher.Customer.Name;
|
|
|
|
|
billText += string.Format("\n\r{0}\n\r{1}", voucher.Customer.Phone, voucher.Customer.Address);
|
|
|
|
|
billText += DrawLine;
|
|
|
|
|
}
|
2016-01-18 10:43:43 +00:00
|
|
|
|
billText += "\n\r" + "Cashier : " + voucher.User.Name;
|
2016-01-04 05:22:01 +00:00
|
|
|
|
using (var bis = new SettingBI())
|
|
|
|
|
billText += "\n\r" + bis.Get(x => x.Name == "Footer").Details;
|
2014-10-16 11:11:55 +00:00
|
|
|
|
return billText;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-16 11:11:55 +00:00
|
|
|
|
private static string Products(Voucher voucher, IList<Inventory> list)
|
2011-12-05 09:41:02 +00:00
|
|
|
|
{
|
2014-11-02 08:03:31 +00:00
|
|
|
|
string billNo;
|
|
|
|
|
switch (voucher.VoucherType)
|
|
|
|
|
{
|
|
|
|
|
case VoucherType.NoCharge:
|
|
|
|
|
billNo = "NC-" + voucher.BillID.Value.ToString();
|
|
|
|
|
break;
|
|
|
|
|
case VoucherType.Staff:
|
|
|
|
|
billNo = "ST-" + voucher.BillID.Value.ToString();
|
|
|
|
|
break;
|
|
|
|
|
case VoucherType.TakeAway:
|
|
|
|
|
case VoucherType.Regular:
|
|
|
|
|
default:
|
|
|
|
|
billNo = (voucher.BillID.Value % 10000).ToString();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-05 09:41:02 +00:00
|
|
|
|
|
|
|
|
|
var billText = "";
|
|
|
|
|
billText += "\n\r" + string.Format("Bill No: {0,-12} {1:dd-MMM-yyyy HH:mm:ss}", billNo, voucher.Date);
|
2014-10-16 11:11:55 +00:00
|
|
|
|
billText += "\n\r" + "Table No.: " + voucher.Table.Name;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
billText += "\n\r" + "------------------------------------------";
|
|
|
|
|
billText += "\n\r" + "Qty. Particulars Price Amount";
|
|
|
|
|
billText += "\n\r" + "------------------------------------------";
|
2014-10-16 11:11:55 +00:00
|
|
|
|
foreach (var item in list.Where(item => item.Quantity != 0))
|
2011-12-05 09:41:02 +00:00
|
|
|
|
{
|
|
|
|
|
billText += "\n\r" + FormatBillNum(item.Quantity, 5) + " ";
|
2016-04-11 07:01:52 +00:00
|
|
|
|
billText += FormatText(item.EffectiveName, 22, Align.Left) + " ";
|
|
|
|
|
billText += FormatBillNum(item.Price, 6) + " ";
|
|
|
|
|
billText += FormatBillNum(item.Price * item.Quantity, 6);
|
2014-10-16 11:11:55 +00:00
|
|
|
|
foreach (var mod in item.InventoryModifier.Where(x => x.Modifier.ShowInBill))
|
|
|
|
|
{
|
|
|
|
|
billText += "\n\r -- " + FormatText(mod.Modifier.Name, 38, Align.Left);
|
|
|
|
|
}
|
2011-12-05 09:41:02 +00:00
|
|
|
|
}
|
|
|
|
|
billText += "\n\r" + "------------------------------------------";
|
|
|
|
|
return billText;
|
|
|
|
|
}
|
|
|
|
|
private static string Header(Voucher voucher)
|
|
|
|
|
{
|
|
|
|
|
var billText = "";
|
2016-01-04 05:22:01 +00:00
|
|
|
|
using (var bi = new SettingBI())
|
|
|
|
|
billText += "\n\r" + bi.Get(x => x.Name == "Header").Details;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
switch (voucher.VoucherType)
|
|
|
|
|
{
|
|
|
|
|
case VoucherType.Regular:
|
|
|
|
|
billText += "\n\r" + "Retail Invoice".Center42();
|
|
|
|
|
billText += "\n\r";
|
|
|
|
|
break;
|
|
|
|
|
case VoucherType.NoCharge:
|
|
|
|
|
billText += "\n\r" + "NO CHARGE - THIS IS NOT A BILL - DON'T PAY".Center42();
|
|
|
|
|
billText += "\n\r";
|
|
|
|
|
break;
|
|
|
|
|
case VoucherType.TakeAway:
|
|
|
|
|
billText += "\n\r" + "Retail Invoice (Delivery)".Center42();
|
|
|
|
|
billText += "\n\r";
|
|
|
|
|
break;
|
|
|
|
|
case VoucherType.Staff:
|
|
|
|
|
billText += "\n\r" + "STAFF CONSUMPTION -- THIS IS NOT A BILL".Center42();
|
|
|
|
|
billText += "\n\r";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return billText;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|