narsil/Tanshu.Accounts.Contracts/Data Contracts/InventoryBO.cs

156 lines
5.3 KiB
C#

using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using System;
using System.Collections.Generic;
namespace Tanshu.Accounts.Entities
{
public class Inventory
{
public Inventory()
{
InventoryModifier = new List<InventoryModifier>();
}
public virtual Guid InventoryID { get; set; }
public virtual Kot Kot { get; set; }
public virtual int SortOrder { get; set; }
public virtual Product Product { get; set; }
public virtual decimal Quantity { get; set; }
public virtual decimal Price { 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; }
public virtual decimal VatRate { get; set; }
public virtual Tax ServiceTax { get; set; }
public virtual Tax Vat { get; set; }
public virtual decimal Discount { get; set; }
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 * EffectivePrice * (1 - Discount) * (1 + ServiceCharge) * (1 + ServiceTaxRate + VatRate);
return Quantity * EffectivePrice * (1 - Discount) * (1 + ServiceCharge + ServiceTaxRate + VatRate);
}
set { }
}
public virtual decimal ServiceTaxAmount
{
get
{
if (IsScTaxable)
return Quantity * EffectivePrice * (1 - Discount) * (1 + ServiceCharge) * ServiceTaxRate;
return Quantity * EffectivePrice * (1 - Discount) * ServiceTaxRate;
}
}
public virtual decimal VatAmount
{
get
{
if (IsScTaxable)
return Quantity * EffectivePrice * (1 - Discount) * (1 + ServiceCharge) * VatRate;
return Quantity * EffectivePrice * (1 - Discount) * VatRate;
}
}
public virtual decimal ServiceChargeAmount
{
get
{
return Quantity * EffectivePrice * (1 - Discount) * ServiceCharge;
}
}
public virtual decimal DiscountAmount
{
get
{
return Quantity * EffectivePrice * Discount;
}
}
public virtual decimal Net
{
get
{
return Quantity * EffectivePrice * (1 - Discount);
}
}
}
public class InventoryMap : ClassMapping<Inventory>
{
public InventoryMap()
{
Table("Inventories");
Schema("dbo");
Lazy(true);
Id(x => x.InventoryID, m => m.Generator(Generators.GuidComb));
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.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("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 =>
{
map.Column("ServiceTaxID");
map.NotNullable(true);
map.Cascade(Cascade.None);
});
ManyToOne(x => x.Vat, map =>
{
map.Column("VatID");
map.NotNullable(true);
map.Cascade(Cascade.None);
});
ManyToOne(x => x.Kot, map =>
{
map.Column("KotID");
map.NotNullable(true);
map.Cascade(Cascade.None);
});
ManyToOne(x => x.Product, map =>
{
map.Column("ProductID");
map.NotNullable(true);
map.Cascade(Cascade.None);
});
Bag(x => x.InventoryModifier, colmap => { colmap.Key(x => x.Column("InventoryID")); colmap.Inverse(true); }, map => { map.OneToMany(); });
}
}
}