Refactor: Instead of a concept of Price/FullPrice, happy hour is now a checkbox in the product.
This needed major refactor in all parts dealing with product or inventory.
This commit is contained in:
@ -15,7 +15,7 @@ namespace Tanshu.Accounts.Contracts
|
||||
{
|
||||
if (inventory != null)
|
||||
{
|
||||
var output = string.Format("{0} @ Rs. {1:#.##}", inventory.Product.FullName, inventory.Price);
|
||||
var output = string.Format("{0} @ Rs. {1:#.##}", inventory.EffectiveName, inventory.Price);
|
||||
if (inventory.Discount != 0)
|
||||
output += string.Format(" - {0:#.##%}", inventory.Discount);
|
||||
foreach (var item in inventory.InventoryModifier)
|
||||
@ -36,12 +36,12 @@ namespace Tanshu.Accounts.Contracts
|
||||
{
|
||||
inventory = inv;
|
||||
}
|
||||
public BillItemValue(Product product)
|
||||
public BillItemValue(Product product, bool isHappyHour)
|
||||
{
|
||||
inventory = new Inventory()
|
||||
{
|
||||
Product = product,
|
||||
FullPrice = product.FullPrice,
|
||||
IsHappyHour = isHappyHour,
|
||||
Price = product.Price,
|
||||
IsScTaxable = product.IsScTaxable,
|
||||
Quantity = 1,
|
||||
|
||||
@ -4,7 +4,8 @@ namespace Tanshu.Accounts.Contracts
|
||||
{
|
||||
public enum BillItemType
|
||||
{
|
||||
Product,
|
||||
RegularProduct,
|
||||
HappyHourProduct,
|
||||
Kot
|
||||
}
|
||||
public class BillItemKey
|
||||
@ -18,15 +19,15 @@ namespace Tanshu.Accounts.Contracts
|
||||
public BillItemKey(Guid kotID)
|
||||
: this(Guid.Empty, kotID, BillItemType.Kot)
|
||||
{ }
|
||||
public BillItemKey(Guid productID, Guid kotID)
|
||||
: this(productID, kotID, BillItemType.Product)
|
||||
public BillItemKey(Guid productID, Guid kotID, bool IsHappyHour)
|
||||
: this(productID, kotID, IsHappyHour? BillItemType.HappyHourProduct : BillItemType.RegularProduct)
|
||||
{ }
|
||||
|
||||
private Guid _productID;
|
||||
public Guid ProductID
|
||||
{
|
||||
get { return BillItemType == BillItemType.Product ? _productID : Guid.Empty; }
|
||||
private set { _productID = BillItemType == BillItemType.Product ? value : Guid.Empty; }
|
||||
get { return BillItemType != BillItemType.Kot ? _productID : Guid.Empty; }
|
||||
private set { _productID = BillItemType != BillItemType.Kot ? value : Guid.Empty; }
|
||||
}
|
||||
|
||||
public Guid KotID { get; private set; }
|
||||
@ -35,7 +36,7 @@ namespace Tanshu.Accounts.Contracts
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return BillItemType.GetHashCode() ^ KotID.GetHashCode() ^ ProductID.GetHashCode();
|
||||
return BillItemType.GetHashCode() ^ KotID.GetHashCode() ^ ProductID.GetHashCode() ^ BillItemType.GetHashCode();
|
||||
}
|
||||
public static bool operator ==(BillItemKey a, BillItemKey b)
|
||||
{
|
||||
@ -50,7 +51,7 @@ namespace Tanshu.Accounts.Contracts
|
||||
if (a.BillItemType != b.BillItemType)
|
||||
return false;
|
||||
|
||||
return a.KotID == b.KotID && a.BillItemType == b.BillItemType && a.ProductID == b.ProductID;
|
||||
return a.KotID == b.KotID && a.BillItemType == b.BillItemType && a.ProductID == b.ProductID && a.BillItemType == b.BillItemType;
|
||||
}
|
||||
public static bool operator !=(BillItemKey a, BillItemKey b)
|
||||
{
|
||||
|
||||
@ -19,10 +19,22 @@ namespace Tanshu.Accounts.Contracts
|
||||
|
||||
public class SalesAnalysisDetail
|
||||
{
|
||||
public virtual string Product { get; set; }
|
||||
public virtual decimal Sale { get; set; }
|
||||
public virtual decimal NC { get; set; }
|
||||
public virtual decimal Staff { get; set; }
|
||||
private string _name;
|
||||
public Guid ProductID { get; set; }
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsHappyHour ? "H H " + _name : _name;
|
||||
}
|
||||
set
|
||||
{
|
||||
_name = value;
|
||||
}
|
||||
}
|
||||
public bool IsHappyHour { get; set; }
|
||||
public decimal Sale { get; set; }
|
||||
public decimal NC { get; set; }
|
||||
}
|
||||
public class BillDetail
|
||||
{
|
||||
|
||||
@ -20,7 +20,7 @@ namespace Tanshu.Accounts.Entities
|
||||
public virtual Product Product { get; set; }
|
||||
public virtual decimal Quantity { get; set; }
|
||||
public virtual decimal Price { get; set; }
|
||||
public virtual decimal FullPrice { get; set; }
|
||||
public virtual bool IsHappyHour { get; set; }
|
||||
public virtual decimal ServiceCharge { get; set; }
|
||||
public virtual bool IsScTaxable { get; set; }
|
||||
public virtual decimal ServiceTaxRate { get; set; }
|
||||
@ -31,13 +31,29 @@ namespace Tanshu.Accounts.Entities
|
||||
|
||||
public virtual IList<InventoryModifier> InventoryModifier { get; set; }
|
||||
|
||||
public virtual string EffectiveName
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsHappyHour ? string.Format("H H {0}", Product.FullName) : Product.FullName;
|
||||
}
|
||||
set { }
|
||||
}
|
||||
public virtual decimal EffectivePrice
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsHappyHour ? 0 : Price;
|
||||
}
|
||||
set { }
|
||||
}
|
||||
public virtual decimal Amount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsScTaxable)
|
||||
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * (1 + ServiceTaxRate + VatRate);
|
||||
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge + ServiceTaxRate + VatRate);
|
||||
return Quantity * EffectivePrice * (1 - Discount) * (1 + ServiceCharge) * (1 + ServiceTaxRate + VatRate);
|
||||
return Quantity * EffectivePrice * (1 - Discount) * (1 + ServiceCharge + ServiceTaxRate + VatRate);
|
||||
}
|
||||
set { }
|
||||
}
|
||||
@ -47,8 +63,8 @@ namespace Tanshu.Accounts.Entities
|
||||
get
|
||||
{
|
||||
if (IsScTaxable)
|
||||
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * ServiceTaxRate;
|
||||
return Quantity * Price * (1 - Discount) * ServiceTaxRate;
|
||||
return Quantity * EffectivePrice * (1 - Discount) * (1 + ServiceCharge) * ServiceTaxRate;
|
||||
return Quantity * EffectivePrice * (1 - Discount) * ServiceTaxRate;
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,8 +73,8 @@ namespace Tanshu.Accounts.Entities
|
||||
get
|
||||
{
|
||||
if (IsScTaxable)
|
||||
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * VatRate;
|
||||
return Quantity * Price * (1 - Discount) * VatRate;
|
||||
return Quantity * EffectivePrice * (1 - Discount) * (1 + ServiceCharge) * VatRate;
|
||||
return Quantity * EffectivePrice * (1 - Discount) * VatRate;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +82,7 @@ namespace Tanshu.Accounts.Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
return Quantity * Price * (1 - Discount) * ServiceCharge;
|
||||
return Quantity * EffectivePrice * (1 - Discount) * ServiceCharge;
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,7 +90,7 @@ namespace Tanshu.Accounts.Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
return Quantity * Price * Discount;
|
||||
return Quantity * EffectivePrice * Discount;
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,7 +98,7 @@ namespace Tanshu.Accounts.Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
return Quantity * Price * (1 - Discount);
|
||||
return Quantity * EffectivePrice * (1 - Discount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97,15 +113,19 @@ namespace Tanshu.Accounts.Entities
|
||||
Property(x => x.SortOrder, map => map.NotNullable(true));
|
||||
Property(x => x.Quantity, map => map.NotNullable(true));
|
||||
Property(x => x.Price, map => map.NotNullable(true));
|
||||
Property(x => x.FullPrice, map => map.NotNullable(true));
|
||||
Property(x => x.IsHappyHour, map => map.NotNullable(true));
|
||||
Property(x => x.ServiceTaxRate, map => map.NotNullable(true));
|
||||
Property(x => x.VatRate, map => map.NotNullable(true));
|
||||
Property(x => x.Discount, map => map.NotNullable(true));
|
||||
Property(x => x.ServiceCharge, map => map.NotNullable(true));
|
||||
Property(x => x.IsScTaxable, map => map.NotNullable(true));
|
||||
Property(x => x.EffectivePrice, map =>
|
||||
{
|
||||
map.Formula("CASE WHEN IsHappyHour = 1 THEN 0 ELSE Price END");
|
||||
});
|
||||
Property(x => x.Amount, map =>
|
||||
{
|
||||
map.Formula("CASE WHEN IsScTaxable = 1 THEN Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * (1 + ServiceTaxRate + VatRate) ELSE Quantity * Price * (1 - Discount) * (1 + ServiceCharge + ServiceTaxRate + VatRate) END");
|
||||
map.Formula("Quantity * CASE WHEN IsHappyHour = 1 THEN 0 ELSE Price END * (1 - Discount) * CASE WHEN IsScTaxable = 1 THEN (1 + ServiceCharge) * (1 + ServiceTaxRate + VatRate) ELSE (1 + ServiceCharge + ServiceTaxRate + VatRate) END");
|
||||
});
|
||||
|
||||
ManyToOne(x => x.ServiceTax, map =>
|
||||
|
||||
@ -17,7 +17,7 @@ namespace Tanshu.Accounts.Entities
|
||||
public virtual decimal ServiceCharge { get; set; }
|
||||
public virtual bool IsScTaxable { get; set; }
|
||||
public virtual decimal Price { get; set; }
|
||||
public virtual decimal FullPrice { get; set; }
|
||||
public virtual bool HasHappyHour { get; set; }
|
||||
public virtual bool IsActive { get; set; }
|
||||
public virtual bool IsNotAvailable { get; set; }
|
||||
public virtual int SortOrder { get; set; }
|
||||
@ -30,6 +30,7 @@ namespace Tanshu.Accounts.Entities
|
||||
{
|
||||
return Units == string.Empty ? Name : string.Format("{0} ({1})", Name, Units);
|
||||
}
|
||||
set { }
|
||||
}
|
||||
}
|
||||
public class ProductMap : ClassMapping<Product>
|
||||
@ -46,12 +47,16 @@ namespace Tanshu.Accounts.Entities
|
||||
Property(x => x.ServiceCharge, map => map.NotNullable(true));
|
||||
Property(x => x.IsScTaxable, map => map.NotNullable(true));
|
||||
Property(x => x.Price, map => map.NotNullable(true));
|
||||
Property(x => x.FullPrice, map => map.NotNullable(true));
|
||||
Property(x => x.HasHappyHour, map => map.NotNullable(true));
|
||||
Property(x => x.IsActive, map => map.NotNullable(true));
|
||||
Property(x => x.IsNotAvailable, map => map.NotNullable(true));
|
||||
Property(x => x.SortOrder, map => map.NotNullable(true));
|
||||
Property(x => x.Quantity, map => map.NotNullable(true));
|
||||
|
||||
Property(x => x.FullName, map =>
|
||||
{
|
||||
map.Formula("CASE WHEN Units = '' THEN Name ELSE Name + ' (' + Units + ')' END");
|
||||
});
|
||||
|
||||
ManyToOne(x => x.ProductGroup, map => { map.Column("ProductGroupID"); map.Cascade(Cascade.None); });
|
||||
ManyToOne(x => x.ServiceTax, map => { map.Column("ServiceTaxID"); map.Cascade(Cascade.None); });
|
||||
ManyToOne(x => x.Vat, map => { map.Column("VatID"); map.Cascade(Cascade.None); });
|
||||
|
||||
Reference in New Issue
Block a user