Multiple settlement options. Upgrade SQL Script included.

This commit is contained in:
unknown 2011-03-12 00:19:48 +05:30
parent 9ed5843dbd
commit aea41a9d24
42 changed files with 1917 additions and 1550 deletions

3
.gitignore vendored

@ -2,4 +2,5 @@
*/[Bb]in/
*.suo
[Bb]in/
*.user
*.user
_[Rr]e[Ss]harper.*/

Binary file not shown.

@ -1,18 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tanshu.Accounts.Contracts
namespace Tanshu.Accounts.Contracts.Attributes
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class AllowNullAttribute : Attribute
{
private string message = string.Empty;
private string _message = string.Empty;
public string Message
{
get { return message; }
set { message = value; }
get { return _message; }
set { _message = value; }
}
}
}
}

@ -0,0 +1,19 @@
using System;
namespace Tanshu.Accounts.Contracts
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DisplayAttribute : Attribute
{
public DisplayAttribute(string name, bool showInChoices, int group)
{
Name = name;
ShowInChoices = showInChoices;
Group = group;
}
public string Name { get; set; }
public int Group { get; set; }
public bool ShowInChoices { get; set; }
}
}

@ -1,6 +1,4 @@
using System;
using System.Runtime.Serialization;
using FluentNHibernate.Mapping;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Contracts;

@ -1,8 +1,4 @@
using System;
using System.Runtime.Serialization;
using FluentNHibernate.Mapping;
namespace Tanshu.Accounts.Entities
namespace Tanshu.Accounts.Entities
{
public class Customer
{

@ -1,18 +1,25 @@
using System;
using System.Runtime.Serialization;
using FluentNHibernate.Mapping;
using System.Collections.Generic;
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.Entities
{
public class Inventory
{
public Inventory()
{
// ReSharper disable DoNotCallOverridableMethodsInConstructor
InventoryModifier = new List<InventoryModifier>();
// ReSharper restore DoNotCallOverridableMethodsInConstructor
}
public virtual int InventoryID { get; set; }
[NotNull]
public virtual Kot Kot { get; set; }
[NotNull]
public virtual Product Product { get; set; }
public virtual decimal Quantity { get; set; }
public virtual decimal Rate { get; set; }
public virtual decimal Tax { get; set; }
@ -21,18 +28,12 @@ namespace Tanshu.Accounts.Entities
[Cascade]
public virtual IList<InventoryModifier> InventoryModifier { get; set; }
[Formula(Formula = "Quantity * Rate * (1 - Discount) * (1 + ServiceCharge) * (1 + Tax)")]
public virtual decimal Amount
{
get
{
return Quantity * Rate * (1 + Tax) * (1 + ServiceCharge) * (1 - Discount);
}
get { return Quantity * Rate * (1 + Tax) * (1 + ServiceCharge) * (1 - Discount); }
private set { }
}
public Inventory()
{
InventoryModifier = new List<InventoryModifier>();
}
}
}
}

@ -1,23 +1,23 @@
using System;
using System.Runtime.Serialization;
using FluentNHibernate.Mapping;
using System.Collections.Generic;
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.Entities
{
public class ProductGroup
{
public virtual int ProductGroupID { get; set; }
[NotNull, Unique]
public virtual string Name { get; set; }
public virtual decimal DiscountLimit { get; set; }
public virtual bool IsModifierCompulsory { get; set; }
public virtual string GroupType { get; set; }
public virtual IList<Product> Products { get; set; }
public ProductGroup()
{
Products = new List<Product>();
}
public virtual int ProductGroupID { get; set; }
[NotNull, Unique]
public virtual string Name { get; set; }
public virtual decimal DiscountLimit { get; set; }
public virtual bool IsModifierCompulsory { get; set; }
public virtual string GroupType { get; set; }
public virtual IList<Product> Products { get; set; }
}
}
}

@ -1,17 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.Entities
{
public enum SettleOption
{
[Display("Unsettled", false, 1)]
Unsettled = 1,
[Display("Cash", true, 2)]
Cash = 2,
[Display("Credit Card", true, 2)]
CreditCard = 3,
[Display("No Charge", true, 3)]
NoCharge = 4,
[Display("Bill To Company", true, 4)]
BillToCompany = 5,
Staff = 6
[Display("Tip", true, 2)]
Tip = 6,
[Display("Round Off", false, 1)]
RoundOff = 7,
[Display("Amount", false, 1)]
Amount = 8
}
}
}

