123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using System;
- using InABox.Core;
- using PRSClasses;
- namespace Comal.Classes
- {
- [UserTracking(typeof(Product))]
- public class SupplierProduct : StockEntity, IPersistent, IRemotable, ILicense<ProductManagementLicense>, IExportable, IImportable, IManyToMany<Supplier, Product>, 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 ProductStyleLink Style { get; set; }
-
- [CodeEditor(Editable = Editable.Enabled)]
- [EditorSequence(4)]
- public string SupplierCode { get; set; }
- [TextBoxEditor]
- [EditorSequence(5)]
- public string SupplierDescription { get; set; }
- [TextBoxEditor]
- [EditorSequence(6)]
- public string SupplierCategory { get; set; }
-
- [EditorSequence(7)]
- public JobLink Job { get; set; }
-
- [DoubleEditor(Visible = Visible.Optional)]
- [EditorSequence(8)]
- public double ForeignCurrencyPrice { get; set; }
-
- [CurrencyEditor(Visible = Visible.Optional)]
- [EditorSequence(9)]
- public double TradePrice { get; set; }
- [DoubleEditor(Visible = Visible.Optional)]
- [EditorSequence(10)]
- public double Discount { get; set; }
- [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Disabled)]
- [EditorSequence(11)]
- public double CostPrice { get; set; }
- [EditorSequence(12)]
- public TaxCodeLink TaxCode { get; set; }
- [URLEditor]
- [EditorSequence(13)]
- public string URL { get; set; }
- [TimestampEditor]
- [EditorSequence(14)]
- public DateTime Expired { get; set; }
-
- static SupplierProduct()
- {
- LinkedProperties.Register<SupplierProduct, ProductLink, String>(x => x.Product, x => x.Code, x => x.SupplierCode);
- LinkedProperties.Register<SupplierProduct, ProductLink, String>(x => x.Product, x => x.Name, x => x.SupplierDescription);
- StockEntity.LinkStockDimensions<SupplierProduct>();
- }
- 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);
- bChanging = false;
- }
- }
- }
|