using System; using InABox.Core; namespace Comal.Classes { [UserTracking(typeof(Product))] public class SupplierProduct : StockEntity, IPersistent, IRemotable, ILicense, IExportable, IImportable, IManyToMany { private bool bChanging; [EditorSequence(0)] public SupplierLink SupplierLink { get; set; } [EntityRelationship(DeleteAction.SetNull)] [NullEditor] [Obsolete("Replaced with Product", true)] public ProductLink ProductLink { get { return Product; } set { Product = value; } } [EntityRelationship(DeleteAction.SetNull)] [EditorSequence(1)] public override ProductLink Product { get; set; } [EditorSequence(2)] public JobLink Job { get; set; } [CodeEditor(Editable = Editable.Enabled)] [EditorSequence(3)] public string SupplierCode { get; set; } [TextBoxEditor] [EditorSequence(4)] public string SupplierDescription { get; set; } [EditorSequence(5)] [RequiredColumn] [DimensionsEditor(typeof(StockDimensions), AllowEditingUnit = false)] public override StockDimensions Dimensions { get; set; } [TextBoxEditor] [EditorSequence(6)] public string SupplierCategory { get; set; } [CurrencyEditor(Visible = Visible.Optional)] [EditorSequence(7)] public double TradePrice { get; set; } [DoubleEditor(Visible = Visible.Optional)] [EditorSequence(8)] public double Discount { get; set; } [CurrencyEditor(Visible = Visible.Optional)] [EditorSequence(9)] public double CostPrice { get; set; } [EditorSequence(10)] public TaxCodeLink TaxCode { get; set; } [URLEditor] [EditorSequence(11)] public string URL { get; set; } [TimestampEditor] [EditorSequence(12)] public DateTime Expired { get; set; } protected override void Init() { base.Init(); SupplierLink = new SupplierLink(() => this); Job = new JobLink(); TaxCode = new TaxCodeLink(); } static SupplierProduct() { LinkedProperties.Register(x => x.Product, x => x.Code, x => x.SupplierCode); LinkedProperties.Register(x => x.Product, x => x.Name, x => x.SupplierDescription); StockEntity.LinkStockDimensions(); } protected override void DoPropertyChanged(string name, object before, object after) { base.DoPropertyChanged(name, before, after); if (bChanging) return; bChanging = true; if (name.Equals("TradePrice")) CostPrice = (double)after * (100.0F - Discount) / 100.0F; else if (name.Equals("Discount")) CostPrice = TradePrice * (100.0F - (double)after) / 100.0F; else if (name.Equals("CostPrice")) TradePrice = Discount == 100.0F ? double.MaxValue : (double)after / ((100.0F - Discount) / 100.0F); bChanging = false; } } }