@ -1,46 +1,60 @@
using System;
using System.Runtime.Serialization;
using FluentNHibernate.Mapping;
using Tanshu.Accounts.Entities.Auth;
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Contracts.Attributes;
using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.Entities
{
public class Voucher
{
public Voucher()
{
Kots = new List<Kot>();
Settlements = new List<VoucherSettlement>();
}
public virtual int VoucherID { get; set; }
public virtual DateTime? Date { get; set; }
public virtual string Narration { get; set; }
[NotNull]
public virtual User User { get; set; }
[NotNull]
public virtual DateTime CreationDate { get; set; }
[NotNull]
public virtual DateTime LastEditDate { get; set; }
[NotNull]
public virtual string BillID { get; set; }
[NotNull]
public virtual string TableID { get; set; }
[NotNull]
public virtual Waiter Waiter { get; set; }
[NotNull]
public virtual Customer Customer { get; set; }
[NotNull]
public virtual SettleOption Settled { get; set; }
[Cascade]
public virtual IList<VoucherSettlement> Settlements { get; set; }
[NotNull]
public virtual bool Void { get; set; }
[AllowNull]
public virtual string VoidReason { get; set; }
[NotNull]
public virtual bool Printed { get; set; }
[NotNull]
public virtual string KotID { get; set; }
[Cascade]
public virtual IList<Kot> Kots { get; set; }
public Voucher()
{
this.Kots = new List<Kot>();
}
}
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Contracts.Attributes;
using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.Entities
{
public class VoucherSettlement
{
public virtual int VoucherSettlementID { get; set; }
[NotNull]
public virtual Voucher Voucher { get; set; }
[NotNull]
public virtual SettleOption Settled { get; set; }
[NotNull]
public virtual decimal Amount { get; set; }
}
}

@ -79,6 +79,7 @@
<ItemGroup>
<Compile Include="Attributes\CascadeAttribute.cs" />
<Compile Include="Attributes\AllowNullAttribute.cs" />
<Compile Include="Attributes\DisplayAttribute.cs" />
<Compile Include="Attributes\FormulaAttribute.cs" />
<Compile Include="Attributes\UniqueAttribute.cs" />
<Compile Include="Attributes\PermissionAttribute.cs" />
@ -91,6 +92,7 @@
<Compile Include="Data Contracts\Auth\RoleGroup.cs" />
<Compile Include="Data Contracts\Auth\Group.cs" />
<Compile Include="Data Contracts\Auth\Role.cs" />
<Compile Include="Data Contracts\VoucherSettlementBO.cs" />
<Compile Include="Data Contracts\KotBO.cs" />
<Compile Include="Data Contracts\PaymentGroupBO.cs" />
<Compile Include="Data Contracts\InventoryModifierBO.cs" />

@ -4,7 +4,7 @@
<add name="FluentCon" connectionString="Server=.;Initial Catalog=Pets;User ID=sa;Password=123456" />
</connectionStrings>
<appSettings>
<add key ="Location" value ="Ground"/>
<add key ="Location" value ="Office"/>
<add key ="Factory" value ="SqlServer"/>
<add key ="LogConnection" value ="connection"/>
<add key ="LogLevel" value ="Warn"/>

@ -1,4 +1,5 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Repository;
@ -8,23 +9,20 @@ namespace Tanshu.Accounts.PointOfSale
{
public partial class LoginForm : Form
{
private User user;
private IKeyboardControl keyboardControl;
private User _user;
private IKeyboardControl _keyboardControl;
public LoginForm(IKeyboardControl keyboardControl)
{
InitializeComponent();
user = null;
this.keyboardControl = keyboardControl;
_user = null;
this._keyboardControl = keyboardControl;
var control = keyboardControl as UserControl;
if (control != null)
{
control.Location = new System.Drawing.Point(6, 87);
var border = (this.Width - this.ClientSize.Width) / 2;
var titlebarHeight = this.Height - this.ClientSize.Height - (2 * border);
this.Controls.Add(control);
this.Width = 6 + control.Width + 6 + (border * 2);
this.Height = titlebarHeight + 87 + control.Height + 6 + (border * 2);
this.Size = this.SizeFromClientSize(new Size(6 + control.Width + 6, 87 + control.Height + 6));
}
}
@ -42,8 +40,8 @@ namespace Tanshu.Accounts.PointOfSale
private void btnLogin_Click(object sender, EventArgs e)
{
user = UserBI.ValidateUser(txtUserName.Text.Trim(), Tanshu.Common.Md5.Hash(txtPassword.Text, "v2"));
if (user != null)
_user = UserBI.ValidateUser(txtUserName.Text.Trim(), Tanshu.Common.Md5.Hash(txtPassword.Text, "v2"));
if (_user != null)
this.Close();
else
MessageBox.Show("Username or password is not valid");
@ -51,8 +49,8 @@ namespace Tanshu.Accounts.PointOfSale
public bool UserName(out string userName)
{
userName = this.user == null ? "" : this.user.Name;
return this.user != null;
userName = this._user == null ? "" : this._user.Name;
return this._user != null;
}
private void btnExit_Click(object sender, EventArgs e)

@ -1,39 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.Contracts;
using System.Windows.Forms;
using Tanshu.Common;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.SqlDAO;
using System.Collections.ObjectModel;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.PointOfSale.Sales;
using Tanshu.Accounts.Print;
using Tanshu.Accounts.Repository;
using Tanshu.Common;
namespace Tanshu.Accounts.PointOfSale
{
public class BillController
{
private Voucher billInfo;
private OrderedDictionary<BillItemKey, BillInventory> bill = new OrderedDictionary<BillItemKey, BillInventory>();
int? editVoucherID;
private readonly OrderedDictionary<BillItemKey, BillInventory> bill =
new OrderedDictionary<BillItemKey, BillInventory>();
private Voucher _billInfo;
private Customer _customer = new CustomerBI().GetCustomer(1);
private int? _editVoucherID;
private ISaleForm _saleForm;
ISaleForm saleForm;
private Customer customer = new CustomerBI().GetCustomer(1);
public BillController(int? editVoucherID)
{
this.editVoucherID = editVoucherID;
this._editVoucherID = editVoucherID;
}
public BillInventory CurrentProduct
{
get
{
if (_saleForm.BindingSource.Position == -1)
return null;
else
{
var item = bill.ElementAt(_saleForm.BindingSource.Position);
if (item.Key.KotID == -1)
return null;
return item.Value;
}
}
}
public BillInventory CurrentKot
{
get
{
if (_saleForm.BindingSource.Position == -1)
return null;
else
{
KeyValuePair<BillItemKey, BillInventory> item = bill.ElementAt(_saleForm.BindingSource.Position);
if (item.Key.KotID != -1)
return null;
if (item.Key.ProductID == 0)
return null;
return item.Value;
}
}
}
public void InitGui(ISaleForm saleForm)
{
this.saleForm = saleForm;
this.saleForm.SetCustomerDisplay(customer.Name);
this.saleForm.SetUserName(Session.User.Name);
this._saleForm = saleForm;
this._saleForm.SetCustomerDisplay(_customer.Name);
this._saleForm.SetUserName(Session.User.Name);
}
private void InitComponents()
{
InitModel();
@ -49,10 +85,11 @@ namespace Tanshu.Accounts.PointOfSale
{
throw new NotImplementedException();
}
public void AddProductToGrid(int productID)
{
new BillHelperFunctions(saleForm.BindingSource, bill, productID).AddProduct();
Product product = ProductBI.GetProduct(productID);
new BillHelperFunctions(_saleForm.BindingSource, bill, productID).AddProduct();
var product = ProductBI.GetProduct(productID);
if (ProductGroupModifierBI.HasCompulsoryModifier(product.ProductGroup.ProductGroupID))
{
var item = CurrentProduct;
@ -85,16 +122,16 @@ namespace Tanshu.Accounts.PointOfSale
if (frm.ShowDialog() == DialogResult.OK)
{
HashSet<string> outList;
decimal discount = frm.Selection(out outList);
var discount = frm.Selection(out outList);
discount = discount / 100;
foreach (var item in bill)
{
if (item.Key.KotID == -1)
continue;
var pg = new ProductGroupBI().GetProductGroupOfProduct(item.Value.ProductID);
ProductGroup pg = new ProductGroupBI().GetProductGroupOfProduct(item.Value.ProductID);
if (outList.Contains(pg.GroupType))
new BillHelperFunctions(saleForm.BindingSource, bill, item.Value.ProductID).SetDiscount(item.Value.Name, discount);
new BillHelperFunctions(_saleForm.BindingSource, bill, item.Value.ProductID).SetDiscount(
item.Value.Name, discount);
}
}
}
@ -103,244 +140,102 @@ namespace Tanshu.Accounts.PointOfSale
public void ShowCustomerList(bool reset)
{
if ((customer.CustomerID == 1) && (!reset))
if ((_customer.CustomerID == 1) && (!reset))
{
using (SelectCustomer selectCustomer = new SelectCustomer(new CustomerBI().GetFilteredCustomers, true))
using (var selectCustomer = new SelectCustomer(new CustomerBI().GetFilteredCustomers, true))
{
selectCustomer.customerEvent += new CustomerEventHandler(selectCustomer_customerEvent);
selectCustomer.customerEvent += selectCustomer_customerEvent;
selectCustomer.ShowDialog();
if (selectCustomer.SelectedItem != null)
{
customer = selectCustomer.SelectedItem;
saleForm.SetCustomerDisplay(customer.Name);
_customer = selectCustomer.SelectedItem;
_saleForm.SetCustomerDisplay(_customer.Name);
}
else
{
customer = new CustomerBI().GetCustomer(1);
_customer = new CustomerBI().GetCustomer(1);
}
}
}
else
{
customer = new CustomerBI().GetCustomer(1);
saleForm.SetCustomerDisplay(customer.Name);
_customer = new CustomerBI().GetCustomer(1);
_saleForm.SetCustomerDisplay(_customer.Name);
}
}
#region Save
// if (btnWaiter.Tag == null)
//btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
public void Save(bool print, int waiterID, string tableID)
{
if (print && !Session.IsAllowed(RoleConstants.PRINT_BILL))
return;
if (!print && !Session.IsAllowed(RoleConstants.PRINT_KOT))
return;
if ((billInfo != null) && (VoucherBI.IsBillPrinted(billInfo.VoucherID)) && (!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL)))
return;
if (bill.Count == 1) //new kot only
return;
if (print)
ShowDiscount();
int? saved;
if (billInfo == null)
saved = InsertVoucher(print, waiterID, tableID);
else
saved = UpdateSale(print, waiterID, tableID);
if (editVoucherID.HasValue)
saleForm.CloseWindow();
else
{
int kotID = 0;
if (!print && saved.HasValue)
kotID = saved.Value;
if (print || kotID != 0)
PrintBill(billInfo.VoucherID, kotID);
}
ClearBill();
}
private int? InsertVoucher(bool finalBill, int waiterID, string tableID)
{
if (billInfo != null)
{
MessageBox.Show("Error in InsertVoucher, there is a previous sale in memory", "Error");
return null;
}
#region Voucher
billInfo = new Voucher
{
Customer = customer,
Settled = SettleOption.Unsettled,
//Paid = finalBill,
TableID = tableID,
Waiter = WaiterBI.GetWaiter(waiterID),
Printed = finalBill,
Void = false,
Date = DateTime.Now,
Narration = "",
User = Session.User
};
#endregion
#region Inventories
var kot = GetKotForBill();
if (kot != null)
billInfo.Kots.Add(kot);
#endregion
return VoucherBI.Insert(billInfo);
}
private int? UpdateSale(bool finalBill, int waiterID, string tableID)
{
#region Voucher
billInfo.User = Session.User;
billInfo.Customer = customer;
if (!billInfo.Printed && finalBill)
billInfo.Date = null;
billInfo.Printed = billInfo.Printed || finalBill;
billInfo.TableID = tableID;
billInfo.Waiter = WaiterBI.GetWaiter(waiterID);
var kot = GetKotForBill();
if (kot != null)
billInfo.Kots.Add(kot);
#endregion
#region Inventory
#endregion
return VoucherBI.Update(billInfo);
}
private Kot GetKotForBill()
{
var kot = new Kot();
foreach (var item in bill)
{
if (item.Key.KotID == -1 || item.Value.Quantity == 0)
continue;
else if (item.Key.KotID != 0)
{
var oldKot = billInfo.Kots.Where(x => x.KotID == item.Key.KotID).Single();
var inv = oldKot.Inventories.Where(x => x.Product.ProductID == item.Key.ProductID).Single();
inv.Rate = item.Value.Price;
inv.Discount = item.Value.Discount;
}
else
{
Inventory temp = new Inventory();
temp.Product = ProductBI.GetProduct(item.Key.ProductID);
temp.Quantity = item.Value.Quantity;
temp.Rate = item.Value.Price;
temp.Discount = item.Value.Discount;
temp.ServiceCharge = item.Value.ServiceCharge;
temp.Tax = item.Value.Tax;
foreach (var mod in item.Value.Modifiers)
temp.InventoryModifier.Add(new InventoryModifier() { Modifier = mod });
kot.Inventories.Add(temp);
}
}
if (kot.Inventories.Count == 0)
return null;
else
return kot;
}
#endregion
public void VoidBill()
{
if (billInfo == null)
if (_billInfo == null)
return;
if (!billInfo.Printed)
if (!_billInfo.Printed)
return;
if (Session.IsAllowed(RoleConstants.VOID_BILL))
if (!Session.IsAllowed(RoleConstants.VOID_BILL))
return;
if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
return;
var voidReason = new SelectVoidReason(GetVoidReason, true);
voidReason.ShowDialog();
if (voidReason.SelectedItem != null)
{
if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
SelectVoidReason voidReason = new SelectVoidReason(GetVoidReason, true);
voidReason.ShowDialog();
if (voidReason.SelectedItem != null)
{
VoucherBI.VoidBill(billInfo.VoucherID, voidReason.SelectedItem.Description);
ClearBill();
}
else
{
MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
VoucherBI.VoidBill(_billInfo.VoucherID, voidReason.SelectedItem.Description);
ClearBill();
}
else
{
MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
Customer selectCustomer_customerEvent(object sender, CustomerEventArgs e)
private Customer selectCustomer_customerEvent(object sender, CustomerEventArgs e)
{
using (CustomersForm form = new CustomersForm(e.CustomerID, e.Phone))
using (var form = new CustomersForm(e.CustomerID, e.Phone))
{
form.ShowDialog();
return form.Customer;
}
}
private void PrintBill(int voucherID, int kotID)
private static void PrintBill(int voucherID, int kotID)
{
if (kotID == 0)
Accounts.Print.Thermal.PrintBill(voucherID);
Thermal.PrintBill(voucherID);
else
Accounts.Print.Thermal.PrintKot(voucherID, kotID);
Thermal.PrintKot(voucherID, kotID);
}
private List<StringType> GetVoidReason(Dictionary<string, string> filter)
private static List<StringType> GetVoidReason(Dictionary<string, string> filter)
{
List<StringType> list = new List<StringType>();
list.Add(new StringType("Discount"));
list.Add(new StringType("Printing Fault"));
list.Add(new StringType("Item Changed"));
list.Add(new StringType("Quantity Reduced"));
list.Add(new StringType("Costing Bill for Party"));
list.Add(new StringType("Cashier Mistake"));
list.Add(new StringType("Management Freesale"));
list.Add(new StringType("Other"));
var list = new List<StringType>
{
new StringType("Discount"),
new StringType("Printing Fault"),
new StringType("Item Changed"),
new StringType("Quantity Reduced"),
new StringType("Costing Bill for Party"),
new StringType("Cashier Mistake"),
new StringType("Management Freesale"),
new StringType("Other")
};
return list.Where(i => i.Description.ToLower().Contains(filter["Name"].ToLower().Trim())).ToList();
}
public BillInventory CurrentProduct
{
get
{
if (saleForm.BindingSource.Position == -1)
return null;
else
{
var item = bill.ElementAt(saleForm.BindingSource.Position);
if (item.Key.KotID == -1)
return null;
else
return item.Value;
}
}
}
public BillInventory CurrentKot
{
get
{
if (saleForm.BindingSource.Position == -1)
return null;
else
{
var item = bill.ElementAt(saleForm.BindingSource.Position);
if (item.Key.KotID != -1)
return null;
else if (item.Key.ProductID == 0)
return null;
else
return item.Value;
}
}
}
private void ShowAmount()
{
//saleForm.BindingSource.CurrencyManager.Position = 1;
decimal taxAmount = bill.Values.Sum(b => b.TaxAmount);
decimal discountAmount = bill.Values.Sum(b => b.DiscountAmount);
decimal grossAmount = bill.Values.Sum(b => b.GrossAmount);
decimal valueAmount = bill.Values.Sum(b => b.Value);
decimal serviceChargeAmount = bill.Values.Sum(b => b.ServiceChargeAmount);
var taxAmount = bill.Values.Sum(b => b.TaxAmount);
var discountAmount = bill.Values.Sum(b => b.DiscountAmount);
var grossAmount = bill.Values.Sum(b => b.GrossAmount);
var valueAmount = bill.Values.Sum(b => b.Value);
var serviceChargeAmount = bill.Values.Sum(b => b.ServiceChargeAmount);
//bill.Values.ToList();
saleForm.ShowAmount(discountAmount, grossAmount, serviceChargeAmount, taxAmount, valueAmount, bill.Values.ToList());
_saleForm.ShowAmount(discountAmount, grossAmount, serviceChargeAmount, taxAmount, valueAmount,
bill.Values.ToList());
}
public void ProductRemove()
{
var item = CurrentProduct;
@ -358,7 +253,8 @@ namespace Tanshu.Accounts.PointOfSale
var item = CurrentProduct;
if (!Allowed(item))
return;
new BillHelperFunctions(saleForm.BindingSource, bill, CurrentProduct.ProductID).SetQuantity(item, quantity, prompt);
new BillHelperFunctions(_saleForm.BindingSource, bill, CurrentProduct.ProductID).SetQuantity(item, quantity,
prompt);
ShowAmount();
}
@ -367,83 +263,91 @@ namespace Tanshu.Accounts.PointOfSale
var item = CurrentProduct;
if (!Allowed(item))
return;
new BillHelperFunctions(saleForm.BindingSource, bill, CurrentProduct.ProductID).SetPrice(CurrentProduct);
new BillHelperFunctions(_saleForm.BindingSource, bill, CurrentProduct.ProductID).SetPrice(CurrentProduct);
ShowAmount();
}
private bool Allowed(BillInventory item, RoleConstants role)
{
if (item == null)
return false;
if (!Session.IsAllowed(role))
return false;
return true;
return Session.IsAllowed(role);
}
private bool Allowed(BillInventory item)
{ return item != null; }
{
return item != null;
}
private void InputBox_Validating(object sender, InputBoxValidatingArgs e)
{
}
private void LoadBill(int voucherID)
{
ClearBill();
bill.Clear();
billInfo = null;
billInfo = VoucherBI.GetSaleVoucher(voucherID);
_billInfo = null;
_billInfo = VoucherBI.GetVoucher(voucherID);
this.customer = billInfo.Customer;
saleForm.ShowInfo(billInfo.BillID, billInfo.KotID, billInfo.CreationDate, billInfo.Date.Value, billInfo.LastEditDate, customer.Name, billInfo.TableID, billInfo.Waiter.WaiterID, billInfo.Waiter.Name);
_customer = _billInfo.Customer;
_saleForm.ShowInfo(_billInfo.BillID, _billInfo.KotID, _billInfo.CreationDate, _billInfo.Date.Value,
_billInfo.LastEditDate, _customer.Name, _billInfo.TableID, _billInfo.Waiter.WaiterID,
_billInfo.Waiter.Name);
foreach (var kot in billInfo.Kots)
foreach (var kot in _billInfo.Kots)
{
BillItemKey kotKey = new BillItemKey(kot.KotID, -1);
var kotKey = new BillItemKey(kot.KotID, -1);
var kotItem = new BillInventory
{
ProductID = kot.KotID,
Discount = 0,
Name = string.Format("Kot No.: {0} / KotID {1}", kot.KotID, kot.Code),
Price = 0,
Printed = true,
Quantity = 0,
Tax = -1,
ServiceCharge = 0,
};
{
ProductID = kot.KotID,
Discount = 0,
Name = string.Format("Kot No.: {0} / KotID {1}", kot.KotID, kot.Code),
Price = 0,
Printed = true,
Quantity = 0,
Tax = -1,
ServiceCharge = 0,
};
bill.Add(kotKey, kotItem);
foreach (var inv in kot.Inventories)
{
BillItemKey key = new BillItemKey(inv.Product.ProductID, kot.KotID);
var key = new BillItemKey(inv.Product.ProductID, kot.KotID);
var item = new BillInventory
{
ProductID = inv.Product.ProductID,
Discount = inv.Discount,
Name = inv.Product.Units == string.Empty ? inv.Product.Name : inv.Product.Name + " (" + inv.Product.Units + ")",
Price = inv.Rate,
Printed = true,
Quantity = inv.Quantity,
Tax = inv.Tax,
ServiceCharge = inv.ServiceCharge,
};
{
ProductID = inv.Product.ProductID,
Discount = inv.Discount,
Name =
inv.Product.Units == string.Empty
? inv.Product.Name
: inv.Product.Name + " (" + inv.Product.Units + ")",
Price = inv.Rate,
Printed = true,
Quantity = inv.Quantity,
Tax = inv.Tax,
ServiceCharge = inv.ServiceCharge,
};
foreach (var mod in inv.InventoryModifier)
item.Modifiers.Add(mod.Modifier);
bill.Add(key, item);
}
}
BillItemKey newKotKey = new BillItemKey(0, -1);
var newKotKey = new BillItemKey(0, -1);
var newKotItem = new BillInventory
{
ProductID = 0,
Discount = 0,
Name = "== New Kot ==",
Price = 0,
Printed = true,
Quantity = 0,
Tax = -1,
ServiceCharge = 0,
};
{
ProductID = 0,
Discount = 0,
Name = "== New Kot ==",
Price = 0,
Printed = true,
Quantity = 0,
Tax = -1,
ServiceCharge = 0,
};
bill.Add(newKotKey, newKotItem);
ShowAmount();
}
public void LoadBillFromTable(string tableName)
{
if (!string.IsNullOrEmpty(tableName))
@ -453,14 +357,13 @@ namespace Tanshu.Accounts.PointOfSale
{
LoadBill(table.VoucherID);
}
}
else
{
InputBoxResult result = InputBox.Show("Table Number", "0", InputBox_Validating);
var result = InputBox.Show("Table Number", "0", InputBox_Validating);
if (result.OK)
{
string tableID = result.Text.Trim();
var tableID = result.Text.Trim();
if ((tableID != "C") && (tableID != "") && (!tableID.Contains(".")))
{
var table = new FoodTableBI().GetByName(tableName);
@ -478,79 +381,82 @@ namespace Tanshu.Accounts.PointOfSale
public void CancelBillChanges()
{
if (bill.Count != 0 && bill.Values.Any(i => i.Printed == false))
if (MessageBox.Show("Abandon Changes?", "Abandon Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
if (
MessageBox.Show("Abandon Changes?", "Abandon Changes", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
return;
ClearBill();
}
public void ClearBill()
{
billInfo = null;
_billInfo = null;
ShowCustomerList(true);
bill.Clear();
BillItemKey newKotKey = new BillItemKey(0, -1);
var newKotKey = new BillItemKey(0, -1);
var newKotItem = new BillInventory
{
ProductID = 0,
Discount = 0,
Name = "== New Kot ==",
Price = 0,
Printed = true,
Quantity = 0,
Tax = -1,
ServiceCharge = 0,
};
{
ProductID = 0,
Discount = 0,
Name = "== New Kot ==",
Price = 0,
Printed = true,
Quantity = 0,
Tax = -1,
ServiceCharge = 0,
};
bill.Add(newKotKey, newKotItem);
saleForm.ClearBill(bill);
_saleForm.ClearBill(bill);
}
public void FormLoad()
{
ClearBill();
if (editVoucherID.HasValue)
if (_editVoucherID.HasValue)
{
LoadBill(editVoucherID.Value);
LoadBill(_editVoucherID.Value);
}
}
internal void SettleBill()
{
if (billInfo == null)
if (_billInfo == null)
return;
if (!billInfo.Printed)
if (!_billInfo.Printed)
return;
if (!Session.IsAllowed(RoleConstants.SETTLE_BILL))
return;
var option = SettleOption.Unsettled;
using (BillSettleForm frm = new BillSettleForm())
IDictionary<SettleOption, decimal> options;
using (var frm = new SettleChoicesForm(_billInfo))
{
frm.ShowDialog();
option = frm.optionChosen;
}
if (option != SettleOption.Unsettled)
{
VoucherBI.SettleVoucher(Session.User, billInfo.VoucherID, option);
ClearBill();
options = frm.OptionsChosen;
}
if (options.Count == 0)
return;
VoucherBI.SettleVoucher(Session.User, _billInfo.VoucherID, options);
ClearBill();
}
internal void MoveTable()
{
if (billInfo == null)
if (_billInfo == null)
return;
if (VoucherBI.IsBillPrinted(billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
if (VoucherBI.IsBillPrinted(_billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
return;
var table = GetTableForMove(true);
if (table == null)
return;
if (table.VoucherID == 0)
LoadBill(MoveTable(table));
else
LoadBill(MergeTable(table));
LoadBill(table.VoucherID == 0 ? MoveTable(table) : MergeTable(table));
}
private int MoveTable(FoodTable table)
{
if (!Session.IsAllowed(RoleConstants.MOVE_TABLE))
return 0;
return new FoodTableBI().Move(billInfo.TableID, table);
return new FoodTableBI().Move(_billInfo.TableID, table);
}
private int MergeTable(FoodTable table)
{
if (!Session.IsAllowed(RoleConstants.MERGE_TABLE))
@ -558,16 +464,17 @@ namespace Tanshu.Accounts.PointOfSale
var kots = bill.Where(x => x.Key.KotID == -1 && x.Key.ProductID != 0);
foreach (var item in kots)
MergeKot(item.Value, table);
VoucherBI.Delete(billInfo.VoucherID);
VoucherBI.Delete(_billInfo.VoucherID);
return table.VoucherID;
}
private int MergeKot(BillInventory kot, FoodTable table)
private static int MergeKot(BillInventory kot, FoodTable table)
{
if (!Session.IsAllowed(RoleConstants.MERGE_KOT))
return 0;
return VoucherBI.MoveKot(kot.ProductID, table);
}
private int MoveKot(BillInventory kot, FoodTable table)
{
if (!Session.IsAllowed(RoleConstants.MOVE_KOT))
@ -575,23 +482,24 @@ namespace Tanshu.Accounts.PointOfSale
CreateNewVoucherForKotMove(kot, table);
return MergeKot(kot, table);
}
private void CreateNewVoucherForKotMove(BillInventory kot, FoodTable table)
{
var voucher = new Voucher
{
Customer = billInfo.Customer,
Settled = SettleOption.Unsettled,
TableID = table.Name,
Waiter = billInfo.Waiter,
Printed = false,
Void = false,
Date = DateTime.Now,
Narration = "",
User = Session.User
};
{
Customer = _billInfo.Customer,
TableID = table.Name,
Waiter = _billInfo.Waiter,
Printed = false,
Void = false,
Date = DateTime.Now,
Narration = "",
User = Session.User
};
VoucherBI.Insert(voucher);
}
private FoodTable GetTableForMove(bool allowMerge)
private static FoodTable GetTableForMove(bool allowMerge)
{
using (var frm = new frmMoveTable(new FoodTableBI().List(), allowMerge))
{
@ -604,9 +512,9 @@ namespace Tanshu.Accounts.PointOfSale
internal void MergeKot()
{
if (billInfo == null)
if (_billInfo == null)
return;
if (VoucherBI.IsBillPrinted(billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
if (VoucherBI.IsBillPrinted(_billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
return;
var kot = CurrentKot;
if (kot == null)
@ -615,7 +523,7 @@ namespace Tanshu.Accounts.PointOfSale
if (table == null)
return;
var count = bill.Keys.Count(x => x.KotID == -1 && x.ProductID != 0);
int voucherID = 0;
var voucherID = 0;
if (table.VoucherID == 0 && count > 1)
//Move Kot
voucherID = MoveKot(kot, table);
@ -631,5 +539,137 @@ namespace Tanshu.Accounts.PointOfSale
if (voucherID != 0)
LoadBill(voucherID);
}
#region Save
// if (btnWaiter.Tag == null)
//btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
public void Save(bool print, int waiterID, string tableID)
{
if (print && !Session.IsAllowed(RoleConstants.PRINT_BILL))
return;
if (!print && !Session.IsAllowed(RoleConstants.PRINT_KOT))
return;
if ((_billInfo != null) && (VoucherBI.IsBillPrinted(_billInfo.VoucherID)) &&
(!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL)))
return;
if (bill.Count == 1) //new kot only
return;
if (print)
ShowDiscount();
int? saved;
if (_billInfo == null)
saved = InsertVoucher(print, waiterID, tableID);
else
saved = UpdateSale(print, waiterID, tableID);
if (_editVoucherID.HasValue)
_saleForm.CloseWindow();
else
{
int kotID = 0;
if (!print && saved.HasValue)
kotID = saved.Value;
if (print || kotID != 0)
PrintBill(_billInfo.VoucherID, kotID);
}
ClearBill();
}
private int? InsertVoucher(bool finalBill, int waiterID, string tableID)
{
if (_billInfo != null)
{
MessageBox.Show("Error in InsertVoucher, there is a previous sale in memory", "Error");
return null;
}
#region Voucher
_billInfo = new Voucher
{
Customer = _customer,
//Paid = finalBill,
TableID = tableID,
Waiter = WaiterBI.GetWaiter(waiterID),
Printed = finalBill,
Void = false,
Date = DateTime.Now,
Narration = "",
User = Session.User
};
#endregion
#region Inventories
Kot kot = GetKotForBill();
if (kot != null)
_billInfo.Kots.Add(kot);
#endregion
return VoucherBI.Insert(_billInfo);
}
private int? UpdateSale(bool finalBill, int waiterID, string tableID)
{
#region Voucher
_billInfo.User = Session.User;
_billInfo.Customer = _customer;
if (!_billInfo.Printed && finalBill)
_billInfo.Date = null;
_billInfo.Printed = _billInfo.Printed || finalBill;
_billInfo.TableID = tableID;
_billInfo.Waiter = WaiterBI.GetWaiter(waiterID);
Kot kot = GetKotForBill();
if (kot != null)
_billInfo.Kots.Add(kot);
#endregion
#region Inventory
#endregion
return VoucherBI.Update(_billInfo);
}
private Kot GetKotForBill()
{
var kot = new Kot();
foreach (var item in bill)
{
if (item.Key.KotID == -1 || item.Value.Quantity == 0)
continue;
else if (item.Key.KotID != 0)
{
Kot oldKot = _billInfo.Kots.Where(x => x.KotID == item.Key.KotID).Single();
Inventory inv = oldKot.Inventories.Where(x => x.Product.ProductID == item.Key.ProductID).Single();
inv.Rate = item.Value.Price;
inv.Discount = item.Value.Discount;
}
else
{
var temp = new Inventory();
temp.Product = ProductBI.GetProduct(item.Key.ProductID);
temp.Quantity = item.Value.Quantity;
temp.Rate = item.Value.Price;
temp.Discount = item.Value.Discount;
temp.ServiceCharge = item.Value.ServiceCharge;
temp.Tax = item.Value.Tax;
foreach (Modifier mod in item.Value.Modifiers)
temp.InventoryModifier.Add(new InventoryModifier { Modifier = mod });
kot.Inventories.Add(temp);
}
}
if (kot.Inventories.Count == 0)
return null;
else
return kot;
}
#endregion
}
}
}

@ -3,8 +3,8 @@ using System.Windows.Forms;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.PointOfSale.Sales;
using Tanshu.Accounts.Repository;
using System.Collections.Generic;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
@ -16,20 +16,20 @@ namespace Tanshu.Accounts.PointOfSale
InitializeComponent();
}
User form_userEvent(object sender, UserEventArgs e)
private User form_userEvent(object sender, UserEventArgs e)
{
User user = e.User;
if (user == null)
{
using (UserForm form = new UserForm(null))
using (var form = new UserForm(null))
{
form.ShowDialog();
}
}
else
{
using (UserForm form = new UserForm(user.UserID))
using (var form = new UserForm(user.UserID))
{
form.ShowDialog();
}
@ -42,19 +42,19 @@ namespace Tanshu.Accounts.PointOfSale
{
LoginUser(true);
}
private void btnSale_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.SALES))
using (SalesForm frmSale = new SalesForm(new BillController(null)))
using (var frmSale = new SalesForm(new BillController(null)))
frmSale.ShowDialog();
}
private void btnProduct_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.PRODUCTS))
using (ProductsForm frm = new ProductsForm())
using (var frm = new ProductsForm())
frm.ShowDialog();
}
private void btnProductGroup_Click(object sender, EventArgs e)
@ -62,16 +62,14 @@ namespace Tanshu.Accounts.PointOfSale
if (Session.IsAllowed(RoleConstants.PRODUCTS))
using (var frm = new ProductTypes())
frm.ShowDialog();
}
private void btnCustomer_Click(object sender, EventArgs e)
{
using (CustomersForm Customer = new CustomersForm(null, ""))
using (var Customer = new CustomersForm(null, ""))
{
Customer.ShowDialog();
}
}
private void btnInitial_Click(object sender, EventArgs e)
@ -88,29 +86,28 @@ namespace Tanshu.Accounts.PointOfSale
private void btnAdvanceReceive_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.SALES))
using (frmRecieveAdvance frm = new frmRecieveAdvance())
using (var frm = new frmRecieveAdvance())
frm.ShowDialog();
}
private void btnAdvanceAdjust_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.SALES))
using (frmAdjustAdvance frm = new frmAdjustAdvance())
using (var frm = new frmAdjustAdvance())
frm.ShowDialog();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
Close();
}
private void btnCreateUser_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.SECURITY_MANAGE_ROLES))
using (SelectUser form = new SelectUser(UserBI.GetFilteredUsers, true))
using (var form = new SelectUser(UserBI.GetFilteredUsers, true))
{
form.userEvent += new UserEventHandler(form_userEvent);
form.userEvent += form_userEvent;
form.ShowDialog();
}
}
@ -124,29 +121,28 @@ namespace Tanshu.Accounts.PointOfSale
private void btnChangePassword_Click(object sender, EventArgs e)
{
using (ChangePassword frm = new ChangePassword(new KeyboardControl()))
using (var frm = new ChangePassword(new KeyboardControl()))
frm.ShowDialog();
}
private void btnCashierCheckout_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.CASHIER_CHECKOUT))
using (Cashier_Checkout_Form frm = new Cashier_Checkout_Form())
using (var frm = new CashierCheckoutForm())
frm.ShowDialog();
}
private void btnSaleAnalysis_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.SALE_ANALYSIS))
using (frmSaleAnalysisForm frm = new frmSaleAnalysisForm())
using (var frm = new frmSaleAnalysisForm())
frm.ShowDialog();
}
private void btnSaleDetail_Click(object sender, EventArgs e)
{
if (Session.IsAllowed(RoleConstants.SALE_DETAIL))
using (var frm = new frmSaleDetail())
using (var frm = new FrmSaleDetail())
frm.ShowDialog();
}
@ -154,6 +150,7 @@ namespace Tanshu.Accounts.PointOfSale
{
CheckRoles();
}
private void CheckRoles()
{
#if (DEBUG)
@ -190,13 +187,13 @@ namespace Tanshu.Accounts.PointOfSale
if (Session.IsAllowed(RoleConstants.SECURITY_MANAGE_ROLES))
using (var frm = new AssignGroupRoles())
frm.ShowDialog();
}
private void btnSwipeLogin_Click(object sender, EventArgs e)
{
LoginUser(false);
}
private void LoginUser(bool keyboard)
{
ILogin login;
@ -209,7 +206,7 @@ namespace Tanshu.Accounts.PointOfSale
{
if (login.LoginUser())
{
this.Text = "Main Menu - User: " + Session.User.Name;
Text = "Main Menu - User: " + Session.User.Name;
btnLogin.Text = "Logout";
btnSwipeLogin.Visible = false;
}
@ -217,13 +214,11 @@ namespace Tanshu.Accounts.PointOfSale
else
{
login.LogoutUser();
this.Text = "Main Menu - Login";
Text = "Main Menu - Login";
btnLogin.Text = "Login";
btnSwipeLogin.Visible = true;
}
CheckRoles();
}
}
}
}

