narsil/Tanshu.Accounts.Contracts/Data Contracts Display/BillInventoryBO.cs

164 lines
4.9 KiB
C#

using System;
using Tanshu.Accounts.Entities;
using System.Collections.Generic;
namespace Tanshu.Accounts.Contracts
{
public class BillItemValue
{
public int 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 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 decimal ServiceTax { get; set; }
public decimal ServiceTaxAmount
{
get
{
if (IsScTaxable)
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * ServiceTax;
return Quantity * Price * (1 - Discount) * ServiceTax;
}
}
public decimal Vat { get; set; }
public decimal VatAmount
{
get
{
if (IsScTaxable)
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * Vat;
return Quantity * Price * (1 - Discount) * Vat;
}
}
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 + ServiceTax + Vat);
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge + ServiceTax + Vat);
}
}
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;
}
}
public override string ToString()
{
return string.Format("{0} - {1}", ProductID, Name);
}
public IList<Modifier> Modifiers { get; set; }
public BillItemValue(Product product)
{
Modifiers = new List<Modifier>();
if (product != null)
{
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.Rate;
Vat = product.Vat.Rate;
ServiceCharge = product.ServiceCharge;
Discount = 0;
Printed = false;
}
}
public BillItemValue()
{
Product = null;
ProductID = 0;
Discount = 0;
Name = "== New Kot ==";
Price = 0;
FullPrice = 0;
Printed = true;
Quantity = 0;
Vat = -1;
ServiceCharge = 0;
}
public BillItemValue(Kot kot)
{
Product = null;
ProductID = kot.KotID;
Discount = 0;
Name = string.Format("Kot: {0} / {1:dd-MMM HH:mm} ({2})", kot.Code, kot.Date, kot.User.Name);
Price = 0;
FullPrice = 0;
Printed = true;
Quantity = 0;
Vat = -1;
ServiceCharge = 0;
}
}
}