narsil/Tanshu.Accounts.Contracts/Data Contracts/InventoryBO.cs
tanshu bb2db24837 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.
2016-03-29 15:06:46 +05:30

138 lines
4.8 KiB
C#

using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;
using System;
using System.ComponentModel;
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 decimal FullPrice { 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 decimal Amount
{
get
{
if (IsScTaxable)
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * (1 + ServiceTaxRate + VatRate);
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge + ServiceTaxRate + VatRate);
}
set { }
}
public virtual decimal ServiceTaxAmount
{
get
{
if (IsScTaxable)
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * ServiceTaxRate;
return Quantity * Price * (1 - Discount) * ServiceTaxRate;
}
}
public virtual decimal VatAmount
{
get
{
if (IsScTaxable)
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * VatRate;
return Quantity * Price * (1 - Discount) * VatRate;
}
}
public virtual decimal ServiceChargeAmount
{
get
{
return Quantity * Price * (1 - Discount) * ServiceCharge;
}
}
public virtual decimal DiscountAmount
{
get
{
return Quantity * Price * Discount;
}
}
public virtual decimal Net
{
get
{
return Quantity * Price * (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.FullPrice, 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.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");
});
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(); });
}
}
}