@ -1,6 +1,6 @@
namespace Tanshu.Accounts.PointOfSale
{
partial class Cashier_Checkout_Form
partial class CashierCheckoutForm
{
/// <summary>
/// Required designer variable.
@ -486,7 +486,7 @@
this.Controls.Add(this.txtReceipts);
this.Controls.Add(this.txtOpening);
this.MaximizeBox = false;
this.Name = "Cashier_Checkout_Form";
this.Name = "CashierCheckoutForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Cashier Checkout Form";
this.Load += new System.EventHandler(this.Cashier_Checkout_Form_Load);

@ -6,14 +6,14 @@ using Tanshu.Accounts.Helpers;
namespace Tanshu.Accounts.PointOfSale
{
public partial class Cashier_Checkout_Form : Form
public partial class CashierCheckoutForm : Form
{
CheckoutBI coProxy;
bool loading;
CheckoutBI _coProxy;
bool _loading;
//private static readonly Tanshu.Logging.SqlLogger log = new Tanshu.Logging.SqlLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public Cashier_Checkout_Form()
public CashierCheckoutForm()
{
loading = true;
_loading = true;
InitializeComponent();
}
@ -21,19 +21,19 @@ namespace Tanshu.Accounts.PointOfSale
{
dtpStart.Format = DateTimePickerFormat.Custom;
dtpStart.CustomFormat = "dd-MMM-yyyy";
dtpStart.Value = DateTime.Now;
dtpStart.Value = DateTime.Now.Date;
dtpFinish.Format = DateTimePickerFormat.Custom;
dtpFinish.CustomFormat = "dd-MMM-yyyy";
dtpFinish.Value = DateTime.Now;
dtpFinish.Value = DateTime.Now.Date;
FillUsers();
loading = false;
_loading = false;
}
private void FillUsers()
{
cmbCashier.DisplayMember = "Name";
cmbCashier.ValueMember = "UserID";
cmbCashier.DataSource = UserBI.GetUsers();
cmbCashier.DataSource = UserBI.ListActive(dtpStart.Value.Date.AddHours(7), dtpFinish.Value.Date.AddDays(1).AddHours(7));
}
private void cmbCashier_SelectedIndexChanged(object sender, EventArgs e)
@ -44,24 +44,24 @@ namespace Tanshu.Accounts.PointOfSale
private void EmployeeStatus()
{
if (loading || cmbCashier.SelectedValue == null)
if (_loading || cmbCashier.SelectedValue == null)
return;
coProxy = new CheckoutBI((int)cmbCashier.SelectedValue, dtpStart.Value, dtpFinish.Value);
txtOpening.Text = string.Format("{0:#,##0.00}", coProxy);
txtReceipts.Text = string.Format("{0:#,##0.00}", coProxy.Receipts);
txtAdvanceReceived.Text = string.Format("{0:#,##0.00}", coProxy.AdvanceReceipts);
txtCCReceipts.Text = string.Format("{0:#,##0.00}", coProxy.CCReceipts);
txtNC.Text = string.Format("{0:#,##0.00}", coProxy.NCReceipts);
txtBillToCompany.Text = string.Format("{0:#,##0.00}", coProxy.BTCReceipts);
txtAdvanceAdjusted.Text = string.Format("{0:#,##0.00}", coProxy.AdvanceAdjusted);
txtPayments.Text = string.Format("{0:#,##0.00}", coProxy.CashPayments);
txtAdditionalVoids.Text = string.Format("{0:#,##0.00}", coProxy.AdditionalVoids);
txtVoidsInSystem.Text = string.Format("{0:#,##0.00}", coProxy.VoidsInSystem);
txtDiscounts.Text = string.Format("{0:#,##0.00}", coProxy.Discount);
txtPending.Text = string.Format("{0:#,##0.00}", coProxy.PendingBills);
txtSales.Text = string.Format("{0:#,##0.00}", coProxy.NetSales);
txtClosingCash.Text = string.Format("{0:#,##0.00}", coProxy.ClosingBalance);
txtStatus.Text = coProxy.Status;
_coProxy = new CheckoutBI((int)cmbCashier.SelectedValue, dtpStart.Value, dtpFinish.Value);
txtOpening.Text = string.Format("{0:#,##0.00}", _coProxy);
txtReceipts.Text = string.Format("{0:#,##0.00}", _coProxy.Receipts);
txtAdvanceReceived.Text = string.Format("{0:#,##0.00}", _coProxy.AdvanceReceipts);
txtCCReceipts.Text = string.Format("{0:#,##0.00}", _coProxy.CcReceipts);
txtNC.Text = string.Format("{0:#,##0.00}", _coProxy.NcReceipts);
txtBillToCompany.Text = string.Format("{0:#,##0.00}", _coProxy.BtcReceipts);
txtAdvanceAdjusted.Text = string.Format("{0:#,##0.00}", _coProxy.AdvanceAdjusted);
txtPayments.Text = string.Format("{0:#,##0.00}", _coProxy.CashPayments);
txtAdditionalVoids.Text = string.Format("{0:#,##0.00}", _coProxy.AdditionalVoids);
txtVoidsInSystem.Text = string.Format("{0:#,##0.00}", _coProxy.VoidsInSystem);
txtDiscounts.Text = string.Format("{0:#,##0.00}", _coProxy.Discount);
txtPending.Text = string.Format("{0:#,##0.00}", _coProxy.PendingBills);
txtSales.Text = string.Format("{0:#,##0.00}", _coProxy.NetSales);
txtClosingCash.Text = string.Format("{0:#,##0.00}", _coProxy.ClosingBalance);
txtStatus.Text = _coProxy.Status;
}
private void dtpStart_ValueChanged(object sender, EventArgs e)
@ -80,13 +80,13 @@ namespace Tanshu.Accounts.PointOfSale
if (!decimal.TryParse(txtDeposited.Text, out deposited))
deposited = 0;
coProxy.Calculate(deposited, 0);
txtStatus.Text = coProxy.Status;
_coProxy.Calculate(deposited, 0);
txtStatus.Text = _coProxy.Status;
}
private void btnPrint_Click(object sender, EventArgs e)
{
Thermal.PrintClosing(coProxy);
Thermal.PrintClosing(_coProxy);
}
}
}

@ -8,14 +8,12 @@ using System.Linq;
namespace Tanshu.Accounts.PointOfSale
{
public partial class frmSaleDetail : Form
public partial class FrmSaleDetail : Form
{
IList<SalesAnalysisDetail> list;
//private static readonly Tanshu.Logging.SqlLogger log = new Tanshu.Logging.SqlLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public frmSaleDetail()
IList<SalesAnalysisDetail> _list;
public FrmSaleDetail()
{
InitializeComponent();
//log.Warn(string.Format("Sales Analysis by: {0}", Session.User.Name));
}
private void dtpStart_ValueChanged(object sender, EventArgs e)
@ -25,9 +23,9 @@ namespace Tanshu.Accounts.PointOfSale
private void ShowStatement()
{
list = new SalesAnalysisBI().GetSaleDetail(dtpStart.Value, dtpFinish.Value).ToList();
_list = new SalesAnalysisBI().GetSaleDetail(dtpStart.Value, dtpFinish.Value).ToList();
dgvSale.AutoGenerateColumns = true;
dgvSale.DataSource = list;
dgvSale.DataSource = _list;
dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dgvSale.Columns[1].DefaultCellStyle.Format = "#,##0.00;(#,##0.00);0";
dgvSale.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
@ -49,12 +47,11 @@ namespace Tanshu.Accounts.PointOfSale
private void btnPrint_Click(object sender, EventArgs e)
{
if (list != null)
{
var startDate = dtpStart.Value.Date.AddHours(6);
var finishDate = dtpFinish.Value.Date.AddDays(1).AddHours(5);
Accounts.Print.Thermal.PrintSale(Session.User.Name, list, startDate, finishDate);
}
if (_list == null)
return;
var startDate = dtpStart.Value.Date.AddHours(6);
var finishDate = dtpFinish.Value.Date.AddDays(1).AddHours(5);
Print.Thermal.PrintSale(Session.User.Name, _list, startDate, finishDate);
}
}
}

@ -1,6 +1,6 @@
namespace Tanshu.Accounts.PointOfSale
{
partial class frmSaleDetail
partial class FrmSaleDetail
{
/// <summary>
/// Required designer variable.
@ -107,7 +107,7 @@
this.Controls.Add(this.dtpStart);
this.Controls.Add(this.label10);
this.MaximizeBox = false;
this.Name = "frmSaleDetail";
this.Name = "FrmSaleDetail";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Sale Detail";
this.Load += new System.EventHandler(this.Sale_Analysis_Form_Load);

@ -1,101 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanshu.Common;
using Tanshu.Accounts.Contracts;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Entities;
using Tanshu.Common;
namespace Tanshu.Accounts.PointOfSale
namespace Tanshu.Accounts.PointOfSale.Sales
{
public class BillHelperFunctions
{
BindingSource bindingSource;
OrderedDictionary<BillItemKey, BillInventory> bill;
BillItemKey newKey;
public BillHelperFunctions(BindingSource bindingSource, OrderedDictionary<BillItemKey, BillInventory> bill, int productID)
private readonly OrderedDictionary<BillItemKey, BillInventory> bill;
private readonly BindingSource _bindingSource;
private readonly BillItemKey _newKey;
public BillHelperFunctions(BindingSource bindingSource, OrderedDictionary<BillItemKey, BillInventory> bill,
int productID)
{
this.bindingSource = bindingSource;
this._bindingSource = bindingSource;
this.bill = bill;
this.newKey = new BillItemKey(productID, 0);
_newKey = new BillItemKey(productID, 0);
}
public void SetDiscount(string name, decimal discount)
{
if (discount > 1 || discount < 0)
return;
decimal maxDiscount = VoucherBI.GetProductDiscountLimit(newKey.ProductID);
decimal maxDiscount = VoucherBI.GetProductDiscountLimit(_newKey.ProductID);
if (discount > maxDiscount)
MessageBox.Show(string.Format("Maximum discount for {0} is {1:P}", name, maxDiscount), "Excessive Discount", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show(string.Format("Maximum discount for {0} is {1:P}", name, maxDiscount),
"Excessive Discount", MessageBoxButtons.OK, MessageBoxIcon.Warning);
foreach (var item in bill)
{
if (item.Value.ProductID == newKey.ProductID)
if (item.Value.ProductID == _newKey.ProductID)
item.Value.Discount = discount;
}
}
#region Add Product
public BillInventory AddProduct()
{
BillInventory product;
if (bill.ContainsKey(newKey))
{
bindingSource.CurrencyManager.Position = bill.IndexOfKey(newKey);
product = bill[newKey];
product.Quantity += 1;
}
else
{ //Has only old
product = VoucherBI.GetDefaultSaleBillItem(newKey.ProductID);
foreach (var item in bill)
{
if (item.Key.ProductID == newKey.ProductID)
{
product.Discount = item.Value.Discount;
product.Price = item.Value.Price;
}
}
product = AddProduct(product);
}
return product;
}
private BillInventory AddProduct(BillInventory product)
{
bill.Add(new BillItemKey(product.ProductID, 0), product);
bindingSource.DataSource = bill.Values;
bindingSource.CurrencyManager.Position = bindingSource.CurrencyManager.Count + 1;
return product;
}
#endregion
#region Quantity
public void SetQuantity(BillInventory product, decimal quantity, bool prompt)
{
if (product.Printed)
return;
if (prompt && !GetInput("Price", ref quantity))
return;
if (!prompt)
quantity += product.Quantity;
SetQuantity(product, quantity);
}
private void SetQuantity(BillInventory product, decimal quantity)
{
if (quantity < 0 && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_PRODUCT))
return;
var total = quantity;
foreach (var item in bill)
{
if (item.Value.ProductID == newKey.ProductID)
total += item.Value.Quantity;
}
if (total < 0)
quantity -= total;
product.Quantity = quantity;
}
#endregion
public void SetPrice(BillInventory product)
{
if (!Allowed(product, RoleConstants.CHANGE_RATE))
@ -107,13 +46,15 @@ namespace Tanshu.Accounts.PointOfSale
return;
foreach (var item in bill)
{
if (item.Value.ProductID == newKey.ProductID)
if (item.Value.ProductID == _newKey.ProductID)
item.Value.Price = rate;
}
}
private void InputBox_Validating(object sender, InputBoxValidatingArgs e)
{
}
private bool Allowed(BillInventory item, RoleConstants role)
{
if (item == null)
@ -122,6 +63,7 @@ namespace Tanshu.Accounts.PointOfSale
return false;
return true;
}
private bool GetInput(string prompt, ref decimal amount)
{
InputBoxResult result = InputBox.Show(prompt, amount.ToString(), InputBox_Validating);
@ -131,5 +73,70 @@ namespace Tanshu.Accounts.PointOfSale
return false;
return true;
}
#region Add Product
public BillInventory AddProduct()
{
BillInventory product;
if (bill.ContainsKey(_newKey))
{
_bindingSource.CurrencyManager.Position = bill.IndexOfKey(_newKey);
product = bill[_newKey];
product.Quantity += 1;
}
else
{
//Has only old
product = VoucherBI.GetDefaultSaleBillItem(_newKey.ProductID);
foreach (var item in bill)
{
if (item.Key.ProductID == _newKey.ProductID)
{
product.Discount = item.Value.Discount;
product.Price = item.Value.Price;
}
}
product = AddProduct(product);
}
return product;
}
private BillInventory AddProduct(BillInventory product)
{
bill.Add(new BillItemKey(product.ProductID, 0), product);
_bindingSource.DataSource = bill.Values.ToList();
_bindingSource.CurrencyManager.Position = _bindingSource.CurrencyManager.Count - 1;
return product;
}
#endregion
#region Quantity
public void SetQuantity(BillInventory product, decimal quantity, bool prompt)
{
if (product.Printed)
return;
if (prompt && !GetInput("Price", ref quantity))
return;
if (!prompt)
quantity += product.Quantity;
SetQuantity(product, quantity);
}
private void SetQuantity(BillInventory product, decimal quantity)
{
if (quantity < 0 && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_PRODUCT))
return;
var total = quantity + bill.Where(item => item.Value.ProductID == _newKey.ProductID).Sum(item => item.Value.Quantity);
if (total < 0)
quantity -= total;
product.Quantity = quantity;
}
#endregion
}
}
}

@ -1,129 +0,0 @@
namespace Tanshu.Accounts.PointOfSale
{
partial class BillSettleForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnCash = new System.Windows.Forms.Button();
this.btnCreditCard = new System.Windows.Forms.Button();
this.btnNC = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.btnStaff = new System.Windows.Forms.Button();
this.btnBillToCompany = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnCash
//
this.btnCash.Location = new System.Drawing.Point(12, 12);
this.btnCash.Name = "btnCash";
this.btnCash.Size = new System.Drawing.Size(75, 75);
this.btnCash.TabIndex = 0;
this.btnCash.Text = "Cash";
this.btnCash.UseVisualStyleBackColor = true;
this.btnCash.Click += new System.EventHandler(this.btnCash_Click);
//
// btnCreditCard
//
this.btnCreditCard.Location = new System.Drawing.Point(93, 12);
this.btnCreditCard.Name = "btnCreditCard";
this.btnCreditCard.Size = new System.Drawing.Size(75, 75);
this.btnCreditCard.TabIndex = 1;
this.btnCreditCard.Text = "Credit Card";
this.btnCreditCard.UseVisualStyleBackColor = true;
this.btnCreditCard.Click += new System.EventHandler(this.btnCreditCard_Click);
//
// btnNC
//
this.btnNC.Location = new System.Drawing.Point(174, 12);
this.btnNC.Name = "btnNC";
this.btnNC.Size = new System.Drawing.Size(75, 75);
this.btnNC.TabIndex = 2;
this.btnNC.Text = "No Charge";
this.btnNC.UseVisualStyleBackColor = true;
this.btnNC.Click += new System.EventHandler(this.btnNC_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(417, 12);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 75);
this.btnCancel.TabIndex = 3;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnStaff
//
this.btnStaff.Location = new System.Drawing.Point(255, 12);
this.btnStaff.Name = "btnStaff";
this.btnStaff.Size = new System.Drawing.Size(75, 75);
this.btnStaff.TabIndex = 4;
this.btnStaff.Text = "Staff";
this.btnStaff.UseVisualStyleBackColor = true;
this.btnStaff.Click += new System.EventHandler(this.btnStaff_Click);
//
// btnBillToCompany
//
this.btnBillToCompany.Location = new System.Drawing.Point(336, 12);
this.btnBillToCompany.Name = "btnBillToCompany";
this.btnBillToCompany.Size = new System.Drawing.Size(75, 75);
this.btnBillToCompany.TabIndex = 5;
this.btnBillToCompany.Text = "Bill To Company";
this.btnBillToCompany.UseVisualStyleBackColor = true;
this.btnBillToCompany.Click += new System.EventHandler(this.btnBillToCompany_Click);
//
// BillSettleForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(504, 99);
this.ControlBox = false;
this.Controls.Add(this.btnBillToCompany);
this.Controls.Add(this.btnStaff);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnNC);
this.Controls.Add(this.btnCreditCard);
this.Controls.Add(this.btnCash);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.Name = "BillSettleForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Settle Bill";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnCash;
private System.Windows.Forms.Button btnCreditCard;
private System.Windows.Forms.Button btnNC;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnStaff;
private System.Windows.Forms.Button btnBillToCompany;
}
}

