c52f382ec2
Chore: Settle Choices form greatly simplified. Feature: Modifiers are now cached.
94 lines
3.7 KiB
C#
94 lines
3.7 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 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(); });
|
|
}
|
|
}
|
|
} |