Refactor: Refactored the bill inventory in the hope of making it less

error prone and more understandable.
Refactor: Also upgrade path to moving from Price/FullPrice to HasHappyHour/
          IsHappyHour
Must have a few errors.
This commit is contained in:
tanshu
2016-03-29 15:06:46 +05:30
parent 4ac6f66041
commit bb2db24837
9 changed files with 295 additions and 323 deletions

View File

@ -6,163 +6,61 @@ namespace Tanshu.Accounts.Contracts
{
public class BillItemValue
{
public Guid ProductID { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public decimal FullPrice { get; set; }
public decimal Quantity { get; set; }
private decimal _discount;
public Product Product { get; private set; }
public bool IsKot { get; private set; }
public decimal Discount
{
get { return _discount; }
set
{
if (value < 0)
throw new ArgumentException("Discount has to be non-negative greater than or equal to zero.");
if (value > 1)
throw new ArgumentException("Discount has to be less than one.");
_discount = value;
}
}
public bool IsScTaxable { get; set; }
public Tax ServiceTax { get; set; }
public decimal ServiceTaxRate { get; set; }
public decimal ServiceTaxAmount
{
get
{
if (IsScTaxable)
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * ServiceTaxRate;
return Quantity * Price * (1 - Discount) * ServiceTaxRate;
}
}
public Tax Vat { get; set; }
public decimal VatRate { get; set; }
public decimal VatAmount
{
get
{
if (IsScTaxable)
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * VatRate;
return Quantity * Price * (1 - Discount) * VatRate;
}
}
public decimal ServiceCharge { get; set; }
public decimal ServiceChargeAmount
{
get
{
return Quantity * Price * (1 - Discount) * ServiceCharge;
}
}
public decimal DiscountAmount
{
get
{
return Quantity * Price * Discount;
}
}
public decimal GrossAmount
{
get
{
return Quantity * Price * (1 - Discount);
}
}
public bool Printed { get; set; }
public decimal Value
{
get
{
if (IsScTaxable)
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * (1 + ServiceTaxRate + VatRate);
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge + ServiceTaxRate + VatRate);
}
}
public Inventory inventory { get; set; }
public Kot kot { get; private set; }
public string Display
{
get
{
var output = string.Format("{0} @ Rs. {1:#.##}", Name, Price);
if (_discount != 0)
output += string.Format(" - {0:#.##%}", _discount);
if (Modifiers != null)
foreach (var item in Modifiers)
output += string.Format("\n\r -- {0}", item.Name);
return output;
//if (Price == 0)
// return string.Format(" -- {0}", Name);
//string output = string.Format("{0} @ Rs. {1:#.##}", Name, Price);
//if (discount != 0)
// output += string.Format(" - {0:#.##%}", discount);
//return output;
if (inventory != null)
{
var output = string.Format("{0} @ Rs. {1:#.##}", inventory.Product.FullName, inventory.Price);
if (inventory.Discount != 0)
output += string.Format(" - {0:#.##%}", inventory.Discount);
foreach (var item in inventory.InventoryModifier)
output += string.Format("\n\r -- {0}", item.Modifier.Name);
return output;
}
else if (kot.KotID != Guid.Empty)
{
return string.Format("Kot: S-{0} / {1:dd-MMM HH:mm} ({2})", kot.Code, kot.Date, kot.User.Name);
}
else
{
return "== New Kot ==";
}
}
}
public override string ToString()
public BillItemValue(Inventory inv)
{
return string.Format("{0} - {1}", ProductID, Name);
inventory = inv;
}
public IList<Modifier> Modifiers { get; set; }
public BillItemValue(Product product)
{
Modifiers = new List<Modifier>();
if (product != null)
inventory = new Inventory()
{
Product = product;
ProductID = product.ProductID;
Name = product.Units == string.Empty ? product.Name : product.Name + " (" + product.Units + ")";
Quantity = 1;
Price = product.Price;
FullPrice = product.FullPrice;
IsScTaxable = product.IsScTaxable;
ServiceTax = product.ServiceTax;
Vat = product.Vat;
ServiceTaxRate = product.ServiceTax.Rate;
VatRate = product.Vat.Rate;
ServiceCharge = product.ServiceCharge;
Discount = 0;
Printed = false;
IsKot = false;
}
Product = product,
FullPrice = product.FullPrice,
Price = product.Price,
IsScTaxable = product.IsScTaxable,
Quantity = 1,
ServiceCharge = product.ServiceCharge,
ServiceTax = product.ServiceTax,
Vat = product.Vat,
Discount = 0,
ServiceTaxRate = product.ServiceTax.Rate,
VatRate = product.Vat.Rate
};
}
public BillItemValue()
{
Product = null;
ProductID = Guid.Empty;
Discount = 0;
Name = "== New Kot ==";
Price = 0;
FullPrice = 0;
Printed = true;
Quantity = 0;
ServiceCharge = 0;
IsKot = true;
this.kot = new Kot();
}
public BillItemValue(Kot kot)
{
Product = null;
ProductID = kot.KotID;
Discount = 0;
Name = string.Format("Kot: S-{0} / {1:dd-MMM HH:mm} ({2})", kot.Code, kot.Date, kot.User.Name);
Price = 0;
FullPrice = 0;
Printed = true;
Quantity = 0;
ServiceCharge = 0;
IsKot = true;
this.kot = kot;
}
}