@ -1,65 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.SqlDAO;
namespace Tanshu.Accounts.PointOfSale
{
public partial class BillSettleForm : Form
{
private SettleOption settleOption = SettleOption.Unsettled;
public BillSettleForm()
{
InitializeComponent();
}
private void btnCash_Click(object sender, EventArgs e)
{
settleOption = SettleOption.Cash;
this.Close();
}
private void btnCreditCard_Click(object sender, EventArgs e)
{
settleOption = SettleOption.CreditCard;
this.Close();
}
private void btnNC_Click(object sender, EventArgs e)
{
settleOption = SettleOption.NoCharge;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
settleOption = SettleOption.Unsettled;
this.Close();
}
private void btnStaff_Click(object sender, EventArgs e)
{
settleOption = SettleOption.Staff;
this.Close();
}
private void btnBillToCompany_Click(object sender, EventArgs e)
{
settleOption = SettleOption.BillToCompany;
this.Close();
}
public SettleOption optionChosen
{
get
{
return settleOption;
}
}
}
}

@ -0,0 +1,80 @@
namespace Tanshu.Accounts.PointOfSale
{
partial class FrmSettleAmounts
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txtAmount = new System.Windows.Forms.TextBox();
this.txtCurrentAmount = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// txtAmount
//
this.txtAmount.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtAmount.Location = new System.Drawing.Point(3, 3);
this.txtAmount.Name = "txtAmount";
this.txtAmount.ReadOnly = true;
this.txtAmount.Size = new System.Drawing.Size(173, 20);
this.txtAmount.TabIndex = 1;
//
// txtCurrentAmount
//
this.txtCurrentAmount.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtCurrentAmount.Location = new System.Drawing.Point(3, 26);
this.txtCurrentAmount.Name = "txtCurrentAmount";
this.txtCurrentAmount.Size = new System.Drawing.Size(173, 20);
this.txtCurrentAmount.TabIndex = 0;
this.txtCurrentAmount.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TxtCurrentAmountKeyDown);
//
// FrmSettleAmounts
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(179, 249);
this.ControlBox = false;
this.Controls.Add(this.txtCurrentAmount);
this.Controls.Add(this.txtAmount);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.Name = "FrmSettleAmounts";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Settle Bill";
this.Load += new System.EventHandler(this.SettleChoicesFormLoad);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtAmount;
private System.Windows.Forms.TextBox txtCurrentAmount;
}
}

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Contracts;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
{
public partial class FrmSettleAmounts : Form
{
private IKeyboardControl _keyboardControl;
private readonly decimal _amount;
private readonly SettleOption _settleOption;
private decimal _settleAmount;
public FrmSettleAmounts(IKeyboardControl keyboardControl, SettleOption settleOption, decimal amount)
{
InitializeComponent();
_keyboardControl = keyboardControl;
_amount = amount;
_settleOption = settleOption;
_settleAmount = 0;
var control = keyboardControl as UserControl;
if (control != null)
{
control.Location = new System.Drawing.Point(3, 49);
this.Controls.Add(control);
this.Size = this.SizeFromClientSize(new Size(3 + control.Width + 3, 49 + control.Height + 3));
}
}
public decimal AmountSettled
{
get
{
return _settleAmount;
}
}
private void SettleChoicesFormLoad(object sender, EventArgs e)
{
var attribute = (DisplayAttribute)_settleOption.GetType().GetField(_settleOption.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false)[0];
this.Text = attribute.Name;
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", _amount);
txtCurrentAmount.Text = string.Format("{0:#,#00}", _amount);
txtCurrentAmount.Focus();
}
private void TxtCurrentAmountKeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Escape:
_settleAmount = 0;
this.Close();
break;
case Keys.Return:
{
decimal settleAmount;
if (!Decimal.TryParse(txtCurrentAmount.Text, out settleAmount))
return;
if (settleAmount > _amount)
settleAmount = _amount;
_settleAmount = settleAmount;
this.Close();
}
break;
}
}
}
}

@ -1,4 +1,4 @@
namespace Tanshu.Accounts.PointOfSale
namespace Tanshu.Accounts.PointOfSale.Sales
{
partial class SalesForm
{
@ -666,6 +666,7 @@
private System.Windows.Forms.DataGridViewTextBoxColumn printedDataGridViewTextBoxColumn;
private System.Windows.Forms.Button btnMore;
private System.Windows.Forms.Button btnMoveKot;
private readonly BillController _billController;
}
}

