da929ad036
Breaking Change: Renamed Discontinued to IsActive and added NA field to products. Cleanup: Removed not used attributes Change: RoleConstants changed to simple string Feature: Table Create/Edit/Reorder and Modifier Create/Edit Form Feature: Bills now show the Tax name from the database and not a hack
168 lines
8.0 KiB
C#
168 lines
8.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Tanshu.Accounts.Entities;
|
|
using Tanshu.Common.Helpers;
|
|
using Tanshu.Accounts.Contracts;
|
|
using Tanshu.Accounts.Repository;
|
|
|
|
namespace Tanshu.Accounts.Print
|
|
{
|
|
|
|
public static partial class Thermal
|
|
{
|
|
private static string DesignBill(Guid voucherID)
|
|
{
|
|
using (var bi = new VoucherBI())
|
|
{
|
|
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();
|
|
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;
|
|
amount = list.Values.Sum(item => item.Quantity * item.FullPrice);
|
|
if (amount != 0)
|
|
billText += "\n\r" + FormatText("Total : ", 33, Align.Right) + FormatBillNum(amount, 9);
|
|
|
|
amount = list.Values.Sum(item => item.Quantity * (item.FullPrice - item.Price));
|
|
if (amount != 0)
|
|
billText += "\n\r" + FormatText("Happy Hour Discount : ", 33, Align.Right) + FormatBillNum(amount, 9);
|
|
|
|
amount = list.Values.Sum(item => item.Quantity * item.Price * item.Discount);
|
|
if (amount != 0)
|
|
billText += "\n\r" + FormatText("Discount : ", 33, Align.Right) + FormatBillNum(amount, 9);
|
|
|
|
amount = list.Values.Sum(item => item.Quantity * item.Price * (1 - item.Discount));
|
|
if (amount != 0)
|
|
{
|
|
billText += "\n\r" + FormatText(" : ", 33, Align.Right) + "---------";
|
|
billText += "\n\r" + FormatText("Net : ", 33, Align.Right) + FormatBillNum(amount, 9);
|
|
|
|
}
|
|
|
|
amount = list.Values.Sum(item => item.Quantity * item.Price * (1 - item.Discount) * item.ServiceCharge);
|
|
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,
|
|
Amount = vat.Sum(x => x.Quantity * x.Price * (1 - x.Discount) * (1 + x.ServiceCharge) * x.VatRate)
|
|
};
|
|
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,
|
|
Amount = serviceTax.Sum(x => x.Quantity * x.Price * (1 - x.Discount) * (1 + x.ServiceCharge) * x.ServiceTaxRate)
|
|
};
|
|
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));
|
|
|
|
billText += DrawLine;
|
|
|
|
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;
|
|
}
|
|
billText += "\n\r" + "Cashier : " + voucher.User.Name + " / " + voucher.Waiter.Name;
|
|
billText += "\n\r" + "Call: 0172-4026666, 8054923853, 8054923856";
|
|
return billText;
|
|
}
|
|
}
|
|
private static string Products(Voucher voucher, IList<Inventory> list)
|
|
{
|
|
var billNo = voucher.BillID.Substring(voucher.BillID.IndexOf("-") + 1);
|
|
|
|
var billText = "";
|
|
billText += "\n\r" + string.Format("Bill No: {0,-12} {1:dd-MMM-yyyy HH:mm:ss}", billNo, voucher.Date);
|
|
billText += "\n\r" + "Table No.: " + voucher.Table.Name;
|
|
billText += "\n\r" + "------------------------------------------";
|
|
billText += "\n\r" + "Qty. Particulars Price Amount";
|
|
billText += "\n\r" + "------------------------------------------";
|
|
foreach (var item in list.Where(item => item.Quantity != 0))
|
|
{
|
|
billText += "\n\r" + FormatBillNum(item.Quantity, 5) + " ";
|
|
billText += FormatText(Name(item.Product), 22, Align.Left) + " ";
|
|
billText += FormatBillNum(item.FullPrice, 6) + " ";
|
|
billText += FormatBillNum(item.FullPrice * item.Quantity, 6);
|
|
foreach (var mod in item.InventoryModifier.Where(x => x.Modifier.ShowInBill))
|
|
{
|
|
billText += "\n\r -- " + FormatText(mod.Modifier.Name, 38, Align.Left);
|
|
}
|
|
}
|
|
billText += "\n\r" + "------------------------------------------";
|
|
return billText;
|
|
}
|
|
private static string Header(Voucher voucher)
|
|
{
|
|
var billText = "";
|
|
billText += "\n\r" + "Hops n Grains".Center42();
|
|
billText += "\n\r" + "The Microbrewery".Center42();
|
|
billText += "\n\r" + "SCO 358, Sector 9, Panchkula".Center42();
|
|
billText += "\n\r" + "A Unit of Peitho Foods Pvt. Ltd.".Center42();
|
|
billText += "\n\r" + "CIN: U15139CH2010PTC032202".Center42();
|
|
billText += "\n\r" + "(Reg Add: SCO 1, Pocket 1, Manimajra, Chd)".Center42();
|
|
billText += "\n\r" + "TIN: 06592507323".Center42();
|
|
billText += "\n\r" + "Service Tax: AAFCP5097GSD001".Center42();
|
|
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;
|
|
}
|
|
}
|
|
} |