narsil/Tanshu.Accounts.Contracts/Data Contracts/InventoryBO.cs
tanshu 69617949bd Important! : Need to update to new schema using SQL Scripts
Important! : This version will not work.  It is pre-alpha and saved in case of catastrophic failure
Refactor: Remove dependency on Fluent Nhibernate.
Refactor: All Primary keys are now Guids.
Refactor: Class Mappings changed from AutoMap to Explicit Mappings.
Breakage: All Cascading is now disabled and entities must be explicitly saved/updated/deleted
Breakage: Auto Commiting is now off and "SaveChanges()" needs to be called on all BIs.
Refactor: Changed the pattern where all relevant db code for an operation is basically in the same function.
Chore: Removed Advance and Payments options.
2014-10-12 15:11:45 +05:30

92 lines
3.5 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 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.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(); });
}
}
}