@ -1,34 +1,63 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Helpers;
using Tanshu.Common;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.Repository;
using Tanshu.Common;
namespace Tanshu.Accounts.PointOfSale
namespace Tanshu.Accounts.PointOfSale.Sales
{
public partial class SalesForm : Form, ISaleForm
{
BillController billController;
public SalesForm(BillController billController)
{
InitializeComponent();
this.billController = billController;
this._billController = billController;
billController.InitGui(this);
}
#region ISaleForm Members
public void SetUserName(string name)
{
this.Text = name;
Text = name;
}
public void SetCustomerDisplay(string name)
{
btnCustomer.Text = name;
}
public void ShowInfo(string billID, string kotID, DateTime creationDate, DateTime date, DateTime lastEditDate,
string customer, string tableID, int waiterID, string waiter)
{
txtBillID.Text = billID;
txtKotID.Text = kotID;
txtCreationDate.Text = creationDate.ToString("HH:mm dd-MMM-yyyy");
txtDate.Text = date.ToString("HH:mm dd-MMM-yyyy");
txtLastEditDate.Text = lastEditDate.ToString("HH:mm dd-MMM-yyyy");
btnCustomer.Text = customer;
txtTableID.Text = tableID;
btnWaiter.Tag = waiterID;
btnWaiter.Text = string.Format("{0} - F5", waiter);
}
public BindingSource BindingSource
{
get { return bindingSource; }
}
public void CloseWindow()
{
Close();
}
#endregion
private void SalesForm_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
@ -46,7 +75,7 @@ namespace Tanshu.Accounts.PointOfSale
case Keys.F4:
{
if (!e.Alt)
billController.ShowCustomerList(false);
_billController.ShowCustomerList(false);
break;
}
case Keys.F5:
@ -56,17 +85,17 @@ namespace Tanshu.Accounts.PointOfSale
}
case Keys.F7:
{
using (SelectProduct selectProduct = new SelectProduct(ProductBI.GetFilteredProducts, true))
using (var selectProduct = new SelectProduct(ProductBI.GetFilteredProducts, true))
{
selectProduct.ShowDialog();
if (selectProduct.SelectedItem != null)
billController.AddProductToGrid(selectProduct.SelectedItem.ProductID);
_billController.AddProductToGrid(selectProduct.SelectedItem.ProductID);
}
break;
}
case Keys.F8:
{
billController.LoadBillFromTable(null);
_billController.LoadBillFromTable(null);
break;
}
case Keys.F11:
@ -81,17 +110,17 @@ namespace Tanshu.Accounts.PointOfSale
}
case Keys.Delete:
{
billController.ProductRemove();
_billController.ProductRemove();
break;
}
case Keys.Add:
{
billController.SetQuantity(1, false);
_billController.SetQuantity(1, false);
break;
}
case Keys.Subtract:
{
billController.SetQuantity(-1, false);
_billController.SetQuantity(-1, false);
break;
}
case Keys.Up:
@ -108,207 +137,49 @@ namespace Tanshu.Accounts.PointOfSale
}
case Keys.Escape:
{
billController.CancelBillChanges();
_billController.CancelBillChanges();
break;
}
}
}
#region Helper Functions
public void ClearBill(OrderedDictionary<BillItemKey, BillInventory> bill)
{
this.txtBillID.Text = "";
this.txtKotID.Text = "";
this.txtCreationDate.Text = "";
this.txtDate.Text = "";
this.txtLastEditDate.Text = "";
this.txtTableID.Text = "";
this.btnWaiter.Text = "Waiter - F5";
this.btnWaiter.Tag = null;
txtGrossTax.Text = "0.00";
txtDiscount.Text = "0.00";
txtServiceCharge.Text = "0.00";
txtGrossAmount.Text = "0.00";
txtAmount.Text = "0.00";
bindingSource.DataSource = bill.Values;
MoreButton(false);
ChangeFormState(SaleFormState.Waiting);
}
private void ChangeFormState(SaleFormState state)
{
flpGroup.Controls.Clear();
flpMain.Controls.Clear();
if (state == SaleFormState.Billing)
{
var list = new ProductGroupBI().GetProductGroups();
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), 0, list, new ButtonClickDelegate(productTypeButton_Click));
}
else
{
ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), 0, new FoodTableBI().List(), new ButtonClickDelegate(tableButton_Click));
}
}
private void productTypeButton_Click(object sender, EventArgs e)
{
Button button = sender as Button;
if (button == null)
return;
var item = button.Tag as ProductGroup;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.ProductGroupID;
if (start < 0)
start = 0;
var list = new ProductGroupBI().GetProductGroups();
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), start, list, new ButtonClickDelegate(productTypeButton_Click));
}
else
{
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), 0, ProductBI.GetProducts(item.ProductGroupID), new ButtonClickDelegate(productButton_Click));
}
}
private void productButton_Click(object sender, EventArgs e)
{
Button button = sender as Button;
if (button == null)
return;
var item = button.Tag as Product;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.ProductID;
if (start < 0)
start = 0;
var list = ProductBI.GetProducts();
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), start, list, new ButtonClickDelegate(productButton_Click));
}
else
{
billController.AddProductToGrid(item.ProductID);
}
}
private void tableButton_Click(object sender, EventArgs e)
{
Button button = sender as Button;
if (button == null)
return;
var item = button.Tag as FoodTable;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.FoodTableID;
if (start < 0)
start = 0;
var list = new FoodTableBI().List();
ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), start, list, new ButtonClickDelegate(tableButton_Click));
}
else
{
string tableName = item.Name;
billController.LoadBillFromTable(tableName);
txtTableID.Text = tableName;
ChangeFormState(SaleFormState.Billing);
}
}
public void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount, decimal taxAmount, decimal valueAmount, List<BillInventory> bill)
{
txtGrossTax.Text = string.Format("{0:#0.00}", taxAmount);
txtDiscount.Text = string.Format("{0:#0.00}", discountAmount);
txtServiceCharge.Text = string.Format("{0:#0.00}", serviceChargeAmount);
txtGrossAmount.Text = string.Format("{0:#0.00}", grossAmount);
txtAmount.Text = string.Format("{0:#0.00}", Math.Round(valueAmount));
bindingSource.DataSource = bill;
dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
}
private void btnPrintBill_Click(object sender, EventArgs e)
{
if (btnWaiter.Tag == null)
btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
billController.Save(true, (int)btnWaiter.Tag, txtTableID.Text);
}
private void btnPrintKot_Click(object sender, EventArgs e)
{
if (btnWaiter.Tag == null)
btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
billController.Save(false, (int)btnWaiter.Tag, txtTableID.Text);
}
private void btnCancel_Click(object sender, EventArgs e)
{
billController.CancelBillChanges();
}
private void btnQuantity_Click(object sender, EventArgs e)
{
billController.SetQuantity(0, true);
}
private void btnDiscount_Click(object sender, EventArgs e)
{
billController.ShowDiscount();
//if (dgvProducts.Rows.Count > 0)
// billController.SetDiscount(billController.CurrentProduct, -1);
}
#endregion
private void SalesForm_Load(object sender, EventArgs e)
{
billController.FormLoad();
_billController.FormLoad();
ChangeFormState(SaleFormState.Waiting);
}
private void btnCustomer_Click(object sender, EventArgs e)
{
billController.ShowCustomerList(false);
_billController.ShowCustomerList(false);
}
public void SetCustomerDisplay(string name)
{
btnCustomer.Text = name;
}
public void ShowInfo(string billID, string kotID, DateTime creationDate, DateTime date, DateTime lastEditDate, string customer, string tableID, int waiterID, string waiter)
{
this.txtBillID.Text = billID;
this.txtKotID.Text = kotID;
this.txtCreationDate.Text = creationDate.ToString("HH:mm dd-MMM-yyyy");
this.txtDate.Text = date.ToString("HH:mm dd-MMM-yyyy");
this.txtLastEditDate.Text = lastEditDate.ToString("HH:mm dd-MMM-yyyy");
this.btnCustomer.Text = customer;
this.txtTableID.Text = tableID;
this.btnWaiter.Tag = waiterID;
this.btnWaiter.Text = string.Format("{0} - F5", waiter);
}
public BindingSource BindingSource
{
get
{
return bindingSource;
}
}
private void btnVoid_Click(object sender, EventArgs e)
{
try
{
billController.VoidBill();
_billController.VoidBill();
}
catch (PermissionException ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnRate_Click(object sender, EventArgs e)
{
billController.ChangeRate();
_billController.ChangeRate();
}
private void btnClear_Click(object sender, EventArgs e)
{
billController.CancelBillChanges();
_billController.CancelBillChanges();
}
private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataGridView dgv = sender as DataGridView;
BillInventory data = dgv.Rows[e.RowIndex].DataBoundItem as BillInventory;
var dgv = sender as DataGridView;
var data = dgv.Rows[e.RowIndex].DataBoundItem as BillInventory;
if (data.Tax == -1)
{
@ -329,9 +200,9 @@ namespace Tanshu.Accounts.PointOfSale
private void btnWaiter_Click(object sender, EventArgs e)
{
using (SelectWaiter selectWaiter = new SelectWaiter(WaiterBI.GetFilteredWaiters, true))
using (var selectWaiter = new SelectWaiter(WaiterBI.GetFilteredWaiters, true))
{
selectWaiter.waiterEvent += new WaiterEventHandler(selectWaiter_waiterEvent);
selectWaiter.waiterEvent += selectWaiter_waiterEvent;
selectWaiter.ShowDialog();
if (selectWaiter.SelectedItem != null)
{
@ -345,7 +216,8 @@ namespace Tanshu.Accounts.PointOfSale
}
}
}
Waiter selectWaiter_waiterEvent(object sender, WaiterEventArgs e)
private Waiter selectWaiter_waiterEvent(object sender, WaiterEventArgs e)
{
Waiter waiter = e.Waiter;
if (!Thread.CurrentPrincipal.IsInRole("Waiter/Master"))
@ -368,33 +240,29 @@ namespace Tanshu.Accounts.PointOfSale
throw new ArgumentException();
}
}
public void CloseWindow()
{
this.Close();
}
private void btnSettle_Click(object sender, EventArgs e)
{
billController.SettleBill();
_billController.SettleBill();
}
private void btnModifier_Click(object sender, EventArgs e)
{
var item = billController.CurrentProduct;
BillInventory item = _billController.CurrentProduct;
if (item == null)
return;
var id = new ProductGroupBI().GetProductGroupOfProduct(item.ProductID).ProductGroupID;
billController.ShowModifiers(id, item);
int id = new ProductGroupBI().GetProductGroupOfProduct(item.ProductID).ProductGroupID;
_billController.ShowModifiers(id, item);
}
private void btnDelete_Click(object sender, EventArgs e)
{
billController.SetQuantity(-1, false);
_billController.SetQuantity(-1, false);
}
private void btnMoveTable_Click(object sender, EventArgs e)
{
billController.MoveTable();
_billController.MoveTable();
}
private void btnMore_Click(object sender, EventArgs e)
@ -407,6 +275,7 @@ namespace Tanshu.Accounts.PointOfSale
else
throw new InvalidOperationException("Button State incorrect");
}
private void MoreButton(bool more)
{
btnMore.Text = more ? "Less" : "More";
@ -418,15 +287,159 @@ namespace Tanshu.Accounts.PointOfSale
btnMoveTable.Visible = more;
btnMoveKot.Visible = more;
btnVoid.Visible = more;
}
private void btnMoveKot_Click(object sender, EventArgs e)
{
billController.MergeKot();
_billController.MergeKot();
}
#region Helper Functions
public void ClearBill(OrderedDictionary<BillItemKey, BillInventory> bill)
{
txtBillID.Text = "";
txtKotID.Text = "";
txtCreationDate.Text = "";
txtDate.Text = "";
txtLastEditDate.Text = "";
txtTableID.Text = "";
btnWaiter.Text = "Waiter - F5";
btnWaiter.Tag = null;
txtGrossTax.Text = "0.00";
txtDiscount.Text = "0.00";
txtServiceCharge.Text = "0.00";
txtGrossAmount.Text = "0.00";
txtAmount.Text = "0.00";
bindingSource.DataSource = bill.Values;
MoreButton(false);
ChangeFormState(SaleFormState.Waiting);
}
public void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount,
decimal taxAmount, decimal valueAmount, List<BillInventory> bill)
{
txtGrossTax.Text = string.Format("{0:#0.00}", taxAmount);
txtDiscount.Text = string.Format("{0:#0.00}", discountAmount);
txtServiceCharge.Text = string.Format("{0:#0.00}", serviceChargeAmount);
txtGrossAmount.Text = string.Format("{0:#0.00}", grossAmount);
txtAmount.Text = string.Format("{0:#0.00}", Math.Round(valueAmount));
bindingSource.DataSource = bill;
dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
}
private void ChangeFormState(SaleFormState state)
{
flpGroup.Controls.Clear();
flpMain.Controls.Clear();
if (state == SaleFormState.Billing)
{
IList<ProductGroup> list = new ProductGroupBI().GetProductGroups();
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), 0, list, productTypeButton_Click);
}
else
{
ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), 0, new FoodTableBI().List(),
tableButton_Click);
}
}
private void productTypeButton_Click(object sender, EventArgs e)
{
var button = sender as Button;
if (button == null)
return;
var item = button.Tag as ProductGroup;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.ProductGroupID;
if (start < 0)
start = 0;
IList<ProductGroup> list = new ProductGroupBI().GetProductGroups();
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), start, list, productTypeButton_Click);
}
else
{
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), 0,
ProductBI.GetProducts(item.ProductGroupID), productButton_Click);
}
}
private void productButton_Click(object sender, EventArgs e)
{
var button = sender as Button;
if (button == null)
return;
var item = button.Tag as Product;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.ProductID;
if (start < 0)
start = 0;
IList<Product> list = ProductBI.GetProducts();
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), start, list, productButton_Click);
}
else
{
_billController.AddProductToGrid(item.ProductID);
}
}
private void tableButton_Click(object sender, EventArgs e)
{
var button = sender as Button;
if (button == null)
return;
var item = button.Tag as FoodTable;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.FoodTableID;
if (start < 0)
start = 0;
IList<FoodTable> list = new FoodTableBI().List();
ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), start, list, tableButton_Click);
}
else
{
string tableName = item.Name;
_billController.LoadBillFromTable(tableName);
txtTableID.Text = tableName;
ChangeFormState(SaleFormState.Billing);
}
}
private void btnPrintBill_Click(object sender, EventArgs e)
{
if (btnWaiter.Tag == null)
btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
_billController.Save(true, (int) btnWaiter.Tag, txtTableID.Text);
}
private void btnPrintKot_Click(object sender, EventArgs e)
{
if (btnWaiter.Tag == null)
btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
_billController.Save(false, (int) btnWaiter.Tag, txtTableID.Text);
}
private void btnCancel_Click(object sender, EventArgs e)
{
_billController.CancelBillChanges();
}
private void btnQuantity_Click(object sender, EventArgs e)
{
_billController.SetQuantity(0, true);
}
private void btnDiscount_Click(object sender, EventArgs e)
{
_billController.ShowDiscount();
//if (dgvProducts.Rows.Count > 0)
// billController.SetDiscount(billController.CurrentProduct, -1);
}
#endregion
}
}
}

@ -0,0 +1,78 @@
namespace Tanshu.Accounts.PointOfSale
{
partial class SettleChoicesForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txtAmount = new System.Windows.Forms.TextBox();
this.flpSettlement = new System.Windows.Forms.FlowLayoutPanel();
this.flpSettlement.SuspendLayout();
this.SuspendLayout();
//
// txtAmount
//
this.txtAmount.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.txtAmount.Location = new System.Drawing.Point(3, 3);
this.txtAmount.Name = "txtAmount";
this.txtAmount.ReadOnly = true;
this.txtAmount.Size = new System.Drawing.Size(598, 20);
this.txtAmount.TabIndex = 6;
//
// flpSettlement
//
this.flpSettlement.Controls.Add(this.txtAmount);
this.flpSettlement.Dock = System.Windows.Forms.DockStyle.Fill;
this.flpSettlement.Location = new System.Drawing.Point(0, 0);
this.flpSettlement.Name = "flpSettlement";
this.flpSettlement.Size = new System.Drawing.Size(604, 107);
this.flpSettlement.TabIndex = 7;
//
// SettleChoicesForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(604, 107);
this.ControlBox = false;
this.Controls.Add(this.flpSettlement);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.Name = "SettleChoicesForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Settle Bill";
this.Load += new System.EventHandler(this.SettleChoicesFormLoad);
this.flpSettlement.ResumeLayout(false);
this.flpSettlement.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TextBox txtAmount;
private System.Windows.Forms.FlowLayoutPanel flpSettlement;
}
}

@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Contracts;
using System.Linq;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
{
public partial class SettleChoicesForm : Form
{
private readonly IDictionary<Button, int> _list;
private decimal _amount;
public SettleChoicesForm(Voucher voucher)
{
InitializeComponent();
_amount = voucher.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount +
voucher.Settlements.Single(x => x.Settled == SettleOption.RoundOff).Amount;
_amount *= -1;
OptionsChosen = new Dictionary<SettleOption, decimal>();
_list = new Dictionary<Button, int>();
}
private void ButtonClick(object sender, EventArgs e)
{
var button = sender as Button;
if (button == null || button.Tag == null)
return;
if (button.Tag is SettleOption)
{
var settleOption = (SettleOption)button.Tag;
using (var frm = new FrmSettleAmounts(new NumpadControl(), settleOption, _amount))
{
frm.ShowDialog();
UpdateChoice(settleOption, frm.AmountSettled, _list[button]);
}
}
else
{
if ((string)button.Tag == "Cancel")
_optionsChosen.Clear();
this.Close();
}
}
private void UpdateChoice(SettleOption settleOption, decimal amount, int group)
{
var oldAmount = _optionsChosen.ContainsKey(settleOption) ? _optionsChosen[settleOption] : 0;
if (amount == 0 && _optionsChosen.ContainsKey(settleOption))
_optionsChosen.Remove(settleOption);
else if (_optionsChosen.ContainsKey(settleOption))
_optionsChosen[settleOption] = amount;
else if (amount != 0)
_optionsChosen.Add(settleOption, amount);
_amount += oldAmount - amount;
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", _amount);
if (_optionsChosen.Count == 0)
foreach (var item in _list.Where(item => item.Value != 0))
item.Key.Enabled = true;
else
foreach (var item in _list.Where(item => item.Value != group && item.Value != 0))
item.Key.Enabled = false;
}
private IDictionary<SettleOption, decimal> _optionsChosen;
public IDictionary<SettleOption, decimal> OptionsChosen
{
get
{
return _amount == 0 ? _optionsChosen : new Dictionary<SettleOption, decimal>();
}
private set { _optionsChosen = value; }
}
private void SettleChoicesFormLoad(object sender, EventArgs e)
{
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", _amount);
var count = 0;
foreach (SettleOption item in Enum.GetValues(typeof(SettleOption)))
{
var attribute = (DisplayAttribute)item.GetType().GetField(item.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false)[0];
if (!attribute.ShowInChoices)
continue;
var button = new Button
{
Name = item.ToString(),
Text = attribute.Name,
Size = new System.Drawing.Size(75, 75),
TabIndex = count,
UseVisualStyleBackColor = true,
Tag = item
};
button.Click += new EventHandler(ButtonClick);
flpSettlement.Controls.Add(button);
_list.Add(button, attribute.Group);
count++;
}
var controlButton = new Button
{
Name = "btnOK",
Text = "OK",
Size = new System.Drawing.Size(75, 75),
TabIndex = count,
UseVisualStyleBackColor = true,
Tag = "OK"
};
controlButton.Click += new EventHandler(ButtonClick);
flpSettlement.Controls.Add(controlButton);
_list.Add(controlButton, 0);
count++;
controlButton = new Button
{
Name = "btnCancel",
Text = "Cancel",
Size = new System.Drawing.Size(75, 75),
TabIndex = count,
UseVisualStyleBackColor = true,
Tag = "Cancel"
};
controlButton.Click += new EventHandler(ButtonClick);
flpSettlement.Controls.Add(controlButton);
_list.Add(controlButton, 0);
count++;
txtAmount.TabIndex = count;
this.Size = this.SizeFromClientSize(new Size(_list.Count * (75 + 6), 3 + txtAmount.Height + 6 + 75 + 3));
txtAmount.Width = flpSettlement.Width - 6;
}
}
}

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

@ -133,11 +133,17 @@
<DependentUpon>SaleDetail.cs</DependentUpon>
</Compile>
<Compile Include="Sales\BillHelperFunctions.cs" />
<Compile Include="Sales\BillSettleForm.cs">
<Compile Include="Sales\FrmSettleAmounts.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Sales\BillSettleForm.Designer.cs">
<DependentUpon>BillSettleForm.cs</DependentUpon>
<Compile Include="Sales\FrmSettleAmounts.Designer.cs">
<DependentUpon>FrmSettleAmounts.cs</DependentUpon>
</Compile>
<Compile Include="Sales\SettleChoicesForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Sales\SettleChoicesForm.Designer.cs">
<DependentUpon>SettleChoicesForm.cs</DependentUpon>
</Compile>
<Compile Include="Advances\frmAdjustAdvance.cs">
<SubType>Form</SubType>
@ -238,8 +244,11 @@
<DependentUpon>SaleDetail.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Sales\BillSettleForm.resx">
<DependentUpon>BillSettleForm.cs</DependentUpon>
<EmbeddedResource Include="Sales\FrmSettleAmounts.resx">
<DependentUpon>FrmSettleAmounts.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Sales\SettleChoicesForm.resx">
<DependentUpon>SettleChoicesForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Advances\frmAdjustAdvance.resx">
<DependentUpon>frmAdjustAdvance.cs</DependentUpon>

@ -1,4 +1,5 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Contracts;
@ -20,11 +21,8 @@ namespace Tanshu.Accounts.PointOfSale
if (control != null)
{
control.Location = new System.Drawing.Point(6, 140);
var border = (this.Width - this.ClientSize.Width) / 2;
var titlebarHeight = this.Height - this.ClientSize.Height - (2 * border);
this.Controls.Add(control);
this.Width = 6 + control.Width + 6 + (border * 2);
this.Height = titlebarHeight + 140 + control.Height + 6 + (border * 2);
this.Size = this.SizeFromClientSize(new Size(6 + control.Width + 6, 140 + control.Height + 6));
}
}

