using System; using InABox.Core; using PRSClasses; namespace Comal.Classes { [UserTracking(typeof(Product))] public class SupplierProduct : StockEntity, IPersistent, IRemotable, ILicense, IExportable, IImportable, IManyToMany, IJobMaterial { private bool bChanging; [RequiredColumn] [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)] [RequiredColumn] [DimensionsEditor(typeof(StockDimensions))] public override StockDimensions Dimensions { get; set; } [EntityRelationship(DeleteAction.SetNull)] [EditorSequence(3)] public ProductStyleGroupLink StyleGroup { get; set; } [EntityRelationship(DeleteAction.SetNull)] [EditorSequence(4)] public ProductStyleLink Style { get; set; } /// /// The product code as the supplier knows it. /// [Comment("Product code as the supplier knows it.")] [CodeEditor(Editable = Editable.Enabled)] [EditorSequence(5)] public string SupplierCode { get; set; } /// /// Product description as the supplier knows it. /// [Comment("Product description as the supplier knows it.")] [TextBoxEditor] [EditorSequence(6)] public string SupplierDescription { get; set; } [TextBoxEditor] [EditorSequence(7)] public string SupplierCategory { get; set; } [EditorSequence(8)] public JobLink Job { get; set; } [CurrencyEditor(Visible = Visible.Optional)] [EditorSequence(9)] public double ForeignCurrencyPrice { get; set; } [CurrencyEditor(Visible = Visible.Optional)] [EditorSequence(10)] public double TradePrice { get; set; } [DoubleEditor(Visible = Visible.Optional)] [EditorSequence(11)] public double Discount { get; set; } [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Disabled)] [EditorSequence(12)] public double CostPrice { get; set; } [EditorSequence(13)] public TaxCodeLink TaxCode { get; set; } [URLEditor] [EditorSequence(14)] public string URL { get; set; } [TimestampEditor] [EditorSequence(15)] public DateTime Expired { get; set; } 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(); } private static String STYLEGROUPID = CoreUtils.GetFullPropertyName(x => x.StyleGroup.ID, "."); private static String STYLEID = CoreUtils.GetFullPropertyName(x => x.Style.ID, "."); protected override void DoPropertyChanged(string name, object? before, object? after) { base.DoPropertyChanged(name, before, after); if (bChanging) return; bChanging = true; if (name.Equals(nameof(ForeignCurrencyPrice)) && SupplierLink.Currency.ID != Guid.Empty) { TradePrice = (double)after / (SupplierLink.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : SupplierLink.Currency.ExchangeRate); CostPrice = TradePrice * (100.0F - Discount) / 100.0F; } else if (name.Equals(nameof(TradePrice))) { if (SupplierLink.Currency.ID != Guid.Empty) ForeignCurrencyPrice = (double)after * SupplierLink.Currency.ExchangeRate; CostPrice = (double)after * (100.0F - Discount) / 100.0F; } else if (name.Equals(nameof(Discount))) CostPrice = TradePrice * (100.0F - (double)after) / 100.0F; //else if (name.Equals(name,nameof(CostPrice))) // TradePrice = Discount == 100.0F ? double.MaxValue : (double)after / ((100.0F - Discount) / 100.0F); else if (name.Equals(STYLEGROUPID)) Style.CopyFrom(new ProductStyleLink()); else if (name.Equals(STYLEID)) StyleGroup.CopyFrom(new ProductStyleGroupLink()); bChanging = false; } } }