@ -1,16 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Repository;
namespace Tanshu.Accounts.Print
{
enum Align
internal enum Align
{
None = 0,
Left = 1,
@ -22,42 +21,37 @@ namespace Tanshu.Accounts.Print
{
private const string DrawLine = "\n\r------------------------------------------";
private const string DrawEqual = "\n\r==========================================";
private static string DesignKot(Voucher trans, string kotCode, List<Inventory> billItems, int copyNumber)
private static string DesignKot(Voucher trans, string kotCode, IEnumerable<Inventory> billItems, int copyNumber)
{
Waiter waiter = trans.Waiter;
string BillText;
try
var waiter = trans.Waiter;
var billText = "\n\r" + FormatText("KOT / BOT", 42, false, Align.Centre);
billText += "\n\r" + FormatText(string.Format("Copy No. {0}", copyNumber), 42, false, Align.Centre);
billText += DrawLine;
billText += string.Format("\n\rKOT ID : {0,-7}/{1,-7} {2:dd-MMM-yyyy HH:mm}", trans.KotID, kotCode,
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 (var item in billItems)
{
BillText = "\n\r" + FormatText("KOT / BOT", 42, false, Align.Centre);
BillText += "\n\r" + FormatText(string.Format("Copy No. {0}", copyNumber), 42, false, Align.Centre);
BillText += DrawLine;
BillText += string.Format("\n\rKOT ID : {0,-7}/{1,-7} {2:dd-MMM-yyyy HH:mm}", trans.KotID, kotCode, 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 (var item in billItems)
{
BillText += string.Format("\n\r{0,6:#,##0.00} x {1,-33}", item.Quantity, Name(item.Product));
foreach (var mod in item.InventoryModifier)
BillText += string.Format("\n\r --- {0,-32}", mod.Modifier.Name);
}
BillText += DrawLine;
if (trans.Narration != "")
{
BillText += "\n\r" + FormatText(trans.Narration, 42, false, Align.Centre);
BillText += DrawLine;
}
return BillText;
billText += string.Format("\n\r{0,6:#,##0.00} x {1,-33}", item.Quantity, Name(item.Product));
foreach (var mod in item.InventoryModifier)
billText += string.Format("\n\r --- {0,-32}", mod.Modifier.Name);
}
catch (Exception ex)
billText += DrawLine;
if (trans.Narration != "")
{
throw ex;
billText += "\n\r" + FormatText(trans.Narration, 42, false, Align.Centre);
billText += DrawLine;
}
return billText;
}
private static string DesignBill(Voucher trans)
{
Dictionary<int, Inventory> list = new Dictionary<int, Inventory>();
var list = new Dictionary<int, Inventory>();
foreach (var kot in trans.Kots)
{
foreach (var item in kot.Inventories)
@ -68,196 +62,165 @@ namespace Tanshu.Accounts.Print
list.Add(item.Product.ProductID, item);
}
}
User cashier = trans.User;
Waiter waiter = trans.Waiter;
Customer customer = trans.Customer;
String billNo = trans.BillID.Substring(trans.BillID.IndexOf("-") + 1);
String BillText = "";
BillText = "\n\r" + FormatText("Hops n Grains", 42, false, Align.Centre);
BillText += "\n\r" + FormatText("The Microbrewery", 42, false, Align.Centre);
BillText += "\n\r" + FormatText("SCO 358, Sector 9, Panchkula", 42, false, Align.Centre);
BillText += "\n\r" + FormatText("A Unit of Peitho Foods Pvt. Ltd.", 42, false, Align.Centre);
BillText += "\n\r" + FormatText("TIN: 06592507323", 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" + "------------------------------------------";
var cashier = trans.User;
var waiter = trans.Waiter;
var customer = trans.Customer;
var billNo = trans.BillID.Substring(trans.BillID.IndexOf("-") + 1);
var billText = "";
billText = "\n\r" + FormatText("Hops n Grains", 42, false, Align.Centre);
billText += "\n\r" + FormatText("The Microbrewery", 42, false, Align.Centre);
billText += "\n\r" + FormatText("SCO 358, Sector 9, Panchkula", 42, false, Align.Centre);
billText += "\n\r" + FormatText("A Unit of Peitho Foods Pvt. Ltd.", 42, false, Align.Centre);
billText += "\n\r" + FormatText("TIN: 06592507323", 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 (var item in list.Values)
{
if (item.Quantity == 0)
continue;
if (Math.Round((item.Rate * (1 + item.Tax)), 0) == 1)
{
BillText += "\n\r" + " ";
BillText += FormatText(Name(item.Product), 22, false, Align.Left) + " ";
BillText += " ";
BillText += FormatBillNum(item.Rate * item.Quantity, 6);
billText += "\n\r" + " ";
billText += FormatText(Name(item.Product), 22, false, Align.Left) + " ";
billText += " ";
billText += FormatBillNum(item.Rate * item.Quantity, 6);
}
else
{
BillText += "\n\r" + FormatBillNum(item.Quantity, 5) + " ";
BillText += FormatText(Name(item.Product), 22, false, Align.Left) + " ";
BillText += FormatBillNum(item.Rate, 6) + " ";
BillText += FormatBillNum(item.Rate * item.Quantity, 6);
billText += "\n\r" + FormatBillNum(item.Quantity, 5) + " ";
billText += FormatText(Name(item.Product), 22, false, Align.Left) + " ";
billText += FormatBillNum(item.Rate, 6) + " ";
billText += FormatBillNum(item.Rate * item.Quantity, 6);
}
}
BillText += "\n\r" + "------------------------------------------";
billText += "\n\r" + "------------------------------------------";
decimal amount;
amount = Net(trans);
amount = Net(list.Values);
if (amount != 0)
BillText += "\n\r" + FormatText("Net : ", 33, false, Align.Right) + FormatBillNum(amount, 9);
billText += "\n\r" + FormatText("Net : ", 33, false, Align.Right) + FormatBillNum(amount, 9);
amount = Discount(trans);
amount = Discount(list.Values);
if (amount != 0)
BillText += "\n\r" + FormatText("Discount : ", 33, false, Align.Right) + FormatBillNum(amount, 9);
billText += "\n\r" + FormatText("Discount : ", 33, false, Align.Right) + FormatBillNum(amount, 9);
amount = ServiceCharge(trans);
amount = ServiceCharge(list.Values);
if (amount != 0)
BillText += "\n\r" + FormatText("Service Charge : ", 33, false, Align.Right) + FormatBillNum(amount, 9);
billText += "\n\r" + FormatText("Service Charge : ", 33, false, Align.Right) + FormatBillNum(amount, 9);
amount = Tax(trans);
amount = Tax(list.Values);
if (amount != 0)
BillText += "\n\r" + FormatText("VAT (incl. surcharge) : ", 33, false, Align.Right) + FormatBillNum(amount, 9);
billText += "\n\r" + FormatText("VAT (incl. surcharge) : ", 33, false, Align.Right) +
FormatBillNum(amount, 9);
amount = Amount(trans);
amount = Amount(list.Values);
if (amount != 0)
BillText += string.Format("\n\r Final Amount : {0,9:#,##0.00;(#,##0.00);0}", Math.Round(amount, 0));
billText += string.Format("\n\r Final Amount : {0,9:#,##0.00;(#,##0.00);0}",
Math.Round(amount, 0));
BillText += DrawLine;
billText += DrawLine;
if (trans.Narration != "")
{
BillText += "\n\r" + FormatText(trans.Narration, 42, false, Align.Centre);
BillText += DrawLine;
billText += "\n\r" + FormatText(trans.Narration, 42, false, Align.Centre);
billText += DrawLine;
}
if (customer.CustomerID != 1)
{
BillText += "\n\r" + customer.Name;
BillText += string.Format("\n\r{0}\n\r{1}", customer.Phone, customer.Address);
BillText += DrawLine;
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" + "Call: 0172-4026666, 8054923853, 8054923856";
return BillText;
billText += "\n\r" + "Cashier : " + cashier.Name + " / " + waiter.Name;
billText += "\n\r" + "Call: 0172-4026666, 8054923853, 8054923856";
return billText;
}
private static decimal Amount(Voucher voucher)
private static decimal Amount(IEnumerable<Inventory> list)
{
decimal amount = 0;
foreach (var kot in voucher.Kots)
{
foreach (var inv in kot.Inventories)
{
amount += inv.Quantity * inv.Rate * (1 - inv.Discount) * (1 + inv.ServiceCharge) * (1 + inv.Tax);
}
}
return amount;
return list.Sum(item => item.Quantity * item.Rate * (1 - item.Discount) * (1 + item.ServiceCharge) * (1 + item.Tax));
}
private static decimal Tax(Voucher voucher)
private static decimal Tax(IEnumerable<Inventory> list)
{
decimal amount = 0;
foreach (var kot in voucher.Kots)
{
foreach (var inv in kot.Inventories)
{
amount += inv.Quantity * inv.Rate * (1 - inv.Discount) * (1 + inv.ServiceCharge) * inv.Tax;
}
}
return amount;
return list.Sum(item => item.Quantity * item.Rate * (1 - item.Discount) * (1 + item.ServiceCharge) * item.Tax);
}
private static decimal ServiceCharge(Voucher voucher)
private static decimal ServiceCharge(IEnumerable<Inventory> list)
{
decimal amount = 0;
foreach (var kot in voucher.Kots)
{
foreach (var inv in kot.Inventories)
{
amount += inv.Quantity * inv.Rate * (1 - inv.Discount) * inv.ServiceCharge;
}
}
return amount;
return list.Sum(item => item.Quantity * item.Rate * (1 - item.Discount) * item.ServiceCharge);
}
private static decimal Discount(Voucher voucher)
private static decimal Discount(IEnumerable<Inventory> list)
{
decimal amount = 0;
foreach (var kot in voucher.Kots)
{
foreach (var inv in kot.Inventories)
{
amount += inv.Quantity * inv.Rate * inv.Discount;
}
}
return amount;
return list.Sum(item => item.Quantity * item.Rate * item.Discount);
}
private static decimal Net(Voucher voucher)
private static decimal Net(IEnumerable<Inventory> list)
{
decimal amount = 0;
foreach (var kot in voucher.Kots)
{
foreach (var inv in kot.Inventories)
{
amount += inv.Quantity * inv.Rate;
}
}
return amount;
return list.Sum(item => item.Quantity * item.Rate);
}
private static string Name(Product product)
{
if (product.Units == null || product.Units == string.Empty)
return product.Name;
else
return string.Format("{0} ({1})", product.Name, product.Units);
return string.IsNullOrEmpty(product.Units)
? product.Name
: string.Format("{0} ({1})", product.Name, product.Units);
}
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++)
var newString = "";
var lines = Convert.ToInt32(Math.Floor(Convert.ToDecimal(inputString.Length / width)));
for (var 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)
if (inputString.Length > width)
return inputString.Substring(0, width);
else if (alignment == Align.None)
if (alignment == Align.None)
return inputString;
else if (alignment == Align.Left)
return string.Format("{0,-" + width.ToString() + "}", inputString);
else if (alignment == Align.Centre)
if (alignment == Align.Left)
return string.Format("{0,-" + width + "}", inputString);
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);
left = Convert.ToInt32(Math.Ceiling(Convert.ToDouble((width - inputString.Length) / 2))) +
inputString.Length;
inputString = string.Format("{0,-" + left + "}", inputString);
return string.Format("{0," + width + "}", inputString);
}
else if (alignment == Align.Right)
return string.Format("{0," + width.ToString() + "}", inputString);
else
return inputString;
if (alignment == Align.Right)
return string.Format("{0," + width + "}", inputString);
return inputString;
}
private static string FormatBillNum(decimal Amount, int Length)
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);
var temp = String.Format("{0:#,##0.00;(#,##0.00);0}", amount);
return string.Format("{0," + length + "}", temp);
}
private static bool PrintRAW(PrintLocation printer, string Text, string DocumentName)
private static bool PrintRaw(PrintLocation printer, string text, string documentName)
{
#if (DEBUG)
System.Windows.Forms.MessageBox.Show(Text);
MessageBox.Show(text);
return true;
#else
try
{
Text += printer.CutCode;
if (!RawPrinterHelper.PrintString(printer.Printer, DocumentName, Text, new char[] { ';' }))
if (!RawPrinterHelper.PrintString(printer.Printer, DocumentName, Text, new[] { ';' }))
{
GC.Collect();
System.Windows.Forms.MessageBox.Show("Error in PrintRAW Function. Please Report immediately");
MessageBox.Show("Error in PrintRAW Function. Please Report immediately");
}
}
catch (Exception ex)
@ -268,7 +231,134 @@ namespace Tanshu.Accounts.Print
#endif
}
public static Boolean PrintAdvance(string user, string advance, string narration)
{
var billText = "\n\r" + FormatText("Hops n Grains", 42, false, Align.Centre);
billText += "\n\r" + FormatText("The Microbrewery", 42, false, Align.Centre);
billText += "\n\r" + FormatText("SCO 358, Sector 9, Panchkula", 42, false, Align.Centre);
billText += "\n\r" + FormatText("A Unit of Peitho Foods 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";
PrintRaw(PrintLocationBI.BasePrinter, billText, "Advance for " + user);
return PrintRaw(PrintLocationBI.BasePrinter, billText, "Advance for " + user);
}
public static Boolean PrintClosing(CheckoutBI details)
{
try
{
var billText = FormatText(string.Format("{0} Checkout By {1}", details.Cashier.Name, details.Manager), 42,
false, 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;
//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\rNC Amount : {0,26:#,##0.00}", details.NcReceipts);
billText += string.Format("\n\rBTC Amount : {0,26:#,##0.00}", details.BtcReceipts);
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\rDiscounts : {0,26:#,##0.00}", details.Discount);
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.NcString.Length > 0)
billText += details.NcString;
if (details.BtcString.Length > 0)
billText += details.BtcString;
if (details.VoidsString.Length > 0)
billText += details.VoidsString;
if (details.PaymentString.Length > 0)
billText += details.PaymentString;
if (details.DiscountString.Length > 0)
billText += details.DiscountString;
return PrintRaw(PrintLocationBI.BasePrinter, billText, "Closing");
}
catch (Exception ex)
{
throw ex;
}
}
public static string FormatPrintNum(string inputString)
{
return inputString == "" ? "0.00" : FormatText(inputString, 24, false, Align.Right);
//return FormatText(FormatNumber(InputString.Trim, 2, TriState.UseDefault, TriState.True, TriState.True), 24, False, Align.Right);
}
public static void PrintBill(int voucherID)
{
var voucher = VoucherBI.GetVoucher(voucherID);
PrintRaw(PrintLocationBI.BasePrinter, DesignBill(voucher), "Bill");
}
public static void PrintKot(int voucherID, int kotID)
{
var voucher = VoucherBI.GetVoucher(voucherID);
var dict = new Dictionary<PrintLocation, List<Inventory>>();
foreach (var item in voucher.Kots.Where(x => x.KotID == kotID))
{
foreach (var inventory in item.Inventories)
{
var type = ProductBI.GetProduct(inventory.Product.ProductID).ProductGroup.ProductGroupID;
var printer = PrintLocationBI.KotPrinter(type);
if (!dict.ContainsKey(printer))
{
dict.Add(printer, new List<Inventory>());
}
dict[printer].Add(inventory);
}
}
foreach (var item in dict)
{
for (var i = 0; i < item.Key.Copies; i++)
{
PrintRaw(item.Key,
DesignKot(voucher, voucher.Kots.Where(x => x.KotID == kotID).Single().Code, item.Value, i),
"KOT");
}
}
}
#region Print Cash Total
public static Boolean PrintCash(Dictionary<int, int> amount, string user)
{
string printText;
@ -277,7 +367,8 @@ namespace Tanshu.Accounts.Print
{
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 HH:mm:ss}", DateTime.Now), 42, false, Align.Centre);
foreach (int key in amount.Keys.OrderByDescending(k => k))
{
printText += CashLine(amount, key);
@ -286,14 +377,14 @@ namespace Tanshu.Accounts.Print
printText += "\n\r" + DrawEqual;
printText += string.Format("\n\r Total = {0,10:#,##0}", total);
printText += DrawLine;
return PrintRAW(PrintLocationBI.BasePrinter, printText, "Closing/Opening for " + user);
return PrintRaw(PrintLocationBI.BasePrinter, printText, "Closing/Opening for " + user);
}
catch (Exception ex)
{
throw ex;
}
}
public static Boolean PrintSale(string user, IList<SalesAnalysis> det, DateTime startDate, DateTime endDate)
{
string printText;
@ -301,192 +392,50 @@ namespace Tanshu.Accounts.Print
{
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 += "\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 (SalesAnalysis d in det)
{
printText += string.Format("\n\r {0,-22} {1,9:#,##0}", d.GroupType, d.Amount);
}
printText += DrawEqual;
return PrintRAW(PrintLocationBI.BasePrinter, printText, "Sale Detail " + user);
return PrintRaw(PrintLocationBI.BasePrinter, printText, "Sale Detail " + user);
}
catch (Exception ex)
{
throw ex;
}
}
public static Boolean PrintSale(string user, IList<SalesAnalysisDetail> list, DateTime startDate, DateTime endDate)
public static Boolean PrintSale(string user, IList<SalesAnalysisDetail> list, DateTime startDate,
DateTime endDate)
{
string printText;
try
var 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 (var item in list)
{
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 (var item in list)
{
printText += string.Format("\n\r{0,-22} {1,9:#,##0.00} {2,9:#,##0.00}", item.Product, item.Sale, item.NC);
}
printText += DrawEqual;
return PrintRAW(PrintLocationBI.BasePrinter, printText, "Sale Detail " + user);
printText += string.Format("\n\r{0,-22} {1,9:#,##0.00} {2,9:#,##0.00}", item.Product, item.Sale,
item.NC);
}
catch (Exception ex)
{
throw ex;
}
printText += DrawEqual;
return PrintRaw(PrintLocationBI.BasePrinter, printText, "Sale Detail " + user);
}
private static string CashLine(Dictionary<int, int> amount, int key)
private static string CashLine(IDictionary<int, int> 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;
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
public static Boolean PrintAdvance(string user, string Advance, string Narration)
{
String BillText;
try
{
BillText = "\n\r" + FormatText("Hops n Grains", 42, false, Align.Centre);
BillText += "\n\r" + FormatText("The Microbrewery", 42, false, Align.Centre);
BillText += "\n\r" + FormatText("SCO 358, Sector 9, Panchkula", 42, false, Align.Centre);
BillText += "\n\r" + FormatText("A Unit of Peitho Foods 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";
PrintRAW(PrintLocationBI.BasePrinter, BillText, "Advance for " + user);
return PrintRAW(PrintLocationBI.BasePrinter, BillText, "Advance for " + user);
}
catch (Exception ex)
{
throw ex;
}
}
public static Boolean PrintClosing(CheckoutBI details)
{
string BillText;
try
{
BillText = FormatText(string.Format("{0} Checkout By {1}", details.Cashier.Name, details.Manager), 42, false, 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;
//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\rNC Amount : {0,26:#,##0.00}", details.NCReceipts);
BillText += string.Format("\n\rBTC Amount : {0,26:#,##0.00}", details.BTCReceipts);
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\rDiscounts : {0,26:#,##0.00}", details.Discount);
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.NCString.Length > 0)
BillText += details.NCString;
if (details.BTCString.Length > 0)
BillText += details.BTCString;
if (details.StaffString.Length > 0)
BillText += details.StaffString;
if (details.VoidsString.Length > 0)
BillText += details.VoidsString;
if (details.PaymentString.Length > 0)
BillText += details.PaymentString;
if (details.DiscountString.Length > 0)
BillText += details.DiscountString;
return PrintRAW(PrintLocationBI.BasePrinter, 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(int voucherID)
{
var voucher = VoucherBI.GetSaleVoucher(voucherID);
PrintRAW(PrintLocationBI.BasePrinter, DesignBill(voucher), "Bill");
}
public static void PrintKot(int voucherID, int kotID)
{
var voucher = VoucherBI.GetSaleVoucher(voucherID);
Dictionary<PrintLocation, List<Inventory>> dict = new Dictionary<PrintLocation, List<Inventory>>();
//Dictionary<string, int> dictCount = new Dictionary<string, int>();
foreach (var item in voucher.Kots.Where(x => x.KotID == kotID))
{
foreach (var inventory in item.Inventories)
{
int type = ProductBI.GetProduct(inventory.Product.ProductID).ProductGroup.ProductGroupID;
var printer = PrintLocationBI.KotPrinter(type);
if (!dict.ContainsKey(printer))
{
dict.Add(printer, new List<Inventory>());
//dictCount.Add(printer.Printer, 0);
}
dict[printer].Add(inventory);
//dictCount[printer.Printer] = printer.Copies;
}
}
foreach (var item in dict)
{
for (int i = 0; i < item.Key.Copies; i++)
{
PrintRAW(item.Key, DesignKot(voucher, voucher.Kots.Where(x => x.KotID == kotID).Single().Code, item.Value, i), "KOT");
}
}
}
}
}
}

@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Data.SqlClient;
using Tanshu.Data.DAO;
using Tanshu.Accounts.SqlDAO;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Entities.Auth;
using NHibernate.Criterion;
@ -19,10 +14,9 @@ namespace Tanshu.Accounts.Repository
public decimal Opening { get; private set; }
public decimal Receipts { get; private set; }
public decimal AdvanceReceipts { get; private set; }
public decimal CCReceipts { get; private set; }
public decimal NCReceipts { get; private set; }
public decimal BTCReceipts { get; private set; }
public decimal StaffReceipts { get; private set; }
public decimal CcReceipts { get; private set; }
public decimal NcReceipts { get; private set; }
public decimal BtcReceipts { get; private set; }
public decimal AdvanceAdjusted { get; private set; }
public decimal CashPayments { get; private set; }
public decimal AdditionalVoids { get; private set; }
@ -46,10 +40,9 @@ namespace Tanshu.Accounts.Repository
public DateTime FinishDate { get; private set; }
public string PendingString { get; private set; }
public string CCString { get; private set; }
public string NCString { get; private set; }
public string BTCString { get; private set; }
public string StaffString { get; private set; }
public string CcString { get; private set; }
public string NcString { get; private set; }
public string BtcString { get; private set; }
public string VoidsString { get; private set; }
public string DiscountString { get; private set; }
@ -71,14 +64,12 @@ namespace Tanshu.Accounts.Repository
string info;
PendingBills = GetPending(out info);
PendingString = info;
CCReceipts = GetCreditCard(out info);
CCString = info;
NCReceipts = GetNoCharge(out info);
NCString = info;
BTCReceipts = GetBillToCompany(out info);
BTCString = info;
StaffReceipts = GetStaffBills(out info);
StaffString = info;
CcReceipts = GetCreditCard(out info);
CcString = info;
NcReceipts = GetNoCharge(out info);
NcString = info;
BtcReceipts = GetBillToCompany(out info);
BtcString = info;
VoidsInSystem = GetVoids(out info);
VoidsString = info;
// Opening = dao.GetOpenings();
@ -104,8 +95,8 @@ namespace Tanshu.Accounts.Repository
ClosingBalance = Opening
+ Receipts
+ AdvanceReceipts
- CCReceipts
- BTCReceipts
- CcReceipts
- BtcReceipts
- AdvanceAdjusted
- CashPayments
- AdditionalVoids
@ -148,35 +139,38 @@ namespace Tanshu.Accounts.Repository
{
using (var session = SessionManager.Session)
{
Voucher voucher = null;
decimal amount;
decimal discount;
info = "\n\r--- Pending Bills ------------------------";
var list = (from i in session.QueryOver<Voucher>()
where i.LastEditDate >= StartDate &&
i.LastEditDate <= FinishDate &&
i.User == Cashier &&
i.Void == false &&
i.Settled == SettleOption.Unsettled
select i).List();
GetInfo(list, out amount, out discount, ref info);
var list = session.QueryOver<Voucher>(() => voucher)
.Where(i => i.LastEditDate >= StartDate &&
i.LastEditDate <= FinishDate &&
i.User == Cashier &&
i.Void == false)
.WithSubquery.WhereExists(QueryOver.Of<VoucherSettlement>().Where(x => x.Voucher.VoucherID == voucher.VoucherID && x.Settled == SettleOption.Unsettled).Select(x => x.Voucher))
.List();
GetInfo(list, SettleOption.Unsettled, out amount, out discount, ref info);
return amount;
}
}
private decimal GetNoCharge(out string info)
{
using (var session = SessionManager.Session)
{
Voucher voucher = null;
decimal amount;
decimal discount;
info = "\n\r--- No Charge ----------------------------";
var list = (from i in session.QueryOver<Voucher>()
where i.LastEditDate >= StartDate &&
i.LastEditDate <= FinishDate &&
i.User == Cashier &&
i.Void == false &&
i.Settled == SettleOption.NoCharge
select i).List();
GetInfo(list, out amount, out discount, ref info);
var list = session.QueryOver<Voucher>(() => voucher)
.Where(i => i.LastEditDate >= StartDate &&
i.LastEditDate <= FinishDate &&
i.User == Cashier &&
i.Void == false)
.WithSubquery.WhereExists(QueryOver.Of<VoucherSettlement>().Where(x => x.Voucher.VoucherID == voucher.VoucherID && x.Settled == SettleOption.NoCharge).Select(x => x.Voucher))
.List();
GetInfo(list, SettleOption.NoCharge, out amount, out discount, ref info);
return amount;
}
}
@ -184,35 +178,18 @@ namespace Tanshu.Accounts.Repository
{
using (var session = SessionManager.Session)
{
Voucher voucher = null;
decimal amount;
decimal discount;
info = "\n\r--- Bill To Company ----------------------";
var list = (from i in session.QueryOver<Voucher>()
where i.LastEditDate >= StartDate &&
i.LastEditDate <= FinishDate &&
i.User == Cashier &&
i.Void == false &&
i.Settled == SettleOption.BillToCompany
select i).List();
GetInfo(list, out amount, out discount, ref info);
return amount;
}
}
private decimal GetStaffBills(out string info)
{
using (var session = SessionManager.Session)
{
decimal amount;
decimal discount;
info = "\n\r--- Staff Bills --------------------------";
var list = (from i in session.QueryOver<Voucher>()
where i.LastEditDate >= StartDate &&
i.LastEditDate <= FinishDate &&
i.User == Cashier &&
i.Void == false &&
i.Settled == SettleOption.Staff
select i).List();
GetInfo(list, out amount, out discount, ref info);
var list = session.QueryOver<Voucher>(() => voucher)
.Where(i => i.LastEditDate >= StartDate &&
i.LastEditDate <= FinishDate &&
i.User == Cashier &&
i.Void == false)
.WithSubquery.WhereExists(QueryOver.Of<VoucherSettlement>().Where(x => x.Voucher.VoucherID == voucher.VoucherID && x.Settled == SettleOption.BillToCompany).Select(x => x.Voucher))
.List();
GetInfo(list, SettleOption.BillToCompany, out amount, out discount, ref info);
return amount;
}
}
@ -220,17 +197,19 @@ namespace Tanshu.Accounts.Repository
{
using (var session = SessionManager.Session)
{
Voucher voucher = null;
decimal amount;
decimal discount;
info = "\n\r--- Credit Card Bills --------------------";
var list = (from i in session.QueryOver<Voucher>()
where i.LastEditDate >= StartDate &&
i.LastEditDate <= FinishDate &&
i.User == Cashier &&
i.Void == false &&
i.Settled == SettleOption.CreditCard
select i).List();
GetInfo(list, out amount, out discount, ref info);
var list = session.QueryOver<Voucher>(() => voucher)
.Where(i => i.LastEditDate >= StartDate &&
i.LastEditDate <= FinishDate &&
i.User == Cashier &&
i.Void == false)
.WithSubquery.WhereExists(QueryOver.Of<VoucherSettlement>().Where(x => x.Voucher.VoucherID == voucher.VoucherID && x.Settled == SettleOption.CreditCard).Select(x => x.Voucher))
.List();
GetInfo(list, SettleOption.CreditCard, out amount, out discount, ref info);
return amount;
}
}
@ -258,11 +237,13 @@ namespace Tanshu.Accounts.Repository
decimal amount;
decimal discount;
info = "\n\r--- High Discount Bills ------------------";
string query = @"
const string query = @"
select distinct(v) from Voucher v
inner join v.Kots k
inner join k.Inventories i
where v.Date >= :startDate and v.Date <= :finishDate and v.User = :cashierID and v.Void = false and v.Settled != :unSettled and v.Settled != :noCharge
where v.Date >= :startDate and v.Date <= :finishDate and v.User = :cashierID and v.Void = false
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v
and vs.Settled != :noCharge and vs.Settled != :unSettled and vs.Settled != :amount and vs.Settled != :roundoff)
and i.Discount >= :discount";
var list = session.CreateQuery(query)
.SetParameter("startDate", StartDate)
@ -270,6 +251,8 @@ and i.Discount >= :discount";
.SetParameter("cashierID", Cashier.UserID)
.SetParameter("unSettled", SettleOption.Unsettled)
.SetParameter("noCharge", SettleOption.NoCharge)
.SetParameter("amount", SettleOption.Amount)
.SetParameter("roundoff", SettleOption.RoundOff)
.SetParameter("discount", disount)
.List<Voucher>();
@ -282,24 +265,28 @@ and i.Discount >= :discount";
{
using (var session = SessionManager.Session)
{
decimal amount = 0;
string query = @"
const string query = @"
select sum(i.Amount) from Voucher v
inner join v.Kots k
inner join k.Inventories i
where v.Date >= :startDate and v.Date <= :finishDate and v.User = :cashierID and v.Void = false and v.Settled != :unSettled and v.Settled != :noCharge";
amount = session.CreateQuery(query)
where v.Date >= :startDate and v.Date <= :finishDate and v.User = :cashierID and v.Void = false
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v
and vs.Settled != :noCharge and vs.Settled != :unSettled and vs.Settled != :amount and vs.Settled != :roundoff)
";
var amount = session.CreateQuery(query)
.SetParameter("startDate", StartDate)
.SetParameter("finishDate", FinishDate)
.SetParameter("cashierID", Cashier.UserID)
.SetParameter("unSettled", SettleOption.Unsettled)
.SetParameter("noCharge", SettleOption.NoCharge)
.SetParameter("amount", SettleOption.Amount)
.SetParameter("roundoff", SettleOption.RoundOff)
.UniqueResult<decimal>();
return amount;
}
}
private void GetInfo(IList<Voucher> list, out decimal amount, out decimal discount, ref string info)
private static void GetInfo(ICollection<Voucher> list, out decimal amount, out decimal discount, ref string info)
{
amount = 0;
discount = 0;
@ -310,9 +297,29 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.User = :cashierID and
}
foreach (var item in list)
{
decimal amt, disc;
amt = item.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
disc = item.Kots.Sum(x => x.Inventories.Sum(y => y.Quantity * y.Rate * y.Discount));
var amt = item.Settlements.Where(x => x.Settled == SettleOption.Amount).Sum(x => x.Amount) * -1;
var disc = item.Kots.Sum(x => x.Inventories.Sum(y => y.Quantity * y.Rate * y.Discount));
info += string.Format("\n\r{0:dd-MMM-yyyy HH:mm:ss} {1} {2}", item.Date, item.BillID, item.Customer.Name);
info += string.Format("\n\rAmount: {0:#0.00} :: Discount: {1:#0.00}", amt, disc);
info += "\n\r------------------------------------------";
amount += amt;
discount += disc;
}
}
private static void GetInfo(ICollection<Voucher> list, SettleOption settleOption, out decimal amount, out decimal discount, ref string info)
{
amount = 0;
discount = 0;
if (list.Count == 0)
{
info = string.Empty;
return;
}
foreach (var item in list)
{
var amt = item.Settlements.Where(x => x.Settled == settleOption).Sum(x => x.Amount);
var disc = item.Kots.Sum(x => x.Inventories.Sum(y => y.Quantity * y.Rate * y.Discount));
info += string.Format("\n\r{0:dd-MMM-yyyy HH:mm:ss} {1} {2}", item.Date, item.BillID, item.Customer.Name);
info += string.Format("\n\rAmount: {0:#0.00} :: Discount: {1:#0.00}", amt, disc);
info += "\n\r------------------------------------------";
@ -323,10 +330,10 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.User = :cashierID and
private string GetActiveCashiers()
{
string cashiers = "";
var cashiers = "";
using (var session = SessionManager.Session)
{
string query = @"
const string query = @"
select distinct(u.Name) from Voucher v
inner join v.User u
where v.Date >= :startDate and v.Date <= :finishDate";

@ -1,127 +1,126 @@
using System;
using System.Collections.Generic;
using System.Text;
using Tanshu.Accounts.Contracts;
using System.Data.SqlClient;
using Tanshu.Data.DAO;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.SqlDAO;
using NHibernate;
using NHibernate.Criterion;
using Tanshu.Accounts.Entities;
namespace Tanshu.Accounts.Repository
{
public class FoodTableBI : IDisposable
{
ISession session;
bool disposeSession;
bool useTransaction;
private readonly bool _disposeSession;
private readonly ISession _session;
private readonly bool _useTransaction;
public FoodTableBI()
{
this.session = SessionManager.Session;
disposeSession = true;
this.useTransaction = false;
_session = SessionManager.Session;
_disposeSession = true;
_useTransaction = false;
}
public FoodTableBI(ISession session)
{
this.session = session;
disposeSession = false;
this.useTransaction = false;
this._session = session;
_disposeSession = false;
_useTransaction = false;
}
public FoodTableBI(ISession session, bool useTransaction)
{
this.session = session;
disposeSession = false;
this.useTransaction = useTransaction;
this._session = session;
_disposeSession = false;
this._useTransaction = useTransaction;
}
#region IDisposable Members
public void Dispose()
{
if (_disposeSession)
_session.Dispose();
}
#endregion
public void Insert(FoodTable foodTable)
{
session.Save(foodTable);
_session.Save(foodTable);
}
public void Update(FoodTable foodTable)
{
session.Update(foodTable);
_session.Update(foodTable);
}
public void Delete(int foodTableID)
{
session.Delete(new FoodTable() { FoodTableID = foodTableID });
_session.Delete(new FoodTable {FoodTableID = foodTableID});
}
public FoodTable Get(int foodTableID)
{
return session.Get<FoodTable>(foodTableID);
return _session.Get<FoodTable>(foodTableID);
}
public FoodTable GetByName(string name)
{
return session.CreateCriteria<FoodTable>()
return _session.CreateCriteria<FoodTable>()
.Add(Restrictions.Eq("Name", name))
.UniqueResult<FoodTable>();
}
public IList<FoodTable> List()
{
return session.CreateCriteria<FoodTable>().List<FoodTable>();
return _session.CreateCriteria<FoodTable>().List<FoodTable>();
}
public void UpdateStatus(string name, int voucherID, string status)
{
if (!useTransaction)
using (var trans = session.BeginTransaction())
if (!_useTransaction)
using (var trans = _session.BeginTransaction())
{
var table = session.CreateCriteria<FoodTable>()
.Add(Restrictions.Eq("Name", name))
.UniqueResult<FoodTable>();
var table = _session.CreateCriteria<FoodTable>()
.Add(Restrictions.Eq("Name", name))
.UniqueResult<FoodTable>();
if (table == null)
return;
if (status == null || status == string.Empty)
table.VoucherID = 0;
else
table.VoucherID = voucherID;
table.VoucherID = string.IsNullOrEmpty(status) ? 0 : voucherID;
table.Status = status;
session.Update(table);
_session.Update(table);
trans.Commit();
}
else
{
var table = session.CreateCriteria<FoodTable>()
.Add(Restrictions.Eq("Name", name))
.UniqueResult<FoodTable>();
if (status == null || status == string.Empty)
table.VoucherID = 0;
else
table.VoucherID = voucherID;
var table = _session.CreateCriteria<FoodTable>()
.Add(Restrictions.Eq("Name", name))
.UniqueResult<FoodTable>();
table.VoucherID = string.IsNullOrEmpty(status) ? 0 : voucherID;
table.Status = status;
session.Update(table);
_session.Update(table);
}
}
public void Dispose()
{
if (disposeSession)
session.Dispose();
}
public int Move(string name, FoodTable foodTable)
{
using (var trans = session.BeginTransaction())
using (var trans = _session.BeginTransaction())
{
var oldTable = session.CreateCriteria<FoodTable>()
var oldTable = _session.CreateCriteria<FoodTable>()
.Add(Restrictions.Eq("Name", name))
.UniqueResult<FoodTable>();
foodTable.Status = oldTable.Status;
foodTable.VoucherID = oldTable.VoucherID;
oldTable.Status = null;
oldTable.VoucherID = 0;
session.Merge(foodTable);
session.Update(oldTable);
_session.Merge(foodTable);
_session.Update(oldTable);
var voucher = session.Get<Voucher>(foodTable.VoucherID);
var voucher = _session.Get<Voucher>(foodTable.VoucherID);
voucher.TableID = foodTable.Name;
session.Update(voucher);
_session.Update(voucher);
trans.Commit();
return voucher.VoucherID;
}
}
}
}
}

@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using Tanshu.Accounts.Contracts;
using Tanshu.Data.DAO;
using Tanshu.Accounts.SqlDAO;
using Tanshu.Accounts.Entities;
using NHibernate.Criterion;
using Tanshu.Common;
namespace Tanshu.Accounts.Repository
@ -29,7 +24,9 @@ from Voucher v
inner join v.Kots k
inner join k.Inventories i
inner join i.Product p
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.Settled != :noCharge
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v
and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff)
group by concat(p.Name, ' ', p.Units), p.ProductGroup
order by p.ProductGroup, concat(p.Name, ' ', p.Units)
";
@ -38,6 +35,9 @@ order by p.ProductGroup, concat(p.Name, ' ', p.Units)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.SetParameter("noCharge", SettleOption.NoCharge)
.SetParameter("unsettled", SettleOption.Unsettled)
.SetParameter("amount", SettleOption.Amount)
.SetParameter("roundoff", SettleOption.RoundOff)
.List<object[]>();
var outList = new OrderedDictionary<string, SalesAnalysisDetail>();
foreach (var item in list)
@ -49,7 +49,8 @@ from Voucher v
inner join v.Kots k
inner join k.Inventories i
inner join i.Product p
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.Settled = :noCharge
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v and vs.Settled = :noCharge)
group by concat(p.Name, ' ', p.Units), p.ProductGroup
order by p.ProductGroup, concat(p.Name, ' ', p.Units)
";
@ -76,14 +77,16 @@ order by p.ProductGroup, concat(p.Name, ' ', p.Units)
return new List<SalesAnalysis>();
using (var session = SessionManager.Session)
{
var query = @"
const string query = @"
select g.GroupType as GroupType, Sum(i.Quantity * i.Rate * (1 - i.Discount)) as Amount
from Voucher v
inner join v.Kots k
inner join k.Inventories i
inner join i.Product p
inner join p.ProductGroup g
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.Settled != :noCharge and v.Settled != :unsettled
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v
and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff)
group by g.GroupType
order by g.GroupType
";
@ -93,6 +96,8 @@ order by g.GroupType
.SetParameter("finishDate", finishDate)
.SetParameter("noCharge", SettleOption.NoCharge)
.SetParameter("unsettled", SettleOption.Unsettled)
.SetParameter("amount", SettleOption.Amount)
.SetParameter("roundoff", SettleOption.RoundOff)
.List<object[]>();
var outList = new List<SalesAnalysis>();
decimal amount = 0;
@ -105,7 +110,7 @@ order by g.GroupType
return GetSettlement(outList, startDate, finishDate);
}
}
private IList<SalesAnalysis> GetSettlement(IList<SalesAnalysis> outList, DateTime startDate, DateTime finishDate)
private static IList<SalesAnalysis> GetSettlement(IList<SalesAnalysis> outList, DateTime startDate, DateTime finishDate)
{
outList.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 });
if (finishDate <= startDate)
@ -113,20 +118,18 @@ order by g.GroupType
using (var session = SessionManager.Session)
{
//select v.Settled, Sum(i.Quantity * i.Rate * (1 - i.Discount) * (1 + i.ServiceCharge) * (1 + i.Tax)) as Amount
var query = @"
select v.Settled, Sum(i.Amount)
const string query = @"
select s.Settled, Sum(s.Amount)
from Voucher v
inner join v.Kots k
inner join k.Inventories i
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.Settled != :noCharge
group by v.Settled
order by v.Settled
inner join v.Settlements s
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
group by s.Settled
order by s.Settled
";
var list = session
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.SetParameter("noCharge", SettleOption.NoCharge)
.List<object[]>();
decimal amount = 0;
foreach (var item in list)
@ -138,7 +141,7 @@ order by v.Settled
return GetOtherDetails(outList, startDate, finishDate);
}
}
private IList<SalesAnalysis> GetOtherDetails(IList<SalesAnalysis> outList, DateTime startDate, DateTime finishDate)
private static IList<SalesAnalysis> GetOtherDetails(IList<SalesAnalysis> outList, DateTime startDate, DateTime finishDate)
{
outList.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 });
if (finishDate <= startDate)
@ -151,17 +154,19 @@ select Sum(i.Quantity * i.Rate * (1 - i.Discount) * i.ServiceCharge)
from Voucher v
inner join v.Kots k
inner join k.Inventories i
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.Settled != :noCharge and v.Settled != :unsettled
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v
and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff)
";
var amt = session
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.SetParameter("noCharge", SettleOption.NoCharge)
.SetParameter("unsettled", SettleOption.Unsettled)
.UniqueResult();
if (amt == null)
amt = 0M;
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.SetParameter("noCharge", SettleOption.NoCharge)
.SetParameter("unsettled", SettleOption.Unsettled)
.SetParameter("amount", SettleOption.Amount)
.SetParameter("roundoff", SettleOption.RoundOff)
.UniqueResult() ?? 0M;
outList.Add(new SalesAnalysis() { GroupType = "Service Charge", Amount = (decimal)amt });
#endregion
#region Tax
@ -170,7 +175,9 @@ select i.Tax, Sum(i.Quantity * i.Rate * (1 - i.Discount) * (1 + i.ServiceCharge)
from Voucher v
inner join v.Kots k
inner join k.Inventories i
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.Settled != :noCharge and v.Settled != :unsettled
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v
and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff)
group by i.Tax
";
var list = session
@ -179,6 +186,8 @@ group by i.Tax
.SetParameter("finishDate", finishDate)
.SetParameter("noCharge", SettleOption.NoCharge)
.SetParameter("unsettled", SettleOption.Unsettled)
.SetParameter("amount", SettleOption.Amount)
.SetParameter("roundoff", SettleOption.RoundOff)
.List<object[]>();
foreach (var item in list)
outList.Add(new SalesAnalysis() { GroupType = string.Format("Tax {0:P}", (decimal)item[0]), Amount = (decimal)item[1] });

@ -124,5 +124,21 @@ namespace Tanshu.Accounts.Repository
return user;
}
}
public static IList<User> ListActive(DateTime startDate, DateTime finishDate)
{
using (var session = SessionManager.Session)
{
const string query = @"
select distinct(u) from Voucher v
inner join v.User u
where v.Date >= :startDate and v.Date <= :finishDate
order by u.Name";
return session.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.List<User>();
}
}
}
}

@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Tanshu.Accounts.Contracts;
using Tanshu.Data.DAO;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.SqlDAO;
using NHibernate.Criterion;
using Tanshu.Accounts.Entities.Auth;
using NHibernate;
using System.Linq;
namespace Tanshu.Accounts.Repository
{
@ -46,54 +43,59 @@ namespace Tanshu.Accounts.Repository
return session.Get<Voucher>(voucherID).Printed;
}
}
static public int? Insert(Voucher saleVoucher)
static public int? Insert(Voucher voucher)
{
using (var session = SessionManager.Session)
{
using (var trans = session.BeginTransaction())
{
DateTime dt = DbValues.Date;
saleVoucher.CreationDate = dt;
saleVoucher.LastEditDate = dt;
saleVoucher.Date = dt;
saleVoucher.KotID = DbValues.KotID;
if (saleVoucher.Printed)
saleVoucher.BillID = DbValues.BillID;
else
saleVoucher.BillID = saleVoucher.KotID;
var dt = DbValues.Date;
voucher.CreationDate = dt;
voucher.LastEditDate = dt;
voucher.Date = dt;
voucher.KotID = DbValues.KotID;
voucher.BillID = voucher.Printed ? DbValues.BillID : voucher.KotID;
Kot addedKot = null;
foreach (var item in saleVoucher.Kots)
foreach (var item in voucher.Kots.Where(item => item.KotID == 0))
{
if (item.KotID != 0)
continue;
addedKot = item;
item.Date = dt;
item.Printed = true;
item.TableID = saleVoucher.TableID;
item.User = saleVoucher.User;
item.TableID = voucher.TableID;
item.User = voucher.User;
item.Code = DbValues.KotCode;
}
session.Save(saleVoucher);
using (var ft = new FoodTableBI(session, true))
{
string status;
if (!saleVoucher.Printed)
status = "running";
else if (saleVoucher.Settled == SettleOption.Unsettled && saleVoucher.Void == false)
status = "printed";
else
status = null;
ft.UpdateStatus(saleVoucher.TableID, saleVoucher.VoucherID, status);
}
UpdateSettlements(voucher, session);
session.Save(voucher);
UpdateTable(voucher, session);
trans.Commit();
if (addedKot == null)
return null;
else
return addedKot.KotID;
return addedKot == null ? (int?)null : addedKot.KotID;
}
}
}
private static void UpdateSettlements(Voucher voucher, ISession session)
{
var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
amount = Math.Round(amount, 5);
if (voucher.Settlements.Count(x => x.Settled == SettleOption.Amount) == 0)
voucher.Settlements.Add(new VoucherSettlement() { Amount = amount, Settled = SettleOption.Amount });
else
voucher.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount = amount;
var roundoff = Math.Round(amount) - amount;
if (voucher.Settlements.Count(x => x.Settled == SettleOption.RoundOff) == 0)
voucher.Settlements.Add(new VoucherSettlement() { Amount = roundoff, Settled = SettleOption.RoundOff });
else
voucher.Settlements.Single(x => x.Settled == SettleOption.RoundOff).Amount = roundoff;
var balance = voucher.Settlements.Where(x => x.Settled != SettleOption.Unsettled).Sum(x => x.Amount);
if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) == 0)
voucher.Settlements.Add(new VoucherSettlement() { Amount = balance, Settled = SettleOption.Unsettled });
else if (balance == 0)
voucher.Settlements.Remove(voucher.Settlements.Single(x => x.Settled == SettleOption.Unsettled));
else
voucher.Settlements.Single(x => x.Settled == SettleOption.Unsettled).Amount = balance;
}
public static void Delete(int voucherID)
{
using (var session = SessionManager.Session)
@ -113,45 +115,34 @@ namespace Tanshu.Accounts.Repository
}
}
static public int? Update(Voucher saleVoucher)
static public int? Update(Voucher voucher)
{
using (var session = SessionManager.Session)
{
using (var trans = session.BeginTransaction())
{
DateTime dt = DbValues.Date;
saleVoucher.LastEditDate = dt;
if (saleVoucher.Date == null)
var dt = DbValues.Date;
voucher.LastEditDate = dt;
if (voucher.Date == null)
{
saleVoucher.Date = dt;
saleVoucher.BillID = DbValues.BillID;
voucher.Date = dt;
voucher.BillID = DbValues.BillID;
}
if (!saleVoucher.Printed)
saleVoucher.Date = dt;
if (!voucher.Printed)
voucher.Date = dt;
Kot addedKot = null;
foreach (var item in saleVoucher.Kots)
foreach (var item in voucher.Kots.Where(item => item.KotID == 0))
{
if (item.KotID != 0)
continue;
addedKot = item;
item.Date = dt;
item.Printed = true;
item.TableID = saleVoucher.TableID;
item.User = saleVoucher.User;
item.TableID = voucher.TableID;
item.User = voucher.User;
item.Code = DbValues.KotCode;
}
session.Update(saleVoucher);
using (var ft = new FoodTableBI(session, true))
{
string status;
if (!saleVoucher.Printed)
status = "running";
else if (saleVoucher.Settled == SettleOption.Unsettled && saleVoucher.Void == false)
status = "printed";
else
status = null;
ft.UpdateStatus(saleVoucher.TableID, saleVoucher.VoucherID, status);
}
UpdateSettlements(voucher, session);
session.Update(voucher);
UpdateTable(voucher, session);
trans.Commit();
if (addedKot == null)
return null;
@ -160,7 +151,21 @@ namespace Tanshu.Accounts.Repository
}
}
}
static public Voucher GetSaleVoucher(int voucherID)
static private void UpdateTable(Voucher voucher, ISession session)
{
using (var ft = new FoodTableBI(session, true))
{
string status;
if (!voucher.Printed)
status = "running";
else if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) != 0 && voucher.Void == false)
status = "printed";
else
status = null;
ft.UpdateStatus(voucher.TableID, voucher.VoucherID, status);
}
}
static public Voucher GetVoucher(int voucherID)
{
using (var session = SessionManager.Session)
{
@ -179,6 +184,8 @@ namespace Tanshu.Accounts.Repository
NHibernateUtil.Initialize(inmod.Modifier);
}
}
foreach (var item in voucher.Settlements)
NHibernateUtil.Initialize(item);
return voucher;
}
}
@ -193,51 +200,28 @@ namespace Tanshu.Accounts.Repository
saleVoucher.Void = true;
saleVoucher.VoidReason = reason;
session.Save(saleVoucher);
using (var ft = new FoodTableBI(session, true))
{
string status;
if (!saleVoucher.Printed)
status = "running";
else if (saleVoucher.Settled == SettleOption.Unsettled && saleVoucher.Void == false)
status = "printed";
else
status = null;
ft.UpdateStatus(saleVoucher.TableID, saleVoucher.VoucherID, status);
}
UpdateTable(saleVoucher, session);
trans.Commit();
}
}
}
static public void SettleVoucher(User user, int voucherID, SettleOption settleOption)
static public void SettleVoucher(User user, int voucherID, IDictionary<SettleOption, decimal> values)
{
using (var session = SessionManager.Session)
{
using (var trans = session.BeginTransaction())
{
var saleVoucher = session.Get<Voucher>(voucherID);
saleVoucher.Settled = (SettleOption)settleOption;
saleVoucher.User = user;
saleVoucher.LastEditDate = DbValues.Date;
session.Update(saleVoucher);
var table = session.CreateCriteria<FoodTable>()
.Add(Restrictions.Eq("Name", saleVoucher.TableID))
.UniqueResult<FoodTable>();
table.Status = null;
session.Update(table);
using (var ft = new FoodTableBI(session, true))
{
string status;
if (!saleVoucher.Printed)
status = "running";
else if (saleVoucher.Settled == SettleOption.Unsettled && saleVoucher.Void == false)
status = "printed";
else
status = null;
ft.UpdateStatus(saleVoucher.TableID, saleVoucher.VoucherID, status);
}
var voucher = session.Get<Voucher>(voucherID);
foreach (var item in voucher.Settlements.Where(x => x.Settled != SettleOption.Amount && x.Settled != SettleOption.RoundOff && x.Settled != SettleOption.Unsettled))
session.Delete(item);
foreach (var item in values.Where(x => x.Key != SettleOption.Amount && x.Key != SettleOption.RoundOff && x.Key != SettleOption.Unsettled))
voucher.Settlements.Add(new VoucherSettlement { Settled = item.Key, Amount = item.Value });
UpdateSettlements(voucher, session);
voucher.User = user;
voucher.LastEditDate = DbValues.Date;
session.Update(voucher);
UpdateTable(voucher, session);
trans.Commit();
}
}

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.Instances;
using FluentNHibernate.Conventions.Inspections;
using FluentNHibernate.Conventions.AcceptanceCriteria;

@ -1,8 +1,6 @@
using System;
using FluentNHibernate;
using FluentNHibernate.Automapping;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.SqlDAO;
namespace Tanshu.Accounts.Repository
{

@ -8,8 +8,8 @@
<ProjectGuid>{B755D152-37C3-47D6-A721-3AD17A8EF316}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Tanshu.Accounts.SqlDAO</RootNamespace>
<AssemblyName>Tanshu.Accounts.SqlDAO</AssemblyName>
<RootNamespace>Tanshu.Accounts.Repository</RootNamespace>
<AssemblyName>Tanshu.Accounts.Repository</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkSubset>Full</TargetFrameworkSubset>